@firebase/data-connect 0.5.0 → 0.6.0-20260408221811

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/index.cjs.js +1165 -143
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm.js +1164 -144
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.node.cjs.js +1231 -190
  6. package/dist/index.node.cjs.js.map +1 -1
  7. package/dist/internal.d.ts +133 -12
  8. package/dist/node-esm/index.node.esm.js +1230 -191
  9. package/dist/node-esm/index.node.esm.js.map +1 -1
  10. package/dist/node-esm/src/api/Mutation.d.ts +2 -2
  11. package/dist/node-esm/src/api/query.d.ts +1 -1
  12. package/dist/node-esm/src/core/query/QueryManager.d.ts +22 -3
  13. package/dist/node-esm/src/network/index.d.ts +1 -1
  14. package/dist/node-esm/src/network/manager.d.ts +61 -0
  15. package/dist/node-esm/src/network/{fetch.d.ts → rest/fetch.d.ts} +9 -4
  16. package/dist/node-esm/src/network/rest/index.d.ts +18 -0
  17. package/dist/node-esm/src/network/rest/restTransport.d.ts +33 -0
  18. package/dist/node-esm/src/network/stream/streamTransport.d.ts +241 -0
  19. package/dist/node-esm/src/network/stream/websocket.d.ts +90 -0
  20. package/dist/node-esm/src/network/stream/wire.d.ts +138 -0
  21. package/dist/node-esm/src/network/transport.d.ts +179 -0
  22. package/dist/node-esm/src/util/url.d.ts +3 -1
  23. package/dist/private.d.ts +29 -7
  24. package/dist/public.d.ts +3 -1
  25. package/dist/src/api/Mutation.d.ts +2 -2
  26. package/dist/src/api/query.d.ts +1 -1
  27. package/dist/src/core/query/QueryManager.d.ts +22 -3
  28. package/dist/src/network/index.d.ts +1 -1
  29. package/dist/src/network/manager.d.ts +61 -0
  30. package/dist/src/network/{fetch.d.ts → rest/fetch.d.ts} +9 -4
  31. package/dist/src/network/rest/index.d.ts +18 -0
  32. package/dist/src/network/rest/restTransport.d.ts +33 -0
  33. package/dist/src/network/stream/streamTransport.d.ts +241 -0
  34. package/dist/src/network/stream/websocket.d.ts +90 -0
  35. package/dist/src/network/stream/wire.d.ts +138 -0
  36. package/dist/src/network/transport.d.ts +179 -0
  37. package/dist/src/util/url.d.ts +3 -1
  38. package/package.json +1 -1
  39. package/dist/node-esm/src/network/transport/index.d.ts +0 -81
  40. package/dist/node-esm/src/network/transport/rest.d.ts +0 -49
  41. package/dist/src/network/transport/index.d.ts +0 -81
  42. package/dist/src/network/transport/rest.d.ts +0 -49
