@firebase/data-connect 0.3.12 → 0.4.0-canary.22476e1bc

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 (64) hide show
  1. package/dist/index.cjs.js +1012 -210
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm.js +1011 -212
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.node.cjs.js +960 -158
  6. package/dist/index.node.cjs.js.map +1 -1
  7. package/dist/internal.d.ts +311 -25
  8. package/dist/node-esm/index.node.esm.js +959 -160
  9. package/dist/node-esm/index.node.esm.js.map +1 -1
  10. package/dist/node-esm/src/api/DataConnect.d.ts +44 -3
  11. package/dist/node-esm/src/api/Reference.d.ts +2 -0
  12. package/dist/node-esm/src/api/index.d.ts +2 -1
  13. package/dist/node-esm/src/api/query.d.ts +9 -26
  14. package/dist/node-esm/src/api.browser.d.ts +2 -18
  15. package/dist/node-esm/src/api.node.d.ts +2 -1
  16. package/dist/node-esm/src/cache/Cache.d.ts +53 -0
  17. package/dist/node-esm/src/cache/CacheProvider.d.ts +25 -0
  18. package/dist/node-esm/src/cache/EntityDataObject.d.ts +37 -0
  19. package/dist/node-esm/src/cache/EntityNode.d.ts +56 -0
  20. package/dist/node-esm/src/cache/ImpactedQueryRefsAccumulator.d.ts +23 -0
  21. package/dist/node-esm/src/cache/InMemoryCacheProvider.d.ts +30 -0
  22. package/dist/node-esm/src/cache/ResultTree.d.ts +42 -0
  23. package/dist/node-esm/src/cache/ResultTreeProcessor.d.ts +40 -0
  24. package/dist/node-esm/src/cache/cacheUtils.d.ts +20 -0
  25. package/dist/node-esm/src/core/FirebaseAuthProvider.d.ts +3 -1
  26. package/dist/node-esm/src/core/query/QueryManager.d.ts +47 -0
  27. package/dist/node-esm/src/core/query/queryOptions.d.ts +25 -0
  28. package/dist/node-esm/src/core/query/subscribe.d.ts +67 -0
  29. package/dist/node-esm/src/network/fetch.d.ts +2 -5
  30. package/dist/node-esm/src/network/index.d.ts +1 -1
  31. package/dist/node-esm/src/network/transport/index.d.ts +37 -8
  32. package/dist/node-esm/src/network/transport/rest.d.ts +5 -17
  33. package/dist/node-esm/src/util/encoder.d.ts +4 -1
  34. package/dist/node-esm/src/util/url.d.ts +1 -0
  35. package/dist/private.d.ts +278 -17
  36. package/dist/public.d.ts +77 -3
  37. package/dist/src/api/DataConnect.d.ts +44 -3
  38. package/dist/src/api/Reference.d.ts +2 -0
  39. package/dist/src/api/index.d.ts +2 -1
  40. package/dist/src/api/query.d.ts +9 -26
  41. package/dist/src/api.browser.d.ts +2 -18
  42. package/dist/src/api.node.d.ts +2 -1
  43. package/dist/src/cache/Cache.d.ts +53 -0
  44. package/dist/src/cache/CacheProvider.d.ts +25 -0
  45. package/dist/src/cache/EntityDataObject.d.ts +37 -0
  46. package/dist/src/cache/EntityNode.d.ts +56 -0
  47. package/dist/src/cache/ImpactedQueryRefsAccumulator.d.ts +23 -0
  48. package/dist/src/cache/InMemoryCacheProvider.d.ts +30 -0
  49. package/dist/src/cache/ResultTree.d.ts +42 -0
  50. package/dist/src/cache/ResultTreeProcessor.d.ts +40 -0
  51. package/dist/src/cache/cacheUtils.d.ts +20 -0
  52. package/dist/src/core/FirebaseAuthProvider.d.ts +3 -1
  53. package/dist/src/core/query/QueryManager.d.ts +47 -0
  54. package/dist/src/core/query/queryOptions.d.ts +25 -0
  55. package/dist/src/core/query/subscribe.d.ts +67 -0
  56. package/dist/src/network/fetch.d.ts +2 -5
  57. package/dist/src/network/index.d.ts +1 -1
  58. package/dist/src/network/transport/index.d.ts +37 -8
  59. package/dist/src/network/transport/rest.d.ts +5 -17
  60. package/dist/src/util/encoder.d.ts +4 -1
  61. package/dist/src/util/url.d.ts +1 -0
  62. package/package.json +7 -7
  63. package/dist/node-esm/src/core/QueryManager.d.ts +0 -45
  64. package/dist/src/core/QueryManager.d.ts +0 -45
