Skip to content

Build and release Firestore compat #4616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages-exp/auth-compat-exp/rollup.config.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export function getEs5Builds(additionalTypescriptPlugins = {}) {
extend: true,
name: 'firebase',
globals: {
'@firebase/app-compat': 'firebase'
'@firebase/app-compat': 'firebase',
'@firebase/app': 'firebase.INTERNAL.modularAPIs'
},
/**
* use iife to avoid below error in the old Safari browser
Expand All @@ -97,7 +98,7 @@ export function getEs5Builds(additionalTypescriptPlugins = {}) {
}`
},
plugins: [...es5BuildPlugins, uglify()],
external: ['@firebase/app-compat']
external: ['@firebase/app-compat', '@firebase/app']
}
];
}
Expand Down
55 changes: 55 additions & 0 deletions packages/firestore/compat/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
loadBundle as expLoadBundle,
namedQuery as expNamedQuery,
LoadBundleTask
} from '../exp/index';
import { Firestore, Query } from '../src/api/database';

export function loadBundle(
this: Firestore,
data: ArrayBuffer | ReadableStream<Uint8Array> | string
): LoadBundleTask {
return expLoadBundle(this._delegate, data);
}

export function namedQuery(
this: Firestore,
queryName: string
): Promise<Query | null> {
return expNamedQuery(this._delegate, queryName).then(expQuery => {
if (!expQuery) {
return null;
}
return new Query(
this,
// We can pass `expQuery` here directly since named queries don't have a UserDataConverter.
// Otherwise, we would have to create a new ExpQuery and pass the old UserDataConverter.
expQuery
);
});
}

/**
* Prototype patches bundle loading to Firestore.
*/
export function registerBundle(instance: typeof Firestore): void {
instance.prototype.loadBundle = loadBundle;
instance.prototype.namedQuery = namedQuery;
}
92 changes: 92 additions & 0 deletions packages/firestore/compat/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { FirebaseApp } from '@firebase/app-compat';
import { FirebaseNamespace } from '@firebase/app-types';
import { _FirebaseNamespace } from '@firebase/app-types/private';
import { Component, ComponentType } from '@firebase/component';

import {
FirebaseFirestore,
CACHE_SIZE_UNLIMITED,
FieldPath,
GeoPoint,
Timestamp,
FieldValue
} from '../exp/index'; // import from the exp public API
import { Blob } from '../src/api/blob';
import {
Firestore,
Transaction,
CollectionReference,
DocumentReference,
DocumentSnapshot,
Query,
QueryDocumentSnapshot,
QuerySnapshot,
WriteBatch,
setLogLevel
} from '../src/api/database';

const firestoreNamespace = {
Firestore,
GeoPoint,
Timestamp,
Blob,
Transaction,
WriteBatch,
DocumentReference,
DocumentSnapshot,
Query,
QueryDocumentSnapshot,
QuerySnapshot,
CollectionReference,
FieldPath,
FieldValue,
setLogLevel,
CACHE_SIZE_UNLIMITED
};

/**
* Configures Firestore as part of the Firebase SDK by calling registerComponent.
*
* @param firebase - The FirebaseNamespace to register Firestore with
* @param firestoreFactory - A factory function that returns a new Firestore
* instance.
*/
export function configureForFirebase(
firebase: FirebaseNamespace,
firestoreFactory: (
app: FirebaseApp,
firestoreExp: FirebaseFirestore
) => Firestore
): void {
(firebase as _FirebaseNamespace).INTERNAL.registerComponent(
new Component(
'firestore',
container => {
const app = container.getProvider('app-compat').getImmediate()!;
const firestoreExp = container
.getProvider('firestore-exp')
.getImmediate()!;
return firestoreFactory(app, firestoreExp);
},
ComponentType.PUBLIC
).setServiceProps({ ...firestoreNamespace })
);
}
44 changes: 44 additions & 0 deletions packages/firestore/compat/index.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import firebase from '@firebase/app-compat';
import { FirebaseNamespace } from '@firebase/app-types';

import { name, version } from '../package.json';
import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database';

import { registerBundle } from './bundle';
import { configureForFirebase } from './config';

import '../register-module';

/**
* Registers the main Firestore Node build with the components framework.
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
*/
export function registerFirestore(instance: FirebaseNamespace): void {
configureForFirebase(
instance,
(app, firestoreExp) =>
new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider())
);
instance.registerVersion(name, version, 'node');
}

registerFirestore((firebase as unknown) as FirebaseNamespace);
registerBundle(Firestore);
44 changes: 44 additions & 0 deletions packages/firestore/compat/index.rn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import firebase from '@firebase/app-compat';
import { FirebaseNamespace } from '@firebase/app-types';

