Skip to content

Began reporting client sdk information #8271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-devsite/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ https://github.com/firebase/firebase-js-sdk
| [@firebase/app](./app.md#app_package) | Firebase App |
| [@firebase/app-check](./app-check.md#app-check_package) | The Firebase App Check Web SDK. |
| [@firebase/auth](./auth.md#auth_package) | Firebase Authentication |
| [@firebase/data-connect](./data-connect.md#data-connect_package) | Firebase Data Connect |
Copy link
Collaborator

@markarndt markarndt May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is docs-devsite/data-connect.md in another branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in this branch I believe

| [@firebase/database](./database.md#database_package) | Firebase Realtime Database |
| [@firebase/firestore](./firestore.md#firestore_package) | Cloud Firestore |
| [@firebase/functions](./functions.md#functions_package) | Cloud Functions for Firebase |
Expand Down
11 changes: 5 additions & 6 deletions packages/data-connect/src/api/DataConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import {

Check failure on line 18 in packages/data-connect/src/api/DataConnect.ts

View workflow job for this annotation

GitHub Actions / Lint

'@firebase/app' should be listed in the project's dependencies, not devDependencies
FirebaseApp,
_getProvider,
_removeServiceInstance,
Expand All @@ -36,7 +36,6 @@

import { MutationManager } from './Mutation';


/**
* Connector Config for calling Data Connect backend.
*/
Expand Down Expand Up @@ -131,10 +130,10 @@

if (this._authProvider) {
this._authTokenProvider = new FirebaseAuthProvider(
this.app.name,
this.app.options,
this._authProvider
);
this.app.name,
this.app.options,
this._authProvider
);
}

this.initialized = true;
Expand Down Expand Up @@ -239,7 +238,7 @@
/**
* Delete DataConnect instance
* @param dataConnect DataConnect instance
* @returns
* @returns
*/
export function terminate(dataConnect: DataConnect): Promise<void> {
return dataConnect._delete();
Expand Down
4 changes: 2 additions & 2 deletions packages/data-connect/src/api/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
mutationName: string
): MutationRef<Data, undefined>;
/**
*
*
* @param dcInstance Data Connect instance
* @param mutationName name of mutation
* @param variables variables to send with mutation
Expand All @@ -51,7 +51,7 @@
variables: Variables
): MutationRef<Data, Variables>;
/**
*
*
* @param dcInstance Data Connect instance
* @param mutationName name of mutation
* @param variables variables to send with mutation
Expand Down Expand Up @@ -95,7 +95,7 @@
return obj;
});
this._inflight.push(result);
const removePromise = () =>

Check failure on line 98 in packages/data-connect/src/api/Mutation.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing return type on function
(this._inflight = this._inflight.filter(promise => promise !== result));
result.then(removePromise, removePromise);
return withRefPromise;
Expand Down
1 change: 0 additions & 1 deletion packages/data-connect/src/core/FirebaseAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { FirebaseOptions } from '@firebase/app';

Check failure on line 18 in packages/data-connect/src/core/FirebaseAuthProvider.ts

View workflow job for this annotation

GitHub Actions / Lint

'@firebase/app' should be listed in the project's dependencies, not devDependencies
import {
FirebaseAuthInternal,
FirebaseAuthInternalName,
Expand Down Expand Up @@ -74,9 +74,8 @@
this._auth?.addAuthTokenListener(listener);
}
removeTokenChangeListener(listener: (token: string | null) => void): void {
this._authProvider

Check failure on line 77 in packages/data-connect/src/core/FirebaseAuthProvider.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
.get()
.then(auth => auth.removeAuthTokenListener(listener));
}
}

4 changes: 1 addition & 3 deletions packages/data-connect/src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
constructor(private transport: DataConnectTransport) {
this._queries = new Map();
}
track<Data, Variables>(

Check failure on line 76 in packages/data-connect/src/core/QueryManager.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing return type on function
queryName: string,
variables: Variables,
initialCache?: OpResult<Data>
Expand Down Expand Up @@ -113,7 +113,7 @@
userCallback: onResultCallback,
errCallback: onErrorCallback
};
const unsubscribe = () => {

Check failure on line 116 in packages/data-connect/src/core/QueryManager.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing return type on function
const trackedQuery = this._queries.get(key)!;
trackedQuery.subscriptions = trackedQuery.subscriptions.filter(
sub => sub !== subscription
Expand Down Expand Up @@ -163,9 +163,7 @@
queryRef.variables
)}. Calling executeQuery.`
);
const promise = this.executeQuery(
queryRef as QueryRef<Data, Variables>
);
const promise = this.executeQuery(queryRef as QueryRef<Data, Variables>);
// We want to ignore the error and let subscriptions handle it
promise.then(undefined, err => {});
}
Expand Down Expand Up @@ -217,11 +215,11 @@

return newR;
}
enableEmulator(host: string, port: number) {

Check failure on line 218 in packages/data-connect/src/core/QueryManager.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing return type on function
this.transport.useEmulator(host, port);
}
}
function compareDates(str1: string, str2: string) {

Check failure on line 222 in packages/data-connect/src/core/QueryManager.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing return type on function
const date1 = new Date(str1);
const date2 = new Date(str2);
return date1.getTime() < date2.getTime();
Expand Down
3 changes: 1 addition & 2 deletions packages/data-connect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export * from './api.browser';

registerDataConnect();


declare module '@firebase/component' {
interface NameServiceMapping {
'data-connect': DataConnect;
}
}
}
15 changes: 12 additions & 3 deletions packages/data-connect/src/network/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
*/

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

let connectFetch: typeof fetch | null = globalThis.fetch;
export function initializeFetch(fetchImpl: typeof fetch) {
connectFetch = fetchImpl;
}
function getGoogApiClientValue(): string {
return 'gl-js/ fire/' + SDK_VERSION;
}
export function dcFetch<T, U>(
url: string,
body: U,
Expand All @@ -32,7 +36,8 @@ export function dcFetch<T, U>(
throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
}
const headers: HeadersInit = {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'X-Goog-Api-Client': getGoogApiClientValue()
};
if (accessToken) {
headers['X-Firebase-Auth-Token'] = accessToken;
Expand All @@ -44,9 +49,13 @@ export function dcFetch<T, U>(
method: 'POST',
headers,
signal
}).catch(err => {
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
})
.catch(err => {
throw new DataConnectError(
Code.OTHER,
'Failed to fetch: ' + JSON.stringify(err)
);
})
.then(async response => {
let jsonResponse = null;
try {
Expand Down
6 changes: 5 additions & 1 deletion packages/data-connect/src/util/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
* limitations under the License.
*/

export function setIfNotExists<T>(map: Map<string, T>, key: string, val: T): void {
export function setIfNotExists<T>(
map: Map<string, T>,
key: string,
val: T
): void {
if (!map.has(key)) {
map.set(key, val);
}
Expand Down
2 changes: 0 additions & 2 deletions packages/data-connect/test/emulatorSeeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import * as path from 'path';
// }
// }



import { ReferenceType } from '../src';

// }
Expand Down
10 changes: 7 additions & 3 deletions packages/data-connect/test/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import {
QueryResult,
SerializedRef,
subscribe,
terminate
, SOURCE_CACHE, SOURCE_SERVER } from '../src';
terminate,
SOURCE_CACHE,
SOURCE_SERVER
} from '../src';

import { setupQueries } from './emulatorSeeder';
import { getConnectionConfig, initDatabase, PROJECT_ID } from './util';
Expand Down Expand Up @@ -161,7 +163,9 @@ describe('DataConnect Tests', async () => {
});
connectDataConnectEmulator(fakeInstance, 'localhost', Number(0));
const taskListQuery = queryRef<TaskListResponse>(dc, 'listPosts');
expect(await executeQuery(taskListQuery)).to.eventually.be.rejectedWith('ECONNREFUSED');
expect(await executeQuery(taskListQuery)).to.eventually.be.rejectedWith(
'ECONNREFUSED'
);
});
});
async function waitForFirstEvent<Data, Variables>(
Expand Down
Loading