package/dist/public.d.ts CHANGED
@@ -11,6 +11,13 @@ import { LogLevelString } from '@firebase/logger';
11
11
  import { FirebaseError } from '@firebase/util';
12
12
 
13
13
 
14
+ export declare interface CacheProvider<T extends StorageType> {
15
+ type: T;
16
+ }
17
+ export declare interface CacheSettings {
18
+ cacheProvider: CacheProvider<StorageType>;
19
+ maxAgeSeconds?: number;
20
+ }
14
21
  /**
15
22
  * enum representing different flavors of the SDK used by developers
16
23
  * use the CallerSdkType for type-checking, and the CallerSdkTypeEnum for value-checking/assigning
@@ -57,17 +64,27 @@ export declare class DataConnect {
57
64
  readonly app: FirebaseApp;
58
65
  private readonly dataConnectOptions;
59
66
  isEmulator: boolean;
67
+ /* Excluded from this release type: cache */
60
68
  constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>, _appCheckProvider: Provider<AppCheckInternalComponentName>);
61
69
  getSettings(): ConnectorConfig;
70
+ /* Excluded from this release type: setCacheSettings */
62
71
  setInitialized(): void;
63
72
  enableEmulator(transportOptions: TransportOptions): void;
64
73
  }
74
+ export declare interface DataConnectEntityArray {
75
+ entityIds: string[];
76
+ }
65
77
  /** An error returned by a DataConnect operation. */
66
78
  export declare class DataConnectError extends FirebaseError {
67
79
  /* Excluded from this release type: name */
68
80
  constructor(code: Code, message: string);
69
81
  }
70
82
  export declare type DataConnectErrorCode = 'other' | 'already-initialized' | 'not-initialized' | 'not-supported' | 'invalid-argument' | 'partial-error' | 'unauthorized';
83
+ export declare type DataConnectExtension = {
84
+ path: Array<string | number>;
85
+ } & (DataConnectEntityArray | DataConnectSingleEntity);
86
+ /* Excluded from this release type: DataConnectExtensionWithMaxAge */
87
+ /* Excluded from this release type: DataConnectMaxAge */
71
88
  /** An error returned by a DataConnect operation. */
72
89
  export declare class DataConnectOperationError extends DataConnectError {
73
90
  /* Excluded from this release type: name */
@@ -89,9 +106,24 @@ export declare interface DataConnectOperationFailureResponseErrorInfo {
89
106
  export declare interface DataConnectOptions extends ConnectorConfig {
90
107
  projectId: string;
91
108
  }
109
+ /* Excluded from this release type: DataConnectResponseWithMaxAge */
92
110
  export declare interface DataConnectResult<Data, Variables> extends OpResult<Data> {
93
111
  ref: OperationRef<Data, Variables>;
94
112
  }
113
+ export declare interface DataConnectSettings {
114
+ cacheSettings?: CacheSettings;
115
+ }
116
+ export declare interface DataConnectSingleEntity {
117
+ entityId: string;
118
+ }
119
+ /**
120
+ * Representation of user provided subscription options.
121
+ */
122
+ export declare interface DataConnectSubscription<Data, Variables> {
123
+ userCallback: OnResultSubscription<Data, Variables>;
124
+ errCallback?: (e?: DataConnectError) => void;
125
+ unsubscribe: () => void;
126
+ }
95
127
  /* Excluded from this release type: DataConnectTransport */
96
128
  export declare type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER;
97
129
  /**
@@ -105,18 +137,33 @@ export declare function executeMutation<Data, Variables>(mutationRef: MutationRe
105
137
  * @param queryRef query to execute.
106
138
  * @returns `QueryPromise`
107
139
  */
108
- export declare function executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
140
+ export declare function executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>, options?: ExecuteQueryOptions): QueryPromise<Data, Variables>;
141
+ export declare interface ExecuteQueryOptions {
142
+ fetchPolicy: QueryFetchPolicy;
143
+ }
144
+ export declare interface Extensions {
145
+ dataConnect?: DataConnectExtension[];
146
+ }
109
147
  /**
110
148
  * Initialize DataConnect instance
111
149
  * @param options ConnectorConfig
112
150
  */
151
+ export declare function getDataConnect(options: ConnectorConfig, settings?: DataConnectSettings): DataConnect;
113
152
  export declare function getDataConnect(options: ConnectorConfig): DataConnect;
114
153
  /**
115
154
  * Initialize DataConnect instance
116
155
  * @param app FirebaseApp to initialize to.
117
- * @param options ConnectorConfig
156
+ * @param connectorConfig ConnectorConfig
118
157
  */
119
- export declare function getDataConnect(app: FirebaseApp, options: ConnectorConfig): DataConnect;
158
+ export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig): DataConnect;
159
+ /**
160
+ * Initialize DataConnect instance
161
+ * @param app FirebaseApp to initialize to.
162
+ * @param connectorConfig ConnectorConfig
163
+ */
164
+ export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig, settings: DataConnectSettings): DataConnect;
165
+ /* Excluded from this release type: InternalQueryResult */
166
+ export declare function makeMemoryCacheProvider(): CacheProvider<'MEMORY'>;
120
167
  export declare const MUTATION_STR = "mutation";
