@firebase/data-connect 0.0.1-dataconnect-preview.81ee5169c → 0.0.2-dataconnect-preview.388b61c7e
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 +181 -141
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +180 -140
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +183 -143
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +132 -72
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/internal.d.ts +156 -44
- package/dist/node-esm/index.node.esm.js +132 -72
- package/dist/node-esm/index.node.esm.js.map +1 -1
- package/dist/node-esm/src/api/DataConnect.d.ts +39 -12
- package/dist/node-esm/src/api/Mutation.d.ts +33 -8
- package/dist/node-esm/src/api/Reference.d.ts +9 -3
- package/dist/node-esm/src/api/query.d.ts +52 -2
- package/dist/node-esm/src/api.browser.d.ts +12 -7
- 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 +151 -47
- package/dist/public.d.ts +135 -37
- package/dist/src/api/DataConnect.d.ts +39 -12
- package/dist/src/api/Mutation.d.ts +33 -8
- package/dist/src/api/Reference.d.ts +9 -3
- package/dist/src/api/query.d.ts +52 -2
- package/dist/src/api.browser.d.ts +12 -7
- 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.388b61c7e";
|
|
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 {
|
|
@@ -648,24 +650,34 @@ var RESTTransport = /** @class */ (function () {
|
|
|
648
650
|
* See the License for the specific language governing permissions and
|
|
649
651
|
* limitations under the License.
|
|
650
652
|
*/
|
|
651
|
-
|
|
653
|
+
/**
|
|
654
|
+
*
|
|
655
|
+
* @param dcInstance Data Connect instance
|
|
656
|
+
* @param mutationName name of mutation
|
|
657
|
+
* @param variables variables to send with mutation
|
|
658
|
+
* @returns `MutationRef`
|
|
659
|
+
*/
|
|
660
|
+
function mutationRef(dcInstance, mutationName, variables) {
|
|
652
661
|
dcInstance.setInitialized();
|
|
653
662
|
var ref = {
|
|
654
663
|
dataConnect: dcInstance,
|
|
655
|
-
name:
|
|
656
|
-
refType:
|
|
664
|
+
name: mutationName,
|
|
665
|
+
refType: MUTATION_STR,
|
|
657
666
|
variables: variables
|
|
658
667
|
};
|
|
659
668
|
return ref;
|
|
660
669
|
}
|
|
670
|
+
/**
|
|
671
|
+
* @internal
|
|
672
|
+
*/
|
|
661
673
|
var MutationManager = /** @class */ (function () {
|
|
662
|
-
function MutationManager(
|
|
663
|
-
this.
|
|
674
|
+
function MutationManager(_transport) {
|
|
675
|
+
this._transport = _transport;
|
|
664
676
|
this._inflight = [];
|
|
665
677
|
}
|
|
666
678
|
MutationManager.prototype.executeMutation = function (mutationRef) {
|
|
667
679
|
var _this = this;
|
|
668
|
-
var result = this.
|
|
680
|
+
var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
669
681
|
var withRefPromise = result.then(function (res) {
|
|
670
682
|
var obj = __assign(__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
671
683
|
return obj;
|
|
@@ -679,6 +691,11 @@ var MutationManager = /** @class */ (function () {
|
|
|
679
691
|
};
|
|
680
692
|
return MutationManager;
|
|
681
693
|
}());
|
|
694
|
+
/**
|
|
695
|
+
* Execute Mutation
|
|
696
|
+
* @param mutationRef mutation to execute
|
|
697
|
+
* @returns `MutationRef`
|
|
698
|
+
*/
|
|
682
699
|
function executeMutation(mutationRef) {
|
|
683
700
|
return mutationRef.dataConnect._mutationManager.executeMutation(mutationRef);
|
|
684
701
|
}
|
|
@@ -713,11 +730,16 @@ function parseOptions(fullHost) {
|
|
|
713
730
|
var port = Number(portAsString);
|
|
714
731
|
return { host: host, port: port, sslEnabled: isSecure };
|
|
715
732
|
}
|
|
733
|
+
/**
|
|
734
|
+
* Class representing Firebase Data Connect
|
|
735
|
+
*/
|
|
716
736
|
var DataConnect = /** @class */ (function () {
|
|
717
|
-
function DataConnect(app,
|
|
737
|
+
function DataConnect(app,
|
|
738
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
739
|
+
dataConnectOptions, _authProvider) {
|
|
718
740
|
this.app = app;
|
|
719
741
|
this.dataConnectOptions = dataConnectOptions;
|
|
720
|
-
this.
|
|
742
|
+
this._authProvider = _authProvider;
|
|
721
743
|
this.isEmulator = false;
|
|
722
744
|
this.initialized = false;
|
|
723
745
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -725,7 +747,7 @@ var DataConnect = /** @class */ (function () {
|
|
|
725
747
|
if (host) {
|
|
726
748
|
logDebug('Found custom host. Using emulator');
|
|
727
749
|
this.isEmulator = true;
|
|
728
|
-
this.
|
|
750
|
+
this._transportOptions = parseOptions(host);
|
|
729
751
|
}
|
|
730
752
|
}
|
|
731
753
|
}
|
|
@@ -742,31 +764,38 @@ var DataConnect = /** @class */ (function () {
|
|
|
742
764
|
if (this.initialized) {
|
|
743
765
|
return;
|
|
744
766
|
}
|
|
745
|
-
if (this.
|
|
767
|
+
if (this._transportClass === undefined) {
|
|
746
768
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
747
|
-
this.
|
|
769
|
+
this._transportClass = RESTTransport;
|
|
748
770
|
}
|
|
749
|
-
if (this.
|
|
750
|
-
this.
|
|
771
|
+
if (this._authProvider) {
|
|
772
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
751
773
|
}
|
|
752
774
|
this.initialized = true;
|
|
753
|
-
this._transport = new this.
|
|
754
|
-
if (this.
|
|
755
|
-
this._transport.useEmulator(this.
|
|
775
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
|
|
776
|
+
if (this._transportOptions) {
|
|
777
|
+
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
756
778
|
}
|
|
757
779
|
this._queryManager = new QueryManager(this._transport);
|
|
758
780
|
this._mutationManager = new MutationManager(this._transport);
|
|
759
781
|
};
|
|
760
782
|
DataConnect.prototype.enableEmulator = function (transportOptions) {
|
|
761
783
|
if (this.initialized) {
|
|
762
|
-
logError('enableEmulator called
|
|
784
|
+
logError('enableEmulator called after initialization');
|
|
763
785
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
764
786
|
}
|
|
765
|
-
this.
|
|
787
|
+
this._transportOptions = transportOptions;
|
|
766
788
|
this.isEmulator = true;
|
|
767
789
|
};
|
|
768
790
|
return DataConnect;
|
|
769
791
|
}());
|
|
792
|
+
/**
|
|
793
|
+
* Connect to the DataConnect Emulator
|
|
794
|
+
* @param dc Data Connect instance
|
|
795
|
+
* @param host host of emulator server
|
|
796
|
+
* @param port port of emulator server
|
|
797
|
+
* @param sslEnabled use https
|
|
798
|
+
*/
|
|
770
799
|
function connectDataConnectEmulator(dc, host, port, sslEnabled) {
|
|
771
800
|
if (sslEnabled === void 0) { sslEnabled = false; }
|
|
772
801
|
dc.enableEmulator({ host: host, port: port, sslEnabled: sslEnabled });
|
|
@@ -806,8 +835,13 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
806
835
|
options: dcOptions
|
|
807
836
|
});
|
|
808
837
|
}
|
|
838
|
+
/**
|
|
839
|
+
* Delete DataConnect instance
|
|
840
|
+
* @param dataConnect DataConnect instance
|
|
841
|
+
* @returns
|
|
842
|
+
*/
|
|
809
843
|
function terminate(dataConnect) {
|
|
810
|
-
dataConnect._delete();
|
|
844
|
+
return dataConnect._delete();
|
|
811
845
|
// TODO(mtewani): Stop pending tasks
|
|
812
846
|
}
|
|
813
847
|
|
|
@@ -844,19 +878,37 @@ function registerDataConnect(variant) {
|
|
|
844
878
|
* See the License for the specific language governing permissions and
|
|
845
879
|
* limitations under the License.
|
|
846
880
|
*/
|
|
881
|
+
/**
|
|
882
|
+
* Execute Query
|
|
883
|
+
* @param queryRef query to execute.
|
|
884
|
+
* @returns `QueryPromise`
|
|
885
|
+
*/
|
|
847
886
|
function executeQuery(queryRef) {
|
|
848
887
|
return queryRef.dataConnect._queryManager.executeQuery(queryRef);
|
|
849
888
|
}
|
|
889
|
+
/**
|
|
890
|
+
* Execute Query
|
|
891
|
+
* @param dcInstance Data Connect instance to use.
|
|
892
|
+
* @param queryName Query to execute
|
|
893
|
+
* @param variables Variables to execute with
|
|
894
|
+
* @param initialCache initial cache to use for client hydration
|
|
895
|
+
* @returns `QueryRef`
|
|
896
|
+
*/
|
|
850
897
|
function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
851
898
|
dcInstance.setInitialized();
|
|
852
899
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
853
900
|
return {
|
|
854
901
|
dataConnect: dcInstance,
|
|
855
|
-
refType:
|
|
902
|
+
refType: QUERY_STR,
|
|
856
903
|
name: queryName,
|
|
857
904
|
variables: variables
|
|
858
905
|
};
|
|
859
906
|
}
|
|
907
|
+
/**
|
|
908
|
+
* Converts serialized ref to query ref
|
|
909
|
+
* @param serializedRef ref to convert to `QueryRef`
|
|
910
|
+
* @returns `QueryRef`
|
|
911
|
+
*/
|
|
860
912
|
function toQueryRef(serializedRef) {
|
|
861
913
|
var _a = serializedRef.refInfo, name = _a.name, variables = _a.variables, connectorConfig = _a.connectorConfig;
|
|
862
914
|
return queryRef(getDataConnect(connectorConfig), name, variables);
|
|
@@ -878,6 +930,14 @@ function toQueryRef(serializedRef) {
|
|
|
878
930
|
* See the License for the specific language governing permissions and
|
|
879
931
|
* limitations under the License.
|
|
880
932
|
*/
|
|
933
|
+
/**
|
|
934
|
+
* Subscribe to a `QueryRef`
|
|
935
|
+
* @param queryRefOrSerializedResult query ref or serialized result.
|
|
936
|
+
* @param observerOrOnNext observer object or next function.
|
|
937
|
+
* @param onError Callback to call when error gets thrown.
|
|
938
|
+
* @param onComplete Called when subscription completes.
|
|
939
|
+
* @returns `SubscriptionOptions`
|
|
940
|
+
*/
|
|
881
941
|
function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComplete) {
|
|
882
942
|
var ref;
|
|
883
943
|
var initialCache;
|
|
@@ -914,27 +974,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
914
974
|
*
|
|
915
975
|
* @packageDocumentation
|
|
916
976
|
*/
|
|
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
|
-
// })
|
|
977
|
+
registerDataConnect();
|
|
938
978
|
|
|
939
|
-
export { DataConnect, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider,
|
|
979
|
+
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
980
|
//# sourceMappingURL=index.esm5.js.map
|