@firebase/data-connect 0.0.2-dataconnect-preview.877f8b7d0 → 0.0.3-canary.beaa4dffb

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 +304 -54
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm2017.js +303 -53
  4. package/dist/index.esm2017.js.map +1 -1
  5. package/dist/index.esm5.js +323 -52
  6. package/dist/index.esm5.js.map +1 -1
  7. package/dist/index.node.cjs.js +324 -53
  8. package/dist/index.node.cjs.js.map +1 -1
  9. package/dist/internal.d.ts +186 -41
  10. package/dist/node-esm/index.node.esm.js +303 -53
  11. package/dist/node-esm/index.node.esm.js.map +1 -1
  12. package/dist/node-esm/src/api/DataConnect.d.ts +47 -3
  13. package/dist/node-esm/src/api/Mutation.d.ts +26 -1
  14. package/dist/node-esm/src/api/Reference.d.ts +6 -0
  15. package/dist/node-esm/src/api/index.d.ts +1 -0
  16. package/dist/node-esm/src/api/query.d.ts +51 -1
  17. package/dist/node-esm/src/api.browser.d.ts +12 -7
  18. package/dist/node-esm/src/core/AppCheckTokenProvider.d.ts +30 -0
  19. package/dist/node-esm/src/core/FirebaseAuthProvider.d.ts +1 -1
  20. package/dist/node-esm/src/core/QueryManager.d.ts +1 -1
  21. package/dist/node-esm/src/core/error.d.ts +2 -1
  22. package/dist/node-esm/src/network/fetch.d.ts +1 -1
  23. package/dist/node-esm/src/network/transport/index.d.ts +8 -10
  24. package/dist/node-esm/src/network/transport/rest.d.ts +24 -10
  25. package/dist/node-esm/src/util/validateArgs.d.ts +33 -0
  26. package/dist/private.d.ts +152 -59
  27. package/dist/public.d.ts +133 -50
  28. package/dist/src/api/DataConnect.d.ts +47 -3
  29. package/dist/src/api/Mutation.d.ts +26 -1
  30. package/dist/src/api/Reference.d.ts +6 -0
  31. package/dist/src/api/index.d.ts +1 -0
  32. package/dist/src/api/query.d.ts +51 -1
  33. package/dist/src/api.browser.d.ts +12 -7
  34. package/dist/src/core/AppCheckTokenProvider.d.ts +30 -0
  35. package/dist/src/core/FirebaseAuthProvider.d.ts +1 -1
  36. package/dist/src/core/QueryManager.d.ts +1 -1
  37. package/dist/src/core/error.d.ts +2 -1
  38. package/dist/src/network/fetch.d.ts +1 -1
  39. package/dist/src/network/transport/index.d.ts +8 -10
  40. package/dist/src/network/transport/rest.d.ts +24 -10
  41. package/dist/src/util/validateArgs.d.ts +33 -0
  42. package/package.json +11 -7
@@ -4,17 +4,32 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
 
7
+ import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
8
+ import { AppCheckTokenListener } from '@firebase/app-check-interop-types';
9
+ import { AppCheckTokenResult } from '@firebase/app-check-interop-types';
7
10
  import { FirebaseApp } from '@firebase/app';
8
11
  import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
9
12
  import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
10
13
  import { FirebaseError } from '@firebase/util';
11
- import { FirebaseOptions } from '@firebase/app';
12
14
  import { LogLevelString } from '@firebase/logger';
13
15
  import { Provider } from '@firebase/component';
14
16
 
15
- export declare type AuthTokenListener = (token: string | null) => void;
17
+ /**
18
+ * @internal
19
+ * Abstraction around AppCheck's token fetching capabilities.
20
+ */
21
+ declare class AppCheckTokenProvider {
22
+ private appName_;
23
+ private appCheckProvider?;
24
+ private appCheck?;
25
+ constructor(appName_: string, appCheckProvider?: Provider<AppCheckInternalComponentName>);
26
+ getToken(forceRefresh?: boolean): Promise<AppCheckTokenResult>;
27
+ addTokenChangeListener(listener: AppCheckTokenListener): void;
28
+ }
16
29
 
