Skip to content

Commit

Permalink
Removed function from type
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht committed May 8, 2024
1 parent 8581bf0 commit b8e015c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 144 deletions.
120 changes: 0 additions & 120 deletions common/api-review/data-connect-react.api.md

This file was deleted.

7 changes: 4 additions & 3 deletions common/api-review/data-connect.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
import { FirebaseError } from '@firebase/util';
import { FirebaseOptions } from '@firebase/app';
import { LogLevelString } from '@firebase/logger';
import { Provider } from '@firebase/component';

// @public (undocumented)
Expand Down Expand Up @@ -210,9 +211,6 @@ export interface OpResult<Data> {
source: DataSource;
}

// @public (undocumented)
export function parseOptions(fullHost: string): TransportOptions;

// @public (undocumented)
export interface ProjectOptions {
// (undocumented)
Expand Down Expand Up @@ -286,6 +284,9 @@ export interface SerializedRef<Data, Variables> extends OpResult<Data> {
refInfo: RefInfo<Variables>;
}

// @public (undocumented)
export function setLogLevel(logLevel: LogLevelString): void;

// @public (undocumented)
export const SOURCE_CACHE = "CACHE";

Expand Down
20 changes: 13 additions & 7 deletions packages/data-connect/src/api/DataConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { RESTTransport } from '../network/transport/rest';

import { MutationManager } from './Mutation';
import { Code, DataConnectError } from '../core/error';
import { logger } from '../logger';
import { logDebug, logError } from '../logger';

export interface ProjectOptions {
location: string;
Expand All @@ -59,6 +59,12 @@ export interface TransportOptions {
export const FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR =
'FIREBASE_DATA_CONNECT_EMULATOR_HOST';

/**
*
* @param fullHost
* @returns TransportOptions
* @internal
*/
export function parseOptions(fullHost: string): TransportOptions {
const [protocol, hostName] = fullHost.split('://');
const isSecure = protocol === 'https';
Expand Down Expand Up @@ -87,7 +93,7 @@ export class DataConnect {
if (typeof process !== 'undefined' && process.env) {
const host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
if (host) {
logger.info('Found custom host. Using emulator');
logDebug('Found custom host. Using emulator');
this.isEmulator = true;
this.transportOptions = parseOptions(host);
}
Expand All @@ -113,7 +119,7 @@ export class DataConnect {
return;
}
if (this.transportClass === undefined) {
logger.info('transportClass not provided. Defaulting to RESTTransport.');
logDebug('transportClass not provided. Defaulting to RESTTransport.');
this.transportClass = RESTTransport;
}

Expand All @@ -126,7 +132,7 @@ export class DataConnect {
this.authProvider
);
this.authTokenProvider.addTokenChangeListener(token => {
logger.info(`New Token Available: ${token}`);
logDebug(`New Token Available: ${token}`);
this._transport.onTokenChanged(token);
});
}
Expand All @@ -150,7 +156,7 @@ export class DataConnect {

enableEmulator(transportOptions: TransportOptions) {
if (this.initialized) {
logger.error('enableEmulator called without initializing');
logError('enableEmulator called without initializing');
throw new DataConnectError(
Code.ALREADY_INITIALIZED,
'DataConnect instance already initialized!'
Expand Down Expand Up @@ -199,14 +205,14 @@ export function getDataConnect(
const options = provider.getOptions(identifier);
const optionsValid = Object.keys(options).length > 0;
if (optionsValid) {
logger.debug('Re-using cached instance');
logDebug('Re-using cached instance');
return dcInstance;
}
}
if (!dcOptions) {
throw new DataConnectError(Code.INVALID_ARGUMENT, 'DC Option Required');
}
logger.debug('Creating new DataConnect instance');
logDebug('Creating new DataConnect instance');
// Initialize with options.
return provider.initialize({
instanceIdentifier: identifier,
Expand Down
1 change: 0 additions & 1 deletion packages/data-connect/src/api/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import { logger } from '../logger';
import { DataConnectTransport } from '../network/transport';

import { DataConnect } from './DataConnect';
Expand Down
2 changes: 1 addition & 1 deletion packages/data-connect/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export * from './DataConnect';
export * from './Reference';
export * from './Mutation';
export * from './query';
export * from '../logger';
export { setLogLevel } from '../logger';
6 changes: 3 additions & 3 deletions packages/data-connect/src/core/FirebaseAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
FirebaseAuthTokenData
} from '@firebase/auth-interop-types';
import { Provider } from '@firebase/component';
import { logger } from '../logger';
import { logDebug, logError } from '../logger';

export interface AuthTokenProvider {
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;
Expand Down Expand Up @@ -56,12 +56,12 @@ export class FirebaseAuthProvider implements AuthTokenProvider {
}
return this.auth_.getToken(forceRefresh).catch(error => {
if (error && error.code === 'auth/token-not-initialized') {
logger.debug(
logDebug(
'Got auth/token-not-initialized error. Treating as null token.'
);
return null;
} else {
logger.error(
logError(
'Error received when attempting to retrieve token: ' +
JSON.stringify(error)
);
Expand Down
6 changes: 3 additions & 3 deletions packages/data-connect/src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
DataSource,
SOURCE_CACHE
} from '../api/Reference';
import { logger } from '../logger';
import { logDebug } from '../logger';
import { DataConnectTransport } from '../network';
import { encoderImpl } from '../util/encoder';
import { setIfNotExists } from '../util/map';
Expand Down Expand Up @@ -119,7 +119,7 @@ export class QueryManager {
);
};
if (initialCache && trackedQuery.currentCache !== initialCache) {
logger.debug('Initial cache found. Comparing dates.');
logDebug('Initial cache found. Comparing dates.');
if (
!trackedQuery.currentCache ||
(trackedQuery.currentCache &&
Expand Down Expand Up @@ -155,7 +155,7 @@ export class QueryManager {
unsubscribe
});
if (!trackedQuery.currentCache) {
logger.info(
logDebug(
`No cache available for query ${
queryRef.name
} with variables ${JSON.stringify(
Expand Down
34 changes: 34 additions & 0 deletions packages/data-connect/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2024 Google LLC
*
* 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 { Logger, LogLevel, LogLevelString } from "@firebase/logger";
import { SDK_VERSION } from "./core/version";

const logger = new Logger('@firebase/data-connect');
export function setLogLevel(logLevel: LogLevelString) {
logger.setLogLevel(logLevel);
}
export function logDebug(msg: string): void {
// if (logger.logLevel <= LogLevel.DEBUG) {
logger.debug(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}

export function logError(msg: string): void {
// if (logger.logLevel <= LogLevel.ERROR) {
logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}
8 changes: 4 additions & 4 deletions packages/data-connect/src/network/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Code, DataConnectError } from '../core/error';
import { logger } from '../logger';
import { logDebug, logError } from '../logger';

let connectFetch: typeof fetch | null = globalThis.fetch;
export function initializeFetch(fetchImpl: typeof fetch) {
Expand All @@ -38,7 +38,7 @@ export function dcFetch<T, U>(
headers['X-Firebase-Auth-Token'] = accessToken;
}
const bodyStr = JSON.stringify(body);
logger.info(`Making request out to ${url} with body: ${bodyStr}`);
logDebug(`Making request out to ${url} with body: ${bodyStr}`);
return connectFetch(url, {
body: bodyStr,
method: 'POST',
Expand All @@ -53,7 +53,7 @@ export function dcFetch<T, U>(
throw new DataConnectError(Code.OTHER, JSON.stringify(e));
}
if (response.status >= 400) {
logger.error(
logError(
'Error while performing request: ' + JSON.stringify(jsonResponse)
);
throw new DataConnectError(Code.OTHER, JSON.stringify(jsonResponse));
Expand All @@ -63,7 +63,7 @@ export function dcFetch<T, U>(
.then(res => {
if (res.errors && res.errors.length) {
const stringified = JSON.stringify(res.errors);
logger.error(
logError(
'DataConnect error while performing request: ' + stringified
);
throw new DataConnectError(Code.OTHER, stringified);
Expand Down
4 changes: 2 additions & 2 deletions packages/data-connect/src/util/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { ProjectOptions, TransportOptions } from '../api/DataConnect';
import { Code, DataConnectError } from '../core/error';
import { logger } from '../logger';
import { logError } from '../logger';

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

0 comments on commit b8e015c

Please sign in to comment.