@firebase/data-connect 0.0.1-dataconnect-preview.81ee5169c → 0.0.2-dataconnect-preview.388b61c7e

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