121
168
  /* Excluded from this release type: MutationManager */
122
169
  /**
@@ -168,9 +215,32 @@ export declare interface OpResult<Data> {
168
215
  data: Data;
169
216
  source: DataSource;
170
217
  fetchTime: string;
218
+ extensions?: Extensions;
171
219
  }
172
220
  /* Excluded from this release type: parseOptions */
173
221
  export declare const QUERY_STR = "query";
222
+ /**
223
+ * @license
224
+ * Copyright 2025 Google LLC
225
+ *
226
+ * Licensed under the Apache License, Version 2.0 (the "License");
227
+ * you may not use this file except in compliance with the License.
228
+ * You may obtain a copy of the License at
229
+ *
230
+ * http://www.apache.org/licenses/LICENSE-2.0
231
+ *
232
+ * Unless required by applicable law or agreed to in writing, software
233
+ * distributed under the License is distributed on an "AS IS" BASIS,
234
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
235
+ * See the License for the specific language governing permissions and
236
+ * limitations under the License.
237
+ */
238
+ export declare const QueryFetchPolicy: {
239
+ readonly PREFER_CACHE: "PREFER_CACHE";
240
+ readonly CACHE_ONLY: "CACHE_ONLY";
241
+ readonly SERVER_ONLY: "SERVER_ONLY";
242
+ };
243
+ export declare type QueryFetchPolicy = (typeof QueryFetchPolicy)[keyof typeof QueryFetchPolicy];
174
244
  /**
175
245
  * Promise returned from `executeQuery`
176
246
  */
@@ -226,6 +296,10 @@ export declare interface SerializedRef<Data, Variables> extends OpResult<Data> {
226
296
  export declare function setLogLevel(logLevel: LogLevelString): void;
227
297
  export declare const SOURCE_CACHE = "CACHE";
228
298
  export declare const SOURCE_SERVER = "SERVER";
299
+ export declare const StorageType: {
300
+ readonly MEMORY: "MEMORY";
301
+ };
302
+ export declare type StorageType = (typeof StorageType)[keyof typeof StorageType];
229
303
  /**
230
304
  * Subscribe to a `QueryRef`
231
305
  * @param queryRefOrSerializedResult query ref or serialized result.
@@ -18,7 +18,9 @@ import { FirebaseApp } from '@firebase/app';
18
18
  import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
19
19
  import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
20
20
  import { Provider } from '@firebase/component';
21
- import { QueryManager } from '../core/QueryManager';
21
+ import { DataConnectCache } from '../cache/Cache';
22
+ import { InternalCacheProvider } from '../cache/CacheProvider';
23
+ import { QueryManager } from '../core/query/QueryManager';
22
24
  import { CallerSdkType } from '../network';
23
25
  import { MutationManager } from './Mutation';
24
26
  /**
@@ -69,11 +71,24 @@ export declare class DataConnect {
69
71
  _isUsingGeneratedSdk: boolean;
70
72
  _callerSdkType: CallerSdkType;
71
73
  private _appCheckTokenProvider?;
74
+ private _cacheSettings?;
75
+ /**
76
+ * @internal
77
+ */
78
+ private cache?;
72
79
  constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>, _appCheckProvider: Provider<AppCheckInternalComponentName>);