@@ -0,0 +1,138 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Extensions } from '../index';
18
+ /**
19
+ * Shape of response from the server.
20
+ * @internal
21
+ */
22
+ export interface DataConnectStreamResponse<Data> {
23
+ requestId: string;
24
+ data: Data;
25
+ extensions: Extensions;
26
+ dataEtag: string;
27
+ errors: Error[];
28
+ cancelled: boolean;
29
+ }
30
+ /**
31
+ * Base interface for stream request payloads sent over the stream to the server.
32
+ * @internal
33
+ */
34
+ export interface StreamRequest {
35
+ /** monotonically increasing request ID */
36
+ requestId: string;
37
+ /** connectorResourcePath - only required on initial connection */
38
+ name?: string;
39
+ /** optional headers for this request, for authentication + telemetry */
40
+ headers?: StreamRequestHeaders;
41
+ /** received from server on previous response, included to optimize bandwidth */
42
+ dataEtag?: string;
43
+ }
44
+ /**
45
+ * Optional headers for a stream request, for authentication + telemetry
46
+ * @internal
47
+ */
48
+ export interface StreamRequestHeaders {
49
+ /** used to initially authenticate or re-authenticate */
50
+ authToken?: string;
51
+ /** used to initially authenticate or re-authenticate */
52
+ appCheckToken?: string;
53
+ /** SDK telemetry header */
54
+ 'X-Goog-Api-Client'?: string;
55
+ /** firebase appid */
56
+ 'x-firebase-gmpid'?: string;
57
+ }
58
+ /**
59
+ * Fields for an execute request payload.
60
+ * @internal
61
+ */
62
+ interface ExecuteRequestKind<Variables> {
63
+ operationName: string;
64
+ variables?: Variables;
65
+ }
66
+ /**
67
+ * Fields for a subscribe request payload.
68
+ * @internal
69
+ */
70
+ interface SubscribeRequestKind<Variables> {
71
+ operationName: string;
72
+ variables?: Variables;
73
+ }
74
+ /**
75
+ * Fields for a resume request payload.
76
+ * @internal
77
+ */
78
+ interface ResumeRequestKind {
79
+ }
80
+ /**
81
+ * Fields for a cancel request payload.
82
+ * @internal
83
+ */
84
+ interface CancelRequestKind {
85
+ }
86
+ /**
87
+ * Fields for a subscribe request payload.
88
+ * @internal
89
+ */
90
+ export interface SubscribeStreamRequest<Variables> extends StreamRequest {
91
+ subscribe: SubscribeRequestKind<Variables>;
92
+ execute?: never;
93
+ resume?: never;
94
+ cancel?: never;
95
+ }
96
+ /**
97
+ * Fields for an execute request payload.
98
+ * @internal
99
+ */
100
+ export interface ExecuteStreamRequest<Variables> extends StreamRequest {
101
+ execute: ExecuteRequestKind<Variables>;
102
+ subscribe?: never;
103
+ resume?: never;
104
+ cancel?: never;
105
+ }
106
+ /**
107
+ * Fields for a resume (subscribe) request payload.
108
+ * @internal
109
+ */
110
+ export interface ResumeStreamRequest extends StreamRequest {
111
+ resume: ResumeRequestKind;
112
+ subscribe?: never;
113
+ execute?: never;
114
+ cancel?: never;
115
+ }
116
+ /**
117
+ * Fields for a cancel (unsubscribe) request payload.
118
+ * @internal
119
+ */
120
+ export interface CancelStreamRequest extends StreamRequest {
121
+ cancel: CancelRequestKind;
122
+ subscribe?: never;
123
+ execute?: never;
124
+ resume?: never;
125
+ }
126
+ /**
127
+ * Shape of the request body to be sent over the stream to the server.
128
+ * @internal
129
+ */
130
+ export type DataConnectStreamRequest<Variables> = ExecuteStreamRequest<Variables> | SubscribeStreamRequest<Variables> | ResumeStreamRequest | CancelStreamRequest;
131
+ /**
132
+ * Determines whether the provided request to execute a query is an execution request or a resume
133
+ * request
134
+ * @returns true if the requestBody is a resume request
135
+ * @internal
136
+ */
137
+ export declare function queryRequestIsResume<Variables>(requestBody: ExecuteStreamRequest<Variables> | ResumeStreamRequest): requestBody is ResumeStreamRequest;
138
+ export {};
@@ -0,0 +1,179 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { DataConnectOptions, TransportOptions } from '../api/DataConnect';
18
+ import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
19
+ import { AuthTokenProvider } from '../core/FirebaseAuthProvider';
20
+ /**
21
+ * enum representing different flavors of the SDK used by developers
22
+ * use the CallerSdkType for type-checking, and the CallerSdkTypeEnum for value-checking/assigning
23
+ */
24
+ export type CallerSdkType = 'Base' | 'Generated' | 'TanstackReactCore' | 'GeneratedReact' | 'TanstackAngularCore' | 'GeneratedAngular';
25
+ export declare const CallerSdkTypeEnum: {
26
+ readonly Base: "Base";
27
+ readonly Generated: "Generated";
28
+ readonly TanstackReactCore: "TanstackReactCore";
29
+ readonly GeneratedReact: "GeneratedReact";
30
+ readonly TanstackAngularCore: "TanstackAngularCore";
31
+ readonly GeneratedAngular: "GeneratedAngular";
32
+ };
33
+ export interface DataConnectEntityArray {
34
+ entityIds: string[];
35
+ }
36
+ export interface DataConnectSingleEntity {
37
+ entityId: string;
38
+ }
39
+ export type DataConnectExtension = {
40
+ path: Array<string | number>;
41
+ } & (DataConnectEntityArray | DataConnectSingleEntity);
42
+ /** @internal */
43
+ export interface DataConnectMaxAge {
44
+ maxAge: string;
45
+ }
46
+ /** @internal */
47
+ export type DataConnectExtensionWithMaxAge = {
48
+ path: Array<string | number>;
49
+ } & (DataConnectEntityArray | DataConnectSingleEntity | DataConnectMaxAge);
50
+ export interface Extensions {
51
+ dataConnect?: DataConnectExtension[];
52
+ }
53
+ /** @internal */
54
+ export interface ExtensionsWithMaxAge {
55
+ dataConnect?: DataConnectExtensionWithMaxAge[];
56
+ }
57
+ /** @internal */
58
+ export interface DataConnectResponse<T> {
59
+ data: T;
60
+ errors: Error[];
61
+ extensions: Extensions;
62
+ }
63
+ /** @internal */
64
+ export interface DataConnectResponseWithMaxAge<T> {
65
+ data: T;
66
+ errors: Error[];
67
+ extensions: ExtensionsWithMaxAge;
68
+ }
69
+ /**
70
+ * Observer defined by the Query Layer for receiving notifications from the Transport Layer.
71
+ * @internal
72
+ */
73
+ export interface SubscribeObserver<Data> {
74
+ onData(response: DataConnectResponse<Data>): Promise<void> | void;
75
+ onDisconnect(code: string, reason: string): void;
76
+ onError(error: Error): void;
77
+ }
78
+ /**
79
+ * Interface defining the external API of the transport layer.
80
+ * @internal
81
+ */
82
+ export interface DataConnectTransportInterface {
83
+ /**
84
+ * Invoke a query execution request.
85
+ * @param queryName The name of the query to execute.
86
+ * @param body The variables associated with the query.
87
+ * @returns A promise resolving to the DataConnectResponse.
88
+ */
89
+ invokeQuery<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponseWithMaxAge<Data>>;
90
+ /**
91
+ * Invoke a mutation execution request.
92
+ * @param queryName The name of the mutation to execute.
93
+ * @param body The variables associated with the mutation.
94
+ * @returns A promise resolving to the DataConnectResponse.
95
+ */
96
+ invokeMutation<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponse<Data>>;
97
+ /**
98
+ * Subscribes to a query to receive push notifications of updates.
99
+ * @param observer the observer passed to the transport layer to notify the query layer of events.
100
+ * @param queryName The name of the query to subscribe to.
101
+ * @param body The variables associated with the subscription.
102
+ */
103
+ invokeSubscribe<Data, Variables>(observer: SubscribeObserver<Data>, queryName: string, body?: Variables): void;
104
+ /**
105
+ * Unsubscribes from an active subscription.
106
+ * @param queryName The name of the query to unsubscribe from.
107
+ * @param body The variables associated with the subscription.
108
+ */
109
+ invokeUnsubscribe<Variables>(queryName: string, body?: Variables): void;
110
+ /**
111
+ * Configures the transport to use a local Data Connect emulator.
112
+ * @param host The host address of the emulator (e.g., '127.0.0.1').
113
+ * @param port The port number the emulator is listening on.
114
+ * @param sslEnabled Whether to use SSL (HTTPS/WSS) for the emulator connection.
115
+ */
116
+ useEmulator(host: string, port?: number, sslEnabled?: boolean): void;
117
+ /**
118
+ * Callback invoked when the Firebase Auth token is refreshed or changed. Note that this callback
119
+ * is called immediately asynchronously when the Auth Provider is initialized to provide
120
+ * the initial auth state.
121
+ * @param token The new access token or null if signed out.
122
+ */
123
+ onAuthTokenChanged: (token: string | null) => void;
124
+ /**
125
+ * Internal method to set the SDK type for metrics and logging purposes.
126
+ * @param callerSdkType The type of SDK making the call (e.g., generated vs base).
127
+ */
128
+ _setCallerSdkType(callerSdkType: CallerSdkType): void;
129
+ }
130
+ /**
131
+ * Type signature of a transport class constructor.
132
+ * @internal
133
+ */
134
+ export type TransportClass = new (options: DataConnectOptions, apiKey?: string, appId?: string, authProvider?: AuthTokenProvider, appCheckProvider?: AppCheckTokenProvider, transportOptions?: TransportOptions, _isUsingGen?: boolean, _callerSdkType?: CallerSdkType) => DataConnectTransportInterface;
135
+ /**
136
+ * Constructs the value for the X-Goog-Api-Client header
137
+ * @internal
138
+ */
139
+ export declare function getGoogApiClientValue(isUsingGen: boolean, callerSdkType: CallerSdkType): string;
140
+ /**
141
+ * The base class for all DataConnectTransportInterface implementations. Handles common logic such as
142
+ * URL construction, auth token management, and emulator usage. Concrete transport implementations
143
+ * should extend this class and implement the abstract {@link DataConnectTransportInterface} methods.
144
+ * @internal
145
+ */
146
+ export declare abstract class AbstractDataConnectTransport implements DataConnectTransportInterface {
147
+ protected apiKey?: string | undefined;
148
+ protected appId?: (string | null) | undefined;
149
+ protected authProvider?: AuthTokenProvider | undefined;
150
+ protected appCheckProvider?: AppCheckTokenProvider | undefined;
151
+ protected _isUsingGen: boolean;
152
+ protected _callerSdkType: CallerSdkType;
153
+ protected _host: string;
154
+ protected _port: number | undefined;
155
+ protected _location: string;
156
+ protected _connectorName: string;
157
+ /** The resource path for requests from this Data Connect instance. */
158
+ protected _connectorResourcePath: string;
159
+ protected _secure: boolean;
160
+ protected _project: string;
161
+ protected _serviceName: string;
162
+ protected _authToken: string | null;
163
+ protected _appCheckToken: string | null | undefined;
164
+ protected _lastToken: string | null;
165
+ protected _isUsingEmulator: boolean;
166
+ constructor(options: DataConnectOptions, apiKey?: string | undefined, appId?: (string | null) | undefined, authProvider?: AuthTokenProvider | undefined, appCheckProvider?: AppCheckTokenProvider | undefined, transportOptions?: TransportOptions | undefined, _isUsingGen?: boolean, _callerSdkType?: CallerSdkType);
167
+ /** Get the endpoint URL this transport should use to communicate with the backend. */
168
+ abstract get endpointUrl(): string;
169
+ useEmulator(host: string, port?: number, isSecure?: boolean): void;
170
+ getWithAuth(forceToken?: boolean): Promise<string | null>;
171
+ withRetry<T>(promiseFactory: () => Promise<DataConnectResponse<T>>, retry?: boolean): Promise<DataConnectResponse<T>>;
172
+ _setLastToken(lastToken: string | null): void;
173
+ abstract invokeQuery<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponseWithMaxAge<Data>>;
174
+ abstract invokeMutation<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponse<Data>>;
175
+ abstract invokeSubscribe<Data, Variables>(observer: SubscribeObserver<Data>, queryName: string, body?: Variables): void;
176
+ abstract invokeUnsubscribe<Variables>(queryName: string, variables: Variables): void;
177
+ abstract onAuthTokenChanged(newToken: string | null): void;
178
+ _setCallerSdkType(callerSdkType: CallerSdkType): void;
179
+ }
@@ -16,5 +16,7 @@
16
16
  */
