Skip to content

feat: Added firebase-admin/app submodule #1134

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 4 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
*
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
*/
// We point to the firebase-namespace.d.ts file since index.d.ts uses namespace imports that are
// We point to the default-namespace.d.ts file since index.d.ts uses namespace imports that are
// not supported by API Extractor. See https://github.com/microsoft/rushstack/issues/1029 and
// https://github.com/microsoft/rushstack/issues/2338.
"mainEntryPointFilePath": "<projectFolder>/lib/firebase-namespace.d.ts",
"mainEntryPointFilePath": "<projectFolder>/lib/default-namespace.d.ts",

/**
* A list of NPM package names whose exports should be treated as part of this package.
Expand Down
11 changes: 10 additions & 1 deletion etc/firebase-admin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as rtdb from '@firebase/database-types';

// @public (undocumented)
export interface App {
delete(): Promise<void>;
name: string;
options: AppOptions;
}
Expand All @@ -26,6 +25,7 @@ export namespace app {
auth(): auth.Auth;
// (undocumented)
database(url?: string): database.Database;
delete(): Promise<void>;
// (undocumented)
firestore(): firestore.Firestore;
// (undocumented)
Expand Down Expand Up @@ -427,6 +427,9 @@ export namespace database {
const ServerValue: rtdb.ServerValue;
}

// @public (undocumented)
export function deleteApp(app: App): Promise<void>;

// @public
export interface FirebaseArrayIndexError {
error: FirebaseError;
Expand Down Expand Up @@ -477,6 +480,12 @@ export namespace firestore {
import setLogFunction = _firestore.setLogFunction;
}

// @public (undocumented)
export function getApp(name?: string): App;

// @public (undocumented)
export function getApps(): App[];

// @public
export interface GoogleOAuthAccessToken {
// (undocumented)
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ gulp.task('compile', function() {
'lib/**/index.d.ts',
'lib/firebase-namespace-api.d.ts',
'lib/core.d.ts',
'lib/app/*.d.ts',
'!lib/utils/index.d.ts',
];

Expand All @@ -107,7 +108,7 @@ gulp.task('compile_test', function() {
});

gulp.task('copyTypings', function() {
return gulp.src(['src/index.d.ts', 'src/firebase-namespace.d.ts'])
return gulp.src(['src/index.d.ts', 'src/default-namespace.d.ts'])
// Add header
.pipe(header(banner))
.pipe(gulp.dest(paths.build))
Expand Down
21 changes: 1 addition & 20 deletions src/core.ts → src/app/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Agent } from 'http';

import { credential } from './credential/index';
import { credential } from '../credential/index';

/**
* Available options to pass to [`initializeApp()`](admin#.initializeApp).
Expand Down Expand Up @@ -121,23 +121,4 @@ export interface App {
* ```
*/
options: AppOptions;

/**
* Renders this local `FirebaseApp` unusable and frees the resources of
* all associated services (though it does *not* clean up any backend
* resources). When running the SDK locally, this method
* must be called to ensure graceful termination of the process.
*
* @example
* ```javascript
* app.delete()
* .then(function() {
* console.log("App deleted successfully");
* })
* .catch(function(error) {
* console.log("Error deleting app:", error);
* });
* ```
*/
delete(): Promise<void>;
}
56 changes: 28 additions & 28 deletions src/firebase-app.ts → src/app/firebase-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
* 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';
import { deepCopy } from './utils/deep-copy';
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';
import { deepCopy } from '../utils/deep-copy';
import { FirebaseNamespaceInternals } from './firebase-namespace';
import { AppErrorCodes, FirebaseAppError } from './utils/error';

import { Auth } from './auth/auth';
import { MachineLearning } from './machine-learning/machine-learning';
import { Messaging } from './messaging/messaging';
import { Storage } from './storage/storage';
import { database } from './database/index';
import { DatabaseService } from './database/database-internal';
import { AppErrorCodes, FirebaseAppError } from '../utils/error';