80
+ /**
81
+ * @internal
82
+ */
83
+ getCache(): DataConnectCache | undefined;
73
84
  _useGeneratedSdk(): void;
74
85
  _setCallerSdkType(callerSdkType: CallerSdkType): void;
75
86
  _delete(): Promise<void>;
76
87
  getSettings(): ConnectorConfig;
88
+ /**
89
+ * @internal
90
+ */
91
+ setCacheSettings(cacheSettings: CacheSettings): void;
77
92
  setInitialized(): void;
78
93
  enableEmulator(transportOptions: TransportOptions): void;
79
94
  }
@@ -92,17 +107,27 @@ export declare function areTransportOptionsEqual(transportOptions1: TransportOpt
92
107
  * @param sslEnabled use https
93
108
  */
94
109
  export declare function connectDataConnectEmulator(dc: DataConnect, host: string, port?: number, sslEnabled?: boolean): void;
110
+ export interface DataConnectSettings {
111
+ cacheSettings?: CacheSettings;
112
+ }
95
113
  /**
96
114
  * Initialize DataConnect instance
97
115
  * @param options ConnectorConfig
98
116
  */
117
+ export declare function getDataConnect(options: ConnectorConfig, settings?: DataConnectSettings): DataConnect;
99
118
  export declare function getDataConnect(options: ConnectorConfig): DataConnect;
100
119
  /**
101
120
  * Initialize DataConnect instance
102
121
  * @param app FirebaseApp to initialize to.
103
- * @param options ConnectorConfig
122
+ * @param connectorConfig ConnectorConfig
123
+ */
124
+ export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig): DataConnect;
125
+ /**
126
+ * Initialize DataConnect instance
127
+ * @param app FirebaseApp to initialize to.
128
+ * @param connectorConfig ConnectorConfig
104
129
  */
105
- export declare function getDataConnect(app: FirebaseApp, options: ConnectorConfig): DataConnect;
130
+ export declare function getDataConnect(app: FirebaseApp, connectorConfig: ConnectorConfig, settings: DataConnectSettings): DataConnect;
106
131
  /**
107
132
  *
108
133
  * @param dcOptions
@@ -116,3 +141,19 @@ export declare function validateDCOptions(dcOptions: ConnectorConfig): boolean;
116
141
  * @returns
117
142
  */
118
143
  export declare function terminate(dataConnect: DataConnect): Promise<void>;
144
+ export declare const StorageType: {
145
+ readonly MEMORY: "MEMORY";
146
+ };
147
+ export type StorageType = (typeof StorageType)[keyof typeof StorageType];
148
+ export interface CacheSettings {
149
+ cacheProvider: CacheProvider<StorageType>;
150
+ maxAgeSeconds?: number;
151
+ }
152
+ export interface CacheProvider<T extends StorageType> {
153
+ type: T;
154
+ /**
155
+ * @internal
156
+ */
157
+ initialize(cacheId: string): InternalCacheProvider;
158
+ }
159
+ export declare function makeMemoryCacheProvider(): CacheProvider<'MEMORY'>;
@@ -14,6 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { Extensions } from '../network';
17
18
  import { DataConnect, DataConnectOptions } from './DataConnect';
18
19
  export declare const QUERY_STR = "query";
19
20
  export declare const MUTATION_STR = "mutation";
@@ -25,6 +26,7 @@ export interface OpResult<Data> {
25
26
  data: Data;
26
27
  source: DataSource;
27
28
  fetchTime: string;
29
+ extensions?: Extensions;
28
30
  }
