@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.esm5.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __extends, __assign, __awaiter, __generator } from 'tslib';
|
|
2
2
|
import { _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
|
|
3
3
|
import { Component } from '@firebase/component';
|
|
4
|
-
import { Logger } from '@firebase/logger';
|
|
5
4
|
import { FirebaseError } from '@firebase/util';
|
|
5
|
+
import { Logger } from '@firebase/logger';
|
|
6
6
|
|
|
7
7
|
var name = "@firebase/data-connect";
|
|
8
|
-
var version = "0.0.
|
|
8
|
+
var version = "0.0.2-dataconnect-preview.877f8b7d0";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @license
|
|
@@ -33,6 +33,55 @@ function setSDKVersion(version) {
|
|
|
33
33
|
SDK_VERSION = version;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @license
|
|
38
|
+
* Copyright 2024 Google LLC
|
|
39
|
+
*
|
|
40
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
41
|
+
* you may not use this file except in compliance with the License.
|
|
42
|
+
* You may obtain a copy of the License at
|
|
43
|
+
*
|
|
44
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
45
|
+
*
|
|
46
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
47
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
48
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
49
|
+
* See the License for the specific language governing permissions and
|
|
50
|
+
* limitations under the License.
|
|
51
|
+
*/
|
|
52
|
+
var Code = {
|
|
53
|
+
OTHER: 'other',
|
|
54
|
+
ALREADY_INITIALIZED: 'already-initialized',
|
|
55
|
+
NOT_INITIALIZED: 'not-initialized',
|
|
56
|
+
NOT_SUPPORTED: 'not-supported',
|
|
57
|
+
INVALID_ARGUMENT: 'invalid-argument',
|
|
58
|
+
PARTIAL_ERROR: 'partial-error'
|
|
59
|
+
};
|
|
60
|
+
/** An error returned by a DataConnect operation. */
|
|
61
|
+
var DataConnectError = /** @class */ (function (_super) {
|
|
62
|
+
__extends(DataConnectError, _super);
|
|
63
|
+
/** @hideconstructor */
|
|
64
|
+
function DataConnectError(
|
|
65
|
+
/**
|
|
66
|
+
* The backend error code associated with this error.
|
|
67
|
+
*/
|
|
68
|
+
code,
|
|
69
|
+
/**
|
|
70
|
+
* A custom error description.
|
|
71
|
+
*/
|
|
72
|
+
message) {
|
|
73
|
+
var _this = _super.call(this, code, message) || this;
|
|
74
|
+
_this.code = code;
|
|
75
|
+
_this.message = message;
|
|
76
|
+
// HACK: We write a toString property directly because Error is not a real
|
|
77
|
+
// class and so inheritance does not work correctly. We could alternatively
|
|
78
|
+
// do the same "back-door inheritance" trick that FirebaseError does.
|
|
79
|
+
_this.toString = function () { return "".concat(_this.name, ": [code=").concat(_this.code, "]: ").concat(_this.message); };
|
|
80
|
+
return _this;
|
|
81
|
+
}
|
|
82
|
+
return DataConnectError;
|
|
83
|
+
}(FirebaseError));
|
|
84
|
+
|
|
36
85
|
/**
|
|
37
86
|
* @license
|
|
38
87
|
* Copyright 2024 Google LLC
|
|
@@ -77,22 +126,22 @@ function logError(msg) {
|
|
|
77
126
|
* limitations under the License.
|
|
78
127
|
*/
|
|
79
128
|
var FirebaseAuthProvider = /** @class */ (function () {
|
|
80
|
-
function FirebaseAuthProvider(
|
|
129
|
+
function FirebaseAuthProvider(_appName, _options, _authProvider) {
|
|
81
130
|
var _this = this;
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
if (!this.
|
|
87
|
-
|
|
131
|
+
this._appName = _appName;
|
|
132
|
+
this._options = _options;
|
|
133
|
+
this._authProvider = _authProvider;
|
|
134
|
+
this._auth = _authProvider.getImmediate({ optional: true });
|
|
135
|
+
if (!this._auth) {
|
|
136
|
+
_authProvider.onInit(function (auth) { return (_this._auth = auth); });
|
|
88
137
|
}
|
|
89
138
|
}
|
|
90
139
|
FirebaseAuthProvider.prototype.getToken = function (forceRefresh) {
|
|
91
140
|
var _this = this;
|
|
92
|
-
if (!this.
|
|
141
|
+
if (!this._auth) {
|
|
93
142
|
return new Promise(function (resolve, reject) {
|
|
94
143
|
setTimeout(function () {
|
|
95
|
-
if (_this.
|
|
144
|
+
if (_this._auth) {
|
|
96
145
|
_this.getToken(forceRefresh).then(resolve, reject);
|
|
97
146
|
}
|
|
98
147
|
else {
|
|
@@ -101,7 +150,7 @@ var FirebaseAuthProvider = /** @class */ (function () {
|
|
|
101
150
|
}, 0);
|
|
102
151
|
});
|
|
103
152
|
}
|
|
104
|
-
return this.
|
|
153
|
+
return this._auth.getToken(forceRefresh).catch(function (error) {
|
|
105
154
|
if (error && error.code === 'auth/token-not-initialized') {
|
|
106
155
|
logDebug('Got auth/token-not-initialized error. Treating as null token.');
|
|
107
156
|
return null;
|
|
@@ -115,10 +164,10 @@ var FirebaseAuthProvider = /** @class */ (function () {
|
|
|
115
164
|
};
|
|
116
165
|
FirebaseAuthProvider.prototype.addTokenChangeListener = function (listener) {
|
|
117
166
|
var _a;
|
|
118
|
-
(_a = this.
|
|
167
|
+
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
|
|
119
168
|
};
|
|
120
169
|
FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
|
|
121
|
-
this.
|
|
170
|
+
this._authProvider
|
|
122
171
|
.get()
|
|
123
172
|
.then(function (auth) { return auth.removeAuthTokenListener(listener); });
|
|
124
173
|
};
|
|
@@ -141,8 +190,8 @@ var FirebaseAuthProvider = /** @class */ (function () {
|
|
|
141
190
|
* See the License for the specific language governing permissions and
|
|
142
191
|
* limitations under the License.
|
|
143
192
|
*/
|
|
144
|
-
var
|
|
145
|
-
var
|
|
193
|
+
var QUERY_STR = 'query';
|
|
194
|
+
var MUTATION_STR = 'mutation';
|
|
146
195
|
var SOURCE_SERVER = 'SERVER';
|
|
147
196
|
var SOURCE_CACHE = 'CACHE';
|
|
148
197
|
|
|
@@ -229,7 +278,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
229
278
|
var ref = {
|
|
230
279
|
name: queryName,
|
|
231
280
|
variables: variables,
|
|
232
|
-
refType:
|
|
281
|
+
refType: QUERY_STR
|
|
233
282
|
};
|
|
234
283
|
var key = encoderImpl(ref);
|
|
235
284
|
var newTrackedQuery = {
|
|
@@ -247,7 +296,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
247
296
|
var key = encoderImpl({
|
|
248
297
|
name: queryRef.name,
|
|
249
298
|
variables: queryRef.variables,
|
|
250
|
-
refType:
|
|
299
|
+
refType: QUERY_STR
|
|
251
300
|
});
|
|
252
301
|
var trackedQuery = this._queries.get(key);
|
|
253
302
|
var subscription = {
|
|
@@ -296,7 +345,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
296
345
|
var key = encoderImpl({
|
|
297
346
|
name: queryRef.name,
|
|
298
347
|
variables: queryRef.variables,
|
|
299
|
-
refType:
|
|
348
|
+
refType: QUERY_STR
|
|
300
349
|
});
|
|
301
350
|
var trackedQuery = this._queries.get(key);
|
|
302
351
|
var result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
|
|
@@ -334,55 +383,6 @@ function compareDates(str1, str2) {
|
|
|
334
383
|
return date1.getTime() < date2.getTime();
|
|
335
384
|
}
|
|
336
385
|
|
|
337
|
-
/**
|
|
338
|
-
* @license
|
|
339
|
-
* Copyright 2024 Google LLC
|
|
340
|
-
*
|
|
341
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
342
|
-
* you may not use this file except in compliance with the License.
|
|
343
|
-
* You may obtain a copy of the License at
|
|
344
|
-
*
|
|
345
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
346
|
-
*
|
|
347
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
348
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
349
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
350
|
-
* See the License for the specific language governing permissions and
|
|
351
|
-
* limitations under the License.
|
|
352
|
-
*/
|
|
353
|
-
var Code = {
|
|
354
|
-
OTHER: 'other',
|
|
355
|
-
ALREADY_INITIALIZED: 'already-initialized',
|
|
356
|
-
NOT_INITIALIZED: 'not-initialized',
|
|
357
|
-
NOT_SUPPORTED: 'not-supported',
|
|
358
|
-
INVALID_ARGUMENT: 'invalid-argument',
|
|
359
|
-
PARTIAL_ERROR: 'partial-error'
|
|
360
|
-
};
|
|
361
|
-
/** An error returned by a DataConnect operation. */
|
|
362
|
-
var DataConnectError = /** @class */ (function (_super) {
|
|
363
|
-
__extends(DataConnectError, _super);
|
|
364
|
-
/** @hideconstructor */
|
|
365
|
-
function DataConnectError(
|
|
366
|
-
/**
|
|
367
|
-
* The backend error code associated with this error.
|
|
368
|
-
*/
|
|
369
|
-
code,
|
|
370
|
-
/**
|
|
371
|
-
* A custom error description.
|
|
372
|
-
*/
|
|
373
|
-
message) {
|
|
374
|
-
var _this = _super.call(this, code, message) || this;
|
|
375
|
-
_this.code = code;
|
|
376
|
-
_this.message = message;
|
|
377
|
-
// HACK: We write a toString property directly because Error is not a real
|
|
378
|
-
// class and so inheritance does not work correctly. We could alternatively
|
|
379
|
-
// do the same "back-door inheritance" trick that FirebaseError does.
|
|
380
|
-
_this.toString = function () { return "".concat(_this.name, ": [code=").concat(_this.code, "]: ").concat(_this.message); };
|
|
381
|
-
return _this;
|
|
382
|
-
}
|
|
383
|
-
return DataConnectError;
|
|
384
|
-
}(FirebaseError));
|
|
385
|
-
|
|
386
386
|
/**
|
|
387
387
|
* @license
|
|
388
388
|
* Copyright 2024 Google LLC
|
|
@@ -459,6 +459,8 @@ function dcFetch(url, body, _a, accessToken) {
|
|
|
459
459
|
method: 'POST',
|
|
460
460
|
headers: headers,
|
|
461
461
|
signal: signal
|
|
462
|
+
}).catch(function (err) {
|
|
463
|
+
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
|
|
462
464
|
})
|
|
463
465
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
464
466
|
var jsonResponse, e_1;
|
|
@@ -517,24 +519,24 @@ var RESTTransport = /** @class */ (function () {
|
|
|
517
519
|
var _a;
|
|
518
520
|
this.apiKey = apiKey;
|
|
519
521
|
this.authProvider = authProvider;
|
|
520
|
-
this.
|
|
521
|
-
this.
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
525
|
-
this.
|
|
526
|
-
this.
|
|
522
|
+
this._host = '';
|
|
523
|
+
this._location = 'l';
|
|
524
|
+
this._connectorName = '';
|
|
525
|
+
this._secure = true;
|
|
526
|
+
this._project = 'p';
|
|
527
|
+
this._accessToken = null;
|
|
528
|
+
this._authInitialized = false;
|
|
527
529
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
528
530
|
this.invokeQuery = function (queryName, body) {
|
|
529
531
|
var abortController = new AbortController();
|
|
530
532
|
// TODO(mtewani): Update to proper value
|
|
531
533
|
var withAuth = _this.getWithAuth().then(function () {
|
|
532
534
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
|
|
533
|
-
name: "projects/".concat(_this.
|
|
535
|
+
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
534
536
|
operationName: queryName,
|
|
535
537
|
variables: body
|
|
536
538
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
537
|
-
abortController, _this.
|
|
539
|
+
abortController, _this._accessToken);
|
|
538
540
|
});
|
|
539
541
|
return {
|
|
540
542
|
then: withAuth.then.bind(withAuth)
|
|
@@ -544,10 +546,10 @@ var RESTTransport = /** @class */ (function () {
|
|
|
544
546
|
var abortController = new AbortController();
|
|
545
547
|
var taskResult = _this.getWithAuth().then(function () {
|
|
546
548
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
|
|
547
|
-
name: "projects/".concat(_this.
|
|
549
|
+
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
548
550
|
operationName: mutationName,
|
|
549
551
|
variables: body
|
|
550
|
-
}, abortController, _this.
|
|
552
|
+
}, abortController, _this._accessToken);
|
|
551
553
|
});
|
|
552
554
|
return {
|
|
553
555
|
then: taskResult.then.bind(taskResult),
|
|
@@ -558,60 +560,60 @@ var RESTTransport = /** @class */ (function () {
|
|
|
558
560
|
};
|
|
559
561
|
if (transportOptions) {
|
|
560
562
|
if (typeof transportOptions.port === 'number') {
|
|
561
|
-
this.
|
|
563
|
+
this._port = transportOptions.port;
|
|
562
564
|
}
|
|
563
565
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
564
|
-
this.
|
|
566
|
+
this._secure = transportOptions.sslEnabled;
|
|
565
567
|
}
|
|
566
|
-
this.
|
|
568
|
+
this._host = transportOptions.host;
|
|
567
569
|
}
|
|
568
570
|
var location = options.location, project = options.projectId, connector = options.connector, service = options.service;
|
|
569
571
|
if (location) {
|
|
570
|
-
this.
|
|
572
|
+
this._location = location;
|
|
571
573
|
}
|
|
572
574
|
if (project) {
|
|
573
|
-
this.
|
|
575
|
+
this._project = project;
|
|
574
576
|
}
|
|
575
|
-
this.
|
|
577
|
+
this._serviceName = service;
|
|
576
578
|
if (!connector) {
|
|
577
579
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
578
580
|
}
|
|
579
|
-
this.
|
|
581
|
+
this._connectorName = connector;
|
|
580
582
|
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(function (token) {
|
|
581
583
|
logDebug("New Token Available: ".concat(token));
|
|
582
|
-
_this.
|
|
584
|
+
_this._accessToken = token;
|
|
583
585
|
});
|
|
584
586
|
}
|
|
585
587
|
Object.defineProperty(RESTTransport.prototype, "endpointUrl", {
|
|
586
588
|
get: function () {
|
|
587
589
|
return urlBuilder({
|
|
588
|
-
connector: this.
|
|
589
|
-
location: this.
|
|
590
|
-
projectId: this.
|
|
591
|
-
service: this.
|
|
592
|
-
}, { host: this.
|
|
590
|
+
connector: this._connectorName,
|
|
591
|
+
location: this._location,
|
|
592
|
+
projectId: this._project,
|
|
593
|
+
service: this._serviceName
|
|
594
|
+
}, { host: this._host, sslEnabled: this._secure, port: this._port });
|
|
593
595
|
},
|
|
594
596
|
enumerable: false,
|
|
595
597
|
configurable: true
|
|
596
598
|
});
|
|
597
599
|
RESTTransport.prototype.useEmulator = function (host, port, isSecure) {
|
|
598
|
-
this.
|
|
600
|
+
this._host = host;
|
|
599
601
|
if (typeof port === 'number') {
|
|
600
|
-
this.
|
|
602
|
+
this._port = port;
|
|
601
603
|
}
|
|
602
604
|
if (typeof isSecure !== 'undefined') {
|
|
603
|
-
this.
|
|
605
|
+
this._secure = isSecure;
|
|
604
606
|
}
|
|
605
607
|
};
|
|
606
608
|
RESTTransport.prototype.onTokenChanged = function (newToken) {
|
|
607
|
-
this.
|
|
609
|
+
this._accessToken = newToken;
|
|
608
610
|
};
|
|
609
611
|
RESTTransport.prototype.getWithAuth = function () {
|
|
610
612
|
var _this = this;
|
|
611
613
|
var starterPromise = new Promise(function (resolve) {
|
|
612
|
-
return resolve(_this.
|
|
614
|
+
return resolve(_this._accessToken);
|
|
613
615
|
});
|
|
614
|
-
if (!this.
|
|
616
|
+
if (!this._authInitialized) {
|
|
615
617
|
if (this.authProvider) {
|
|
616
618
|
starterPromise = this.authProvider
|
|
617
619
|
.getToken(/*forceToken=*/ false)
|
|
@@ -619,8 +621,8 @@ var RESTTransport = /** @class */ (function () {
|
|
|
619
621
|
if (!data) {
|
|
620
622
|
return null;
|
|
621
623
|
}
|
|
622
|
-
_this.
|
|
623
|
-
return _this.
|
|
624
|
+
_this._accessToken = data.accessToken;
|
|
625
|
+
return _this._accessToken;
|
|
624
626
|
});
|
|
625
627
|
}
|
|
626
628
|
else {
|
|
@@ -653,19 +655,19 @@ function mutationRef(dcInstance, queryName, variables) {
|
|
|
653
655
|
var ref = {
|
|
654
656
|
dataConnect: dcInstance,
|
|
655
657
|
name: queryName,
|
|
656
|
-
refType:
|
|
658
|
+
refType: MUTATION_STR,
|
|
657
659
|
variables: variables
|
|
658
660
|
};
|
|
659
661
|
return ref;
|
|
660
662
|
}
|
|
661
663
|
var MutationManager = /** @class */ (function () {
|
|
662
|
-
function MutationManager(
|
|
663
|
-
this.
|
|
664
|
+
function MutationManager(_transport) {
|
|
665
|
+
this._transport = _transport;
|
|
664
666
|
this._inflight = [];
|
|
665
667
|
}
|
|
666
668
|
MutationManager.prototype.executeMutation = function (mutationRef) {
|
|
667
669
|
var _this = this;
|
|
668
|
-
var result = this.
|
|
670
|
+
var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
669
671
|
var withRefPromise = result.then(function (res) {
|
|
670
672
|
var obj = __assign(__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
671
673
|
return obj;
|
|
@@ -714,10 +716,12 @@ function parseOptions(fullHost) {
|
|
|
714
716
|
return { host: host, port: port, sslEnabled: isSecure };
|
|
715
717
|
}
|
|
716
718
|
var DataConnect = /** @class */ (function () {
|
|
717
|
-
function DataConnect(app,
|
|
719
|
+
function DataConnect(app,
|
|
720
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
721
|
+
dataConnectOptions, _authProvider) {
|
|
718
722
|
this.app = app;
|
|
719
723
|
this.dataConnectOptions = dataConnectOptions;
|
|
720
|
-
this.
|
|
724
|
+
this._authProvider = _authProvider;
|
|
721
725
|
this.isEmulator = false;
|
|
722
726
|
this.initialized = false;
|
|
723
727
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -725,7 +729,7 @@ var DataConnect = /** @class */ (function () {
|
|
|
725
729
|
if (host) {
|
|
726
730
|
logDebug('Found custom host. Using emulator');
|
|
727
731
|
this.isEmulator = true;
|
|
728
|
-
this.
|
|
732
|
+
this._transportOptions = parseOptions(host);
|
|
729
733
|
}
|
|
730
734
|
}
|
|
731
735
|
}
|
|
@@ -742,27 +746,27 @@ var DataConnect = /** @class */ (function () {
|
|
|
742
746
|
if (this.initialized) {
|
|
743
747
|
return;
|
|
744
748
|
}
|
|
745
|
-
if (this.
|
|
749
|
+
if (this._transportClass === undefined) {
|
|
746
750
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
747
|
-
this.
|
|
751
|
+
this._transportClass = RESTTransport;
|
|
748
752
|
}
|
|
749
|
-
if (this.
|
|
750
|
-
this.
|
|
753
|
+
if (this._authProvider) {
|
|
754
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
751
755
|
}
|
|
752
756
|
this.initialized = true;
|
|
753
|
-
this._transport = new this.
|
|
754
|
-
if (this.
|
|
755
|
-
this._transport.useEmulator(this.
|
|
757
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
|
|
758
|
+
if (this._transportOptions) {
|
|
759
|
+
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
756
760
|
}
|
|
757
761
|
this._queryManager = new QueryManager(this._transport);
|
|
758
762
|
this._mutationManager = new MutationManager(this._transport);
|
|
759
763
|
};
|
|
760
764
|
DataConnect.prototype.enableEmulator = function (transportOptions) {
|
|
761
765
|
if (this.initialized) {
|
|
762
|
-
logError('enableEmulator called
|
|
766
|
+
logError('enableEmulator called after initialization');
|
|
763
767
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
764
768
|
}
|
|
765
|
-
this.
|
|
769
|
+
this._transportOptions = transportOptions;
|
|
766
770
|
this.isEmulator = true;
|
|
767
771
|
};
|
|
768
772
|
return DataConnect;
|
|
@@ -807,7 +811,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
807
811
|
});
|
|
808
812
|
}
|
|
809
813
|
function terminate(dataConnect) {
|
|
810
|
-
dataConnect._delete();
|
|
814
|
+
return dataConnect._delete();
|
|
811
815
|
// TODO(mtewani): Stop pending tasks
|
|
812
816
|
}
|
|
813
817
|
|
|
@@ -852,7 +856,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
852
856
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
853
857
|
return {
|
|
854
858
|
dataConnect: dcInstance,
|
|
855
|
-
refType:
|
|
859
|
+
refType: QUERY_STR,
|
|
856
860
|
name: queryName,
|
|
857
861
|
variables: variables
|
|
858
862
|
};
|
|
@@ -914,27 +918,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
914
918
|
*
|
|
915
919
|
* @packageDocumentation
|
|
916
920
|
*/
|
|
917
|
-
registerDataConnect();
|
|
918
|
-
// import { getDataConnect, queryRef } from './api';
|
|
919
|
-
// import { getApp } from '@firebase/app';
|
|
920
|
-
// const app = getApp();
|
|
921
|
-
// const dc = getDataConnect({ location: '', connector: '', serviceId: '', projectId: '' });
|
|
922
|
-
// interface Response {
|
|
923
|
-
// name: string;
|
|
924
|
-
// }
|
|
925
|
-
// const converter: Converter<Response> = {
|
|
926
|
-
// fromDataConnect(input: string) {
|
|
927
|
-
// return { name: input };
|
|
928
|
-
// },
|
|
929
|
-
// fromType(input) {
|
|
930
|
-
// return input;
|
|
931
|
-
// }
|
|
932
|
-
// };
|
|
933
|
-
// const myRef = queryRef(dc, '', converter);
|
|
934
|
-
// // Ref's shouldn't have access to their own cache, right?
|
|
935
|
-
// const a = execute(myRef);
|
|
936
|
-
// subscribe(myRef, (res) => {
|
|
937
|
-
// })
|
|
921
|
+
registerDataConnect();
|
|
938
922
|
|
|
939
|
-
export { DataConnect, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider,
|
|
923
|
+
export { DataConnect, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider, MUTATION_STR, MutationManager, QUERY_STR, SOURCE_CACHE, SOURCE_SERVER, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef };
|
|
940
924
|
//# sourceMappingURL=index.esm5.js.map
|