17
17
  import { DataConnectOptions, TransportOptions } from '../api/DataConnect';
18
18
  export declare const PROD_HOST = "firebasedataconnect.googleapis.com";
19
- export declare function urlBuilder(projectConfig: DataConnectOptions, transportOptions: TransportOptions): string;
19
+ export declare const WEBSOCKET_PATH = "ws/google.firebase.dataconnect.v1.ConnectorStreamService";
20
+ export declare function restUrlBuilder(projectConfig: DataConnectOptions, transportOptions: TransportOptions): string;
21
+ export declare function websocketUrlBuilder(projectConfig: DataConnectOptions, transportOptions: TransportOptions): string;
20
22
  export declare function addToken(url: string, apiKey?: string): string;
package/dist/private.d.ts CHANGED
@@ -15,6 +15,8 @@ import { FirebaseError } from '@firebase/util';
15
15
  import { LogLevelString } from '@firebase/logger';
16
16
  import { Provider } from '@firebase/component';
17
17
 
18
+ /* Excluded from this release type: AbstractDataConnectTransport */
19
+
18
20
  /* Excluded from this release type: AppCheckTokenProvider */
19
21
 
20
22
  /* Excluded from this release type: areTransportOptionsEqual */
@@ -179,11 +181,7 @@ export declare interface DataConnectOptions extends ConnectorConfig {
179
181
  projectId: string;
180
182
  }
