Skip to content

Commit 72bf15a

Browse files
authored
fix: Added lightweight App interface (#1132)
* fix: Added lightweight App interface * fix: Updated API report * fix: Consolidated export statements
1 parent 2f6da89 commit 72bf15a

File tree

5 files changed

+158
-129
lines changed

5 files changed

+158
-129
lines changed

docgen/generate-docs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const repoPath = path.resolve(`${__dirname}/..`);
2828
const defaultSources = [
2929
`${repoPath}/lib/firebase-namespace.d.ts`,
3030
`${repoPath}/lib/firebase-namespace-api.d.ts`,
31+
`${repoPath}/lib/core.d.ts`,
3132
`${repoPath}/lib/**/*.d.ts`,
3233
];
3334

etc/firebase-admin.api.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ import { Bucket } from '@google-cloud/storage';
99
import * as _firestore from '@google-cloud/firestore';
1010
import * as rtdb from '@firebase/database-types';
1111

12+
// @public (undocumented)
13+
export interface App {
14+
delete(): Promise<void>;
15+
name: string;
16+
options: AppOptions;
17+
}
18+
1219
// @public (undocumented)
1320
export function app(name?: string): app.App;
1421

1522
// @public (undocumented)
1623
export namespace app {
17-
export interface App {
24+
export interface App extends App {
1825
// (undocumented)
1926
auth(): auth.Auth;
2027
// (undocumented)
2128
database(url?: string): database.Database;
22-
delete(): Promise<void>;
2329
// (undocumented)
2430
firestore(): firestore.Firestore;
2531
// (undocumented)
@@ -28,8 +34,6 @@ export namespace app {
2834
machineLearning(): machineLearning.MachineLearning;
2935
// (undocumented)
3036
messaging(): messaging.Messaging;
31-
name: string;
32-
options: AppOptions;
3337
// (undocumented)
3438
projectManagement(): projectManagement.ProjectManagement;
3539
// (undocumented)

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ gulp.task('compile', function() {
8686
'lib/**/*.js',
8787
'lib/**/index.d.ts',
8888
'lib/firebase-namespace-api.d.ts',
89+
'lib/core.d.ts',
8990
'!lib/utils/index.d.ts',
9091
];
9192

src/core.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*!
2+
* Copyright 2021 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { Agent } from 'http';
18+
19+
import { credential } from './credential/index';
20+
21+
/**
22+
* Available options to pass to [`initializeApp()`](admin#.initializeApp).
23+
*/
24+
export interface AppOptions {
25+
26+
/**
27+
* A {@link credential.Credential `Credential`} object used to
28+
* authenticate the Admin SDK.
29+
*
30+
* See [Initialize the SDK](/docs/admin/setup#initialize_the_sdk) for detailed
31+
* documentation and code samples.
32+
*/
33+
credential?: credential.Credential;
34+
35+
/**
36+
* The object to use as the [`auth`](/docs/reference/security/database/#auth)
37+
* variable in your Realtime Database Rules when the Admin SDK reads from or
38+
* writes to the Realtime Database. This allows you to downscope the Admin SDK
39+
* from its default full read and write privileges.
40+
*
41+
* You can pass `null` to act as an unauthenticated client.
42+
*
43+
* See
44+
* [Authenticate with limited privileges](/docs/database/admin/start#authenticate-with-limited-privileges)
45+
* for detailed documentation and code samples.
46+
*/
47+
databaseAuthVariableOverride?: object | null;
48+
49+
/**
50+
* The URL of the Realtime Database from which to read and write data.
51+
*/
52+
databaseURL?: string;
53+
54+
/**
55+
* The ID of the service account to be used for signing custom tokens. This
56+
* can be found in the `client_email` field of a service account JSON file.
57+
*/
58+
serviceAccountId?: string;
59+
60+
/**
61+
* The name of the Google Cloud Storage bucket used for storing application data.
62+
* Use only the bucket name without any prefixes or additions (do *not* prefix
63+
* the name with "gs://").
64+
*/
65+
storageBucket?: string;
66+
67+
/**
68+
* The ID of the Google Cloud project associated with the App.
69+
*/
70+
projectId?: string;
71+
72+
/**
73+
* An [HTTP Agent](https://nodejs.org/api/http.html#http_class_http_agent)
74+
* to be used when making outgoing HTTP calls. This Agent instance is used
75+
* by all services that make REST calls (e.g. `auth`, `messaging`,
76+
* `projectManagement`).
77+
*
78+
* Realtime Database and Firestore use other means of communicating with
79+
* the backend servers, so they do not use this HTTP Agent. `Credential`
80+
* instances also do not use this HTTP Agent, but instead support
81+
* specifying an HTTP Agent in the corresponding factory methods.
82+
*/
83+
httpAgent?: Agent;
84+
}
85+
86+
export interface App {
87+
88+
/**
89+
* The (read-only) name for this app.
90+
*
91+
* The default app's name is `"[DEFAULT]"`.
92+
*
93+
* @example
94+
* ```javascript
95+
* // The default app's name is "[DEFAULT]"
96+
* admin.initializeApp(defaultAppConfig);
97+
* console.log(admin.app().name); // "[DEFAULT]"
98+
* ```
99+
*
100+
* @example
101+
* ```javascript
102+
* // A named app's name is what you provide to initializeApp()
103+
* var otherApp = admin.initializeApp(otherAppConfig, "other");
104+
* console.log(otherApp.name); // "other"
105+
* ```
106+
*/
107+
name: string;
108+
109+
/**
110+
* The (read-only) configuration options for this app. These are the original
111+
* parameters given in
112+
* {@link
113+
* https://firebase.google.com/docs/reference/admin/node/admin#.initializeApp
114+
* `admin.initializeApp()`}.
115+
*
116+
* @example
117+
* ```javascript
118+
* var app = admin.initializeApp(config);
119+
* console.log(app.options.credential === config.credential); // true
120+
* console.log(app.options.databaseURL === config.databaseURL); // true
121+
* ```
122+
*/
123+
options: AppOptions;
124+
125+
/**
126+
* Renders this local `FirebaseApp` unusable and frees the resources of
127+
* all associated services (though it does *not* clean up any backend
128+
* resources). When running the SDK locally, this method
129+
* must be called to ensure graceful termination of the process.
130+
*
131+
* @example
132+
* ```javascript
133+
* app.delete()
134+
* .then(function() {
135+
* console.log("App deleted successfully");
136+
* })
137+
* .catch(function(error) {
138+
* console.log("Error deleting app:", error);
139+
* });
140+
* ```
141+
*/
142+
delete(): Promise<void>;
143+
}

src/firebase-namespace-api.ts

Lines changed: 5 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Agent } from 'http';
1817
import { auth } from './auth/index';
19-
import { credential } from './credential/index';
2018
import { database } from './database/index';
2119
import { firestore } from './firestore/index';
2220
import { instanceId } from './instance-id/index';
@@ -27,6 +25,10 @@ import { remoteConfig } from './remote-config/index';
2725
import { securityRules } from './security-rules/index';
2826
import { storage } from './storage/index';
2927

28+
import { App as AppCore, AppOptions } from './core';
29+
30+
export * from './core';
31+
3032
/**
3133
* `FirebaseError` is a subclass of the standard JavaScript `Error` object. In
3234
* addition to a message string and stack trace, it contains a string code.
@@ -106,71 +108,6 @@ export interface FirebaseArrayIndexError {
106108
error: FirebaseError;
107109
}
108110

109-
/**
110-
* Available options to pass to [`initializeApp()`](admin#.initializeApp).
111-
*/
112-
export interface AppOptions {
113-
114-
/**
115-
* A {@link credential.Credential `Credential`} object used to
116-
* authenticate the Admin SDK.
117-
*
118-
* See [Initialize the SDK](/docs/admin/setup#initialize_the_sdk) for detailed
119-
* documentation and code samples.
120-
*/
121-
credential?: credential.Credential;
122-
123-
/**
124-
* The object to use as the [`auth`](/docs/reference/security/database/#auth)
125-
* variable in your Realtime Database Rules when the Admin SDK reads from or
126-
* writes to the Realtime Database. This allows you to downscope the Admin SDK
127-
* from its default full read and write privileges.
128-
*
129-
* You can pass `null` to act as an unauthenticated client.
130-
*
131-
* See
132-
* [Authenticate with limited privileges](/docs/database/admin/start#authenticate-with-limited-privileges)
133-
* for detailed documentation and code samples.
134-
*/
135-
databaseAuthVariableOverride?: object | null;
136-
137-
/**
138-
* The URL of the Realtime Database from which to read and write data.
139-
*/
140-
databaseURL?: string;
141-
142-
/**
143-
* The ID of the service account to be used for signing custom tokens. This
144-
* can be found in the `client_email` field of a service account JSON file.
145-
*/
146-
serviceAccountId?: string;
147-
148-
/**
149-
* The name of the Google Cloud Storage bucket used for storing application data.
150-
* Use only the bucket name without any prefixes or additions (do *not* prefix
151-
* the name with "gs://").
152-
*/
153-
storageBucket?: string;
154-
155-
/**
156-
* The ID of the Google Cloud project associated with the App.
157-
*/
158-
projectId?: string;
159-
160-
/**
161-
* An [HTTP Agent](https://nodejs.org/api/http.html#http_class_http_agent)
162-
* to be used when making outgoing HTTP calls. This Agent instance is used
163-
* by all services that make REST calls (e.g. `auth`, `messaging`,
164-
* `projectManagement`).
165-
*
166-
* Realtime Database and Firestore use other means of communicating with
167-
* the backend servers, so they do not use this HTTP Agent. `Credential`
168-
* instances also do not use this HTTP Agent, but instead support
169-
* specifying an HTTP Agent in the corresponding factory methods.
170-
*/
171-
httpAgent?: Agent;
172-
}
173-
174111
// eslint-disable-next-line @typescript-eslint/no-namespace
175112
export namespace app {
176113
/**
@@ -183,45 +120,7 @@ export namespace app {
183120
* `admin.initializeApp()`}
184121
* to create an app.
185122
*/
186-
export interface App {
187-
188-
/**
189-
* The (read-only) name for this app.
190-
*
191-
* The default app's name is `"[DEFAULT]"`.
192-
*
193-
* @example
194-
* ```javascript
195-
* // The default app's name is "[DEFAULT]"
196-
* admin.initializeApp(defaultAppConfig);
197-
* console.log(admin.app().name); // "[DEFAULT]"
198-
* ```
199-
*
200-
* @example
201-
* ```javascript
202-
* // A named app's name is what you provide to initializeApp()
203-
* var otherApp = admin.initializeApp(otherAppConfig, "other");
204-
* console.log(otherApp.name); // "other"
205-
* ```
206-
*/
207-
name: string;
208-
209-
/**
210-
* The (read-only) configuration options for this app. These are the original
211-
* parameters given in
212-
* {@link
213-
* https://firebase.google.com/docs/reference/admin/node/admin#.initializeApp
214-
* `admin.initializeApp()`}.
215-
*
216-
* @example
217-
* ```javascript
218-
* var app = admin.initializeApp(config);
219-
* console.log(app.options.credential === config.credential); // true
220-
* console.log(app.options.databaseURL === config.databaseURL); // true
221-
* ```
222-
*/
223-
options: AppOptions;
224-
123+
export interface App extends AppCore {
225124
auth(): auth.Auth;
226125
database(url?: string): database.Database;
227126
firestore(): firestore.Firestore;
@@ -232,25 +131,6 @@ export namespace app {
232131
remoteConfig(): remoteConfig.RemoteConfig;
233132
securityRules(): securityRules.SecurityRules;
234133
storage(): storage.Storage;
235-
236-
/**
237-
* Renders this local `FirebaseApp` unusable and frees the resources of
238-
* all associated services (though it does *not* clean up any backend
239-
* resources). When running the SDK locally, this method
240-
* must be called to ensure graceful termination of the process.
241-
*
242-
* @example
243-
* ```javascript
244-
* app.delete()
245-
* .then(function() {
246-
* console.log("App deleted successfully");
247-
* })
248-
* .catch(function(error) {
249-
* console.log("Error deleting app:", error);
250-
* });
251-
* ```
252-
*/
253-
delete(): Promise<void>;
254134
}
255135
}
256136

0 commit comments

Comments
 (0)