@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.cjs.js
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var app = require('@firebase/app');
|
|
6
6
|
var component = require('@firebase/component');
|
|
7
|
-
var logger$1 = require('@firebase/logger');
|
|
8
7
|
var util = require('@firebase/util');
|
|
8
|
+
var logger$1 = require('@firebase/logger');
|
|
9
9
|
|
|
10
10
|
const name = "@firebase/data-connect";
|
|
11
|
-
const version = "0.0.
|
|
11
|
+
const version = "0.0.2-dataconnect-preview.877f8b7d0";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @license
|
|
@@ -36,6 +36,52 @@ function setSDKVersion(version) {
|
|
|
36
36
|
SDK_VERSION = version;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @license
|
|
41
|
+
* Copyright 2024 Google LLC
|
|
42
|
+
*
|
|
43
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
44
|
+
* you may not use this file except in compliance with the License.
|
|
45
|
+
* You may obtain a copy of the License at
|
|
46
|
+
*
|
|
47
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
48
|
+
*
|
|
49
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
50
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
51
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
52
|
+
* See the License for the specific language governing permissions and
|
|
53
|
+
* limitations under the License.
|
|
54
|
+
*/
|
|
55
|
+
const Code = {
|
|
56
|
+
OTHER: 'other',
|
|
57
|
+
ALREADY_INITIALIZED: 'already-initialized',
|
|
58
|
+
NOT_INITIALIZED: 'not-initialized',
|
|
59
|
+
NOT_SUPPORTED: 'not-supported',
|
|
60
|
+
INVALID_ARGUMENT: 'invalid-argument',
|
|
61
|
+
PARTIAL_ERROR: 'partial-error'
|
|
62
|
+
};
|
|
63
|
+
/** An error returned by a DataConnect operation. */
|
|
64
|
+
class DataConnectError extends util.FirebaseError {
|
|
65
|
+
/** @hideconstructor */
|
|
66
|
+
constructor(
|
|
67
|
+
/**
|
|
68
|
+
* The backend error code associated with this error.
|
|
69
|
+
*/
|
|
70
|
+
code,
|
|
71
|
+
/**
|
|
72
|
+
* A custom error description.
|
|
73
|
+
*/
|
|
74
|
+
message) {
|
|
75
|
+
super(code, message);
|
|
76
|
+
this.code = code;
|
|
77
|
+
this.message = message;
|
|
78
|
+
// HACK: We write a toString property directly because Error is not a real
|
|
79
|
+
// class and so inheritance does not work correctly. We could alternatively
|
|
80
|
+
// do the same "back-door inheritance" trick that FirebaseError does.
|
|
81
|
+
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
39
85
|
/**
|
|
40
86
|
* @license
|
|
41
87
|
* Copyright 2024 Google LLC
|
|
@@ -80,20 +126,20 @@ function logError(msg) {
|
|
|
80
126
|
* limitations under the License.
|
|
81
127
|
*/
|
|
82
128
|
class FirebaseAuthProvider {
|
|
83
|
-
constructor(
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
87
|
-
this.
|
|
88
|
-
if (!this.
|
|
89
|
-
|
|
129
|
+
constructor(_appName, _options, _authProvider) {
|
|
130
|
+
this._appName = _appName;
|
|
131
|
+
this._options = _options;
|
|
132
|
+
this._authProvider = _authProvider;
|
|
133
|
+
this._auth = _authProvider.getImmediate({ optional: true });
|
|
134
|
+
if (!this._auth) {
|
|
135
|
+
_authProvider.onInit(auth => (this._auth = auth));
|
|
90
136
|
}
|
|
91
137
|
}
|
|
92
138
|
getToken(forceRefresh) {
|
|
93
|
-
if (!this.
|
|
139
|
+
if (!this._auth) {
|
|
94
140
|
return new Promise((resolve, reject) => {
|
|
95
141
|
setTimeout(() => {
|
|
96
|
-
if (this.
|
|
142
|
+
if (this._auth) {
|
|
97
143
|
this.getToken(forceRefresh).then(resolve, reject);
|
|
98
144
|
}
|
|
99
145
|
else {
|
|
@@ -102,7 +148,7 @@ class FirebaseAuthProvider {
|
|
|
102
148
|
}, 0);
|
|
103
149
|
});
|
|
104
150
|
}
|
|
105
|
-
return this.
|
|
151
|
+
return this._auth.getToken(forceRefresh).catch(error => {
|
|
106
152
|
if (error && error.code === 'auth/token-not-initialized') {
|
|
107
153
|
logDebug('Got auth/token-not-initialized error. Treating as null token.');
|
|
108
154
|
return null;
|
|
@@ -116,33 +162,14 @@ class FirebaseAuthProvider {
|
|
|
116
162
|
}
|
|
117
163
|
addTokenChangeListener(listener) {
|
|
118
164
|
var _a;
|
|
119
|
-
(_a = this.
|
|
165
|
+
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
|
|
120
166
|
}
|
|
121
167
|
removeTokenChangeListener(listener) {
|
|
122
|
-
this.
|
|
168
|
+
this._authProvider
|
|
123
169
|
.get()
|
|
124
170
|
.then(auth => auth.removeAuthTokenListener(listener));
|
|
125
171
|
}
|
|
126
|
-
}
|
|
127
|
-
class EmulatorTokenProvider {
|
|
128
|
-
constructor(accessToken) {
|
|
129
|
-
this.accessToken = accessToken;
|
|
130
|
-
}
|
|
131
|
-
getToken(forceRefresh) {
|
|
132
|
-
return Promise.resolve({
|
|
133
|
-
accessToken: this.accessToken
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
addTokenChangeListener(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
|
-
removeTokenChangeListener(listener) { }
|
|
142
|
-
notifyForInvalidToken() { }
|
|
143
|
-
}
|
|
144
|
-
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
|
|
145
|
-
EmulatorTokenProvider.OWNER = 'owner';
|
|
172
|
+
}
|
|
146
173
|
|
|
147
174
|
/**
|
|
148
175
|
* @license
|
|
@@ -160,8 +187,8 @@ EmulatorTokenProvider.OWNER = 'owner';
|
|
|
160
187
|
* See the License for the specific language governing permissions and
|
|
161
188
|
* limitations under the License.
|
|
162
189
|
*/
|
|
163
|
-
const
|
|
164
|
-
const
|
|
190
|
+
const QUERY_STR = 'query';
|
|
191
|
+
const MUTATION_STR = 'mutation';
|
|
165
192
|
const SOURCE_SERVER = 'SERVER';
|
|
166
193
|
const SOURCE_CACHE = 'CACHE';
|
|
167
194
|
|
|
@@ -248,7 +275,7 @@ class QueryManager {
|
|
|
248
275
|
const ref = {
|
|
249
276
|
name: queryName,
|
|
250
277
|
variables,
|
|
251
|
-
refType:
|
|
278
|
+
refType: QUERY_STR
|
|
252
279
|
};
|
|
253
280
|
const key = encoderImpl(ref);
|
|
254
281
|
const newTrackedQuery = {
|
|
@@ -265,7 +292,7 @@ class QueryManager {
|
|
|
265
292
|
const key = encoderImpl({
|
|
266
293
|
name: queryRef.name,
|
|
267
294
|
variables: queryRef.variables,
|
|
268
|
-
refType:
|
|
295
|
+
refType: QUERY_STR
|
|
269
296
|
});
|
|
270
297
|
const trackedQuery = this._queries.get(key);
|
|
271
298
|
const subscription = {
|
|
@@ -314,7 +341,7 @@ class QueryManager {
|
|
|
314
341
|
const key = encoderImpl({
|
|
315
342
|
name: queryRef.name,
|
|
316
343
|
variables: queryRef.variables,
|
|
317
|
-
refType:
|
|
344
|
+
refType: QUERY_STR
|
|
318
345
|
});
|
|
319
346
|
const trackedQuery = this._queries.get(key);
|
|
320
347
|
const result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
|
|
@@ -351,52 +378,6 @@ function compareDates(str1, str2) {
|
|
|
351
378
|
return date1.getTime() < date2.getTime();
|
|
352
379
|
}
|
|
353
380
|
|
|
354
|
-
/**
|
|
355
|
-
* @license
|
|
356
|
-
* Copyright 2024 Google LLC
|
|
357
|
-
*
|
|
358
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
359
|
-
* you may not use this file except in compliance with the License.
|
|
360
|
-
* You may obtain a copy of the License at
|
|
361
|
-
*
|
|
362
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
363
|
-
*
|
|
364
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
365
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
366
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
367
|
-
* See the License for the specific language governing permissions and
|
|
368
|
-
* limitations under the License.
|
|
369
|
-
*/
|
|
370
|
-
const Code = {
|
|
371
|
-
OTHER: 'other',
|
|
372
|
-
ALREADY_INITIALIZED: 'already-initialized',
|
|
373
|
-
NOT_INITIALIZED: 'not-initialized',
|
|
374
|
-
NOT_SUPPORTED: 'not-supported',
|
|
375
|
-
INVALID_ARGUMENT: 'invalid-argument',
|
|
376
|
-
PARTIAL_ERROR: 'partial-error'
|
|
377
|
-
};
|
|
378
|
-
/** An error returned by a DataConnect operation. */
|
|
379
|
-
class DataConnectError extends util.FirebaseError {
|
|
380
|
-
/** @hideconstructor */
|
|
381
|
-
constructor(
|
|
382
|
-
/**
|
|
383
|
-
* The backend error code associated with this error.
|
|
384
|
-
*/
|
|
385
|
-
code,
|
|
386
|
-
/**
|
|
387
|
-
* A custom error description.
|
|
388
|
-
*/
|
|
389
|
-
message) {
|
|
390
|
-
super(code, message);
|
|
391
|
-
this.code = code;
|
|
392
|
-
this.message = message;
|
|
393
|
-
// HACK: We write a toString property directly because Error is not a real
|
|
394
|
-
// class and so inheritance does not work correctly. We could alternatively
|
|
395
|
-
// do the same "back-door inheritance" trick that FirebaseError does.
|
|
396
|
-
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
381
|
/**
|
|
401
382
|
* @license
|
|
402
383
|
* Copyright 2024 Google LLC
|
|
@@ -471,6 +452,8 @@ function dcFetch(url, body, { signal }, accessToken) {
|
|
|
471
452
|
method: 'POST',
|
|
472
453
|
headers,
|
|
473
454
|
signal
|
|
455
|
+
}).catch(err => {
|
|
456
|
+
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
|
|
474
457
|
})
|
|
475
458
|
.then(async (response) => {
|
|
476
459
|
let jsonResponse = null;
|
|
@@ -517,24 +500,24 @@ class RESTTransport {
|
|
|
517
500
|
var _a;
|
|
518
501
|
this.apiKey = apiKey;
|
|
519
502
|
this.authProvider = authProvider;
|
|
520
|
-
this.
|
|
521
|
-
this.
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
525
|
-
this.
|
|
526
|
-
this.
|
|
503
|
+
this._host = '';
|
|
504
|
+
this._location = 'l';
|
|
505
|
+
this._connectorName = '';
|
|
506
|
+
this._secure = true;
|
|
507
|
+
this._project = 'p';
|
|
508
|
+
this._accessToken = null;
|
|
509
|
+
this._authInitialized = false;
|
|
527
510
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
528
511
|
this.invokeQuery = (queryName, body) => {
|
|
529
512
|
const abortController = new AbortController();
|
|
530
513
|
// TODO(mtewani): Update to proper value
|
|
531
514
|
const withAuth = this.getWithAuth().then(() => {
|
|
532
515
|
return dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
|
|
533
|
-
name: `projects/${this.
|
|
516
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
534
517
|
operationName: queryName,
|
|
535
518
|
variables: body
|
|
536
519
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
537
|
-
abortController, this.
|
|
520
|
+
abortController, this._accessToken);
|
|
538
521
|
});
|
|
539
522
|
return {
|
|
540
523
|
then: withAuth.then.bind(withAuth)
|
|
@@ -544,10 +527,10 @@ class RESTTransport {
|
|
|
544
527
|
const abortController = new AbortController();
|
|
545
528
|
const taskResult = this.getWithAuth().then(() => {
|
|
546
529
|
return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
|
|
547
|
-
name: `projects/${this.
|
|
530
|
+
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
548
531
|
operationName: mutationName,
|
|
549
532
|
variables: body
|
|
550
|
-
}, abortController, this.
|
|
533
|
+
}, abortController, this._accessToken);
|
|
551
534
|
});
|
|
552
535
|
return {
|
|
553
536
|
then: taskResult.then.bind(taskResult),
|
|
@@ -558,53 +541,53 @@ class RESTTransport {
|
|
|
558
541
|
};
|
|
559
542
|
if (transportOptions) {
|
|
560
543
|
if (typeof transportOptions.port === 'number') {
|
|
561
|
-
this.
|
|
544
|
+
this._port = transportOptions.port;
|
|
562
545
|
}
|
|
563
546
|
if (typeof transportOptions.sslEnabled !== 'undefined') {
|
|
564
|
-
this.
|
|
547
|
+
this._secure = transportOptions.sslEnabled;
|
|
565
548
|
}
|
|
566
|
-
this.
|
|
549
|
+
this._host = transportOptions.host;
|
|
567
550
|
}
|
|
568
551
|
const { location, projectId: project, connector, service } = options;
|
|
569
552
|
if (location) {
|
|
570
|
-
this.
|
|
553
|
+
this._location = location;
|
|
571
554
|
}
|
|
572
555
|
if (project) {
|
|
573
|
-
this.
|
|
556
|
+
this._project = project;
|
|
574
557
|
}
|
|
575
|
-
this.
|
|
558
|
+
this._serviceName = service;
|
|
576
559
|
if (!connector) {
|
|
577
560
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
|
|
578
561
|
}
|
|
579
|
-
this.
|
|
562
|
+
this._connectorName = connector;
|
|
580
563
|
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
|
|
581
564
|
logDebug(`New Token Available: ${token}`);
|
|
582
|
-
this.
|
|
565
|
+
this._accessToken = token;
|
|
583
566
|
});
|
|
584
567
|
}
|
|
585
568
|
get endpointUrl() {
|
|
586
569
|
return urlBuilder({
|
|
587
|
-
connector: this.
|
|
588
|
-
location: this.
|
|
589
|
-
projectId: this.
|
|
590
|
-
service: this.
|
|
591
|
-
}, { host: this.
|
|
570
|
+
connector: this._connectorName,
|
|
571
|
+
location: this._location,
|
|
572
|
+
projectId: this._project,
|
|
573
|
+
service: this._serviceName
|
|
574
|
+
}, { host: this._host, sslEnabled: this._secure, port: this._port });
|
|
592
575
|
}
|
|
593
576
|
useEmulator(host, port, isSecure) {
|
|
594
|
-
this.
|
|
577
|
+
this._host = host;
|
|
595
578
|
if (typeof port === 'number') {
|
|
596
|
-
this.
|
|
579
|
+
this._port = port;
|
|
597
580
|
}
|
|
598
581
|
if (typeof isSecure !== 'undefined') {
|
|
599
|
-
this.
|
|
582
|
+
this._secure = isSecure;
|
|
600
583
|
}
|
|
601
584
|
}
|
|
602
585
|
onTokenChanged(newToken) {
|
|
603
|
-
this.
|
|
586
|
+
this._accessToken = newToken;
|
|
604
587
|
}
|
|
605
588
|
getWithAuth() {
|
|
606
|
-
let starterPromise = new Promise(resolve => resolve(this.
|
|
607
|
-
if (!this.
|
|
589
|
+
let starterPromise = new Promise(resolve => resolve(this._accessToken));
|
|
590
|
+
if (!this._authInitialized) {
|
|
608
591
|
if (this.authProvider) {
|
|
609
592
|
starterPromise = this.authProvider
|
|
610
593
|
.getToken(/*forceToken=*/ false)
|
|
@@ -612,8 +595,8 @@ class RESTTransport {
|
|
|
612
595
|
if (!data) {
|
|
613
596
|
return null;
|
|
614
597
|
}
|
|
615
|
-
this.
|
|
616
|
-
return this.
|
|
598
|
+
this._accessToken = data.accessToken;
|
|
599
|
+
return this._accessToken;
|
|
617
600
|
});
|
|
618
601
|
}
|
|
619
602
|
else {
|
|
@@ -645,18 +628,18 @@ function mutationRef(dcInstance, queryName, variables) {
|
|
|
645
628
|
const ref = {
|
|
646
629
|
dataConnect: dcInstance,
|
|
647
630
|
name: queryName,
|
|
648
|
-
refType:
|
|
631
|
+
refType: MUTATION_STR,
|
|
649
632
|
variables: variables
|
|
650
633
|
};
|
|
651
634
|
return ref;
|
|
652
635
|
}
|
|
653
636
|
class MutationManager {
|
|
654
|
-
constructor(
|
|
655
|
-
this.
|
|
637
|
+
constructor(_transport) {
|
|
638
|
+
this._transport = _transport;
|
|
656
639
|
this._inflight = [];
|
|
657
640
|
}
|
|
658
641
|
executeMutation(mutationRef) {
|
|
659
|
-
const result = this.
|
|
642
|
+
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
|
|
660
643
|
const withRefPromise = result.then(res => {
|
|
661
644
|
const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
|
|
662
645
|
return obj;
|
|
@@ -702,10 +685,12 @@ function parseOptions(fullHost) {
|
|
|
702
685
|
return { host, port, sslEnabled: isSecure };
|
|
703
686
|
}
|
|
704
687
|
class DataConnect {
|
|
705
|
-
constructor(app,
|
|
688
|
+
constructor(app,
|
|
689
|
+
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
690
|
+
dataConnectOptions, _authProvider) {
|
|
706
691
|
this.app = app;
|
|
707
692
|
this.dataConnectOptions = dataConnectOptions;
|
|
708
|
-
this.
|
|
693
|
+
this._authProvider = _authProvider;
|
|
709
694
|
this.isEmulator = false;
|
|
710
695
|
this.initialized = false;
|
|
711
696
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -713,7 +698,7 @@ class DataConnect {
|
|
|
713
698
|
if (host) {
|
|
714
699
|
logDebug('Found custom host. Using emulator');
|
|
715
700
|
this.isEmulator = true;
|
|
716
|
-
this.
|
|
701
|
+
this._transportOptions = parseOptions(host);
|
|
717
702
|
}
|
|
718
703
|
}
|
|
719
704
|
}
|
|
@@ -730,29 +715,27 @@ class DataConnect {
|
|
|
730
715
|
if (this.initialized) {
|
|
731
716
|
return;
|
|
732
717
|
}
|
|
733
|
-
if (this.
|
|
718
|
+
if (this._transportClass === undefined) {
|
|
734
719
|
logDebug('transportClass not provided. Defaulting to RESTTransport.');
|
|
735
|
-
this.
|
|
720
|
+
this._transportClass = RESTTransport;
|
|
736
721
|
}
|
|
737
|
-
if (this.
|
|
738
|
-
this.
|
|
739
|
-
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
|
|
740
|
-
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
|
|
722
|
+
if (this._authProvider) {
|
|
723
|
+
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
741
724
|
}
|
|
742
725
|
this.initialized = true;
|
|
743
|
-
this._transport = new this.
|
|
744
|
-
if (this.
|
|
745
|
-
this._transport.useEmulator(this.
|
|
726
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
|
|
727
|
+
if (this._transportOptions) {
|
|
728
|
+
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
746
729
|
}
|
|
747
730
|
this._queryManager = new QueryManager(this._transport);
|
|
748
731
|
this._mutationManager = new MutationManager(this._transport);
|
|
749
732
|
}
|
|
750
733
|
enableEmulator(transportOptions) {
|
|
751
734
|
if (this.initialized) {
|
|
752
|
-
logError('enableEmulator called
|
|
735
|
+
logError('enableEmulator called after initialization');
|
|
753
736
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
754
737
|
}
|
|
755
|
-
this.
|
|
738
|
+
this._transportOptions = transportOptions;
|
|
756
739
|
this.isEmulator = true;
|
|
757
740
|
}
|
|
758
741
|
}
|
|
@@ -795,7 +778,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
795
778
|
});
|
|
796
779
|
}
|
|
797
780
|
function terminate(dataConnect) {
|
|
798
|
-
dataConnect._delete();
|
|
781
|
+
return dataConnect._delete();
|
|
799
782
|
// TODO(mtewani): Stop pending tasks
|
|
800
783
|
}
|
|
801
784
|
|
|
@@ -855,7 +838,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
855
838
|
dcInstance._queryManager.track(queryName, variables, initialCache);
|
|
856
839
|
return {
|
|
857
840
|
dataConnect: dcInstance,
|
|
858
|
-
refType:
|
|
841
|
+
refType: QUERY_STR,
|
|
859
842
|
name: queryName,
|
|
860
843
|
variables: variables
|
|
861
844
|
};
|
|
@@ -885,7 +868,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
885
868
|
let ref;
|
|
886
869
|
let initialCache;
|
|
887
870
|
if ('refInfo' in queryRefOrSerializedResult) {
|
|
888
|
-
|
|
871
|
+
const serializedRef = queryRefOrSerializedResult;
|
|
889
872
|
const { data, source, fetchTime } = serializedRef;
|
|
890
873
|
initialCache = {
|
|
891
874
|
data,
|
|
@@ -917,35 +900,14 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
917
900
|
*
|
|
918
901
|
* @packageDocumentation
|
|
919
902
|
*/
|
|
920
|
-
registerDataConnect();
|
|
921
|
-
// import { getDataConnect, queryRef } from './api';
|
|
922
|
-
// import { getApp } from '@firebase/app';
|
|
923
|
-
// const app = getApp();
|
|
924
|
-
// const dc = getDataConnect({ location: '', connector: '', serviceId: '', projectId: '' });
|
|
925
|
-
// interface Response {
|
|
926
|
-
// name: string;
|
|
927
|
-
// }
|
|
928
|
-
// const converter: Converter<Response> = {
|
|
929
|
-
// fromDataConnect(input: string) {
|
|
930
|
-
// return { name: input };
|
|
931
|
-
// },
|
|
932
|
-
// fromType(input) {
|
|
933
|
-
// return input;
|
|
934
|
-
// }
|
|
935
|
-
// };
|
|
936
|
-
// const myRef = queryRef(dc, '', converter);
|
|
937
|
-
// // Ref's shouldn't have access to their own cache, right?
|
|
938
|
-
// const a = execute(myRef);
|
|
939
|
-
// subscribe(myRef, (res) => {
|
|
940
|
-
// })
|
|
903
|
+
registerDataConnect();
|
|
941
904
|
|
|
942
905
|
exports.DataConnect = DataConnect;
|
|
943
|
-
exports.EmulatorTokenProvider = EmulatorTokenProvider;
|
|
944
906
|
exports.FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR;
|
|
945
907
|
exports.FirebaseAuthProvider = FirebaseAuthProvider;
|
|
908
|
+
exports.MUTATION_STR = MUTATION_STR;
|
|
946
909
|
exports.MutationManager = MutationManager;
|
|
947
|
-
exports.
|
|
948
|
-
exports.QueryStr = QueryStr;
|
|
910
|
+
exports.QUERY_STR = QUERY_STR;
|
|
949
911
|
exports.SOURCE_CACHE = SOURCE_CACHE;
|
|
950
912
|
exports.SOURCE_SERVER = SOURCE_SERVER;
|
|
951
913
|
exports.connectDataConnectEmulator = connectDataConnectEmulator;
|