@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
|
@@ -139,6 +139,8 @@ function dcFetch(url, body, { signal }, accessToken) {
|
|
|
139
139
|
method: 'POST',
|
|
140
140
|
headers,
|
|
141
141
|
signal
|
|
142
|
+
}).catch(err => {
|
|
143
|
+
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
|
|
142
144
|
})
|
|
143
145
|
.then(async (response) => {
|
|
144
146
|
let jsonResponse = null;
|
|
@@ -165,7 +167,7 @@ function dcFetch(url, body, { signal }, accessToken) {
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
const name = "@firebase/data-connect";
|
|
168
|
-
const version = "0.0.
|
|
170
|
+
const version = "0.0.2-dataconnect-preview.877f8b7d0";
|
|
169
171
|
|
|
170
172
|
/**
|
|
171
173
|
* @license
|
|
@@ -184,20 +186,20 @@ const version = "0.0.1-dataconnect-preview.81ee5169c";
|
|
|
184
186
|
* limitations under the License.
|
|
185
187
|
*/
|
|
186
188
|
class FirebaseAuthProvider {
|
|
187
|
-
constructor(
|
|
188
|
-
this.
|
|
189
|
-
this.
|
|
190
|
-
this.
|
|
191
|
-
this.
|
|
192
|
-
if (!this.
|
|
193
|
-
|
|
189
|
+
constructor(_appName, _options, _authProvider) {
|
|
190
|
+
this._appName = _appName;
|
|
191
|
+
this._options = _options;
|
|
192
|
+
this._authProvider = _authProvider;
|
|
193
|
+
this._auth = _authProvider.getImmediate({ optional: true });
|
|
194
|
+
if (!this._auth) {
|
|
195
|
+
_authProvider.onInit(auth => (this._auth = auth));
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
getToken(forceRefresh) {
|
|
197
|
-
if (!this.
|
|
199
|
+
if (!this._auth) {
|
|
198
200
|
return new Promise((resolve, reject) => {
|
|
199
201
|
setTimeout(() => {
|
|
200
|
-
if (this.
|
|
202
|
+
if (this._auth) {
|
|
201
203
|
this.getToken(forceRefresh).then(resolve, reject);
|
|
202
204
|
}
|
|
203
205
|
else {
|
|
@@ -206,7 +208,7 @@ class FirebaseAuthProvider {
|
|
|
206
208
|
}, 0);
|
|
207
209
|
});
|
|
208
210
|
}
|
|
209
|
-
return this.
|
|
211
|
+
return this._auth.getToken(forceRefresh).catch(error => {
|
|
210
212
|
if (error && error.code === 'auth/token-not-initialized') {
|
|
211
213
|
logDebug('Got auth/token-not-initialized error. Treating as null token.');
|
|
212
214
|
return null;
|
|
@@ -220,10 +222,10 @@ class FirebaseAuthProvider {
|
|
|
220
222
|
}
|
|
221
223
|
addTokenChangeListener(listener) {
|
|
222
224
|
var _a;
|
|
223
|
-
(_a = this.
|
|
225
|
+
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
|
|
224
226
|
}
|
|
225
227
|
removeTokenChangeListener(listener) {
|
|
226
|
-
this.
|
|
228
|
+
this._authProvider
|
|
227
229
|
.get()
|
|
228
230
|
.then(auth => auth.removeAuthTokenListener(listener));
|
|
229
231
|
}
|
|
@@ -245,8 +247,8 @@ class FirebaseAuthProvider {
|
|
|
245
247
|
* See the License for the specific language governing permissions and
|
|
246
248
|
* limitations under the License.
|
|
247
249
|
*/
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
+
const QUERY_STR = 'query';
|
|
251
|
+
const MUTATION_STR = 'mutation';
|
|
250
252
|
const SOURCE_SERVER = 'SERVER';
|
|
251
253
|
const SOURCE_CACHE = 'CACHE';
|
|
252
254
|
|
|
@@ -333,7 +335,7 @@ class QueryManager {
|
|
|
333
335
|
const ref = {
|
|
334
336
|
name: queryName,
|
|
335
337
|
variables,
|
|
336
|
-
refType:
|
|
338
|
+
refType: QUERY_STR
|
|
337
339
|
};
|
|
338
340
|
const key = encoderImpl(ref);
|
|
339
341
|
const newTrackedQuery = {
|
|
@@ -350,7 +352,7 @@ class QueryManager {
|
|
|
350
352
|
const key = encoderImpl({
|
|
351
353
|
name: queryRef.name,
|
|
352
354
|
variables: queryRef.variables,
|
|
353
|
-
refType:
|
|
355
|
+
refType: QUERY_STR
|
|
354
356
|
});
|
|
355
357
|
const trackedQuery = this._queries.get(key);
|
|
356
358
|
const subscription = {
|
|
@@ -399,7 +401,7 @@ class QueryManager {
|
|
|
399
401
|
const key = encoderImpl({
|
|
400
402
|
name: queryRef.name,
|
|
401
403
|
variables: queryRef.variables,
|
|
402
|
-
refType:
|
|
404
|
+
refType: QUERY_STR
|
|
403
405
|
});
|
|
404
406
|
const trackedQuery = this._queries.get(key);
|
|
405
407
|
const result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
|
|
@@ -497,24 +499,24 @@ class RESTTransport {
|
|
|
497
499
|
var _a;
|
|
498
500
|
this.apiKey = apiKey;
|
|
499
501
|
this.authProvider = authProvider;
|
|
500
|
-
this.
|
|
501
|
-
this.
|
|
502
|
-
this.
|
|
503
|
-
this.
|
|
504
|
-
this.
|
|
505
|
-
this.
|
|
506
|
-
this.
|
|
502
|
+
this._host = '';
|
|
503
|
+
this._location = 'l';
|
|
504
|
+
this._connectorName = '';
|
|
505
|
+
this._secure = true;
|
|
506
|
+
this._project = 'p';
|
|
507
|
+
this._accessToken = null;
|
|
508
|
+
this._authInitialized = false;
|
|
507
509
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
508
510
|
this.invokeQuery = (queryName, body) => {
|
|
509
511
|
const abortController = new AbortController();
|
|
510
512
|
// TODO(mtewani): Update to proper value
|
|
511
513
|
const withAuth = this.getWithAuth().then(() => {
|
|
512
514
|
return dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
|
|
513
|
-
name: `projects/${this.
|
|
515
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
514
516
|
operationName: queryName,
|
|
515
517
|
variables: body
|
|
516
518
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
517
|
-
abortController, this.
|
|
519
|
+
abortController, this._accessToken);
|
|
518
520
|
});
|
|
519
521
|
return {
|
|
520
522
|
then: withAuth.then.bind(withAuth)
|
|
@@ -524,10 +526,10 @@ class RESTTransport {
|
|
|
524
526
|
const abortController = new AbortController();
|
|
525
527
|
const taskResult = this.getWithAuth().then(() => {
|
|
526
528
|
return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
|
|
527
|
-
name: `projects/${this.
|
|
529
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
528
530
|
operationName: mutationName,
|
|
529
531
|
variables: body
|
|
530
|
-
}, abortController, this.
|
|
532
|
+
}, abortController, this._accessToken);
|
|
531
533
|
});
|
|
532
534
|
return {
|
|
533
535
|
then: taskResult.then.bind(taskResult),
|
|
@@ -538,53 +540,53 @@ class RESTTransport {
|
|
|
538
540
|
};
|
|
539
541
|
if (transportOptions) {
|
|
540
542
|
if (typeof transportOptions.port === 'number') {
|
|
541
|
-
this.
|
|
543
|
+
this._port = transportOptions.port;
|
|
542
544
|
}
|
|
543
545
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
544
|
-
this.
|
|
546
|
+
this._secure = transportOptions.sslEnabled;
|
|
545
547
|
}
|
|
546
|
-
this.
|
|
548
|
+
this._host = transportOptions.host;
|
|
547
549
|
}
|
|
548
550
|
const { location, projectId: project, connector, service } = options;
|
|
549
551
|
if (location) {
|
|
550
|
-
this.
|
|
552
|
+
this._location = location;
|
|
551
553
|
}
|
|
552
554
|
if (project) {
|
|
553
|
-
this.
|
|
555
|
+
this._project = project;
|
|
554
556
|
}
|
|
555
|
-
this.
|
|
557
|
+
this._serviceName = service;
|
|
556
558
|
if (!connector) {
|
|
557
559
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
558
560
|
}
|
|
559
|
-
this.
|
|
561
|
+
this._connectorName = connector;
|
|
560
562
|
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
|
|
561
563
|
logDebug(`New Token Available: ${token}`);
|
|
562
|
-
this.
|
|
564
|
+
this._accessToken = token;
|
|
563
565
|
});
|
|
564
566
|
}
|
|
565
567
|
get endpointUrl() {
|
|
566
568
|
return urlBuilder({
|
|
567
|
-
connector: this.
|
|
568
|
-
location: this.
|
|
569
|
-
projectId: this.
|
|
570
|
-
service: this.
|
|
571
|
-
}, { host: this.
|
|
569
|
+
connector: this._connectorName,
|
|
570
|
+
location: this._location,
|
|
571
|
+
projectId: this._project,
|
|
572
|
+
service: this._serviceName
|
|
573
|
+
}, { host: this._host, sslEnabled: this._secure, port: this._port });
|
|
572
574
|
}
|
|
573
575
|
useEmulator(host, port, isSecure) {
|
|
574
|
-
this.
|
|
576
|
+
this._host = host;
|
|
575
577
|
if (typeof port === 'number') {
|
|
576
|
-
this.
|
|
578
|
+
this._port = port;
|
|
577
579
|
}
|
|
578
580
|
if (typeof isSecure !== 'undefined') {
|
|
579
|
-
this.
|
|
581
|
+
this._secure = isSecure;
|
|
580
582
|
}
|
|
581
583
|
}
|
|
582
584
|
onTokenChanged(newToken) {
|
|
583
|
-
this.
|
|
585
|
+
this._accessToken = newToken;
|
|
584
586
|
}
|
|
585
587
|
getWithAuth() {
|
|
586
|
-
let starterPromise = new Promise(resolve => resolve(this.
|
|
587
|
-
if (!this.
|
|
588
|
+
let starterPromise = new Promise(resolve => resolve(this._accessToken));
|
|
589
|
+
if (!this._authInitialized) {
|
|
588
590
|
if (this.authProvider) {
|
|
589
591
|
starterPromise = this.authProvider
|
|
590
592
|
.getToken(/*forceToken=*/ false)
|
|
@@ -592,8 +594,8 @@ class RESTTransport {
|
|
|
592
594
|
if (!data) {
|
|
593
595
|
return null;
|
|
594
596
|
}
|
|
595
|
-
this.
|
|
596
|
-
return this.
|
|
597
|
+
this._accessToken = data.accessToken;
|
|
598
|
+
return this._accessToken;
|
|
597
599
|
});
|
|
598
600
|
}
|
|
599
601
|
else {
|
|
@@ -625,18 +627,18 @@ function mutationRef(dcInstance, queryName, variables) {
|
|
|
625
627
|
const ref = {
|
|
626
628
|
dataConnect: dcInstance,
|
|
627
629
|
name: queryName,
|
|
628
|
-
refType:
|
|
630
|
+
refType: MUTATION_STR,
|
|
629
631
|
variables: variables
|
|
630
632
|
};
|
|
631
633
|
return ref;
|
|
632
634
|
}
|
|
633
635
|
class MutationManager {
|
|
634
|
-
constructor(
|
|
635
|
-
this.
|
|
636
|
+
constructor(_transport) {
|
|
637
|
+
this._transport = _transport;
|
|
636
638
|
this._inflight = [];
|
|
637
639
|
}
|
|
638
640
|
executeMutation(mutationRef) {
|
|
639
|
-
const result = this.
|
|
641
|
+
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
640
642
|
const withRefPromise = result.then(res => {
|
|
641
643
|
const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
642
644
|
return obj;
|
|
@@ -682,10 +684,12 @@ function parseOptions(fullHost) {
|
|
|
682
684
|
return { host, port, sslEnabled: isSecure };
|
|
683
685
|
}
|
|
684
686
|
class DataConnect {
|
|
685
|
-
constructor(app,
|
|
687
|
+
constructor(app,
|
|
688
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
689
|
+
dataConnectOptions, _authProvider) {
|
|
686
690
|
this.app = app;
|
|
687
691
|
this.dataConnectOptions = dataConnectOptions;
|
|
688
|
-
this.
|
|
692
|
+
this._authProvider = _authProvider;
|
|
689
693
|
this.isEmulator = false;
|
|
690
694
|
this.initialized = false;
|
|
691
695
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -693,7 +697,7 @@ class DataConnect {
|
|
|
693
697
|
if (host) {
|
|
694
698
|
logDebug('Found custom host. Using emulator');
|
|
695
699
|
this.isEmulator = true;
|
|
696
|
-
this.
|
|
700
|
+
this._transportOptions = parseOptions(host);
|
|
697
701
|
}
|
|
698
702
|
}
|
|
699
703
|
}
|
|
@@ -710,27 +714,27 @@ class DataConnect {
|
|
|
710
714
|
if (this.initialized) {
|
|
711
715
|
return;
|
|
712
716
|
}
|
|
713
|
-
if (this.
|
|
717
|
+
if (this._transportClass === undefined) {
|
|
714
718
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
715
|
-
this.
|
|
719
|
+
this._transportClass = RESTTransport;
|
|
716
720
|
}
|
|
717
|
-
if (this.
|
|
718
|
-
this.
|
|
721
|
+
if (this._authProvider) {
|
|
722
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
719
723
|
}
|
|
720
724
|
this.initialized = true;
|
|
721
|
-
this._transport = new this.
|
|
722
|
-
if (this.
|
|
723
|
-
this._transport.useEmulator(this.
|
|
725
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
|
|
726
|
+
if (this._transportOptions) {
|
|
727
|
+
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
724
728
|
}
|
|
725
729
|
this._queryManager = new QueryManager(this._transport);
|
|
726
730
|
this._mutationManager = new MutationManager(this._transport);
|
|
727
731
|
}
|
|
728
732
|
enableEmulator(transportOptions) {
|
|
729
733
|
if (this.initialized) {
|
|
730
|
-
logError('enableEmulator called
|
|
734
|
+
logError('enableEmulator called after initialization');
|
|
731
735
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
732
736
|
}
|
|
733
|
-
this.
|
|
737
|
+
this._transportOptions = transportOptions;
|
|
734
738
|
this.isEmulator = true;
|
|
735
739
|
}
|
|
736
740
|
}
|
|
@@ -773,7 +777,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
773
777
|
});
|
|
774
778
|
}
|
|
775
779
|
function terminate(dataConnect) {
|
|
776
|
-
dataConnect._delete();
|
|
780
|
+
return dataConnect._delete();
|
|
777
781
|
// TODO(mtewani): Stop pending tasks
|
|
778
782
|
}
|
|
779
783
|
|
|
@@ -833,7 +837,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
833
837
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
834
838
|
return {
|
|
835
839
|
dataConnect: dcInstance,
|
|
836
|
-
refType:
|
|
840
|
+
refType: QUERY_STR,
|
|
837
841
|
name: queryName,
|
|
838
842
|
variables: variables
|
|
839
843
|
};
|
|
@@ -863,7 +867,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
863
867
|
let ref;
|
|
864
868
|
let initialCache;
|
|
865
869
|
if ('refInfo' in queryRefOrSerializedResult) {
|
|
866
|
-
|
|
870
|
+
const serializedRef = queryRefOrSerializedResult;
|
|
867
871
|
const { data, source, fetchTime } = serializedRef;
|
|
868
872
|
initialCache = {
|
|
869
873
|
data,
|
|
@@ -909,5 +913,5 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
909
913
|
initializeFetch(fetch);
|
|
910
914
|
registerDataConnect('node');
|
|
911
915
|
|
|
912
|
-
export { DataConnect, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider,
|
|
916
|
+
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 };
|
|
913
917
|
//# sourceMappingURL=index.node.esm.js.map
|