181
183
 
182
- declare interface DataConnectResponse<T> {
183
- data: T;
184
- errors: Error[];
185
- extensions: Extensions;
186
- }
184
+ /* Excluded from this release type: DataConnectResponse */
187
185
 
188
186
  /* Excluded from this release type: DataConnectResponseWithMaxAge */
189
187
 
@@ -208,7 +206,7 @@ export declare interface DataConnectSubscription<Data, Variables> {
208
206
  unsubscribe: () => void;
209
207
  }
210
208
 
211
- /* Excluded from this release type: DataConnectTransport */
209
+ /* Excluded from this release type: DataConnectTransportInterface */
212
210
 
213
211
  export declare type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER;
214
212
 
@@ -343,6 +341,8 @@ export declare function getDataConnect(app: FirebaseApp, connectorConfig: Connec
343
341
  */
344
342
  export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig, settings: DataConnectSettings): DataConnect;
345
343
 
344
+ /* Excluded from this release type: getGoogApiClientValue */
345
+
346
346
  /**
347
347
  * @license
348
348
  * Copyright 2025 Google LLC
@@ -484,8 +484,12 @@ declare class QueryManager {
484
484
  private cache?;
485
485
  preferCacheResults<Data, Variables>(queryRef: QueryRef<Data, Variables>, allowStale?: boolean): Promise<QueryResult<Data, Variables>>;
486
486
  private callbacks;
487
+ /**
488
+ * Map of serialized query keys to most recent Query Result. Used as a simple fallback cache
489
+ * for subsciptions if caching is not enabled.
490
+ */
487
491
  private subscriptionCache;
