From a2c6bea568d17e25e5e3d8d91e35b47c84b743b5 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Tue, 3 Dec 2024 16:26:40 -0600 Subject: [PATCH 01/10] Fixed issue where multiple calls to connectDataConnectEmulator throws an error --- .../src/platform_browser/strategies/popup.ts | 3 ++ packages/data-connect/src/api/DataConnect.ts | 7 ++- packages/data-connect/src/api/query.ts | 22 ++++++-- packages/data-connect/test/queries.test.ts | 13 ++++- .../test/unit/transportoptions.test.ts | 52 +++++++++++++++++++ 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 packages/data-connect/test/unit/transportoptions.test.ts diff --git a/packages/auth/src/platform_browser/strategies/popup.ts b/packages/auth/src/platform_browser/strategies/popup.ts index 12ba128aca9..6007728a4e9 100644 --- a/packages/auth/src/platform_browser/strategies/popup.ts +++ b/packages/auth/src/platform_browser/strategies/popup.ts @@ -299,6 +299,9 @@ class PopupOperation extends AbstractPopupRedirectOperation { private pollUserCancellation(): void { const poll = (): void => { + if(typeof window !== 'undefined' && this.authWindow?.window?.location.host !== window.location.host) { + console.error('Unable to determine whether window was closed or not'); + } if (this.authWindow?.window?.closed) { // Make sure that there is sufficient time for whatever action to // complete. The window could have closed but the sign in network diff --git a/packages/data-connect/src/api/DataConnect.ts b/packages/data-connect/src/api/DataConnect.ts index 27ab83660fd..1fd020950a3 100644 --- a/packages/data-connect/src/api/DataConnect.ts +++ b/packages/data-connect/src/api/DataConnect.ts @@ -179,7 +179,7 @@ export class DataConnect { // @internal enableEmulator(transportOptions: TransportOptions): void { - if (this._initialized) { + if (this._initialized && !areTransportOptionsEqual(this._transportOptions, transportOptions)) { logError('enableEmulator called after initialization'); throw new DataConnectError( Code.ALREADY_INITIALIZED, @@ -191,6 +191,11 @@ export class DataConnect { } } +// @internal +export function areTransportOptionsEqual(transportOptions1: TransportOptions, transportOptions2: TransportOptions) { + return JSON.stringify(transportOptions1) === JSON.stringify(transportOptions2); +} + /** * Connect to the DataConnect Emulator * @param dc Data Connect instance diff --git a/packages/data-connect/src/api/query.ts b/packages/data-connect/src/api/query.ts index a4ab17b7ceb..119ff8470b0 100644 --- a/packages/data-connect/src/api/query.ts +++ b/packages/data-connect/src/api/query.ts @@ -104,27 +104,39 @@ export function queryRef( queryName: string, variables: Variables ): QueryRef; + +export function queryRef( + dcInstance: DataConnect, + serializedRef: SerializedRef +): QueryRef; + /** * Execute Query * @param dcInstance Data Connect instance to use. - * @param queryName Query to execute + * @param queryNameOrSerializedRef Query to execute * @param variables Variables to execute with * @param initialCache initial cache to use for client hydration * @returns `QueryRef` */ export function queryRef( dcInstance: DataConnect, - queryName: string, + queryNameOrSerializedRef: string | SerializedRef, variables?: Variables, initialCache?: QueryResult ): QueryRef { dcInstance.setInitialized(); - dcInstance._queryManager.track(queryName, variables, initialCache); + if(typeof queryNameOrSerializedRef === 'string') { + dcInstance._queryManager.track(queryNameOrSerializedRef, variables, initialCache); + } else { + dcInstance._queryManager.track(queryNameOrSerializedRef.refInfo.name, queryNameOrSerializedRef.refInfo.variables, queryNameOrSerializedRef); + } + const vars = typeof queryNameOrSerializedRef !== 'string'? queryNameOrSerializedRef.refInfo.variables : variables; + const name = typeof queryNameOrSerializedRef !== 'string'? queryNameOrSerializedRef.refInfo.name : queryNameOrSerializedRef; return { dataConnect: dcInstance, refType: QUERY_STR, - name: queryName, - variables: variables as Variables + name, + variables: vars }; } /** diff --git a/packages/data-connect/test/queries.test.ts b/packages/data-connect/test/queries.test.ts index dd7e4e6c9e3..16c81a9fa90 100644 --- a/packages/data-connect/test/queries.test.ts +++ b/packages/data-connect/test/queries.test.ts @@ -33,11 +33,13 @@ import { subscribe, terminate, SOURCE_CACHE, - SOURCE_SERVER + SOURCE_SERVER, + toQueryRef } from '../src'; import { setupQueries } from './emulatorSeeder'; import { getConnectionConfig, initDatabase, PROJECT_ID } from './util'; +import { serialize } from 'v8'; use(chaiAsPromised); @@ -136,6 +138,15 @@ describe('DataConnect Tests', async () => { expect(result.data).to.eq(queryResult.data); expect(result.source).to.eq(SOURCE_CACHE); }); + + it(`returns the result source as cache when data already exists`, async () => { + const taskListQuery = queryRef(dc, 'listPosts'); + const queryResult = await executeQuery(taskListQuery); + const serializedRef = queryResult.toJSON(); + const newRef = queryRef(dc, serializedRef); + expect(newRef.name).to.eq(serializedRef.refInfo.name); + expect(newRef.variables).to.eq(serializedRef.refInfo.variables); + }); it(`returns the proper JSON when calling .toJSON()`, async () => { const taskListQuery = queryRef(dc, 'listPosts'); await executeQuery(taskListQuery); diff --git a/packages/data-connect/test/unit/transportoptions.test.ts b/packages/data-connect/test/unit/transportoptions.test.ts new file mode 100644 index 00000000000..b3ed10ff4bc --- /dev/null +++ b/packages/data-connect/test/unit/transportoptions.test.ts @@ -0,0 +1,52 @@ +import { expect } from 'chai'; +import { TransportOptions, areTransportOptionsEqual, connectDataConnectEmulator, getDataConnect} from '../../src/api/DataConnect'; +import { app } from '../util'; +import { queryRef } from '../../src'; +describe.only('Transport Options', () => { + it('should return false if transport options are not equal', () => { + const transportOptions1: TransportOptions = { + host: 'h', + port: 1, + sslEnabled: false + }; + const transportOptions2: TransportOptions = { + host: 'h2', + port: 2, + sslEnabled: false + }; + expect(areTransportOptionsEqual(transportOptions1, transportOptions2)).to.eq(false); + }); + it('should return true if transport options are equal', () => { + const transportOptions1: TransportOptions = { + host: 'h', + port: 1, + sslEnabled: false + }; + const transportOptions2: TransportOptions = { + host: 'h', + port: 1, + sslEnabled: false + }; + expect(areTransportOptionsEqual(transportOptions1, transportOptions2)).to.eq(true); + }); + it.only('should throw if emulator is connected to with new transport options', () => { + const dc = getDataConnect(app, { + connector: 'c', + location: 'l', + service: 's' + }); + expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); + queryRef(dc, 'query'); + expect(() => connectDataConnectEmulator(dc, 'h2', 80, false)).to.throw('DataConnect instance already initialized!'); + }); + it.only('should not throw if emulator is connected to with the same transport options', () => { + const dc = getDataConnect(app, { + connector: 'c', + location: 'l', + service: 's' + }); + expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); + queryRef(dc, 'query'); + expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); + }); +}); \ No newline at end of file From a51822f90841bb307f0f086b8835d16d2e48b08f Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Tue, 3 Dec 2024 16:30:21 -0600 Subject: [PATCH 02/10] Undid auth changes --- packages/auth/src/platform_browser/strategies/popup.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/auth/src/platform_browser/strategies/popup.ts b/packages/auth/src/platform_browser/strategies/popup.ts index 6007728a4e9..12ba128aca9 100644 --- a/packages/auth/src/platform_browser/strategies/popup.ts +++ b/packages/auth/src/platform_browser/strategies/popup.ts @@ -299,9 +299,6 @@ class PopupOperation extends AbstractPopupRedirectOperation { private pollUserCancellation(): void { const poll = (): void => { - if(typeof window !== 'undefined' && this.authWindow?.window?.location.host !== window.location.host) { - console.error('Unable to determine whether window was closed or not'); - } if (this.authWindow?.window?.closed) { // Make sure that there is sufficient time for whatever action to // complete. The window could have closed but the sign in network From 193240046213a9141d7e13e86a9e5265b5becb67 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Tue, 3 Dec 2024 16:33:31 -0600 Subject: [PATCH 03/10] Fixed linting --- packages/data-connect/src/api/DataConnect.ts | 14 +- packages/data-connect/src/api/query.ts | 24 +++- packages/data-connect/test/queries.test.ts | 4 +- .../test/unit/transportoptions.test.ts | 120 +++++++++++------- 4 files changed, 106 insertions(+), 56 deletions(-) diff --git a/packages/data-connect/src/api/DataConnect.ts b/packages/data-connect/src/api/DataConnect.ts index 1fd020950a3..33fca9b9e97 100644 --- a/packages/data-connect/src/api/DataConnect.ts +++ b/packages/data-connect/src/api/DataConnect.ts @@ -179,7 +179,10 @@ export class DataConnect { // @internal enableEmulator(transportOptions: TransportOptions): void { - if (this._initialized && !areTransportOptionsEqual(this._transportOptions, transportOptions)) { + if ( + this._initialized && + !areTransportOptionsEqual(this._transportOptions, transportOptions) + ) { logError('enableEmulator called after initialization'); throw new DataConnectError( Code.ALREADY_INITIALIZED, @@ -192,8 +195,13 @@ export class DataConnect { } // @internal -export function areTransportOptionsEqual(transportOptions1: TransportOptions, transportOptions2: TransportOptions) { - return JSON.stringify(transportOptions1) === JSON.stringify(transportOptions2); +export function areTransportOptionsEqual( + transportOptions1: TransportOptions, + transportOptions2: TransportOptions +) { + return ( + JSON.stringify(transportOptions1) === JSON.stringify(transportOptions2) + ); } /** diff --git a/packages/data-connect/src/api/query.ts b/packages/data-connect/src/api/query.ts index 119ff8470b0..9c34c10184f 100644 --- a/packages/data-connect/src/api/query.ts +++ b/packages/data-connect/src/api/query.ts @@ -125,13 +125,27 @@ export function queryRef( initialCache?: QueryResult ): QueryRef { dcInstance.setInitialized(); - if(typeof queryNameOrSerializedRef === 'string') { - dcInstance._queryManager.track(queryNameOrSerializedRef, variables, initialCache); + if (typeof queryNameOrSerializedRef === 'string') { + dcInstance._queryManager.track( + queryNameOrSerializedRef, + variables, + initialCache + ); } else { - dcInstance._queryManager.track(queryNameOrSerializedRef.refInfo.name, queryNameOrSerializedRef.refInfo.variables, queryNameOrSerializedRef); + dcInstance._queryManager.track( + queryNameOrSerializedRef.refInfo.name, + queryNameOrSerializedRef.refInfo.variables, + queryNameOrSerializedRef + ); } - const vars = typeof queryNameOrSerializedRef !== 'string'? queryNameOrSerializedRef.refInfo.variables : variables; - const name = typeof queryNameOrSerializedRef !== 'string'? queryNameOrSerializedRef.refInfo.name : queryNameOrSerializedRef; + const vars = + typeof queryNameOrSerializedRef !== 'string' + ? queryNameOrSerializedRef.refInfo.variables + : variables; + const name = + typeof queryNameOrSerializedRef !== 'string' + ? queryNameOrSerializedRef.refInfo.name + : queryNameOrSerializedRef; return { dataConnect: dcInstance, refType: QUERY_STR, diff --git a/packages/data-connect/test/queries.test.ts b/packages/data-connect/test/queries.test.ts index 16c81a9fa90..354ff055b14 100644 --- a/packages/data-connect/test/queries.test.ts +++ b/packages/data-connect/test/queries.test.ts @@ -138,11 +138,11 @@ describe('DataConnect Tests', async () => { expect(result.data).to.eq(queryResult.data); expect(result.source).to.eq(SOURCE_CACHE); }); - + it(`returns the result source as cache when data already exists`, async () => { const taskListQuery = queryRef(dc, 'listPosts'); const queryResult = await executeQuery(taskListQuery); - const serializedRef = queryResult.toJSON(); + const serializedRef = queryResult.toJSON(); const newRef = queryRef(dc, serializedRef); expect(newRef.name).to.eq(serializedRef.refInfo.name); expect(newRef.variables).to.eq(serializedRef.refInfo.variables); diff --git a/packages/data-connect/test/unit/transportoptions.test.ts b/packages/data-connect/test/unit/transportoptions.test.ts index b3ed10ff4bc..51672c2f49d 100644 --- a/packages/data-connect/test/unit/transportoptions.test.ts +++ b/packages/data-connect/test/unit/transportoptions.test.ts @@ -1,52 +1,80 @@ +/** + * @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 { expect } from 'chai'; -import { TransportOptions, areTransportOptionsEqual, connectDataConnectEmulator, getDataConnect} from '../../src/api/DataConnect'; +import { + TransportOptions, + areTransportOptionsEqual, + connectDataConnectEmulator, + getDataConnect +} from '../../src/api/DataConnect'; import { app } from '../util'; import { queryRef } from '../../src'; describe.only('Transport Options', () => { - it('should return false if transport options are not equal', () => { - const transportOptions1: TransportOptions = { - host: 'h', - port: 1, - sslEnabled: false - }; - const transportOptions2: TransportOptions = { - host: 'h2', - port: 2, - sslEnabled: false - }; - expect(areTransportOptionsEqual(transportOptions1, transportOptions2)).to.eq(false); + it('should return false if transport options are not equal', () => { + const transportOptions1: TransportOptions = { + host: 'h', + port: 1, + sslEnabled: false + }; + const transportOptions2: TransportOptions = { + host: 'h2', + port: 2, + sslEnabled: false + }; + expect( + areTransportOptionsEqual(transportOptions1, transportOptions2) + ).to.eq(false); + }); + it('should return true if transport options are equal', () => { + const transportOptions1: TransportOptions = { + host: 'h', + port: 1, + sslEnabled: false + }; + const transportOptions2: TransportOptions = { + host: 'h', + port: 1, + sslEnabled: false + }; + expect( + areTransportOptionsEqual(transportOptions1, transportOptions2) + ).to.eq(true); + }); + it.only('should throw if emulator is connected to with new transport options', () => { + const dc = getDataConnect(app, { + connector: 'c', + location: 'l', + service: 's' }); - it('should return true if transport options are equal', () => { - const transportOptions1: TransportOptions = { - host: 'h', - port: 1, - sslEnabled: false - }; - const transportOptions2: TransportOptions = { - host: 'h', - port: 1, - sslEnabled: false - }; - expect(areTransportOptionsEqual(transportOptions1, transportOptions2)).to.eq(true); + expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); + queryRef(dc, 'query'); + expect(() => connectDataConnectEmulator(dc, 'h2', 80, false)).to.throw( + 'DataConnect instance already initialized!' + ); + }); + it.only('should not throw if emulator is connected to with the same transport options', () => { + const dc = getDataConnect(app, { + connector: 'c', + location: 'l', + service: 's' }); - it.only('should throw if emulator is connected to with new transport options', () => { - const dc = getDataConnect(app, { - connector: 'c', - location: 'l', - service: 's' - }); - expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); - queryRef(dc, 'query'); - expect(() => connectDataConnectEmulator(dc, 'h2', 80, false)).to.throw('DataConnect instance already initialized!'); - }); - it.only('should not throw if emulator is connected to with the same transport options', () => { - const dc = getDataConnect(app, { - connector: 'c', - location: 'l', - service: 's' - }); - expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); - queryRef(dc, 'query'); - expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); - }); -}); \ No newline at end of file + expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); + queryRef(dc, 'query'); + expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw(); + }); +}); From 0253a6d0193911a654f406149971650f0144eb19 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Tue, 3 Dec 2024 16:34:14 -0600 Subject: [PATCH 04/10] Create funny-weeks-attack.md --- .changeset/funny-weeks-attack.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/funny-weeks-attack.md diff --git a/.changeset/funny-weeks-attack.md b/.changeset/funny-weeks-attack.md new file mode 100644 index 00000000000..54e26f5c749 --- /dev/null +++ b/.changeset/funny-weeks-attack.md @@ -0,0 +1,5 @@ +--- +"@firebase/data-connect": patch +--- + +Fixed issue where multiple calls to connectDataConnectEmulator caused an exception From 2e418310fa66237df57e077aab0a22f8f4af6549 Mon Sep 17 00:00:00 2001 From: maneesht Date: Tue, 3 Dec 2024 22:45:16 +0000 Subject: [PATCH 05/10] Update API reports --- common/api-review/data-connect.api.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/api-review/data-connect.api.md b/common/api-review/data-connect.api.md index b2c6fb01931..eb27c3f92cf 100644 --- a/common/api-review/data-connect.api.md +++ b/common/api-review/data-connect.api.md @@ -11,6 +11,9 @@ import { FirebaseError } from '@firebase/util'; import { LogLevelString } from '@firebase/logger'; import { Provider } from '@firebase/component'; +// @public (undocumented) +export function areTransportOptionsEqual(transportOptions1: TransportOptions, transportOptions2: TransportOptions): boolean; + // @public (undocumented) export interface CancellableOperation extends PromiseLike<{ data: T; @@ -159,6 +162,9 @@ export function queryRef(dcInstance: DataConnect, queryName: string): Quer // @public export function queryRef(dcInstance: DataConnect, queryName: string, variables: Variables): QueryRef; +// @public (undocumented) +export function queryRef(dcInstance: DataConnect, serializedRef: SerializedRef): QueryRef; + // @public export interface QueryResult extends DataConnectResult { // (undocumented) From b0800ef7636784ef0264a16418b48bf069efc6b7 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 4 Dec 2024 10:14:55 -0800 Subject: [PATCH 06/10] Removed only's and updated equality check --- packages/data-connect/src/api/DataConnect.ts | 4 +++- packages/data-connect/test/unit/transportoptions.test.ts | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/data-connect/src/api/DataConnect.ts b/packages/data-connect/src/api/DataConnect.ts index 33fca9b9e97..5826d84e3e8 100644 --- a/packages/data-connect/src/api/DataConnect.ts +++ b/packages/data-connect/src/api/DataConnect.ts @@ -200,7 +200,9 @@ export function areTransportOptionsEqual( transportOptions2: TransportOptions ) { return ( - JSON.stringify(transportOptions1) === JSON.stringify(transportOptions2) + transportOptions1.host === transportOptions2.host && + transportOptions1.port === transportOptions2.port && + transportOptions1.sslEnabled === transportOptions2.sslEnabled ); } diff --git a/packages/data-connect/test/unit/transportoptions.test.ts b/packages/data-connect/test/unit/transportoptions.test.ts index 51672c2f49d..91e090e6a54 100644 --- a/packages/data-connect/test/unit/transportoptions.test.ts +++ b/packages/data-connect/test/unit/transportoptions.test.ts @@ -24,7 +24,7 @@ import { } from '../../src/api/DataConnect'; import { app } from '../util'; import { queryRef } from '../../src'; -describe.only('Transport Options', () => { +describe('Transport Options', () => { it('should return false if transport options are not equal', () => { const transportOptions1: TransportOptions = { host: 'h', @@ -47,15 +47,15 @@ describe.only('Transport Options', () => { sslEnabled: false }; const transportOptions2: TransportOptions = { - host: 'h', port: 1, + host: 'h', sslEnabled: false }; expect( areTransportOptionsEqual(transportOptions1, transportOptions2) ).to.eq(true); }); - it.only('should throw if emulator is connected to with new transport options', () => { + it('should throw if emulator is connected to with new transport options', () => { const dc = getDataConnect(app, { connector: 'c', location: 'l', @@ -67,7 +67,7 @@ describe.only('Transport Options', () => { 'DataConnect instance already initialized!' ); }); - it.only('should not throw if emulator is connected to with the same transport options', () => { + it('should not throw if emulator is connected to with the same transport options', () => { const dc = getDataConnect(app, { connector: 'c', location: 'l', From d21037252f6dafb7e758d664e6a06dbf45a65dc1 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 4 Dec 2024 10:17:28 -0800 Subject: [PATCH 07/10] Added return type --- packages/data-connect/src/api/DataConnect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-connect/src/api/DataConnect.ts b/packages/data-connect/src/api/DataConnect.ts index 5826d84e3e8..e378d59e5c8 100644 --- a/packages/data-connect/src/api/DataConnect.ts +++ b/packages/data-connect/src/api/DataConnect.ts @@ -198,7 +198,7 @@ export class DataConnect { export function areTransportOptionsEqual( transportOptions1: TransportOptions, transportOptions2: TransportOptions -) { +): boolean { return ( transportOptions1.host === transportOptions2.host && transportOptions1.port === transportOptions2.port && From 22c8fa2398952cb51f089b3901a58af597a594f0 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 4 Dec 2024 10:57:54 -0800 Subject: [PATCH 08/10] Removed unnecessary changes --- common/api-review/data-connect.api.md | 6 ---- packages/data-connect/src/api/DataConnect.ts | 7 +++- packages/data-connect/src/api/query.ts | 36 +++----------------- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/common/api-review/data-connect.api.md b/common/api-review/data-connect.api.md index eb27c3f92cf..b2c6fb01931 100644 --- a/common/api-review/data-connect.api.md +++ b/common/api-review/data-connect.api.md @@ -11,9 +11,6 @@ import { FirebaseError } from '@firebase/util'; import { LogLevelString } from '@firebase/logger'; import { Provider } from '@firebase/component'; -// @public (undocumented) -export function areTransportOptionsEqual(transportOptions1: TransportOptions, transportOptions2: TransportOptions): boolean; - // @public (undocumented) export interface CancellableOperation extends PromiseLike<{ data: T; @@ -162,9 +159,6 @@ export function queryRef(dcInstance: DataConnect, queryName: string): Quer // @public export function queryRef(dcInstance: DataConnect, queryName: string, variables: Variables): QueryRef; -// @public (undocumented) -export function queryRef(dcInstance: DataConnect, serializedRef: SerializedRef): QueryRef; - // @public export interface QueryResult extends DataConnectResult { // (undocumented) diff --git a/packages/data-connect/src/api/DataConnect.ts b/packages/data-connect/src/api/DataConnect.ts index e378d59e5c8..6d93b21379e 100644 --- a/packages/data-connect/src/api/DataConnect.ts +++ b/packages/data-connect/src/api/DataConnect.ts @@ -194,7 +194,12 @@ export class DataConnect { } } -// @internal +/** + * @internal + * @param transportOptions1 + * @param transportOptions2 + * @returns + */ export function areTransportOptionsEqual( transportOptions1: TransportOptions, transportOptions2: TransportOptions diff --git a/packages/data-connect/src/api/query.ts b/packages/data-connect/src/api/query.ts index 9c34c10184f..a4ab17b7ceb 100644 --- a/packages/data-connect/src/api/query.ts +++ b/packages/data-connect/src/api/query.ts @@ -104,53 +104,27 @@ export function queryRef( queryName: string, variables: Variables ): QueryRef; - -export function queryRef( - dcInstance: DataConnect, - serializedRef: SerializedRef -): QueryRef; - /** * Execute Query * @param dcInstance Data Connect instance to use. - * @param queryNameOrSerializedRef Query to execute + * @param queryName Query to execute * @param variables Variables to execute with * @param initialCache initial cache to use for client hydration * @returns `QueryRef` */ export function queryRef( dcInstance: DataConnect, - queryNameOrSerializedRef: string | SerializedRef, + queryName: string, variables?: Variables, initialCache?: QueryResult ): QueryRef { dcInstance.setInitialized(); - if (typeof queryNameOrSerializedRef === 'string') { - dcInstance._queryManager.track( - queryNameOrSerializedRef, - variables, - initialCache - ); - } else { - dcInstance._queryManager.track( - queryNameOrSerializedRef.refInfo.name, - queryNameOrSerializedRef.refInfo.variables, - queryNameOrSerializedRef - ); - } - const vars = - typeof queryNameOrSerializedRef !== 'string' - ? queryNameOrSerializedRef.refInfo.variables - : variables; - const name = - typeof queryNameOrSerializedRef !== 'string' - ? queryNameOrSerializedRef.refInfo.name - : queryNameOrSerializedRef; + dcInstance._queryManager.track(queryName, variables, initialCache); return { dataConnect: dcInstance, refType: QUERY_STR, - name, - variables: vars + name: queryName, + variables: variables as Variables }; } /** From 2356080882985c58cdc29666859a557cbea4436b Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 4 Dec 2024 11:02:39 -0800 Subject: [PATCH 09/10] Removed query test from previous change --- packages/data-connect/test/queries.test.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/data-connect/test/queries.test.ts b/packages/data-connect/test/queries.test.ts index 354ff055b14..dd7e4e6c9e3 100644 --- a/packages/data-connect/test/queries.test.ts +++ b/packages/data-connect/test/queries.test.ts @@ -33,13 +33,11 @@ import { subscribe, terminate, SOURCE_CACHE, - SOURCE_SERVER, - toQueryRef + SOURCE_SERVER } from '../src'; import { setupQueries } from './emulatorSeeder'; import { getConnectionConfig, initDatabase, PROJECT_ID } from './util'; -import { serialize } from 'v8'; use(chaiAsPromised); @@ -138,15 +136,6 @@ describe('DataConnect Tests', async () => { expect(result.data).to.eq(queryResult.data); expect(result.source).to.eq(SOURCE_CACHE); }); - - it(`returns the result source as cache when data already exists`, async () => { - const taskListQuery = queryRef(dc, 'listPosts'); - const queryResult = await executeQuery(taskListQuery); - const serializedRef = queryResult.toJSON(); - const newRef = queryRef(dc, serializedRef); - expect(newRef.name).to.eq(serializedRef.refInfo.name); - expect(newRef.variables).to.eq(serializedRef.refInfo.variables); - }); it(`returns the proper JSON when calling .toJSON()`, async () => { const taskListQuery = queryRef(dc, 'listPosts'); await executeQuery(taskListQuery); From e7a7c2a5c36b36334970a37510cc95d46b700277 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 4 Dec 2024 11:21:22 -0800 Subject: [PATCH 10/10] Fixed formatting --- packages/data-connect/src/api/DataConnect.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/data-connect/src/api/DataConnect.ts b/packages/data-connect/src/api/DataConnect.ts index 6d93b21379e..30ec344f3ef 100644 --- a/packages/data-connect/src/api/DataConnect.ts +++ b/packages/data-connect/src/api/DataConnect.ts @@ -196,9 +196,9 @@ export class DataConnect { /** * @internal - * @param transportOptions1 - * @param transportOptions2 - * @returns + * @param transportOptions1 + * @param transportOptions2 + * @returns */ export function areTransportOptionsEqual( transportOptions1: TransportOptions,