@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.
- package/dist/index.cjs.js +124 -162
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +123 -160
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +125 -163
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +74 -93
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/internal.d.ts +30 -48
- package/dist/node-esm/index.node.esm.js +75 -92
- package/dist/node-esm/index.node.esm.js.map +1 -1
- package/dist/node-esm/src/api/DataConnect.d.ts +6 -12
- package/dist/node-esm/src/api/Mutation.d.ts +8 -8
- package/dist/node-esm/src/api/Reference.d.ts +3 -3
- package/dist/node-esm/src/api/query.d.ts +2 -2
- package/dist/node-esm/src/core/FirebaseAuthProvider.d.ts +5 -15
- package/dist/node-esm/src/core/QueryManager.d.ts +7 -7
- package/dist/node-esm/src/network/transport/rest.d.ts +13 -25
- package/dist/node-esm/src/util/url.d.ts +2 -2
- package/dist/private.d.ts +30 -48
- package/dist/public.d.ts +13 -38
- package/dist/src/api/DataConnect.d.ts +6 -12
- package/dist/src/api/Mutation.d.ts +8 -8
- package/dist/src/api/Reference.d.ts +3 -3
- package/dist/src/api/query.d.ts +2 -2
- package/dist/src/core/FirebaseAuthProvider.d.ts +5 -15
- package/dist/src/core/QueryManager.d.ts +7 -7
- package/dist/src/network/transport/rest.d.ts +13 -25
- package/dist/src/util/url.d.ts +2 -2
- package/package.json +7 -7
- package/dist/node-esm/test/emulatorSeeder.d.ts +0 -22
- package/dist/node-esm/test/queries.test.d.ts +0 -17
- package/dist/node-esm/test/util.d.ts +0 -26
- package/dist/test/emulatorSeeder.d.ts +0 -22
- package/dist/test/queries.test.d.ts +0 -17
- package/dist/test/util.d.ts +0 -26
package/dist/index.node.cjs.js
CHANGED
|
@@ -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.
|
|
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(
|
|
210
|
+
function FirebaseAuthProvider(_appName, _options, _authProvider) {
|
|
209
211
|
var _this = this;
|
|
210
|
-
this.
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
if (!this.
|
|
215
|
-
|
|
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.
|
|
222
|
+
if (!this._auth) {
|
|
221
223
|
return new Promise(function (resolve, reject) {
|
|
222
224
|
setTimeout(function () {
|
|
223
|
-
if (_this.
|
|
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.
|
|
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.
|
|
248
|
+
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
|
|
247
249
|
};
|
|
248
250
|
FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
|
|
249
|
-
this.
|
|
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
|
|
293
|
-
var
|
|
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:
|
|
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:
|
|
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:
|
|
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.
|
|
548
|
-
this.
|
|
549
|
-
this.
|
|
550
|
-
this.
|
|
551
|
-
this.
|
|
552
|
-
this.
|
|
553
|
-
this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
570
|
+
this._port = transportOptions.port;
|
|
589
571
|
}
|
|
590
572
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
591
|
-
this.
|
|
573
|
+
this._secure = transportOptions.sslEnabled;
|
|
592
574
|
}
|
|
593
|
-
this.
|
|
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.
|
|
579
|
+
this._location = location;
|
|
598
580
|
}
|
|
599
581
|
if (project) {
|
|
600
|
-
this.
|
|
582
|
+
this._project = project;
|
|
601
583
|
}
|
|
602
|
-
this.
|
|
584
|
+
this._serviceName = service;
|
|
603
585
|
if (!connector) {
|
|
604
586
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
605
587
|
}
|
|
606
|
-
this.
|
|
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.
|
|
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.
|
|
616
|
-
location: this.
|
|
617
|
-
projectId: this.
|
|
618
|
-
service: this.
|
|
619
|
-
}, { host: this.
|
|
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.
|
|
607
|
+
this._host = host;
|
|
626
608
|
if (typeof port === 'number') {
|
|
627
|
-
this.
|
|
609
|
+
this._port = port;
|
|
628
610
|
}
|
|
629
611
|
if (typeof isSecure !== 'undefined') {
|
|
630
|
-
this.
|
|
612
|
+
this._secure = isSecure;
|
|
631
613
|
}
|
|
632
614
|
};
|
|
633
615
|
RESTTransport.prototype.onTokenChanged = function (newToken) {
|
|
634
|
-
this.
|
|
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.
|
|
621
|
+
return resolve(_this._accessToken);
|
|
640
622
|
});
|
|
641
|
-
if (!this.
|
|
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.
|
|
650
|
-
return _this.
|
|
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:
|
|
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(
|
|
690
|
-
this.
|
|
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.
|
|
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,
|
|
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.
|
|
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.
|
|
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.
|
|
756
|
+
if (this._transportClass === undefined) {
|
|
773
757
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
774
|
-
this.
|
|
758
|
+
this._transportClass = RESTTransport;
|
|
775
759
|
}
|
|
776
|
-
if (this.
|
|
777
|
-
this.
|
|
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.
|
|
783
|
-
if (this.
|
|
784
|
-
this._transport.useEmulator(this.
|
|
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
|
|
773
|
+
logError('enableEmulator called after initialization');
|
|
792
774
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
793
775
|
}
|
|
794
|
-
this.
|
|
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:
|
|
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.
|
|
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;
|