488
- constructor(transport: DataConnectTransport, dc: DataConnect, cache?: DataConnectCache | undefined);
492
+ constructor(transport: DataConnectTransportInterface, dc: DataConnect, cache?: DataConnectCache | undefined);
489
493
  private queue;
490
494
  waitForQueuedWrites(): Promise<void>;
491
495
  updateSSR<Data, Variables>(updatedData: QueryResult<Data, Variables>): void;
@@ -496,9 +500,25 @@ declare class QueryManager {
496
500
  publishErrorToSubscribers(key: string, err: unknown): void;
497
501
  getFromResultTreeCache<Data, Variables>(queryRef: QueryRef<Data, Variables>, allowStale?: boolean): Promise<QueryResult<Data, Variables> | null>;
498
502
  getFromSubscriberCache<Data, Variables>(queryRef: QueryRef<Data, Variables>): Promise<QueryResult<Data, Variables> | undefined>;
503
+ /** Call the registered onNext callbacks for the given key */
499
504
  publishDataToSubscribers(key: string, queryResult: QueryResult<unknown, unknown>): void;
500
505
  publishCacheResultsToSubscribers(impactedQueries: string[], fetchTime: string): Promise<void>;
501
506
  enableEmulator(host: string, port: number): void;
507
+ /**
508
+ * Create a new {@link SubscribeObserver} for the given QueryRef. This will be passed to
509
+ * {@link DataConnectTransportInterface.invokeSubscribe | invokeSubscribe()} to notify the query
510
+ * layer of data update notifications or if the stream disconnected.
511
+ */
512
+ private makeSubscribeObserver;
513
+ /**
514
+ * Handle a data update notification from the stream. Notify subscribers of results/errors, and
515
+ * update the cache.
516
+ */
517
+ private handleStreamNotification;
518
+ /**
519
+ * Handle a disconnect from the stream. Unsubscribe all callbacks for the given key.
520
+ */
521
+ private handleStreamDisconnect;
502
522
  }