29
31
  export interface OperationRef<_Data, Variables> {
30
32
  name: string;
@@ -15,7 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  export * from '../network';
18
- export * from './DataConnect';
18
+ export { ExecuteQueryOptions, QueryFetchPolicy } from '../core/query/queryOptions';
19
+ export { CacheSettings, validateDCOptions, ConnectorConfig, DataConnect, DataConnectOptions, DataConnectSettings, StorageType, TransportOptions, areTransportOptionsEqual, connectDataConnectEmulator, getDataConnect, parseOptions, terminate } from './DataConnect';
19
20
  export * from './Reference';
20
21
  export * from './Mutation';
21
22
  export * from './query';
@@ -14,27 +14,22 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { DataConnectError } from '../core/error';
17
+ import { ExecuteQueryOptions } from '../core/query/queryOptions';
18
+ import { DataConnectExtensionWithMaxAge } from '../network/transport';
18
19
  import { DataConnect } from './DataConnect';
19
20
  import { OperationRef, QUERY_STR, DataConnectResult, SerializedRef } from './Reference';
20
- /**
21
- * Signature for `OnResultSubscription` for `subscribe`
22
- */
23
- export type OnResultSubscription<Data, Variables> = (res: QueryResult<Data, Variables>) => void;
24
- /**
25
- * Signature for `OnErrorSubscription` for `subscribe`
26
- */
27
- export type OnErrorSubscription = (err?: DataConnectError) => void;
28
- /**
29
- * Signature for unsubscribe from `subscribe`
30
- */
31
- export type QueryUnsubscribe = () => void;
32
21
  /**
33
22
  * QueryRef object
34
23
  */
35
24
  export interface QueryRef<Data, Variables> extends OperationRef<Data, Variables> {
36
25
  refType: typeof QUERY_STR;
37
26
  }
27
+ /** @internal */
28
+ export type InternalQueryResult<Data, Variables> = QueryResult<Data, Variables> & Omit<DataConnectResult<Data, Variables>, 'extensions'> & {
29
+ extensions?: {
30
+ dataConnect?: DataConnectExtensionWithMaxAge[];
31
+ };
32
+ };
38
33
  /**
39
34
  * Result of `executeQuery`
40
35
  */
@@ -52,7 +47,7 @@ export interface QueryPromise<Data, Variables> extends Promise<QueryResult<Data,
52
47
  * @param queryRef query to execute.
53
48
  * @returns `QueryPromise`
54
49
  */
55
- export declare function executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
50
+ export declare function executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>, options?: ExecuteQueryOptions): QueryPromise<Data, Variables>;
56
51
  /**
57
52
  * Execute Query
58
53
  * @param dcInstance Data Connect instance to use.
@@ -74,15 +69,3 @@ export declare function queryRef<Data, Variables>(dcInstance: DataConnect, query
74
69
  * @returns `QueryRef`
75
70
  */
76
71
  export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<Data, Variables>;
