From 02bca9375ca8cc60171ed71cea915c5c5190902e Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 5 Dec 2024 16:50:29 -0800 Subject: [PATCH 01/10] Updated to include promise instead of promiselike --- packages/data-connect/src/api/Mutation.ts | 6 ++--- packages/data-connect/src/api/query.ts | 4 ++-- .../data-connect/src/core/QueryManager.ts | 7 +++--- packages/data-connect/src/network/fetch.ts | 9 ++++++-- .../src/network/transport/index.ts | 6 ++--- .../src/network/transport/rest.ts | 22 +++++-------------- packages/data-connect/test/unit/fetch.test.ts | 12 ++++++++-- 7 files changed, 34 insertions(+), 32 deletions(-) diff --git a/packages/data-connect/src/api/Mutation.ts b/packages/data-connect/src/api/Mutation.ts index ca2efdb7a30..570b28b0eab 100644 --- a/packages/data-connect/src/api/Mutation.ts +++ b/packages/data-connect/src/api/Mutation.ts @@ -76,7 +76,7 @@ export function mutationRef( * @internal */ export class MutationManager { - private _inflight: Array> = []; + private _inflight: Array> = []; constructor(private _transport: DataConnectTransport) {} executeMutation( mutationRef: MutationRef @@ -95,7 +95,7 @@ export class MutationManager { return obj; }); this._inflight.push(result); - const removePromise = (): Array> => + const removePromise = (): Array> => (this._inflight = this._inflight.filter(promise => promise !== result)); result.then(removePromise, removePromise); return withRefPromise; @@ -113,7 +113,7 @@ export interface MutationResult * Mutation return value from `executeMutation` */ export interface MutationPromise - extends PromiseLike> { + extends Promise> { // reserved for special actions like cancellation } diff --git a/packages/data-connect/src/api/query.ts b/packages/data-connect/src/api/query.ts index a4ab17b7ceb..00382686dab 100644 --- a/packages/data-connect/src/api/query.ts +++ b/packages/data-connect/src/api/query.ts @@ -67,7 +67,7 @@ export interface QueryResult * Promise returned from `executeQuery` */ export interface QueryPromise - extends PromiseLike> { + extends Promise> { // reserved for special actions like cancellation } @@ -124,7 +124,7 @@ export function queryRef( dataConnect: dcInstance, refType: QUERY_STR, name: queryName, - variables: variables as Variables + variables: variables }; } /** diff --git a/packages/data-connect/src/core/QueryManager.ts b/packages/data-connect/src/core/QueryManager.ts index 8b7c59aea85..f20dfaa44e9 100644 --- a/packages/data-connect/src/core/QueryManager.ts +++ b/packages/data-connect/src/core/QueryManager.ts @@ -105,10 +105,9 @@ export class QueryManager { variables: queryRef.variables, refType: QUERY_STR }); - const trackedQuery = this._queries.get(key) as TrackedQuery< - Data, - Variables - >; + const trackedQuery: TrackedQuery = this._queries.get( + key + ) as TrackedQuery; const subscription = { userCallback: onResultCallback, errCallback: onErrorCallback diff --git a/packages/data-connect/src/network/fetch.ts b/packages/data-connect/src/network/fetch.ts index 06ef6dd8285..d5d2a439432 100644 --- a/packages/data-connect/src/network/fetch.ts +++ b/packages/data-connect/src/network/fetch.ts @@ -30,9 +30,14 @@ function getGoogApiClientValue(_isUsingGen: boolean): string { } return str; } +export interface DataConnectFetchBody { + name: string; + operationName: string; + variables: T; +} export function dcFetch( url: string, - body: U, + body: DataConnectFetchBody, { signal }: AbortController, appId: string | null, accessToken: string | null, @@ -95,7 +100,7 @@ export function dcFetch( logError('DataConnect error while performing request: ' + stringified); throw new DataConnectError(Code.OTHER, stringified); } - return res as { data: T; errors: Error[] }; + return res; }); } interface MessageObject { diff --git a/packages/data-connect/src/network/transport/index.ts b/packages/data-connect/src/network/transport/index.ts index 5518faa0f95..bd7ce604ac5 100644 --- a/packages/data-connect/src/network/transport/index.ts +++ b/packages/data-connect/src/network/transport/index.ts @@ -26,16 +26,16 @@ export interface DataConnectTransport { invokeQuery( queryName: string, body?: U - ): PromiseLike<{ data: T; errors: Error[] }>; + ): Promise<{ data: T; errors: Error[] }>; invokeMutation( queryName: string, body?: U - ): PromiseLike<{ data: T; errors: Error[] }>; + ): Promise<{ data: T; errors: Error[] }>; useEmulator(host: string, port?: number, sslEnabled?: boolean): void; onTokenChanged: (token: string | null) => void; } -export interface CancellableOperation extends PromiseLike<{ data: T }> { +export interface CancellableOperation extends Promise<{ data: T }> { cancel: () => void; } diff --git a/packages/data-connect/src/network/transport/rest.ts b/packages/data-connect/src/network/transport/rest.ts index 85847868c5d..0a49fc9e269 100644 --- a/packages/data-connect/src/network/transport/rest.ts +++ b/packages/data-connect/src/network/transport/rest.ts @@ -161,7 +161,7 @@ export class RESTTransport implements DataConnectTransport { invokeQuery: ( queryName: string, body?: U - ) => PromiseLike<{ data: T; errors: Error[] }> = ( + ) => Promise<{ data: T; errors: Error[] }> = ( queryName: string, body: U ) => { @@ -174,7 +174,7 @@ export class RESTTransport implements DataConnectTransport { name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`, operationName: queryName, variables: body - } as unknown as U, // TODO(mtewani): This is a patch, fix this. + }, abortController, this.appId, this._accessToken, @@ -182,16 +182,12 @@ export class RESTTransport implements DataConnectTransport { this._isUsingGen ) ); - - return { - then: withAuth.then.bind(withAuth), - catch: withAuth.catch.bind(withAuth) - }; + return withAuth; }; invokeMutation: ( queryName: string, body?: U - ) => PromiseLike<{ data: T; errors: Error[] }> = ( + ) => Promise<{ data: T; errors: Error[] }> = ( mutationName: string, body: U ) => { @@ -203,7 +199,7 @@ export class RESTTransport implements DataConnectTransport { name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`, operationName: mutationName, variables: body - } as unknown as U, + }, abortController, this.appId, this._accessToken, @@ -211,12 +207,6 @@ export class RESTTransport implements DataConnectTransport { this._isUsingGen ); }); - - return { - then: taskResult.then.bind(taskResult), - // catch: taskResult.catch.bind(taskResult), - // finally: taskResult.finally.bind(taskResult), - cancel: () => abortController.abort() - }; + return taskResult; }; } diff --git a/packages/data-connect/test/unit/fetch.test.ts b/packages/data-connect/test/unit/fetch.test.ts index a50ac188724..3d9a9b04523 100644 --- a/packages/data-connect/test/unit/fetch.test.ts +++ b/packages/data-connect/test/unit/fetch.test.ts @@ -42,7 +42,11 @@ describe('fetch', () => { await expect( dcFetch( 'http://localhost', - {}, + { + name: 'n', + operationName: 'n', + variables: {} + }, {} as AbortController, null, null, @@ -61,7 +65,11 @@ describe('fetch', () => { await expect( dcFetch( 'http://localhost', - {}, + { + name: 'n', + operationName: 'n', + variables: {} + }, {} as AbortController, null, null, From 78257890cd2980210cd1ab9a477c23db5919d299 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 5 Dec 2024 16:51:32 -0800 Subject: [PATCH 02/10] Updated API --- common/api-review/data-connect.api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/api-review/data-connect.api.md b/common/api-review/data-connect.api.md index b2c6fb01931..6aa6ea16a8d 100644 --- a/common/api-review/data-connect.api.md +++ b/common/api-review/data-connect.api.md @@ -12,7 +12,7 @@ import { LogLevelString } from '@firebase/logger'; import { Provider } from '@firebase/component'; // @public (undocumented) -export interface CancellableOperation extends PromiseLike<{ +export interface CancellableOperation extends Promise<{ data: T; }> { // (undocumented) @@ -88,7 +88,7 @@ export function getDataConnect(app: FirebaseApp, options: ConnectorConfig): Data export const MUTATION_STR = "mutation"; // @public -export interface MutationPromise extends PromiseLike> { +export interface MutationPromise extends Promise> { } // @public (undocumented) @@ -144,7 +144,7 @@ export interface OpResult { export const QUERY_STR = "query"; // @public -export interface QueryPromise extends PromiseLike> { +export interface QueryPromise extends Promise> { } // @public From 599db1cacde9d2ce14e4ef0ce48df9e9619fcef4 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 5 Dec 2024 16:51:44 -0800 Subject: [PATCH 03/10] Create tame-tigers-approve.md --- .changeset/tame-tigers-approve.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tame-tigers-approve.md diff --git a/.changeset/tame-tigers-approve.md b/.changeset/tame-tigers-approve.md new file mode 100644 index 00000000000..3b9a0571c9b --- /dev/null +++ b/.changeset/tame-tigers-approve.md @@ -0,0 +1,5 @@ +--- +"@firebase/data-connect": patch +--- + +Updated to include promise instead of promiselike From 92b889d8b24c39c3cf1b3eca9c18b558dafd91df Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 5 Dec 2024 16:52:46 -0800 Subject: [PATCH 04/10] Removed unnecessary interface --- packages/data-connect/src/network/transport/index.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/data-connect/src/network/transport/index.ts b/packages/data-connect/src/network/transport/index.ts index bd7ce604ac5..f4bb801f9b3 100644 --- a/packages/data-connect/src/network/transport/index.ts +++ b/packages/data-connect/src/network/transport/index.ts @@ -35,10 +35,6 @@ export interface DataConnectTransport { onTokenChanged: (token: string | null) => void; } -export interface CancellableOperation extends Promise<{ data: T }> { - cancel: () => void; -} - /** * @internal */ From 9c04231b14009ec7b5fbe932b39c5728b252e539 Mon Sep 17 00:00:00 2001 From: maneesht Date: Fri, 6 Dec 2024 01:03:54 +0000 Subject: [PATCH 05/10] Update API reports --- common/api-review/data-connect.api.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/common/api-review/data-connect.api.md b/common/api-review/data-connect.api.md index 6aa6ea16a8d..952d8b4dc10 100644 --- a/common/api-review/data-connect.api.md +++ b/common/api-review/data-connect.api.md @@ -11,14 +11,6 @@ import { FirebaseError } from '@firebase/util'; import { LogLevelString } from '@firebase/logger'; import { Provider } from '@firebase/component'; -// @public (undocumented) -export interface CancellableOperation extends Promise<{ - data: T; -}> { - // (undocumented) - cancel: () => void; -} - // @public export function connectDataConnectEmulator(dc: DataConnect, host: string, port?: number, sslEnabled?: boolean): void; From f2b8be0cec0708eb8d93edb3b4532294e44be581 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 8 Jan 2025 16:41:02 -0800 Subject: [PATCH 06/10] Addressed review feedback --- packages/data-connect/src/core/QueryManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-connect/src/core/QueryManager.ts b/packages/data-connect/src/core/QueryManager.ts index f20dfaa44e9..8049d0593a7 100644 --- a/packages/data-connect/src/core/QueryManager.ts +++ b/packages/data-connect/src/core/QueryManager.ts @@ -105,7 +105,7 @@ export class QueryManager { variables: queryRef.variables, refType: QUERY_STR }); - const trackedQuery: TrackedQuery = this._queries.get( + const trackedQuery = this._queries.get( key ) as TrackedQuery; const subscription = { From c486948ac89f98f482a39afdf03622c88d5f8767 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 8 Jan 2025 16:51:51 -0800 Subject: [PATCH 07/10] Formatting --- packages/data-connect/src/core/QueryManager.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/data-connect/src/core/QueryManager.ts b/packages/data-connect/src/core/QueryManager.ts index 8049d0593a7..8b7c59aea85 100644 --- a/packages/data-connect/src/core/QueryManager.ts +++ b/packages/data-connect/src/core/QueryManager.ts @@ -105,9 +105,10 @@ export class QueryManager { variables: queryRef.variables, refType: QUERY_STR }); - const trackedQuery = this._queries.get( - key - ) as TrackedQuery; + const trackedQuery = this._queries.get(key) as TrackedQuery< + Data, + Variables + >; const subscription = { userCallback: onResultCallback, errCallback: onErrorCallback From ecd67cee5bc17066df61c6c3c8b385ca85d4e9b4 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 9 Jan 2025 09:38:13 -0800 Subject: [PATCH 08/10] Updated patch to minor --- .changeset/tame-tigers-approve.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tame-tigers-approve.md b/.changeset/tame-tigers-approve.md index 3b9a0571c9b..dcab0648901 100644 --- a/.changeset/tame-tigers-approve.md +++ b/.changeset/tame-tigers-approve.md @@ -1,5 +1,5 @@ --- -"@firebase/data-connect": patch +"@firebase/data-connect": minor --- Updated to include promise instead of promiselike From 877ee8e1f172b241b85113e68bd85730e6ae73f3 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 9 Jan 2025 09:45:55 -0800 Subject: [PATCH 09/10] Bump upload artifact version --- .github/workflows/test-all.yml | 2 +- .github/workflows/test-changed-firestore.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index 68983f50a38..2c31784a98f 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -57,7 +57,7 @@ jobs: gzip build.tar - name: Upload build archive if: ${{ !cancelled() }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: build.tar.gz path: build.tar.gz diff --git a/.github/workflows/test-changed-firestore.yml b/.github/workflows/test-changed-firestore.yml index 259e9164d7f..3e4c2f45d74 100644 --- a/.github/workflows/test-changed-firestore.yml +++ b/.github/workflows/test-changed-firestore.yml @@ -72,7 +72,7 @@ jobs: gzip build.tar - name: Upload build archive if: ${{ !cancelled() && steps.build.outcome == 'success' && steps.check-changed.outcome != 'success' }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: build.tar.gz path: build.tar.gz From c94a9ca921ad404f30b28ba0cb864e810db7e14a Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 9 Jan 2025 09:55:02 -0800 Subject: [PATCH 10/10] Bumped firebase minor --- .changeset/tame-tigers-approve.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/tame-tigers-approve.md b/.changeset/tame-tigers-approve.md index dcab0648901..42ce75ecfc0 100644 --- a/.changeset/tame-tigers-approve.md +++ b/.changeset/tame-tigers-approve.md @@ -1,5 +1,6 @@ --- "@firebase/data-connect": minor +"firebase": minor --- Updated to include promise instead of promiselike