Skip to content

Commit 875d865

Browse files
authored
Allow RemoteConfig to auto-generate typings, separate internal vs external APIs (#984)
1 parent 24ac03f commit 875d865

File tree

8 files changed

+738
-498
lines changed

8 files changed

+738
-498
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var paths = {
5757
'!src/instance-id.d.ts',
5858
'!src/security-rules.d.ts',
5959
'!src/project-management.d.ts',
60+
'!src/remote-config.d.ts',
6061
'!src/messaging.d.ts',
6162
],
6263
};
@@ -70,7 +71,6 @@ const TEMPORARY_TYPING_EXCLUDES = [
7071
'!lib/database/*.d.ts',
7172
'!lib/firestore/*.d.ts',
7273
'!lib/machine-learning/*.d.ts',
73-
'!lib/remote-config/*.d.ts',
7474
'!lib/storage/*.d.ts',
7575
'!lib/utils/*.d.ts',
7676
];

src/remote-config/index.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*!
2+
* Copyright 2020 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 { FirebaseApp } from '../firebase-app';
18+
import * as remoteConfigApi from './remote-config';
19+
import * as remoteConfigClientApi from './remote-config-api-client';
20+
import * as firebaseAdmin from '../index';
21+
22+
export function remoteConfig(app?: FirebaseApp): remoteConfigApi.RemoteConfig {
23+
if (typeof(app) === 'undefined') {
24+
app = firebaseAdmin.app();
25+
}
26+
return app.remoteConfig();
27+
}
28+
29+
/**
30+
* We must define a namespace to make the typings work correctly. Otherwise
31+
* `admin.remoteConfig()` cannot be called like a function. Temporarily,
32+
* admin.remoteConfig is used as the namespace name because we cannot barrel
33+
* re-export the contents from remote-config, and we want it to
34+
* match the namespacing in the re-export inside src/index.d.ts
35+
*/
36+
/* eslint-disable @typescript-eslint/no-namespace */
37+
export namespace admin.remoteConfig {
38+
// See https://github.com/microsoft/TypeScript/issues/4336
39+
/* eslint-disable @typescript-eslint/no-unused-vars */
40+
// See https://github.com/typescript-eslint/typescript-eslint/issues/363
41+
export import ExplicitParameterValue = remoteConfigClientApi.ExplicitParameterValue;
42+
export import ListVersionsOptions = remoteConfigClientApi.ListVersionsOptions;
43+
export import ListVersionsResult = remoteConfigClientApi.ListVersionsResult;
44+
export import InAppDefaultValue = remoteConfigClientApi.InAppDefaultValue;
45+
export import RemoteConfigCondition = remoteConfigClientApi.RemoteConfigCondition;
46+
export import RemoteConfigParameter = remoteConfigClientApi.RemoteConfigParameter;
47+
export import RemoteConfigParameterGroup = remoteConfigClientApi.RemoteConfigParameterGroup;
48+
export import RemoteConfigParameterValue = remoteConfigClientApi.RemoteConfigParameterValue;
49+
export import RemoteConfigTemplate = remoteConfigClientApi.RemoteConfigTemplate;
50+
export import RemoteConfigUser = remoteConfigClientApi.RemoteConfigUser;
51+
export import TagColor = remoteConfigClientApi.TagColor;
52+
export import Version = remoteConfigClientApi.Version;
53+
54+
// Allows for exposing classes as interfaces in typings
55+
/* eslint-disable @typescript-eslint/no-empty-interface */
56+
export interface RemoteConfig extends remoteConfigApi.RemoteConfig {}
57+
}

0 commit comments

Comments
 (0)