UNPKG

5.19 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * THIS FILE IS FOR INTERNAL USAGE ONLY, IF YOU ARE NOT DEVELOPING THE FIREBASE
20 * SDKs, PLEASE DO NOT REFERENCE THIS FILE AS IT MAY CHANGE WITHOUT WARNING
21 */
22
23import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
24import { Observer, Subscribe } from '@firebase/util';
25import { FirebaseError, ErrorFactory } from '@firebase/util';
26import { Component, ComponentContainer } from '@firebase/component';
27
28export interface FirebaseServiceInternals {
29 /**
30 * Delete the service and free it's resources - called from
31 * app.delete().
32 */
33 delete(): Promise<void>;
34}
35
36// Services are exposed through instances - each of which is associated with a
37// FirebaseApp.
38export interface FirebaseService {
39 app: FirebaseApp;
40 INTERNAL?: FirebaseServiceInternals;
41}
42
43export type AppHook = (event: string, app: FirebaseApp) => void;
44
45/**
46 * Firebase Services create instances given a Firebase App instance and can
47 * optionally add properties and methods to each FirebaseApp via the extendApp()
48 * function.
49 */
50export interface FirebaseServiceFactory {
51 (
52 app: FirebaseApp,
53 extendApp?: (props: { [prop: string]: any }) => void,
54 instanceString?: string
55 ): FirebaseService;
56}
57
58export interface PlatformLoggerService {
59 getPlatformInfoString(): string;
60}
61
62/**
63 * All ServiceNamespaces extend from FirebaseServiceNamespace
64 */
65export interface FirebaseServiceNamespace<T extends FirebaseService> {
66 (app?: FirebaseApp): T;
67}
68
69export interface FirebaseAuthTokenData {
70 accessToken: string;
71}
72
73export interface FirebaseAppInternals {
74 getToken(refreshToken?: boolean): Promise<FirebaseAuthTokenData | null>;
75 getUid(): string | null;
76 addAuthTokenListener(fn: (token: string | null) => void): void;
77 removeAuthTokenListener(fn: (token: string | null) => void): void;
78 analytics: {
79 logEvent: (
80 eventName: string,
81 eventParams: { [key: string]: any },
82 options?: { global: boolean }
83 ) => void;
84 };
85}
86
87export interface _FirebaseApp extends FirebaseApp {
88 container: ComponentContainer;
89 _addComponent(component: Component): void;
90 _addOrOverwriteComponent(component: Component): void;
91 _removeServiceInstance(name: string, instanceIdentifier?: string): void;
92}
93export interface _FirebaseNamespace extends FirebaseNamespace {
94 INTERNAL: {
95 /**
96 * Internal API to register a Firebase Service into the firebase namespace.
97 *
98 * Each service will create a child namespace (firebase.<name>) which acts as
99 * both a namespace for service specific properties, and also as a service
100 * accessor function (firebase.<name>() or firebase.<name>(app)).
101 *
102 * @param name The Firebase Service being registered.
103 * @param createService Factory function to create a service instance.
104 * @param serviceProperties Properties to copy to the service's namespace.
105 * @param appHook All appHooks called before initializeApp returns to caller.
106 * @param allowMultipleInstances Whether the registered service supports
107 * multiple instances per app. If not specified, the default is false.
108 */
109 registerComponent(
110 component: Component
111 ): FirebaseServiceNamespace<FirebaseService> | null;
112
113 /**
114 * Just used for testing to start from a fresh namespace.
115 */
116 createFirebaseNamespace(): FirebaseNamespace;
117
118 /**
119 * Internal API to install properties on the top-level firebase namespace.
120 * @prop props The top level properties of this object are copied to the
121 * namespace.
122 */
123 extendNamespace(props: { [prop: string]: any }): void;
124
125 /**
126 * Create a Subscribe function. A proxy Observer is created so that
127 * events can be sent to single Observer to be fanned out automatically.
128 */
129 createSubscribe<T>(
130 executor: (observer: Observer<T>) => void,
131 onNoObservers?: (observer: Observer<T>) => void
132 ): Subscribe<T>;
133
134 /**
135 * Utility exposed for internal testing.
136 */
137 deepExtend(target: any, source: any): any;
138
139 /**
140 * Internal API to remove an app from the list of registered apps.
141 */
142 removeApp(name: string): void;
143
144 /**
145 * registered components.
146 */
147 components: Map<string, Component>;
148
149 /*
150 * Convert service name to factory name to use.
151 */
152 useAsService(app: FirebaseApp, serviceName: string): string | null;
153
154 /**
155 * Use to construct all thrown FirebaseError's.
156 */
157 ErrorFactory: typeof ErrorFactory;
158 };
159}
160
161declare module '@firebase/component' {
162 interface NameServiceMapping {
163 'platform-logger': PlatformLoggerService;
164 }
165}