@firebase/data-connect 0.5.0 → 0.6.0-20260409172004

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 +1173 -143
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm.js +1172 -144
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.node.cjs.js +1239 -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 +1238 -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 +243 -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 +243 -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
@@ -15,6 +15,47 @@ import { FirebaseError } from '@firebase/util';
15
15
  import { LogLevelString } from '@firebase/logger';
16
16
  import { Provider } from '@firebase/component';
17
17
 
18
+ /**
19
+ * The base class for all DataConnectTransportInterface implementations. Handles common logic such as
20
+ * URL construction, auth token management, and emulator usage. Concrete transport implementations
21
+ * should extend this class and implement the abstract {@link DataConnectTransportInterface} methods.
22
+ * @internal
23
+ */
24
+ export declare abstract class AbstractDataConnectTransport implements DataConnectTransportInterface {
25
+ protected apiKey?: string | undefined;
26
+ protected appId?: (string | null) | undefined;
27
+ protected authProvider?: AuthTokenProvider | undefined;
28
+ protected appCheckProvider?: AppCheckTokenProvider | undefined;
29
+ protected _isUsingGen: boolean;
30
+ protected _callerSdkType: CallerSdkType;
31
+ protected _host: string;
32
+ protected _port: number | undefined;
33
+ protected _location: string;
34
+ protected _connectorName: string;
35
+ /** The resource path for requests from this Data Connect instance. */
36
+ protected _connectorResourcePath: string;
37
+ protected _secure: boolean;
38
+ protected _project: string;
39
+ protected _serviceName: string;
40
+ protected _authToken: string | null;
41
+ protected _appCheckToken: string | null | undefined;
42
+ protected _lastToken: string | null;
43
+ protected _isUsingEmulator: boolean;
44
+ constructor(options: DataConnectOptions, apiKey?: string | undefined, appId?: (string | null) | undefined, authProvider?: AuthTokenProvider | undefined, appCheckProvider?: AppCheckTokenProvider | undefined, transportOptions?: TransportOptions | undefined, _isUsingGen?: boolean, _callerSdkType?: CallerSdkType);
45
+ /** Get the endpoint URL this transport should use to communicate with the backend. */
46
+ abstract get endpointUrl(): string;
47
+ useEmulator(host: string, port?: number, isSecure?: boolean): void;
48
+ getWithAuth(forceToken?: boolean): Promise<string | null>;
49
+ withRetry<T>(promiseFactory: () => Promise<DataConnectResponse<T>>, retry?: boolean): Promise<DataConnectResponse<T>>;
50
+ _setLastToken(lastToken: string | null): void;
51
+ abstract invokeQuery<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponseWithMaxAge<Data>>;
52
+ abstract invokeMutation<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponse<Data>>;
53
+ abstract invokeSubscribe<Data, Variables>(observer: SubscribeObserver<Data>, queryName: string, body?: Variables): void;
54
+ abstract invokeUnsubscribe<Variables>(queryName: string, variables: Variables): void;
55
+ abstract onAuthTokenChanged(newToken: string | null): void;
56
+ _setCallerSdkType(callerSdkType: CallerSdkType): void;
57
+ }
58
+
18
59
  /**
19
60
  * @internal
20
61
  * Abstraction around AppCheck's token fetching capabilities.
@@ -181,12 +222,12 @@ export declare type DataConnectExtension = {
181
222
  } & (DataConnectEntityArray | DataConnectSingleEntity);
182
223
 
183
224
  /** @internal */
184
- declare type DataConnectExtensionWithMaxAge = {
225
+ export declare type DataConnectExtensionWithMaxAge = {
185
226
  path: Array<string | number>;
186
227
  } & (DataConnectEntityArray | DataConnectSingleEntity | DataConnectMaxAge);
187
228
 
188
229
  /** @internal */
189
- declare interface DataConnectMaxAge {
230
+ export declare interface DataConnectMaxAge {
190
231
  maxAge: string;
191
232
  }
192
233
 
@@ -217,14 +258,15 @@ export declare interface DataConnectOptions extends ConnectorConfig {
217
258
  projectId: string;
218
259
  }
219
260
 
220
- declare interface DataConnectResponse<T> {
261
+ /** @internal */
262
+ export declare interface DataConnectResponse<T> {
221
263
  data: T;
222
264
  errors: Error[];
223
265
  extensions: Extensions;
224
266
  }
225
267
 
226
268
  /** @internal */
227
- declare interface DataConnectResponseWithMaxAge<T> {
269
+ export declare interface DataConnectResponseWithMaxAge<T> {
228
270
  data: T;
229
271
  errors: Error[];
230
272
  extensions: ExtensionsWithMaxAge;
@@ -252,13 +294,55 @@ export declare interface DataConnectSubscription<Data, Variables> {
252
294
  }
253
295
 
254
296
  /**
297
+ * Interface defining the external API of the transport layer.
255
298
  * @internal
256
299
  */
257
- export declare interface DataConnectTransport {
258
- invokeQuery<T, U>(queryName: string, body?: U): Promise<DataConnectResponseWithMaxAge<T>>;
259
- invokeMutation<T, U>(queryName: string, body?: U): Promise<DataConnectResponse<T>>;
300
+ export declare interface DataConnectTransportInterface {
301
+ /**
302
+ * Invoke a query execution request.
303
+ * @param queryName The name of the query to execute.
304
+ * @param body The variables associated with the query.
305
+ * @returns A promise resolving to the DataConnectResponse.
306
+ */
307
+ invokeQuery<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponseWithMaxAge<Data>>;
308
+ /**
309
+ * Invoke a mutation execution request.
310
+ * @param queryName The name of the mutation to execute.
311
+ * @param body The variables associated with the mutation.
312
+ * @returns A promise resolving to the DataConnectResponse.
313
+ */
314
+ invokeMutation<Data, Variables>(queryName: string, body?: Variables): Promise<DataConnectResponse<Data>>;
315
+ /**
316
+ * Subscribes to a query to receive push notifications of updates.
317
+ * @param observer the observer passed to the transport layer to notify the query layer of events.
318
+ * @param queryName The name of the query to subscribe to.
319
+ * @param body The variables associated with the subscription.
320
+ */
321
+ invokeSubscribe<Data, Variables>(observer: SubscribeObserver<Data>, queryName: string, body?: Variables): void;
322
+ /**
323
+ * Unsubscribes from an active subscription.
324
+ * @param queryName The name of the query to unsubscribe from.
325
+ * @param body The variables associated with the subscription.
326
+ */
327
+ invokeUnsubscribe<Variables>(queryName: string, body?: Variables): void;
328
+ /**
329
+ * Configures the transport to use a local Data Connect emulator.
330
+ * @param host The host address of the emulator (e.g., '127.0.0.1').
331
+ * @param port The port number the emulator is listening on.
332
+ * @param sslEnabled Whether to use SSL (HTTPS/WSS) for the emulator connection.
333
+ */
260
334
  useEmulator(host: string, port?: number, sslEnabled?: boolean): void;
261
- onTokenChanged: (token: string | null) => void;
335
+ /**
336
+ * Callback invoked when the Firebase Auth token is refreshed or changed. Note that this callback
337
+ * is called immediately asynchronously when the Auth Provider is initialized to provide
338
+ * the initial auth state.
339
+ * @param token The new access token or null if signed out.
340
+ */
341
+ onAuthTokenChanged: (token: string | null) => void;
342
+ /**
343
+ * Internal method to set the SDK type for metrics and logging purposes.
344
+ * @param callerSdkType The type of SDK making the call (e.g., generated vs base).
345
+ */
262
346
  _setCallerSdkType(callerSdkType: CallerSdkType): void;
263
347
  }
264
348
 
@@ -354,7 +438,7 @@ export declare interface Extensions {
354
438
  }
355
439
 
356
440
  /** @internal */
357
- declare interface ExtensionsWithMaxAge {
441
+ export declare interface ExtensionsWithMaxAge {
358
442
  dataConnect?: DataConnectExtensionWithMaxAge[];
359
443
  }
360
444
 
@@ -398,6 +482,12 @@ export declare function getDataConnect(app: FirebaseApp, connectorConfig: Connec
398
482
  */
399
483
  export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig, settings: DataConnectSettings): DataConnect;
400
484
 
485
+ /**
486
+ * Constructs the value for the X-Goog-Api-Client header
487
+ * @internal
488
+ */
489
+ export declare function getGoogApiClientValue(isUsingGen: boolean, callerSdkType: CallerSdkType): string;
490
+
401
491
  /**
402
492
  * @license
403
493
  * Copyright 2025 Google LLC
@@ -447,7 +537,7 @@ export declare const MUTATION_STR = "mutation";
447
537
  export declare class MutationManager {
448
538
  private _transport;
449
539
  private _inflight;
450
- constructor(_transport: DataConnectTransport);
540
+ constructor(_transport: DataConnectTransportInterface);
451
541
  executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
452
542
  }
453
543
 
@@ -558,8 +648,12 @@ declare class QueryManager {
558
648
  private cache?;
559
649
  preferCacheResults<Data, Variables>(queryRef: QueryRef<Data, Variables>, allowStale?: boolean): Promise<QueryResult<Data, Variables>>;
560
650
  private callbacks;
651
+ /**
652
+ * Map of serialized query keys to most recent Query Result. Used as a simple fallback cache
653
+ * for subsciptions if caching is not enabled.
654
+ */
561
655
  private subscriptionCache;
562
- constructor(transport: DataConnectTransport, dc: DataConnect, cache?: DataConnectCache | undefined);
656
+ constructor(transport: DataConnectTransportInterface, dc: DataConnect, cache?: DataConnectCache | undefined);
563
657
  private queue;
564
658
  waitForQueuedWrites(): Promise<void>;
565
659
  updateSSR<Data, Variables>(updatedData: QueryResult<Data, Variables>): void;
@@ -570,9 +664,25 @@ declare class QueryManager {
570
664
  publishErrorToSubscribers(key: string, err: unknown): void;
571
665
  getFromResultTreeCache<Data, Variables>(queryRef: QueryRef<Data, Variables>, allowStale?: boolean): Promise<QueryResult<Data, Variables> | null>;
572
666
  getFromSubscriberCache<Data, Variables>(queryRef: QueryRef<Data, Variables>): Promise<QueryResult<Data, Variables> | undefined>;
667
+ /** Call the registered onNext callbacks for the given key */
573
668
  publishDataToSubscribers(key: string, queryResult: QueryResult<unknown, unknown>): void;
574
669
  publishCacheResultsToSubscribers(impactedQueries: string[], fetchTime: string): Promise<void>;
575
670
  enableEmulator(host: string, port: number): void;
671
+ /**
672
+ * Create a new {@link SubscribeObserver} for the given QueryRef. This will be passed to
673
+ * {@link DataConnectTransportInterface.invokeSubscribe | invokeSubscribe()} to notify the query
674
+ * layer of data update notifications or if the stream disconnected.
675
+ */
676
+ private makeSubscribeObserver;
677
+ /**
678
+ * Handle a data update notification from the stream. Notify subscribers of results/errors, and
679
+ * update the cache.
680
+ */
681
+ private handleStreamNotification;
682
+ /**
683
+ * Handle a disconnect from the stream. Unsubscribe all callbacks for the given key.
684
+ */
685
+ private handleStreamDisconnect;
576
686
  }
577
687
 
578
688
  /**
@@ -692,6 +802,16 @@ export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: Q
692
802
  */
693
803
  export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: QueryRef<Data, Variables> | SerializedRef<Data, Variables>, onNext: OnResultSubscription<Data, Variables>, onError?: OnErrorSubscription, onComplete?: OnCompleteSubscription): QueryUnsubscribe;
694
804
 
805
+ /**
806
+ * Observer defined by the Query Layer for receiving notifications from the Transport Layer.
807
+ * @internal
808
+ */
809
+ export declare interface SubscribeObserver<Data> {
810
+ onData(response: DataConnectResponse<Data>): Promise<void> | void;
811
+ onDisconnect(code: string, reason: string): void;
812
+ onError(error: Error): void;
813
+ }
814
+
695
815
  /**
696
816
  * Representation of full observer options in `subscribe`
697
817
  */
@@ -716,9 +836,10 @@ export declare function terminate(dataConnect: DataConnect): Promise<void>;
716
836
  export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<Data, Variables>;
717
837
 
718
838
  /**
839
+ * Type signature of a transport class constructor.
719
840
  * @internal
720
841
  */
721
- export declare type TransportClass = new (options: DataConnectOptions, apiKey?: string, appId?: string, authProvider?: AuthTokenProvider, appCheckProvider?: AppCheckTokenProvider, transportOptions?: TransportOptions, _isUsingGen?: boolean, _callerSdkType?: CallerSdkType) => DataConnectTransport;
842
+ export declare type TransportClass = new (options: DataConnectOptions, apiKey?: string, appId?: string, authProvider?: AuthTokenProvider, appCheckProvider?: AppCheckTokenProvider, transportOptions?: TransportOptions, _isUsingGen?: boolean, _callerSdkType?: CallerSdkType) => DataConnectTransportInterface;
722
843
 
723
844
  /**
724
845
  * Options to connect to emulator