Skip to content

Commit c19a051

Browse files
authoredJan 9, 2025··
Updated FDC to include promise instead of promiselike (#8667)
1 parent a133053 commit c19a051

File tree

8 files changed

+38
-41
lines changed

8 files changed

+38
-41
lines changed
 

Diff for: ‎.changeset/tame-tigers-approve.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/data-connect": minor
3+
"firebase": minor
4+
---
5+
6+
Updated to include promise instead of promiselike

Diff for: ‎common/api-review/data-connect.api.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ import { FirebaseError } from '@firebase/util';
1111
import { LogLevelString } from '@firebase/logger';
1212
import { Provider } from '@firebase/component';
1313

14-
// @public (undocumented)
15-
export interface CancellableOperation<T> extends PromiseLike<{
16-
data: T;
17-
}> {
18-
// (undocumented)
19-
cancel: () => void;
20-
}
21-
2214
// @public
2315
export function connectDataConnectEmulator(dc: DataConnect, host: string, port?: number, sslEnabled?: boolean): void;
2416

@@ -88,7 +80,7 @@ export function getDataConnect(app: FirebaseApp, options: ConnectorConfig): Data
8880
export const MUTATION_STR = "mutation";
8981

9082
// @public
91-
export interface MutationPromise<Data, Variables> extends PromiseLike<MutationResult<Data, Variables>> {
83+
export interface MutationPromise<Data, Variables> extends Promise<MutationResult<Data, Variables>> {
9284
}
9385

9486
// @public (undocumented)
@@ -144,7 +136,7 @@ export interface OpResult<Data> {
144136
export const QUERY_STR = "query";
145137

146138
// @public
147-
export interface QueryPromise<Data, Variables> extends PromiseLike<QueryResult<Data, Variables>> {
139+
export interface QueryPromise<Data, Variables> extends Promise<QueryResult<Data, Variables>> {
148140
}
149141

150142
// @public

Diff for: ‎packages/data-connect/src/api/Mutation.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function mutationRef<Data, Variables>(
7676
* @internal
7777
*/
7878
export class MutationManager {
79-
private _inflight: Array<PromiseLike<unknown>> = [];
79+
private _inflight: Array<Promise<unknown>> = [];
8080
constructor(private _transport: DataConnectTransport) {}
8181
executeMutation<Data, Variables>(
8282
mutationRef: MutationRef<Data, Variables>
@@ -95,7 +95,7 @@ export class MutationManager {
9595
return obj;
9696
});
9797
this._inflight.push(result);
98-
const removePromise = (): Array<PromiseLike<unknown>> =>
98+
const removePromise = (): Array<Promise<unknown>> =>
9999
(this._inflight = this._inflight.filter(promise => promise !== result));
100100
result.then(removePromise, removePromise);
101101
return withRefPromise;
@@ -113,7 +113,7 @@ export interface MutationResult<Data, Variables>
113113
* Mutation return value from `executeMutation`
114114
*/
115115
export interface MutationPromise<Data, Variables>
116-
extends PromiseLike<MutationResult<Data, Variables>> {
116+
extends Promise<MutationResult<Data, Variables>> {
117117
// reserved for special actions like cancellation
118118
}
119119

Diff for: ‎packages/data-connect/src/api/query.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface QueryResult<Data, Variables>
6767
* Promise returned from `executeQuery`
6868
*/
6969
export interface QueryPromise<Data, Variables>
70-
extends PromiseLike<QueryResult<Data, Variables>> {
70+
extends Promise<QueryResult<Data, Variables>> {
7171
// reserved for special actions like cancellation
7272
}
7373

@@ -124,7 +124,7 @@ export function queryRef<Data, Variables>(
124124
dataConnect: dcInstance,
125125
refType: QUERY_STR,
126126
name: queryName,
127-
variables: variables as Variables
127+
variables: variables
128128
};
129129
}
130130
/**

Diff for: ‎packages/data-connect/src/network/fetch.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ function getGoogApiClientValue(_isUsingGen: boolean): string {
3030
}
3131
return str;
3232
}
33+
export interface DataConnectFetchBody<T> {
34+
name: string;
35+
operationName: string;
36+
variables: T;
37+
}
3338
export function dcFetch<T, U>(
3439
url: string,
35-
body: U,
40+
body: DataConnectFetchBody<U>,
3641
{ signal }: AbortController,
3742
appId: string | null,
3843
accessToken: string | null,
@@ -95,7 +100,7 @@ export function dcFetch<T, U>(
95100
logError('DataConnect error while performing request: ' + stringified);
96101
throw new DataConnectError(Code.OTHER, stringified);
97102
}
98-
return res as { data: T; errors: Error[] };
103+
return res;
99104
});
100105
}
101106
interface MessageObject {

Diff for: ‎packages/data-connect/src/network/transport/index.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,15 @@ export interface DataConnectTransport {
2626
invokeQuery<T, U>(
2727
queryName: string,
2828
body?: U
29-
): PromiseLike<{ data: T; errors: Error[] }>;
29+
): Promise<{ data: T; errors: Error[] }>;
3030
invokeMutation<T, U>(
3131
queryName: string,
3232
body?: U
33-
): PromiseLike<{ data: T; errors: Error[] }>;
33+
): Promise<{ data: T; errors: Error[] }>;
3434
useEmulator(host: string, port?: number, sslEnabled?: boolean): void;
3535
onTokenChanged: (token: string | null) => void;
3636
}
3737

38-
export interface CancellableOperation<T> extends PromiseLike<{ data: T }> {
39-
cancel: () => void;
40-
}
41-
4238
/**
4339
* @internal
4440
*/

Diff for: ‎packages/data-connect/src/network/transport/rest.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class RESTTransport implements DataConnectTransport {
161161
invokeQuery: <T, U>(
162162
queryName: string,
163163
body?: U
164-
) => PromiseLike<{ data: T; errors: Error[] }> = <T, U = unknown>(
164+
) => Promise<{ data: T; errors: Error[] }> = <T, U = unknown>(
165165
queryName: string,
166166
body: U
167167
) => {
@@ -174,24 +174,20 @@ export class RESTTransport implements DataConnectTransport {
174174
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
175175
operationName: queryName,
176176
variables: body
177-
} as unknown as U, // TODO(mtewani): This is a patch, fix this.
177+
},
178178
abortController,
179179
this.appId,
180180
this._accessToken,
181181
this._appCheckToken,
182182
this._isUsingGen
183183
)
184184
);
185-
186-
return {
187-
then: withAuth.then.bind(withAuth),
188-
catch: withAuth.catch.bind(withAuth)
189-
};
185+
return withAuth;
190186
};
191187
invokeMutation: <T, U>(
192188
queryName: string,
193189
body?: U
194-
) => PromiseLike<{ data: T; errors: Error[] }> = <T, U = unknown>(
190+
) => Promise<{ data: T; errors: Error[] }> = <T, U = unknown>(
195191
mutationName: string,
196192
body: U
197193
) => {
@@ -203,20 +199,14 @@ export class RESTTransport implements DataConnectTransport {
203199
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
204200
operationName: mutationName,
205201
variables: body
206-
} as unknown as U,
202+
},
207203
abortController,
208204
this.appId,
209205
this._accessToken,
210206
this._appCheckToken,
211207
this._isUsingGen
212208
);
213209
});
214-
215-
return {
216-
then: taskResult.then.bind(taskResult),
217-
// catch: taskResult.catch.bind(taskResult),
218-
// finally: taskResult.finally.bind(taskResult),
219-
cancel: () => abortController.abort()
220-
};
210+
return taskResult;
221211
};
222212
}

Diff for: ‎packages/data-connect/test/unit/fetch.test.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ describe('fetch', () => {
4242
await expect(
4343
dcFetch(
4444
'http://localhost',
45-
{},
45+
{
46+
name: 'n',
47+
operationName: 'n',
48+
variables: {}
49+
},
4650
{} as AbortController,
4751
null,
4852
null,
@@ -61,7 +65,11 @@ describe('fetch', () => {
6165
await expect(
6266
dcFetch(
6367
'http://localhost',
64-
{},
68+
{
69+
name: 'n',
70+
operationName: 'n',
71+
variables: {}
72+
},
6573
{} as AbortController,
6674
null,
6775
null,

0 commit comments

Comments
 (0)
Please sign in to comment.