-
Notifications
You must be signed in to change notification settings - Fork 946
FirebaseApp modularization #2709
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b133298
initial firebaseapp next implementation
Feiyang1 11c3a1f
add destroyed check to FirebaseAppNext
Feiyang1 526f0ad
create the compat layer
Feiyang1 a228250
[AUTOMATED]: Prettier Code Styling
Feiyang1 98e1377
[AUTOMATED]: License Headers
Feiyang1 d9c9e1c
create a compat layer for the lite impl
Feiyang1 b38aa3b
create a build pipeline for the modular APIs
Feiyang1 74bed6a
add tests for the new API
Feiyang1 4b9f25e
format
Feiyang1 4fdc2db
[AUTOMATED]: License Headers
Feiyang1 4d9e9b0
move next types to @firebase/app-types/next
Feiyang1 1e5f50b
remove unused script
Feiyang1 d313697
fix some tests
Feiyang1 d22d2f4
address comments
Feiyang1 dbd9a72
get provider given an app
Feiyang1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ComponentContainer } from '@firebase/component'; | ||
|
||
export interface FirebaseAppNext { | ||
/** | ||
* The (read-only) name (identifier) for this App. '[DEFAULT]' is the default | ||
* App. | ||
*/ | ||
readonly name: string; | ||
|
||
/** | ||
* The (read-only) configuration options from the app initialization. | ||
*/ | ||
readonly options: FirebaseOptionsNext; | ||
|
||
/** | ||
* The settable config flag for GDPR opt-in/opt-out | ||
*/ | ||
automaticDataCollectionEnabled: boolean; | ||
} | ||
|
||
export interface FirebaseAppInternalNext extends FirebaseAppNext { | ||
container: ComponentContainer; | ||
isDeleted: boolean; | ||
checkDestroyed(): void; | ||
} | ||
|
||
export interface FirebaseOptionsNext { | ||
apiKey?: string; | ||
authDomain?: string; | ||
databaseURL?: string; | ||
projectId?: string; | ||
storageBucket?: string; | ||
messagingSenderId?: string; | ||
appId?: string; | ||
measurementId?: string; | ||
} | ||
|
||
export interface FirebaseAppConfigNext { | ||
name?: string; | ||
automaticDataCollectionEnabled?: boolean; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@firebase/app/next/internal", | ||
"main": "../../dist/cjs/next/internal.js", | ||
"browser": "../../dist/cjs/next/internal.js", | ||
"module": "../../dist/esm5/next/internal.js", | ||
"esm2017": "../../dist/esm2017/next/internal.js", | ||
"typings": "../../dist/packages/app/src/next/internal.d.ts" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@firebase/app/next", | ||
"main": "../dist/cjs/next.js", | ||
"browser": "../dist/cjs/next.js", | ||
"module": "../dist/esm5/next.js", | ||
"esm2017": "../dist/esm2017/next.js", | ||
"typings": "../dist/packages/app/src/next/index.d.ts" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,10 @@ | |
"description": "The primary entrypoint to the Firebase JS SDK", | ||
"author": "Firebase <[email protected]> (https://firebase.google.com/)", | ||
"main": "dist/index.node.cjs.js", | ||
"browser": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"browser": "dist/cjs/index.js", | ||
"module": "dist/esm5/index.js", | ||
"react-native": "dist/index.rn.cjs.js", | ||
"esm2017": "dist/index.esm2017.js", | ||
"esm2017": "dist/esm2017/index.js", | ||
"lite": "dist/index.lite.js", | ||
"lite-esm2017": "dist/index.lite.esm2017.js", | ||
"files": [ | ||
|
@@ -22,7 +22,7 @@ | |
"type-check": "tsc -p . --noEmit", | ||
"test:browser": "karma start --single-run", | ||
"test:browser:debug": "karma start --browsers Chrome --auto-watch", | ||
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* --opts ../../config/mocha.node.opts", | ||
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* src/**/*.test.ts --opts ../../config/mocha.node.opts", | ||
"prepare": "yarn build" | ||
}, | ||
"license": "Apache-2.0", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/** | ||
* @license | ||
* Copyright 2017 Google Inc. | ||
* | ||
* 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 { FirebaseApp, FirebaseOptions } from '@firebase/app-types'; | ||
import { | ||
_FirebaseApp, | ||
_FirebaseNamespace, | ||
FirebaseService | ||
} from '@firebase/app-types/private'; | ||
import { Component, ComponentType, Name, ComponentContainer } from '@firebase/component'; | ||
import { DEFAULT_ENTRY_NAME } from '../constants'; | ||
import { FirebaseAppInternalNext } from '@firebase/app-types/next'; | ||
import { deleteApp } from '../next'; | ||
import { addComponent, addOrOverwriteComponent } from '../next/internal'; | ||
|
||
/** | ||
* Global context object for a collection of services using | ||
* a shared authentication state. | ||
*/ | ||
export class FirebaseAppImpl implements FirebaseApp { | ||
private readonly container: ComponentContainer; | ||
|
||
constructor( | ||
private readonly app: FirebaseAppInternalNext, | ||
private readonly firebase: _FirebaseNamespace | ||
) { | ||
// add itself to container | ||
addComponent(app, new Component('app', () => this, ComponentType.PUBLIC)); | ||
this.container = app.container; | ||
} | ||
|
||
get automaticDataCollectionEnabled(): boolean { | ||
return this.app.automaticDataCollectionEnabled; | ||
} | ||
|
||
set automaticDataCollectionEnabled(val) { | ||
this.app.automaticDataCollectionEnabled = val; | ||
} | ||
|
||
get name(): string { | ||
return this.app.name; | ||
} | ||
|
||
get options(): FirebaseOptions { | ||
return this.app.options; | ||
} | ||
|
||
delete(): Promise<void> { | ||
return new Promise(resolve => { | ||
this.app.checkDestroyed(); | ||
resolve(); | ||
}).then(() => { | ||
this.firebase.INTERNAL.removeApp(this.name); | ||
return deleteApp(this.app); | ||
}); | ||
} | ||
|
||
/** | ||
* Return a service instance associated with this app (creating it | ||
* on demand), identified by the passed instanceIdentifier. | ||
* | ||
* NOTE: Currently storage and functions are the only ones that are leveraging this | ||
* functionality. They invoke it by calling: | ||
* | ||
* ```javascript | ||
* firebase.app().storage('STORAGE BUCKET ID') | ||
* ``` | ||
* | ||
* The service name is passed to this already | ||
* @internal | ||
*/ | ||
_getService( | ||
name: string, | ||
instanceIdentifier: string = DEFAULT_ENTRY_NAME | ||
): FirebaseService { | ||
this.app.checkDestroyed(); | ||
|
||
// getImmediate will always succeed because _getService is only called for registered components. | ||
return (this.app.container.getProvider(name as Name).getImmediate({ | ||
identifier: instanceIdentifier | ||
}) as unknown) as FirebaseService; | ||
} | ||
|
||
/** | ||
* Remove a service instance from the cache, so we will create a new instance for this service | ||
* when people try to get it again. | ||
* | ||
* NOTE: currently only firestore uses this functionality to support firestore shutdown. | ||
* | ||
* @param name The service name | ||
* @param instanceIdentifier instance identifier in case multiple instances are allowed | ||
* @internal | ||
*/ | ||
_removeServiceInstance( | ||
name: string, | ||
instanceIdentifier: string = DEFAULT_ENTRY_NAME | ||
): void { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this.app.container.getProvider(name as any) | ||
.clearInstance(instanceIdentifier); | ||
} | ||
|
||
/** | ||
* @param component the component being added to this app's container | ||
* @internal | ||
*/ | ||
_addComponent(component: Component): void { | ||
addComponent(this.app, component); | ||
} | ||
|
||
_addOrOverwriteComponent(component: Component): void { | ||
addOrOverwriteComponent(this.app, component); | ||
} | ||
} | ||
|
||
// TODO: investigate why the following needs to be commented out | ||
// Prevent dead-code elimination of these methods w/o invalid property | ||
// copying. | ||
// (FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options) || | ||
// FirebaseAppImpl.prototype.delete || | ||
// console.log('dc'); |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.