Skip to content

chore: Declared admin and admin.app namespaces #1037

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 3 commits into from
Sep 23, 2020
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Copy generated d.ts files to the build directory.
* Re-enable the `npm run build:tests` in CI.
* Update return types in the methods of `FirebaseNamespace` class.

# Firebase Admin Node.js SDK

Expand Down
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ gulp.task('compile', function() {
const configuration = [
'lib/**/*.js',
'lib/credential/index.d.ts',
'lib/firebase-namespace-api.d.ts',
];

workflow = workflow.pipe(filter(configuration));
Expand Down
8 changes: 1 addition & 7 deletions src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ import { FirebaseApp } from '../firebase-app';
import { ServerValue as sv } from '@firebase/database';
import * as adminDb from './database';
import * as firebaseDbTypesApi from '@firebase/database-types';
import * as firebaseAdmin from '../index';

export function database(app?: FirebaseApp): adminDb.Database {
if (typeof(app) === 'undefined') {
app = firebaseAdmin.app();
}
return app.database();
}
export declare function database(app?: FirebaseApp): adminDb.Database;

/**
* We must define a namespace to make the typings work correctly. Otherwise
Expand Down
59 changes: 21 additions & 38 deletions src/firebase-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { AppOptions, app } from './firebase-namespace-api';
import { credential, GoogleOAuthAccessToken } from './credential/index';
import { getApplicationDefault } from './credential/credential-internal';
import * as validator from './utils/validator';
Expand All @@ -31,33 +32,17 @@ import { DatabaseService } from './database/database-internal';
import { Firestore } from '@google-cloud/firestore';
import { FirestoreService } from './firestore/firestore-internal';
import { InstanceId } from './instance-id/instance-id';

import { ProjectManagement } from './project-management/project-management';
import { SecurityRules } from './security-rules/security-rules';
import { RemoteConfig } from './remote-config/remote-config';

import { Agent } from 'http';

import Credential = credential.Credential;

/**
* Type representing a callback which is called every time an app lifecycle event occurs.
*/
export type AppHook = (event: string, app: FirebaseApp) => void;

/**
* Type representing the options object passed into initializeApp().
*/
export interface FirebaseAppOptions {
credential?: Credential;
databaseAuthVariableOverride?: object | null;
databaseURL?: string;
serviceAccountId?: string;
storageBucket?: string;
projectId?: string;
httpAgent?: Agent;
}

/**
* Type representing a Firebase OAuth access token (derived from a Google OAuth2 access token) which
* can be used to authenticate to Firebase services such as the Realtime Database and Auth.
Expand Down Expand Up @@ -243,22 +228,20 @@ export class FirebaseAppInternals {
}
}



/**
* Global context object for a collection of services using a shared authentication state.
*/
export class FirebaseApp {
export class FirebaseApp implements app.App {
public INTERNAL: FirebaseAppInternals;

private name_: string;
private options_: FirebaseAppOptions;
private options_: AppOptions;
private services_: {[name: string]: FirebaseServiceInterface} = {};
private isDeleted_ = false;

constructor(options: FirebaseAppOptions, name: string, private firebaseInternals_: FirebaseNamespaceInternals) {
constructor(options: AppOptions, name: string, private firebaseInternals_: FirebaseNamespaceInternals) {
this.name_ = name;
this.options_ = deepCopy(options) as FirebaseAppOptions;
this.options_ = deepCopy(options);

if (!validator.isNonNullObject(this.options_)) {
throw new FirebaseAppError(
Expand Down Expand Up @@ -294,7 +277,7 @@ export class FirebaseApp {
/**
* Returns the Auth service instance associated with this app.
*
* @return {Auth} The Auth service instance of this app.
* @return The Auth service instance of this app.
*/
public auth(): Auth {
return this.ensureService_('auth', () => {
Expand All @@ -306,7 +289,7 @@ export class FirebaseApp {
/**
* Returns the Database service for the specified URL, and the current app.
*
* @return {Database} The Database service instance of this app.
* @return The Database service instance of this app.
*/
public database(url?: string): Database {
const service: DatabaseService = this.ensureService_('database', () => {
Expand All @@ -319,7 +302,7 @@ export class FirebaseApp {
/**
* Returns the Messaging service instance associated with this app.
*
* @return {Messaging} The Messaging service instance of this app.
* @return The Messaging service instance of this app.
*/
public messaging(): Messaging {
return this.ensureService_('messaging', () => {
Expand All @@ -331,7 +314,7 @@ export class FirebaseApp {
/**
* Returns the Storage service instance associated with this app.
*
* @return {Storage} The Storage service instance of this app.
* @return The Storage service instance of this app.
*/
public storage(): Storage {
return this.ensureService_('storage', () => {
Expand All @@ -351,7 +334,7 @@ export class FirebaseApp {
/**
* Returns the InstanceId service instance associated with this app.
*
* @return {InstanceId} The InstanceId service instance of this app.
* @return The InstanceId service instance of this app.
*/
public instanceId(): InstanceId {
return this.ensureService_('iid', () => {
Expand All @@ -363,7 +346,7 @@ export class FirebaseApp {
/**
* Returns the MachineLearning service instance associated with this app.
*
* @return {MachineLearning} The Machine Learning service instance of this app
* @return The Machine Learning service instance of this app
*/
public machineLearning(): MachineLearning {
return this.ensureService_('machine-learning', () => {
Expand All @@ -376,7 +359,7 @@ export class FirebaseApp {
/**
* Returns the ProjectManagement service instance associated with this app.
*
* @return {ProjectManagement} The ProjectManagement service instance of this app.
* @return The ProjectManagement service instance of this app.
*/
public projectManagement(): ProjectManagement {
return this.ensureService_('project-management', () => {
Expand All @@ -389,7 +372,7 @@ export class FirebaseApp {
/**
* Returns the SecurityRules service instance associated with this app.
*
* @return {SecurityRules} The SecurityRules service instance of this app.
* @return The SecurityRules service instance of this app.
*/
public securityRules(): SecurityRules {
return this.ensureService_('security-rules', () => {
Expand All @@ -402,7 +385,7 @@ export class FirebaseApp {
/**
* Returns the RemoteConfig service instance associated with this app.
*
* @return {RemoteConfig} The RemoteConfig service instance of this app.
* @return The RemoteConfig service instance of this app.
*/
public remoteConfig(): RemoteConfig {
return this.ensureService_('remoteConfig', () => {
Expand All @@ -414,7 +397,7 @@ export class FirebaseApp {
/**
* Returns the name of the FirebaseApp instance.
*
* @return {string} The name of the FirebaseApp instance.
* @return The name of the FirebaseApp instance.
*/
get name(): string {
this.checkDestroyed_();
Expand All @@ -424,17 +407,17 @@ export class FirebaseApp {
/**
* Returns the options for the FirebaseApp instance.
*
* @return {FirebaseAppOptions} The options for the FirebaseApp instance.
* @return The options for the FirebaseApp instance.
*/
get options(): FirebaseAppOptions {
get options(): AppOptions {
this.checkDestroyed_();
return deepCopy(this.options_) as FirebaseAppOptions;
return deepCopy(this.options_);
}

/**
* Deletes the FirebaseApp instance.
*
* @return {Promise<void>} An empty Promise fulfilled once the FirebaseApp instance is deleted.
* @return An empty Promise fulfilled once the FirebaseApp instance is deleted.
*/
public delete(): Promise<void> {
this.checkDestroyed_();
Expand Down Expand Up @@ -467,8 +450,8 @@ export class FirebaseApp {
* Returns the service instance associated with this FirebaseApp instance (creating it on demand
* if needed). This is used for looking up monkeypatched service instances.
*
* @param {string} serviceName The name of the service instance to return.
* @return {FirebaseServiceInterface} The service instance with the provided name.
* @param serviceName The name of the service instance to return.
* @return The service instance with the provided name.
*/
private getService_(serviceName: string): FirebaseServiceInterface {
this.checkDestroyed_();
Expand Down
Loading