New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@firebase/data-connect

Package Overview
Dependencies
Maintainers
4
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/data-connect - npm Package Compare versions

Comparing version 0.0.1-dataconnect-preview.f2ddc3d7b to 0.0.2-dataconnect-preview.877f8b7d0

293

dist/index.cjs.js

@@ -7,7 +7,7 @@ 'use strict';

var component = require('@firebase/component');
var util = require('@firebase/util');
var logger$1 = require('@firebase/logger');
var util = require('@firebase/util');
const name = "@firebase/data-connect";
const version = "0.0.1";
const version = "0.0.2-dataconnect-preview.877f8b7d0";

@@ -56,2 +56,48 @@ /**

*/
const Code = {
OTHER: 'other',
ALREADY_INITIALIZED: 'already-initialized',
NOT_INITIALIZED: 'not-initialized',
NOT_SUPPORTED: 'not-supported',
INVALID_ARGUMENT: 'invalid-argument',
PARTIAL_ERROR: 'partial-error'
};
/** An error returned by a DataConnect operation. */
class DataConnectError extends util.FirebaseError {
/** @hideconstructor */
constructor(
/**
* The backend error code associated with this error.
*/
code,
/**
* A custom error description.
*/
message) {
super(code, message);
this.code = code;
this.message = message;
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
}
}
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const logger = new logger$1.Logger('@firebase/data-connect');

@@ -62,10 +108,6 @@ function setLogLevel(logLevel) {

function logDebug(msg) {
// if (logger.logLevel <= LogLevel.DEBUG) {
logger.debug(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}
function logError(msg) {
// if (logger.logLevel <= LogLevel.ERROR) {
logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}

@@ -90,16 +132,16 @@

class FirebaseAuthProvider {
constructor(appName, options, authProvider_) {
this.appName = appName;
this.options = options;
this.authProvider_ = authProvider_;
this.auth_ = authProvider_.getImmediate({ optional: true });
if (!this.auth_) {
authProvider_.onInit(auth => (this.auth_ = auth));
constructor(_appName, _options, _authProvider) {
this._appName = _appName;
this._options = _options;
this._authProvider = _authProvider;
this._auth = _authProvider.getImmediate({ optional: true });
if (!this._auth) {
_authProvider.onInit(auth => (this._auth = auth));
}
}
getToken(forceRefresh) {
if (!this.auth_) {
if (!this._auth) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (this.auth_) {
if (this._auth) {
this.getToken(forceRefresh).then(resolve, reject);

@@ -113,3 +155,3 @@ }

}
return this.auth_.getToken(forceRefresh).catch(error => {
return this._auth.getToken(forceRefresh).catch(error => {
if (error && error.code === 'auth/token-not-initialized') {

@@ -128,6 +170,6 @@ logDebug('Got auth/token-not-initialized error. Treating as null token.');

var _a;
(_a = this.auth_) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
}
removeTokenChangeListener(listener) {
this.authProvider_
this._authProvider
.get()

@@ -137,21 +179,2 @@ .then(auth => auth.removeAuthTokenListener(listener));

}
class EmulatorTokenProvider {
constructor(accessToken) {
this.accessToken = accessToken;
}
getToken(forceRefresh) {
return Promise.resolve({
accessToken: this.accessToken
});
}
addTokenChangeListener(listener) {
// Invoke the listener immediately to match the behavior in Firebase Auth
// (see packages/auth/src/auth.js#L1807)
listener(this.accessToken);
}
removeTokenChangeListener(listener) { }
notifyForInvalidToken() { }
}
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
EmulatorTokenProvider.OWNER = 'owner';

@@ -174,4 +197,4 @@ /**

*/
const QueryStr = 'query';
const MutationStr = 'mutation';
const QUERY_STR = 'query';
const MUTATION_STR = 'mutation';
const SOURCE_SERVER = 'SERVER';

@@ -263,3 +286,3 @@ const SOURCE_CACHE = 'CACHE';

variables,
refType: QueryStr
refType: QUERY_STR
};

@@ -281,3 +304,3 @@ const key = encoderImpl(ref);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -331,3 +354,3 @@ const trackedQuery = this._queries.get(key);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -385,48 +408,2 @@ const trackedQuery = this._queries.get(key);

*/
const Code = {
OTHER: 'other',
ALREADY_INITIALIZED: 'already-initialized',
NOT_INITIALIZED: 'not-initialized',
NOT_SUPPORTED: 'not-supported',
INVALID_ARGUMENT: 'invalid-argument',
PARTIAL_ERROR: 'partial-error'
};
/** An error returned by a DataConnect operation. */
class DataConnectError extends util.FirebaseError {
/** @hideconstructor */
constructor(
/**
* The backend error code associated with this error.
*/
code,
/**
* A custom error description.
*/
message) {
super(code, message);
this.code = code;
this.message = message;
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
}
}
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function urlBuilder(projectConfig, transportOptions) {

@@ -490,2 +467,4 @@ const { connector, location, projectId: project, service } = projectConfig;

signal
}).catch(err => {
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
})

@@ -534,11 +513,12 @@ .then(async (response) => {

constructor(options, apiKey, authProvider, transportOptions) {
var _a;
this.apiKey = apiKey;
this.authProvider = authProvider;
this.host = '';
this.location = 'l';
this.connectorName = '';
this.secure = true;
this.project = 'p';
this.accessToken = null;
this.authInitialized_ = false;
this._host = '';
this._location = 'l';
this._connectorName = '';
this._secure = true;
this._project = 'p';
this._accessToken = null;
this._authInitialized = false;
// TODO(mtewani): Update U to include shape of body defined in line 13.

@@ -550,7 +530,7 @@ this.invokeQuery = (queryName, body) => {

return dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
name: `projects/${this.project}/locations/${this.location}/services/${this.serviceName}/connectors/${this.connectorName}`,
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: queryName,
variables: body
}, // TODO(mtewani): This is a patch, fix this.
abortController, this.accessToken);
abortController, this._accessToken);
});

@@ -565,6 +545,6 @@ return {

return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
name: `projects/${this.project}/locations/${this.location}/services/${this.serviceName}/connectors/${this.connectorName}`,
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: mutationName,
variables: body
}, abortController, this.accessToken);
}, abortController, this._accessToken);
});

@@ -580,45 +560,49 @@ return {

if (typeof transportOptions.port === 'number') {
this.port = transportOptions.port;
this._port = transportOptions.port;
}
if (typeof transportOptions.sslEnabled !== 'undefined') {
this.secure = transportOptions.sslEnabled;
this._secure = transportOptions.sslEnabled;
}
this.host = transportOptions.host;
this._host = transportOptions.host;
}
const { location, projectId: project, connector, service } = options;
if (location) {
this.location = location;
this._location = location;
}
if (project) {
this.project = project;
this._project = project;
}
this.serviceName = service;
this._serviceName = service;
if (!connector) {
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
}
this.connectorName = connector;
this._connectorName = connector;
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
logDebug(`New Token Available: ${token}`);
this._accessToken = token;
});
}
get endpointUrl() {
return urlBuilder({
connector: this.connectorName,
location: this.location,
projectId: this.project,
service: this.serviceName
}, { host: this.host, sslEnabled: this.secure, port: this.port });
connector: this._connectorName,
location: this._location,
projectId: this._project,
service: this._serviceName
}, { host: this._host, sslEnabled: this._secure, port: this._port });
}
useEmulator(host, port, isSecure) {
this.host = host;
this._host = host;
if (typeof port === 'number') {
this.port = port;
this._port = port;
}
if (typeof isSecure !== 'undefined') {
this.secure = isSecure;
this._secure = isSecure;
}
}
onTokenChanged(newToken) {
this.accessToken = newToken;
this._accessToken = newToken;
}
getWithAuth() {
let starterPromise = new Promise(resolve => resolve(this.accessToken));
if (!this.authInitialized_) {
let starterPromise = new Promise(resolve => resolve(this._accessToken));
if (!this._authInitialized) {
if (this.authProvider) {

@@ -631,4 +615,4 @@ starterPromise = this.authProvider

}
this.accessToken = data.accessToken;
return this.accessToken;
this._accessToken = data.accessToken;
return this._accessToken;
});

@@ -665,3 +649,3 @@ }

name: queryName,
refType: MutationStr,
refType: MUTATION_STR,
variables: variables

@@ -672,8 +656,8 @@ };

