Skip to content

Commit b8e015c

Browse files
committed
Removed function from type
1 parent 8581bf0 commit b8e015c

File tree

10 files changed

+64
-144
lines changed

10 files changed

+64
-144
lines changed

common/api-review/data-connect-react.api.md

Lines changed: 0 additions & 120 deletions
This file was deleted.

common/api-review/data-connect.api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
99
import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
1010
import { FirebaseError } from '@firebase/util';
1111
import { FirebaseOptions } from '@firebase/app';
12+
import { LogLevelString } from '@firebase/logger';
1213
import { Provider } from '@firebase/component';
1314

1415
// @public (undocumented)
@@ -210,9 +211,6 @@ export interface OpResult<Data> {
210211
source: DataSource;
211212
}
212213

213-
// @public (undocumented)
214-
export function parseOptions(fullHost: string): TransportOptions;
215-
216214
// @public (undocumented)
217215
export interface ProjectOptions {
218216
// (undocumented)
@@ -286,6 +284,9 @@ export interface SerializedRef<Data, Variables> extends OpResult<Data> {
286284
refInfo: RefInfo<Variables>;
287285
}
288286

287+
// @public (undocumented)
288+
export function setLogLevel(logLevel: LogLevelString): void;
289+
289290
// @public (undocumented)
290291
export const SOURCE_CACHE = "CACHE";
291292

packages/data-connect/src/api/DataConnect.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { RESTTransport } from '../network/transport/rest';
3535

3636
import { MutationManager } from './Mutation';
3737
import { Code, DataConnectError } from '../core/error';
38-
import { logger } from '../logger';
38+
import { logDebug, logError } from '../logger';
3939

4040
export interface ProjectOptions {
4141
location: string;
@@ -59,6 +59,12 @@ export interface TransportOptions {
5959
export const FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR =
6060
'FIREBASE_DATA_CONNECT_EMULATOR_HOST';
6161

62+
/**
63+
*
64+
* @param fullHost
65+
* @returns TransportOptions
66+
* @internal
67+
*/
6268
export function parseOptions(fullHost: string): TransportOptions {
6369
const [protocol, hostName] = fullHost.split('://');
6470
const isSecure = protocol === 'https';
@@ -87,7 +93,7 @@ export class DataConnect {
8793
if (typeof process !== 'undefined' && process.env) {
8894
const host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
8995
if (host) {
90-
logger.info('Found custom host. Using emulator');
96+
logDebug('Found custom host. Using emulator');
9197
this.isEmulator = true;
9298
this.transportOptions = parseOptions(host);
9399
}
@@ -113,7 +119,7 @@ export class DataConnect {
113119
return;
114120
}
115121
if (this.transportClass === undefined) {
116-
logger.info('transportClass not provided. Defaulting to RESTTransport.');
122+
logDebug('transportClass not provided. Defaulting to RESTTransport.');
117123
this.transportClass = RESTTransport;
118124
}
119125

@@ -126,7 +132,7 @@ export class DataConnect {
126132
this.authProvider
127133
);
128134
this.authTokenProvider.addTokenChangeListener(token => {
129-
logger.info(`New Token Available: ${token}`);
135+
logDebug(`New Token Available: ${token}`);
130136
this._transport.onTokenChanged(token);
131137
});
132138
}
@@ -150,7 +156,7 @@ export class DataConnect {
150156

151157
enableEmulator(transportOptions: TransportOptions) {
152158
if (this.initialized) {
153-
logger.error('enableEmulator called without initializing');
159+
logError('enableEmulator called without initializing');
154160
throw new DataConnectError(
155161
Code.ALREADY_INITIALIZED,
156162
'DataConnect instance already initialized!'
@@ -199,14 +205,14 @@ export function getDataConnect(
199205
const options = provider.getOptions(identifier);
200206
const optionsValid = Object.keys(options).length > 0;
201207
if (optionsValid) {
202-
logger.debug('Re-using cached instance');
208+
logDebug('Re-using cached instance');
203209
return dcInstance;
204210
}
205211
}
206212
if (!dcOptions) {
207213
throw new DataConnectError(Code.INVALID_ARGUMENT, 'DC Option Required');
208214
}
209-
logger.debug('Creating new DataConnect instance');
215+
logDebug('Creating new DataConnect instance');
210216
// Initialize with options.
211217
return provider.initialize({
212218
instanceIdentifier: identifier,

packages/data-connect/src/api/Mutation.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { logger } from '../logger';
1918
import { DataConnectTransport } from '../network/transport';
2019

2120
import { DataConnect } from './DataConnect';

packages/data-connect/src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export * from './DataConnect';
2020
export * from './Reference';
2121
export * from './Mutation';
2222
export * from './query';
23-
export * from '../logger';
23+
export { setLogLevel } from '../logger';

packages/data-connect/src/core/FirebaseAuthProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
FirebaseAuthTokenData
2323
} from '@firebase/auth-interop-types';
2424
import { Provider } from '@firebase/component';
25-
import { logger } from '../logger';
25+
import { logDebug, logError } from '../logger';
2626

2727
export interface AuthTokenProvider {
2828
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;
@@ -56,12 +56,12 @@ export class FirebaseAuthProvider implements AuthTokenProvider {
5656
}
5757
return this.auth_.getToken(forceRefresh).catch(error => {
5858
if (error && error.code === 'auth/token-not-initialized') {
59-
logger.debug(
59+
logDebug(
6060
'Got auth/token-not-initialized error. Treating as null token.'
6161
);
6262
return null;
6363
} else {
64-
logger.error(
64+
logError(
6565
'Error received when attempting to retrieve token: ' +
6666
JSON.stringify(error)
6767
);

packages/data-connect/src/core/QueryManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
DataSource,
3333
SOURCE_CACHE
3434
} from '../api/Reference';
35-
import { logger } from '../logger';
35+
import { logDebug } from '../logger';
3636
import { DataConnectTransport } from '../network';
3737
import { encoderImpl } from '../util/encoder';
3838
import { setIfNotExists } from '../util/map';
@@ -119,7 +119,7 @@ export class QueryManager {
119119
);
120120
};
121121
if (initialCache && trackedQuery.currentCache !== initialCache) {
122-
logger.debug('Initial cache found. Comparing dates.');
122+
logDebug('Initial cache found. Comparing dates.');
123123
if (
124124
!trackedQuery.currentCache ||
125125
(trackedQuery.currentCache &&
@@ -155,7 +155,7 @@ export class QueryManager {
155155
unsubscribe
156156
});
157157
if (!trackedQuery.currentCache) {
158-
logger.info(
158+
logDebug(
159159
`No cache available for query ${
160160
queryRef.name
161161
} with variables ${JSON.stringify(

packages/data-connect/src/logger.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright 2024 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+
import { Logger, LogLevel, LogLevelString } from "@firebase/logger";
18+
import { SDK_VERSION } from "./core/version";
19+
20+
const logger = new Logger('@firebase/data-connect');
21+
export function setLogLevel(logLevel: LogLevelString) {
22+
logger.setLogLevel(logLevel);
23+
}
24+
export function logDebug(msg: string): void {
25+
// if (logger.logLevel <= LogLevel.DEBUG) {
26+
logger.debug(`DataConnect (${SDK_VERSION}): ${msg}`);
27+
// }
28+
}
29+
30+
export function logError(msg: string): void {
31+
// if (logger.logLevel <= LogLevel.ERROR) {
32+
logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
33+
// }
34+
}

packages/data-connect/src/network/fetch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { Code, DataConnectError } from '../core/error';
19-
import { logger } from '../logger';
19+
import { logDebug, logError } from '../logger';
2020

2121
let connectFetch: typeof fetch | null = globalThis.fetch;
2222
export function initializeFetch(fetchImpl: typeof fetch) {
@@ -38,7 +38,7 @@ export function dcFetch<T, U>(
3838
headers['X-Firebase-Auth-Token'] = accessToken;
3939
}
4040
const bodyStr = JSON.stringify(body);
41-
logger.info(`Making request out to ${url} with body: ${bodyStr}`);
41+
logDebug(`Making request out to ${url} with body: ${bodyStr}`);
4242
return connectFetch(url, {
4343
body: bodyStr,
4444
method: 'POST',
@@ -53,7 +53,7 @@ export function dcFetch<T, U>(
5353
throw new DataConnectError(Code.OTHER, JSON.stringify(e));
5454
}
5555
if (response.status >= 400) {
56-
logger.error(
56+
logError(
5757
'Error while performing request: ' + JSON.stringify(jsonResponse)
5858
);
5959
throw new DataConnectError(Code.OTHER, JSON.stringify(jsonResponse));
@@ -63,7 +63,7 @@ export function dcFetch<T, U>(
6363
.then(res => {
6464
if (res.errors && res.errors.length) {
6565
const stringified = JSON.stringify(res.errors);
66-
logger.error(
66+
logError(
6767
'DataConnect error while performing request: ' + stringified
6868
);
6969
throw new DataConnectError(Code.OTHER, stringified);

packages/data-connect/src/util/url.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { ProjectOptions, TransportOptions } from '../api/DataConnect';
1919
import { Code, DataConnectError } from '../core/error';
20-
import { logger } from '../logger';
20+
import { logError } from '../logger';
2121

2222
export function urlBuilder(
2323
projectConfig: ProjectOptions,
@@ -31,7 +31,7 @@ export function urlBuilder(
3131
if (typeof port === 'number') {
3232
baseUrl += `:${port}`;
3333
} else if (typeof port !== 'undefined') {
34-
logger.error('Port type is of an invalid type');
34+
logError('Port type is of an invalid type');
3535
throw new DataConnectError(
3636
Code.INVALID_ARGUMENT,
3737
'Incorrect type for port passed in!'

0 commit comments

Comments
 (0)