import { name, version } from '../package.json';
import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database';

import { registerBundle } from './bundle';
import { configureForFirebase } from './config';

import '../register-module';

/**
* Registers the main Firestore ReactNative build with the components framework.
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
*/
export function registerFirestore(instance: FirebaseNamespace): void {
configureForFirebase(
instance,
(app, firestoreExp) =>
new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider())
);
instance.registerVersion(name, version, 'rn');
}

registerFirestore((firebase as unknown) as FirebaseNamespace);
registerBundle(Firestore);
44 changes: 44 additions & 0 deletions packages/firestore/compat/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import firebase from '@firebase/app-compat';
import { FirebaseNamespace } from '@firebase/app-types';

import { name, version } from '../package.json';
import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database';

import { registerBundle } from './bundle';
import { configureForFirebase } from './config';

import '../register-module';

/**
* Registers the main Firestore build with the components framework.
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
*/
export function registerFirestore(instance: FirebaseNamespace): void {
configureForFirebase(
instance,
(app, firestoreExp) =>
new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider())
);
instance.registerVersion(name, version);
}

registerFirestore((firebase as unknown) as FirebaseNamespace);
registerBundle(Firestore);
15 changes: 15 additions & 0 deletions packages/firestore/compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@firebase/firestore-compat",
"version": "0.0.900",
"description": "The Cloud Firestore component of the Firebase JS SDK.",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "../dist/compat/node-cjs/index.js",
"main-esm2017": "../dist/compat/node-esm2017/index.js",
"react-native": "../dist/compat/rn/index.js",
"browser": "../dist/compat/esm5/index.js",
"module": "../dist/compat/esm5/index.js",
"esm2017": "../dist/compat/esm2017/index.js",
"license": "Apache-2.0",
"typings": "../dist/compat/esm5/packages/firestore/compat/index.d.ts"
}

11 changes: 7 additions & 4 deletions packages/firestore/exp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export {
terminate,
useFirestoreEmulator,
loadBundle,
namedQuery
namedQuery,
ensureFirestoreConfigured
} from '../src/exp/database';

export {
Expand Down Expand Up @@ -87,12 +88,11 @@ export {
WhereFilterOp
} from '../src/exp/query';

export { Unsubscribe } from '../src/exp/reference_impl';
export { Unsubscribe, SnapshotListenOptions } from '../src/exp/reference_impl';

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

export {
SnapshotListenOptions,
getDoc,
getDocFromCache,
getDocFromServer,
Expand All @@ -104,7 +104,8 @@ export {
setDoc,
updateDoc,
deleteDoc,
addDoc
addDoc,
executeWrite
} from '../src/exp/reference_impl';

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

export { FirestoreErrorCode, FirestoreError } from '../src/util/error';

export { AbstractUserDataWriter } from '../src/lite/user_data_writer';
4 changes: 2 additions & 2 deletions packages/firestore/externs.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"packages/app-types/private.d.ts",
"packages-exp/app-exp/dist/app-exp.d.ts",
"packages/auth-interop-types/index.d.ts",
"packages/firestore/dist/lite/index.d.ts",
"packages/firestore/dist/exp/index.d.ts",
"packages/firestore/dist/lite/internal.d.ts",
"packages/firestore/dist/exp/internal.d.ts",
"packages/firestore-types/index.d.ts",
"packages/firebase/index.d.ts",
"packages/component/dist/src/component.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"prebuild": "tsc --emitDeclarationOnly --declaration -p tsconfig.json; yarn api-report",
"build": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js' build:lite build:exp",
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
"prebuild:release": "yarn prebuild",
"build:release": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js'",
"build:deps": "lerna run --scope @firebase/firestore --include-dependencies build",
"build:compat": "run-p 'bundle ./rollup.config.browser.compat.js' 'bundle ./rollup.config.node.compat.js' 'bundle ./rollup.config.rn.compat.js'",
"build:console": "node tools/console.build.js",
"build:exp": "rollup -c rollup.config.exp.js",
"build:lite": "rollup -c rollup.config.lite.js",
"build:exp:release": "yarn build:exp && yarn build:lite",
"build:exp:release": "yarn build:exp && yarn build:lite && yarn build:compat",
"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",
"build:browser": "rollup -c rollup.config.browser.js",
"predev": "yarn prebuild",
Expand Down Expand Up @@ -104,7 +104,7 @@
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/index.d.ts",
"typings": "dist/firestore/index.d.ts",
"nyc": {
"extension": [
".ts"
Expand Down
Loading