class MutationManager {
constructor(transport) {
this.transport = transport;
constructor(_transport) {
this._transport = _transport;
this._inflight = [];
}
executeMutation(mutationRef) {
const result = this.transport.invokeMutation(mutationRef.name, mutationRef.variables);
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
const withRefPromise = result.then(res => {

@@ -724,6 +708,8 @@ const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });

class DataConnect {
constructor(app, dataConnectOptions, authProvider) {
constructor(app,
// TODO(mtewani): Replace with _dataConnectOptions in the future
dataConnectOptions, _authProvider) {
this.app = app;
this.dataConnectOptions = dataConnectOptions;
this.authProvider = authProvider;
this._authProvider = _authProvider;
this.isEmulator = false;

@@ -736,3 +722,3 @@ this.initialized = false;

this.isEmulator = true;
this.transportOptions = parseOptions(host);
this._transportOptions = parseOptions(host);
}

@@ -754,19 +740,13 @@ }

}
if (this.transportClass === undefined) {
if (this._transportClass === undefined) {
logDebug('transportClass not provided. Defaulting to RESTTransport.');
this.transportClass = RESTTransport;
this._transportClass = RESTTransport;
}
if (this.authProvider) {
this.authTokenProvider = this.isEmulator
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
this.authTokenProvider.addTokenChangeListener(token => {
logDebug(`New Token Available: ${token}`);
this._transport.onTokenChanged(token);
});
if (this._authProvider) {
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
}
this.initialized = true;
this._transport = new this.transportClass(this.dataConnectOptions, this.app.options.apiKey, this.authTokenProvider);
if (this.transportOptions) {
this._transport.useEmulator(this.transportOptions.host, this.transportOptions.port, this.transportOptions.sslEnabled);
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
if (this._transportOptions) {
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
}

@@ -778,6 +758,6 @@ this._queryManager = new QueryManager(this._transport);

if (this.initialized) {
logError('enableEmulator called without initializing');
logError('enableEmulator called after initialization');
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
}
this.transportOptions = transportOptions;
this._transportOptions = transportOptions;
this.isEmulator = true;

@@ -825,3 +805,3 @@ }

function terminate(dataConnect) {
dataConnect._delete();
return dataConnect._delete();
// TODO(mtewani): Stop pending tasks

@@ -886,3 +866,3 @@ }

dataConnect: dcInstance,
refType: QueryStr,
refType: QUERY_STR,
name: queryName,

@@ -917,3 +897,3 @@ variables: variables

if ('refInfo' in queryRefOrSerializedResult) {
let serializedRef = queryRefOrSerializedResult;
const serializedRef = queryRefOrSerializedResult;
const { data, source, fetchTime } = serializedRef;

@@ -951,30 +931,9 @@ initialCache = {

registerDataConnect();
// import { getDataConnect, queryRef } from './api';
// import { getApp } from '@firebase/app';
// const app = getApp();
// const dc = getDataConnect({ location: '', connector: '', serviceId: '', projectId: '' });
// interface Response {
// name: string;
// }
// const converter: Converter<Response> = {
// fromDataConnect(input: string) {
// return { name: input };
// },
// fromType(input) {
// return input;
// }
// };
// const myRef = queryRef(dc, '', converter);
// // Ref's shouldn't have access to their own cache, right?
// const a = execute(myRef);
// subscribe(myRef, (res) => {
// })
exports.DataConnect = DataConnect;
exports.EmulatorTokenProvider = EmulatorTokenProvider;
exports.FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR;
exports.FirebaseAuthProvider = FirebaseAuthProvider;
exports.MUTATION_STR = MUTATION_STR;
exports.MutationManager = MutationManager;
exports.MutationStr = MutationStr;
exports.QueryStr = QueryStr;
exports.QUERY_STR = QUERY_STR;
exports.SOURCE_CACHE = SOURCE_CACHE;

@@ -981,0 +940,0 @@ exports.SOURCE_SERVER = SOURCE_SERVER;

import { _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
import { Component } from '@firebase/component';
import { FirebaseError } from '@firebase/util';
import { Logger } from '@firebase/logger';
import { FirebaseError } from '@firebase/util';
const name = "@firebase/data-connect";
const version = "0.0.1";
const version = "0.0.2-dataconnect-preview.877f8b7d0";

@@ -51,2 +51,48 @@ /**

*/
const Code = {
OTHER: 'other',
ALREADY_INITIALIZED: 'already-initialized',
NOT_INITIALIZED: 'not-initialized',
NOT_SUPPORTED: 'not-supported',
INVALID_ARGUMENT: 'invalid-argument',
PARTIAL_ERROR: 'partial-error'
};
/** An error returned by a DataConnect operation. */
class DataConnectError extends FirebaseError {
/** @hideconstructor */
constructor(
/**
* The backend error code associated with this error.
*/
code,
/**
* A custom error description.
*/
message) {
super(code, message);
this.code = code;
this.message = message;
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
}
}
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const logger = new Logger('@firebase/data-connect');

@@ -57,10 +103,6 @@ function setLogLevel(logLevel) {

function logDebug(msg) {
// if (logger.logLevel <= LogLevel.DEBUG) {
logger.debug(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}
function logError(msg) {
// if (logger.logLevel <= LogLevel.ERROR) {
logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}

@@ -85,16 +127,16 @@

class FirebaseAuthProvider {
constructor(appName, options, authProvider_) {
this.appName = appName;
this.options = options;
this.authProvider_ = authProvider_;
this.auth_ = authProvider_.getImmediate({ optional: true });
if (!this.auth_) {
authProvider_.onInit(auth => (this.auth_ = auth));
constructor(_appName, _options, _authProvider) {
this._appName = _appName;
this._options = _options;
this._authProvider = _authProvider;
this._auth = _authProvider.getImmediate({ optional: true });
if (!this._auth) {
_authProvider.onInit(auth => (this._auth = auth));
}
}
getToken(forceRefresh) {
if (!this.auth_) {
if (!this._auth) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (this.auth_) {
if (this._auth) {
this.getToken(forceRefresh).then(resolve, reject);

@@ -108,3 +150,3 @@ }

}
return this.auth_.getToken(forceRefresh).catch(error => {
return this._auth.getToken(forceRefresh).catch(error => {
if (error && error.code === 'auth/token-not-initialized') {

@@ -123,6 +165,6 @@ logDebug('Got auth/token-not-initialized error. Treating as null token.');

var _a;
(_a = this.auth_) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
}
removeTokenChangeListener(listener) {
this.authProvider_
this._authProvider
.get()

@@ -132,21 +174,2 @@ .then(auth => auth.removeAuthTokenListener(listener));

}
class EmulatorTokenProvider {
constructor(accessToken) {
this.accessToken = accessToken;
}
getToken(forceRefresh) {
return Promise.resolve({
accessToken: this.accessToken
});
}
addTokenChangeListener(listener) {
// Invoke the listener immediately to match the behavior in Firebase Auth
// (see packages/auth/src/auth.js#L1807)
listener(this.accessToken);
}
removeTokenChangeListener(listener) { }
notifyForInvalidToken() { }
}
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
EmulatorTokenProvider.OWNER = 'owner';

@@ -169,4 +192,4 @@ /**

*/
const QueryStr = 'query';
const MutationStr = 'mutation';
const QUERY_STR = 'query';
const MUTATION_STR = 'mutation';
const SOURCE_SERVER = 'SERVER';

@@ -258,3 +281,3 @@ const SOURCE_CACHE = 'CACHE';

variables,
refType: QueryStr
refType: QUERY_STR
};

@@ -276,3 +299,3 @@ const key = encoderImpl(ref);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -326,3 +349,3 @@ const trackedQuery = this._queries.get(key);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -380,48 +403,2 @@ const trackedQuery = this._queries.get(key);

*/
const Code = {
OTHER: 'other',
ALREADY_INITIALIZED: 'already-initialized',
NOT_INITIALIZED: 'not-initialized',
NOT_SUPPORTED: 'not-supported',
INVALID_ARGUMENT: 'invalid-argument',
PARTIAL_ERROR: 'partial-error'
};
/** An error returned by a DataConnect operation. */
class DataConnectError extends FirebaseError {
/** @hideconstructor */
constructor(
/**
* The backend error code associated with this error.
*/
code,
/**
* A custom error description.
*/
message) {
super(code, message);
this.code = code;
this.message = message;
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
}
}
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function urlBuilder(projectConfig, transportOptions) {

@@ -485,2 +462,4 @@ const { connector, location, projectId: project, service } = projectConfig;

signal
}).catch(err => {
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
})

@@ -529,11 +508,12 @@ .then(async (response) => {

constructor(options, apiKey, authProvider, transportOptions) {
var _a;
this.apiKey = apiKey;
this.authProvider = authProvider;
this.host = '';
this.location = 'l';
this.connectorName = '';
this.secure = true;
this.project = 'p';
this.accessToken = null;
this.authInitialized_ = false;
this._host = '';
this._location = 'l';
this._connectorName = '';
this._secure = true;
this._project = 'p';
this._accessToken = null;
this._authInitialized = false;
// TODO(mtewani): Update U to include shape of body defined in line 13.

@@ -545,7 +525,7 @@ this.invokeQuery = (queryName, body) => {

return dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
name: `projects/${this.project}/locations/${this.location}/services/${this.serviceName}/connectors/${this.connectorName}`,
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: queryName,
variables: body
}, // TODO(mtewani): This is a patch, fix this.
abortController, this.accessToken);
abortController, this._accessToken);
});

@@ -560,6 +540,6 @@ return {

return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
name: `projects/${this.project}/locations/${this.location}/services/${this.serviceName}/connectors/${this.connectorName}`,
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: mutationName,
variables: body
}, abortController, this.accessToken);
}, abortController, this._accessToken);
});

@@ -575,45 +555,49 @@ return {

if (typeof transportOptions.port === 'number') {
this.port = transportOptions.port;
this._port = transportOptions.port;
}
if (typeof transportOptions.sslEnabled !== 'undefined') {
this.secure = transportOptions.sslEnabled;
this._secure = transportOptions.sslEnabled;
}
this.host = transportOptions.host;
this._host = transportOptions.host;
}
const { location, projectId: project, connector, service } = options;
if (location) {
this.location = location;
this._location = location;
}
if (project) {
this.project = project;
this._project = project;
}
this.serviceName = service;
this._serviceName = service;
if (!connector) {
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
}
this.connectorName = connector;
this._connectorName = connector;
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
logDebug(`New Token Available: ${token}`);
this._accessToken = token;
});
}
get endpointUrl() {
return urlBuilder({
connector: this.connectorName,
location: this.location,
projectId: this.project,
service: this.serviceName
}, { host: this.host, sslEnabled: this.secure, port: this.port });
connector: this._connectorName,
location: this._location,
projectId: this._project,
service: this._serviceName
}, { host: this._host, sslEnabled: this._secure, port: this._port });
}
useEmulator(host, port, isSecure) {
this.host = host;
this._host = host;
if (typeof port === 'number') {
this.port = port;
this._port = port;
}
if (typeof isSecure !== 'undefined') {
this.secure = isSecure;
this._secure = isSecure;
}
}
onTokenChanged(newToken) {
this.accessToken = newToken;
this._accessToken = newToken;
}
getWithAuth() {
let starterPromise = new Promise(resolve => resolve(this.accessToken));
if (!this.authInitialized_) {
let starterPromise = new Promise(resolve => resolve(this._accessToken));
if (!this._authInitialized) {
if (this.authProvider) {

@@ -626,4 +610,4 @@ starterPromise = this.authProvider

}
this.accessToken = data.accessToken;
return this.accessToken;
this._accessToken = data.accessToken;
return this._accessToken;
});

@@ -660,3 +644,3 @@ }

name: queryName,
refType: MutationStr,
refType: MUTATION_STR,
variables: variables

@@ -667,8 +651,8 @@ };

class MutationManager {
constructor(transport) {
this.transport = transport;
constructor(_transport) {
this._transport = _transport;
this._inflight = [];
}
executeMutation(mutationRef) {
const result = this.transport.invokeMutation(mutationRef.name, mutationRef.variables);
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
const withRefPromise = result.then(res => {

@@ -719,6 +703,8 @@ const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });

class DataConnect {
constructor(app, dataConnectOptions, authProvider) {
constructor(app,
// TODO(mtewani): Replace with _dataConnectOptions in the future
dataConnectOptions, _authProvider) {
this.app = app;
this.dataConnectOptions = dataConnectOptions;
this.authProvider = authProvider;
this._authProvider = _authProvider;
this.isEmulator = false;

@@ -731,3 +717,3 @@ this.initialized = false;

this.isEmulator = true;
this.transportOptions = parseOptions(host);
this._transportOptions = parseOptions(host);
}

@@ -749,19 +735,13 @@ }

}
if (this.transportClass === undefined) {
if (this._transportClass === undefined) {
logDebug('transportClass not provided. Defaulting to RESTTransport.');
this.transportClass = RESTTransport;
this._transportClass = RESTTransport;
}
if (this.authProvider) {
this.authTokenProvider = this.isEmulator
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
this.authTokenProvider.addTokenChangeListener(token => {
logDebug(`New Token Available: ${token}`);
this._transport.onTokenChanged(token);
});
if (this._authProvider) {
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
}
this.initialized = true;
this._transport = new this.transportClass(this.dataConnectOptions, this.app.options.apiKey, this.authTokenProvider);
if (this.transportOptions) {
this._transport.useEmulator(this.transportOptions.host, this.transportOptions.port, this.transportOptions.sslEnabled);
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
if (this._transportOptions) {
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
}

@@ -773,6 +753,6 @@ this._queryManager = new QueryManager(this._transport);

if (this.initialized) {
logError('enableEmulator called without initializing');
logError('enableEmulator called after initialization');
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
}
this.transportOptions = transportOptions;
this._transportOptions = transportOptions;
this.isEmulator = true;

@@ -820,3 +800,3 @@ }

function terminate(dataConnect) {
dataConnect._delete();
return dataConnect._delete();
// TODO(mtewani): Stop pending tasks

@@ -881,3 +861,3 @@ }

dataConnect: dcInstance,
refType: QueryStr,
refType: QUERY_STR,
name: queryName,

@@ -912,3 +892,3 @@ variables: variables

if ('refInfo' in queryRefOrSerializedResult) {
let serializedRef = queryRefOrSerializedResult;
const serializedRef = queryRefOrSerializedResult;
const { data, source, fetchTime } = serializedRef;

@@ -946,24 +926,4 @@ initialCache = {

registerDataConnect();
// import { getDataConnect, queryRef } from './api';
// import { getApp } from '@firebase/app';
// const app = getApp();
// const dc = getDataConnect({ location: '', connector: '', serviceId: '', projectId: '' });
// interface Response {
// name: string;
// }
// const converter: Converter<Response> = {
// fromDataConnect(input: string) {
// return { name: input };
// },
// fromType(input) {
// return input;
// }
// };
// const myRef = queryRef(dc, '', converter);
// // Ref's shouldn't have access to their own cache, right?
// const a = execute(myRef);
// subscribe(myRef, (res) => {
// })
export { DataConnect, EmulatorTokenProvider, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider, MutationManager, MutationStr, QueryStr, SOURCE_CACHE, SOURCE_SERVER, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef };
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 };
//# sourceMappingURL=index.esm2017.js.map

@@ -1,9 +0,9 @@

import { __assign, __extends, __awaiter, __generator } from 'tslib';
import { __extends, __assign, __awaiter, __generator } from 'tslib';
import { _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
import { Component } from '@firebase/component';
import { FirebaseError } from '@firebase/util';
import { Logger } from '@firebase/logger';
import { FirebaseError } from '@firebase/util';
var name = "@firebase/data-connect";
var version = "0.0.1";
var version = "0.0.2-dataconnect-preview.877f8b7d0";

@@ -52,2 +52,51 @@ /**

*/
var Code = {
OTHER: 'other',
ALREADY_INITIALIZED: 'already-initialized',
NOT_INITIALIZED: 'not-initialized',
NOT_SUPPORTED: 'not-supported',
INVALID_ARGUMENT: 'invalid-argument',
PARTIAL_ERROR: 'partial-error'
};
/** An error returned by a DataConnect operation. */
var DataConnectError = /** @class */ (function (_super) {
__extends(DataConnectError, _super);
/** @hideconstructor */
function DataConnectError(
/**
* The backend error code associated with this error.
*/
code,
/**
* A custom error description.
*/
message) {
var _this = _super.call(this, code, message) || this;
_this.code = code;
_this.message = message;
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
_this.toString = function () { return "".concat(_this.name, ": [code=").concat(_this.code, "]: ").concat(_this.message); };
return _this;
}
return DataConnectError;
}(FirebaseError));
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var logger = new Logger('@firebase/data-connect');

@@ -58,10 +107,6 @@ function setLogLevel(logLevel) {

function logDebug(msg) {
// if (logger.logLevel <= LogLevel.DEBUG) {
logger.debug("DataConnect (".concat(SDK_VERSION, "): ").concat(msg));
// }
}
function logError(msg) {
// if (logger.logLevel <= LogLevel.ERROR) {
logger.error("DataConnect (".concat(SDK_VERSION, "): ").concat(msg));
// }
}

@@ -86,10 +131,10 @@

var FirebaseAuthProvider = /** @class */ (function () {
function FirebaseAuthProvider(appName, options, authProvider_) {
function FirebaseAuthProvider(_appName, _options, _authProvider) {
var _this = this;
this.appName = appName;
this.options = options;
this.authProvider_ = authProvider_;
this.auth_ = authProvider_.getImmediate({ optional: true });
if (!this.auth_) {
authProvider_.onInit(function (auth) { return (_this.auth_ = auth); });
this._appName = _appName;
this._options = _options;
this._authProvider = _authProvider;
this._auth = _authProvider.getImmediate({ optional: true });
if (!this._auth) {
_authProvider.onInit(function (auth) { return (_this._auth = auth); });
}

@@ -99,6 +144,6 @@ }

var _this = this;
if (!this.auth_) {
if (!this._auth) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
if (_this.auth_) {
if (_this._auth) {
_this.getToken(forceRefresh).then(resolve, reject);

@@ -112,3 +157,3 @@ }

}
return this.auth_.getToken(forceRefresh).catch(function (error) {
return this._auth.getToken(forceRefresh).catch(function (error) {
if (error && error.code === 'auth/token-not-initialized') {

@@ -127,6 +172,6 @@ logDebug('Got auth/token-not-initialized error. Treating as null token.');

var _a;
(_a = this.auth_) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
};
FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
this.authProvider_
this._authProvider
.get()

@@ -137,22 +182,2 @@ .then(function (auth) { return auth.removeAuthTokenListener(listener); });

}());
var EmulatorTokenProvider = /** @class */ (function () {
function EmulatorTokenProvider(accessToken) {
this.accessToken = accessToken;
}
EmulatorTokenProvider.prototype.getToken = function (forceRefresh) {
return Promise.resolve({
accessToken: this.accessToken
});
};
EmulatorTokenProvider.prototype.addTokenChangeListener = function (listener) {
// Invoke the listener immediately to match the behavior in Firebase Auth
// (see packages/auth/src/auth.js#L1807)
listener(this.accessToken);
};
EmulatorTokenProvider.prototype.removeTokenChangeListener = function (listener) { };
EmulatorTokenProvider.prototype.notifyForInvalidToken = function () { };
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
EmulatorTokenProvider.OWNER = 'owner';
return EmulatorTokenProvider;
}());

@@ -175,4 +200,4 @@ /**

*/
var QueryStr = 'query';
var MutationStr = 'mutation';
var QUERY_STR = 'query';
var MUTATION_STR = 'mutation';
var SOURCE_SERVER = 'SERVER';

@@ -264,3 +289,3 @@ var SOURCE_CACHE = 'CACHE';

variables: variables,
refType: QueryStr
refType: QUERY_STR
};

@@ -283,3 +308,3 @@ var key = encoderImpl(ref);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -333,3 +358,3 @@ var trackedQuery = this._queries.get(key);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -388,51 +413,2 @@ var trackedQuery = this._queries.get(key);

*/
var Code = {
OTHER: 'other',
ALREADY_INITIALIZED: 'already-initialized',
NOT_INITIALIZED: 'not-initialized',
NOT_SUPPORTED: 'not-supported',
INVALID_ARGUMENT: 'invalid-argument',
PARTIAL_ERROR: 'partial-error'
};
/** An error returned by a DataConnect operation. */
var DataConnectError = /** @class */ (function (_super) {
__extends(DataConnectError, _super);
/** @hideconstructor */
function DataConnectError(
/**
* The backend error code associated with this error.
*/
code,
/**
* A custom error description.
*/
message) {
var _this = _super.call(this, code, message) || this;
_this.code = code;
_this.message = message;
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
_this.toString = function () { return "".concat(_this.name, ": [code=").concat(_this.code, "]: ").concat(_this.message); };
return _this;
}
return DataConnectError;
}(FirebaseError));
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function urlBuilder(projectConfig, transportOptions) {

@@ -498,2 +474,4 @@ var connector = projectConfig.connector, location = projectConfig.location, project = projectConfig.projectId, service = projectConfig.service;

signal: signal
}).catch(function (err) {
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
})

@@ -554,11 +532,12 @@ .then(function (response) { return __awaiter(_this, void 0, void 0, function () {

var _this = this;
var _a;
this.apiKey = apiKey;
this.authProvider = authProvider;
this.host = '';
this.location = 'l';
this.connectorName = '';
this.secure = true;
this.project = 'p';
this.accessToken = null;
this.authInitialized_ = false;
this._host = '';
this._location = 'l';
this._connectorName = '';
this._secure = true;
this._project = 'p';
this._accessToken = null;
this._authInitialized = false;
// TODO(mtewani): Update U to include shape of body defined in line 13.

@@ -570,7 +549,7 @@ this.invokeQuery = function (queryName, body) {

return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
name: "projects/".concat(_this.project, "/locations/").concat(_this.location, "/services/").concat(_this.serviceName, "/connectors/").concat(_this.connectorName),
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
operationName: queryName,
variables: body
}, // TODO(mtewani): This is a patch, fix this.
abortController, _this.accessToken);
abortController, _this._accessToken);
});

@@ -585,6 +564,6 @@ return {

return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
name: "projects/".concat(_this.project, "/locations/").concat(_this.location, "/services/").concat(_this.serviceName, "/connectors/").concat(_this.connectorName),
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
operationName: mutationName,
variables: body
}, abortController, _this.accessToken);
}, abortController, _this._accessToken);
});

@@ -600,21 +579,25 @@ return {

if (typeof transportOptions.port === 'number') {
this.port = transportOptions.port;
this._port = transportOptions.port;
}
if (typeof transportOptions.sslEnabled !== 'undefined') {
this.secure = transportOptions.sslEnabled;
this._secure = transportOptions.sslEnabled;
}
this.host = transportOptions.host;
this._host = transportOptions.host;
}
var location = options.location, project = options.projectId, connector = options.connector, service = options.service;
if (location) {
this.location = location;
this._location = location;
}
if (project) {
this.project = project;
this._project = project;
}
this.serviceName = service;
this._serviceName = service;
if (!connector) {
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
}
this.connectorName = connector;
this._connectorName = connector;
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(function (token) {
logDebug("New Token Available: ".concat(token));
_this._accessToken = token;
});
}

@@ -624,7 +607,7 @@ Object.defineProperty(RESTTransport.prototype, "endpointUrl", {

return urlBuilder({
connector: this.connectorName,
location: this.location,
projectId: this.project,
service: this.serviceName
}, { host: this.host, sslEnabled: this.secure, port: this.port });
connector: this._connectorName,
location: this._location,
projectId: this._project,
service: this._serviceName
}, { host: this._host, sslEnabled: this._secure, port: this._port });
},

@@ -635,12 +618,12 @@ enumerable: false,

RESTTransport.prototype.useEmulator = function (host, port, isSecure) {
this.host = host;
this._host = host;
if (typeof port === 'number') {
this.port = port;
this._port = port;
}
if (typeof isSecure !== 'undefined') {
this.secure = isSecure;
this._secure = isSecure;
}
};
RESTTransport.prototype.onTokenChanged = function (newToken) {
this.accessToken = newToken;
this._accessToken = newToken;
};

@@ -650,5 +633,5 @@ RESTTransport.prototype.getWithAuth = function () {

var starterPromise = new Promise(function (resolve) {
return resolve(_this.accessToken);
return resolve(_this._accessToken);
});
if (!this.authInitialized_) {
if (!this._authInitialized) {
if (this.authProvider) {

@@ -661,4 +644,4 @@ starterPromise = this.authProvider

}
_this.accessToken = data.accessToken;
return _this.accessToken;
_this._accessToken = data.accessToken;
return _this._accessToken;
});

@@ -696,3 +679,3 @@ }

name: queryName,
refType: MutationStr,
refType: MUTATION_STR,
variables: variables

@@ -703,4 +686,4 @@ };

var MutationManager = /** @class */ (function () {
function MutationManager(transport) {
this.transport = transport;
function MutationManager(_transport) {
this._transport = _transport;
this._inflight = [];

@@ -710,3 +693,3 @@ }

var _this = this;
var result = this.transport.invokeMutation(mutationRef.name, mutationRef.variables);
var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
var withRefPromise = result.then(function (res) {

@@ -760,6 +743,8 @@ var obj = __assign(__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });

var DataConnect = /** @class */ (function () {
function DataConnect(app, dataConnectOptions, authProvider) {
function DataConnect(app,
// TODO(mtewani): Replace with _dataConnectOptions in the future
dataConnectOptions, _authProvider) {
this.app = app;
this.dataConnectOptions = dataConnectOptions;
this.authProvider = authProvider;
this._authProvider = _authProvider;
this.isEmulator = false;

@@ -772,3 +757,3 @@ this.initialized = false;

this.isEmulator = true;
this.transportOptions = parseOptions(host);
this._transportOptions = parseOptions(host);
}

@@ -787,23 +772,16 @@ }

DataConnect.prototype.setInitialized = function () {
var _this = this;
if (this.initialized) {
return;
}
if (this.transportClass === undefined) {
if (this._transportClass === undefined) {
logDebug('transportClass not provided. Defaulting to RESTTransport.');
this.transportClass = RESTTransport;
this._transportClass = RESTTransport;
}
if (this.authProvider) {
this.authTokenProvider = this.isEmulator
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
this.authTokenProvider.addTokenChangeListener(function (token) {
logDebug("New Token Available: ".concat(token));
_this._transport.onTokenChanged(token);
});
if (this._authProvider) {
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
}
this.initialized = true;
this._transport = new this.transportClass(this.dataConnectOptions, this.app.options.apiKey, this.authTokenProvider);
if (this.transportOptions) {
this._transport.useEmulator(this.transportOptions.host, this.transportOptions.port, this.transportOptions.sslEnabled);
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
if (this._transportOptions) {
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
}

@@ -815,6 +793,6 @@ this._queryManager = new QueryManager(this._transport);

if (this.initialized) {
logError('enableEmulator called without initializing');
logError('enableEmulator called after initialization');
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
}
this.transportOptions = transportOptions;
this._transportOptions = transportOptions;
this.isEmulator = true;

@@ -864,3 +842,3 @@ };

function terminate(dataConnect) {
dataConnect._delete();
return dataConnect._delete();
// TODO(mtewani): Stop pending tasks

@@ -910,3 +888,3 @@ }

dataConnect: dcInstance,
refType: QueryStr,
refType: QUERY_STR,
name: queryName,

@@ -974,24 +952,4 @@ variables: variables

registerDataConnect();
// import { getDataConnect, queryRef } from './api';
// import { getApp } from '@firebase/app';
// const app = getApp();
// const dc = getDataConnect({ location: '', connector: '', serviceId: '', projectId: '' });
// interface Response {
// name: string;
// }
// const converter: Converter<Response> = {
// fromDataConnect(input: string) {
// return { name: input };
// },
// fromType(input) {
// return input;
// }
// };
// const myRef = queryRef(dc, '', converter);
// // Ref's shouldn't have access to their own cache, right?
// const a = execute(myRef);
// subscribe(myRef, (res) => {
// })
export { DataConnect, EmulatorTokenProvider, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider, MutationManager, MutationStr, QueryStr, SOURCE_CACHE, SOURCE_SERVER, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef };
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 };
//# sourceMappingURL=index.esm5.js.map

@@ -107,10 +107,6 @@ 'use strict';

function logDebug(msg) {
// if (logger.logLevel <= LogLevel.DEBUG) {
logger.debug("DataConnect (".concat(SDK_VERSION, "): ").concat(msg));
// }
}
function logError(msg) {
// if (logger.logLevel <= LogLevel.ERROR) {
logger.error("DataConnect (".concat(SDK_VERSION, "): ").concat(msg));
// }
}

@@ -157,2 +153,4 @@

signal: signal
}).catch(function (err) {
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
})

@@ -195,3 +193,3 @@ .then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {

var name = "@firebase/data-connect";
var version = "0.0.1";
var version = "0.0.2-dataconnect-preview.877f8b7d0";

@@ -215,10 +213,10 @@ /**

var FirebaseAuthProvider = /** @class */ (function () {
function FirebaseAuthProvider(appName, options, authProvider_) {
function FirebaseAuthProvider(_appName, _options, _authProvider) {
var _this = this;
this.appName = appName;
this.options = options;
this.authProvider_ = authProvider_;
this.auth_ = authProvider_.getImmediate({ optional: true });
if (!this.auth_) {
authProvider_.onInit(function (auth) { return (_this.auth_ = auth); });
this._appName = _appName;
this._options = _options;
this._authProvider = _authProvider;
this._auth = _authProvider.getImmediate({ optional: true });
if (!this._auth) {
_authProvider.onInit(function (auth) { return (_this._auth = auth); });
}

@@ -228,6 +226,6 @@ }

var _this = this;
if (!this.auth_) {
if (!this._auth) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
if (_this.auth_) {
if (_this._auth) {
_this.getToken(forceRefresh).then(resolve, reject);

@@ -241,3 +239,3 @@ }

}
return this.auth_.getToken(forceRefresh).catch(function (error) {
return this._auth.getToken(forceRefresh).catch(function (error) {
if (error && error.code === 'auth/token-not-initialized') {

@@ -256,6 +254,6 @@ logDebug('Got auth/token-not-initialized error. Treating as null token.');

var _a;
(_a = this.auth_) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
};
FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
this.authProvider_
this._authProvider
.get()

@@ -266,22 +264,2 @@ .then(function (auth) { return auth.removeAuthTokenListener(listener); });

}());
var EmulatorTokenProvider = /** @class */ (function () {
function EmulatorTokenProvider(accessToken) {
this.accessToken = accessToken;
}
EmulatorTokenProvider.prototype.getToken = function (forceRefresh) {
return Promise.resolve({
accessToken: this.accessToken
});
};
EmulatorTokenProvider.prototype.addTokenChangeListener = function (listener) {
// Invoke the listener immediately to match the behavior in Firebase Auth
// (see packages/auth/src/auth.js#L1807)
listener(this.accessToken);
};
EmulatorTokenProvider.prototype.removeTokenChangeListener = function (listener) { };
EmulatorTokenProvider.prototype.notifyForInvalidToken = function () { };
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
EmulatorTokenProvider.OWNER = 'owner';
return EmulatorTokenProvider;
}());

@@ -304,4 +282,4 @@ /**

*/
var QueryStr = 'query';
var MutationStr = 'mutation';
var QUERY_STR = 'query';
var MUTATION_STR = 'mutation';
var SOURCE_SERVER = 'SERVER';

@@ -393,3 +371,3 @@ var SOURCE_CACHE = 'CACHE';

variables: variables,
refType: QueryStr
refType: QUERY_STR
};

@@ -412,3 +390,3 @@ var key = encoderImpl(ref);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -462,3 +440,3 @@ var trackedQuery = this._queries.get(key);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -560,11 +538,12 @@ var trackedQuery = this._queries.get(key);

var _this = this;
var _a;
this.apiKey = apiKey;
this.authProvider = authProvider;
this.host = '';
this.location = 'l';
this.connectorName = '';
this.secure = true;
this.project = 'p';
this.accessToken = null;
this.authInitialized_ = false;
this._host = '';
this._location = 'l';
this._connectorName = '';
this._secure = true;
this._project = 'p';
this._accessToken = null;
this._authInitialized = false;
// TODO(mtewani): Update U to include shape of body defined in line 13.

@@ -576,7 +555,7 @@ this.invokeQuery = function (queryName, body) {

return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
name: "projects/".concat(_this.project, "/locations/").concat(_this.location, "/services/").concat(_this.serviceName, "/connectors/").concat(_this.connectorName),
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
operationName: queryName,
variables: body
}, // TODO(mtewani): This is a patch, fix this.
abortController, _this.accessToken);
abortController, _this._accessToken);
});

@@ -591,6 +570,6 @@ return {

return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
name: "projects/".concat(_this.project, "/locations/").concat(_this.location, "/services/").concat(_this.serviceName, "/connectors/").concat(_this.connectorName),
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
operationName: mutationName,
variables: body
}, abortController, _this.accessToken);
}, abortController, _this._accessToken);
});

@@ -606,21 +585,25 @@ return {

if (typeof transportOptions.port === 'number') {
this.port = transportOptions.port;
this._port = transportOptions.port;
}
if (typeof transportOptions.sslEnabled !== 'undefined') {
this.secure = transportOptions.sslEnabled;
this._secure = transportOptions.sslEnabled;
}
this.host = transportOptions.host;
this._host = transportOptions.host;
}
var location = options.location, project = options.projectId, connector = options.connector, service = options.service;
if (location) {
this.location = location;
this._location = location;
}
if (project) {
this.project = project;
this._project = project;
}
this.serviceName = service;
this._serviceName = service;
if (!connector) {
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
}
this.connectorName = connector;
this._connectorName = connector;
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(function (token) {
logDebug("New Token Available: ".concat(token));
_this._accessToken = token;
});
}

@@ -630,7 +613,7 @@ Object.defineProperty(RESTTransport.prototype, "endpointUrl", {

return urlBuilder({
connector: this.connectorName,
location: this.location,
projectId: this.project,
service: this.serviceName
}, { host: this.host, sslEnabled: this.secure, port: this.port });
connector: this._connectorName,
location: this._location,
projectId: this._project,
service: this._serviceName
}, { host: this._host, sslEnabled: this._secure, port: this._port });
},

@@ -641,12 +624,12 @@ enumerable: false,

RESTTransport.prototype.useEmulator = function (host, port, isSecure) {
this.host = host;
this._host = host;
if (typeof port === 'number') {
this.port = port;
this._port = port;
}
if (typeof isSecure !== 'undefined') {
this.secure = isSecure;
this._secure = isSecure;
}
};
RESTTransport.prototype.onTokenChanged = function (newToken) {
this.accessToken = newToken;
this._accessToken = newToken;
};

@@ -656,5 +639,5 @@ RESTTransport.prototype.getWithAuth = function () {

var starterPromise = new Promise(function (resolve) {
return resolve(_this.accessToken);
return resolve(_this._accessToken);
});
if (!this.authInitialized_) {
if (!this._authInitialized) {
if (this.authProvider) {

@@ -667,4 +650,4 @@ starterPromise = this.authProvider

}
_this.accessToken = data.accessToken;
return _this.accessToken;
_this._accessToken = data.accessToken;
return _this._accessToken;
});

@@ -702,3 +685,3 @@ }

name: queryName,
refType: MutationStr,
refType: MUTATION_STR,
variables: variables

@@ -709,4 +692,4 @@ };

var MutationManager = /** @class */ (function () {
function MutationManager(transport) {
this.transport = transport;
function MutationManager(_transport) {
this._transport = _transport;
this._inflight = [];

@@ -716,3 +699,3 @@ }

var _this = this;
var result = this.transport.invokeMutation(mutationRef.name, mutationRef.variables);
var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
var withRefPromise = result.then(function (res) {

@@ -766,6 +749,8 @@ var obj = tslib.__assign(tslib.__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });

var DataConnect = /** @class */ (function () {
function DataConnect(app, dataConnectOptions, authProvider) {
function DataConnect(app,
// TODO(mtewani): Replace with _dataConnectOptions in the future
dataConnectOptions, _authProvider) {
this.app = app;
this.dataConnectOptions = dataConnectOptions;
this.authProvider = authProvider;
this._authProvider = _authProvider;
this.isEmulator = false;

@@ -778,3 +763,3 @@ this.initialized = false;

this.isEmulator = true;
this.transportOptions = parseOptions(host);
this._transportOptions = parseOptions(host);
}

@@ -793,23 +778,16 @@ }

DataConnect.prototype.setInitialized = function () {
var _this = this;
if (this.initialized) {
return;
}
if (this.transportClass === undefined) {
if (this._transportClass === undefined) {
logDebug('transportClass not provided. Defaulting to RESTTransport.');
this.transportClass = RESTTransport;
this._transportClass = RESTTransport;
}
if (this.authProvider) {
this.authTokenProvider = this.isEmulator
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
this.authTokenProvider.addTokenChangeListener(function (token) {
logDebug("New Token Available: ".concat(token));
_this._transport.onTokenChanged(token);
});
if (this._authProvider) {
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
}
this.initialized = true;
this._transport = new this.transportClass(this.dataConnectOptions, this.app.options.apiKey, this.authTokenProvider);
if (this.transportOptions) {
this._transport.useEmulator(this.transportOptions.host, this.transportOptions.port, this.transportOptions.sslEnabled);
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
if (this._transportOptions) {
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
}

@@ -821,6 +799,6 @@ this._queryManager = new QueryManager(this._transport);

if (this.initialized) {
logError('enableEmulator called without initializing');
logError('enableEmulator called after initialization');
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
}
this.transportOptions = transportOptions;
this._transportOptions = transportOptions;
this.isEmulator = true;

@@ -870,3 +848,3 @@ };

function terminate(dataConnect) {
dataConnect._delete();
return dataConnect._delete();
// TODO(mtewani): Stop pending tasks

@@ -916,3 +894,3 @@ }

dataConnect: dcInstance,
refType: QueryStr,
refType: QUERY_STR,
name: queryName,

@@ -994,8 +972,7 @@ variables: variables

exports.DataConnect = DataConnect;
exports.EmulatorTokenProvider = EmulatorTokenProvider;
exports.FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR;
exports.FirebaseAuthProvider = FirebaseAuthProvider;
exports.MUTATION_STR = MUTATION_STR;
exports.MutationManager = MutationManager;
exports.MutationStr = MutationStr;
exports.QueryStr = QueryStr;
exports.QUERY_STR = QUERY_STR;
exports.SOURCE_CACHE = SOURCE_CACHE;

@@ -1002,0 +979,0 @@ exports.SOURCE_SERVER = SOURCE_SERVER;

@@ -39,3 +39,3 @@ /**

private readonly dataConnectOptions;
private readonly authProvider;
private readonly _authProvider;
_queryManager: QueryManager;

@@ -46,6 +46,6 @@ _mutationManager: MutationManager;

private _transport;
private transportClass;
private transportOptions?;
private authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, authProvider: Provider<FirebaseAuthInternalName>);
private _transportClass;
private _transportOptions?;
private _authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>);
_delete(): Promise<void>;

@@ -112,13 +112,2 @@ getSettings(): ConnectorConfig;

export declare class EmulatorTokenProvider implements AuthTokenProvider {
private accessToken;
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
static OWNER: string;
constructor(accessToken: string);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
addTokenChangeListener(listener: AuthTokenListener): void;
removeTokenChangeListener(listener: (token: string | null) => void): void;
notifyForInvalidToken(): void;
}
export declare function executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;

@@ -131,7 +120,7 @@

export declare class FirebaseAuthProvider implements AuthTokenProvider {
private appName;
private options;
private authProvider_;
private auth_;
constructor(appName: string, options: FirebaseOptions, authProvider_: Provider<FirebaseAuthInternalName>);
private _appName;
private _options;
private _authProvider;
private _auth;
constructor(_appName: string, _options: FirebaseOptions, _authProvider: Provider<FirebaseAuthInternalName>);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;

@@ -146,7 +135,9 @@ addTokenChangeListener(listener: AuthTokenListener): void;

export declare const MUTATION_STR = "mutation";
export declare class MutationManager {
private transport;
private _transport;
private _inflight;
constructor(transport: DataConnectTransport);
executeMutation<Response, Variables>(mutationRef: MutationRef<Response, Variables>): MutationPromise<Response, Variables>;
constructor(_transport: DataConnectTransport);
executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
}

@@ -157,9 +148,9 @@

export declare interface MutationRef<Response, Variables> extends OperationRef<Response, Variables> {
refType: typeof MutationStr;
export declare interface MutationRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof MUTATION_STR;
}
export declare function mutationRef<Response>(dcInstance: DataConnect, queryName: string): MutationRef<Response, undefined>;
export declare function mutationRef<Data>(dcInstance: DataConnect, queryName: string): MutationRef<Data, undefined>;
export declare function mutationRef<Response, Variables>(dcInstance: DataConnect, queryName: string, variables: Variables): MutationRef<Response, Variables>;
export declare function mutationRef<Data, Variables>(dcInstance: DataConnect, mutationName: string, variables: Variables): MutationRef<Data, Variables>;

@@ -173,4 +164,2 @@ export declare interface MutationResponse<T> extends CancellableOperation<T> {

export declare const MutationStr = "mutation";
export declare type OnCompleteSubscription = () => void;

@@ -203,8 +192,3 @@

export declare interface ProjectOptions {
location: string;
connector: string;
service: string;
projectId: string;
}
export declare const QUERY_STR = "query";

@@ -215,5 +199,5 @@ declare class QueryManager {

constructor(transport: DataConnectTransport);
track<Response, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Response>): TrackedQuery<unknown, unknown> | undefined;
addSubscription<Response, Variables>(queryRef: OperationRef<Response, Variables>, onResultCallback: OnResultSubscription<Response, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Response>): () => void;
executeQuery<Response, Variables>(queryRef: QueryRef<Response, Variables>): QueryPromise<Response, Variables>;
track<Data, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Data>): TrackedQuery<unknown, unknown>;
addSubscription<Data, Variables>(queryRef: OperationRef<Data, Variables>, onResultCallback: OnResultSubscription<Data, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Data>): () => void;
executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
enableEmulator(host: string, port: number): void;

@@ -226,3 +210,3 @@ }

export declare interface QueryRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof QueryStr;
refType: typeof QUERY_STR;
}

@@ -242,7 +226,5 @@

export declare const QueryStr = "query";
export declare type QueryUnsubscribe = () => void;
export declare type ReferenceType = typeof QueryStr | typeof MutationStr;
export declare type ReferenceType = typeof QUERY_STR | typeof MUTATION_STR;

@@ -289,10 +271,10 @@ export declare interface RefInfo<Variables> {

export declare function terminate(dataConnect: DataConnect): void;
export declare function terminate(dataConnect: DataConnect): Promise<void>;
export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<unknown, Variables>;
declare interface TrackedQuery<Response, Variables> {
ref: Omit<OperationRef<Response, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Response, Variables>>;
currentCache: OpResult<Response> | null;
declare interface TrackedQuery<Data, Variables> {
ref: Omit<OperationRef<Data, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Data, Variables>>;
currentCache: OpResult<Data> | null;
lastError: DataConnectError | null;

@@ -299,0 +281,0 @@ }

@@ -99,10 +99,6 @@ import { FirebaseError } from '@firebase/util';

function logDebug(msg) {
// if (logger.logLevel <= LogLevel.DEBUG) {
logger.debug(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}
function logError(msg) {
// if (logger.logLevel <= LogLevel.ERROR) {
logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
// }
}

@@ -147,2 +143,4 @@

signal
}).catch(err => {
throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
})

@@ -174,3 +172,3 @@ .then(async (response) => {

const name = "@firebase/data-connect";
const version = "0.0.1";
const version = "0.0.2-dataconnect-preview.877f8b7d0";

@@ -194,16 +192,16 @@ /**

class FirebaseAuthProvider {
constructor(appName, options, authProvider_) {
this.appName = appName;
this.options = options;
this.authProvider_ = authProvider_;
this.auth_ = authProvider_.getImmediate({ optional: true });
if (!this.auth_) {
authProvider_.onInit(auth => (this.auth_ = auth));
constructor(_appName, _options, _authProvider) {
this._appName = _appName;
this._options = _options;
this._authProvider = _authProvider;
this._auth = _authProvider.getImmediate({ optional: true });
if (!this._auth) {
_authProvider.onInit(auth => (this._auth = auth));
}
}
getToken(forceRefresh) {
if (!this.auth_) {
if (!this._auth) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (this.auth_) {
if (this._auth) {
this.getToken(forceRefresh).then(resolve, reject);

@@ -217,3 +215,3 @@ }

}
return this.auth_.getToken(forceRefresh).catch(error => {
return this._auth.getToken(forceRefresh).catch(error => {
if (error && error.code === 'auth/token-not-initialized') {

@@ -232,6 +230,6 @@ logDebug('Got auth/token-not-initialized error. Treating as null token.');

var _a;
(_a = this.auth_) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
}
removeTokenChangeListener(listener) {
this.authProvider_
this._authProvider
.get()

@@ -241,21 +239,2 @@ .then(auth => auth.removeAuthTokenListener(listener));

}
class EmulatorTokenProvider {
constructor(accessToken) {
this.accessToken = accessToken;
}
getToken(forceRefresh) {
return Promise.resolve({
accessToken: this.accessToken
});
}
addTokenChangeListener(listener) {
// Invoke the listener immediately to match the behavior in Firebase Auth
// (see packages/auth/src/auth.js#L1807)
listener(this.accessToken);
}
removeTokenChangeListener(listener) { }
notifyForInvalidToken() { }
}
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
EmulatorTokenProvider.OWNER = 'owner';

@@ -278,4 +257,4 @@ /**

*/
const QueryStr = 'query';
const MutationStr = 'mutation';
const QUERY_STR = 'query';
const MUTATION_STR = 'mutation';
const SOURCE_SERVER = 'SERVER';

@@ -367,3 +346,3 @@ const SOURCE_CACHE = 'CACHE';

variables,
refType: QueryStr
refType: QUERY_STR
};

@@ -385,3 +364,3 @@ const key = encoderImpl(ref);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -435,3 +414,3 @@ const trackedQuery = this._queries.get(key);

variables: queryRef.variables,
refType: QueryStr
refType: QUERY_STR
});

@@ -531,11 +510,12 @@ const trackedQuery = this._queries.get(key);

constructor(options, apiKey, authProvider, transportOptions) {
var _a;
this.apiKey = apiKey;
this.authProvider = authProvider;
this.host = '';
this.location = 'l';
this.connectorName = '';
this.secure = true;
this.project = 'p';
this.accessToken = null;
this.authInitialized_ = false;
this._host = '';
this._location = 'l';
this._connectorName = '';
this._secure = true;
this._project = 'p';
this._accessToken = null;
this._authInitialized = false;
// TODO(mtewani): Update U to include shape of body defined in line 13.

@@ -547,7 +527,7 @@ this.invokeQuery = (queryName, body) => {

return dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
name: `projects/${this.project}/locations/${this.location}/services/${this.serviceName}/connectors/${this.connectorName}`,
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: queryName,
variables: body
}, // TODO(mtewani): This is a patch, fix this.
abortController, this.accessToken);
abortController, this._accessToken);
});

@@ -562,6 +542,6 @@ return {

return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
name: `projects/${this.project}/locations/${this.location}/services/${this.serviceName}/connectors/${this.connectorName}`,
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: mutationName,
variables: body
}, abortController, this.accessToken);
}, abortController, this._accessToken);
});

@@ -577,45 +557,49 @@ return {

if (typeof transportOptions.port === 'number') {
this.port = transportOptions.port;
this._port = transportOptions.port;
}
if (typeof transportOptions.sslEnabled !== 'undefined') {
this.secure = transportOptions.sslEnabled;
this._secure = transportOptions.sslEnabled;
}
this.host = transportOptions.host;
this._host = transportOptions.host;
}
const { location, projectId: project, connector, service } = options;
if (location) {
this.location = location;
this._location = location;
}
if (project) {
this.project = project;
this._project = project;
}
this.serviceName = service;
this._serviceName = service;
if (!connector) {
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Connector Name required!');
}
this.connectorName = connector;
this._connectorName = connector;
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
logDebug(`New Token Available: ${token}`);
this._accessToken = token;
});
}
get endpointUrl() {
return urlBuilder({
connector: this.connectorName,
location: this.location,
projectId: this.project,
service: this.serviceName
}, { host: this.host, sslEnabled: this.secure, port: this.port });
connector: this._connectorName,
location: this._location,
projectId: this._project,
service: this._serviceName
}, { host: this._host, sslEnabled: this._secure, port: this._port });
}
useEmulator(host, port, isSecure) {
this.host = host;
this._host = host;
if (typeof port === 'number') {
this.port = port;
this._port = port;
}
if (typeof isSecure !== 'undefined') {
this.secure = isSecure;
this._secure = isSecure;
}
}
onTokenChanged(newToken) {
this.accessToken = newToken;
this._accessToken = newToken;
}
getWithAuth() {
let starterPromise = new Promise(resolve => resolve(this.accessToken));
if (!this.authInitialized_) {
let starterPromise = new Promise(resolve => resolve(this._accessToken));
if (!this._authInitialized) {
if (this.authProvider) {

@@ -628,4 +612,4 @@ starterPromise = this.authProvider

}
this.accessToken = data.accessToken;
return this.accessToken;
this._accessToken = data.accessToken;
return this._accessToken;
});

@@ -662,3 +646,3 @@ }

name: queryName,
refType: MutationStr,
refType: MUTATION_STR,
variables: variables

@@ -669,8 +653,8 @@ };

class MutationManager {
constructor(transport) {
this.transport = transport;
constructor(_transport) {
this._transport = _transport;
this._inflight = [];
}
executeMutation(mutationRef) {
const result = this.transport.invokeMutation(mutationRef.name, mutationRef.variables);
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
const withRefPromise = result.then(res => {

@@ -721,6 +705,8 @@ const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });

class DataConnect {
constructor(app, dataConnectOptions, authProvider) {
constructor(app,
// TODO(mtewani): Replace with _dataConnectOptions in the future
dataConnectOptions, _authProvider) {
this.app = app;
this.dataConnectOptions = dataConnectOptions;
this.authProvider = authProvider;
this._authProvider = _authProvider;
this.isEmulator = false;

@@ -733,3 +719,3 @@ this.initialized = false;

this.isEmulator = true;
this.transportOptions = parseOptions(host);
this._transportOptions = parseOptions(host);
}

@@ -751,19 +737,13 @@ }

}
if (this.transportClass === undefined) {
if (this._transportClass === undefined) {
logDebug('transportClass not provided. Defaulting to RESTTransport.');
this.transportClass = RESTTransport;
this._transportClass = RESTTransport;
}
if (this.authProvider) {
this.authTokenProvider = this.isEmulator
? new EmulatorTokenProvider(EmulatorTokenProvider.OWNER)
: new FirebaseAuthProvider(this.app.name, this.app.options, this.authProvider);
this.authTokenProvider.addTokenChangeListener(token => {
logDebug(`New Token Available: ${token}`);
this._transport.onTokenChanged(token);
});
if (this._authProvider) {
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
}
this.initialized = true;
this._transport = new this.transportClass(this.dataConnectOptions, this.app.options.apiKey, this.authTokenProvider);
if (this.transportOptions) {
this._transport.useEmulator(this.transportOptions.host, this.transportOptions.port, this.transportOptions.sslEnabled);
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
if (this._transportOptions) {
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
}

@@ -775,6 +755,6 @@ this._queryManager = new QueryManager(this._transport);

if (this.initialized) {
logError('enableEmulator called without initializing');
logError('enableEmulator called after initialization');
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
}
this.transportOptions = transportOptions;
this._transportOptions = transportOptions;
this.isEmulator = true;

@@ -822,3 +802,3 @@ }

function terminate(dataConnect) {
dataConnect._delete();
return dataConnect._delete();
// TODO(mtewani): Stop pending tasks

@@ -883,3 +863,3 @@ }

dataConnect: dcInstance,
refType: QueryStr,
refType: QUERY_STR,
name: queryName,

@@ -914,3 +894,3 @@ variables: variables

if ('refInfo' in queryRefOrSerializedResult) {
let serializedRef = queryRefOrSerializedResult;
const serializedRef = queryRefOrSerializedResult;
const { data, source, fetchTime } = serializedRef;

@@ -961,3 +941,3 @@ initialCache = {

export { DataConnect, EmulatorTokenProvider, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider, MutationManager, MutationStr, QueryStr, SOURCE_CACHE, SOURCE_SERVER, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef };
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 };
//# sourceMappingURL=index.node.esm.js.map

@@ -22,8 +22,2 @@ /**

import { MutationManager } from './Mutation';
export interface ProjectOptions {
location: string;
connector: string;
service: string;
projectId: string;
}
export interface ConnectorConfig {

@@ -53,3 +47,3 @@ location: string;

private readonly dataConnectOptions;
private readonly authProvider;
private readonly _authProvider;
_queryManager: QueryManager;

@@ -60,6 +54,6 @@ _mutationManager: MutationManager;

private _transport;
private transportClass;
private transportOptions?;
private authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, authProvider: Provider<FirebaseAuthInternalName>);
private _transportClass;
private _transportOptions?;
private _authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>);
_delete(): Promise<void>;

@@ -73,2 +67,2 @@ getSettings(): ConnectorConfig;

export declare function getDataConnect(app: FirebaseApp, options: ConnectorConfig): DataConnect;
export declare function terminate(dataConnect: DataConnect): void;
export declare function terminate(dataConnect: DataConnect): Promise<void>;

@@ -19,13 +19,13 @@ /**

import { DataConnect } from './DataConnect';
import { DataConnectResult, MutationStr, OperationRef } from './Reference';
export interface MutationRef<Response, Variables> extends OperationRef<Response, Variables> {
refType: typeof MutationStr;
import { DataConnectResult, MUTATION_STR, OperationRef } from './Reference';
export interface MutationRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof MUTATION_STR;
}
export declare function mutationRef<Response>(dcInstance: DataConnect, queryName: string): MutationRef<Response, undefined>;
export declare function mutationRef<Response, Variables>(dcInstance: DataConnect, queryName: string, variables: Variables): MutationRef<Response, Variables>;
export declare function mutationRef<Data>(dcInstance: DataConnect, queryName: string): MutationRef<Data, undefined>;
export declare function mutationRef<Data, Variables>(dcInstance: DataConnect, mutationName: string, variables: Variables): MutationRef<Data, Variables>;
export declare class MutationManager {
private transport;
private _transport;
private _inflight;
constructor(transport: DataConnectTransport);
executeMutation<Response, Variables>(mutationRef: MutationRef<Response, Variables>): MutationPromise<Response, Variables>;
constructor(_transport: DataConnectTransport);
executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
}

@@ -32,0 +32,0 @@ export interface MutationResult<Data, Variables> extends DataConnectResult<Data, Variables> {

@@ -19,3 +19,3 @@ /**

import { DataConnect } from './DataConnect';
import { OperationRef, QueryStr, DataConnectResult, SerializedRef } from './Reference';
import { OperationRef, QUERY_STR, DataConnectResult, SerializedRef } from './Reference';
export declare type OnResultSubscription<Data, Variables> = (res: QueryResult<Data, Variables>) => void;

@@ -30,3 +30,3 @@ export declare type OnErrorSubscription = (err?: DataConnectError) => void;

export interface QueryRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof QueryStr;
refType: typeof QUERY_STR;
}

@@ -33,0 +33,0 @@ export interface QueryResult<Data, Variables> extends DataConnectResult<Data, Variables> {

@@ -18,5 +18,5 @@ /**

import { DataConnect, DataConnectOptions } from './DataConnect';
export declare const QueryStr = "query";
export declare const MutationStr = "mutation";
export declare type ReferenceType = typeof QueryStr | typeof MutationStr;
export declare const QUERY_STR = "query";
export declare const MUTATION_STR = "mutation";
export declare type ReferenceType = typeof QUERY_STR | typeof MUTATION_STR;
export declare const SOURCE_SERVER = "SERVER";

@@ -23,0 +23,0 @@ export declare const SOURCE_CACHE = "CACHE";

@@ -26,7 +26,7 @@ /**

export declare class FirebaseAuthProvider implements AuthTokenProvider {
private appName;
private options;
private authProvider_;
private auth_;
constructor(appName: string, options: FirebaseOptions, authProvider_: Provider<FirebaseAuthInternalName>);
private _appName;
private _options;
private _authProvider;
private _auth;
constructor(_appName: string, _options: FirebaseOptions, _authProvider: Provider<FirebaseAuthInternalName>);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;

@@ -36,11 +36,1 @@ addTokenChangeListener(listener: AuthTokenListener): void;

}
export declare class EmulatorTokenProvider implements AuthTokenProvider {
private accessToken;
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
static OWNER: string;
constructor(accessToken: string);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
addTokenChangeListener(listener: AuthTokenListener): void;
removeTokenChangeListener(listener: (token: string | null) => void): void;
notifyForInvalidToken(): void;
}

@@ -21,6 +21,6 @@ /**

import { DataConnectError } from './error';
interface TrackedQuery<Response, Variables> {
ref: Omit<OperationRef<Response, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Response, Variables>>;
currentCache: OpResult<Response> | null;
interface TrackedQuery<Data, Variables> {
ref: Omit<OperationRef<Data, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Data, Variables>>;
currentCache: OpResult<Data> | null;
lastError: DataConnectError | null;

@@ -32,7 +32,7 @@ }

constructor(transport: DataConnectTransport);
track<Response, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Response>): TrackedQuery<unknown, unknown> | undefined;
addSubscription<Response, Variables>(queryRef: OperationRef<Response, Variables>, onResultCallback: OnResultSubscription<Response, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Response>): () => void;
executeQuery<Response, Variables>(queryRef: QueryRef<Response, Variables>): QueryPromise<Response, Variables>;
track<Data, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Data>): TrackedQuery<unknown, unknown>;
addSubscription<Data, Variables>(queryRef: OperationRef<Data, Variables>, onResultCallback: OnResultSubscription<Data, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Data>): () => void;
executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
enableEmulator(host: string, port: number): void;
}
export {};

@@ -17,5 +17,5 @@ /**

*/
import { LogLevelString } from "@firebase/logger";
import { LogLevelString } from '@firebase/logger';
export declare function setLogLevel(logLevel: LogLevelString): void;
export declare function logDebug(msg: string): void;
export declare function logError(msg: string): void;

@@ -17,17 +17,17 @@ /**

*/
import { DataConnectTransport } from '.';
import { DataConnectOptions, TransportOptions } from '../../api/DataConnect';
import { AuthTokenProvider } from '../../core/FirebaseAuthProvider';
import { DataConnectTransport } from '.';
export declare class RESTTransport implements DataConnectTransport {
private apiKey?;
private authProvider?;
private host;
private port;
private location;
private connectorName;
private secure;
private project;
private serviceName;
private accessToken;
private authInitialized_;
private _host;
private _port;
private _location;
private _connectorName;
private _secure;
private _project;
private _serviceName;
private _accessToken;
private _authInitialized;
constructor(options: DataConnectOptions, apiKey?: string | undefined, authProvider?: AuthTokenProvider | undefined, transportOptions?: TransportOptions | undefined);

@@ -37,22 +37,10 @@ get endpointUrl(): string;

onTokenChanged(newToken: string | null): void;
getWithAuth(): Promise<string | null>;
getWithAuth(): Promise<string>;
invokeQuery: <T, U = unknown>(queryName: string, body: U) => {
then: <TResult1 = {
data: T;
errors: Error[];
}, TResult2 = never>(onfulfilled?: ((value: {
data: T;
errors: Error[];
}) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
then: any;
};
invokeMutation: <T, U = unknown>(mutationName: string, body: U) => {
then: <TResult1 = {
data: T;
errors: Error[];
}, TResult2 = never>(onfulfilled?: ((value: {
data: T;
errors: Error[];
}) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
then: any;
cancel: () => void;
};
}

@@ -17,4 +17,4 @@ /**

*/
import { ProjectOptions, TransportOptions } from '../api/DataConnect';
export declare function urlBuilder(projectConfig: ProjectOptions, transportOptions: TransportOptions): string;
import { DataConnectOptions, TransportOptions } from '../api/DataConnect';
export declare function urlBuilder(projectConfig: DataConnectOptions, transportOptions: TransportOptions): string;
export declare function addToken(url: string, apiKey?: string): string;

@@ -39,3 +39,3 @@ /**

private readonly dataConnectOptions;
private readonly authProvider;
private readonly _authProvider;
_queryManager: QueryManager;

@@ -46,6 +46,6 @@ _mutationManager: MutationManager;

private _transport;
private transportClass;
private transportOptions?;
private authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, authProvider: Provider<FirebaseAuthInternalName>);
private _transportClass;
private _transportOptions?;
private _authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>);
_delete(): Promise<void>;

@@ -112,13 +112,2 @@ getSettings(): ConnectorConfig;

export declare class EmulatorTokenProvider implements AuthTokenProvider {
private accessToken;
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
static OWNER: string;
constructor(accessToken: string);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
addTokenChangeListener(listener: AuthTokenListener): void;
removeTokenChangeListener(listener: (token: string | null) => void): void;
notifyForInvalidToken(): void;
}
export declare function executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;

@@ -131,7 +120,7 @@

export declare class FirebaseAuthProvider implements AuthTokenProvider {
private appName;
private options;
private authProvider_;
private auth_;
constructor(appName: string, options: FirebaseOptions, authProvider_: Provider<FirebaseAuthInternalName>);
private _appName;
private _options;
private _authProvider;
private _auth;
constructor(_appName: string, _options: FirebaseOptions, _authProvider: Provider<FirebaseAuthInternalName>);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;

@@ -146,7 +135,9 @@ addTokenChangeListener(listener: AuthTokenListener): void;

export declare const MUTATION_STR = "mutation";
export declare class MutationManager {
private transport;
private _transport;
private _inflight;
constructor(transport: DataConnectTransport);
executeMutation<Response, Variables>(mutationRef: MutationRef<Response, Variables>): MutationPromise<Response, Variables>;
constructor(_transport: DataConnectTransport);
executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
}

@@ -157,9 +148,9 @@

export declare interface MutationRef<Response, Variables> extends OperationRef<Response, Variables> {
refType: typeof MutationStr;
export declare interface MutationRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof MUTATION_STR;
}
export declare function mutationRef<Response>(dcInstance: DataConnect, queryName: string): MutationRef<Response, undefined>;
export declare function mutationRef<Data>(dcInstance: DataConnect, queryName: string): MutationRef<Data, undefined>;
export declare function mutationRef<Response, Variables>(dcInstance: DataConnect, queryName: string, variables: Variables): MutationRef<Response, Variables>;
export declare function mutationRef<Data, Variables>(dcInstance: DataConnect, mutationName: string, variables: Variables): MutationRef<Data, Variables>;

@@ -173,4 +164,2 @@ export declare interface MutationResponse<T> extends CancellableOperation<T> {

export declare const MutationStr = "mutation";
export declare type OnCompleteSubscription = () => void;

@@ -197,8 +186,3 @@

export declare interface ProjectOptions {
location: string;
connector: string;
service: string;
projectId: string;
}
export declare const QUERY_STR = "query";

@@ -209,5 +193,5 @@ declare class QueryManager {

constructor(transport: DataConnectTransport);
track<Response, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Response>): TrackedQuery<unknown, unknown> | undefined;
addSubscription<Response, Variables>(queryRef: OperationRef<Response, Variables>, onResultCallback: OnResultSubscription<Response, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Response>): () => void;
executeQuery<Response, Variables>(queryRef: QueryRef<Response, Variables>): QueryPromise<Response, Variables>;
track<Data, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Data>): TrackedQuery<unknown, unknown>;
addSubscription<Data, Variables>(queryRef: OperationRef<Data, Variables>, onResultCallback: OnResultSubscription<Data, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Data>): () => void;
executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
enableEmulator(host: string, port: number): void;

@@ -220,3 +204,3 @@ }

export declare interface QueryRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof QueryStr;
refType: typeof QUERY_STR;
}

@@ -236,7 +220,5 @@

export declare const QueryStr = "query";
export declare type QueryUnsubscribe = () => void;
export declare type ReferenceType = typeof QueryStr | typeof MutationStr;
export declare type ReferenceType = typeof QUERY_STR | typeof MUTATION_STR;

@@ -283,10 +265,10 @@ export declare interface RefInfo<Variables> {

export declare function terminate(dataConnect: DataConnect): void;
export declare function terminate(dataConnect: DataConnect): Promise<void>;
export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<unknown, Variables>;
declare interface TrackedQuery<Response, Variables> {
ref: Omit<OperationRef<Response, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Response, Variables>>;
currentCache: OpResult<Response> | null;
declare interface TrackedQuery<Data, Variables> {
ref: Omit<OperationRef<Data, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Data, Variables>>;
currentCache: OpResult<Data> | null;
lastError: DataConnectError | null;

@@ -293,0 +275,0 @@ }

@@ -33,9 +33,5 @@ /**

private readonly dataConnectOptions;
private readonly authProvider;
isEmulator: boolean;
initialized: boolean;
private transportClass;
private transportOptions?;
private authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, authProvider: Provider<FirebaseAuthInternalName>);
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>);
getSettings(): ConnectorConfig;

@@ -69,12 +65,2 @@ setInitialized(): void;

export declare type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER;
export declare class EmulatorTokenProvider implements AuthTokenProvider {
private accessToken;
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
static OWNER: string;
constructor(accessToken: string);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
addTokenChangeListener(listener: AuthTokenListener): void;
removeTokenChangeListener(listener: (token: string | null) => void): void;
notifyForInvalidToken(): void;
}
export declare function executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;

@@ -84,7 +70,3 @@ export declare function executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;

export declare class FirebaseAuthProvider implements AuthTokenProvider {
private appName;
private options;
private authProvider_;
private auth_;
constructor(appName: string, options: FirebaseOptions, authProvider_: Provider<FirebaseAuthInternalName>);
constructor(_appName: string, _options: FirebaseOptions, _authProvider: Provider<FirebaseAuthInternalName>);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;

@@ -96,14 +78,14 @@ addTokenChangeListener(listener: AuthTokenListener): void;

export declare function getDataConnect(app: FirebaseApp, options: ConnectorConfig): DataConnect;
export declare const MUTATION_STR = "mutation";
export declare class MutationManager {
private transport;
constructor(transport: DataConnectTransport);
executeMutation<Response, Variables>(mutationRef: MutationRef<Response, Variables>): MutationPromise<Response, Variables>;
constructor(_transport: DataConnectTransport);
executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
}
export declare interface MutationPromise<Data, Variables> extends PromiseLike<MutationResult<Data, Variables>> {
}
export declare interface MutationRef<Response, Variables> extends OperationRef<Response, Variables> {
refType: typeof MutationStr;
export declare interface MutationRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof MUTATION_STR;
}
export declare function mutationRef<Response>(dcInstance: DataConnect, queryName: string): MutationRef<Response, undefined>;
export declare function mutationRef<Response, Variables>(dcInstance: DataConnect, queryName: string, variables: Variables): MutationRef<Response, Variables>;
export declare function mutationRef<Data>(dcInstance: DataConnect, queryName: string): MutationRef<Data, undefined>;
export declare function mutationRef<Data, Variables>(dcInstance: DataConnect, mutationName: string, variables: Variables): MutationRef<Data, Variables>;
export declare interface MutationResponse<T> extends CancellableOperation<T> {

@@ -114,3 +96,2 @@ }

}
export declare const MutationStr = "mutation";
export declare type OnCompleteSubscription = () => void;

@@ -131,12 +112,7 @@ export declare type OnErrorSubscription = (err?: FirebaseError) => void;

/* Excluded from this release type: parseOptions */
export declare interface ProjectOptions {
location: string;
connector: string;
service: string;
projectId: string;
}
export declare const QUERY_STR = "query";
export declare interface QueryPromise<Data, Variables> extends PromiseLike<QueryResult<Data, Variables>> {
}
export declare interface QueryRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof QueryStr;
refType: typeof QUERY_STR;
}

@@ -151,5 +127,4 @@ export declare function queryRef<Data>(dcInstance: DataConnect, queryName: string): QueryRef<Data, undefined>;

}
export declare const QueryStr = "query";
export declare type QueryUnsubscribe = () => void;
export declare type ReferenceType = typeof QueryStr | typeof MutationStr;
export declare type ReferenceType = typeof QUERY_STR | typeof MUTATION_STR;
export declare interface RefInfo<Variables> {

@@ -186,3 +161,3 @@ name: string;

}
export declare function terminate(dataConnect: DataConnect): void;
export declare function terminate(dataConnect: DataConnect): Promise<void>;
export declare function toQueryRef<Data, Variables>(serializedRef: SerializedRef<Data, Variables>): QueryRef<unknown, Variables>;

@@ -189,0 +164,0 @@ export declare type TransportClass = new (options: DataConnectOptions, apiKey?: string, authProvider?: AuthTokenProvider, transportOptions?: TransportOptions) => DataConnectTransport;

@@ -22,8 +22,2 @@ /**

import { MutationManager } from './Mutation';
export interface ProjectOptions {
location: string;
connector: string;
service: string;
projectId: string;
}
export interface ConnectorConfig {

@@ -53,3 +47,3 @@ location: string;

private readonly dataConnectOptions;
private readonly authProvider;
private readonly _authProvider;
_queryManager: QueryManager;

@@ -60,6 +54,6 @@ _mutationManager: MutationManager;

private _transport;
private transportClass;
private transportOptions?;
private authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, authProvider: Provider<FirebaseAuthInternalName>);
private _transportClass;
private _transportOptions?;
private _authTokenProvider?;
constructor(app: FirebaseApp, dataConnectOptions: DataConnectOptions, _authProvider: Provider<FirebaseAuthInternalName>);
_delete(): Promise<void>;

@@ -73,2 +67,2 @@ getSettings(): ConnectorConfig;

export declare function getDataConnect(app: FirebaseApp, options: ConnectorConfig): DataConnect;
export declare function terminate(dataConnect: DataConnect): void;
export declare function terminate(dataConnect: DataConnect): Promise<void>;

@@ -19,13 +19,13 @@ /**

import { DataConnect } from './DataConnect';
import { DataConnectResult, MutationStr, OperationRef } from './Reference';
export interface MutationRef<Response, Variables> extends OperationRef<Response, Variables> {
refType: typeof MutationStr;
import { DataConnectResult, MUTATION_STR, OperationRef } from './Reference';
export interface MutationRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof MUTATION_STR;
}
export declare function mutationRef<Response>(dcInstance: DataConnect, queryName: string): MutationRef<Response, undefined>;
export declare function mutationRef<Response, Variables>(dcInstance: DataConnect, queryName: string, variables: Variables): MutationRef<Response, Variables>;
export declare function mutationRef<Data>(dcInstance: DataConnect, queryName: string): MutationRef<Data, undefined>;
export declare function mutationRef<Data, Variables>(dcInstance: DataConnect, mutationName: string, variables: Variables): MutationRef<Data, Variables>;
export declare class MutationManager {
private transport;
private _transport;
private _inflight;
constructor(transport: DataConnectTransport);
executeMutation<Response, Variables>(mutationRef: MutationRef<Response, Variables>): MutationPromise<Response, Variables>;
constructor(_transport: DataConnectTransport);
executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;
}

@@ -32,0 +32,0 @@ export interface MutationResult<Data, Variables> extends DataConnectResult<Data, Variables> {

@@ -19,3 +19,3 @@ /**

import { DataConnect } from './DataConnect';
import { OperationRef, QueryStr, DataConnectResult, SerializedRef } from './Reference';
import { OperationRef, QUERY_STR, DataConnectResult, SerializedRef } from './Reference';
export declare type OnResultSubscription<Data, Variables> = (res: QueryResult<Data, Variables>) => void;

@@ -30,3 +30,3 @@ export declare type OnErrorSubscription = (err?: DataConnectError) => void;

export interface QueryRef<Data, Variables> extends OperationRef<Data, Variables> {
refType: typeof QueryStr;
refType: typeof QUERY_STR;
}

@@ -33,0 +33,0 @@ export interface QueryResult<Data, Variables> extends DataConnectResult<Data, Variables> {

@@ -18,5 +18,5 @@ /**

import { DataConnect, DataConnectOptions } from './DataConnect';
export declare const QueryStr = "query";
export declare const MutationStr = "mutation";
export declare type ReferenceType = typeof QueryStr | typeof MutationStr;
export declare const QUERY_STR = "query";
export declare const MUTATION_STR = "mutation";
export declare type ReferenceType = typeof QUERY_STR | typeof MUTATION_STR;
export declare const SOURCE_SERVER = "SERVER";

@@ -23,0 +23,0 @@ export declare const SOURCE_CACHE = "CACHE";

@@ -26,7 +26,7 @@ /**

export declare class FirebaseAuthProvider implements AuthTokenProvider {
private appName;
private options;
private authProvider_;
private auth_;
constructor(appName: string, options: FirebaseOptions, authProvider_: Provider<FirebaseAuthInternalName>);
private _appName;
private _options;
private _authProvider;
private _auth;
constructor(_appName: string, _options: FirebaseOptions, _authProvider: Provider<FirebaseAuthInternalName>);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData | null>;

@@ -36,11 +36,1 @@ addTokenChangeListener(listener: AuthTokenListener): void;

}
export declare class EmulatorTokenProvider implements AuthTokenProvider {
private accessToken;
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
static OWNER: string;
constructor(accessToken: string);
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
addTokenChangeListener(listener: AuthTokenListener): void;
removeTokenChangeListener(listener: (token: string | null) => void): void;
notifyForInvalidToken(): void;
}

@@ -21,6 +21,6 @@ /**

import { DataConnectError } from './error';
interface TrackedQuery<Response, Variables> {
ref: Omit<OperationRef<Response, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Response, Variables>>;
currentCache: OpResult<Response> | null;
interface TrackedQuery<Data, Variables> {
ref: Omit<OperationRef<Data, Variables>, 'dataConnect'>;
subscriptions: Array<DataConnectSubscription<Data, Variables>>;
currentCache: OpResult<Data> | null;
lastError: DataConnectError | null;

@@ -32,7 +32,7 @@ }

constructor(transport: DataConnectTransport);
track<Response, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Response>): TrackedQuery<unknown, unknown> | undefined;
addSubscription<Response, Variables>(queryRef: OperationRef<Response, Variables>, onResultCallback: OnResultSubscription<Response, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Response>): () => void;
executeQuery<Response, Variables>(queryRef: QueryRef<Response, Variables>): QueryPromise<Response, Variables>;
track<Data, Variables>(queryName: string, variables: Variables, initialCache?: OpResult<Data>): TrackedQuery<unknown, unknown>;
addSubscription<Data, Variables>(queryRef: OperationRef<Data, Variables>, onResultCallback: OnResultSubscription<Data, Variables>, onErrorCallback?: OnErrorSubscription, initialCache?: OpResult<Data>): () => void;
executeQuery<Data, Variables>(queryRef: QueryRef<Data, Variables>): QueryPromise<Data, Variables>;
enableEmulator(host: string, port: number): void;
}
export {};

@@ -17,5 +17,5 @@ /**

*/
import { LogLevelString } from "@firebase/logger";
import { LogLevelString } from '@firebase/logger';
export declare function setLogLevel(logLevel: LogLevelString): void;
export declare function logDebug(msg: string): void;
export declare function logError(msg: string): void;

@@ -17,17 +17,17 @@ /**

*/
import { DataConnectTransport } from '.';
import { DataConnectOptions, TransportOptions } from '../../api/DataConnect';
import { AuthTokenProvider } from '../../core/FirebaseAuthProvider';
import { DataConnectTransport } from '.';
export declare class RESTTransport implements DataConnectTransport {
private apiKey?;
private authProvider?;
private host;
private port;
private location;
private connectorName;
private secure;
private project;
private serviceName;
private accessToken;
private authInitialized_;
private _host;
private _port;
private _location;
private _connectorName;
private _secure;
private _project;
private _serviceName;
private _accessToken;
private _authInitialized;
constructor(options: DataConnectOptions, apiKey?: string | undefined, authProvider?: AuthTokenProvider | undefined, transportOptions?: TransportOptions | undefined);

@@ -37,22 +37,10 @@ get endpointUrl(): string;

onTokenChanged(newToken: string | null): void;
getWithAuth(): Promise<string | null>;
getWithAuth(): Promise<string>;
invokeQuery: <T, U = unknown>(queryName: string, body: U) => {
then: <TResult1 = {
data: T;
errors: Error[];
}, TResult2 = never>(onfulfilled?: ((value: {
data: T;
errors: Error[];
}) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
then: any;
};
invokeMutation: <T, U = unknown>(mutationName: string, body: U) => {
then: <TResult1 = {
data: T;
errors: Error[];
}, TResult2 = never>(onfulfilled?: ((value: {
data: T;
errors: Error[];
}) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
then: any;
cancel: () => void;
};
}

@@ -17,4 +17,4 @@ /**

*/
import { ProjectOptions, TransportOptions } from '../api/DataConnect';
export declare function urlBuilder(projectConfig: ProjectOptions, transportOptions: TransportOptions): string;
import { DataConnectOptions, TransportOptions } from '../api/DataConnect';
export declare function urlBuilder(projectConfig: DataConnectOptions, transportOptions: TransportOptions): string;
export declare function addToken(url: string, apiKey?: string): string;
{
"name": "@firebase/data-connect",
"version": "0.0.1-dataconnect-preview.f2ddc3d7b",
"version": "0.0.2-dataconnect-preview.877f8b7d0",
"description": "",

@@ -36,3 +36,3 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",

"dev": "rollup -c -w",
"test": "run-p --npm-path npm lint test:emulator",
"test": "run-p --npm-path npm test:emulator",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:emulator",

@@ -47,13 +47,13 @@ "test:all": "npm run test:node",

"typings:public": "node ../../scripts/build/use_typings.js ./dist/public.d.ts"
},
},
"license": "Apache-2.0",
"dependencies": {
"@firebase/auth-interop-types": "0.2.2",
"@firebase/component": "0.6.6",
"@firebase/logger": "0.4.1",
"@firebase/util": "1.9.5",
"@firebase/auth-interop-types": "0.2.3-dataconnect-preview.877f8b7d0",
"@firebase/component": "0.6.7-dataconnect-preview.877f8b7d0",
"@firebase/logger": "0.4.2-dataconnect-preview.877f8b7d0",
"@firebase/util": "1.9.6-dataconnect-preview.877f8b7d0",
"tslib": "^2.1.0"
},
"devDependencies": {
"@firebase/app": "0.10.2",
"@firebase/app": "0.10.3-dataconnect-preview.877f8b7d0",
"rollup": "2.79.1",

@@ -71,3 +71,3 @@ "rollup-plugin-typescript2": "0.31.2",

},
"typings": "dist/src/index.d.ts",
"typings": "./dist/public.d.ts",
"nyc": {

@@ -74,0 +74,0 @@ "extension": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc