/** * Firebase Data Connect * * @packageDocumentation */ import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types'; import { AppCheckTokenListener } from '@firebase/app-check-interop-types'; import { AppCheckTokenResult } from '@firebase/app-check-interop-types'; import { FirebaseApp } from '@firebase/app'; import { FirebaseAuthInternal } from '@firebase/auth-interop-types'; import { FirebaseAuthInternalName } from '@firebase/auth-interop-types'; import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; import { FirebaseError } from '@firebase/util'; import { LogLevelString } from '@firebase/logger'; import { Provider } from '@firebase/component'; /* Excluded from this release type: AbstractDataConnectTransport */ /* Excluded from this release type: AppCheckTokenProvider */ /* Excluded from this release type: areTransportOptionsEqual */ declare type AuthTokenListener = (token: string | null) => void; declare interface AuthTokenProvider { getToken(forceRefresh: boolean): Promise; addTokenChangeListener(listener: AuthTokenListener): void; getAuth(): FirebaseAuthInternal; } export declare interface CacheProvider { type: T; /* Excluded from this release type: initialize */ } export declare interface CacheSettings { cacheProvider: CacheProvider; maxAgeSeconds?: number; } /** * enum representing different flavors of the SDK used by developers * use the CallerSdkType for type-checking, and the CallerSdkTypeEnum for value-checking/assigning */ export declare type CallerSdkType = 'Base' | 'Generated' | 'TanstackReactCore' | 'GeneratedReact' | 'TanstackAngularCore' | 'GeneratedAngular'; export declare const CallerSdkTypeEnum: { readonly Base: "Base"; readonly Generated: "Generated"; readonly TanstackReactCore: "TanstackReactCore"; readonly GeneratedReact: "GeneratedReact"; readonly TanstackAngularCore: "TanstackAngularCore"; readonly GeneratedAngular: "GeneratedAngular"; }; export declare type Code = DataConnectErrorCode; export declare const Code: { OTHER: DataConnectErrorCode; ALREADY_INITIALIZED: DataConnectErrorCode; NOT_INITIALIZED: DataConnectErrorCode; NOT_SUPPORTED: DataConnectErrorCode; INVALID_ARGUMENT: DataConnectErrorCode; PARTIAL_ERROR: DataConnectErrorCode; UNAUTHORIZED: DataConnectErrorCode; }; /** * Connect to the DataConnect Emulator * @param dc Data Connect instance * @param host host of emulator server * @param port port of emulator server * @param sslEnabled use https */ export declare function connectDataConnectEmulator(dc: DataConnect, host: string, port?: number, sslEnabled?: boolean): void; /** * Connector Config for calling Data Connect backend. */ export declare interface ConnectorConfig { location: string; connector: string; service: string; } /** * Class representing Firebase Data Connect */ export declare class DataConnect { readonly app: FirebaseApp; private readonly dataConnectOptions; private readonly _authProvider; private readonly _appCheckProvider; _queryManager: QueryManager; _mutationManager: MutationManager; isEmulator: boolean; _initialized: boolean; private _transport; private _transportClass; private _transportOptions?; private _authTokenProvider?; _isUsingGeneratedSdk: boolean; _callerSdkType: CallerSdkType; private _appCheckTokenProvider?; private _cacheSettings?; /* Excluded from this release type: cache */ constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider, _appCheckProvider: Provider); /* Excluded from this release type: getCache */ _useGeneratedSdk(): void; _setCallerSdkType(callerSdkType: CallerSdkType): void; _delete(): Promise; getSettings(): ConnectorConfig; /* Excluded from this release type: setCacheSettings */ setInitialized(): void; enableEmulator(transportOptions: TransportOptions): void; } declare class DataConnectCache { private authProvider; private projectId; private connectorConfig; private host; cacheSettings: CacheSettings; private cacheProvider; private uid; constructor(authProvider: AuthTokenProvider, projectId: string, connectorConfig: ConnectorConfig, host: string, cacheSettings: CacheSettings); initialize(): Promise; getIdentifier(uid: string | null): Promise; initializeNewProviders(identifier: string): InternalCacheProvider; containsResultTree(queryId: string): Promise; getResultTree(queryId: string): Promise; getResultJSON(queryId: string): Promise>; update(queryId: string, serverValues: ServerValues, entityIds: Record): Promise; } export declare interface DataConnectEntityArray { entityIds: string[]; } /** An error returned by a DataConnect operation. */ export declare class DataConnectError extends FirebaseError { /* Excluded from this release type: name */ constructor(code: Code, message: string); /* Excluded from this release type: toString */ } export declare type DataConnectErrorCode = 'other' | 'already-initialized' | 'not-initialized' | 'not-supported' | 'invalid-argument' | 'partial-error' | 'unauthorized'; export declare type DataConnectExtension = { path: Array; } & (DataConnectEntityArray | DataConnectSingleEntity); /* Excluded from this release type: DataConnectExtensionWithMaxAge */ /* Excluded from this release type: DataConnectMaxAge */ /** An error returned by a DataConnect operation. */ export declare class DataConnectOperationError extends DataConnectError { /* Excluded from this release type: name */ /** The response received from the backend. */ readonly response: DataConnectOperationFailureResponse; /** @hideconstructor */ constructor(message: string, response: DataConnectOperationFailureResponse); } export declare interface DataConnectOperationFailureResponse { readonly data?: Record | null; readonly errors: DataConnectOperationFailureResponseErrorInfo[]; } export declare interface DataConnectOperationFailureResponseErrorInfo { readonly message: string; readonly path: Array; } /** * DataConnectOptions including project id */ export declare interface DataConnectOptions extends ConnectorConfig { projectId: string; } /* Excluded from this release type: DataConnectResponse */ /* Excluded from this release type: DataConnectResponseWithMaxAge */ export declare interface DataConnectResult extends OpResult { ref: OperationRef; } export declare interface DataConnectSettings { cacheSettings?: CacheSettings; } export declare interface DataConnectSingleEntity { entityId: string; } /** * Representation of user provided subscription options. */ export declare interface DataConnectSubscription { userCallback: OnResultSubscription; errCallback?: (e?: DataConnectError) => void; unsubscribe: () => void; } /* Excluded from this release type: DataConnectTransportInterface */ export declare type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER; declare interface DehydratedResultTreeJson { rootStub: DehydratedStubDataObject; maxAge: number; cachedAt: Date; lastAccessed: Date; } declare interface DehydratedStubDataObject { backingData?: EntityDataObjectJson; globalID?: string; scalars: { [key: string]: FDCScalarValue; }; references: { [key: string]: DehydratedStubDataObject; }; objectLists: { [key: string]: DehydratedStubDataObject[]; }; } declare enum EncodingMode { hydrated = 0, dehydrated = 1 } declare class EntityDataObject { readonly globalID: string; getServerValue(key: string): unknown; private serverValues; private referencedFrom; constructor(globalID: string); getServerValues(): { [key: string]: FDCScalarValue; }; toJSON(): EntityDataObjectJson; static fromJSON(json: EntityDataObjectJson): EntityDataObject; updateServerValue(key: string, value: FDCScalarValue, requestedFrom: string): string[]; } declare interface EntityDataObjectJson { map: { [key: string]: FDCScalarValue; }; referencedFrom: string[]; globalID: string; } declare class EntityNode { entityData?: EntityDataObject; scalars: Record; references: { [key: string]: EntityNode; }; objectLists: { [key: string]: EntityNode[]; }; globalId?: string; entityDataKeys: Set; loadData(queryId: string, values: FDCScalarValue, entityIds: Record | undefined, acc: ImpactedQueryRefsAccumulator, cacheProvider: InternalCacheProvider): Promise; toJSON(mode: EncodingMode): Record; static fromJson(obj: DehydratedStubDataObject): EntityNode; } /** * Execute Mutation * @param mutationRef mutation to execute * @returns `MutationRef` */ export declare function executeMutation(mutationRef: MutationRef): MutationPromise; /** * Execute Query * @param queryRef query to execute. * @returns `QueryPromise` */ export declare function executeQuery(queryRef: QueryRef, options?: ExecuteQueryOptions): QueryPromise; /** * Options for executing a query. */ export declare interface ExecuteQueryOptions { fetchPolicy: QueryFetchPolicy; } export declare interface Extensions { dataConnect?: DataConnectExtension[]; } /* Excluded from this release type: ExtensionsWithMaxAge */ /** * @license * Copyright 2025 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. */ declare type FDCScalarValue = string | number | boolean | undefined | null | Record | FDCScalarValue[]; /** * Initialize DataConnect instance * @param options ConnectorConfig */ export declare function getDataConnect(options: ConnectorConfig, settings?: DataConnectSettings): DataConnect; export declare function getDataConnect(options: ConnectorConfig): DataConnect; /** * Initialize DataConnect instance * @param app FirebaseApp to initialize to. * @param connectorConfig ConnectorConfig */ export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig): DataConnect; /** * Initialize DataConnect instance * @param app FirebaseApp to initialize to. * @param connectorConfig ConnectorConfig */ export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig, settings: DataConnectSettings): DataConnect; /* Excluded from this release type: getGoogApiClientValue */ /** * @license * Copyright 2025 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. */ declare class ImpactedQueryRefsAccumulator { private queryId; impacted: Set; constructor(queryId: string); add(impacted: string[]): void; consumeEvents(): string[]; } declare interface InternalCacheProvider { getEntityData(globalId: string): Promise; updateEntityData(entityData: EntityDataObject): Promise; getResultTree(queryId: string): Promise; setResultTree(queryId: string, resultTree: ResultTree): Promise; close(): void; } /* Excluded from this release type: InternalQueryResult */ export declare function makeMemoryCacheProvider(): CacheProvider<'MEMORY'>; export declare const MUTATION_STR = "mutation"; /* Excluded from this release type: MutationManager */ /** * Mutation return value from `executeMutation` */ export declare interface MutationPromise extends Promise> { } export declare interface MutationRef extends OperationRef { refType: typeof MUTATION_STR; } /** * Creates a `MutationRef` * @param dcInstance Data Connect instance * @param mutationName name of mutation */ export declare function mutationRef(dcInstance: DataConnect, mutationName: string): MutationRef; /** * * @param dcInstance Data Connect instance * @param mutationName name of mutation * @param variables variables to send with mutation */ export declare function mutationRef(dcInstance: DataConnect, mutationName: string, variables: Variables): MutationRef; /** * Mutation Result from `executeMutation` */ export declare interface MutationResult extends DataConnectResult { ref: MutationRef; } /** * `OnCompleteSubscription` */ export declare type OnCompleteSubscription = () => void; /** * Signature for `OnErrorSubscription` for `subscribe` */ export declare type OnErrorSubscription = (err?: DataConnectError) => void; /** * Signature for `OnResultSubscription` for `subscribe` */ export declare type OnResultSubscription = (res: QueryResult) => void; export declare interface OperationRef<_Data, Variables> { name: string; variables: Variables; refType: ReferenceType; dataConnect: DataConnect; } export declare interface OpResult { data: Data; source: DataSource; fetchTime: string; extensions?: Extensions; } declare interface ParsedArgs { dc: DataConnect; vars: Variables; options?: ExecuteQueryOptions; } /* Excluded from this release type: parseOptions */ export declare const QUERY_STR = "query"; /** * @license * Copyright 2025 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. */ export declare const QueryFetchPolicy: { readonly PREFER_CACHE: "PREFER_CACHE"; readonly CACHE_ONLY: "CACHE_ONLY"; readonly SERVER_ONLY: "SERVER_ONLY"; }; export declare type QueryFetchPolicy = (typeof QueryFetchPolicy)[keyof typeof QueryFetchPolicy]; declare class QueryManager { private transport; private dc; private cache?; preferCacheResults(queryRef: QueryRef, allowStale?: boolean): Promise>; private callbacks; /** * Map of serialized query keys to most recent Query Result. Used as a simple fallback cache * for subsciptions if caching is not enabled. */ private subscriptionCache; constructor(transport: DataConnectTransportInterface, dc: DataConnect, cache?: DataConnectCache | undefined); private queue; waitForQueuedWrites(): Promise; updateSSR(updatedData: QueryResult): void; updateCache(result: QueryResult, extensions?: DataConnectExtensionWithMaxAge[]): Promise; addSubscription(queryRef: QueryRef, onResultCallback: OnResultSubscription, onCompleteCallback?: OnCompleteSubscription, onErrorCallback?: OnErrorSubscription, initialCache?: QueryResult): () => void; fetchServerResults(queryRef: QueryRef): Promise>; fetchCacheResults(queryRef: QueryRef, allowStale?: boolean): Promise>; publishErrorToSubscribers(key: string, err: unknown): void; getFromResultTreeCache(queryRef: QueryRef, allowStale?: boolean): Promise | null>; getFromSubscriberCache(queryRef: QueryRef): Promise | undefined>; /** Call the registered onNext callbacks for the given key */ publishDataToSubscribers(key: string, queryResult: QueryResult): void; publishCacheResultsToSubscribers(impactedQueries: string[], fetchTime: string): Promise; enableEmulator(host: string, port: number): void; /** * Create a new {@link SubscribeObserver} for the given QueryRef. This will be passed to * {@link DataConnectTransportInterface.invokeSubscribe | invokeSubscribe()} to notify the query * layer of data update notifications or if the stream disconnected. */ private makeSubscribeObserver; /** * Handle a data update notification from the stream. Notify subscribers of results/errors, and * update the cache. */ private handleStreamNotification; /** * Handle a disconnect from the stream. Unsubscribe all callbacks for the given key. */ private handleStreamDisconnect; } /** * Promise returned from `executeQuery` */ export declare interface QueryPromise extends Promise> { } /** * QueryRef object */ export declare interface QueryRef extends OperationRef { refType: typeof QUERY_STR; } /** * Execute Query * @param dcInstance Data Connect instance to use. * @param queryName Query to execute * @returns `QueryRef` */ export declare function queryRef(dcInstance: DataConnect, queryName: string): QueryRef; /** * Execute Query * @param dcInstance Data Connect instance to use. * @param queryName Query to execute * @param variables Variables to execute with * @returns `QueryRef` */ export declare function queryRef(dcInstance: DataConnect, queryName: string, variables: Variables): QueryRef; /** * Result of `executeQuery` */ export declare interface QueryResult extends DataConnectResult { ref: QueryRef; toJSON: () => SerializedRef; } /** * Signature for unsubscribe from `subscribe` */ export declare type QueryUnsubscribe = () => void; export declare type ReferenceType = typeof QUERY_STR | typeof MUTATION_STR; /** * Serialized RefInfo as a result of `QueryResult.toJSON().refInfo` */ export declare interface RefInfo { name: string; variables: Variables; connectorConfig: DataConnectOptions; } declare class ResultTree { private rootStub; private maxAge; readonly cachedAt: Date; private _lastAccessed; /** * Create a {@link ResultTree} from a dehydrated JSON object. * @param value The dehydrated JSON object. * @returns The {@link ResultTree}. */ static fromJson(value: DehydratedResultTreeJson): ResultTree; constructor(rootStub: EntityNode, maxAge: number, cachedAt: Date, _lastAccessed: Date); isStale(): boolean; updateMaxAge(maxAgeInSeconds: number): void; updateAccessed(): void; get lastAccessed(): Date; getRootStub(): EntityNode; } /** * Serialized Ref as a result of `QueryResult.toJSON()` */ export declare interface SerializedRef extends OpResult { refInfo: RefInfo; } /** * ServerValues */ declare interface ServerValues extends Record { maxAge?: number; } export declare function setLogLevel(logLevel: LogLevelString): void; export declare const SOURCE_CACHE = "CACHE"; export declare const SOURCE_SERVER = "SERVER"; export declare const StorageType: { readonly MEMORY: "MEMORY"; }; export declare type StorageType = (typeof StorageType)[keyof typeof StorageType]; /** * Subscribe to a `QueryRef` * @param queryRefOrSerializedResult query ref or serialized result. * @param observer observer object to use for subscribing. * @returns `SubscriptionOptions` */ export declare function subscribe(queryRefOrSerializedResult: QueryRef | SerializedRef, observer: SubscriptionOptions): QueryUnsubscribe; /** * Subscribe to a `QueryRef` * @param queryRefOrSerializedResult query ref or serialized result. * @param onNext Callback to call when result comes back. * @param onError Callback to call when error gets thrown. * @param onComplete Called when subscription completes. * @returns `SubscriptionOptions` */ export declare function subscribe(queryRefOrSerializedResult: QueryRef | SerializedRef, onNext: OnResultSubscription, onError?: OnErrorSubscription, onComplete?: OnCompleteSubscription): QueryUnsubscribe; /* Excluded from this release type: SubscribeObserver */ /** * Representation of full observer options in `subscribe` */ export declare interface SubscriptionOptions { onNext?: OnResultSubscription; onErr?: OnErrorSubscription; onComplete?: OnCompleteSubscription; } /** * Delete DataConnect instance * @param dataConnect DataConnect instance * @returns */ export declare function terminate(dataConnect: DataConnect): Promise; /** * Converts serialized ref to query ref * @param serializedRef ref to convert to `QueryRef` * @returns `QueryRef` */ export declare function toQueryRef(serializedRef: SerializedRef): QueryRef; /* Excluded from this release type: TransportClass */ /** * Options to connect to emulator */ export declare interface TransportOptions { host: string; sslEnabled?: boolean; port?: number; } /* Excluded from this release type: validateArgs */ /* Excluded from this release type: validateArgsWithOptions */ /* Excluded from this release type: validateDCOptions */ export { }