@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.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,34 +164,14 @@ 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
|
};
|
|
125
174
|
return FirebaseAuthProvider;
|
|
126
|
-
}());
|
|
127
|
-
var EmulatorTokenProvider = /** @class */ (function () {
|
|
128
|
-
function EmulatorTokenProvider(accessToken) {
|
|
129
|
-
this.accessToken = accessToken;
|
|
130
|
-
}
|
|
131
|
-
EmulatorTokenProvider.prototype.getToken = function (forceRefresh) {
|
|
132
|
-
return Promise.resolve({
|
|
133
|
-
accessToken: this.accessToken
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
EmulatorTokenProvider.prototype.addTokenChangeListener = function (listener) {
|
|
137
|
-
// Invoke the listener immediately to match the behavior in Firebase Auth
|
|
138
|
-
// (see packages/auth/src/auth.js#L1807)
|
|
139
|
-
listener(this.accessToken);
|
|
140
|
-
};
|
|
141
|
-
EmulatorTokenProvider.prototype.removeTokenChangeListener = function (listener) { };
|
|
142
|
-
EmulatorTokenProvider.prototype.notifyForInvalidToken = function () { };
|
|
143
|
-
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
|
|
144
|
-
EmulatorTokenProvider.OWNER = 'owner';
|
|
145
|
-
return EmulatorTokenProvider;
|
|
146
175
|
}());
|
|
147
176
|
|
|
148
177
|
/**
|
|
@@ -161,8 +190,8 @@ var EmulatorTokenProvider = /** @class */ (function () {
|
|
|
161
190
|
* See the License for the specific language governing permissions and
|
|
162
191
|
* limitations under the License.
|
|
163
192
|
*/
|
|
164
|
-
var
|
|
165
|
-
var
|
|
193
|
+
var QUERY_STR = 'query';
|
|
194
|
+
var MUTATION_STR = 'mutation';
|
|
166
195
|
var SOURCE_SERVER = 'SERVER';
|
|
167
196
|
var SOURCE_CACHE = 'CACHE';
|
|
168
197
|
|
|
@@ -249,7 +278,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
249
278
|
var ref = {
|
|
250
279
|
name: queryName,
|
|
251
280
|
variables: variables,
|
|
252
|
-
refType:
|
|
281
|
+
refType: QUERY_STR
|
|
253
282
|
};
|
|
254
283
|
var key = encoderImpl(ref);
|
|
255
284
|
var newTrackedQuery = {
|
|
@@ -267,7 +296,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
267
296
|
var key = encoderImpl({
|
|
268
297
|
name: queryRef.name,
|
|
269
298
|
variables: queryRef.variables,
|
|
270
|
-
refType:
|
|
299
|
+
refType: QUERY_STR
|
|
271
300
|
});
|
|
272
301
|
var trackedQuery = this._queries.get(key);
|
|
273
302
|
var subscription = {
|
|
@@ -316,7 +345,7 @@ var QueryManager = /** @class */ (function () {
|
|
|
316
345
|
var key = encoderImpl({
|
|
317
346
|
name: queryRef.name,
|
|
318
347
|
variables: queryRef.variables,
|
|
319
|
-
refType:
|
|
348
|
+
refType: QUERY_STR
|
|
320
349
|
});
|
|
321
350
|
var trackedQuery = this._queries.get(key);
|
|
322
351
|
var result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
|
|
@@ -354,55 +383,6 @@ function compareDates(str1, str2) {
|
|
|
354
383
|
return date1.getTime() < date2.getTime();
|
|
355
384
|
}
|
|
356
385
|
|
|
357
|
-
/**
|
|
358
|
-
* @license
|
|
359
|
-
* Copyright 2024 Google LLC
|
|
360
|
-
*
|
|
361
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
362
|
-
* you may not use this file except in compliance with the License.
|
|
363
|
-
* You may obtain a copy of the License at
|
|
364
|
-
*
|
|
365
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
366
|
-
*
|
|
367
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
368
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
369
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
370
|
-
* See the License for the specific language governing permissions and
|
|
371
|
-
* limitations under the License.
|
|
372
|
-
*/
|
|
373
|
-
var Code = {
|
|
374
|
-
OTHER: 'other',
|
|
375
|
-
ALREADY_INITIALIZED: 'already-initialized',
|
|
376
|
-
NOT_INITIALIZED: 'not-initialized',
|
|
377
|
-
NOT_SUPPORTED: 'not-supported',
|
|
378
|
-
INVALID_ARGUMENT: 'invalid-argument',
|
|
379
|
-
PARTIAL_ERROR: 'partial-error'
|
|
380
|
-
};
|
|
381
|
-
/** An error returned by a DataConnect operation. */
|
|
382
|
-
var DataConnectError = /** @class */ (function (_super) {
|
|
383
|
-
__extends(DataConnectError, _super);
|
|
384
|
-
/** @hideconstructor */
|
|
385
|
-
function DataConnectError(
|
|
386
|
-
/**
|
|
387
|
-
* The backend error code associated with this error.
|
|
388
|
-
*/
|
|
389
|
-
code,
|
|
390
|
-
/**
|
|
391
|
-
* A custom error description.
|
|
392
|
-
*/
|
|
393
|
-
message) {
|
|
394
|
-
var _this = _super.call(this, code, message) || this;
|
|
395
|
-
_this.code = code;
|
|
396
|
-
_this.message = message;
|
|
397
|
-
// HACK: We write a toString property directly because Error is not a real
|
|
398
|
-
// class and so inheritance does not work correctly. We could alternatively
|
|
399
|
-
// do the same "back-door inheritance" trick that FirebaseError does.
|
|
400
|
-
_this.toString = function () { return "".concat(_this.name, ": [code=").concat(_this.code, "]: ").concat(_this.message); };
|
|
401
|
-
return _this;
|
|
402
|
-
}
|
|
403
|
-
return DataConnectError;
|
|
404
|
-
}(FirebaseError));
|
|
405
|
-
|
|
406
386
|
/**
|
|
407
387
|
* @license
|
|
408
388
|
* Copyright 2024 Google LLC
|
|
@@ -479,6 +459,8 @@ function dcFetch(url, body, _a, accessToken) {
|
|
|
479
459
|
method: 'POST',
|
|
480
460
|
headers: headers,
|
|
481
461
|
signal: signal
|
|
462
|
+
}).catch(function (err) {
|
|
463
|
+
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
|
|
482
464
|
})
|
|
483
465
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
484
466
|
var jsonResponse, e_1;
|
|
@@ -537,24 +519,24 @@ var RESTTransport = /** @class */ (function () {
|
|
|
537
519
|
var _a;
|
|
538
520
|
this.apiKey = apiKey;
|
|
539
521
|
this.authProvider = authProvider;
|
|
540
|
-
this.
|
|
541
|
-
this.
|
|
542
|
-
this.
|
|
543
|
-
this.
|
|
544
|
-
this.
|
|
545
|
-
this.
|
|
546
|
-
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;
|
|
547
529
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
548
530
|
this.invokeQuery = function (queryName, body) {
|
|
549
531
|
var abortController = new AbortController();
|
|
550
532
|
// TODO(mtewani): Update to proper value
|
|
551
533
|
var withAuth = _this.getWithAuth().then(function () {
|
|
552
534
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
|
|
553
|
-
name: "projects/".concat(_this.
|
|
535
|
+
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
554
536
|
operationName: queryName,
|
|
555
537
|
variables: body
|
|
556
538
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
557
|
-
abortController, _this.
|
|
539
|
+
abortController, _this._accessToken);
|
|
558
540
|
});
|
|
559
541
|
return {
|
|
560
542
|
then: withAuth.then.bind(withAuth)
|
|
@@ -564,10 +546,10 @@ var RESTTransport = /** @class */ (function () {
|
|
|
564
546
|
var abortController = new AbortController();
|
|
565
547
|
var taskResult = _this.getWithAuth().then(function () {
|
|
566
548
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
|
|
567
|
-
name: "projects/".concat(_this.
|
|
549
|
+
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
568
550
|
operationName: mutationName,
|
|
569
551
|
variables: body
|
|
570
|
-
}, abortController, _this.
|
|
552
|
+
}, abortController, _this._accessToken);
|
|
571
553
|
});
|
|
572
554
|
return {
|
|
573
555
|
then: taskResult.then.bind(taskResult),
|
|
@@ -578,60 +560,60 @@ var RESTTransport = /** @class */ (function () {
|
|
|
578
560
|
};
|
|
579
561
|
if (transportOptions) {
|
|
580
562
|
if (typeof transportOptions.port === 'number') {
|
|
581
|
-
this.
|
|
563
|
+
this._port = transportOptions.port;
|
|
582
564
|
}
|
|
583
565
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
584
|
-
this.
|
|
566
|
+
this._secure = transportOptions.sslEnabled;
|
|
585
567
|
}
|
|
586
|
-
this.
|
|
568
|
+
this._host = transportOptions.host;
|
|
587
569
|
}
|
|
588
570
|
var location = options.location, project = options.projectId, connector = options.connector, service = options.service;
|
|
589
571
|
if (location) {
|
|
590
|
-
this.
|
|
572
|
+
this._location = location;
|
|
591
573
|
}
|
|
592
574
|
if (project) {
|
|
593
|
-
this.
|
|
575
|
+
this._project = project;
|
|
594
576
|
}
|
|
595
|
-
this.
|
|
577
|
+
this._serviceName = service;
|
|
596
578
|
if (!connector) {
|
|
597
579
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
598
580
|
}
|
|
599
|
-
this.
|
|
581
|
+
this._connectorName = connector;
|
|
600
582
|
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(function (token) {
|
|
601
583
|
logDebug("New Token Available: ".concat(token));
|
|
602
|
-
_this.
|
|
584
|
+
_this._accessToken = token;
|
|
603
585
|
});
|
|
604
586
|
}
|
|
605
587
|
Object.defineProperty(RESTTransport.prototype, "endpointUrl", {
|
|
606
588
|
get: function () {
|
|
607
589
|
return urlBuilder({
|
|
608
|
-
connector: this.
|
|
609
|
-
location: this.
|
|
610
|
-
projectId: this.
|
|
611
|
-
service: this.
|
|
612
|
-
}, { 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 });
|
|
613
595
|
},
|
|
614
596
|
enumerable: false,
|
|
615
597
|
configurable: true
|
|
616
598
|
});
|
|
617
599
|
RESTTransport.prototype.useEmulator = function (host, port, isSecure) {
|
|
618
|
-
this.
|
|
600
|
+
this._host = host;
|
|
619
601
|
if (typeof port === 'number') {
|
|
620
|
-
this.
|
|
602
|
+
this._port = port;
|
|
621
603
|
}
|
|
622
604
|
if (typeof isSecure !== 'undefined') {
|
|
623
|
-
this.
|
|
605
|
+
this._secure = isSecure;
|
|
624
606
|
}
|
|
625
607
|
};
|
|
626
608
|
RESTTransport.prototype.onTokenChanged = function (newToken) {
|
|
627
|
-
this.
|
|
609
|
+
this._accessToken = newToken;
|
|
628
610
|
};
|
|
629
611
|
RESTTransport.prototype.getWithAuth = function () {
|
|
630
612
|
var _this = this;
|
|
631
613
|
var starterPromise = new Promise(function (resolve) {
|
|
632
|
-
return resolve(_this.
|
|
614
|
+
return resolve(_this._accessToken);
|
|
633
615
|
});
|
|
634
|
-
if (!this.
|
|
616
|
+
if (!this._authInitialized) {
|
|
635
617
|
if (this.authProvider) {
|
|
636
618
|
starterPromise = this.authProvider
|
|
637
619
|
.getToken(/*forceToken=*/ false)
|
|
@@ -639,8 +621,8 @@ var RESTTransport = /** @class */ (function () {
|
|
|
639
621
|
if (!data) {
|
|
640
622
|
return null;
|
|
641
623
|
}
|
|
642
|
-
_this.
|
|
643
|
-
return _this.
|
|
624
|
+
_this._accessToken = data.accessToken;
|
|
625
|
+
return _this._accessToken;
|
|
644
626
|
});
|
|
645
627
|
}
|
|
646
628
|
else {
|
|
@@ -673,19 +655,19 @@ function mutationRef(dcInstance, queryName, variables) {
|
|
|
673
655
|
var ref = {
|
|
674
656
|
dataConnect: dcInstance,
|
|
675
657
|
name: queryName,
|
|
676
|
-
refType:
|
|
658
|
+
refType: MUTATION_STR,
|
|
677
659
|
variables: variables
|
|
678
660
|
};
|
|
679
661
|
return ref;
|
|
680
662
|
}
|
|
681
663
|
var MutationManager = /** @class */ (function () {
|
|
682
|
-
function MutationManager(
|
|
683
|
-
this.
|
|
664
|
+
function MutationManager(_transport) {
|
|
665
|
+
this._transport = _transport;
|
|
684
666
|
this._inflight = [];
|
|
685
667
|
}
|
|
686
668
|
MutationManager.prototype.executeMutation = function (mutationRef) {
|
|
687
669
|
var _this = this;
|
|
688
|
-
var result = this.
|
|
670
|
+
var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
689
671
|
var withRefPromise = result.then(function (res) {
|
|
690
672
|
var obj = __assign(__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
691
673
|
return obj;
|
|
@@ -734,10 +716,12 @@ function parseOptions(fullHost) {
|
|
|
734
716
|
return { host: host, port: port, sslEnabled: isSecure };
|
|
735
717
|
}
|
|
736
718
|
var DataConnect = /** @class */ (function () {
|
|
737
|
-
function DataConnect(app,
|
|
719
|
+
function DataConnect(app,
|
|
720
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
721
|
+
dataConnectOptions, _authProvider) {
|
|
738
722
|
this.app = app;
|
|
739
723
|
this.dataConnectOptions = dataConnectOptions;
|
|
740
|
-
this.
|
|
724
|
+
this._authProvider = _authProvider;
|
|
741
725
|
this.isEmulator = false;
|
|
742
726
|
this.initialized = false;
|
|
743
727
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -745,7 +729,7 @@ var DataConnect = /** @class */ (function () {
|
|
|
745
729
|
if (host) {
|
|
746
730
|
logDebug('Found custom host. Using emulator');
|
|
747
731
|
this.isEmulator = true;
|
|
748
|
-
this.
|
|
732
|
+
this._transportOptions = parseOptions(host);
|
|
749
733
|
}
|
|
750
734
|
}
|
|
751
735
|
}
|
|
@@ -762,29 +746,27 @@ var DataConnect = /** @class */ (function () {
|
|
|
762
746
|
if (this.initialized) {
|
|
763
747
|
return;
|
|
764
748
|
}
|
|
765
|
-
if (this.
|
|
749
|
+
if (this._transportClass === undefined) {
|
|
766
750
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
767
|
-
this.
|
|
751
|
+
this._transportClass = RESTTransport;
|
|
768
752
|
}
|
|
769
|
-
if (this.
|
|
770
|
-
this.
|
|
771
|
-
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
|
|
772
|
-
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
|
|
753
|
+
if (this._authProvider) {
|
|
754
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
773
755
|
}
|
|
774
756
|
this.initialized = true;
|
|
775
|
-
this._transport = new this.
|
|
776
|
-
if (this.
|
|
777
|
-
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);
|
|
778
760
|
}
|
|
779
761
|
this._queryManager = new QueryManager(this._transport);
|
|
780
762
|
this._mutationManager = new MutationManager(this._transport);
|
|
781
763
|
};
|
|
782
764
|
DataConnect.prototype.enableEmulator = function (transportOptions) {
|
|
783
765
|
if (this.initialized) {
|
|
784
|
-
logError('enableEmulator called
|
|
766
|
+
logError('enableEmulator called after initialization');
|
|
785
767
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
786
768
|
}
|
|
787
|
-
this.
|
|
769
|
+
this._transportOptions = transportOptions;
|
|
788
770
|
this.isEmulator = true;
|
|
789
771
|
};
|
|
790
772
|
return DataConnect;
|
|
@@ -829,7 +811,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
829
811
|
});
|
|
830
812
|
}
|
|
831
813
|
function terminate(dataConnect) {
|
|
832
|
-
dataConnect._delete();
|
|
814
|
+
return dataConnect._delete();
|
|
833
815
|
// TODO(mtewani): Stop pending tasks
|
|
834
816
|
}
|
|
835
817
|
|
|
@@ -874,7 +856,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
874
856
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
875
857
|
return {
|
|
876
858
|
dataConnect: dcInstance,
|
|
877
|
-
refType:
|
|
859
|
+
refType: QUERY_STR,
|
|
878
860
|
name: queryName,
|
|
879
861
|
variables: variables
|
|
880
862
|
};
|
|
@@ -936,27 +918,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
936
918
|
*
|
|
937
919
|
* @packageDocumentation
|
|
938
920
|
*/
|
|
939
|
-
registerDataConnect();
|
|
940
|
-
// import { getDataConnect, queryRef } from './api';
|
|
941
|
-
// import { getApp } from '@firebase/app';
|
|
942
|
-
// const app = getApp();
|
|
943
|
-
// const dc = getDataConnect({ location: '', connector: '', serviceId: '', projectId: '' });
|
|
944
|
-
// interface Response {
|
|
945
|
-
// name: string;
|
|
946
|
-
// }
|
|
947
|
-
// const converter: Converter<Response> = {
|
|
948
|
-
// fromDataConnect(input: string) {
|
|
949
|
-
// return { name: input };
|
|
950
|
-
// },
|
|
951
|
-
// fromType(input) {
|
|
952
|
-
// return input;
|
|
953
|
-
// }
|
|
954
|
-
// };
|
|
955
|
-
// const myRef = queryRef(dc, '', converter);
|
|
956
|
-
// // Ref's shouldn't have access to their own cache, right?
|
|
957
|
-
// const a = execute(myRef);
|
|
958
|
-
// subscribe(myRef, (res) => {
|
|
959
|
-
// })
|
|
921
|
+
registerDataConnect();
|
|
960
922
|
|
|
961
|
-
export { DataConnect,
|
|
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 };
|
|
962
924
|
//# sourceMappingURL=index.esm5.js.map
|