17
- export declare interface AuthTokenProvider {
30
+ declare type AuthTokenListener = (token: string | null) => void;
31
+
32
+ declare interface AuthTokenProvider {
18
33
  getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;
19
34
  addTokenChangeListener(listener: AuthTokenListener): void;
20
35
  }
@@ -25,27 +40,44 @@ export declare interface CancellableOperation<T> extends PromiseLike<{
25
40
  cancel: () => void;
26
41
  }
27
42
 
43
+ /**
44
+ * Connect to the DataConnect Emulator
45
+ * @param dc Data Connect instance
46
+ * @param host host of emulator server
47
+ * @param port port of emulator server
48
+ * @param sslEnabled use https
49
+ */
28
50
  export declare function connectDataConnectEmulator(dc: DataConnect, host: string, port?: number, sslEnabled?: boolean): void;
29
51
 
52
+ /**
53
+ * Connector Config for calling Data Connect backend.
54
+ */
30
55
  export declare interface ConnectorConfig {
31
56
  location: string;
32
57
  connector: string;
33
58
  service: string;
34
59
  }
35
60
 
61
+ /**
62
+ * Class representing Firebase Data Connect
63
+ */
36
64
  export declare class DataConnect {
37
65
  readonly app: FirebaseApp;
38
66
  private readonly dataConnectOptions;
39
67
  private readonly _authProvider;
68
+ private readonly _appCheckProvider;
40
69
  _queryManager: QueryManager;
41
70
  _mutationManager: MutationManager;
42
71
  isEmulator: boolean;
43
- initialized: boolean;
72
+ _initialized: boolean;
44
73
  private _transport;
45
74
  private _transportClass;
46
75
  private _transportOptions?;
47
76
  private _authTokenProvider?;
48
- constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>);
77
+ _isUsingGeneratedSdk: boolean;
78
+ private _appCheckTokenProvider?;
79
+ constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>, _appCheckProvider: Provider<AppCheckInternalComponentName>);
80
+ _useGeneratedSdk(): void;
49
81
  _delete(): Promise<void>;
50
82
  getSettings(): ConnectorConfig;
51
83
  setInitialized(): void;
@@ -76,8 +108,11 @@ declare class DataConnectError extends FirebaseError {
76
108
  message: string);
77
109
  }
78
110
 
79
- declare type DataConnectErrorCode = 'other' | 'already-initialized' | 'not-initialized' | 'not-supported' | 'invalid-argument' | 'partial-error';
111
+ declare type DataConnectErrorCode = 'other' | 'already-initialized' | 'not-initialized' | 'not-supported' | 'invalid-argument' | 'partial-error' | 'unauthorized';
80
112
 
113
+ /**
114
+ * DataConnectOptions including project id
115
+ */
81
116
  export declare interface DataConnectOptions extends ConnectorConfig {
82
117
  projectId: string;
83
118
  }
@@ -86,12 +121,18 @@ export declare interface DataConnectResult<Data, Variables> extends OpResult<Dat
86
121
  ref: OperationRef<Data, Variables>;
87
122
  }
88
123
 
124
+ /**
125
+ * Representation of user provided subscription options.
126
+ */
89
127
  export declare interface DataConnectSubscription<Data, Variables> {
90
128
  userCallback: OnResultSubscription<Data, Variables>;
91
129
  errCallback?: (e?: DataConnectError) => void;
92
130
  unsubscribe: () => void;
93
131
  }
94
132
 
