@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.esm2017.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
|
|
2
2
|
import { Component } from '@firebase/component';
|
|
3
|
-
import { Logger } from '@firebase/logger';
|
|
4
3
|
import { FirebaseError } from '@firebase/util';
|
|
4
|
+
import { Logger } from '@firebase/logger';
|
|
5
5
|
|
|
6
6
|
const name = "@firebase/data-connect";
|
|
7
|
-
const version = "0.0.
|
|
7
|
+
const version = "0.0.2-dataconnect-preview.877f8b7d0";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @license
|
|
@@ -32,6 +32,52 @@ function setSDKVersion(version) {
|
|
|
32
32
|
SDK_VERSION = version;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* @license
|
|
37
|
+
* Copyright 2024 Google LLC
|
|
38
|
+
*
|
|
39
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
40
|
+
* you may not use this file except in compliance with the License.
|
|
41
|
+
* You may obtain a copy of the License at
|
|
42
|
+
*
|
|
43
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
44
|
+
*
|
|
45
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
46
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
47
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
48
|
+
* See the License for the specific language governing permissions and
|
|
49
|
+
* limitations under the License.
|
|
50
|
+
*/
|
|
51
|
+
const Code = {
|
|
52
|
+
OTHER: 'other',
|
|
53
|
+
ALREADY_INITIALIZED: 'already-initialized',
|
|
54
|
+
NOT_INITIALIZED: 'not-initialized',
|
|
55
|
+
NOT_SUPPORTED: 'not-supported',
|
|
56
|
+
INVALID_ARGUMENT: 'invalid-argument',
|
|
57
|
+
PARTIAL_ERROR: 'partial-error'
|
|
58
|
+
};
|
|
59
|
+
/** An error returned by a DataConnect operation. */
|
|
60
|
+
class DataConnectError extends FirebaseError {
|
|
61
|
+
/** @hideconstructor */
|
|
62
|
+
constructor(
|
|
63
|
+
/**
|
|
64
|
+
* The backend error code associated with this error.
|
|
65
|
+
*/
|
|
66
|
+
code,
|
|
67
|
+
/**
|
|
68
|
+
* A custom error description.
|
|
69
|
+
*/
|
|
70
|
+
message) {
|
|
71
|
+
super(code, message);
|
|
72
|
+
this.code = code;
|
|
73
|
+
this.message = message;
|
|
74
|
+
// HACK: We write a toString property directly because Error is not a real
|
|
75
|
+
// class and so inheritance does not work correctly. We could alternatively
|
|
76
|
+
// do the same "back-door inheritance" trick that FirebaseError does.
|
|
77
|
+
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
35
81
|
/**
|
|
36
82
|
* @license
|
|
37
83
|
* Copyright 2024 Google LLC
|
|
@@ -76,20 +122,20 @@ function logError(msg) {
|
|
|
76
122
|
* limitations under the License.
|
|
77
123
|
*/
|
|
78
124
|
class FirebaseAuthProvider {
|
|
79
|
-
constructor(
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
if (!this.
|
|
85
|
-
|
|
125
|
+
constructor(_appName, _options, _authProvider) {
|
|
126
|
+
this._appName = _appName;
|
|
127
|
+
this._options = _options;
|
|
128
|
+
this._authProvider = _authProvider;
|
|
129
|
+
this._auth = _authProvider.getImmediate({ optional: true });
|
|
130
|
+
if (!this._auth) {
|
|
131
|
+
_authProvider.onInit(auth => (this._auth = auth));
|
|
86
132
|
}
|
|
87
133
|
}
|
|
88
134
|
getToken(forceRefresh) {
|
|
89
|
-
if (!this.
|
|
135
|
+
if (!this._auth) {
|
|
90
136
|
return new Promise((resolve, reject) => {
|
|
91
137
|
setTimeout(() => {
|
|
92
|
-
if (this.
|
|
138
|
+
if (this._auth) {
|
|
93
139
|
this.getToken(forceRefresh).then(resolve, reject);
|
|
94
140
|
}
|
|
95
141
|
else {
|
|
@@ -98,7 +144,7 @@ class FirebaseAuthProvider {
|
|
|
98
144
|
}, 0);
|
|
99
145
|
});
|
|
100
146
|
}
|
|
101
|
-
return this.
|
|
147
|
+
return this._auth.getToken(forceRefresh).catch(error => {
|
|
102
148
|
if (error && error.code === 'auth/token-not-initialized') {
|
|
103
149
|
logDebug('Got auth/token-not-initialized error. Treating as null token.');
|
|
104
150
|
return null;
|
|
@@ -112,33 +158,14 @@ class FirebaseAuthProvider {
|
|
|
112
158
|
}
|
|
113
159
|
addTokenChangeListener(listener) {
|
|
114
160
|
var _a;
|
|
115
|
-
(_a = this.
|
|
161
|
+
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
|
|
116
162
|
}
|
|
117
163
|
removeTokenChangeListener(listener) {
|
|
118
|
-
this.
|
|
164
|
+
this._authProvider
|
|
119
165
|
.get()
|
|
120
166
|
.then(auth => auth.removeAuthTokenListener(listener));
|
|
121
167
|
}
|
|
122
|
-
}
|
|
123
|
-
class EmulatorTokenProvider {
|
|
124
|
-
constructor(accessToken) {
|
|
125
|
-
this.accessToken = accessToken;
|
|
126
|
-
}
|
|
127
|
-
getToken(forceRefresh) {
|
|
128
|
-
return Promise.resolve({
|
|
129
|
-
accessToken: this.accessToken
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
addTokenChangeListener(listener) {
|
|
133
|
-
// Invoke the listener immediately to match the behavior in Firebase Auth
|
|
134
|
-
// (see packages/auth/src/auth.js#L1807)
|
|
135
|
-
listener(this.accessToken);
|
|
136
|
-
}
|
|
137
|
-
removeTokenChangeListener(listener) { }
|
|
138
|
-
notifyForInvalidToken() { }
|
|
139
|
-
}
|
|
140
|
-
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
|
|
141
|
-
EmulatorTokenProvider.OWNER = 'owner';
|
|
168
|
+
}
|
|
142
169
|
|
|
143
170
|
/**
|
|
144
171
|
* @license
|
|
@@ -156,8 +183,8 @@ EmulatorTokenProvider.OWNER = 'owner';
|
|
|
156
183
|
* See the License for the specific language governing permissions and
|
|
157
184
|
* limitations under the License.
|
|
158
185
|
*/
|
|
159
|
-
const
|
|
160
|
-
const
|
|
186
|
+
const QUERY_STR = 'query';
|
|
187
|
+
const MUTATION_STR = 'mutation';
|
|
161
188
|
const SOURCE_SERVER = 'SERVER';
|
|
162
189
|
const SOURCE_CACHE = 'CACHE';
|
|
163
190
|
|
|
@@ -244,7 +271,7 @@ class QueryManager {
|
|
|
244
271
|
const ref = {
|
|
245
272
|
name: queryName,
|
|
246
273
|
variables,
|
|
247
|
-
refType:
|
|
274
|
+
refType: QUERY_STR
|
|
248
275
|
};
|
|
249
276
|
const key = encoderImpl(ref);
|
|
250
277
|
const newTrackedQuery = {
|
|
@@ -261,7 +288,7 @@ class QueryManager {
|
|
|
261
288
|
const key = encoderImpl({
|
|
262
289
|
name: queryRef.name,
|
|
263
290
|
variables: queryRef.variables,
|
|
264
|
-
refType:
|
|
291
|
+
refType: QUERY_STR
|
|
265
292
|
});
|
|
266
293
|
const trackedQuery = this._queries.get(key);
|
|
267
294
|
const subscription = {
|
|
@@ -310,7 +337,7 @@ class QueryManager {
|
|
|
310
337
|
const key = encoderImpl({
|
|
311
338
|
name: queryRef.name,
|
|
312
339
|
variables: queryRef.variables,
|
|
313
|
-
refType:
|
|
340
|
+
refType: QUERY_STR
|
|
314
341
|
});
|
|
315
342
|
const trackedQuery = this._queries.get(key);
|
|
316
343
|
const result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
|
|
@@ -347,52 +374,6 @@ function compareDates(str1, str2) {
|
|
|
347
374
|
return date1.getTime() < date2.getTime();
|
|
348
375
|
}
|
|
349
376
|
|
|
350
|
-
/**
|
|
351
|
-
* @license
|
|
352
|
-
* Copyright 2024 Google LLC
|
|
353
|
-
*
|
|
354
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
355
|
-
* you may not use this file except in compliance with the License.
|
|
356
|
-
* You may obtain a copy of the License at
|
|
357
|
-
*
|
|
358
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
359
|
-
*
|
|
360
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
361
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
362
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
363
|
-
* See the License for the specific language governing permissions and
|
|
364
|
-
* limitations under the License.
|
|
365
|
-
*/
|
|
366
|
-
const Code = {
|
|
367
|
-
OTHER: 'other',
|
|
368
|
-
ALREADY_INITIALIZED: 'already-initialized',
|
|
369
|
-
NOT_INITIALIZED: 'not-initialized',
|
|
370
|
-
NOT_SUPPORTED: 'not-supported',
|
|
371
|
-
INVALID_ARGUMENT: 'invalid-argument',
|
|
372
|
-
PARTIAL_ERROR: 'partial-error'
|
|
373
|
-
};
|
|
374
|
-
/** An error returned by a DataConnect operation. */
|
|
375
|
-
class DataConnectError extends FirebaseError {
|
|
376
|
-
/** @hideconstructor */
|
|
377
|
-
constructor(
|
|
378
|
-
/**
|
|
379
|
-
* The backend error code associated with this error.
|
|
380
|
-
*/
|
|
381
|
-
code,
|
|
382
|
-
/**
|
|
383
|
-
* A custom error description.
|
|
384
|
-
*/
|
|
385
|
-
message) {
|
|
386
|
-
super(code, message);
|
|
387
|
-
this.code = code;
|
|
388
|
-
this.message = message;
|
|
389
|
-
// HACK: We write a toString property directly because Error is not a real
|
|
390
|
-
// class and so inheritance does not work correctly. We could alternatively
|
|
391
|
-
// do the same "back-door inheritance" trick that FirebaseError does.
|
|
392
|
-
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
377
|
/**
|
|
397
378
|
* @license
|
|
398
379
|
* Copyright 2024 Google LLC
|
|
@@ -467,6 +448,8 @@ function dcFetch(url, body, { signal }, accessToken) {
|
|
|
467
448
|
method: 'POST',
|
|
468
449
|
headers,
|
|
469
450
|
signal
|
|
451
|
+
}).catch(err => {
|
|
452
|
+
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
|
|
470
453
|
})
|
|
471
454
|
.then(async (response) => {
|
|
472
455
|
let jsonResponse = null;
|
|
@@ -513,24 +496,24 @@ class RESTTransport {
|
|
|
513
496
|
var _a;
|
|
514
497
|
this.apiKey = apiKey;
|
|
515
498
|
this.authProvider = authProvider;
|
|
516
|
-
this.
|
|
517
|
-
this.
|
|
518
|
-
this.
|
|
519
|
-
this.
|
|
520
|
-
this.
|
|
521
|
-
this.
|
|
522
|
-
this.
|
|
499
|
+
this._host = '';
|
|
500
|
+
this._location = 'l';
|
|
501
|
+
this._connectorName = '';
|
|
502
|
+
this._secure = true;
|
|
503
|
+
this._project = 'p';
|
|
504
|
+
this._accessToken = null;
|
|
505
|
+
this._authInitialized = false;
|
|
523
506
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
524
507
|
this.invokeQuery = (queryName, body) => {
|
|
525
508
|
const abortController = new AbortController();
|
|
526
509
|
// TODO(mtewani): Update to proper value
|
|
527
510
|
const withAuth = this.getWithAuth().then(() => {
|
|
528
511
|
return dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
|
|
529
|
-
name: `projects/${this.
|
|
512
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
530
513
|
operationName: queryName,
|
|
531
514
|
variables: body
|
|
532
515
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
533
|
-
abortController, this.
|
|
516
|
+
abortController, this._accessToken);
|
|
534
517
|
});
|
|
535
518
|
return {
|
|
536
519
|
then: withAuth.then.bind(withAuth)
|
|
@@ -540,10 +523,10 @@ class RESTTransport {
|
|
|
540
523
|
const abortController = new AbortController();
|
|
541
524
|
const taskResult = this.getWithAuth().then(() => {
|
|
542
525
|
return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
|
|
543
|
-
name: `projects/${this.
|
|
526
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
544
527
|
operationName: mutationName,
|
|
545
528
|
variables: body
|
|
546
|
-
}, abortController, this.
|
|
529
|
+
}, abortController, this._accessToken);
|
|
547
530
|
});
|
|
548
531
|
return {
|
|
549
532
|
then: taskResult.then.bind(taskResult),
|
|
@@ -554,53 +537,53 @@ class RESTTransport {
|
|
|
554
537
|
};
|
|
555
538
|
if (transportOptions) {
|
|
556
539
|
if (typeof transportOptions.port === 'number') {
|
|
557
|
-
this.
|
|
540
|
+
this._port = transportOptions.port;
|
|
558
541
|
}
|
|
559
542
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
560
|
-
this.
|
|
543
|
+
this._secure = transportOptions.sslEnabled;
|
|
561
544
|
}
|
|
562
|
-
this.
|
|
545
|
+
this._host = transportOptions.host;
|
|
563
546
|
}
|
|
564
547
|
const { location, projectId: project, connector, service } = options;
|
|
565
548
|
if (location) {
|
|
566
|
-
this.
|
|
549
|
+
this._location = location;
|
|
567
550
|
}
|
|
568
551
|
if (project) {
|
|
569
|
-
this.
|
|
552
|
+
this._project = project;
|
|
570
553
|
}
|
|
571
|
-
this.
|
|
554
|
+
this._serviceName = service;
|
|
572
555
|
if (!connector) {
|
|
573
556
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
574
557
|
}
|
|
575
|
-
this.
|
|
558
|
+
this._connectorName = connector;
|
|
576
559
|
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
|
|
577
560
|
logDebug(`New Token Available: ${token}`);
|
|
578
|
-
this.
|
|
561
|
+
this._accessToken = token;
|
|
579
562
|
});
|
|
580
563
|
}
|
|
581
564
|
get endpointUrl() {
|
|
582
565
|
return urlBuilder({
|
|
583
|
-
connector: this.
|
|
584
|
-
location: this.
|
|
585
|
-
projectId: this.
|
|
586
|
-
service: this.
|
|
587
|
-
}, { host: this.
|
|
566
|
+
connector: this._connectorName,
|
|
567
|
+
location: this._location,
|
|
568
|
+
projectId: this._project,
|
|
569
|
+
service: this._serviceName
|
|
570
|
+
}, { host: this._host, sslEnabled: this._secure, port: this._port });
|
|
588
571
|
}
|
|
589
572
|
useEmulator(host, port, isSecure) {
|
|
590
|
-
this.
|
|
573
|
+
this._host = host;
|
|
591
574
|
if (typeof port === 'number') {
|
|
592
|
-
this.
|
|
575
|
+
this._port = port;
|
|
593
576
|
}
|
|
594
577
|
if (typeof isSecure !== 'undefined') {
|
|
595
|
-
this.
|
|
578
|
+
this._secure = isSecure;
|
|
596
579
|
}
|
|
597
580
|
}
|
|
598
581
|
onTokenChanged(newToken) {
|
|
599
|
-
this.
|
|
582
|
+
this._accessToken = newToken;
|
|
600
583
|
}
|
|
601
584
|
getWithAuth() {
|
|
602
|
-
let starterPromise = new Promise(resolve => resolve(this.
|
|
603
|
-
if (!this.
|
|
585
|
+
let starterPromise = new Promise(resolve => resolve(this._accessToken));
|
|
586
|
+
if (!this._authInitialized) {
|
|
604
587
|
if (this.authProvider) {
|
|
605
588
|
starterPromise = this.authProvider
|
|
606
589
|
.getToken(/*forceToken=*/ false)
|
|
@@ -608,8 +591,8 @@ class RESTTransport {
|
|
|
608
591
|
if (!data) {
|
|
609
592
|
return null;
|
|
610
593
|
}
|
|
611
|
-
this.
|
|
612
|
-
return this.
|
|
594
|
+
this._accessToken = data.accessToken;
|
|
595
|
+
return this._accessToken;
|
|
613
596
|
});
|
|
614
597
|
}
|
|
615
598
|
else {
|
|
@@ -641,18 +624,18 @@ function mutationRef(dcInstance, queryName, variables) {
|
|
|
641
624
|
const ref = {
|
|
642
625
|
dataConnect: dcInstance,
|
|
643
626
|
name: queryName,
|
|
644
|
-
refType:
|
|
627
|
+
refType: MUTATION_STR,
|
|
645
628
|
variables: variables
|
|
646
629
|
};
|
|
647
630
|
return ref;
|
|
648
631
|
}
|
|
649
632
|
class MutationManager {
|
|
650
|
-
constructor(
|
|
651
|
-
this.
|
|
633
|
+
constructor(_transport) {
|
|
634
|
+
this._transport = _transport;
|
|
652
635
|
this._inflight = [];
|
|
653
636
|
}
|
|
654
637
|
executeMutation(mutationRef) {
|
|
655
|
-
const result = this.
|
|
638
|
+
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
656
639
|
const withRefPromise = result.then(res => {
|
|
657
640
|
const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
658
641
|
return obj;
|
|
@@ -698,10 +681,12 @@ function parseOptions(fullHost) {
|
|
|
698
681
|
return { host, port, sslEnabled: isSecure };
|
|
699
682
|
}
|
|
700
683
|
class DataConnect {
|
|
701
|
-
constructor(app,
|
|
684
|
+
constructor(app,
|
|
685
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
686
|
+
dataConnectOptions, _authProvider) {
|
|
702
687
|
this.app = app;
|
|
703
688
|
this.dataConnectOptions = dataConnectOptions;
|
|
704
|
-
this.
|
|
689
|
+
this._authProvider = _authProvider;
|
|
705
690
|
this.isEmulator = false;
|
|
706
691
|
this.initialized = false;
|
|
707
692
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -709,7 +694,7 @@ class DataConnect {
|
|
|
709
694
|
if (host) {
|
|
710
695
|
logDebug('Found custom host. Using emulator');
|
|
711
696
|
this.isEmulator = true;
|
|
712
|
-
this.
|
|
697
|
+
this._transportOptions = parseOptions(host);
|
|
713
698
|
}
|
|
714
699
|
}
|
|
715
700
|
}
|
|
@@ -726,29 +711,27 @@ class DataConnect {
|
|
|
726
711
|
if (this.initialized) {
|
|
727
712
|
return;
|
|
728
713
|
}
|
|
729
|
-
if (this.
|
|
714
|
+
if (this._transportClass === undefined) {
|
|
730
715
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
731
|
-
this.
|
|
716
|
+
this._transportClass = RESTTransport;
|
|
732
717
|
}
|
|
733
|
-
if (this.
|
|
734
|
-
this.
|
|
735
|
-
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
|
|
736
|
-
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
|
|
718
|
+
if (this._authProvider) {
|
|
719
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
737
720
|
}
|
|
738
721
|
this.initialized = true;
|
|
739
|
-
this._transport = new this.
|
|
740
|
-
if (this.
|
|
741
|
-
this._transport.useEmulator(this.
|
|
722
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
|
|
723
|
+
if (this._transportOptions) {
|
|
724
|
+
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
742
725
|
}
|
|
743
726
|
this._queryManager = new QueryManager(this._transport);
|
|
744
727
|
this._mutationManager = new MutationManager(this._transport);
|
|
745
728
|
}
|
|
746
729
|
enableEmulator(transportOptions) {
|
|
747
730
|
if (this.initialized) {
|
|
748
|
-
logError('enableEmulator called
|
|
731
|
+
logError('enableEmulator called after initialization');
|
|
749
732
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
750
733
|
}
|
|
751
|
-
this.
|
|
734
|
+
this._transportOptions = transportOptions;
|
|
752
735
|
this.isEmulator = true;
|
|
753
736
|
}
|
|
754
737
|
}
|
|
@@ -791,7 +774,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
791
774
|
});
|
|
792
775
|
}
|
|
793
776
|
function terminate(dataConnect) {
|
|
794
|
-
dataConnect._delete();
|
|
777
|
+
return dataConnect._delete();
|
|
795
778
|
// TODO(mtewani): Stop pending tasks
|
|
796
779
|
}
|
|
797
780
|
|
|
@@ -851,7 +834,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
851
834
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
852
835
|
return {
|
|
853
836
|
dataConnect: dcInstance,
|
|
854
|
-
refType:
|
|
837
|
+
refType: QUERY_STR,
|
|
855
838
|
name: queryName,
|
|
856
839
|
variables: variables
|
|
857
840
|
};
|
|
@@ -881,7 +864,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
881
864
|
let ref;
|
|
882
865
|
let initialCache;
|
|
883
866
|
if ('refInfo' in queryRefOrSerializedResult) {
|
|
884
|
-
|
|
867
|
+
const serializedRef = queryRefOrSerializedResult;
|
|
885
868
|
const { data, source, fetchTime } = serializedRef;
|
|
886
869
|
initialCache = {
|
|
887
870
|
data,
|
|
@@ -913,27 +896,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
913
896
|
*
|
|
914
897
|
* @packageDocumentation
|
|
915
898
|
*/
|
|
916
|
-
registerDataConnect();
|
|
917
|
-
// import { getDataConnect, queryRef } from './api';
|
|
918
|
-
// import { getApp } from '@firebase/app';
|
|
919
|
-
// const app = getApp();
|
|
920
|
-
// const dc = getDataConnect({ location: '', connector: '', serviceId: '', projectId: '' });
|
|
921
|
-
// interface Response {
|
|
922
|
-
// name: string;
|
|
923
|
-
// }
|
|
924
|
-
// const converter: Converter<Response> = {
|
|
925
|
-
// fromDataConnect(input: string) {
|
|
926
|
-
// return { name: input };
|
|
927
|
-
// },
|
|
928
|
-
// fromType(input) {
|
|
929
|
-
// return input;
|
|
930
|
-
// }
|
|
931
|
-
// };
|
|
932
|
-
// const myRef = queryRef(dc, '', converter);
|
|
933
|
-
// // Ref's shouldn't have access to their own cache, right?
|
|
934
|
-
// const a = execute(myRef);
|
|
935
|
-
// subscribe(myRef, (res) => {
|
|
936
|
-
// })
|
|
899
|
+
registerDataConnect();
|
|
937
900
|
|
|
938
|
-
export { DataConnect,
|
|
901
|
+
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 };
|
|
939
902
|
//# sourceMappingURL=index.esm2017.js.map
|