@firebase/data-connect 0.0.1-dataconnect-preview.323fdc1b8 → 0.0.2-dataconnect-preview.877f8b7d0

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 (36) hide show
  1. package/dist/index.cjs.js +124 -162
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm2017.js +123 -160
  4. package/dist/index.esm2017.js.map +1 -1
  5. package/dist/index.esm5.js +125 -163
  6. package/dist/index.esm5.js.map +1 -1
  7. package/dist/index.node.cjs.js +74 -93
  8. package/dist/index.node.cjs.js.map +1 -1
  9. package/dist/internal.d.ts +30 -48
  10. package/dist/node-esm/index.node.esm.js +75 -92
  11. package/dist/node-esm/index.node.esm.js.map +1 -1
  12. package/dist/node-esm/src/api/DataConnect.d.ts +6 -12
  13. package/dist/node-esm/src/api/Mutation.d.ts +8 -8
  14. package/dist/node-esm/src/api/Reference.d.ts +3 -3
  15. package/dist/node-esm/src/api/query.d.ts +2 -2
  16. package/dist/node-esm/src/core/FirebaseAuthProvider.d.ts +5 -15
  17. package/dist/node-esm/src/core/QueryManager.d.ts +7 -7
  18. package/dist/node-esm/src/network/transport/rest.d.ts +13 -25
  19. package/dist/node-esm/src/util/url.d.ts +2 -2
  20. package/dist/private.d.ts +30 -48
  21. package/dist/public.d.ts +13 -38
  22. package/dist/src/api/DataConnect.d.ts +6 -12
  23. package/dist/src/api/Mutation.d.ts +8 -8
  24. package/dist/src/api/Reference.d.ts +3 -3
  25. package/dist/src/api/query.d.ts +2 -2
  26. package/dist/src/core/FirebaseAuthProvider.d.ts +5 -15
  27. package/dist/src/core/QueryManager.d.ts +7 -7
  28. package/dist/src/network/transport/rest.d.ts +13 -25
  29. package/dist/src/util/url.d.ts +2 -2
  30. package/package.json +7 -7
  31. package/dist/node-esm/test/emulatorSeeder.d.ts +0 -22
  32. package/dist/node-esm/test/queries.test.d.ts +0 -17
  33. package/dist/node-esm/test/util.d.ts +0 -26
  34. package/dist/test/emulatorSeeder.d.ts +0 -22
  35. package/dist/test/queries.test.d.ts +0 -17
  36. package/dist/test/util.d.ts +0 -26
@@ -149,6 +149,8 @@ function dcFetch(url, body, _a, accessToken) {
149
149
  method: 'POST',
150
150
  headers: headers,
151
151
  signal: signal
152
+ }).catch(function (err) {
153
+ throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
152
154
  })
153
155
  .then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
154
156
  var jsonResponse, e_1;
@@ -186,7 +188,7 @@ function dcFetch(url, body, _a, accessToken) {
186
188
  }
187
189
 
188
190
  var name = "@firebase/data-connect";
189
- var version = "0.0.1-dataconnect-preview.323fdc1b8";
191
+ var version = "0.0.2-dataconnect-preview.877f8b7d0";
190
192
 
191
193
  /**
192
194
  * @license
@@ -205,22 +207,22 @@ var version = "0.0.1-dataconnect-preview.323fdc1b8";
205
207
  * limitations under the License.
206
208
  */