import { Auth } from '../auth/auth';
import { MachineLearning } from '../machine-learning/machine-learning';
import { Messaging } from '../messaging/messaging';
import { Storage } from '../storage/storage';
import { database } from '../database/index';
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 { 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 Credential = credential.Credential;
import Database = database.Database;
Expand Down Expand Up @@ -277,7 +277,7 @@ export class FirebaseApp implements app.App {
*/
public auth(): Auth {
return this.ensureService_('auth', () => {
const authService: typeof Auth = require('./auth/auth').Auth;
const authService: typeof Auth = require('../auth/auth').Auth;
return new authService(this);
});
}
Expand All @@ -289,7 +289,7 @@ export class FirebaseApp implements app.App {
*/
public database(url?: string): Database {
const service: DatabaseService = this.ensureService_('database', () => {
const dbService: typeof DatabaseService = require('./database/database-internal').DatabaseService;
const dbService: typeof DatabaseService = require('../database/database-internal').DatabaseService;
return new dbService(this);
});
return service.getDatabase(url);
Expand All @@ -302,7 +302,7 @@ export class FirebaseApp implements app.App {
*/
public messaging(): Messaging {
return this.ensureService_('messaging', () => {
const messagingService: typeof Messaging = require('./messaging/messaging').Messaging;
const messagingService: typeof Messaging = require('../messaging/messaging').Messaging;
return new messagingService(this);
});
}
Expand All @@ -314,14 +314,14 @@ export class FirebaseApp implements app.App {
*/
public storage(): Storage {
return this.ensureService_('storage', () => {
const storageService: typeof Storage = require('./storage/storage').Storage;
const storageService: typeof Storage = require('../storage/storage').Storage;
return new storageService(this);
});
}

public firestore(): Firestore {
const service: FirestoreService = this.ensureService_('firestore', () => {
const firestoreService: typeof FirestoreService = require('./firestore/firestore-internal').FirestoreService;
const firestoreService: typeof FirestoreService = require('../firestore/firestore-internal').FirestoreService;
return new firestoreService(this);
});
return service.client;
Expand All @@ -334,7 +334,7 @@ export class FirebaseApp implements app.App {
*/
public instanceId(): InstanceId {
return this.ensureService_('iid', () => {
const iidService: typeof InstanceId = require('./instance-id/instance-id').InstanceId;
const iidService: typeof InstanceId = require('../instance-id/instance-id').InstanceId;
return new iidService(this);
});
}
Expand All @@ -347,7 +347,7 @@ export class FirebaseApp implements app.App {
public machineLearning(): MachineLearning {
return this.ensureService_('machine-learning', () => {
const machineLearningService: typeof MachineLearning =
require('./machine-learning/machine-learning').MachineLearning;
require('../machine-learning/machine-learning').MachineLearning;
return new machineLearningService(this);
});
}
Expand All @@ -360,7 +360,7 @@ export class FirebaseApp implements app.App {
public projectManagement(): ProjectManagement {
return this.ensureService_('project-management', () => {
const projectManagementService: typeof ProjectManagement =
require('./project-management/project-management').ProjectManagement;
require('../project-management/project-management').ProjectManagement;
return new projectManagementService(this);
});
}
Expand All @@ -373,7 +373,7 @@ export class FirebaseApp implements app.App {
public securityRules(): SecurityRules {
return this.ensureService_('security-rules', () => {
const securityRulesService: typeof SecurityRules =
require('./security-rules/security-rules').SecurityRules;
require('../security-rules/security-rules').SecurityRules;
return new securityRulesService(this);
});
}
Expand All @@ -385,7 +385,7 @@ export class FirebaseApp implements app.App {
*/
public remoteConfig(): RemoteConfig {
return this.ensureService_('remoteConfig', () => {
const remoteConfigService: typeof RemoteConfig = require('./remote-config/remote-config').RemoteConfig;
const remoteConfigService: typeof RemoteConfig = require('../remote-config/remote-config').RemoteConfig;
return new remoteConfigService(this);
});
}
Expand Down
52 changes: 26 additions & 26 deletions src/firebase-namespace.ts → src/app/firebase-namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@

import fs = require('fs');

import { AppErrorCodes, FirebaseAppError } from './utils/error';
import { AppOptions, app } from './firebase-namespace-api';
import { AppErrorCodes, FirebaseAppError } from '../utils/error';
import { AppOptions, app } from '../firebase-namespace-api';
import { FirebaseApp } from './firebase-app';
import { cert, refreshToken, applicationDefault } from './credential/credential';
import { getApplicationDefault } from './credential/credential-internal';

import { auth } from './auth/index';
import { database } from './database/index';
import { firestore } from './firestore/index';
import { instanceId } from './instance-id/index';
import { machineLearning } from './machine-learning/index';
import { messaging } from './messaging/index';
import { projectManagement } from './project-management/index';
import { remoteConfig } from './remote-config/index';
import { securityRules } from './security-rules/index';
import { storage } from './storage/index';

import * as validator from './utils/validator';
import { getSdkVersion } from './utils/index';
import { cert, refreshToken, applicationDefault } from '../credential/credential';
import { getApplicationDefault } from '../credential/credential-internal';

import { auth } from '../auth/index';
import { database } from '../database/index';
import { firestore } from '../firestore/index';
import { instanceId } from '../instance-id/index';
import { machineLearning } from '../machine-learning/index';
import { messaging } from '../messaging/index';
import { projectManagement } from '../project-management/index';
import { remoteConfig } from '../remote-config/index';
import { securityRules } from '../security-rules/index';
import { storage } from '../storage/index';

import * as validator from '../utils/validator';
import { getSdkVersion } from '../utils/index';

import App = app.App;
import Auth = auth.Auth;
Expand Down Expand Up @@ -223,7 +223,7 @@ export class FirebaseNamespace {
const fn: FirebaseServiceNamespace<Auth> = (app?: App) => {
return this.ensureApp(app).auth();
};
const auth = require('./auth/auth').Auth;
const auth = require('../auth/auth').Auth;
return Object.assign(fn, { Auth: auth });
}

Expand All @@ -248,7 +248,7 @@ export class FirebaseNamespace {
const fn: FirebaseServiceNamespace<Messaging> = (app?: App) => {
return this.ensureApp(app).messaging();
};
const messaging = require('./messaging/messaging').Messaging;
const messaging = require('../messaging/messaging').Messaging;
return Object.assign(fn, { Messaging: messaging });
}

Expand All @@ -260,7 +260,7 @@ export class FirebaseNamespace {
const fn: FirebaseServiceNamespace<Storage> = (app?: App) => {
return this.ensureApp(app).storage();
};
const storage = require('./storage/storage').Storage;
const storage = require('../storage/storage').Storage;
return Object.assign(fn, { Storage: storage });
}

Expand Down Expand Up @@ -305,7 +305,7 @@ export class FirebaseNamespace {
return this.ensureApp(app).machineLearning();
};
const machineLearning =
require('./machine-learning/machine-learning').MachineLearning;
require('../machine-learning/machine-learning').MachineLearning;
return Object.assign(fn, { MachineLearning: machineLearning });
}

Expand All @@ -317,7 +317,7 @@ export class FirebaseNamespace {
const fn: FirebaseServiceNamespace<InstanceId> = (app?: App) => {
return this.ensureApp(app).instanceId();
};
const instanceId = require('./instance-id/instance-id').InstanceId;
const instanceId = require('../instance-id/instance-id').InstanceId;
return Object.assign(fn, { InstanceId: instanceId });
}

Expand All @@ -329,7 +329,7 @@ export class FirebaseNamespace {
const fn: FirebaseServiceNamespace<ProjectManagement> = (app?: App) => {
return this.ensureApp(app).projectManagement();
};
const projectManagement = require('./project-management/project-management').ProjectManagement;
const projectManagement = require('../project-management/project-management').ProjectManagement;
return Object.assign(fn, { ProjectManagement: projectManagement });
}

Expand All @@ -341,7 +341,7 @@ export class FirebaseNamespace {
const fn: FirebaseServiceNamespace<SecurityRules> = (app?: App) => {
return this.ensureApp(app).securityRules();
};
const securityRules = require('./security-rules/security-rules').SecurityRules;
const securityRules = require('../security-rules/security-rules').SecurityRules;
return Object.assign(fn, { SecurityRules: securityRules });
}

Expand All @@ -353,7 +353,7 @@ export class FirebaseNamespace {
const fn: FirebaseServiceNamespace<RemoteConfig> = (app?: App) => {
return this.ensureApp(app).remoteConfig();
};
const remoteConfig = require('./remote-config/remote-config').RemoteConfig;
const remoteConfig = require('../remote-config/remote-config').RemoteConfig;
return Object.assign(fn, { RemoteConfig: remoteConfig });
}

Expand Down
22 changes: 22 additions & 0 deletions src/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
* Copyright 2021 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 { getSdkVersion } from '../utils';

export { App, AppOptions } from './core'
export { initializeApp, getApp, getApps, deleteApp } from './lifecycle';

export const SDK_VERSION = getSdkVersion();
Loading