77
- /**
78
- * `OnCompleteSubscription`
79
- */
80
- export type OnCompleteSubscription = () => void;
81
- /**
82
- * Representation of full observer options in `subscribe`
83
- */
84
- export interface SubscriptionOptions<Data, Variables> {
85
- onNext?: OnResultSubscription<Data, Variables>;
86
- onErr?: OnErrorSubscription;
87
- onComplete?: OnCompleteSubscription;
88
- }
@@ -14,21 +14,5 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { OnCompleteSubscription, OnErrorSubscription, OnResultSubscription, QueryRef, QueryUnsubscribe, SubscriptionOptions } from './api/query';
18
- import { SerializedRef } from './api/Reference';
19
- /**
20
- * Subscribe to a `QueryRef`
21
- * @param queryRefOrSerializedResult query ref or serialized result.
22
- * @param observer observer object to use for subscribing.
23
- * @returns `SubscriptionOptions`
24
- */
25
- export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: QueryRef<Data, Variables> | SerializedRef<Data, Variables>, observer: SubscriptionOptions<Data, Variables>): QueryUnsubscribe;
26
- /**
27
- * Subscribe to a `QueryRef`
28
- * @param queryRefOrSerializedResult query ref or serialized result.
29
- * @param onNext Callback to call when result comes back.
30
- * @param onError Callback to call when error gets thrown.
31
- * @param onComplete Called when subscription completes.
32
- * @returns `SubscriptionOptions`
33
- */
34
- export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: QueryRef<Data, Variables> | SerializedRef<Data, Variables>, onNext: OnResultSubscription<Data, Variables>, onError?: OnErrorSubscription, onComplete?: OnCompleteSubscription): QueryUnsubscribe;
17
+ export * from './core/query/subscribe';
18
+ export { makeMemoryCacheProvider, CacheProvider } from './api/DataConnect';
@@ -14,4 +14,5 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export { subscribe } from './api.browser';
17
+ export * from './core/query/subscribe';
18
+ export { makeMemoryCacheProvider, CacheProvider } from './api/DataConnect';
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 { CacheProvider, CacheSettings, type ConnectorConfig } from '../api/DataConnect';
18
+ import { type AuthTokenProvider } from '../core/FirebaseAuthProvider';
19
+ import { InternalCacheProvider } from './CacheProvider';
20
+ import { InMemoryCacheProvider } from './InMemoryCacheProvider';
21
+ import { ResultTree } from './ResultTree';
22
+ export declare const Memory = "memory";
23
+ export type DataConnectStorage = typeof Memory;
24
+ /**
25
+ * ServerValues
26
+ */
27
+ export interface ServerValues extends Record<string, unknown> {
28
+ maxAge?: number;
29
+ }
30
+ export declare class DataConnectCache {
31
+ private authProvider;
32
+ private projectId;
33
+ private connectorConfig;
34
+ private host;
35
+ cacheSettings: CacheSettings;
36
+ private cacheProvider;
37
+ private uid;
38
+ constructor(authProvider: AuthTokenProvider, projectId: string, connectorConfig: ConnectorConfig, host: string, cacheSettings: CacheSettings);
39
+ initialize(): Promise<void>;
40
+ getIdentifier(uid: string | null): Promise<string>;
41
+ initializeNewProviders(identifier: string): InternalCacheProvider;
42
+ containsResultTree(queryId: string): Promise<boolean>;
43
+ getResultTree(queryId: string): Promise<ResultTree | undefined>;
44
+ getResultJSON(queryId: string): Promise<Record<string, unknown>>;
45
+ update(queryId: string, serverValues: ServerValues, entityIds: Record<string, unknown>): Promise<string[]>;
46
+ }
47
+ export declare class MemoryStub implements CacheProvider<'MEMORY'> {
48
+ type: 'MEMORY';
49
+ /**
50
+ * @internal
51
+ */
52
+ initialize(cacheId: string): InMemoryCacheProvider;
53
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 { EntityDataObject } from './EntityDataObject';
18
+ import { ResultTree } from './ResultTree';
19
+ export interface InternalCacheProvider {
20
+ getEntityData(globalId: string): Promise<EntityDataObject>;
21
+ updateEntityData(entityData: EntityDataObject): Promise<void>;
22
+ getResultTree(queryId: string): Promise<ResultTree | undefined>;
23
+ setResultTree(queryId: string, resultTree: ResultTree): Promise<void>;
24
+ close(): void;
25
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 type FDCScalarValue = string | number | boolean | undefined | null | Record<string, unknown> | FDCScalarValue[];
18
+ export interface EntityDataObjectJson {
19
+ map: {
20
+ [key: string]: FDCScalarValue;
21
+ };
22
+ referencedFrom: string[];
23
+ globalID: string;
24
+ }
25
+ export declare class EntityDataObject {
26
+ readonly globalID: string;
27
+ getServerValue(key: string): unknown;
28
+ private serverValues;
29
+ private referencedFrom;
30
+ constructor(globalID: string);
31
+ getServerValues(): {
32
+ [key: string]: FDCScalarValue;
33
+ };
34
+ toJSON(): EntityDataObjectJson;
35
+ static fromJSON(json: EntityDataObjectJson): EntityDataObject;
36
+ updateServerValue(key: string, value: FDCScalarValue, requestedFrom: string): string[];
37
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 { InternalCacheProvider } from './CacheProvider';
18
+ import { EntityDataObject, EntityDataObjectJson, FDCScalarValue } from './EntityDataObject';
19
+ import { ImpactedQueryRefsAccumulator } from './ImpactedQueryRefsAccumulator';
20
+ export declare const GLOBAL_ID_KEY = "_id";
21
+ export declare const OBJECT_LISTS_KEY = "_objectLists";
22
+ export declare const REFERENCES_KEY = "_references";
23
+ export declare const SCALARS_KEY = "_scalars";
24
+ export declare const ENTITY_DATA_KEYS_KEY = "_entity_data_keys";
25
+ export declare class EntityNode {
26
+ entityData?: EntityDataObject;
27
+ scalars: Record<string, FDCScalarValue>;
28
+ references: {
29
+ [key: string]: EntityNode;
30
+ };
31
+ objectLists: {
32
+ [key: string]: EntityNode[];
33
+ };
34
+ globalId?: string;
35
+ entityDataKeys: Set<string>;
36
+ loadData(queryId: string, values: FDCScalarValue, entityIds: Record<string, unknown> | undefined, acc: ImpactedQueryRefsAccumulator, cacheProvider: InternalCacheProvider): Promise<void>;
37
+ toJSON(mode: EncodingMode): Record<string, unknown>;
38
+ static fromJson(obj: DehydratedStubDataObject): EntityNode;
39
+ }
40
+ export interface DehydratedStubDataObject {
41
+ backingData?: EntityDataObjectJson;
42
+ globalID?: string;
43
+ scalars: {
44
+ [key: string]: FDCScalarValue;
45
+ };
46
+ references: {
47
+ [key: string]: DehydratedStubDataObject;
48
+ };
49
+ objectLists: {
50
+ [key: string]: DehydratedStubDataObject[];
51
+ };
52
+ }
53
+ export declare enum EncodingMode {
54
+ hydrated = 0,
55
+ dehydrated = 1
56
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 declare class ImpactedQueryRefsAccumulator {
18
+ private queryId;
19
+ impacted: Set<string>;
20
+ constructor(queryId: string);
21
+ add(impacted: string[]): void;
22
+ consumeEvents(): string[];
23
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 { InternalCacheProvider } from './CacheProvider';
18
+ import { EntityDataObject } from './EntityDataObject';
19
+ import { ResultTree } from './ResultTree';
20
+ export declare class InMemoryCacheProvider implements InternalCacheProvider {
21
+ private _keyId;
22
+ private edos;
23
+ private resultTrees;
24
+ constructor(_keyId: string);
25
+ setResultTree(queryId: string, rt: ResultTree): Promise<void>;
26
+ getResultTree(queryId: string): Promise<ResultTree | undefined>;
27
+ updateEntityData(entityData: EntityDataObject): Promise<void>;
28
+ getEntityData(globalId: string): Promise<EntityDataObject>;
29
+ close(): Promise<void>;
30
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 { EntityNode, DehydratedStubDataObject } from './EntityNode';
18
+ export declare class ResultTree {
19
+ private rootStub;
20
+ private maxAge;
21
+ readonly cachedAt: Date;
22
+ private _lastAccessed;
23
+ /**
24
+ * Create a {@link ResultTree} from a dehydrated JSON object.
25
+ * @param value The dehydrated JSON object.
26
+ * @returns The {@link ResultTree}.
27
+ */
28
+ static fromJson(value: DehydratedResultTreeJson): ResultTree;
29
+ constructor(rootStub: EntityNode, maxAge: number, cachedAt: Date, _lastAccessed: Date);
30
+ isStale(): boolean;
31
+ updateMaxAge(maxAgeInSeconds: number): void;
32
+ updateAccessed(): void;
33
+ get lastAccessed(): Date;
34
+ getRootStub(): EntityNode;
35
+ }
36
+ interface DehydratedResultTreeJson {
37
+ rootStub: DehydratedStubDataObject;
38
+ maxAge: number;
39
+ cachedAt: Date;
40
+ lastAccessed: Date;
41
+ }
42
+ export {};
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 { InternalCacheProvider } from './CacheProvider';
18
+ import { EntityNode } from './EntityNode';
19
+ interface DehydratedResults {
20
+ entityNode: EntityNode;
21
+ impacted: string[];
22
+ }
23
+ export declare class ResultTreeProcessor {
24
+ /**
25
+ * Hydrate the EntityNode into a JSON object so that it can be returned to the user.
26
+ * @param rootStubObject
27
+ * @returns {string}
28
+ */
29
+ hydrateResults(rootStubObject: EntityNode): Record<string, unknown>;
30
+ /**
31
+ * Dehydrate results so that they can be stored in the cache.
32
+ * @param json
33
+ * @param entityIds
34
+ * @param cacheProvider
35
+ * @param queryId
36
+ * @returns {Promise<DehydratedResults>}
37
+ */
38
+ dehydrateResults(json: Record<string, unknown>, entityIds: Record<string, unknown>, cacheProvider: InternalCacheProvider, queryId: string): Promise<DehydratedResults>;
39
+ }
40
+ export {};