@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
|
@@ -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.323fdc1b8";
|
|
|
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,33 +222,14 @@ 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
|
}
|
|
230
|
-
}
|
|
231
|
-
class EmulatorTokenProvider {
|
|
232
|
-
constructor(accessToken) {
|
|
233
|
-
this.accessToken = accessToken;
|
|
234
|
-
}
|
|
235
|
-
getToken(forceRefresh) {
|
|
236
|
-
return Promise.resolve({
|
|
237
|
-
accessToken: this.accessToken
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
addTokenChangeListener(listener) {
|
|
241
|
-
// Invoke the listener immediately to match the behavior in Firebase Auth
|
|
242
|
-
// (see packages/auth/src/auth.js#L1807)
|
|
243
|
-
listener(this.accessToken);
|
|
244
|
-
}
|
|
245
|
-
removeTokenChangeListener(listener) { }
|
|
246
|
-
notifyForInvalidToken() { }
|
|
247
|
-
}
|
|
248
|
-
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
|
|
249
|
-
EmulatorTokenProvider.OWNER = 'owner';
|
|
232
|
+
}
|
|
250
233
|
|
|
251
234
|
/**
|
|
252
235
|
* @license
|
|
@@ -264,8 +247,8 @@ EmulatorTokenProvider.OWNER = 'owner';
|
|
|
264
247
|
* See the License for the specific language governing permissions and
|
|
265
248
|
* limitations under the License.
|
|
266
249
|
*/
|
|
267
|
-
const
|
|
268
|
-
const
|
|
250
|
+
const QUERY_STR = 'query';
|
|
251
|
+
const MUTATION_STR = 'mutation';
|
|
269
252
|
const SOURCE_SERVER = 'SERVER';
|
|
270
253
|
const SOURCE_CACHE = 'CACHE';
|
|
271
254
|
|
|
@@ -352,7 +335,7 @@ class QueryManager {
|
|
|
352
335
|
const ref = {
|
|
353
336
|
name: queryName,
|
|
354
337
|
variables,
|
|
355
|
-
refType:
|
|
338
|
+
refType: QUERY_STR
|
|
356
339
|
};
|
|
357
340
|
const key = encoderImpl(ref);
|
|
358
341
|
const newTrackedQuery = {
|
|
@@ -369,7 +352,7 @@ class QueryManager {
|
|
|
369
352
|
const key = encoderImpl({
|
|
370
353
|
name: queryRef.name,
|
|
371
354
|
variables: queryRef.variables,
|
|
372
|
-
refType:
|
|
355
|
+
refType: QUERY_STR
|
|
373
356
|
});
|
|
374
357
|
const trackedQuery = this._queries.get(key);
|
|
375
358
|
const subscription = {
|
|
@@ -418,7 +401,7 @@ class QueryManager {
|
|
|
418
401
|
const key = encoderImpl({
|
|
419
402
|
name: queryRef.name,
|
|
420
403
|
variables: queryRef.variables,
|
|
421
|
-
refType:
|
|
404
|
+
refType: QUERY_STR
|
|
422
405
|
});
|
|
423
406
|
const trackedQuery = this._queries.get(key);
|
|
424
407
|
const result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
|
|
@@ -516,24 +499,24 @@ class RESTTransport {
|
|
|
516
499
|
var _a;
|
|
517
500
|
this.apiKey = apiKey;
|
|
518
501
|
this.authProvider = authProvider;
|
|
519
|
-
this.
|
|
520
|
-
this.
|
|
521
|
-
this.
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
525
|
-
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;
|
|
526
509
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
527
510
|
this.invokeQuery = (queryName, body) => {
|
|
528
511
|
const abortController = new AbortController();
|
|
529
512
|
// TODO(mtewani): Update to proper value
|
|
530
513
|
const withAuth = this.getWithAuth().then(() => {
|
|
531
514
|
return dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
|
|
532
|
-
name: `projects/${this.
|
|
515
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
533
516
|
operationName: queryName,
|
|
534
517
|
variables: body
|
|
535
518
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
536
|
-
abortController, this.
|
|
519
|
+
abortController, this._accessToken);
|
|
537
520
|
});
|
|
538
521
|
return {
|
|
539
522
|
then: withAuth.then.bind(withAuth)
|
|
@@ -543,10 +526,10 @@ class RESTTransport {
|
|
|
543
526
|
const abortController = new AbortController();
|
|
544
527
|
const taskResult = this.getWithAuth().then(() => {
|
|
545
528
|
return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
|
|
546
|
-
name: `projects/${this.
|
|
529
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
547
530
|
operationName: mutationName,
|
|
548
531
|
variables: body
|
|
549
|
-
}, abortController, this.
|
|
532
|
+
}, abortController, this._accessToken);
|
|
550
533
|
});
|
|
551
534
|
return {
|
|
552
535
|
then: taskResult.then.bind(taskResult),
|
|
@@ -557,53 +540,53 @@ class RESTTransport {
|
|
|
557
540
|
};
|
|
558
541
|
if (transportOptions) {
|
|
559
542
|
if (typeof transportOptions.port === 'number') {
|
|
560
|
-
this.
|
|
543
|
+
this._port = transportOptions.port;
|
|
561
544
|
}
|
|
562
545
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
563
|
-
this.
|
|
546
|
+
this._secure = transportOptions.sslEnabled;
|
|
564
547
|
}
|
|
565
|
-
this.
|
|
548
|
+
this._host = transportOptions.host;
|
|
566
549
|
}
|
|
567
550
|
const { location, projectId: project, connector, service } = options;
|
|
568
551
|
if (location) {
|
|
569
|
-
this.
|
|
552
|
+
this._location = location;
|
|
570
553
|
}
|
|
571
554
|
if (project) {
|
|
572
|
-
this.
|
|
555
|
+
this._project = project;
|
|
573
556
|
}
|
|
574
|
-
this.
|
|
557
|
+
this._serviceName = service;
|
|
575
558
|
if (!connector) {
|
|
576
559
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
577
560
|
}
|
|
578
|
-
this.
|
|
561
|
+
this._connectorName = connector;
|
|
579
562
|
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
|
|
580
563
|
logDebug(`New Token Available: ${token}`);
|
|
581
|
-
this.
|
|
564
|
+
this._accessToken = token;
|
|
582
565
|
});
|
|
583
566
|
}
|
|
584
567
|
get endpointUrl() {
|
|
585
568
|
return urlBuilder({
|
|
586
|
-
connector: this.
|
|
587
|
-
location: this.
|
|
588
|
-
projectId: this.
|
|
589
|
-
service: this.
|
|
590
|
-
}, { 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 });
|
|
591
574
|
}
|
|
592
575
|
useEmulator(host, port, isSecure) {
|
|
593
|
-
this.
|
|
576
|
+
this._host = host;
|
|
594
577
|
if (typeof port === 'number') {
|
|
595
|
-
this.
|
|
578
|
+
this._port = port;
|
|
596
579
|
}
|
|
597
580
|
if (typeof isSecure !== 'undefined') {
|
|
598
|
-
this.
|
|
581
|
+
this._secure = isSecure;
|
|
599
582
|
}
|
|
600
583
|
}
|
|
601
584
|
onTokenChanged(newToken) {
|
|
602
|
-
this.
|
|
585
|
+
this._accessToken = newToken;
|
|
603
586
|
}
|
|
604
587
|
getWithAuth() {
|
|
605
|
-
let starterPromise = new Promise(resolve => resolve(this.
|
|
606
|
-
if (!this.
|
|
588
|
+
let starterPromise = new Promise(resolve => resolve(this._accessToken));
|
|
589
|
+
if (!this._authInitialized) {
|
|
607
590
|
if (this.authProvider) {
|
|
608
591
|
starterPromise = this.authProvider
|
|
609
592
|
.getToken(/*forceToken=*/ false)
|
|
@@ -611,8 +594,8 @@ class RESTTransport {
|
|
|
611
594
|
if (!data) {
|
|
612
595
|
return null;
|
|
613
596
|
}
|
|
614
|
-
this.
|
|
615
|
-
return this.
|
|
597
|
+
this._accessToken = data.accessToken;
|
|
598
|
+
return this._accessToken;
|
|
616
599
|
});
|
|
617
600
|
}
|
|
618
601
|
else {
|
|
@@ -644,18 +627,18 @@ function mutationRef(dcInstance, queryName, variables) {
|
|
|
644
627
|
const ref = {
|
|
645
628
|
dataConnect: dcInstance,
|
|
646
629
|
name: queryName,
|
|
647
|
-
refType:
|
|
630
|
+
refType: MUTATION_STR,
|
|
648
631
|
variables: variables
|
|
649
632
|
};
|
|
650
633
|
return ref;
|
|
651
634
|
}
|
|
652
635
|
class MutationManager {
|
|
653
|
-
constructor(
|
|
654
|
-
this.
|
|
636
|
+
constructor(_transport) {
|
|
637
|
+
this._transport = _transport;
|
|
655
638
|
this._inflight = [];
|
|
656
639
|
}
|
|
657
640
|
executeMutation(mutationRef) {
|
|
658
|
-
const result = this.
|
|
641
|
+
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
659
642
|
const withRefPromise = result.then(res => {
|
|
660
643
|
const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
661
644
|
return obj;
|
|
@@ -701,10 +684,12 @@ function parseOptions(fullHost) {
|
|
|
701
684
|
return { host, port, sslEnabled: isSecure };
|
|
702
685
|
}
|
|
703
686
|
class DataConnect {
|
|
704
|
-
constructor(app,
|
|
687
|
+
constructor(app,
|
|
688
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
689
|
+
dataConnectOptions, _authProvider) {
|
|
705
690
|
this.app = app;
|
|
706
691
|
this.dataConnectOptions = dataConnectOptions;
|
|
707
|
-
this.
|
|
692
|
+
this._authProvider = _authProvider;
|
|
708
693
|
this.isEmulator = false;
|
|
709
694
|
this.initialized = false;
|
|
710
695
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -712,7 +697,7 @@ class DataConnect {
|
|
|
712
697
|
if (host) {
|
|
713
698
|
logDebug('Found custom host. Using emulator');
|
|
714
699
|
this.isEmulator = true;
|
|
715
|
-
this.
|
|
700
|
+
this._transportOptions = parseOptions(host);
|
|
716
701
|
}
|
|
717
702
|
}
|
|
718
703
|
}
|
|
@@ -729,29 +714,27 @@ class DataConnect {
|
|
|
729
714
|
if (this.initialized) {
|
|
730
715
|
return;
|
|
731
716
|
}
|
|
732
|
-
if (this.
|
|
717
|
+
if (this._transportClass === undefined) {
|
|
733
718
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
734
|
-
this.
|
|
719
|
+
this._transportClass = RESTTransport;
|
|
735
720
|
}
|
|
736
|
-
if (this.
|
|
737
|
-
this.
|
|
738
|
-
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
|
|
739
|
-
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
|
|
721
|
+
if (this._authProvider) {
|
|
722
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
740
723
|
}
|
|
741
724
|
this.initialized = true;
|
|
742
|
-
this._transport = new this.
|
|
743
|
-
if (this.
|
|
744
|
-
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);
|
|
745
728
|
}
|
|
746
729
|
this._queryManager = new QueryManager(this._transport);
|
|
747
730
|
this._mutationManager = new MutationManager(this._transport);
|
|
748
731
|
}
|
|
749
732
|
enableEmulator(transportOptions) {
|
|
750
733
|
if (this.initialized) {
|
|
751
|
-
logError('enableEmulator called
|
|
734
|
+
logError('enableEmulator called after initialization');
|
|
752
735
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
753
736
|
}
|
|
754
|
-
this.
|
|
737
|
+
this._transportOptions = transportOptions;
|
|
755
738
|
this.isEmulator = true;
|
|
756
739
|
}
|
|
757
740
|
}
|
|
@@ -794,7 +777,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
794
777
|
});
|
|
795
778
|
}
|
|
796
779
|
function terminate(dataConnect) {
|
|
797
|
-
dataConnect._delete();
|
|
780
|
+
return dataConnect._delete();
|
|
798
781
|
// TODO(mtewani): Stop pending tasks
|
|
799
782
|
}
|
|
800
783
|
|
|
@@ -854,7 +837,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
854
837
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
855
838
|
return {
|
|
856
839
|
dataConnect: dcInstance,
|
|
857
|
-
refType:
|
|
840
|
+
refType: QUERY_STR,
|
|
858
841
|
name: queryName,
|
|
859
842
|
variables: variables
|
|
860
843
|
};
|
|
@@ -884,7 +867,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
884
867
|
let ref;
|
|
885
868
|
let initialCache;
|
|
886
869
|
if ('refInfo' in queryRefOrSerializedResult) {
|
|
887
|
-
|
|
870
|
+
const serializedRef = queryRefOrSerializedResult;
|
|
888
871
|
const { data, source, fetchTime } = serializedRef;
|
|
889
872
|
initialCache = {
|
|
890
873
|
data,
|
|
@@ -930,5 +913,5 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
930
913
|
initializeFetch(fetch);
|
|
931
914
|
registerDataConnect('node');
|
|
932
915
|
|
|
933
|
-
export { DataConnect,
|
|
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 };
|
|
934
917
|
//# sourceMappingURL=index.node.esm.js.map
|