133
+ /**
134
+ * @internal
135
+ */
95
136
  export declare interface DataConnectTransport {
96
137
  invokeQuery<T, U>(queryName: string, body?: U): PromiseLike<{
97
138
  data: T;
@@ -107,29 +148,38 @@ export declare interface DataConnectTransport {
107
148
 
108
149
  export declare type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER;
109
150
 
151
+ /**
152
+ * Execute Mutation
153
+ * @param mutationRef mutation to execute
154
+ * @returns `MutationRef`
155
+ */
110
156
  export declare function executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
111
157
 
158
+ /**
159
+ * Execute Query
160
+ * @param queryRef query to execute.
161
+ * @returns `QueryPromise`
162
+ */
112
163
  export declare function executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
113
164
 
114
- export declare const FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = "FIREBASE_DATA_CONNECT_EMULATOR_HOST";
115
-
116
- export declare class FirebaseAuthProvider implements AuthTokenProvider {
117
- private _appName;
118
- private _options;
119
- private _authProvider;
120
- private _auth;
121
- constructor(_appName: string, _options: FirebaseOptions, _authProvider: Provider<FirebaseAuthInternalName>);
122
- getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;
123
- addTokenChangeListener(listener: AuthTokenListener): void;
124
- removeTokenChangeListener(listener: (token: string | null) => void): void;
125
- }
126
-
165
+ /**
166
+ * Initialize DataConnect instance
167
+ * @param options ConnectorConfig
168
+ */
127
169
  export declare function getDataConnect(options: ConnectorConfig): DataConnect;
128
170
 
171
+ /**
172
+ * Initialize DataConnect instance
173
+ * @param app FirebaseApp to initialize to.
174
+ * @param options ConnectorConfig
175
+ */
129
176
  export declare function getDataConnect(app: FirebaseApp, options: ConnectorConfig): DataConnect;
130
177
 
131
178
  export declare const MUTATION_STR = "mutation";
132
179
 
180
+ /**
181
+ * @internal
182
+ */
133
183
  export declare class MutationManager {
134
184
  private _transport;
135
185
  private _inflight;
@@ -137,6 +187,9 @@ export declare class MutationManager {
137
187
  executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
138
188
  }
139
189
 
190
+ /**
191
+ * Mutation return value from `executeMutation`
192
+ */
140
193
  export declare interface MutationPromise<Data, Variables> extends PromiseLike<MutationResult<Data, Variables>> {
141
194
  }
142
195
 
@@ -144,21 +197,41 @@ export declare interface MutationRef<Data, Variables> extends OperationRef<Data,
144
197
  refType: typeof MUTATION_STR;
145
198
  }
146
199
 
147
- export declare function mutationRef<Data>(dcInstance: DataConnect, queryName: string): MutationRef<Data, undefined>;
200
+ /**
201
+ * Creates a `MutationRef`
202
+ * @param dcInstance Data Connect instance
203
+ * @param mutationName name of mutation
204
+ */
205
+ export declare function mutationRef<Data>(dcInstance: DataConnect, mutationName: string): MutationRef<Data, undefined>;
148
206
 
207
+ /**
208
+ *
209
+ * @param dcInstance Data Connect instance
210
+ * @param mutationName name of mutation
211
+ * @param variables variables to send with mutation
212
+ */
149
213
  export declare function mutationRef<Data, Variables>(dcInstance: DataConnect, mutationName: string, variables: Variables): MutationRef<Data, Variables>;
150
214
 
151
- export declare interface MutationResponse<T> extends CancellableOperation<T> {
152
- }
153
-
215
+ /**
216
+ * Mutation Result from `executeMutation`
217
+ */
154
218
  export declare interface MutationResult<Data, Variables> extends DataConnectResult<Data, Variables> {
155
219
  ref: MutationRef<Data, Variables>;
156
220
  }
157
221
 
222
+ /**
223
+ * `OnCompleteSubscription`
224
+ */
158
225
  export declare type OnCompleteSubscription = () => void;
159
226
 
227
+ /**
228
+ * Signature for `OnErrorSubscription` for `subscribe`
229
+ */
160
230
  export declare type OnErrorSubscription = (err?: DataConnectError) => void;
161
231
 
232
+ /**
233
+ * Signature for `OnResultSubscription` for `subscribe`
234
+ */
162
235
  export declare type OnResultSubscription<Data, Variables> = (res: QueryResult<Data, Variables>) => void;
163
236
 
164
237
  export declare interface OperationRef<_Data, Variables> {
@@ -174,6 +247,11 @@ export declare interface OpResult<Data> {
174
247
  fetchTime: string;
175
248
  }
176
249
 
250
+ declare interface ParsedArgs<Variables> {
251
+ dc: DataConnect;
252
+ vars: Variables;
253
+ }
254
+
177
255
  /**
178
256
  *
179
257
  * @param fullHost
@@ -188,46 +266,69 @@ declare class QueryManager {
188
266
  private transport;
189
267
  _queries: Map<string, TrackedQuery<unknown, unknown>>;
190
268
  constructor(transport: DataConnectTransport);
191
- track<Data, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Data>): TrackedQuery<unknown, unknown>;
269
+ track<Data, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Data>): TrackedQuery<Data, Variables>;
192
270
  addSubscription<Data, Variables>(queryRef: OperationRef<Data, Variables>, onResultCallback: OnResultSubscription<Data, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Data>): () => void;
193
271
  executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
194
272
  enableEmulator(host: string, port: number): void;
195
273
  }
196
274
 
275
+ /**
276
+ * Promise returned from `executeQuery`
277
+ */
197
278
  export declare interface QueryPromise<Data, Variables> extends PromiseLike<QueryResult<Data, Variables>> {
198
279
  }
199
280
 
281
+ /**
282
+ * QueryRef object
283
+ */
200
284
  export declare interface QueryRef<Data, Variables> extends OperationRef<Data, Variables> {
201
285
  refType: typeof QUERY_STR;
202
286
  }
203
287
 
288
+ /**
289
+ * Execute Query
290
+ * @param dcInstance Data Connect instance to use.
291
+ * @param queryName Query to execute
292
+ * @returns `QueryRef`
293
+ */
204
294
  export declare function queryRef<Data>(dcInstance: DataConnect, queryName: string): QueryRef<Data, undefined>;
205
295
 
296
+ /**
297
+ * Execute Query
298
+ * @param dcInstance Data Connect instance to use.
299
+ * @param queryName Query to execute
300
+ * @param variables Variables to execute with
301
+ * @returns `QueryRef`
302
+ */
206
303
  export declare function queryRef<Data, Variables>(dcInstance: DataConnect, queryName: string, variables: Variables): QueryRef<Data, Variables>;
207
304
 
208
- export declare interface QueryResponse<T> extends CancellableOperation<T> {
209
- }
210
-
305
+ /**
306
+ * Result of `executeQuery`
307
+ */
211
308
  export declare interface QueryResult<Data, Variables> extends DataConnectResult<Data, Variables> {
212
309
  ref: QueryRef<Data, Variables>;
213
310
  toJSON: () => SerializedRef<Data, Variables>;
214
311
  }
215
312
 
313
+ /**
314
+ * Signature for unsubscribe from `subscribe`
315
+ */
216
316
  export declare type QueryUnsubscribe = () => void;
217
317
 
218
318
  export declare type ReferenceType = typeof QUERY_STR | typeof MUTATION_STR;
219
319
 
320
+ /**
321
+ * Serialized RefInfo as a result of `QueryResult.toJSON().refInfo`
322
+ */
220
323
  export declare interface RefInfo<Variables> {
221
324
  name: string;
222
325
  variables: Variables;
223
326
  connectorConfig: DataConnectOptions;
224
327
  }
225
328
 
226
- export declare interface Sender<T> {
227
- abort: () => void;
228
- send: () => Promise<T>;
229
- }
230
-
329
+ /**
330
+ * Serialized Ref as a result of `QueryResult.toJSON()`
331
+ */
231
332
  export declare interface SerializedRef<Data, Variables> extends OpResult<Data> {
232
333
  refInfo: RefInfo<Variables>;
233
334
  }
@@ -239,27 +340,45 @@ export declare const SOURCE_CACHE = "CACHE";
239
340
  export declare const SOURCE_SERVER = "SERVER";
240
341
 
241
342
  /**
242
- *
243
- * @public
244
- * @param queryRef
245
- * @param onResult
246
- * @param onErr
247
- * @param initialCache
248
- * @returns
343
+ * Subscribe to a `QueryRef`
344
+ * @param queryRefOrSerializedResult query ref or serialized result.
345
+ * @param observer observer object to use for subscribing.
346
+ * @returns `SubscriptionOptions`
249
347
  */
250
348
  export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: QueryRef<Data, Variables> | SerializedRef<Data, Variables>, observer: SubscriptionOptions<Data, Variables>): QueryUnsubscribe;
251
349
 
350
+ /**
351
+ * Subscribe to a `QueryRef`
352
+ * @param queryRefOrSerializedResult query ref or serialized result.
353
+ * @param onNext Callback to call when result comes back.
354
+ * @param onError Callback to call when error gets thrown.
355
+ * @param onComplete Called when subscription completes.
356
+ * @returns `SubscriptionOptions`
357
+ */
252
358
  export declare function subscribe<Data, Variables>(queryRefOrSerializedResult: QueryRef<Data, Variables> | SerializedRef<Data, Variables>, onNext: OnResultSubscription<Data, Variables>, onError?: OnErrorSubscription, onComplete?: OnCompleteSubscription): QueryUnsubscribe;
253
359
 
360
+ /**
361
+ * Representation of full observer options in `subscribe`
362
+ */
254
363
  export declare interface SubscriptionOptions<Data, Variables> {
255
364
  onNext?: OnResultSubscription<Data, Variables>;
256
365
  onErr?: OnErrorSubscription;
257
366
  onComplete?: OnCompleteSubscription;
258
367
  }
259
368
 
369
+ /**
370
+ * Delete DataConnect instance
371
+ * @param dataConnect DataConnect instance
372
+ * @returns
373
+ */
260
374
  export declare function terminate(dataConnect: DataConnect): Promise<void>;
261
375
 
262
- export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<unknown, Variables>;
376
+ /**
377
+ * Converts serialized ref to query ref
378
+ * @param serializedRef ref to convert to `QueryRef`
379
+ * @returns `QueryRef`
380
+ */
381
+ export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<Data, Variables>;
263
382
 
264
383
  declare interface TrackedQuery<Data, Variables> {
265
384
  ref: Omit<OperationRef<Data, Variables>, 'dataConnect'>;
@@ -268,12 +387,38 @@ declare interface TrackedQuery<Data, Variables> {
268
387
  lastError: DataConnectError | null;
269
388
  }
270
389
 
271
- export declare type TransportClass = new (options: DataConnectOptions, apiKey?: string, authProvider?: AuthTokenProvider, transportOptions?: TransportOptions) => DataConnectTransport;
390
+ /**
391
+ * @internal
392
+ */
393
+ export declare type TransportClass = new (options: DataConnectOptions, apiKey?: string, appId?: string, authProvider?: AuthTokenProvider, appCheckProvider?: AppCheckTokenProvider, transportOptions?: TransportOptions, _isUsingGen?: boolean) => DataConnectTransport;
272
394
 
395
+ /**
396
+ * Options to connect to emulator
397
+ */
273
398
  export declare interface TransportOptions {
274
399
  host: string;
275
400
  sslEnabled?: boolean;
276
401
  port?: number;
277
402
  }
278
403
 
404
+ /**
405
+ * The generated SDK will allow the user to pass in either the variable or the data connect instance with the variable,
406
+ * and this function validates the variables and returns back the DataConnect instance and variables based on the arguments passed in.
407
+ * @param connectorConfig
408
+ * @param dcOrVars
409
+ * @param vars
410
+ * @param validateVars
411
+ * @returns {DataConnect} and {Variables} instance
412
+ * @internal
413
+ */
414
+ export declare function validateArgs<Variables extends object>(connectorConfig: ConnectorConfig, dcOrVars?: DataConnect | Variables, vars?: Variables, validateVars?: boolean): ParsedArgs<Variables>;
415
+
416
+ /**
417
+ *
418
+ * @param dcOptions
419
+ * @returns {void}
420
+ * @internal
421
+ */
422
+ export declare function validateDCOptions(dcOptions: ConnectorConfig): boolean;
423
+
279
424
  export { }