@firebase/data-connect 0.0.1-dataconnect-preview.81ee5169c → 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 +123 -139
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +122 -138
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +125 -141
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +74 -70
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/internal.d.ts +30 -37
- package/dist/node-esm/index.node.esm.js +74 -70
- 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 -5
- 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 -37
- package/dist/public.d.ts +13 -28
- 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 -5
- 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.81ee5169c";
|
|
|
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,10 +245,10 @@ 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
|
};
|
|
@@ -269,8 +271,8 @@ var FirebaseAuthProvider = /** @class */ (function () {
|
|
|
269
271
|
* See the License for the specific language governing permissions and
|
|
270
272
|
* limitations under the License.
|
|
271
273
|
*/
|
|
272
|
-
var
|
|
273
|
-
var
|
|
274
|
+
var QUERY_STR = 'query';
|
|
275
|
+
var MUTATION_STR = 'mutation';
|
|
274
276
|
var SOURCE_SERVER = 'SERVER';
|
|
275
277
|
var SOURCE_CACHE = 'CACHE';
|
|
276
278
|
|
|
@@ -357,7 +359,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
357
359
|
var ref = {
|
|
358
360
|
name: queryName,
|
|
359
361
|
variables: variables,
|
|
360
|
-
refType:
|
|
362
|
+
refType: QUERY_STR
|
|
361
363
|
};
|
|
362
364
|
var key = encoderImpl(ref);
|
|
363
365
|
var newTrackedQuery = {
|
|
@@ -375,7 +377,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
375
377
|
var key = encoderImpl({
|
|
376
378
|
name: queryRef.name,
|
|
377
379
|
variables: queryRef.variables,
|
|
378
|
-
refType:
|
|
380
|
+
refType: QUERY_STR
|
|
379
381
|
});
|
|
380
382
|
var trackedQuery = this._queries.get(key);
|
|
381
383
|
var subscription = {
|
|
@@ -424,7 +426,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
424
426
|
var key = encoderImpl({
|
|
425
427
|
name: queryRef.name,
|
|
426
428
|
variables: queryRef.variables,
|
|
427
|
-
refType:
|
|
429
|
+
refType: QUERY_STR
|
|
428
430
|
});
|
|
429
431
|
var trackedQuery = this._queries.get(key);
|
|
430
432
|
var result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
|
|
@@ -524,24 +526,24 @@ var RESTTransport = /** @class */ (function () {
|
|
|
524
526
|
var _a;
|
|
525
527
|
this.apiKey = apiKey;
|
|
526
528
|
this.authProvider = authProvider;
|
|
527
|
-
this.
|
|
528
|
-
this.
|
|
529
|
-
this.
|
|
530
|
-
this.
|
|
531
|
-
this.
|
|
532
|
-
this.
|
|
533
|
-
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;
|
|
534
536
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
535
537
|
this.invokeQuery = function (queryName, body) {
|
|
536
538
|
var abortController = new AbortController();
|
|
537
539
|
// TODO(mtewani): Update to proper value
|
|
538
540
|
var withAuth = _this.getWithAuth().then(function () {
|
|
539
541
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
|
|
540
|
-
name: "projects/".concat(_this.
|
|
542
|
+
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
541
543
|
operationName: queryName,
|
|
542
544
|
variables: body
|
|
543
545
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
544
|
-
abortController, _this.
|
|
546
|
+
abortController, _this._accessToken);
|
|
545
547
|
});
|
|
546
548
|
return {
|
|
547
549
|
then: withAuth.then.bind(withAuth)
|
|
@@ -551,10 +553,10 @@ var RESTTransport = /** @class */ (function () {
|
|
|
551
553
|
var abortController = new AbortController();
|
|
552
554
|
var taskResult = _this.getWithAuth().then(function () {
|
|
553
555
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
|
|
554
|
-
name: "projects/".concat(_this.
|
|
556
|
+
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
555
557
|
operationName: mutationName,
|
|
556
558
|
variables: body
|
|
557
|
-
}, abortController, _this.
|
|
559
|
+
}, abortController, _this._accessToken);
|
|
558
560
|
});
|
|
559
561
|
return {
|
|
560
562
|
then: taskResult.then.bind(taskResult),
|
|
@@ -565,60 +567,60 @@ var RESTTransport = /** @class */ (function () {
|
|
|
565
567
|
};
|
|
566
568
|
if (transportOptions) {
|
|
567
569
|
if (typeof transportOptions.port === 'number') {
|
|
568
|
-
this.
|
|
570
|
+
this._port = transportOptions.port;
|
|
569
571
|
}
|
|
570
572
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
571
|
-
this.
|
|
573
|
+
this._secure = transportOptions.sslEnabled;
|
|
572
574
|
}
|
|
573
|
-
this.
|
|
575
|
+
this._host = transportOptions.host;
|
|
574
576
|
}
|
|
575
577
|
var location = options.location, project = options.projectId, connector = options.connector, service = options.service;
|
|
576
578
|
if (location) {
|
|
577
|
-
this.
|
|
579
|
+
this._location = location;
|
|
578
580
|
}
|
|
579
581
|
if (project) {
|
|
580
|
-
this.
|
|
582
|
+
this._project = project;
|
|
581
583
|
}
|
|
582
|
-
this.
|
|
584
|
+
this._serviceName = service;
|
|
583
585
|
if (!connector) {
|
|
584
586
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
585
587
|
}
|
|
586
|
-
this.
|
|
588
|
+
this._connectorName = connector;
|
|
587
589
|
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(function (token) {
|
|
588
590
|
logDebug("New Token Available: ".concat(token));
|
|
589
|
-
_this.
|
|
591
|
+
_this._accessToken = token;
|
|
590
592
|
});
|
|
591
593
|
}
|
|
592
594
|
Object.defineProperty(RESTTransport.prototype, "endpointUrl", {
|
|
593
595
|
get: function () {
|
|
594
596
|
return urlBuilder({
|
|
595
|
-
connector: this.
|
|
596
|
-
location: this.
|
|
597
|
-
projectId: this.
|
|
598
|
-
service: this.
|
|
599
|
-
}, { 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 });
|
|
600
602
|
},
|
|
601
603
|
enumerable: false,
|
|
602
604
|
configurable: true
|
|
603
605
|
});
|
|
604
606
|
RESTTransport.prototype.useEmulator = function (host, port, isSecure) {
|
|
605
|
-
this.
|
|
607
|
+
this._host = host;
|
|
606
608
|
if (typeof port === 'number') {
|
|
607
|
-
this.
|
|
609
|
+
this._port = port;
|
|
608
610
|
}
|
|
609
611
|
if (typeof isSecure !== 'undefined') {
|
|
610
|
-
this.
|
|
612
|
+
this._secure = isSecure;
|
|
611
613
|
}
|
|
612
614
|
};
|
|
613
615
|
RESTTransport.prototype.onTokenChanged = function (newToken) {
|
|
614
|
-
this.
|
|
616
|
+
this._accessToken = newToken;
|
|
615
617
|
};
|
|
616
618
|
RESTTransport.prototype.getWithAuth = function () {
|
|
617
619
|
var _this = this;
|
|
618
620
|
var starterPromise = new Promise(function (resolve) {
|
|
619
|
-
return resolve(_this.
|
|
621
|
+
return resolve(_this._accessToken);
|
|
620
622
|
});
|
|
621
|
-
if (!this.
|
|
623
|
+
if (!this._authInitialized) {
|
|
622
624
|
if (this.authProvider) {
|
|
623
625
|
starterPromise = this.authProvider
|
|
624
626
|
.getToken(/*forceToken=*/ false)
|
|
@@ -626,8 +628,8 @@ var RESTTransport = /** @class */ (function () {
|
|
|
626
628
|
if (!data) {
|
|
627
629
|
return null;
|
|
628
630
|
}
|
|
629
|
-
_this.
|
|
630
|
-
return _this.
|
|
631
|
+
_this._accessToken = data.accessToken;
|
|
632
|
+
return _this._accessToken;
|
|
631
633
|
});
|
|
632
634
|
}
|
|
633
635
|
else {
|
|
@@ -660,19 +662,19 @@ function mutationRef(dcInstance, queryName, variables) {
|
|
|
660
662
|
var ref = {
|
|
661
663
|
dataConnect: dcInstance,
|
|
662
664
|
name: queryName,
|
|
663
|
-
refType:
|
|
665
|
+
refType: MUTATION_STR,
|
|
664
666
|
variables: variables
|
|
665
667
|
};
|
|
666
668
|
return ref;
|
|
667
669
|
}
|
|
668
670
|
var MutationManager = /** @class */ (function () {
|
|
669
|
-
function MutationManager(
|
|
670
|
-
this.
|
|
671
|
+
function MutationManager(_transport) {
|
|
672
|
+
this._transport = _transport;
|
|
671
673
|
this._inflight = [];
|
|
672
674
|
}
|
|
673
675
|
MutationManager.prototype.executeMutation = function (mutationRef) {
|
|
674
676
|
var _this = this;
|
|
675
|
-
var result = this.
|
|
677
|
+
var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
676
678
|
var withRefPromise = result.then(function (res) {
|
|
677
679
|
var obj = tslib.__assign(tslib.__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
678
680
|
return obj;
|
|
@@ -721,10 +723,12 @@ function parseOptions(fullHost) {
|
|
|
721
723
|
return { host: host, port: port, sslEnabled: isSecure };
|
|
722
724
|
}
|
|
723
725
|
var DataConnect = /** @class */ (function () {
|
|
724
|
-
function DataConnect(app,
|
|
726
|
+
function DataConnect(app,
|
|
727
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
728
|
+
dataConnectOptions, _authProvider) {
|
|
725
729
|
this.app = app;
|
|
726
730
|
this.dataConnectOptions = dataConnectOptions;
|
|
727
|
-
this.
|
|
731
|
+
this._authProvider = _authProvider;
|
|
728
732
|
this.isEmulator = false;
|
|
729
733
|
this.initialized = false;
|
|
730
734
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -732,7 +736,7 @@ var DataConnect = /** @class */ (function () {
|
|
|
732
736
|
if (host) {
|
|
733
737
|
logDebug('Found custom host. Using emulator');
|
|
734
738
|
this.isEmulator = true;
|
|
735
|
-
this.
|
|
739
|
+
this._transportOptions = parseOptions(host);
|
|
736
740
|
}
|
|
737
741
|
}
|
|
738
742
|
}
|
|
@@ -749,27 +753,27 @@ var DataConnect = /** @class */ (function () {
|
|
|
749
753
|
if (this.initialized) {
|
|
750
754
|
return;
|
|
751
755
|
}
|
|
752
|
-
if (this.
|
|
756
|
+
if (this._transportClass === undefined) {
|
|
753
757
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
754
|
-
this.
|
|
758
|
+
this._transportClass = RESTTransport;
|
|
755
759
|
}
|
|
756
|
-
if (this.
|
|
757
|
-
this.
|
|
760
|
+
if (this._authProvider) {
|
|
761
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
758
762
|
}
|
|
759
763
|
this.initialized = true;
|
|
760
|
-
this._transport = new this.
|
|
761
|
-
if (this.
|
|
762
|
-
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);
|
|
763
767
|
}
|
|
764
768
|
this._queryManager = new QueryManager(this._transport);
|
|
765
769
|
this._mutationManager = new MutationManager(this._transport);
|
|
766
770
|
};
|
|
767
771
|
DataConnect.prototype.enableEmulator = function (transportOptions) {
|
|
768
772
|
if (this.initialized) {
|
|
769
|
-
logError('enableEmulator called
|
|
773
|
+
logError('enableEmulator called after initialization');
|
|
770
774
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
771
775
|
}
|
|
772
|
-
this.
|
|
776
|
+
this._transportOptions = transportOptions;
|
|
773
777
|
this.isEmulator = true;
|
|
774
778
|
};
|
|
775
779
|
return DataConnect;
|
|
@@ -814,7 +818,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
814
818
|
});
|
|
815
819
|
}
|
|
816
820
|
function terminate(dataConnect) {
|
|
817
|
-
dataConnect._delete();
|
|
821
|
+
return dataConnect._delete();
|
|
818
822
|
// TODO(mtewani): Stop pending tasks
|
|
819
823
|
}
|
|
820
824
|
|
|
@@ -859,7 +863,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
859
863
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
860
864
|
return {
|
|
861
865
|
dataConnect: dcInstance,
|
|
862
|
-
refType:
|
|
866
|
+
refType: QUERY_STR,
|
|
863
867
|
name: queryName,
|
|
864
868
|
variables: variables
|
|
865
869
|
};
|
|
@@ -938,9 +942,9 @@ registerDataConnect('node');
|
|
|
938
942
|
exports.DataConnect = DataConnect;
|
|
939
943
|
exports.FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR;
|
|
940
944
|
exports.FirebaseAuthProvider = FirebaseAuthProvider;
|
|
945
|
+
exports.MUTATION_STR = MUTATION_STR;
|
|
941
946
|
exports.MutationManager = MutationManager;
|
|
942
|
-
exports.
|
|
943
|
-
exports.QueryStr = QueryStr;
|
|
947
|
+
exports.QUERY_STR = QUERY_STR;
|
|
944
948
|
exports.SOURCE_CACHE = SOURCE_CACHE;
|
|
945
949
|
exports.SOURCE_SERVER = SOURCE_SERVER;
|
|
946
950
|
exports.connectDataConnectEmulator = connectDataConnectEmulator;
|