207
209
  var FirebaseAuthProvider = /** @class */ (function () {
208
- function FirebaseAuthProvider(appName, options, authProvider_) {
210
+ function FirebaseAuthProvider(_appName, _options, _authProvider) {
209
211
  var _this = this;
210
- this.appName = appName;
211
- this.options = options;
212
- this.authProvider_ = authProvider_;
213
- this.auth_ = authProvider_.getImmediate({ optional: true });
214
- if (!this.auth_) {
215
- authProvider_.onInit(function (auth) { return (_this.auth_ = auth); });
212
+ this._appName = _appName;
213
+ this._options = _options;
214
+ this._authProvider = _authProvider;
215
+ this._auth = _authProvider.getImmediate({ optional: true });
216
+ if (!this._auth) {
217
+ _authProvider.onInit(function (auth) { return (_this._auth = auth); });
216
218
  }
217
219
  }
218
220
  FirebaseAuthProvider.prototype.getToken = function (forceRefresh) {
219
221
  var _this = this;
220
- if (!this.auth_) {
222
+ if (!this._auth) {
221
223
  return new Promise(function (resolve, reject) {
222
224
  setTimeout(function () {
223
- if (_this.auth_) {
225
+ if (_this._auth) {
224
226
  _this.getToken(forceRefresh).then(resolve, reject);
225
227
  }
226
228
  else {
@@ -229,7 +231,7 @@ var FirebaseAuthProvider = /** @class */ (function () {
229
231
  }, 0);
230
232
  });
231
233
  }
232
- return this.auth_.getToken(forceRefresh).catch(function (error) {
234
+ return this._auth.getToken(forceRefresh).catch(function (error) {
233
235
  if (error && error.code === 'auth/token-not-initialized') {
234
236
  logDebug('Got auth/token-not-initialized error. Treating as null token.');
235
237
  return null;
@@ -243,34 +245,14 @@ var FirebaseAuthProvider = /** @class */ (function () {
243
245
  };
244
246
  FirebaseAuthProvider.prototype.addTokenChangeListener = function (listener) {
245
247
  var _a;
246
- (_a = this.auth_) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
248
+ (_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
247
249
  };
248
250
  FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
249
- this.authProvider_
251
+ this._authProvider
250
252
  .get()
251
253
  .then(function (auth) { return auth.removeAuthTokenListener(listener); });
252
254
  };
253
255
  return FirebaseAuthProvider;
254
- }());
255
- var EmulatorTokenProvider = /** @class */ (function () {
256
- function EmulatorTokenProvider(accessToken) {
257
- this.accessToken = accessToken;
258
- }
259
- EmulatorTokenProvider.prototype.getToken = function (forceRefresh) {
260
- return Promise.resolve({
261
- accessToken: this.accessToken
262
- });
263
- };
264
- EmulatorTokenProvider.prototype.addTokenChangeListener = function (listener) {
265
- // Invoke the listener immediately to match the behavior in Firebase Auth
266
- // (see packages/auth/src/auth.js#L1807)
267
- listener(this.accessToken);
268
- };
269
- EmulatorTokenProvider.prototype.removeTokenChangeListener = function (listener) { };
270
- EmulatorTokenProvider.prototype.notifyForInvalidToken = function () { };
271
- /** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
272
- EmulatorTokenProvider.OWNER = 'owner';
273
- return EmulatorTokenProvider;
274
256
  }());
275
257
 
276
258
  /**
@@ -289,8 +271,8 @@ var EmulatorTokenProvider = /** @class */ (function () {
289
271
  * See the License for the specific language governing permissions and
290
272
  * limitations under the License.
291
273
  */
292
- var QueryStr = 'query';
293
- var MutationStr = 'mutation';
274
+ var QUERY_STR = 'query';
275
+ var MUTATION_STR = 'mutation';
294
276
  var SOURCE_SERVER = 'SERVER';
295
277
  var SOURCE_CACHE = 'CACHE';
296
278
 
@@ -377,7 +359,7 @@ var QueryManager = /** @class */ (function () {
377
359
  var ref = {
378
360
  name: queryName,
379
361
  variables: variables,
380
- refType: QueryStr
362
+ refType: QUERY_STR
381
363
  };
382
364
  var key = encoderImpl(ref);
383
365
  var newTrackedQuery = {
@@ -395,7 +377,7 @@ var QueryManager = /** @class */ (function () {
395
377
  var key = encoderImpl({
396
378
  name: queryRef.name,
397
379
  variables: queryRef.variables,
398
- refType: QueryStr
380
+ refType: QUERY_STR
399
381
  });
400
382
  var trackedQuery = this._queries.get(key);
401
383
  var subscription = {
@@ -444,7 +426,7 @@ var QueryManager = /** @class */ (function () {
444
426
  var key = encoderImpl({
445
427
  name: queryRef.name,
446
428
  variables: queryRef.variables,
447
- refType: QueryStr
429
+ refType: QUERY_STR
448
430
  });
449
431
  var trackedQuery = this._queries.get(key);
450
432
  var result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
@@ -544,24 +526,24 @@ var RESTTransport = /** @class */ (function () {
544
526
  var _a;
545
527
  this.apiKey = apiKey;
546
528
  this.authProvider = authProvider;
547
- this.host = '';
548
- this.location = 'l';
549
- this.connectorName = '';
550
- this.secure = true;
551
- this.project = 'p';
552
- this.accessToken = null;
553
- this.authInitialized_ = false;
529
+ this._host = '';
530
+ this._location = 'l';
531
+ this._connectorName = '';
532
+ this._secure = true;
533
+ this._project = 'p';
534
+ this._accessToken = null;
535
+ this._authInitialized = false;
554
536
  // TODO(mtewani): Update U to include shape of body defined in line 13.
555
537
  this.invokeQuery = function (queryName, body) {
556
538
  var abortController = new AbortController();
557
539
  // TODO(mtewani): Update to proper value
558
540
  var withAuth = _this.getWithAuth().then(function () {
559
541
  return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
560
- name: "projects/".concat(_this.project, "/locations/").concat(_this.location, "/services/").concat(_this.serviceName, "/connectors/").concat(_this.connectorName),
542
+ name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
561
543
  operationName: queryName,
562
544
  variables: body
563
545
  }, // TODO(mtewani): This is a patch, fix this.
564
- abortController, _this.accessToken);
546
+ abortController, _this._accessToken);
565
547
  });
566
548
  return {
567
549
  then: withAuth.then.bind(withAuth)
@@ -571,10 +553,10 @@ var RESTTransport = /** @class */ (function () {
571
553
  var abortController = new AbortController();
572
554
  var taskResult = _this.getWithAuth().then(function () {
573
555
  return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
574
- name: "projects/".concat(_this.project, "/locations/").concat(_this.location, "/services/").concat(_this.serviceName, "/connectors/").concat(_this.connectorName),
556
+ name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
575
557
  operationName: mutationName,
576
558
  variables: body
577
- }, abortController, _this.accessToken);
559
+ }, abortController, _this._accessToken);
578
560
  });
579
561
  return {
580
562
  then: taskResult.then.bind(taskResult),
@@ -585,60 +567,60 @@ var RESTTransport = /** @class */ (function () {
585
567
  };
586
568
  if (transportOptions) {
587
569
  if (typeof transportOptions.port === 'number') {
588
- this.port = transportOptions.port;
570
+ this._port = transportOptions.port;
589
571
  }
590
572
  if (typeof transportOptions.sslEnabled !== 'undefined') {
591
- this.secure = transportOptions.sslEnabled;
573
+ this._secure = transportOptions.sslEnabled;
592
574
  }
593
- this.host = transportOptions.host;
575
+ this._host = transportOptions.host;
594
576
  }
595
577
  var location = options.location, project = options.projectId, connector = options.connector, service = options.service;
596
578
  if (location) {
597
- this.location = location;
579
+ this._location = location;
598
580
  }
599
581
  if (project) {
600
- this.project = project;
582
+ this._project = project;
601
583
  }
602
- this.serviceName = service;
584
+ this._serviceName = service;
603
585
  if (!connector) {
604
586
  throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
605
587
  }
606
- this.connectorName = connector;
588
+ this._connectorName = connector;
607
589
  (_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(function (token) {
608
590
  logDebug("New Token Available: ".concat(token));
609
- _this.accessToken = token;
591
+ _this._accessToken = token;
610
592
  });
611
593
  }
612
594
  Object.defineProperty(RESTTransport.prototype, "endpointUrl", {
613
595
  get: function () {
614
596
  return urlBuilder({
615
- connector: this.connectorName,
616
- location: this.location,
617
- projectId: this.project,
618
- service: this.serviceName
619
- }, { host: this.host, sslEnabled: this.secure, port: this.port });
597
+ connector: this._connectorName,
598
+ location: this._location,
599
+ projectId: this._project,
600
+ service: this._serviceName
601
+ }, { host: this._host, sslEnabled: this._secure, port: this._port });
620
602
  },
621
603
  enumerable: false,
622
604
  configurable: true
623
605
  });
624
606
  RESTTransport.prototype.useEmulator = function (host, port, isSecure) {
625
- this.host = host;
607
+ this._host = host;
626
608
  if (typeof port === 'number') {
627
- this.port = port;
609
+ this._port = port;
628
610
  }
629
611
  if (typeof isSecure !== 'undefined') {
630
- this.secure = isSecure;
612
+ this._secure = isSecure;
631
613
  }
632
614
  };
633
615
  RESTTransport.prototype.onTokenChanged = function (newToken) {
634
- this.accessToken = newToken;
616
+ this._accessToken = newToken;
635
617
  };
636
618
  RESTTransport.prototype.getWithAuth = function () {
637
619
  var _this = this;
638
620
  var starterPromise = new Promise(function (resolve) {
639
- return resolve(_this.accessToken);
621
+ return resolve(_this._accessToken);
640
622
  });
641
- if (!this.authInitialized_) {
623
+ if (!this._authInitialized) {
642
624
  if (this.authProvider) {
643
625
  starterPromise = this.authProvider
644
626
  .getToken(/*forceToken=*/ false)
@@ -646,8 +628,8 @@ var RESTTransport = /** @class */ (function () {
646
628
  if (!data) {
647
629
  return null;
648
630
  }
649
- _this.accessToken = data.accessToken;
650
- return _this.accessToken;
631
+ _this._accessToken = data.accessToken;
632
+ return _this._accessToken;
651
633
  });
652
634
  }
653
635
  else {
@@ -680,19 +662,19 @@ function mutationRef(dcInstance, queryName, variables) {
680
662
  var ref = {
681
663
  dataConnect: dcInstance,
682
664
  name: queryName,
683
- refType: MutationStr,
665
+ refType: MUTATION_STR,
684
666
  variables: variables
685
667
  };
686
668
  return ref;
687
669
  }
688
670
  var MutationManager = /** @class */ (function () {
689
- function MutationManager(transport) {
690
- this.transport = transport;
671
+ function MutationManager(_transport) {
672
+ this._transport = _transport;
691
673
  this._inflight = [];
692
674
  }
693
675
  MutationManager.prototype.executeMutation = function (mutationRef) {
694
676
  var _this = this;
695
- var result = this.transport.invokeMutation(mutationRef.name, mutationRef.variables);
677
+ var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
696
678
  var withRefPromise = result.then(function (res) {
697
679
  var obj = tslib.__assign(tslib.__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
698
680
  return obj;
@@ -741,10 +723,12 @@ function parseOptions(fullHost) {
741
723
  return { host: host, port: port, sslEnabled: isSecure };
742
724
  }
743
725
  var DataConnect = /** @class */ (function () {
744
- function DataConnect(app, dataConnectOptions, authProvider) {
726
+ function DataConnect(app,
727
+ // TODO(mtewani): Replace with _dataConnectOptions in the future
728
+ dataConnectOptions, _authProvider) {
745
729
  this.app = app;
746
730
  this.dataConnectOptions = dataConnectOptions;
747
- this.authProvider = authProvider;
731
+ this._authProvider = _authProvider;
748
732
  this.isEmulator = false;
749
733
  this.initialized = false;
750
734
  if (typeof process !== 'undefined' && process.env) {
@@ -752,7 +736,7 @@ var DataConnect = /** @class */ (function () {
752
736
  if (host) {
753
737
  logDebug('Found custom host. Using emulator');
754
738
  this.isEmulator = true;
755
- this.transportOptions = parseOptions(host);
739
+ this._transportOptions = parseOptions(host);
756
740
  }
757
741
  }
758
742
  }
@@ -769,29 +753,27 @@ var DataConnect = /** @class */ (function () {
769
753
  if (this.initialized) {
770
754
  return;
771
755
  }
772
- if (this.transportClass === undefined) {
756
+ if (this._transportClass === undefined) {
773
757
  logDebug('transportClass not provided. Defaulting to RESTTransport.');
774
- this.transportClass = RESTTransport;
758
+ this._transportClass = RESTTransport;
775
759
  }
776
- if (this.authProvider) {
777
- this.authTokenProvider = this.isEmulator
778
- ? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
779
- : new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
760
+ if (this._authProvider) {
761
+ this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
780
762
  }
781
763
  this.initialized = true;
782
- this._transport = new this.transportClass(this.dataConnectOptions, this.app.options.apiKey, this.authTokenProvider);
783
- if (this.transportOptions) {
784
- this._transport.useEmulator(this.transportOptions.host, this.transportOptions.port, this.transportOptions.sslEnabled);
764
+ this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
765
+ if (this._transportOptions) {
766
+ this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
785
767
  }
786
768
  this._queryManager = new QueryManager(this._transport);
787
769
  this._mutationManager = new MutationManager(this._transport);
788
770
  };
789
771
  DataConnect.prototype.enableEmulator = function (transportOptions) {
790
772
  if (this.initialized) {
791
- logError('enableEmulator called without initializing');
773
+ logError('enableEmulator called after initialization');
792
774
  throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
793
775
  }
794
- this.transportOptions = transportOptions;
776
+ this._transportOptions = transportOptions;
795
777
  this.isEmulator = true;
796
778
  };
797
779
  return DataConnect;
@@ -836,7 +818,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
836
818
  });
837
819
  }
838
820
  function terminate(dataConnect) {
839
- dataConnect._delete();
821
+ return dataConnect._delete();
840
822
  // TODO(mtewani): Stop pending tasks
841
823
  }
842
824
 
@@ -881,7 +863,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
881
863
  dcInstance._queryManager.track(queryName, variables, initialCache);
882
864
  return {
883
865
  dataConnect: dcInstance,
884
- refType: QueryStr,
866
+ refType: QUERY_STR,
885
867
  name: queryName,
886
868
  variables: variables
887
869
  };
@@ -958,12 +940,11 @@ initializeFetch(fetch);
958
940
  registerDataConnect('node');
959
941
 
960
942
  exports.DataConnect = DataConnect;
961
- exports.EmulatorTokenProvider = EmulatorTokenProvider;
962
943
  exports.FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR;
963
944
  exports.FirebaseAuthProvider = FirebaseAuthProvider;
945
+ exports.MUTATION_STR = MUTATION_STR;
964
946
  exports.MutationManager = MutationManager;
965
- exports.MutationStr = MutationStr;
966
- exports.QueryStr = QueryStr;
947
+ exports.QUERY_STR = QUERY_STR;
967
948
  exports.SOURCE_CACHE = SOURCE_CACHE;
968
949
  exports.SOURCE_SERVER = SOURCE_SERVER;
969
950
  exports.connectDataConnectEmulator = connectDataConnectEmulator;