503
523
 
504
524
  /**
@@ -618,6 +638,8 @@ export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: Q
618
638
  */
619
639
  export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: QueryRef<Data, Variables> | SerializedRef<Data, Variables>, onNext: OnResultSubscription<Data, Variables>, onError?: OnErrorSubscription, onComplete?: OnCompleteSubscription): QueryUnsubscribe;
620
640
 
641
+ /* Excluded from this release type: SubscribeObserver */
642
+
621
643
  /**
622
644
  * Representation of full observer options in `subscribe`
623
645
  */
package/dist/public.d.ts CHANGED
@@ -106,6 +106,7 @@ export declare interface DataConnectOperationFailureResponseErrorInfo {
106
106
  export declare interface DataConnectOptions extends ConnectorConfig {
107
107
  projectId: string;
108
108
  }
109
+ /* Excluded from this release type: DataConnectResponse */
109
110
  /* Excluded from this release type: DataConnectResponseWithMaxAge */
110
111
  export declare interface DataConnectResult<Data, Variables> extends OpResult<Data> {
111
112
  ref: OperationRef<Data, Variables>;
@@ -124,7 +125,7 @@ export declare interface DataConnectSubscription<Data, Variables> {
124
125
  errCallback?: (e?: DataConnectError) => void;
125
126
  unsubscribe: () => void;
126
127
  }
127
- /* Excluded from this release type: DataConnectTransport */
128
+ /* Excluded from this release type: DataConnectTransportInterface */
128
129
  export declare type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER;
129
130
  /**
130
131
  * Execute Mutation
@@ -319,6 +320,7 @@ export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: Q
319
320
  * @returns `SubscriptionOptions`
320
321
  */
321
322
  export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: QueryRef<Data, Variables> | SerializedRef<Data, Variables>, onNext: OnResultSubscription<Data, Variables>, onError?: OnErrorSubscription, onComplete?: OnCompleteSubscription): QueryUnsubscribe;
323
+ /* Excluded from this release type: SubscribeObserver */
322
324
  /**
323
325
  * Representation of full observer options in `subscribe`
324
326
  */
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { DataConnectTransport } from '../network/transport';
17
+ import { DataConnectTransportInterface } from '../network';
18
18
  import { DataConnect } from './DataConnect';
19
19
  import { DataConnectResult, MUTATION_STR, OperationRef } from './Reference';
20
20
  export interface MutationRef<Data, Variables> extends OperationRef<Data, Variables> {
@@ -39,7 +39,7 @@ export declare function mutationRef<Data, Variables>(dcInstance: DataConnect, mu
39
39
  export declare class MutationManager {
40
40
  private _transport;
41
41
  private _inflight;
42
- constructor(_transport: DataConnectTransport);
42
+ constructor(_transport: DataConnectTransportInterface);
43
43
  executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
44
44
  }
45
45
  /**
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { ExecuteQueryOptions } from '../core/query/queryOptions';
18
- import { DataConnectExtensionWithMaxAge } from '../network/transport';
18
+ import { DataConnectExtensionWithMaxAge } from '../network';
19
19
  import { DataConnect } from './DataConnect';
20
20
  import { OperationRef, QUERY_STR, DataConnectResult, SerializedRef } from './Reference';
21
21
  /**
@@ -18,8 +18,7 @@ import { type DataConnect } from '../../api/DataConnect';
18
18
  import { QueryRef, QueryResult } from '../../api/query';
19
19
  import { SerializedRef, DataSource } from '../../api/Reference';
20
20
  import { DataConnectCache } from '../../cache/Cache';
21
- import { DataConnectTransport } from '../../network';
22
- import { DataConnectExtensionWithMaxAge } from '../../network/transport';
21
+ import { DataConnectTransportInterface, DataConnectExtensionWithMaxAge } from '../../network';
23
22
  import { OnCompleteSubscription, OnErrorSubscription, OnResultSubscription } from './subscribe';
24
23
  export declare function getRefSerializer<Data, Variables>(queryRef: QueryRef<Data, Variables>, data: Data, source: DataSource, fetchTime: string): () => SerializedRef<Data, Variables>;
25
24
  export declare class QueryManager {
@@ -28,8 +27,12 @@ export declare class QueryManager {
28
27
  private cache?;
29
28
  preferCacheResults<Data, Variables>(queryRef: QueryRef<Data, Variables>, allowStale?: boolean): Promise<QueryResult<Data, Variables>>;
30
29
  private callbacks;
30
+ /**
31
+ * Map of serialized query keys to most recent Query Result. Used as a simple fallback cache
32
+ * for subsciptions if caching is not enabled.
33
+ */
31
34
  private subscriptionCache;
32
- constructor(transport: DataConnectTransport, dc: DataConnect, cache?: DataConnectCache | undefined);
35
+ constructor(transport: DataConnectTransportInterface, dc: DataConnect, cache?: DataConnectCache | undefined);
33
36
  private queue;
34
37
  waitForQueuedWrites(): Promise<void>;
35
38
  updateSSR<Data, Variables>(updatedData: QueryResult<Data, Variables>): void;
@@ -40,8 +43,24 @@ export declare class QueryManager {
40
43
  publishErrorToSubscribers(key: string, err: unknown): void;
41
44
  getFromResultTreeCache<Data, Variables>(queryRef: QueryRef<Data, Variables>, allowStale?: boolean): Promise<QueryResult<Data, Variables> | null>;
42
45
  getFromSubscriberCache<Data, Variables>(queryRef: QueryRef<Data, Variables>): Promise<QueryResult<Data, Variables> | undefined>;
46
+ /** Call the registered onNext callbacks for the given key */
43
47
  publishDataToSubscribers(key: string, queryResult: QueryResult<unknown, unknown>): void;
44
48
  publishCacheResultsToSubscribers(impactedQueries: string[], fetchTime: string): Promise<void>;
45
49
  enableEmulator(host: string, port: number): void;
50
+ /**
51
+ * Create a new {@link SubscribeObserver} for the given QueryRef. This will be passed to
52
+ * {@link DataConnectTransportInterface.invokeSubscribe | invokeSubscribe()} to notify the query
53
+ * layer of data update notifications or if the stream disconnected.
54
+ */
55
+ private makeSubscribeObserver;
56
+ /**
57
+ * Handle a data update notification from the stream. Notify subscribers of results/errors, and
58
+ * update the cache.
59
+ */
60
+ private handleStreamNotification;
61
+ /**
62
+ * Handle a disconnect from the stream. Unsubscribe all callbacks for the given key.
63
+ */
64
+ private handleStreamDisconnect;
46
65
  }
47
66
  export declare function getMaxAgeFromExtensions(extensions: DataConnectExtensionWithMaxAge[] | undefined): number | undefined;
@@ -14,4 +14,4 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export { CallerSdkType, CallerSdkTypeEnum, DataConnectTransport, DataConnectEntityArray, DataConnectSingleEntity, DataConnectExtension, Extensions, TransportClass } from './transport';
17
+ export * from './transport';
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { DataConnectOptions, TransportOptions } from '../api/DataConnect';
18
+ import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
19
+ import { AuthTokenProvider } from '../core/FirebaseAuthProvider';
20
+ import { CallerSdkType, DataConnectResponse, DataConnectResponseWithMaxAge, DataConnectTransportInterface, SubscribeObserver } from './transport';
21
+ /**
22
+ * Entry point for the transport layer. Manages routing between transport implementations.
23
+ * @internal
24
+ */
25
+ export declare class DataConnectTransportManager implements DataConnectTransportInterface {
26
+ private options;
27
+ private apiKey?;
28
+ private appId?;
29
+ private authProvider?;
30
+ private appCheckProvider?;
31
+ private transportOptions?;
32
+ private _isUsingGen;
33
+ private _callerSdkType?;
34
+ private restTransport;
35
+ private streamTransport?;
36
+ private isUsingEmulator;
37
+ constructor(options: DataConnectOptions, apiKey?: string | undefined, appId?: (string | null) | undefined, authProvider?: AuthTokenProvider | undefined, appCheckProvider?: AppCheckTokenProvider | undefined, transportOptions?: TransportOptions | undefined, _isUsingGen?: boolean, _callerSdkType?: CallerSdkType | undefined);
38
+ /**
39
+ * Initializes the stream transport if it hasn't been already.
40
+ */
41
+ private initStreamTransport;
42
+ /**
43
+ * Returns true if the stream is in a healthy, ready connection state and has active subscriptions.
44
+ */
45
+ private executeShouldUseStream;
46
+ /**
47
+ * Prefer to use Streaming Transport connection when one is available.
48
+ * @inheritdoc
49
+ */
50
+ invokeQuery<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponseWithMaxAge<Data>>;
51
+ /**
52
+ * Prefer to use Streaming Transport connection when one is available.
53
+ * @inheritdoc
54
+ */
55
+ invokeMutation<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponse<Data>>;
56
+ invokeSubscribe<Data, Variables>(observer: SubscribeObserver<Data>, queryName: string, body?: Variables): void;
57
+ invokeUnsubscribe<Variables>(queryName: string, body?: Variables): void;
58
+ useEmulator(host: string, port?: number, sslEnabled?: boolean): void;
59
+ onAuthTokenChanged(token: string | null): void;
60
+ _setCallerSdkType(callerSdkType: CallerSdkType): void;
61
+ }
@@ -14,11 +14,16 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { CallerSdkType, DataConnectResponse } from './transport';
17
+ import { CallerSdkType, DataConnectResponse } from '..';
18
+ /**
19
+ * This function is ONLY used for testing and for ensuring compatability in environments which may
20
+ * be using a poyfill and/or bundlers. It should not be called by users of the Firebase JS SDK.
21
+ * @internal
22
+ */
18
23
  export declare function initializeFetch(fetchImpl: typeof fetch): void;
19
- export interface DataConnectFetchBody<T> {
24
+ export interface DataConnectFetchBody<Variables> {
20
25
  name: string;
21
26
  operationName: string;
22
- variables: T;
27
+ variables: Variables;
23
28
  }
24
- export declare function dcFetch<T, U>(url: string, body: DataConnectFetchBody<U>, { signal }: AbortController, appId: string | null | undefined, accessToken: string | null, appCheckToken: string | null | undefined, _isUsingGen: boolean, _callerSdkType: CallerSdkType, _isUsingEmulator: boolean): Promise<DataConnectResponse<T>>;
29
+ export declare function dcFetch<Data, Variables>(url: string, body: DataConnectFetchBody<Variables>, { signal }: AbortController, appId: string | null | undefined, accessToken: string | null, appCheckToken: string | null | undefined, _isUsingGen: boolean, _callerSdkType: CallerSdkType, _isUsingEmulator: boolean): Promise<DataConnectResponse<Data>>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from './fetch';
18
+ export * from './restTransport';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { CallerSdkType, DataConnectResponse, DataConnectResponseWithMaxAge, AbstractDataConnectTransport, SubscribeObserver } from '..';
18
+ import { DataConnectOptions, TransportOptions } from '../../api/DataConnect';
19
+ import { AppCheckTokenProvider } from '../../core/AppCheckTokenProvider';
20
+ import { AuthTokenProvider } from '../../core/FirebaseAuthProvider';
21
+ /**
22
+ * Fetch-based REST implementation of {@link AbstractDataConnectTransport}.
23
+ * @internal
24
+ */
25
+ export declare class RESTTransport extends AbstractDataConnectTransport {
26
+ constructor(options: DataConnectOptions, apiKey?: string | undefined, appId?: string | null, authProvider?: AuthTokenProvider | undefined, appCheckProvider?: AppCheckTokenProvider | undefined, transportOptions?: TransportOptions | undefined, _isUsingGen?: boolean, _callerSdkType?: CallerSdkType);
27
+ get endpointUrl(): string;
28
+ invokeQuery: <Data, Variables>(queryName: string, body?: Variables) => Promise<DataConnectResponseWithMaxAge<Data>>;
29
+ invokeMutation: <Data, Variables>(queryName: string, body?: Variables) => Promise<DataConnectResponse<Data>>;
30
+ invokeSubscribe<Data, Variables>(observer: SubscribeObserver<Data>, queryName: string, body?: Variables): void;
31
+ invokeUnsubscribe<Variables>(queryName: string, body?: Variables): void;
32
+ onAuthTokenChanged(newToken: string | null): void;
33
+ }