Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
@@ -0,0 +1,38 @@
|
||||
const {
|
||||
RtcTokenBuilder,
|
||||
RtmTokenBuilder,
|
||||
RtcRole,
|
||||
RtmRole,
|
||||
} = require('agora-access-token');
|
||||
|
||||
function getAgoraToken(req, res) {
|
||||
// Rtc Examples
|
||||
const appID = 'c8dfd65deb5c4741bd564085627139d0';
|
||||
const appCertificate = 'aa57b809934b4efcb407cf30089d9f25';
|
||||
const channelName = req.params.channelName;
|
||||
const uid = 0; // no need to use this as we have authenticated this user
|
||||
const role = RtcRole.PUBLISHER;
|
||||
|
||||
const expirationTimeInSeconds = 3600;
|
||||
|
||||
const currentTimestamp = Math.floor(Date.now() / 1000);
|
||||
|
||||
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds;
|
||||
|
||||
// IMPORTANT! Build token with either the uid or with the user account. Comment out the option you do not want to use below.
|
||||
|
||||
// Build token with uid
|
||||
const tokenA = RtcTokenBuilder.buildTokenWithUid(
|
||||
appID,
|
||||
appCertificate,
|
||||
channelName,
|
||||
uid,
|
||||
role,
|
||||
privilegeExpiredTs
|
||||
);
|
||||
console.log('Token With Integer Number Uid: ' + tokenA);
|
||||
|
||||
res.status(200).send({ token: tokenA });
|
||||
}
|
||||
|
||||
module.exports = { getAgoraToken };
|
||||
@@ -0,0 +1,10 @@
|
||||
var admin = require('firebase-admin');
|
||||
|
||||
var serviceAccount = require('./firebaseServiceKey.json');
|
||||
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert(serviceAccount),
|
||||
databaseURL: 'https://nirvana.',
|
||||
});
|
||||
|
||||
module.exports = { admin };
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "nirvana-ccf04",
|
||||
"private_key_id": "01df72847e28a2e061d3a15a915a367b08569087",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC8UG8Q6FLwx90o\ndwk2Q9mhnOJOpPDDmxa0Wc5qlIWD9SmoHwdH5ljbXhsvmxW3jNua17h0Xqt5t4T8\n+x4ibxNpEeHV3G5n3q5TcwW4GUB4ZjEP7JmoHDT2bd+fw2+pcBt36MUcE1MKBr+W\ny88Yu6VQZrAPV8qDYmys3TQTcyjl55LFE7gZBUwbEhnSeQo3V09XfOO1Ejs/1JlX\nj3AiHjfKYAFyVllDQwBYAr+cxWpcCkcmXfxKw+RiM70mBk+lqCRzoVEnSnEUbtN/\n0SPmAd38SzUvLc9t9qFlX012FS+b2yrlbi6kNLMkREYicbRz7OIvkKq5G2MsU8Vw\nubJzBih5AgMBAAECggEAAVWum9eRsuwvuJgzZAOSGM+kWPtZS4GfZRLX4DCCS7+i\nlnL12cAbtB5UIf++5Sil69CImaaMH5Y55pMfEQ5pfE6oo5vm2mydHrFLgpUHPHM4\n+MxsAGGGzJJVyeuYMIK/ZxeqwfqvFXybwgVax+mYj9vSdqFgKZM6gvUkZ9jimtKI\nvkNUpCR75j1vTKn0pSFQoqbCOPfRxh2U91sJqPK/wnwrw9OzTgJagVlrGaRJv7+L\nQsvsJUqKUTbIytQjW43dbAGnBwXK8hK+dUdRapyUrtigCrwua1gSx5cLfQZB+jqn\n/tJlbbfEbh6cfHX4E4xUuBkh7lzb45QIe1uwXY7bEwKBgQDg7SuPYuVgBSo+qser\nVnVY1q4jf6r1l+hwA1pYM52USXMnOVolUWPxgN4ua3K8jYLyX/7gJGRDdo+ASwD7\nAvbX6yyGz/+WUj+aCukmXj5DneWY3rRX9YDrPxjEtAO1WnsZDmruOYAvDPAMRHCx\n05ip+KxN+EGAMtogQTUBA4I7cwKBgQDWVGvulPznAIDF4dWTMER4CYvbo+HD5o4m\nDny7WXjO6fQnqFUjS55KzUO730QiWc2YYE+1zClIUuwoIDncYhZxziIaKIuhPUHy\nEqcgA8UYERGf+UXZ1VRMyykBatqjmO5pwdqbA8+3Ig2fgtEKm7IKO+8X3VmcMFsG\nPpSNed1pYwKBgEhRGNNGGbdwka+KWx4kcyA4Dc8OChpiV/JDsbVwCvcVUnfHAcvD\nyl1ocIb+NuqWmQZyhNDuAmqKYQL/mnYZ8uFjFHLXxzY+hYJyhZm3bU9yIdKvr84j\n+eoo5D7CHfsd9zwMHacwR51ZDIj1LEKQZKIpeMSsz+p27xi1vmPwC9wvAoGAa5T0\nmE0wpMMb4Df7fGY9+ALSsO0R5cNUlsWu1luSyEmmxEE6evz595IQ7byj9podGN8/\nI4HXNvZok7uZT4XsvjM56udvLwAQmfHC8c7yn6HxttrotO7f4awYaR25oWSiR3OG\nx0iiesodDHQdebWtKHXtDY2N7VhYWEoRRvJksQECgYBXcU97IPj8ZPZRBgo5OXVV\n9zkxx0/pFTmdozDw33KdconmQ41ca8wVOm0a38WnHpK3Wwop3FXJPHZe86Gyf+IX\n+HDqztHP/VSFo78yU7dtCUJvoqmxHJhqtvnCtNXN5s3IDsoa8ziVGGX2OXqbsQeS\nbtMdDIMtiyCgZFY097yYKQ==\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "firebase-adminsdk-nvjav@nirvana-ccf04.iam.gserviceaccount.com",
|
||||
"client_id": "109413001593852775982",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-nvjav%40nirvana-ccf04.iam.gserviceaccount.com"
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
const express = require('express');
|
||||
var path = require('path');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
var cookieParser = require('cookie-parser');
|
||||
var logger = require('morgan');
|
||||
const cors = require('cors');
|
||||
|
||||
app.use(cors());
|
||||
app.use(logger('dev'));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
|
||||
const routes = require('./routes');
|
||||
|
||||
const firebase = require('./firebase-setup');
|
||||
|
||||
// auth middleware
|
||||
function checkAuth(req, res, next) {
|
||||
if (req.headers.authorization) {
|
||||
firebase.admin
|
||||
.auth()
|
||||
.verifyIdToken(req.headers.authorization)
|
||||
.then((decodedToken) => {
|
||||
let uid = decodedToken.uid;
|
||||
console.log('user Id is ' + uid);
|
||||
res.locals.uid = decodedToken.uid;
|
||||
next();
|
||||
})
|
||||
.catch(() => {
|
||||
res.status(403).send('Unauthorized');
|
||||
});
|
||||
} else {
|
||||
res.status(403).send('Unauthorized');
|
||||
}
|
||||
}
|
||||
|
||||
app.use('/', checkAuth);
|
||||
|
||||
// hello world endpoint
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello World!');
|
||||
});
|
||||
|
||||
// agora token generator
|
||||
const agora = require('./agora');
|
||||
app.get(routes.agoraToken, agora.getAgoraToken);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening at http://localhost:${port}`);
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
../google-gax/build/tools/compileProtos.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../crc-32/bin/crc32.njs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../gcs-resumable-upload/build/src/cli.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../google-p12-pem/build/src/bin/gp12-pem.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../is-ci/bin.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../mime/cli.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../nodemon/bin/nodemon.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../touch/bin/nodetouch.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../nopt/bin/nopt.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../protobufjs/bin/pbjs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../protobufjs/bin/pbts
|
||||
+1
@@ -0,0 +1 @@
|
||||
../printj/bin/printj.njs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../@grpc/proto-loader/build/bin/proto-loader-gen-types.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../rc/cli.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../semver/bin/semver.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../uuid/dist/bin/uuid
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# @firebase/app-types
|
||||
|
||||
## 0.7.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [`cdada6c68`](https://github.com/firebase/firebase-js-sdk/commit/cdada6c68f9740d13dd6674bcb658e28e68253b6) [#5345](https://github.com/firebase/firebase-js-sdk/pull/5345) (fixes [#5015](https://github.com/firebase/firebase-js-sdk/issues/5015)) - Release modularized SDKs
|
||||
|
||||
## 0.6.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`3d10d33bc`](https://github.com/firebase/firebase-js-sdk/commit/3d10d33bc167177fecbf86d2a6574af2e4e210f9) [#5144](https://github.com/firebase/firebase-js-sdk/pull/5144) - Add @firebase/logger as a dependency to @firebase/app-types to ensure that it can be resolved when compiling the package in a strict yarn PnP environment.
|
||||
|
||||
## 0.6.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`f24d8961b`](https://github.com/firebase/firebase-js-sdk/commit/f24d8961b3b87821413297688803fc85113086b3) [#4714](https://github.com/firebase/firebase-js-sdk/pull/4714) - Internal typing changes
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# @firebase/app-types
|
||||
|
||||
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { LogCallback, LogLevelString, LogOptions } from '@firebase/logger';
|
||||
|
||||
export type FirebaseOptions = {
|
||||
apiKey?: string;
|
||||
authDomain?: string;
|
||||
databaseURL?: string;
|
||||
projectId?: string;
|
||||
storageBucket?: string;
|
||||
messagingSenderId?: string;
|
||||
appId?: string;
|
||||
measurementId?: string;
|
||||
};
|
||||
|
||||
export interface FirebaseAppConfig {
|
||||
name?: string;
|
||||
automaticDataCollectionEnabled?: boolean;
|
||||
}
|
||||
|
||||
export class FirebaseApp {
|
||||
/**
|
||||
* The (read-only) name (identifier) for this App. '[DEFAULT]' is the default
|
||||
* App.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The (read-only) configuration options from the app initialization.
|
||||
*/
|
||||
options: FirebaseOptions;
|
||||
|
||||
/**
|
||||
* The settable config flag for GDPR opt-in/opt-out
|
||||
*/
|
||||
automaticDataCollectionEnabled: boolean;
|
||||
|
||||
/**
|
||||
* Make the given App unusable and free resources.
|
||||
*/
|
||||
delete(): Promise<void>;
|
||||
}
|
||||
|
||||
export interface FirebaseNamespace {
|
||||
/**
|
||||
* Create (and initialize) a FirebaseApp.
|
||||
*
|
||||
* @param options Options to configure the services used in the App.
|
||||
* @param config The optional config for your firebase app
|
||||
*/
|
||||
initializeApp(
|
||||
options: FirebaseOptions,
|
||||
config?: FirebaseAppConfig
|
||||
): FirebaseApp;
|
||||
/**
|
||||
* Create (and initialize) a FirebaseApp.
|
||||
*
|
||||
* @param options Options to configure the services used in the App.
|
||||
* @param name The optional name of the app to initialize ('[DEFAULT]' if
|
||||
* omitted)
|
||||
*/
|
||||
initializeApp(options: FirebaseOptions, name?: string): FirebaseApp;
|
||||
|
||||
app: {
|
||||
/**
|
||||
* Retrieve an instance of a FirebaseApp.
|
||||
*
|
||||
* Usage: firebase.app()
|
||||
*
|
||||
* @param name The optional name of the app to return ('[DEFAULT]' if omitted)
|
||||
*/
|
||||
(name?: string): FirebaseApp;
|
||||
|
||||
/**
|
||||
* For testing FirebaseApp instances:
|
||||
* app() instanceof firebase.app.App
|
||||
*
|
||||
* DO NOT call this constuctor directly (use firebase.app() instead).
|
||||
*/
|
||||
App: typeof FirebaseApp;
|
||||
};
|
||||
|
||||
/**
|
||||
* A (read-only) array of all the initialized Apps.
|
||||
*/
|
||||
apps: FirebaseApp[];
|
||||
|
||||
/**
|
||||
* Registers a library's name and version for platform logging purposes.
|
||||
* @param library Name of 1p or 3p library (e.g. firestore, angularfire)
|
||||
* @param version Current version of that library.
|
||||
*/
|
||||
registerVersion(library: string, version: string, variant?: string): void;
|
||||
|
||||
// Sets log level for all Firebase components.
|
||||
setLogLevel(logLevel: LogLevelString): void;
|
||||
|
||||
// Sets log handler for all Firebase components.
|
||||
onLog(logCallback: LogCallback, options?: LogOptions): void;
|
||||
|
||||
// The current SDK version.
|
||||
SDK_VERSION: string;
|
||||
}
|
||||
|
||||
export interface VersionService {
|
||||
library: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
declare module '@firebase/component' {
|
||||
interface NameServiceMapping {
|
||||
'app-version': VersionService;
|
||||
'platform-identifier': VersionService;
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"_from": "@firebase/app-types@0.7.0",
|
||||
"_id": "@firebase/app-types@0.7.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-6fbHQwDv2jp/v6bXhBw2eSRbNBpxHcd1NBF864UksSMVIqIyri9qpJB1Mn6sGZE+bnDsSQBC5j2TbMxYsJQkQg==",
|
||||
"_location": "/@firebase/app-types",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@firebase/app-types@0.7.0",
|
||||
"name": "@firebase/app-types",
|
||||
"escapedName": "@firebase%2fapp-types",
|
||||
"scope": "@firebase",
|
||||
"rawSpec": "0.7.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.7.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@firebase/database-compat/@firebase/database-types"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@firebase/app-types/-/app-types-0.7.0.tgz",
|
||||
"_shasum": "c9e16d1b8bed1a991840b8d2a725fb58d0b5899f",
|
||||
"_spec": "@firebase/app-types@0.7.0",
|
||||
"_where": "/Users/talksik/Development/nirvana-server/node_modules/@firebase/database-compat/node_modules/@firebase/database-types",
|
||||
"author": {
|
||||
"name": "Firebase",
|
||||
"email": "firebase-support@google.com",
|
||||
"url": "https://firebase.google.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/firebase/firebase-js-sdk/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependency": {
|
||||
"@firebase/logger": "0.2.6"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "@firebase/app Types",
|
||||
"devDependencies": {
|
||||
"typescript": "4.2.2"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"private.d.ts"
|
||||
],
|
||||
"homepage": "https://github.com/firebase/firebase-js-sdk#readme",
|
||||
"license": "Apache-2.0",
|
||||
"name": "@firebase/app-types",
|
||||
"repository": {
|
||||
"directory": "packages/app-types",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/firebase/firebase-js-sdk.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tsc",
|
||||
"test:ci": "node ../../scripts/run_tests_in_ci.js"
|
||||
},
|
||||
"version": "0.7.0"
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* THIS FILE IS FOR INTERNAL USAGE ONLY, IF YOU ARE NOT DEVELOPING THE FIREBASE
|
||||
* SDKs, PLEASE DO NOT REFERENCE THIS FILE AS IT MAY CHANGE WITHOUT WARNING
|
||||
*/
|
||||
|
||||
import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
|
||||
import { Observer, Subscribe } from '@firebase/util';
|
||||
import { FirebaseError, ErrorFactory } from '@firebase/util';
|
||||
import { Component, ComponentContainer, Name } from '@firebase/component';
|
||||
|
||||
export interface FirebaseServiceInternals {
|
||||
/**
|
||||
* Delete the service and free it's resources - called from
|
||||
* app.delete().
|
||||
*/
|
||||
delete(): Promise<void>;
|
||||
}
|
||||
|
||||
// Services are exposed through instances - each of which is associated with a
|
||||
// FirebaseApp.
|
||||
export interface FirebaseService {
|
||||
app: FirebaseApp;
|
||||
INTERNAL?: FirebaseServiceInternals;
|
||||
}
|
||||
|
||||
export type AppHook = (event: string, app: FirebaseApp) => void;
|
||||
|
||||
/**
|
||||
* Firebase Services create instances given a Firebase App instance and can
|
||||
* optionally add properties and methods to each FirebaseApp via the extendApp()
|
||||
* function.
|
||||
*/
|
||||
export interface FirebaseServiceFactory {
|
||||
(
|
||||
app: FirebaseApp,
|
||||
extendApp?: (props: { [prop: string]: any }) => void,
|
||||
instanceString?: string
|
||||
): FirebaseService;
|
||||
}
|
||||
|
||||
export interface PlatformLoggerService {
|
||||
getPlatformInfoString(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* All ServiceNamespaces extend from FirebaseServiceNamespace
|
||||
*/
|
||||
export interface FirebaseServiceNamespace<T extends FirebaseService> {
|
||||
(app?: FirebaseApp): T;
|
||||
}
|
||||
|
||||
export interface FirebaseAuthTokenData {
|
||||
accessToken: string;
|
||||
}
|
||||
|
||||
export interface FirebaseAppInternals {
|
||||
getToken(refreshToken?: boolean): Promise<FirebaseAuthTokenData | null>;
|
||||
getUid(): string | null;
|
||||
addAuthTokenListener(fn: (token: string | null) => void): void;
|
||||
removeAuthTokenListener(fn: (token: string | null) => void): void;
|
||||
analytics: {
|
||||
logEvent: (
|
||||
eventName: string,
|
||||
eventParams: { [key: string]: any },
|
||||
options?: { global: boolean }
|
||||
) => void;
|
||||
};
|
||||
}
|
||||
|
||||
export interface _FirebaseApp extends FirebaseApp {
|
||||
container: ComponentContainer;
|
||||
_addComponent<T extends Name>(component: Component<T>): void;
|
||||
_addOrOverwriteComponent<T extends Name>(component: Component<T>): void;
|
||||
_removeServiceInstance(name: string, instanceIdentifier?: string): void;
|
||||
}
|
||||
export interface _FirebaseNamespace extends FirebaseNamespace {
|
||||
INTERNAL: {
|
||||
/**
|
||||
* Internal API to register a Firebase Service into the firebase namespace.
|
||||
*
|
||||
* Each service will create a child namespace (firebase.<name>) which acts as
|
||||
* both a namespace for service specific properties, and also as a service
|
||||
* accessor function (firebase.<name>() or firebase.<name>(app)).
|
||||
*
|
||||
* @param name The Firebase Service being registered.
|
||||
* @param createService Factory function to create a service instance.
|
||||
* @param serviceProperties Properties to copy to the service's namespace.
|
||||
* @param appHook All appHooks called before initializeApp returns to caller.
|
||||
* @param allowMultipleInstances Whether the registered service supports
|
||||
* multiple instances per app. If not specified, the default is false.
|
||||
*/
|
||||
registerComponent<T extends Name>(
|
||||
component: Component<T>
|
||||
): FirebaseServiceNamespace<FirebaseService> | null;
|
||||
|
||||
/**
|
||||
* Just used for testing to start from a fresh namespace.
|
||||
*/
|
||||
createFirebaseNamespace(): FirebaseNamespace;
|
||||
|
||||
/**
|
||||
* Internal API to install properties on the top-level firebase namespace.
|
||||
* @prop props The top level properties of this object are copied to the
|
||||
* namespace.
|
||||
*/
|
||||
extendNamespace(props: { [prop: string]: any }): void;
|
||||
|
||||
/**
|
||||
* Create a Subscribe function. A proxy Observer is created so that
|
||||
* events can be sent to single Observer to be fanned out automatically.
|
||||
*/
|
||||
createSubscribe<T>(
|
||||
executor: (observer: Observer<T>) => void,
|
||||
onNoObservers?: (observer: Observer<T>) => void
|
||||
): Subscribe<T>;
|
||||
|
||||
/**
|
||||
* Utility exposed for internal testing.
|
||||
*/
|
||||
deepExtend(target: any, source: any): any;
|
||||
|
||||
/**
|
||||
* Internal API to remove an app from the list of registered apps.
|
||||
*/
|
||||
removeApp(name: string): void;
|
||||
|
||||
/**
|
||||
* registered components.
|
||||
*/
|
||||
components: Map<string, Component>;
|
||||
|
||||
/*
|
||||
* Convert service name to factory name to use.
|
||||
*/
|
||||
useAsService(app: FirebaseApp, serviceName: string): string | null;
|
||||
|
||||
/**
|
||||
* Use to construct all thrown FirebaseError's.
|
||||
*/
|
||||
ErrorFactory: typeof ErrorFactory;
|
||||
};
|
||||
}
|
||||
|
||||
declare module '@firebase/component' {
|
||||
interface NameServiceMapping {
|
||||
'platform-logger': PlatformLoggerService;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
# @firebase/auth-interop-types
|
||||
|
||||
## 0.1.6
|
||||
### Patch Changes
|
||||
|
||||
|
||||
|
||||
- [`3f370215a`](https://github.com/firebase/firebase-js-sdk/commit/3f370215aa571db6b41b92a7d8a9aaad2ea0ecd0) [#4808](https://github.com/firebase/firebase-js-sdk/pull/4808) (fixes [#4789](https://github.com/firebase/firebase-js-sdk/issues/4789)) - Update peerDependencies
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# @firebase/auth-interop-types
|
||||
|
||||
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
export interface FirebaseAuthTokenData {
|
||||
accessToken: string;
|
||||
}
|
||||
|
||||
export interface FirebaseAuthInternal {
|
||||
getToken(refreshToken?: boolean): Promise<FirebaseAuthTokenData | null>;
|
||||
getUid(): string | null;
|
||||
addAuthTokenListener(fn: (token: string | null) => void): void;
|
||||
removeAuthTokenListener(fn: (token: string | null) => void): void;
|
||||
}
|
||||
|
||||
export type FirebaseAuthInternalName = 'auth-internal';
|
||||
|
||||
declare module '@firebase/component' {
|
||||
interface NameServiceMapping {
|
||||
'auth-internal': FirebaseAuthInternal;
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"_from": "@firebase/auth-interop-types@0.1.6",
|
||||
"_id": "@firebase/auth-interop-types@0.1.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-etIi92fW3CctsmR9e3sYM3Uqnoq861M0Id9mdOPF6PWIg38BXL5k4upCNBggGUpLIS0H1grMOvy/wn1xymwe2g==",
|
||||
"_location": "/@firebase/auth-interop-types",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@firebase/auth-interop-types@0.1.6",
|
||||
"name": "@firebase/auth-interop-types",
|
||||
"escapedName": "@firebase%2fauth-interop-types",
|
||||
"scope": "@firebase",
|
||||
"rawSpec": "0.1.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.1.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@firebase/database"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@firebase/auth-interop-types/-/auth-interop-types-0.1.6.tgz",
|
||||
"_shasum": "5ce13fc1c527ad36f1bb1322c4492680a6cf4964",
|
||||
"_spec": "@firebase/auth-interop-types@0.1.6",
|
||||
"_where": "/Users/talksik/Development/nirvana-server/node_modules/@firebase/database",
|
||||
"author": {
|
||||
"name": "Firebase",
|
||||
"email": "firebase-support@google.com",
|
||||
"url": "https://firebase.google.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/firebase/firebase-js-sdk/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "@firebase/auth interop Types",
|
||||
"devDependencies": {
|
||||
"typescript": "4.2.2"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts"
|
||||
],
|
||||
"homepage": "https://github.com/firebase/firebase-js-sdk#readme",
|
||||
"license": "Apache-2.0",
|
||||
"name": "@firebase/auth-interop-types",
|
||||
"peerDependencies": {
|
||||
"@firebase/app-types": "0.x",
|
||||
"@firebase/util": "1.x"
|
||||
},
|
||||
"repository": {
|
||||
"directory": "packages/auth-types",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/firebase/firebase-js-sdk.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tsc",
|
||||
"test:ci": "node ../../scripts/run_tests_in_ci.js"
|
||||
},
|
||||
"version": "0.1.6"
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
# @firebase/component
|
||||
|
||||
## 0.5.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`3281315fa`](https://github.com/firebase/firebase-js-sdk/commit/3281315fae9c6f535f9d5052ee17d60861ea569a) [#5708](https://github.com/firebase/firebase-js-sdk/pull/5708) (fixes [#1487](https://github.com/firebase/firebase-js-sdk/issues/1487)) - Update build scripts to work with the exports field
|
||||
|
||||
- Updated dependencies [[`3281315fa`](https://github.com/firebase/firebase-js-sdk/commit/3281315fae9c6f535f9d5052ee17d60861ea569a)]:
|
||||
- @firebase/util@1.4.2
|
||||
|
||||
## 0.5.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`2322b6023`](https://github.com/firebase/firebase-js-sdk/commit/2322b6023c628cd9f4f4172767c17d215dd91684) [#5693](https://github.com/firebase/firebase-js-sdk/pull/5693) - Add exports field to all packages
|
||||
|
||||
- Updated dependencies [[`2322b6023`](https://github.com/firebase/firebase-js-sdk/commit/2322b6023c628cd9f4f4172767c17d215dd91684)]:
|
||||
- @firebase/util@1.4.1
|
||||
|
||||
## 0.5.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a99943fe3`](https://github.com/firebase/firebase-js-sdk/commit/a99943fe3bd5279761aa29d138ec91272b06df39), [`b835b4cba`](https://github.com/firebase/firebase-js-sdk/commit/b835b4cbabc4b7b180ae38b908c49205ce31a422)]:
|
||||
- @firebase/util@1.4.0
|
||||
|
||||
## 0.5.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`bb6b5abff`](https://github.com/firebase/firebase-js-sdk/commit/bb6b5abff6f89ce9ec1bd66ff4e795a059a98eec) [#5272](https://github.com/firebase/firebase-js-sdk/pull/5272) - Store instance initialization options on the Provider.
|
||||
|
||||
- Updated dependencies [[`3c6a11c8d`](https://github.com/firebase/firebase-js-sdk/commit/3c6a11c8d0b35afddb50e9c3e0c4d2e30f642131)]:
|
||||
- @firebase/util@1.3.0
|
||||
|
||||
## 0.5.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a3cbe719b`](https://github.com/firebase/firebase-js-sdk/commit/a3cbe719b1bd733a5c4c15ee0d0e6388d512054c)]:
|
||||
- @firebase/util@1.2.0
|
||||
|
||||
## 0.5.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`56a6a9d4a`](https://github.com/firebase/firebase-js-sdk/commit/56a6a9d4af2766154584a0f66d3c4d8024d74ba5) [#5071](https://github.com/firebase/firebase-js-sdk/pull/5071) (fixes [#4932](https://github.com/firebase/firebase-js-sdk/issues/4932)) - Auto initialize `auth-internal` after `auth` has been initialized.
|
||||
|
||||
## 0.5.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`725ab4684`](https://github.com/firebase/firebase-js-sdk/commit/725ab4684ef0999a12f71e704c204a00fb030e5d) [#5023](https://github.com/firebase/firebase-js-sdk/pull/5023) (fixes [#5018](https://github.com/firebase/firebase-js-sdk/issues/5018)) - Pass the instance to onInit callback
|
||||
|
||||
## 0.5.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`4c4b6aed9`](https://github.com/firebase/firebase-js-sdk/commit/4c4b6aed9757c9a7e75fb698a15e53274f93880b) [#4971](https://github.com/firebase/firebase-js-sdk/pull/4971) - Fixes a regression that prevented Firestore from detecting Auth during its initial initialization, which could cause some writes to not be send.
|
||||
|
||||
## 0.5.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`5fbc5fb01`](https://github.com/firebase/firebase-js-sdk/commit/5fbc5fb0140d7da980fd7ebbfbae810f8c64ae19) [#4911](https://github.com/firebase/firebase-js-sdk/pull/4911) - handle `undefined` correctly from input.
|
||||
|
||||
## 0.5.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [`c34ac7a92`](https://github.com/firebase/firebase-js-sdk/commit/c34ac7a92a616915f38d192654db7770d81747ae) [#4866](https://github.com/firebase/firebase-js-sdk/pull/4866) - Support onInit callback in provider
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`ac4ad08a2`](https://github.com/firebase/firebase-js-sdk/commit/ac4ad08a284397ec966e991dd388bb1fba857467)]:
|
||||
- @firebase/util@1.1.0
|
||||
|
||||
## 0.4.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`7354a0ed4`](https://github.com/firebase/firebase-js-sdk/commit/7354a0ed438f4e3df6577e4927e8c8f8f1fbbfda)]:
|
||||
- @firebase/util@1.0.0
|
||||
|
||||
## 0.4.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [`f24d8961b`](https://github.com/firebase/firebase-js-sdk/commit/f24d8961b3b87821413297688803fc85113086b3) [#4714](https://github.com/firebase/firebase-js-sdk/pull/4714) - Support new instantiation mode `EXPLICIT`
|
||||
|
||||
## 0.3.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`de5f90501`](https://github.com/firebase/firebase-js-sdk/commit/de5f9050137acc9ed1490082e5aa429b5de3cb2a)]:
|
||||
- @firebase/util@0.4.1
|
||||
|
||||
## 0.3.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [`5c1a83ed7`](https://github.com/firebase/firebase-js-sdk/commit/5c1a83ed70bae979322bd8751c0885d683ce4bf3) [#4595](https://github.com/firebase/firebase-js-sdk/pull/4595) - Component facotry now takes an options object. And added `Provider.initialize()` that can be used to pass an options object to the component factory.
|
||||
|
||||
## 0.2.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`ec95df3d0`](https://github.com/firebase/firebase-js-sdk/commit/ec95df3d07e5f091f2a7f7327e46417f64d04b4e)]:
|
||||
- @firebase/util@0.4.0
|
||||
|
||||
## 0.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [`6afe42613`](https://github.com/firebase/firebase-js-sdk/commit/6afe42613ed3d7a842d378dc1a09a795811db2ac) [#4495](https://github.com/firebase/firebase-js-sdk/pull/4495) - Added isInitialized() method to Provider
|
||||
|
||||
## 0.1.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`9cf727fcc`](https://github.com/firebase/firebase-js-sdk/commit/9cf727fcc3d049551b16ae0698ac33dc2fe45ada)]:
|
||||
- @firebase/util@0.3.4
|
||||
|
||||
## 0.1.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`a5768b0aa`](https://github.com/firebase/firebase-js-sdk/commit/a5768b0aa7d7ce732279931aa436e988c9f36487) [#3932](https://github.com/firebase/firebase-js-sdk/pull/3932) - Point browser field to esm build. Now you need to use default import instead of namespace import to import firebase.
|
||||
|
||||
Before this change
|
||||
|
||||
```
|
||||
import * as firebase from 'firebase/app';
|
||||
```
|
||||
|
||||
After this change
|
||||
|
||||
```
|
||||
import firebase from 'firebase/app';
|
||||
```
|
||||
|
||||
- Updated dependencies [[`a5768b0aa`](https://github.com/firebase/firebase-js-sdk/commit/a5768b0aa7d7ce732279931aa436e988c9f36487), [`7d916d905`](https://github.com/firebase/firebase-js-sdk/commit/7d916d905ba16816ac8ac7c8748c83831ff614ce)]:
|
||||
- @firebase/util@0.3.3
|
||||
|
||||
## 0.1.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`da1c7df79`](https://github.com/firebase/firebase-js-sdk/commit/da1c7df7982b08bbef82fcc8d93255f3e2d23cca) [#3601](https://github.com/firebase/firebase-js-sdk/pull/3601) - Correctly delete services created by modular SDKs when calling provider.delete()
|
||||
|
||||
- Updated dependencies [[`fb3b095e4`](https://github.com/firebase/firebase-js-sdk/commit/fb3b095e4b7c8f57fdb3172bc039c84576abf290)]:
|
||||
- @firebase/util@0.3.2
|
||||
|
||||
## 0.1.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`d4ca3da0`](https://github.com/firebase/firebase-js-sdk/commit/d4ca3da0a59fcea1261ba69d7eb663bba38d3089)]:
|
||||
- @firebase/util@0.3.1
|
||||
|
||||
## 0.1.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a87676b8`](https://github.com/firebase/firebase-js-sdk/commit/a87676b84b78ccc2f057a22eb947a5d13402949c)]:
|
||||
- @firebase/util@0.3.0
|
||||
|
||||
## 0.1.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`a754645e`](https://github.com/firebase/firebase-js-sdk/commit/a754645ec2be1b8c205f25f510196eee298b0d6e) [#3297](https://github.com/firebase/firebase-js-sdk/pull/3297) Thanks [@renovate](https://github.com/apps/renovate)! - Update dependency typescript to v3.9.5
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# @firebase/component
|
||||
|
||||
_NOTE: This is specifically tailored for Firebase JS SDK usage, if you are not a
|
||||
member of the Firebase team, please avoid using this package_
|
||||
|
||||
## Usage
|
||||
|
||||
**ES Modules**
|
||||
|
||||
```javascript
|
||||
import { Component } from '@firebase/component';
|
||||
```
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export { Component } from './src/component';
|
||||
export { ComponentContainer } from './src/component_container';
|
||||
export { Provider } from './src/provider';
|
||||
export { ComponentType, InstanceFactory, InstantiationMode, NameServiceMapping, Name, InstanceFactoryOptions } from './src/types';
|
||||
+409
@@ -0,0 +1,409 @@
|
||||
import { Deferred } from '@firebase/util';
|
||||
|
||||
/**
|
||||
* Component for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
class Component {
|
||||
/**
|
||||
*
|
||||
* @param name The public service name, e.g. app, auth, firestore, database
|
||||
* @param instanceFactory Service factory responsible for creating the public interface
|
||||
* @param type whether the service provided by the component is public or private
|
||||
*/
|
||||
constructor(name, instanceFactory, type) {
|
||||
this.name = name;
|
||||
this.instanceFactory = instanceFactory;
|
||||
this.type = type;
|
||||
this.multipleInstances = false;
|
||||
/**
|
||||
* Properties to be added to the service namespace
|
||||
*/
|
||||
this.serviceProps = {};
|
||||
this.instantiationMode = "LAZY" /* LAZY */;
|
||||
this.onInstanceCreated = null;
|
||||
}
|
||||
setInstantiationMode(mode) {
|
||||
this.instantiationMode = mode;
|
||||
return this;
|
||||
}
|
||||
setMultipleInstances(multipleInstances) {
|
||||
this.multipleInstances = multipleInstances;
|
||||
return this;
|
||||
}
|
||||
setServiceProps(props) {
|
||||
this.serviceProps = props;
|
||||
return this;
|
||||
}
|
||||
setInstanceCreatedCallback(callback) {
|
||||
this.onInstanceCreated = callback;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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 DEFAULT_ENTRY_NAME = '[DEFAULT]';
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
/**
|
||||
* Provider for instance for service name T, e.g. 'auth', 'auth-internal'
|
||||
* NameServiceMapping[T] is an alias for the type of the instance
|
||||
*/
|
||||
class Provider {
|
||||
constructor(name, container) {
|
||||
this.name = name;
|
||||
this.container = container;
|
||||
this.component = null;
|
||||
this.instances = new Map();
|
||||
this.instancesDeferred = new Map();
|
||||
this.instancesOptions = new Map();
|
||||
this.onInitCallbacks = new Map();
|
||||
}
|
||||
/**
|
||||
* @param identifier A provider can provide mulitple instances of a service
|
||||
* if this.component.multipleInstances is true.
|
||||
*/
|
||||
get(identifier) {
|
||||
// if multipleInstances is not supported, use the default name
|
||||
const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
|
||||
if (!this.instancesDeferred.has(normalizedIdentifier)) {
|
||||
const deferred = new Deferred();
|
||||
this.instancesDeferred.set(normalizedIdentifier, deferred);
|
||||
if (this.isInitialized(normalizedIdentifier) ||
|
||||
this.shouldAutoInitialize()) {
|
||||
// initialize the service if it can be auto-initialized
|
||||
try {
|
||||
const instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
if (instance) {
|
||||
deferred.resolve(instance);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory throws an exception during get(), it should not cause
|
||||
// a fatal error. We just return the unresolved promise in this case.
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.instancesDeferred.get(normalizedIdentifier).promise;
|
||||
}
|
||||
getImmediate(options) {
|
||||
var _a;
|
||||
// if multipleInstances is not supported, use the default name
|
||||
const normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
|
||||
const optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
|
||||
if (this.isInitialized(normalizedIdentifier) ||
|
||||
this.shouldAutoInitialize()) {
|
||||
try {
|
||||
return this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// In case a component is not initialized and should/can not be auto-initialized at the moment, return null if the optional flag is set, or throw
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw Error(`Service ${this.name} is not available`);
|
||||
}
|
||||
}
|
||||
}
|
||||
getComponent() {
|
||||
return this.component;
|
||||
}
|
||||
setComponent(component) {
|
||||
if (component.name !== this.name) {
|
||||
throw Error(`Mismatching Component ${component.name} for Provider ${this.name}.`);
|
||||
}
|
||||
if (this.component) {
|
||||
throw Error(`Component for ${this.name} has already been provided`);
|
||||
}
|
||||
this.component = component;
|
||||
// return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)
|
||||
if (!this.shouldAutoInitialize()) {
|
||||
return;
|
||||
}
|
||||
// if the service is eager, initialize the default instance
|
||||
if (isComponentEager(component)) {
|
||||
try {
|
||||
this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory for an eager Component throws an exception during the eager
|
||||
// initialization, it should not cause a fatal error.
|
||||
// TODO: Investigate if we need to make it configurable, because some component may want to cause
|
||||
// a fatal error in this case?
|
||||
}
|
||||
}
|
||||
// Create service instances for the pending promises and resolve them
|
||||
// NOTE: if this.multipleInstances is false, only the default instance will be created
|
||||
// and all promises with resolve with it regardless of the identifier.
|
||||
for (const [instanceIdentifier, instanceDeferred] of this.instancesDeferred.entries()) {
|
||||
const normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
|
||||
try {
|
||||
// `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
|
||||
const instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
instanceDeferred.resolve(instance);
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory throws an exception, it should not cause
|
||||
// a fatal error. We just leave the promise unresolved.
|
||||
}
|
||||
}
|
||||
}
|
||||
clearInstance(identifier = DEFAULT_ENTRY_NAME) {
|
||||
this.instancesDeferred.delete(identifier);
|
||||
this.instancesOptions.delete(identifier);
|
||||
this.instances.delete(identifier);
|
||||
}
|
||||
// app.delete() will call this method on every provider to delete the services
|
||||
// TODO: should we mark the provider as deleted?
|
||||
async delete() {
|
||||
const services = Array.from(this.instances.values());
|
||||
await Promise.all([
|
||||
...services
|
||||
.filter(service => 'INTERNAL' in service) // legacy services
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.map(service => service.INTERNAL.delete()),
|
||||
...services
|
||||
.filter(service => '_delete' in service) // modularized services
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.map(service => service._delete())
|
||||
]);
|
||||
}
|
||||
isComponentSet() {
|
||||
return this.component != null;
|
||||
}
|
||||
isInitialized(identifier = DEFAULT_ENTRY_NAME) {
|
||||
return this.instances.has(identifier);
|
||||
}
|
||||
getOptions(identifier = DEFAULT_ENTRY_NAME) {
|
||||
return this.instancesOptions.get(identifier) || {};
|
||||
}
|
||||
initialize(opts = {}) {
|
||||
const { options = {} } = opts;
|
||||
const normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
|
||||
if (this.isInitialized(normalizedIdentifier)) {
|
||||
throw Error(`${this.name}(${normalizedIdentifier}) has already been initialized`);
|
||||
}
|
||||
if (!this.isComponentSet()) {
|
||||
throw Error(`Component ${this.name} has not been registered yet`);
|
||||
}
|
||||
const instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier,
|
||||
options
|
||||
});
|
||||
// resolve any pending promise waiting for the service instance
|
||||
for (const [instanceIdentifier, instanceDeferred] of this.instancesDeferred.entries()) {
|
||||
const normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
|
||||
if (normalizedIdentifier === normalizedDeferredIdentifier) {
|
||||
instanceDeferred.resolve(instance);
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
|
||||
* The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.
|
||||
*
|
||||
* @param identifier An optional instance identifier
|
||||
* @returns a function to unregister the callback
|
||||
*/
|
||||
onInit(callback, identifier) {
|
||||
var _a;
|
||||
const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
|
||||
const existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
|
||||
existingCallbacks.add(callback);
|
||||
this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);
|
||||
const existingInstance = this.instances.get(normalizedIdentifier);
|
||||
if (existingInstance) {
|
||||
callback(existingInstance, normalizedIdentifier);
|
||||
}
|
||||
return () => {
|
||||
existingCallbacks.delete(callback);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Invoke onInit callbacks synchronously
|
||||
* @param instance the service instance`
|
||||
*/
|
||||
invokeOnInitCallbacks(instance, identifier) {
|
||||
const callbacks = this.onInitCallbacks.get(identifier);
|
||||
if (!callbacks) {
|
||||
return;
|
||||
}
|
||||
for (const callback of callbacks) {
|
||||
try {
|
||||
callback(instance, identifier);
|
||||
}
|
||||
catch (_a) {
|
||||
// ignore errors in the onInit callback
|
||||
}
|
||||
}
|
||||
}
|
||||
getOrInitializeService({ instanceIdentifier, options = {} }) {
|
||||
let instance = this.instances.get(instanceIdentifier);
|
||||
if (!instance && this.component) {
|
||||
instance = this.component.instanceFactory(this.container, {
|
||||
instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),
|
||||
options
|
||||
});
|
||||
this.instances.set(instanceIdentifier, instance);
|
||||
this.instancesOptions.set(instanceIdentifier, options);
|
||||
/**
|
||||
* Invoke onInit listeners.
|
||||
* Note this.component.onInstanceCreated is different, which is used by the component creator,
|
||||
* while onInit listeners are registered by consumers of the provider.
|
||||
*/
|
||||
this.invokeOnInitCallbacks(instance, instanceIdentifier);
|
||||
/**
|
||||
* Order is important
|
||||
* onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which
|
||||
* makes `isInitialized()` return true.
|
||||
*/
|
||||
if (this.component.onInstanceCreated) {
|
||||
try {
|
||||
this.component.onInstanceCreated(this.container, instanceIdentifier, instance);
|
||||
}
|
||||
catch (_a) {
|
||||
// ignore errors in the onInstanceCreatedCallback
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance || null;
|
||||
}
|
||||
normalizeInstanceIdentifier(identifier = DEFAULT_ENTRY_NAME) {
|
||||
if (this.component) {
|
||||
return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;
|
||||
}
|
||||
else {
|
||||
return identifier; // assume multiple instances are supported before the component is provided.
|
||||
}
|
||||
}
|
||||
shouldAutoInitialize() {
|
||||
return (!!this.component &&
|
||||
this.component.instantiationMode !== "EXPLICIT" /* EXPLICIT */);
|
||||
}
|
||||
}
|
||||
// undefined should be passed to the service factory for the default instance
|
||||
function normalizeIdentifierForFactory(identifier) {
|
||||
return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;
|
||||
}
|
||||
function isComponentEager(component) {
|
||||
return component.instantiationMode === "EAGER" /* EAGER */;
|
||||
}
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
/**
|
||||
* ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
class ComponentContainer {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
this.providers = new Map();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param component Component being added
|
||||
* @param overwrite When a component with the same name has already been registered,
|
||||
* if overwrite is true: overwrite the existing component with the new component and create a new
|
||||
* provider with the new component. It can be useful in tests where you want to use different mocks
|
||||
* for different tests.
|
||||
* if overwrite is false: throw an exception
|
||||
*/
|
||||
addComponent(component) {
|
||||
const provider = this.getProvider(component.name);
|
||||
if (provider.isComponentSet()) {
|
||||
throw new Error(`Component ${component.name} has already been registered with ${this.name}`);
|
||||
}
|
||||
provider.setComponent(component);
|
||||
}
|
||||
addOrOverwriteComponent(component) {
|
||||
const provider = this.getProvider(component.name);
|
||||
if (provider.isComponentSet()) {
|
||||
// delete the existing provider from the container, so we can register the new component
|
||||
this.providers.delete(component.name);
|
||||
}
|
||||
this.addComponent(component);
|
||||
}
|
||||
/**
|
||||
* getProvider provides a type safe interface where it can only be called with a field name
|
||||
* present in NameServiceMapping interface.
|
||||
*
|
||||
* Firebase SDKs providing services should extend NameServiceMapping interface to register
|
||||
* themselves.
|
||||
*/
|
||||
getProvider(name) {
|
||||
if (this.providers.has(name)) {
|
||||
return this.providers.get(name);
|
||||
}
|
||||
// create a Provider for a service that hasn't registered with Firebase
|
||||
const provider = new Provider(name, this);
|
||||
this.providers.set(name, provider);
|
||||
return provider;
|
||||
}
|
||||
getProviders() {
|
||||
return Array.from(this.providers.values());
|
||||
}
|
||||
}
|
||||
|
||||
export { Component, ComponentContainer, Provider };
|
||||
//# sourceMappingURL=index.esm2017.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+460
@@ -0,0 +1,460 @@
|
||||
import { __values, __read, __awaiter, __generator, __spreadArray } from 'tslib';
|
||||
import { Deferred } from '@firebase/util';
|
||||
|
||||
/**
|
||||
* Component for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
var Component = /** @class */ (function () {
|
||||
/**
|
||||
*
|
||||
* @param name The public service name, e.g. app, auth, firestore, database
|
||||
* @param instanceFactory Service factory responsible for creating the public interface
|
||||
* @param type whether the service provided by the component is public or private
|
||||
*/
|
||||
function Component(name, instanceFactory, type) {
|
||||
this.name = name;
|
||||
this.instanceFactory = instanceFactory;
|
||||
this.type = type;
|
||||
this.multipleInstances = false;
|
||||
/**
|
||||
* Properties to be added to the service namespace
|
||||
*/
|
||||
this.serviceProps = {};
|
||||
this.instantiationMode = "LAZY" /* LAZY */;
|
||||
this.onInstanceCreated = null;
|
||||
}
|
||||
Component.prototype.setInstantiationMode = function (mode) {
|
||||
this.instantiationMode = mode;
|
||||
return this;
|
||||
};
|
||||
Component.prototype.setMultipleInstances = function (multipleInstances) {
|
||||
this.multipleInstances = multipleInstances;
|
||||
return this;
|
||||
};
|
||||
Component.prototype.setServiceProps = function (props) {
|
||||
this.serviceProps = props;
|
||||
return this;
|
||||
};
|
||||
Component.prototype.setInstanceCreatedCallback = function (callback) {
|
||||
this.onInstanceCreated = callback;
|
||||
return this;
|
||||
};
|
||||
return Component;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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 DEFAULT_ENTRY_NAME = '[DEFAULT]';
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
/**
|
||||
* Provider for instance for service name T, e.g. 'auth', 'auth-internal'
|
||||
* NameServiceMapping[T] is an alias for the type of the instance
|
||||
*/
|
||||
var Provider = /** @class */ (function () {
|
||||
function Provider(name, container) {
|
||||
this.name = name;
|
||||
this.container = container;
|
||||
this.component = null;
|
||||
this.instances = new Map();
|
||||
this.instancesDeferred = new Map();
|
||||
this.instancesOptions = new Map();
|
||||
this.onInitCallbacks = new Map();
|
||||
}
|
||||
/**
|
||||
* @param identifier A provider can provide mulitple instances of a service
|
||||
* if this.component.multipleInstances is true.
|
||||
*/
|
||||
Provider.prototype.get = function (identifier) {
|
||||
// if multipleInstances is not supported, use the default name
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
|
||||
if (!this.instancesDeferred.has(normalizedIdentifier)) {
|
||||
var deferred = new Deferred();
|
||||
this.instancesDeferred.set(normalizedIdentifier, deferred);
|
||||
if (this.isInitialized(normalizedIdentifier) ||
|
||||
this.shouldAutoInitialize()) {
|
||||
// initialize the service if it can be auto-initialized
|
||||
try {
|
||||
var instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
if (instance) {
|
||||
deferred.resolve(instance);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory throws an exception during get(), it should not cause
|
||||
// a fatal error. We just return the unresolved promise in this case.
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.instancesDeferred.get(normalizedIdentifier).promise;
|
||||
};
|
||||
Provider.prototype.getImmediate = function (options) {
|
||||
var _a;
|
||||
// if multipleInstances is not supported, use the default name
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
|
||||
var optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
|
||||
if (this.isInitialized(normalizedIdentifier) ||
|
||||
this.shouldAutoInitialize()) {
|
||||
try {
|
||||
return this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// In case a component is not initialized and should/can not be auto-initialized at the moment, return null if the optional flag is set, or throw
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw Error("Service " + this.name + " is not available");
|
||||
}
|
||||
}
|
||||
};
|
||||
Provider.prototype.getComponent = function () {
|
||||
return this.component;
|
||||
};
|
||||
Provider.prototype.setComponent = function (component) {
|
||||
var e_1, _a;
|
||||
if (component.name !== this.name) {
|
||||
throw Error("Mismatching Component " + component.name + " for Provider " + this.name + ".");
|
||||
}
|
||||
if (this.component) {
|
||||
throw Error("Component for " + this.name + " has already been provided");
|
||||
}
|
||||
this.component = component;
|
||||
// return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)
|
||||
if (!this.shouldAutoInitialize()) {
|
||||
return;
|
||||
}
|
||||
// if the service is eager, initialize the default instance
|
||||
if (isComponentEager(component)) {
|
||||
try {
|
||||
this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory for an eager Component throws an exception during the eager
|
||||
// initialization, it should not cause a fatal error.
|
||||
// TODO: Investigate if we need to make it configurable, because some component may want to cause
|
||||
// a fatal error in this case?
|
||||
}
|
||||
}
|
||||
try {
|
||||
// Create service instances for the pending promises and resolve them
|
||||
// NOTE: if this.multipleInstances is false, only the default instance will be created
|
||||
// and all promises with resolve with it regardless of the identifier.
|
||||
for (var _b = __values(this.instancesDeferred.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||
var _d = __read(_c.value, 2), instanceIdentifier = _d[0], instanceDeferred = _d[1];
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
|
||||
try {
|
||||
// `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
|
||||
var instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
instanceDeferred.resolve(instance);
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory throws an exception, it should not cause
|
||||
// a fatal error. We just leave the promise unresolved.
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
};
|
||||
Provider.prototype.clearInstance = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
this.instancesDeferred.delete(identifier);
|
||||
this.instancesOptions.delete(identifier);
|
||||
this.instances.delete(identifier);
|
||||
};
|
||||
// app.delete() will call this method on every provider to delete the services
|
||||
// TODO: should we mark the provider as deleted?
|
||||
Provider.prototype.delete = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var services;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
services = Array.from(this.instances.values());
|
||||
return [4 /*yield*/, Promise.all(__spreadArray(__spreadArray([], __read(services
|
||||
.filter(function (service) { return 'INTERNAL' in service; }) // legacy services
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.map(function (service) { return service.INTERNAL.delete(); }))), __read(services
|
||||
.filter(function (service) { return '_delete' in service; }) // modularized services
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.map(function (service) { return service._delete(); }))))];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Provider.prototype.isComponentSet = function () {
|
||||
return this.component != null;
|
||||
};
|
||||
Provider.prototype.isInitialized = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
return this.instances.has(identifier);
|
||||
};
|
||||
Provider.prototype.getOptions = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
return this.instancesOptions.get(identifier) || {};
|
||||
};
|
||||
Provider.prototype.initialize = function (opts) {
|
||||
var e_2, _a;
|
||||
if (opts === void 0) { opts = {}; }
|
||||
var _b = opts.options, options = _b === void 0 ? {} : _b;
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
|
||||
if (this.isInitialized(normalizedIdentifier)) {
|
||||
throw Error(this.name + "(" + normalizedIdentifier + ") has already been initialized");
|
||||
}
|
||||
if (!this.isComponentSet()) {
|
||||
throw Error("Component " + this.name + " has not been registered yet");
|
||||
}
|
||||
var instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier,
|
||||
options: options
|
||||
});
|
||||
try {
|
||||
// resolve any pending promise waiting for the service instance
|
||||
for (var _c = __values(this.instancesDeferred.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
||||
var _e = __read(_d.value, 2), instanceIdentifier = _e[0], instanceDeferred = _e[1];
|
||||
var normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
|
||||
if (normalizedIdentifier === normalizedDeferredIdentifier) {
|
||||
instanceDeferred.resolve(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
||||
}
|
||||
finally { if (e_2) throw e_2.error; }
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
|
||||
* The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.
|
||||
*
|
||||
* @param identifier An optional instance identifier
|
||||
* @returns a function to unregister the callback
|
||||
*/
|
||||
Provider.prototype.onInit = function (callback, identifier) {
|
||||
var _a;
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
|
||||
var existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
|
||||
existingCallbacks.add(callback);
|
||||
this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);
|
||||
var existingInstance = this.instances.get(normalizedIdentifier);
|
||||
if (existingInstance) {
|
||||
callback(existingInstance, normalizedIdentifier);
|
||||
}
|
||||
return function () {
|
||||
existingCallbacks.delete(callback);
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Invoke onInit callbacks synchronously
|
||||
* @param instance the service instance`
|
||||
*/
|
||||
Provider.prototype.invokeOnInitCallbacks = function (instance, identifier) {
|
||||
var e_3, _a;
|
||||
var callbacks = this.onInitCallbacks.get(identifier);
|
||||
if (!callbacks) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (var callbacks_1 = __values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
|
||||
var callback = callbacks_1_1.value;
|
||||
try {
|
||||
callback(instance, identifier);
|
||||
}
|
||||
catch (_b) {
|
||||
// ignore errors in the onInit callback
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
|
||||
}
|
||||
finally { if (e_3) throw e_3.error; }
|
||||
}
|
||||
};
|
||||
Provider.prototype.getOrInitializeService = function (_a) {
|
||||
var instanceIdentifier = _a.instanceIdentifier, _b = _a.options, options = _b === void 0 ? {} : _b;
|
||||
var instance = this.instances.get(instanceIdentifier);
|
||||
if (!instance && this.component) {
|
||||
instance = this.component.instanceFactory(this.container, {
|
||||
instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),
|
||||
options: options
|
||||
});
|
||||
this.instances.set(instanceIdentifier, instance);
|
||||
this.instancesOptions.set(instanceIdentifier, options);
|
||||
/**
|
||||
* Invoke onInit listeners.
|
||||
* Note this.component.onInstanceCreated is different, which is used by the component creator,
|
||||
* while onInit listeners are registered by consumers of the provider.
|
||||
*/
|
||||
this.invokeOnInitCallbacks(instance, instanceIdentifier);
|
||||
/**
|
||||
* Order is important
|
||||
* onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which
|
||||
* makes `isInitialized()` return true.
|
||||
*/
|
||||
if (this.component.onInstanceCreated) {
|
||||
try {
|
||||
this.component.onInstanceCreated(this.container, instanceIdentifier, instance);
|
||||
}
|
||||
catch (_c) {
|
||||
// ignore errors in the onInstanceCreatedCallback
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance || null;
|
||||
};
|
||||
Provider.prototype.normalizeInstanceIdentifier = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
if (this.component) {
|
||||
return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;
|
||||
}
|
||||
else {
|
||||
return identifier; // assume multiple instances are supported before the component is provided.
|
||||
}
|
||||
};
|
||||
Provider.prototype.shouldAutoInitialize = function () {
|
||||
return (!!this.component &&
|
||||
this.component.instantiationMode !== "EXPLICIT" /* EXPLICIT */);
|
||||
};
|
||||
return Provider;
|
||||
}());
|
||||
// undefined should be passed to the service factory for the default instance
|
||||
function normalizeIdentifierForFactory(identifier) {
|
||||
return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;
|
||||
}
|
||||
function isComponentEager(component) {
|
||||
return component.instantiationMode === "EAGER" /* EAGER */;
|
||||
}
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
/**
|
||||
* ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
var ComponentContainer = /** @class */ (function () {
|
||||
function ComponentContainer(name) {
|
||||
this.name = name;
|
||||
this.providers = new Map();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param component Component being added
|
||||
* @param overwrite When a component with the same name has already been registered,
|
||||
* if overwrite is true: overwrite the existing component with the new component and create a new
|
||||
* provider with the new component. It can be useful in tests where you want to use different mocks
|
||||
* for different tests.
|
||||
* if overwrite is false: throw an exception
|
||||
*/
|
||||
ComponentContainer.prototype.addComponent = function (component) {
|
||||
var provider = this.getProvider(component.name);
|
||||
if (provider.isComponentSet()) {
|
||||
throw new Error("Component " + component.name + " has already been registered with " + this.name);
|
||||
}
|
||||
provider.setComponent(component);
|
||||
};
|
||||
ComponentContainer.prototype.addOrOverwriteComponent = function (component) {
|
||||
var provider = this.getProvider(component.name);
|
||||
if (provider.isComponentSet()) {
|
||||
// delete the existing provider from the container, so we can register the new component
|
||||
this.providers.delete(component.name);
|
||||
}
|
||||
this.addComponent(component);
|
||||
};
|
||||
/**
|
||||
* getProvider provides a type safe interface where it can only be called with a field name
|
||||
* present in NameServiceMapping interface.
|
||||
*
|
||||
* Firebase SDKs providing services should extend NameServiceMapping interface to register
|
||||
* themselves.
|
||||
*/
|
||||
ComponentContainer.prototype.getProvider = function (name) {
|
||||
if (this.providers.has(name)) {
|
||||
return this.providers.get(name);
|
||||
}
|
||||
// create a Provider for a service that hasn't registered with Firebase
|
||||
var provider = new Provider(name, this);
|
||||
this.providers.set(name, provider);
|
||||
return provider;
|
||||
};
|
||||
ComponentContainer.prototype.getProviders = function () {
|
||||
return Array.from(this.providers.values());
|
||||
};
|
||||
return ComponentContainer;
|
||||
}());
|
||||
|
||||
export { Component, ComponentContainer, Provider };
|
||||
//# sourceMappingURL=index.esm5.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
{"type":"module"}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { InstantiationMode, InstanceFactory, ComponentType, Dictionary, Name, onInstanceCreatedCallback } from './types';
|
||||
/**
|
||||
* Component for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
export declare class Component<T extends Name = Name> {
|
||||
readonly name: T;
|
||||
readonly instanceFactory: InstanceFactory<T>;
|
||||
readonly type: ComponentType;
|
||||
multipleInstances: boolean;
|
||||
/**
|
||||
* Properties to be added to the service namespace
|
||||
*/
|
||||
serviceProps: Dictionary;
|
||||
instantiationMode: InstantiationMode;
|
||||
onInstanceCreated: onInstanceCreatedCallback<T> | null;
|
||||
/**
|
||||
*
|
||||
* @param name The public service name, e.g. app, auth, firestore, database
|
||||
* @param instanceFactory Service factory responsible for creating the public interface
|
||||
* @param type whether the service provided by the component is public or private
|
||||
*/
|
||||
constructor(name: T, instanceFactory: InstanceFactory<T>, type: ComponentType);
|
||||
setInstantiationMode(mode: InstantiationMode): this;
|
||||
setMultipleInstances(multipleInstances: boolean): this;
|
||||
setServiceProps(props: Dictionary): this;
|
||||
setInstanceCreatedCallback(callback: onInstanceCreatedCallback<T>): this;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { Provider } from './provider';
|
||||
import { Component } from './component';
|
||||
import { Name } from './types';
|
||||
/**
|
||||
* ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
export declare class ComponentContainer {
|
||||
private readonly name;
|
||||
private readonly providers;
|
||||
constructor(name: string);
|
||||
/**
|
||||
*
|
||||
* @param component Component being added
|
||||
* @param overwrite When a component with the same name has already been registered,
|
||||
* if overwrite is true: overwrite the existing component with the new component and create a new
|
||||
* provider with the new component. It can be useful in tests where you want to use different mocks
|
||||
* for different tests.
|
||||
* if overwrite is false: throw an exception
|
||||
*/
|
||||
addComponent<T extends Name>(component: Component<T>): void;
|
||||
addOrOverwriteComponent<T extends Name>(component: Component<T>): void;
|
||||
/**
|
||||
* getProvider provides a type safe interface where it can only be called with a field name
|
||||
* present in NameServiceMapping interface.
|
||||
*
|
||||
* Firebase SDKs providing services should extend NameServiceMapping interface to register
|
||||
* themselves.
|
||||
*/
|
||||
getProvider<T extends Name>(name: T): Provider<T>;
|
||||
getProviders(): Array<Provider<Name>>;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import '../test/setup';
|
||||
declare module './types' {
|
||||
interface NameServiceMapping {
|
||||
rocket: {};
|
||||
ship: {};
|
||||
fireball: {};
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
export declare const DEFAULT_ENTRY_NAME = "[DEFAULT]";
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { ComponentContainer } from './component_container';
|
||||
import { InitializeOptions, Name, NameServiceMapping, OnInitCallBack } from './types';
|
||||
import { Component } from './component';
|
||||
/**
|
||||
* Provider for instance for service name T, e.g. 'auth', 'auth-internal'
|
||||
* NameServiceMapping[T] is an alias for the type of the instance
|
||||
*/
|
||||
export declare class Provider<T extends Name> {
|
||||
private readonly name;
|
||||
private readonly container;
|
||||
private component;
|
||||
private readonly instances;
|
||||
private readonly instancesDeferred;
|
||||
private readonly instancesOptions;
|
||||
private onInitCallbacks;
|
||||
constructor(name: T, container: ComponentContainer);
|
||||
/**
|
||||
* @param identifier A provider can provide mulitple instances of a service
|
||||
* if this.component.multipleInstances is true.
|
||||
*/
|
||||
get(identifier?: string): Promise<NameServiceMapping[T]>;
|
||||
/**
|
||||
*
|
||||
* @param options.identifier A provider can provide mulitple instances of a service
|
||||
* if this.component.multipleInstances is true.
|
||||
* @param options.optional If optional is false or not provided, the method throws an error when
|
||||
* the service is not immediately available.
|
||||
* If optional is true, the method returns null if the service is not immediately available.
|
||||
*/
|
||||
getImmediate(options: {
|
||||
identifier?: string;
|
||||
optional: true;
|
||||
}): NameServiceMapping[T] | null;
|
||||
getImmediate(options?: {
|
||||
identifier?: string;
|
||||
optional?: false;
|
||||
}): NameServiceMapping[T];
|
||||
getComponent(): Component<T> | null;
|
||||
setComponent(component: Component<T>): void;
|
||||
clearInstance(identifier?: string): void;
|
||||
delete(): Promise<void>;
|
||||
isComponentSet(): boolean;
|
||||
isInitialized(identifier?: string): boolean;
|
||||
getOptions(identifier?: string): Record<string, unknown>;
|
||||
initialize(opts?: InitializeOptions): NameServiceMapping[T];
|
||||
/**
|
||||
*
|
||||
* @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
|
||||
* The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.
|
||||
*
|
||||
* @param identifier An optional instance identifier
|
||||
* @returns a function to unregister the callback
|
||||
*/
|
||||
onInit(callback: OnInitCallBack<T>, identifier?: string): () => void;
|
||||
/**
|
||||
* Invoke onInit callbacks synchronously
|
||||
* @param instance the service instance`
|
||||
*/
|
||||
private invokeOnInitCallbacks;
|
||||
private getOrInitializeService;
|
||||
private normalizeInstanceIdentifier;
|
||||
private shouldAutoInitialize;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import '../test/setup';
|
||||
declare module './types' {
|
||||
interface NameServiceMapping {
|
||||
test: {};
|
||||
badtest: {};
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { ComponentContainer } from './component_container';
|
||||
export declare const enum InstantiationMode {
|
||||
LAZY = "LAZY",
|
||||
EAGER = "EAGER",
|
||||
EXPLICIT = "EXPLICIT"
|
||||
}
|
||||
/**
|
||||
* PUBLIC: A public component provides a set of public APIs to customers. A service namespace will be patched
|
||||
* onto `firebase` namespace. Assume the component name is `test`, customers will be able
|
||||
* to get the service by calling `firebase.test()` or `app.test()` where `app` is a `FirebaseApp` instance.
|
||||
*
|
||||
* PRIVATE: A private component provides a set of private APIs that are used internally by other
|
||||
* Firebase SDKs. No serivce namespace is created in `firebase` namespace and customers have no way to get them.
|
||||
*/
|
||||
export declare const enum ComponentType {
|
||||
PUBLIC = "PUBLIC",
|
||||
PRIVATE = "PRIVATE",
|
||||
VERSION = "VERSION"
|
||||
}
|
||||
export interface InstanceFactoryOptions {
|
||||
instanceIdentifier?: string;
|
||||
options?: {};
|
||||
}
|
||||
export declare type InitializeOptions = InstanceFactoryOptions;
|
||||
/**
|
||||
* Factory to create an instance of type T, given a ComponentContainer.
|
||||
* ComponentContainer is the IOC container that provides {@link Provider}
|
||||
* for dependencies.
|
||||
*
|
||||
* NOTE: The container only provides {@link Provider} rather than the actual instances of dependencies.
|
||||
* It is useful for lazily loaded dependencies and optional dependencies.
|
||||
*/
|
||||
export declare type InstanceFactory<T extends Name> = (container: ComponentContainer, options: InstanceFactoryOptions) => NameServiceMapping[T];
|
||||
export declare type onInstanceCreatedCallback<T extends Name> = (container: ComponentContainer, instanceIdentifier: string, instance: NameServiceMapping[T]) => void;
|
||||
export interface Dictionary {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
/**
|
||||
* This interface will be extended by Firebase SDKs to provide service name and service type mapping.
|
||||
* It is used as a generic constraint to ensure type safety.
|
||||
*/
|
||||
export interface NameServiceMapping {
|
||||
}
|
||||
export declare type Name = keyof NameServiceMapping;
|
||||
export declare type Service = NameServiceMapping[Name];
|
||||
export declare type OnInitCallBack<T extends Name> = (instance: NameServiceMapping[T], identifier: string) => void;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { InstanceFactory, InstantiationMode, Name } from '../src/types';
|
||||
import { Component } from '../src/component';
|
||||
export declare function getFakeApp(appName?: string): FirebaseApp;
|
||||
export declare function getFakeComponent<T extends Name>(name: T, factory: InstanceFactory<T>, multipleInstance?: boolean, instantiationMode?: InstantiationMode): Component<T>;
|
||||
+466
@@ -0,0 +1,466 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var tslib = require('tslib');
|
||||
var util = require('@firebase/util');
|
||||
|
||||
/**
|
||||
* Component for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
var Component = /** @class */ (function () {
|
||||
/**
|
||||
*
|
||||
* @param name The public service name, e.g. app, auth, firestore, database
|
||||
* @param instanceFactory Service factory responsible for creating the public interface
|
||||
* @param type whether the service provided by the component is public or private
|
||||
*/
|
||||
function Component(name, instanceFactory, type) {
|
||||
this.name = name;
|
||||
this.instanceFactory = instanceFactory;
|
||||
this.type = type;
|
||||
this.multipleInstances = false;
|
||||
/**
|
||||
* Properties to be added to the service namespace
|
||||
*/
|
||||
this.serviceProps = {};
|
||||
this.instantiationMode = "LAZY" /* LAZY */;
|
||||
this.onInstanceCreated = null;
|
||||
}
|
||||
Component.prototype.setInstantiationMode = function (mode) {
|
||||
this.instantiationMode = mode;
|
||||
return this;
|
||||
};
|
||||
Component.prototype.setMultipleInstances = function (multipleInstances) {
|
||||
this.multipleInstances = multipleInstances;
|
||||
return this;
|
||||
};
|
||||
Component.prototype.setServiceProps = function (props) {
|
||||
this.serviceProps = props;
|
||||
return this;
|
||||
};
|
||||
Component.prototype.setInstanceCreatedCallback = function (callback) {
|
||||
this.onInstanceCreated = callback;
|
||||
return this;
|
||||
};
|
||||
return Component;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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 DEFAULT_ENTRY_NAME = '[DEFAULT]';
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
/**
|
||||
* Provider for instance for service name T, e.g. 'auth', 'auth-internal'
|
||||
* NameServiceMapping[T] is an alias for the type of the instance
|
||||
*/
|
||||
var Provider = /** @class */ (function () {
|
||||
function Provider(name, container) {
|
||||
this.name = name;
|
||||
this.container = container;
|
||||
this.component = null;
|
||||
this.instances = new Map();
|
||||
this.instancesDeferred = new Map();
|
||||
this.instancesOptions = new Map();
|
||||
this.onInitCallbacks = new Map();
|
||||
}
|
||||
/**
|
||||
* @param identifier A provider can provide mulitple instances of a service
|
||||
* if this.component.multipleInstances is true.
|
||||
*/
|
||||
Provider.prototype.get = function (identifier) {
|
||||
// if multipleInstances is not supported, use the default name
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
|
||||
if (!this.instancesDeferred.has(normalizedIdentifier)) {
|
||||
var deferred = new util.Deferred();
|
||||
this.instancesDeferred.set(normalizedIdentifier, deferred);
|
||||
if (this.isInitialized(normalizedIdentifier) ||
|
||||
this.shouldAutoInitialize()) {
|
||||
// initialize the service if it can be auto-initialized
|
||||
try {
|
||||
var instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
if (instance) {
|
||||
deferred.resolve(instance);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory throws an exception during get(), it should not cause
|
||||
// a fatal error. We just return the unresolved promise in this case.
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.instancesDeferred.get(normalizedIdentifier).promise;
|
||||
};
|
||||
Provider.prototype.getImmediate = function (options) {
|
||||
var _a;
|
||||
// if multipleInstances is not supported, use the default name
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
|
||||
var optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
|
||||
if (this.isInitialized(normalizedIdentifier) ||
|
||||
this.shouldAutoInitialize()) {
|
||||
try {
|
||||
return this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// In case a component is not initialized and should/can not be auto-initialized at the moment, return null if the optional flag is set, or throw
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw Error("Service " + this.name + " is not available");
|
||||
}
|
||||
}
|
||||
};
|
||||
Provider.prototype.getComponent = function () {
|
||||
return this.component;
|
||||
};
|
||||
Provider.prototype.setComponent = function (component) {
|
||||
var e_1, _a;
|
||||
if (component.name !== this.name) {
|
||||
throw Error("Mismatching Component " + component.name + " for Provider " + this.name + ".");
|
||||
}
|
||||
if (this.component) {
|
||||
throw Error("Component for " + this.name + " has already been provided");
|
||||
}
|
||||
this.component = component;
|
||||
// return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)
|
||||
if (!this.shouldAutoInitialize()) {
|
||||
return;
|
||||
}
|
||||
// if the service is eager, initialize the default instance
|
||||
if (isComponentEager(component)) {
|
||||
try {
|
||||
this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory for an eager Component throws an exception during the eager
|
||||
// initialization, it should not cause a fatal error.
|
||||
// TODO: Investigate if we need to make it configurable, because some component may want to cause
|
||||
// a fatal error in this case?
|
||||
}
|
||||
}
|
||||
try {
|
||||
// Create service instances for the pending promises and resolve them
|
||||
// NOTE: if this.multipleInstances is false, only the default instance will be created
|
||||
// and all promises with resolve with it regardless of the identifier.
|
||||
for (var _b = tslib.__values(this.instancesDeferred.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||
var _d = tslib.__read(_c.value, 2), instanceIdentifier = _d[0], instanceDeferred = _d[1];
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
|
||||
try {
|
||||
// `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
|
||||
var instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier
|
||||
});
|
||||
instanceDeferred.resolve(instance);
|
||||
}
|
||||
catch (e) {
|
||||
// when the instance factory throws an exception, it should not cause
|
||||
// a fatal error. We just leave the promise unresolved.
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
};
|
||||
Provider.prototype.clearInstance = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
this.instancesDeferred.delete(identifier);
|
||||
this.instancesOptions.delete(identifier);
|
||||
this.instances.delete(identifier);
|
||||
};
|
||||
// app.delete() will call this method on every provider to delete the services
|
||||
// TODO: should we mark the provider as deleted?
|
||||
Provider.prototype.delete = function () {
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
var services;
|
||||
return tslib.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
services = Array.from(this.instances.values());
|
||||
return [4 /*yield*/, Promise.all(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(services
|
||||
.filter(function (service) { return 'INTERNAL' in service; }) // legacy services
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.map(function (service) { return service.INTERNAL.delete(); }))), tslib.__read(services
|
||||
.filter(function (service) { return '_delete' in service; }) // modularized services
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.map(function (service) { return service._delete(); }))))];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Provider.prototype.isComponentSet = function () {
|
||||
return this.component != null;
|
||||
};
|
||||
Provider.prototype.isInitialized = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
return this.instances.has(identifier);
|
||||
};
|
||||
Provider.prototype.getOptions = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
return this.instancesOptions.get(identifier) || {};
|
||||
};
|
||||
Provider.prototype.initialize = function (opts) {
|
||||
var e_2, _a;
|
||||
if (opts === void 0) { opts = {}; }
|
||||
var _b = opts.options, options = _b === void 0 ? {} : _b;
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
|
||||
if (this.isInitialized(normalizedIdentifier)) {
|
||||
throw Error(this.name + "(" + normalizedIdentifier + ") has already been initialized");
|
||||
}
|
||||
if (!this.isComponentSet()) {
|
||||
throw Error("Component " + this.name + " has not been registered yet");
|
||||
}
|
||||
var instance = this.getOrInitializeService({
|
||||
instanceIdentifier: normalizedIdentifier,
|
||||
options: options
|
||||
});
|
||||
try {
|
||||
// resolve any pending promise waiting for the service instance
|
||||
for (var _c = tslib.__values(this.instancesDeferred.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
||||
var _e = tslib.__read(_d.value, 2), instanceIdentifier = _e[0], instanceDeferred = _e[1];
|
||||
var normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
|
||||
if (normalizedIdentifier === normalizedDeferredIdentifier) {
|
||||
instanceDeferred.resolve(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
||||
}
|
||||
finally { if (e_2) throw e_2.error; }
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
|
||||
* The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.
|
||||
*
|
||||
* @param identifier An optional instance identifier
|
||||
* @returns a function to unregister the callback
|
||||
*/
|
||||
Provider.prototype.onInit = function (callback, identifier) {
|
||||
var _a;
|
||||
var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
|
||||
var existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
|
||||
existingCallbacks.add(callback);
|
||||
this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);
|
||||
var existingInstance = this.instances.get(normalizedIdentifier);
|
||||
if (existingInstance) {
|
||||
callback(existingInstance, normalizedIdentifier);
|
||||
}
|
||||
return function () {
|
||||
existingCallbacks.delete(callback);
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Invoke onInit callbacks synchronously
|
||||
* @param instance the service instance`
|
||||
*/
|
||||
Provider.prototype.invokeOnInitCallbacks = function (instance, identifier) {
|
||||
var e_3, _a;
|
||||
var callbacks = this.onInitCallbacks.get(identifier);
|
||||
if (!callbacks) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (var callbacks_1 = tslib.__values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
|
||||
var callback = callbacks_1_1.value;
|
||||
try {
|
||||
callback(instance, identifier);
|
||||
}
|
||||
catch (_b) {
|
||||
// ignore errors in the onInit callback
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
|
||||
}
|
||||
finally { if (e_3) throw e_3.error; }
|
||||
}
|
||||
};
|
||||
Provider.prototype.getOrInitializeService = function (_a) {
|
||||
var instanceIdentifier = _a.instanceIdentifier, _b = _a.options, options = _b === void 0 ? {} : _b;
|
||||
var instance = this.instances.get(instanceIdentifier);
|
||||
if (!instance && this.component) {
|
||||
instance = this.component.instanceFactory(this.container, {
|
||||
instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),
|
||||
options: options
|
||||
});
|
||||
this.instances.set(instanceIdentifier, instance);
|
||||
this.instancesOptions.set(instanceIdentifier, options);
|
||||
/**
|
||||
* Invoke onInit listeners.
|
||||
* Note this.component.onInstanceCreated is different, which is used by the component creator,
|
||||
* while onInit listeners are registered by consumers of the provider.
|
||||
*/
|
||||
this.invokeOnInitCallbacks(instance, instanceIdentifier);
|
||||
/**
|
||||
* Order is important
|
||||
* onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which
|
||||
* makes `isInitialized()` return true.
|
||||
*/
|
||||
if (this.component.onInstanceCreated) {
|
||||
try {
|
||||
this.component.onInstanceCreated(this.container, instanceIdentifier, instance);
|
||||
}
|
||||
catch (_c) {
|
||||
// ignore errors in the onInstanceCreatedCallback
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance || null;
|
||||
};
|
||||
Provider.prototype.normalizeInstanceIdentifier = function (identifier) {
|
||||
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
|
||||
if (this.component) {
|
||||
return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;
|
||||
}
|
||||
else {
|
||||
return identifier; // assume multiple instances are supported before the component is provided.
|
||||
}
|
||||
};
|
||||
Provider.prototype.shouldAutoInitialize = function () {
|
||||
return (!!this.component &&
|
||||
this.component.instantiationMode !== "EXPLICIT" /* EXPLICIT */);
|
||||
};
|
||||
return Provider;
|
||||
}());
|
||||
// undefined should be passed to the service factory for the default instance
|
||||
function normalizeIdentifierForFactory(identifier) {
|
||||
return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;
|
||||
}
|
||||
function isComponentEager(component) {
|
||||
return component.instantiationMode === "EAGER" /* EAGER */;
|
||||
}
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
/**
|
||||
* ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
var ComponentContainer = /** @class */ (function () {
|
||||
function ComponentContainer(name) {
|
||||
this.name = name;
|
||||
this.providers = new Map();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param component Component being added
|
||||
* @param overwrite When a component with the same name has already been registered,
|
||||
* if overwrite is true: overwrite the existing component with the new component and create a new
|
||||
* provider with the new component. It can be useful in tests where you want to use different mocks
|
||||
* for different tests.
|
||||
* if overwrite is false: throw an exception
|
||||
*/
|
||||
ComponentContainer.prototype.addComponent = function (component) {
|
||||
var provider = this.getProvider(component.name);
|
||||
if (provider.isComponentSet()) {
|
||||
throw new Error("Component " + component.name + " has already been registered with " + this.name);
|
||||
}
|
||||
provider.setComponent(component);
|
||||
};
|
||||
ComponentContainer.prototype.addOrOverwriteComponent = function (component) {
|
||||
var provider = this.getProvider(component.name);
|
||||
if (provider.isComponentSet()) {
|
||||
// delete the existing provider from the container, so we can register the new component
|
||||
this.providers.delete(component.name);
|
||||
}
|
||||
this.addComponent(component);
|
||||
};
|
||||
/**
|
||||
* getProvider provides a type safe interface where it can only be called with a field name
|
||||
* present in NameServiceMapping interface.
|
||||
*
|
||||
* Firebase SDKs providing services should extend NameServiceMapping interface to register
|
||||
* themselves.
|
||||
*/
|
||||
ComponentContainer.prototype.getProvider = function (name) {
|
||||
if (this.providers.has(name)) {
|
||||
return this.providers.get(name);
|
||||
}
|
||||
// create a Provider for a service that hasn't registered with Firebase
|
||||
var provider = new Provider(name, this);
|
||||
this.providers.set(name, provider);
|
||||
return provider;
|
||||
};
|
||||
ComponentContainer.prototype.getProviders = function () {
|
||||
return Array.from(this.providers.values());
|
||||
};
|
||||
return ComponentContainer;
|
||||
}());
|
||||
|
||||
exports.Component = Component;
|
||||
exports.ComponentContainer = ComponentContainer;
|
||||
exports.Provider = Provider;
|
||||
//# sourceMappingURL=index.cjs.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export { Component } from './src/component';
|
||||
export { ComponentContainer } from './src/component_container';
|
||||
export { Provider } from './src/provider';
|
||||
export { ComponentType, InstanceFactory, InstantiationMode, NameServiceMapping, Name, InstanceFactoryOptions } from './src/types';
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { InstantiationMode, InstanceFactory, ComponentType, Dictionary, Name, onInstanceCreatedCallback } from './types';
|
||||
/**
|
||||
* Component for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
export declare class Component<T extends Name = Name> {
|
||||
readonly name: T;
|
||||
readonly instanceFactory: InstanceFactory<T>;
|
||||
readonly type: ComponentType;
|
||||
multipleInstances: boolean;
|
||||
/**
|
||||
* Properties to be added to the service namespace
|
||||
*/
|
||||
serviceProps: Dictionary;
|
||||
instantiationMode: InstantiationMode;
|
||||
onInstanceCreated: onInstanceCreatedCallback<T> | null;
|
||||
/**
|
||||
*
|
||||
* @param name The public service name, e.g. app, auth, firestore, database
|
||||
* @param instanceFactory Service factory responsible for creating the public interface
|
||||
* @param type whether the service provided by the component is public or private
|
||||
*/
|
||||
constructor(name: T, instanceFactory: InstanceFactory<T>, type: ComponentType);
|
||||
setInstantiationMode(mode: InstantiationMode): this;
|
||||
setMultipleInstances(multipleInstances: boolean): this;
|
||||
setServiceProps(props: Dictionary): this;
|
||||
setInstanceCreatedCallback(callback: onInstanceCreatedCallback<T>): this;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { Provider } from './provider';
|
||||
import { Component } from './component';
|
||||
import { Name } from './types';
|
||||
/**
|
||||
* ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
|
||||
*/
|
||||
export declare class ComponentContainer {
|
||||
private readonly name;
|
||||
private readonly providers;
|
||||
constructor(name: string);
|
||||
/**
|
||||
*
|
||||
* @param component Component being added
|
||||
* @param overwrite When a component with the same name has already been registered,
|
||||
* if overwrite is true: overwrite the existing component with the new component and create a new
|
||||
* provider with the new component. It can be useful in tests where you want to use different mocks
|
||||
* for different tests.
|
||||
* if overwrite is false: throw an exception
|
||||
*/
|
||||
addComponent<T extends Name>(component: Component<T>): void;
|
||||
addOrOverwriteComponent<T extends Name>(component: Component<T>): void;
|
||||
/**
|
||||
* getProvider provides a type safe interface where it can only be called with a field name
|
||||
* present in NameServiceMapping interface.
|
||||
*
|
||||
* Firebase SDKs providing services should extend NameServiceMapping interface to register
|
||||
* themselves.
|
||||
*/
|
||||
getProvider<T extends Name>(name: T): Provider<T>;
|
||||
getProviders(): Array<Provider<Name>>;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import '../test/setup';
|
||||
declare module './types' {
|
||||
interface NameServiceMapping {
|
||||
rocket: {};
|
||||
ship: {};
|
||||
fireball: {};
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
export declare const DEFAULT_ENTRY_NAME = "[DEFAULT]";
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { ComponentContainer } from './component_container';
|
||||
import { InitializeOptions, Name, NameServiceMapping, OnInitCallBack } from './types';
|
||||
import { Component } from './component';
|
||||
/**
|
||||
* Provider for instance for service name T, e.g. 'auth', 'auth-internal'
|
||||
* NameServiceMapping[T] is an alias for the type of the instance
|
||||
*/
|
||||
export declare class Provider<T extends Name> {
|
||||
private readonly name;
|
||||
private readonly container;
|
||||
private component;
|
||||
private readonly instances;
|
||||
private readonly instancesDeferred;
|
||||
private readonly instancesOptions;
|
||||
private onInitCallbacks;
|
||||
constructor(name: T, container: ComponentContainer);
|
||||
/**
|
||||
* @param identifier A provider can provide mulitple instances of a service
|
||||
* if this.component.multipleInstances is true.
|
||||
*/
|
||||
get(identifier?: string): Promise<NameServiceMapping[T]>;
|
||||
/**
|
||||
*
|
||||
* @param options.identifier A provider can provide mulitple instances of a service
|
||||
* if this.component.multipleInstances is true.
|
||||
* @param options.optional If optional is false or not provided, the method throws an error when
|
||||
* the service is not immediately available.
|
||||
* If optional is true, the method returns null if the service is not immediately available.
|
||||
*/
|
||||
getImmediate(options: {
|
||||
identifier?: string;
|
||||
optional: true;
|
||||
}): NameServiceMapping[T] | null;
|
||||
getImmediate(options?: {
|
||||
identifier?: string;
|
||||
optional?: false;
|
||||
}): NameServiceMapping[T];
|
||||
getComponent(): Component<T> | null;
|
||||
setComponent(component: Component<T>): void;
|
||||
clearInstance(identifier?: string): void;
|
||||
delete(): Promise<void>;
|
||||
isComponentSet(): boolean;
|
||||
isInitialized(identifier?: string): boolean;
|
||||
getOptions(identifier?: string): Record<string, unknown>;
|
||||
initialize(opts?: InitializeOptions): NameServiceMapping[T];
|
||||
/**
|
||||
*
|
||||
* @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
|
||||
* The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.
|
||||
*
|
||||
* @param identifier An optional instance identifier
|
||||
* @returns a function to unregister the callback
|
||||
*/
|
||||
onInit(callback: OnInitCallBack<T>, identifier?: string): () => void;
|
||||
/**
|
||||
* Invoke onInit callbacks synchronously
|
||||
* @param instance the service instance`
|
||||
*/
|
||||
private invokeOnInitCallbacks;
|
||||
private getOrInitializeService;
|
||||
private normalizeInstanceIdentifier;
|
||||
private shouldAutoInitialize;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import '../test/setup';
|
||||
declare module './types' {
|
||||
interface NameServiceMapping {
|
||||
test: {};
|
||||
badtest: {};
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
import { ComponentContainer } from './component_container';
|
||||
export declare const enum InstantiationMode {
|
||||
LAZY = "LAZY",
|
||||
EAGER = "EAGER",
|
||||
EXPLICIT = "EXPLICIT"
|
||||
}
|
||||
/**
|
||||
* PUBLIC: A public component provides a set of public APIs to customers. A service namespace will be patched
|
||||
* onto `firebase` namespace. Assume the component name is `test`, customers will be able
|
||||
* to get the service by calling `firebase.test()` or `app.test()` where `app` is a `FirebaseApp` instance.
|
||||
*
|
||||
* PRIVATE: A private component provides a set of private APIs that are used internally by other
|
||||
* Firebase SDKs. No serivce namespace is created in `firebase` namespace and customers have no way to get them.
|
||||
*/
|
||||
export declare const enum ComponentType {
|
||||
PUBLIC = "PUBLIC",
|
||||
PRIVATE = "PRIVATE",
|
||||
VERSION = "VERSION"
|
||||
}
|
||||
export interface InstanceFactoryOptions {
|
||||
instanceIdentifier?: string;
|
||||
options?: {};
|
||||
}
|
||||
export declare type InitializeOptions = InstanceFactoryOptions;
|
||||
/**
|
||||
* Factory to create an instance of type T, given a ComponentContainer.
|
||||
* ComponentContainer is the IOC container that provides {@link Provider}
|
||||
* for dependencies.
|
||||
*
|
||||
* NOTE: The container only provides {@link Provider} rather than the actual instances of dependencies.
|
||||
* It is useful for lazily loaded dependencies and optional dependencies.
|
||||
*/
|
||||
export declare type InstanceFactory<T extends Name> = (container: ComponentContainer, options: InstanceFactoryOptions) => NameServiceMapping[T];
|
||||
export declare type onInstanceCreatedCallback<T extends Name> = (container: ComponentContainer, instanceIdentifier: string, instance: NameServiceMapping[T]) => void;
|
||||
export interface Dictionary {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
/**
|
||||
* This interface will be extended by Firebase SDKs to provide service name and service type mapping.
|
||||
* It is used as a generic constraint to ensure type safety.
|
||||
*/
|
||||
export interface NameServiceMapping {
|
||||
}
|
||||
export declare type Name = keyof NameServiceMapping;
|
||||
export declare type Service = NameServiceMapping[Name];
|
||||
export declare type OnInitCallBack<T extends Name> = (instance: NameServiceMapping[T], identifier: string) => void;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { InstanceFactory, InstantiationMode, Name } from '../src/types';
|
||||
import { Component } from '../src/component';
|
||||
export declare function getFakeApp(appName?: string): FirebaseApp;
|
||||
export declare function getFakeComponent<T extends Name>(name: T, factory: InstanceFactory<T>, multipleInstance?: boolean, instantiationMode?: InstantiationMode): Component<T>;
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"_from": "@firebase/component@0.5.9",
|
||||
"_id": "@firebase/component@0.5.9",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-oLCY3x9WbM5rn06qmUvbtJuPj4dIw/C9T4Th52IiHF5tiCRC5k6YthvhfUVcTwfoUhK0fOgtwuKJKA/LpCPjgA==",
|
||||
"_location": "/@firebase/component",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@firebase/component@0.5.9",
|
||||
"name": "@firebase/component",
|
||||
"escapedName": "@firebase%2fcomponent",
|
||||
"scope": "@firebase",
|
||||
"rawSpec": "0.5.9",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.5.9"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@firebase/database",
|
||||
"/@firebase/database-compat"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@firebase/component/-/component-0.5.9.tgz",
|
||||
"_shasum": "a859f655bd6e5b691bc5596fe43a91b12a443052",
|
||||
"_spec": "@firebase/component@0.5.9",
|
||||
"_where": "/Users/talksik/Development/nirvana-server/node_modules/@firebase/database-compat",
|
||||
"author": {
|
||||
"name": "Firebase",
|
||||
"email": "firebase-support@google.com",
|
||||
"url": "https://firebase.google.com/"
|
||||
},
|
||||
"browser": "dist/esm/index.esm2017.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/firebase/firebase-js-sdk/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@firebase/util": "1.4.2",
|
||||
"tslib": "^2.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Firebase Component Platform",
|
||||
"devDependencies": {
|
||||
"rollup": "2.57.0",
|
||||
"rollup-plugin-typescript2": "0.30.0",
|
||||
"typescript": "4.2.2"
|
||||
},
|
||||
"esm5": "dist/esm/index.esm5.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./dist/index.cjs.js",
|
||||
"esm5": "./dist/esm/index.esm5.js",
|
||||
"default": "./dist/esm/index.esm2017.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"homepage": "https://github.com/firebase/firebase-js-sdk#readme",
|
||||
"license": "Apache-2.0",
|
||||
"main": "dist/index.cjs.js",
|
||||
"module": "dist/esm/index.esm2017.js",
|
||||
"name": "@firebase/component",
|
||||
"nyc": {
|
||||
"extension": [
|
||||
".ts"
|
||||
],
|
||||
"reportDir": "./coverage/node"
|
||||
},
|
||||
"repository": {
|
||||
"directory": "packages/component",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/firebase/firebase-js-sdk.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"build:deps": "lerna run --scope @firebase/component --include-dependencies build",
|
||||
"dev": "rollup -c -w",
|
||||
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
|
||||
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
|
||||
"test": "run-p lint test:all",
|
||||
"test:all": "run-p test:browser test:node",
|
||||
"test:browser": "karma start --single-run",
|
||||
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
|
||||
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.ts --config ../../config/mocharc.node.js"
|
||||
},
|
||||
"typings": "dist/index.d.ts",
|
||||
"version": "0.5.9"
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
# @firebase/database-compat
|
||||
|
||||
## 0.1.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`3281315fa`](https://github.com/firebase/firebase-js-sdk/commit/3281315fae9c6f535f9d5052ee17d60861ea569a) [#5708](https://github.com/firebase/firebase-js-sdk/pull/5708) (fixes [#1487](https://github.com/firebase/firebase-js-sdk/issues/1487)) - Update build scripts to work with the exports field
|
||||
|
||||
- Updated dependencies [[`3281315fa`](https://github.com/firebase/firebase-js-sdk/commit/3281315fae9c6f535f9d5052ee17d60861ea569a)]:
|
||||
- @firebase/component@0.5.9
|
||||
- @firebase/database@0.12.4
|
||||
- @firebase/logger@0.3.2
|
||||
- @firebase/util@1.4.2
|
||||
- @firebase/database-types@0.9.3
|
||||
|
||||
## 0.1.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`2322b6023`](https://github.com/firebase/firebase-js-sdk/commit/2322b6023c628cd9f4f4172767c17d215dd91684) [#5693](https://github.com/firebase/firebase-js-sdk/pull/5693) - Add exports field to all packages
|
||||
|
||||
- Updated dependencies [[`2322b6023`](https://github.com/firebase/firebase-js-sdk/commit/2322b6023c628cd9f4f4172767c17d215dd91684)]:
|
||||
- @firebase/component@0.5.8
|
||||
- @firebase/database@0.12.3
|
||||
- @firebase/logger@0.3.1
|
||||
- @firebase/util@1.4.1
|
||||
- @firebase/database-types@0.9.2
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`352cc2647`](https://github.com/firebase/firebase-js-sdk/commit/352cc26476a0c249f89d19eb371ecdcbbd067e5f) [#5587](https://github.com/firebase/firebase-js-sdk/pull/5587) - Add "repository" field to package.json files that were missing it.
|
||||
|
||||
- Updated dependencies [[`93795c780`](https://github.com/firebase/firebase-js-sdk/commit/93795c7801d6b28ccbbe5855fd2f3fc377b1db5f)]:
|
||||
- @firebase/database@0.12.2
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`dfe65ff9b`](https://github.com/firebase/firebase-js-sdk/commit/dfe65ff9bfa66d318d45e2a666e302867ae53a01) [#5537](https://github.com/firebase/firebase-js-sdk/pull/5537) - Added an entry point `@firebase/database-compat/standalone` to share code with Admin SDK properly
|
||||
|
||||
* [`b79bd33e4`](https://github.com/firebase/firebase-js-sdk/commit/b79bd33e4d3fe6c051b29a85d5141fcb8dcc8d2d) [#5531](https://github.com/firebase/firebase-js-sdk/pull/5531) - export types from @firebase/database-compat for admin SDK
|
||||
|
||||
* Updated dependencies [[`dfe65ff9b`](https://github.com/firebase/firebase-js-sdk/commit/dfe65ff9bfa66d318d45e2a666e302867ae53a01), [`a99943fe3`](https://github.com/firebase/firebase-js-sdk/commit/a99943fe3bd5279761aa29d138ec91272b06df39), [`b835b4cba`](https://github.com/firebase/firebase-js-sdk/commit/b835b4cbabc4b7b180ae38b908c49205ce31a422)]:
|
||||
- @firebase/database@0.12.1
|
||||
- @firebase/logger@0.3.0
|
||||
- @firebase/util@1.4.0
|
||||
- @firebase/component@0.5.7
|
||||
- @firebase/database-types@0.9.1
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [`cdada6c68`](https://github.com/firebase/firebase-js-sdk/commit/cdada6c68f9740d13dd6674bcb658e28e68253b6) [#5345](https://github.com/firebase/firebase-js-sdk/pull/5345) (fixes [#5015](https://github.com/firebase/firebase-js-sdk/issues/5015)) - Release modularized SDKs
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`cdada6c68`](https://github.com/firebase/firebase-js-sdk/commit/cdada6c68f9740d13dd6674bcb658e28e68253b6)]:
|
||||
- @firebase/database@0.12.0
|
||||
- @firebase/database-types@0.9.0
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
# @firebase/database-compat
|
||||
|
||||
This is the compatibility layer for the Firebase Realtime Database component of the Firebase JS SDK.
|
||||
|
||||
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
|
||||
Generated
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { FirebaseService } from '@firebase/app-types/private';
|
||||
import { Database as ModularDatabase } from '@firebase/database';
|
||||
import { Compat, EmulatorMockTokenOptions } from '@firebase/util';
|
||||
import { Reference } from './Reference';
|
||||
/**
|
||||
* Class representing a firebase database.
|
||||
*/
|
||||
export declare class Database implements FirebaseService, Compat<ModularDatabase> {
|
||||
readonly _delegate: ModularDatabase;
|
||||
readonly app: FirebaseApp;
|
||||
static readonly ServerValue: {
|
||||
TIMESTAMP: object;
|
||||
increment: (delta: number) => object;
|
||||
};
|
||||
/**
|
||||
* The constructor should not be called by users of our public API.
|
||||
*/
|
||||
constructor(_delegate: ModularDatabase, app: FirebaseApp);
|
||||
INTERNAL: {
|
||||
delete: () => Promise<void>;
|
||||
};
|
||||
/**
|
||||
* Modify this instance to communicate with the Realtime Database emulator.
|
||||
*
|
||||
* <p>Note: This method must be called before performing any other operation.
|
||||
*
|
||||
* @param host - the emulator host (ex: localhost)
|
||||
* @param port - the emulator port (ex: 8080)
|
||||
* @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
|
||||
*/
|
||||
useEmulator(host: string, port: number, options?: {
|
||||
mockUserToken?: EmulatorMockTokenOptions;
|
||||
}): void;
|
||||
/**
|
||||
* Returns a reference to the root or to the path specified in the provided
|
||||
* argument.
|
||||
*
|
||||
* @param path - The relative string path or an existing Reference to a database
|
||||
* location.
|
||||
* @throws If a Reference is provided, throws if it does not belong to the
|
||||
* same project.
|
||||
* @returns Firebase reference.
|
||||
*/
|
||||
ref(path?: string): Reference;
|
||||
ref(path?: Reference): Reference;
|
||||
/**
|
||||
* Returns a reference to the root or the path specified in url.
|
||||
* We throw a exception if the url is not in the same domain as the
|
||||
* current repo.
|
||||
* @returns Firebase reference.
|
||||
*/
|
||||
refFromURL(url: string): Reference;
|
||||
goOffline(): void;
|
||||
goOnline(): void;
|
||||
}
|
||||
Generated
Vendored
+201
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { DataSnapshot as ModularDataSnapshot, Query as ExpQuery, DatabaseReference as ModularReference } from '@firebase/database';
|
||||
import { Compat } from '@firebase/util';
|
||||
import { Database } from './Database';
|
||||
import { OnDisconnect } from './onDisconnect';
|
||||
import { TransactionResult } from './TransactionResult';
|
||||
/**
|
||||
* Class representing a firebase data snapshot. It wraps a SnapshotNode and
|
||||
* surfaces the public methods (val, forEach, etc.) we want to expose.
|
||||
*/
|
||||
export declare class DataSnapshot implements Compat<ModularDataSnapshot> {
|
||||
readonly _database: Database;
|
||||
readonly _delegate: ModularDataSnapshot;
|
||||
constructor(_database: Database, _delegate: ModularDataSnapshot);
|
||||
/**
|
||||
* Retrieves the snapshot contents as JSON. Returns null if the snapshot is
|
||||
* empty.
|
||||
*
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
val(): unknown;
|
||||
/**
|
||||
* Returns the snapshot contents as JSON, including priorities of node. Suitable for exporting
|
||||
* the entire node contents.
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
exportVal(): unknown;
|
||||
toJSON(): unknown;
|
||||
/**
|
||||
* Returns whether the snapshot contains a non-null value.
|
||||
*
|
||||
* @returns Whether the snapshot contains a non-null value, or is empty.
|
||||
*/
|
||||
exists(): boolean;
|
||||
/**
|
||||
* Returns a DataSnapshot of the specified child node's contents.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns DataSnapshot for child node.
|
||||
*/
|
||||
child(path: string): DataSnapshot;
|
||||
/**
|
||||
* Returns whether the snapshot contains a child at the specified path.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns Whether the child exists.
|
||||
*/
|
||||
hasChild(path: string): boolean;
|
||||
/**
|
||||
* Returns the priority of the object, or null if no priority was set.
|
||||
*
|
||||
* @returns The priority.
|
||||
*/
|
||||
getPriority(): string | number | null;
|
||||
/**
|
||||
* Iterates through child nodes and calls the specified action for each one.
|
||||
*
|
||||
* @param action - Callback function to be called
|
||||
* for each child.
|
||||
* @returns True if forEach was canceled by action returning true for
|
||||
* one of the child nodes.
|
||||
*/
|
||||
forEach(action: (snapshot: DataSnapshot) => boolean | void): boolean;
|
||||
/**
|
||||
* Returns whether this DataSnapshot has children.
|
||||
* @returns True if the DataSnapshot contains 1 or more child nodes.
|
||||
*/
|
||||
hasChildren(): boolean;
|
||||
get key(): string;
|
||||
/**
|
||||
* Returns the number of children for this DataSnapshot.
|
||||
* @returns The number of children that this DataSnapshot contains.
|
||||
*/
|
||||
numChildren(): number;
|
||||
/**
|
||||
* @returns The Firebase reference for the location this snapshot's data came
|
||||
* from.
|
||||
*/
|
||||
getRef(): Reference;
|
||||
get ref(): Reference;
|
||||
}
|
||||
export interface SnapshotCallback {
|
||||
(dataSnapshot: DataSnapshot, previousChildName?: string | null): unknown;
|
||||
}
|
||||
/**
|
||||
* A Query represents a filter to be applied to a firebase location. This object purely represents the
|
||||
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
|
||||
*
|
||||
* Since every Firebase reference is a query, Firebase inherits from this object.
|
||||
*/
|
||||
export declare class Query implements Compat<ExpQuery> {
|
||||
readonly database: Database;
|
||||
readonly _delegate: ExpQuery;
|
||||
constructor(database: Database, _delegate: ExpQuery);
|
||||
on(eventType: string, callback: SnapshotCallback, cancelCallbackOrContext?: ((a: Error) => unknown) | object | null, context?: object | null): SnapshotCallback;
|
||||
off(eventType?: string, callback?: SnapshotCallback, context?: object | null): void;
|
||||
/**
|
||||
* Get the server-value for this query, or return a cached value if not connected.
|
||||
*/
|
||||
get(): Promise<DataSnapshot>;
|
||||
/**
|
||||
* Attaches a listener, waits for the first event, and then removes the listener
|
||||
*/
|
||||
once(eventType: string, callback?: SnapshotCallback, failureCallbackOrContext?: ((a: Error) => void) | object | null, context?: object | null): Promise<DataSnapshot>;
|
||||
/**
|
||||
* Set a limit and anchor it to the start of the window.
|
||||
*/
|
||||
limitToFirst(limit: number): Query;
|
||||
/**
|
||||
* Set a limit and anchor it to the end of the window.
|
||||
*/
|
||||
limitToLast(limit: number): Query;
|
||||
/**
|
||||
* Given a child path, return a new query ordered by the specified grandchild path.
|
||||
*/
|
||||
orderByChild(path: string): Query;
|
||||
/**
|
||||
* Return a new query ordered by the KeyIndex
|
||||
*/
|
||||
orderByKey(): Query;
|
||||
/**
|
||||
* Return a new query ordered by the PriorityIndex
|
||||
*/
|
||||
orderByPriority(): Query;
|
||||
/**
|
||||
* Return a new query ordered by the ValueIndex
|
||||
*/
|
||||
orderByValue(): Query;
|
||||
startAt(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
startAfter(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
endAt(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
endBefore(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
/**
|
||||
* Load the selection of children with exactly the specified value, and, optionally,
|
||||
* the specified name.
|
||||
*/
|
||||
equalTo(value: number | string | boolean | null, name?: string): Query;
|
||||
/**
|
||||
* @returns URL for this location.
|
||||
*/
|
||||
toString(): string;
|
||||
toJSON(): string;
|
||||
/**
|
||||
* Return true if this query and the provided query are equivalent; otherwise, return false.
|
||||
*/
|
||||
isEqual(other: Query): boolean;
|
||||
/**
|
||||
* Helper used by .on and .once to extract the context and or cancel arguments.
|
||||
* @param fnName - The function name (on or once)
|
||||
*
|
||||
*/
|
||||
private static getCancelAndContextArgs_;
|
||||
get ref(): Reference;
|
||||
}
|
||||
export declare class Reference extends Query implements Compat<ModularReference> {
|
||||
readonly database: Database;
|
||||
readonly _delegate: ModularReference;
|
||||
then: Promise<Reference>['then'];
|
||||
catch: Promise<Reference>['catch'];
|
||||
/**
|
||||
* Call options:
|
||||
* new Reference(Repo, Path) or
|
||||
* new Reference(url: string, string|RepoManager)
|
||||
*
|
||||
* Externally - this is the firebase.database.Reference type.
|
||||
*/
|
||||
constructor(database: Database, _delegate: ModularReference);
|
||||
/** @returns {?string} */
|
||||
getKey(): string | null;
|
||||
child(pathString: string): Reference;
|
||||
/** @returns {?Reference} */
|
||||
getParent(): Reference | null;
|
||||
/** @returns {!Reference} */
|
||||
getRoot(): Reference;
|
||||
set(newVal: unknown, onComplete?: (error: Error | null) => void): Promise<unknown>;
|
||||
update(values: object, onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
setWithPriority(newVal: unknown, newPriority: string | number | null, onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
remove(onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
transaction(transactionUpdate: (currentData: unknown) => unknown, onComplete?: (error: Error | null, committed: boolean, dataSnapshot: DataSnapshot | null) => void, applyLocally?: boolean): Promise<TransactionResult>;
|
||||
setPriority(priority: string | number | null, onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
push(value?: unknown, onComplete?: (a: Error | null) => void): Reference;
|
||||
onDisconnect(): OnDisconnect;
|
||||
get key(): string | null;
|
||||
get parent(): Reference | null;
|
||||
get root(): Reference;
|
||||
}
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { DataSnapshot } from './Reference';
|
||||
export declare class TransactionResult {
|
||||
committed: boolean;
|
||||
snapshot: DataSnapshot;
|
||||
/**
|
||||
* A type for the resolve value of Firebase.transaction.
|
||||
*/
|
||||
constructor(committed: boolean, snapshot: DataSnapshot);
|
||||
toJSON(): object;
|
||||
}
|
||||
Generated
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
|
||||
import * as types from '@firebase/database-types';
|
||||
/**
|
||||
* Used by console to create a database based on the app,
|
||||
* passed database URL and a custom auth implementation.
|
||||
*
|
||||
* @param app - A valid FirebaseApp-like object
|
||||
* @param url - A valid Firebase databaseURL
|
||||
* @param version - custom version e.g. firebase-admin version
|
||||
* @param customAuthImpl - custom auth implementation
|
||||
*/
|
||||
export declare function initStandalone<T>({ app, url, version, customAuthImpl, namespace, nodeAdmin }: {
|
||||
app: FirebaseApp;
|
||||
url: string;
|
||||
version: string;
|
||||
customAuthImpl: FirebaseAuthInternal;
|
||||
namespace: T;
|
||||
nodeAdmin?: boolean;
|
||||
}): {
|
||||
instance: types.Database;
|
||||
namespace: T;
|
||||
};
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { OnDisconnect as ModularOnDisconnect } from '@firebase/database';
|
||||
import { Compat } from '@firebase/util';
|
||||
export declare class OnDisconnect implements Compat<ModularOnDisconnect> {
|
||||
readonly _delegate: ModularOnDisconnect;
|
||||
constructor(_delegate: ModularOnDisconnect);
|
||||
cancel(onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
remove(onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
set(value: unknown, onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
setWithPriority(value: unknown, priority: number | string | null, onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
update(objectToMerge: Record<string, unknown>, onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
import { FirebaseNamespace } from '@firebase/app-compat';
|
||||
import * as types from '@firebase/database-types';
|
||||
export declare function registerDatabase(instance: FirebaseNamespace): void;
|
||||
declare module '@firebase/app-compat' {
|
||||
interface FirebaseNamespace {
|
||||
database?: {
|
||||
(app?: FirebaseApp): types.FirebaseDatabase;
|
||||
enableLogging: typeof types.enableLogging;
|
||||
ServerValue: types.ServerValue;
|
||||
Database: typeof types.FirebaseDatabase;
|
||||
};
|
||||
}
|
||||
interface FirebaseApp {
|
||||
database?(databaseURL?: string): types.FirebaseDatabase;
|
||||
}
|
||||
}
|
||||
|
||||
import { FirebaseApp as FirebaseAppCompat } from "@firebase/app-compat";
|
||||
import { DatabaseReference, EmulatorMockTokenOptions, DataSnapshot, Database, EventType, Unsubscribe, ListenOptions, OnDisconnect, ThenableReference, QueryConstraint, Query, TransactionOptions, TransactionResult } from "@firebase/database";
|
||||
declare module "@firebase/database" {
|
||||
function child(parent: types.Reference, path: string): DatabaseReference;
|
||||
function connectDatabaseEmulator(db: types.FirebaseDatabase, host: string, port: number, options?: {
|
||||
mockUserToken?: EmulatorMockTokenOptions | string;
|
||||
}): void;
|
||||
function get(query: types.Query): Promise<DataSnapshot>;
|
||||
function getDatabase(app?: FirebaseAppCompat, url?: string): Database;
|
||||
function goOffline(db: types.FirebaseDatabase): void;
|
||||
function goOnline(db: types.FirebaseDatabase): void;
|
||||
function off(query: types.Query, eventType?: EventType, callback?: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown): void;
|
||||
function onChildAdded(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
|
||||
function onChildAdded(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onChildAdded(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onChildChanged(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
|
||||
function onChildChanged(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onChildChanged(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onChildMoved(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
|
||||
function onChildMoved(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onChildMoved(query: types.Query, callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onChildRemoved(query: types.Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
|
||||
function onChildRemoved(query: types.Query, callback: (snapshot: DataSnapshot) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onChildRemoved(query: types.Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onDisconnect(ref: types.Reference): OnDisconnect;
|
||||
function onValue(query: types.Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
|
||||
function onValue(query: types.Query, callback: (snapshot: DataSnapshot) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function onValue(query: types.Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback: (error: Error) => unknown, options: ListenOptions): Unsubscribe;
|
||||
function push(parent: types.Reference, value?: unknown): ThenableReference;
|
||||
function query(query: types.Query, ...queryConstraints: QueryConstraint[]): Query;
|
||||
function ref(db: types.FirebaseDatabase, path?: string): DatabaseReference;
|
||||
function refFromURL(db: types.FirebaseDatabase, url: string): DatabaseReference;
|
||||
function remove(ref: types.Reference): Promise<void>;
|
||||
function runTransaction(ref: types.Reference, transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions): Promise<TransactionResult>;
|
||||
function set(ref: types.Reference, value: unknown): Promise<void>;
|
||||
function setPriority(ref: types.Reference, priority: string | number | null): Promise<void>;
|
||||
function setWithPriority(ref: types.Reference, value: unknown, priority: string | number | null): Promise<void>;
|
||||
function update(ref: types.Reference, values: object): Promise<void>;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import * as types from '@firebase/database-types';
|
||||
declare module '@firebase/app-compat' {
|
||||
interface FirebaseNamespace {
|
||||
database?: {
|
||||
(app?: FirebaseApp): types.FirebaseDatabase;
|
||||
enableLogging: typeof types.enableLogging;
|
||||
ServerValue: types.ServerValue;
|
||||
Database: typeof types.FirebaseDatabase;
|
||||
};
|
||||
}
|
||||
interface FirebaseApp {
|
||||
database?(): types.FirebaseDatabase;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { enableLogging } from '@firebase/database';
|
||||
import { Database } from './api/Database';
|
||||
import * as INTERNAL from './api/internal';
|
||||
import { DataSnapshot, Query, Reference } from './api/Reference';
|
||||
declare const ServerValue: {
|
||||
TIMESTAMP: object;
|
||||
increment: (delta: number) => object;
|
||||
};
|
||||
/**
|
||||
* A one off register function which returns a database based on the app and
|
||||
* passed database URL. (Used by the Admin SDK)
|
||||
*
|
||||
* @param app - A valid FirebaseApp-like object
|
||||
* @param url - A valid Firebase databaseURL
|
||||
* @param version - custom version e.g. firebase-admin version
|
||||
* @param nodeAdmin - true if the SDK is being initialized from Firebase Admin.
|
||||
*/
|
||||
export declare function initStandalone(app: FirebaseApp, url: string, version: string, nodeAdmin?: boolean): {
|
||||
instance: import("@firebase/database-types").Database;
|
||||
namespace: {
|
||||
Reference: typeof Reference;
|
||||
Query: typeof Query;
|
||||
Database: typeof Database;
|
||||
DataSnapshot: typeof DataSnapshot;
|
||||
enableLogging: typeof enableLogging;
|
||||
INTERNAL: typeof INTERNAL;
|
||||
ServerValue: {
|
||||
TIMESTAMP: object;
|
||||
increment: (delta: number) => object;
|
||||
};
|
||||
};
|
||||
};
|
||||
export { Database, Query, Reference, enableLogging, ServerValue };
|
||||
export { OnDisconnect } from '@firebase/database';
|
||||
export { DataSnapshot } from './api/Reference';
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
export declare const warn: (msg: string) => void;
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
export declare const validateBoolean: (fnName: string, argumentName: string, bool: unknown, optional: boolean) => void;
|
||||
export declare const validateEventType: (fnName: string, eventType: string, optional: boolean) => void;
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export {};
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import '../src/index';
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export {};
|
||||
Generated
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* A set of functions to clean up event handlers.
|
||||
*/
|
||||
export declare let eventCleanupHandlers: any[];
|
||||
/** Clean up outstanding event handlers */
|
||||
export declare function eventCleanup(): void;
|
||||
/**
|
||||
* Creates a struct which waits for many events.
|
||||
* @param pathAndEvents - an array of tuples of [Firebase, [event type strings]]
|
||||
*/
|
||||
export declare function eventTestHelper(pathAndEvents: any, helperName?: any): {
|
||||
promise: Promise<unknown>;
|
||||
initPromise: Promise<unknown>;
|
||||
waiter: () => boolean;
|
||||
watchesInitializedWaiter: () => boolean;
|
||||
unregister: () => void;
|
||||
addExpectedEvents(moreEvents: any): void;
|
||||
};
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import '../../src/index';
|
||||
import { Path } from '../../../database/src/core/util/Path';
|
||||
import { Query, Reference } from '../../src/api/Reference';
|
||||
export declare const TEST_PROJECT: any;
|
||||
export declare const DATABASE_ADDRESS: any;
|
||||
export declare const DATABASE_URL: any;
|
||||
export declare function createTestApp(): import("@firebase/app-compat").FirebaseApp;
|
||||
/**
|
||||
* Gets or creates a root node to the test namespace. All calls sharing the
|
||||
* value of opt_i will share an app context.
|
||||
*/
|
||||
export declare function getRootNode(i?: number, ref?: string): any;
|
||||
/**
|
||||
* Create multiple refs to the same top level
|
||||
* push key - each on it's own Firebase.Context.
|
||||
*/
|
||||
export declare function getRandomNode(numNodes?: any): Reference | Reference[];
|
||||
export declare function getQueryValue(query: Query): Promise<unknown>;
|
||||
export declare function pause(milliseconds: number): Promise<void>;
|
||||
export declare function getPath(query: Query): string;
|
||||
export declare function shuffle(arr: any, randFn?: () => number): void;
|
||||
export declare function getFreshRepo(path: Path): any;
|
||||
export declare function getFreshRepoFromReference(ref: any): any;
|
||||
export declare function getSnap(path: any): any;
|
||||
export declare function getVal(path: any): any;
|
||||
export declare function canCreateExtraConnections(): boolean;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export {};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export {};
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export {};
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export {};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
export {};
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
export {};
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import '../src/index';
|
||||
+870
@@ -0,0 +1,870 @@
|
||||
import firebase from '@firebase/app-compat';
|
||||
import { Provider, ComponentContainer, Component } from '@firebase/component';
|
||||
import { _validatePathString, onChildMoved, onChildChanged, onChildRemoved, onChildAdded, onValue, off, get, query, limitToFirst, limitToLast, orderByChild, orderByKey, orderByPriority, orderByValue, startAt, startAfter, endAt, endBefore, equalTo, _ReferenceImpl, _QueryImpl, _QueryParams, child, set, _validateWritablePath, update, setWithPriority, remove, runTransaction, setPriority, push, OnDisconnect as OnDisconnect$1, connectDatabaseEmulator, refFromURL, ref, goOffline, goOnline, serverTimestamp, increment, _setSDKVersion, _repoManagerDatabaseFromApp, enableLogging } from '@firebase/database';
|
||||
import { errorPrefix, validateArgCount, validateCallback, validateContextObject, Deferred } from '@firebase/util';
|
||||
import { Logger } from '@firebase/logger';
|
||||
|
||||
const name = "@firebase/database-compat";
|
||||
const version = "0.1.4";
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 logClient = new Logger('@firebase/database-compat');
|
||||
const warn = function (msg) {
|
||||
const message = 'FIREBASE WARNING: ' + msg;
|
||||
logClient.warn(message);
|
||||
};
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 validateBoolean = function (fnName, argumentName, bool, optional) {
|
||||
if (optional && bool === undefined) {
|
||||
return;
|
||||
}
|
||||
if (typeof bool !== 'boolean') {
|
||||
throw new Error(errorPrefix(fnName, argumentName) + 'must be a boolean.');
|
||||
}
|
||||
};
|
||||
const validateEventType = function (fnName, eventType, optional) {
|
||||
if (optional && eventType === undefined) {
|
||||
return;
|
||||
}
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
case 'child_added':
|
||||
case 'child_removed':
|
||||
case 'child_changed':
|
||||
case 'child_moved':
|
||||
break;
|
||||
default:
|
||||
throw new Error(errorPrefix(fnName, 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
class OnDisconnect {
|
||||
constructor(_delegate) {
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
cancel(onComplete) {
|
||||
validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
|
||||
validateCallback('OnDisconnect.cancel', 'onComplete', onComplete, true);
|
||||
const result = this._delegate.cancel();
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
remove(onComplete) {
|
||||
validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
|
||||
validateCallback('OnDisconnect.remove', 'onComplete', onComplete, true);
|
||||
const result = this._delegate.remove();
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
set(value, onComplete) {
|
||||
validateArgCount('OnDisconnect.set', 1, 2, arguments.length);
|
||||
validateCallback('OnDisconnect.set', 'onComplete', onComplete, true);
|
||||
const result = this._delegate.set(value);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
setWithPriority(value, priority, onComplete) {
|
||||
validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
|
||||
validateCallback('OnDisconnect.setWithPriority', 'onComplete', onComplete, true);
|
||||
const result = this._delegate.setWithPriority(value, priority);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
update(objectToMerge, onComplete) {
|
||||
validateArgCount('OnDisconnect.update', 1, 2, arguments.length);
|
||||
if (Array.isArray(objectToMerge)) {
|
||||
const newObjectToMerge = {};
|
||||
for (let i = 0; i < objectToMerge.length; ++i) {
|
||||
newObjectToMerge['' + i] = objectToMerge[i];
|
||||
}
|
||||
objectToMerge = newObjectToMerge;
|
||||
warn('Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the ' +
|
||||
'existing data, or an Object with integer keys if you really do want to only update some of the children.');
|
||||
}
|
||||
validateCallback('OnDisconnect.update', 'onComplete', onComplete, true);
|
||||
const result = this._delegate.update(objectToMerge);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
class TransactionResult {
|
||||
/**
|
||||
* A type for the resolve value of Firebase.transaction.
|
||||
*/
|
||||
constructor(committed, snapshot) {
|
||||
this.committed = committed;
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users
|
||||
toJSON() {
|
||||
validateArgCount('TransactionResult.toJSON', 0, 1, arguments.length);
|
||||
return { committed: this.committed, snapshot: this.snapshot.toJSON() };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Class representing a firebase data snapshot. It wraps a SnapshotNode and
|
||||
* surfaces the public methods (val, forEach, etc.) we want to expose.
|
||||
*/
|
||||
class DataSnapshot {
|
||||
constructor(_database, _delegate) {
|
||||
this._database = _database;
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
/**
|
||||
* Retrieves the snapshot contents as JSON. Returns null if the snapshot is
|
||||
* empty.
|
||||
*
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
val() {
|
||||
validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
|
||||
return this._delegate.val();
|
||||
}
|
||||
/**
|
||||
* Returns the snapshot contents as JSON, including priorities of node. Suitable for exporting
|
||||
* the entire node contents.
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
exportVal() {
|
||||
validateArgCount('DataSnapshot.exportVal', 0, 0, arguments.length);
|
||||
return this._delegate.exportVal();
|
||||
}
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users
|
||||
toJSON() {
|
||||
// Optional spacer argument is unnecessary because we're depending on recursion rather than stringifying the content
|
||||
validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
|
||||
return this._delegate.toJSON();
|
||||
}
|
||||
/**
|
||||
* Returns whether the snapshot contains a non-null value.
|
||||
*
|
||||
* @returns Whether the snapshot contains a non-null value, or is empty.
|
||||
*/
|
||||
exists() {
|
||||
validateArgCount('DataSnapshot.exists', 0, 0, arguments.length);
|
||||
return this._delegate.exists();
|
||||
}
|
||||
/**
|
||||
* Returns a DataSnapshot of the specified child node's contents.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns DataSnapshot for child node.
|
||||
*/
|
||||
child(path) {
|
||||
validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
|
||||
// Ensure the childPath is a string (can be a number)
|
||||
path = String(path);
|
||||
_validatePathString('DataSnapshot.child', 'path', path, false);
|
||||
return new DataSnapshot(this._database, this._delegate.child(path));
|
||||
}
|
||||
/**
|
||||
* Returns whether the snapshot contains a child at the specified path.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns Whether the child exists.
|
||||
*/
|
||||
hasChild(path) {
|
||||
validateArgCount('DataSnapshot.hasChild', 1, 1, arguments.length);
|
||||
_validatePathString('DataSnapshot.hasChild', 'path', path, false);
|
||||
return this._delegate.hasChild(path);
|
||||
}
|
||||
/**
|
||||
* Returns the priority of the object, or null if no priority was set.
|
||||
*
|
||||
* @returns The priority.
|
||||
*/
|
||||
getPriority() {
|
||||
validateArgCount('DataSnapshot.getPriority', 0, 0, arguments.length);
|
||||
return this._delegate.priority;
|
||||
}
|
||||
/**
|
||||
* Iterates through child nodes and calls the specified action for each one.
|
||||
*
|
||||
* @param action - Callback function to be called
|
||||
* for each child.
|
||||
* @returns True if forEach was canceled by action returning true for
|
||||
* one of the child nodes.
|
||||
*/
|
||||
forEach(action) {
|
||||
validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length);
|
||||
validateCallback('DataSnapshot.forEach', 'action', action, false);
|
||||
return this._delegate.forEach(expDataSnapshot => action(new DataSnapshot(this._database, expDataSnapshot)));
|
||||
}
|
||||
/**
|
||||
* Returns whether this DataSnapshot has children.
|
||||
* @returns True if the DataSnapshot contains 1 or more child nodes.
|
||||
*/
|
||||
hasChildren() {
|
||||
validateArgCount('DataSnapshot.hasChildren', 0, 0, arguments.length);
|
||||
return this._delegate.hasChildren();
|
||||
}
|
||||
get key() {
|
||||
return this._delegate.key;
|
||||
}
|
||||
/**
|
||||
* Returns the number of children for this DataSnapshot.
|
||||
* @returns The number of children that this DataSnapshot contains.
|
||||
*/
|
||||
numChildren() {
|
||||
validateArgCount('DataSnapshot.numChildren', 0, 0, arguments.length);
|
||||
return this._delegate.size;
|
||||
}
|
||||
/**
|
||||
* @returns The Firebase reference for the location this snapshot's data came
|
||||
* from.
|
||||
*/
|
||||
getRef() {
|
||||
validateArgCount('DataSnapshot.ref', 0, 0, arguments.length);
|
||||
return new Reference(this._database, this._delegate.ref);
|
||||
}
|
||||
get ref() {
|
||||
return this.getRef();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A Query represents a filter to be applied to a firebase location. This object purely represents the
|
||||
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
|
||||
*
|
||||
* Since every Firebase reference is a query, Firebase inherits from this object.
|
||||
*/
|
||||
class Query {
|
||||
constructor(database, _delegate) {
|
||||
this.database = database;
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
on(eventType, callback, cancelCallbackOrContext, context) {
|
||||
var _a;
|
||||
validateArgCount('Query.on', 2, 4, arguments.length);
|
||||
validateCallback('Query.on', 'callback', callback, false);
|
||||
const ret = Query.getCancelAndContextArgs_('Query.on', cancelCallbackOrContext, context);
|
||||
const valueCallback = (expSnapshot, previousChildName) => {
|
||||
callback.call(ret.context, new DataSnapshot(this.database, expSnapshot), previousChildName);
|
||||
};
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = ret.context;
|
||||
const cancelCallback = (_a = ret.cancel) === null || _a === void 0 ? void 0 : _a.bind(ret.context);
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
onValue(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_added':
|
||||
onChildAdded(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_removed':
|
||||
onChildRemoved(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_changed':
|
||||
onChildChanged(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_moved':
|
||||
onChildMoved(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
default:
|
||||
throw new Error(errorPrefix('Query.on', 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
}
|
||||
off(eventType, callback, context) {
|
||||
validateArgCount('Query.off', 0, 3, arguments.length);
|
||||
validateEventType('Query.off', eventType, true);
|
||||
validateCallback('Query.off', 'callback', callback, true);
|
||||
validateContextObject('Query.off', 'context', context, true);
|
||||
if (callback) {
|
||||
const valueCallback = () => { };
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = context;
|
||||
off(this._delegate, eventType, valueCallback);
|
||||
}
|
||||
else {
|
||||
off(this._delegate, eventType);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the server-value for this query, or return a cached value if not connected.
|
||||
*/
|
||||
get() {
|
||||
return get(this._delegate).then(expSnapshot => {
|
||||
return new DataSnapshot(this.database, expSnapshot);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Attaches a listener, waits for the first event, and then removes the listener
|
||||
*/
|
||||
once(eventType, callback, failureCallbackOrContext, context) {
|
||||
validateArgCount('Query.once', 1, 4, arguments.length);
|
||||
validateCallback('Query.once', 'callback', callback, true);
|
||||
const ret = Query.getCancelAndContextArgs_('Query.once', failureCallbackOrContext, context);
|
||||
const deferred = new Deferred();
|
||||
const valueCallback = (expSnapshot, previousChildName) => {
|
||||
const result = new DataSnapshot(this.database, expSnapshot);
|
||||
if (callback) {
|
||||
callback.call(ret.context, result, previousChildName);
|
||||
}
|
||||
deferred.resolve(result);
|
||||
};
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = ret.context;
|
||||
const cancelCallback = (error) => {
|
||||
if (ret.cancel) {
|
||||
ret.cancel.call(ret.context, error);
|
||||
}
|
||||
deferred.reject(error);
|
||||
};
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
onValue(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_added':
|
||||
onChildAdded(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_removed':
|
||||
onChildRemoved(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_changed':
|
||||
onChildChanged(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_moved':
|
||||
onChildMoved(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Error(errorPrefix('Query.once', 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
return deferred.promise;
|
||||
}
|
||||
/**
|
||||
* Set a limit and anchor it to the start of the window.
|
||||
*/
|
||||
limitToFirst(limit) {
|
||||
validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, limitToFirst(limit)));
|
||||
}
|
||||
/**
|
||||
* Set a limit and anchor it to the end of the window.
|
||||
*/
|
||||
limitToLast(limit) {
|
||||
validateArgCount('Query.limitToLast', 1, 1, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, limitToLast(limit)));
|
||||
}
|
||||
/**
|
||||
* Given a child path, return a new query ordered by the specified grandchild path.
|
||||
*/
|
||||
orderByChild(path) {
|
||||
validateArgCount('Query.orderByChild', 1, 1, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByChild(path)));
|
||||
}
|
||||
/**
|
||||
* Return a new query ordered by the KeyIndex
|
||||
*/
|
||||
orderByKey() {
|
||||
validateArgCount('Query.orderByKey', 0, 0, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByKey()));
|
||||
}
|
||||
/**
|
||||
* Return a new query ordered by the PriorityIndex
|
||||
*/
|
||||
orderByPriority() {
|
||||
validateArgCount('Query.orderByPriority', 0, 0, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByPriority()));
|
||||
}
|
||||
/**
|
||||
* Return a new query ordered by the ValueIndex
|
||||
*/
|
||||
orderByValue() {
|
||||
validateArgCount('Query.orderByValue', 0, 0, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByValue()));
|
||||
}
|
||||
startAt(value = null, name) {
|
||||
validateArgCount('Query.startAt', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, startAt(value, name)));
|
||||
}
|
||||
startAfter(value = null, name) {
|
||||
validateArgCount('Query.startAfter', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, startAfter(value, name)));
|
||||
}
|
||||
endAt(value = null, name) {
|
||||
validateArgCount('Query.endAt', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, endAt(value, name)));
|
||||
}
|
||||
endBefore(value = null, name) {
|
||||
validateArgCount('Query.endBefore', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, endBefore(value, name)));
|
||||
}
|
||||
/**
|
||||
* Load the selection of children with exactly the specified value, and, optionally,
|
||||
* the specified name.
|
||||
*/
|
||||
equalTo(value, name) {
|
||||
validateArgCount('Query.equalTo', 1, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, equalTo(value, name)));
|
||||
}
|
||||
/**
|
||||
* @returns URL for this location.
|
||||
*/
|
||||
toString() {
|
||||
validateArgCount('Query.toString', 0, 0, arguments.length);
|
||||
return this._delegate.toString();
|
||||
}
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users.
|
||||
toJSON() {
|
||||
// An optional spacer argument is unnecessary for a string.
|
||||
validateArgCount('Query.toJSON', 0, 1, arguments.length);
|
||||
return this._delegate.toJSON();
|
||||
}
|
||||
/**
|
||||
* Return true if this query and the provided query are equivalent; otherwise, return false.
|
||||
*/
|
||||
isEqual(other) {
|
||||
validateArgCount('Query.isEqual', 1, 1, arguments.length);
|
||||
if (!(other instanceof Query)) {
|
||||
const error = 'Query.isEqual failed: First argument must be an instance of firebase.database.Query.';
|
||||
throw new Error(error);
|
||||
}
|
||||
return this._delegate.isEqual(other._delegate);
|
||||
}
|
||||
/**
|
||||
* Helper used by .on and .once to extract the context and or cancel arguments.
|
||||
* @param fnName - The function name (on or once)
|
||||
*
|
||||
*/
|
||||
static getCancelAndContextArgs_(fnName, cancelOrContext, context) {
|
||||
const ret = { cancel: undefined, context: undefined };
|
||||
if (cancelOrContext && context) {
|
||||
ret.cancel = cancelOrContext;
|
||||
validateCallback(fnName, 'cancel', ret.cancel, true);
|
||||
ret.context = context;
|
||||
validateContextObject(fnName, 'context', ret.context, true);
|
||||
}
|
||||
else if (cancelOrContext) {
|
||||
// we have either a cancel callback or a context.
|
||||
if (typeof cancelOrContext === 'object' && cancelOrContext !== null) {
|
||||
// it's a context!
|
||||
ret.context = cancelOrContext;
|
||||
}
|
||||
else if (typeof cancelOrContext === 'function') {
|
||||
ret.cancel = cancelOrContext;
|
||||
}
|
||||
else {
|
||||
throw new Error(errorPrefix(fnName, 'cancelOrContext') +
|
||||
' must either be a cancel callback or a context object.');
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
get ref() {
|
||||
return new Reference(this.database, new _ReferenceImpl(this._delegate._repo, this._delegate._path));
|
||||
}
|
||||
}
|
||||
class Reference extends Query {
|
||||
/**
|
||||
* Call options:
|
||||
* new Reference(Repo, Path) or
|
||||
* new Reference(url: string, string|RepoManager)
|
||||
*
|
||||
* Externally - this is the firebase.database.Reference type.
|
||||
*/
|
||||
constructor(database, _delegate) {
|
||||
super(database, new _QueryImpl(_delegate._repo, _delegate._path, new _QueryParams(), false));
|
||||
this.database = database;
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
/** @returns {?string} */
|
||||
getKey() {
|
||||
validateArgCount('Reference.key', 0, 0, arguments.length);
|
||||
return this._delegate.key;
|
||||
}
|
||||
child(pathString) {
|
||||
validateArgCount('Reference.child', 1, 1, arguments.length);
|
||||
if (typeof pathString === 'number') {
|
||||
pathString = String(pathString);
|
||||
}
|
||||
return new Reference(this.database, child(this._delegate, pathString));
|
||||
}
|
||||
/** @returns {?Reference} */
|
||||
getParent() {
|
||||
validateArgCount('Reference.parent', 0, 0, arguments.length);
|
||||
const parent = this._delegate.parent;
|
||||
return parent ? new Reference(this.database, parent) : null;
|
||||
}
|
||||
/** @returns {!Reference} */
|
||||
getRoot() {
|
||||
validateArgCount('Reference.root', 0, 0, arguments.length);
|
||||
return new Reference(this.database, this._delegate.root);
|
||||
}
|
||||
set(newVal, onComplete) {
|
||||
validateArgCount('Reference.set', 1, 2, arguments.length);
|
||||
validateCallback('Reference.set', 'onComplete', onComplete, true);
|
||||
const result = set(this._delegate, newVal);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
update(values, onComplete) {
|
||||
validateArgCount('Reference.update', 1, 2, arguments.length);
|
||||
if (Array.isArray(values)) {
|
||||
const newObjectToMerge = {};
|
||||
for (let i = 0; i < values.length; ++i) {
|
||||
newObjectToMerge['' + i] = values[i];
|
||||
}
|
||||
values = newObjectToMerge;
|
||||
warn('Passing an Array to Firebase.update() is deprecated. ' +
|
||||
'Use set() if you want to overwrite the existing data, or ' +
|
||||
'an Object with integer keys if you really do want to ' +
|
||||
'only update some of the children.');
|
||||
}
|
||||
_validateWritablePath('Reference.update', this._delegate._path);
|
||||
validateCallback('Reference.update', 'onComplete', onComplete, true);
|
||||
const result = update(this._delegate, values);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
setWithPriority(newVal, newPriority, onComplete) {
|
||||
validateArgCount('Reference.setWithPriority', 2, 3, arguments.length);
|
||||
validateCallback('Reference.setWithPriority', 'onComplete', onComplete, true);
|
||||
const result = setWithPriority(this._delegate, newVal, newPriority);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
remove(onComplete) {
|
||||
validateArgCount('Reference.remove', 0, 1, arguments.length);
|
||||
validateCallback('Reference.remove', 'onComplete', onComplete, true);
|
||||
const result = remove(this._delegate);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
transaction(transactionUpdate, onComplete, applyLocally) {
|
||||
validateArgCount('Reference.transaction', 1, 3, arguments.length);
|
||||
validateCallback('Reference.transaction', 'transactionUpdate', transactionUpdate, false);
|
||||
validateCallback('Reference.transaction', 'onComplete', onComplete, true);
|
||||
validateBoolean('Reference.transaction', 'applyLocally', applyLocally, true);
|
||||
const result = runTransaction(this._delegate, transactionUpdate, {
|
||||
applyLocally
|
||||
}).then(transactionResult => new TransactionResult(transactionResult.committed, new DataSnapshot(this.database, transactionResult.snapshot)));
|
||||
if (onComplete) {
|
||||
result.then(transactionResult => onComplete(null, transactionResult.committed, transactionResult.snapshot), error => onComplete(error, false, null));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
setPriority(priority, onComplete) {
|
||||
validateArgCount('Reference.setPriority', 1, 2, arguments.length);
|
||||
validateCallback('Reference.setPriority', 'onComplete', onComplete, true);
|
||||
const result = setPriority(this._delegate, priority);
|
||||
if (onComplete) {
|
||||
result.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
push(value, onComplete) {
|
||||
validateArgCount('Reference.push', 0, 2, arguments.length);
|
||||
validateCallback('Reference.push', 'onComplete', onComplete, true);
|
||||
const expPromise = push(this._delegate, value);
|
||||
const promise = expPromise.then(expRef => new Reference(this.database, expRef));
|
||||
if (onComplete) {
|
||||
promise.then(() => onComplete(null), error => onComplete(error));
|
||||
}
|
||||
const result = new Reference(this.database, expPromise);
|
||||
result.then = promise.then.bind(promise);
|
||||
result.catch = promise.catch.bind(promise, undefined);
|
||||
return result;
|
||||
}
|
||||
onDisconnect() {
|
||||
_validateWritablePath('Reference.onDisconnect', this._delegate._path);
|
||||
return new OnDisconnect(new OnDisconnect$1(this._delegate._repo, this._delegate._path));
|
||||
}
|
||||
get key() {
|
||||
return this.getKey();
|
||||
}
|
||||
get parent() {
|
||||
return this.getParent();
|
||||
}
|
||||
get root() {
|
||||
return this.getRoot();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Class representing a firebase database.
|
||||
*/
|
||||
class Database {
|
||||
/**
|
||||
* The constructor should not be called by users of our public API.
|
||||
*/
|
||||
constructor(_delegate, app) {
|
||||
this._delegate = _delegate;
|
||||
this.app = app;
|
||||
this.INTERNAL = {
|
||||
delete: () => this._delegate._delete()
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Modify this instance to communicate with the Realtime Database emulator.
|
||||
*
|
||||
* <p>Note: This method must be called before performing any other operation.
|
||||
*
|
||||
* @param host - the emulator host (ex: localhost)
|
||||
* @param port - the emulator port (ex: 8080)
|
||||
* @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
|
||||
*/
|
||||
useEmulator(host, port, options = {}) {
|
||||
connectDatabaseEmulator(this._delegate, host, port, options);
|
||||
}
|
||||
ref(path) {
|
||||
validateArgCount('database.ref', 0, 1, arguments.length);
|
||||
if (path instanceof Reference) {
|
||||
const childRef = refFromURL(this._delegate, path.toString());
|
||||
return new Reference(this, childRef);
|
||||
}
|
||||
else {
|
||||
const childRef = ref(this._delegate, path);
|
||||
return new Reference(this, childRef);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a reference to the root or the path specified in url.
|
||||
* We throw a exception if the url is not in the same domain as the
|
||||
* current repo.
|
||||
* @returns Firebase reference.
|
||||
*/
|
||||
refFromURL(url) {
|
||||
const apiName = 'database.refFromURL';
|
||||
validateArgCount(apiName, 1, 1, arguments.length);
|
||||
const childRef = refFromURL(this._delegate, url);
|
||||
return new Reference(this, childRef);
|
||||
}
|
||||
// Make individual repo go offline.
|
||||
goOffline() {
|
||||
validateArgCount('database.goOffline', 0, 0, arguments.length);
|
||||
return goOffline(this._delegate);
|
||||
}
|
||||
goOnline() {
|
||||
validateArgCount('database.goOnline', 0, 0, arguments.length);
|
||||
return goOnline(this._delegate);
|
||||
}
|
||||
}
|
||||
Database.ServerValue = {
|
||||
TIMESTAMP: serverTimestamp(),
|
||||
increment: (delta) => increment(delta)
|
||||
};
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Used by console to create a database based on the app,
|
||||
* passed database URL and a custom auth implementation.
|
||||
*
|
||||
* @param app - A valid FirebaseApp-like object
|
||||
* @param url - A valid Firebase databaseURL
|
||||
* @param version - custom version e.g. firebase-admin version
|
||||
* @param customAuthImpl - custom auth implementation
|
||||
*/
|
||||
function initStandalone({ app, url, version, customAuthImpl, namespace, nodeAdmin = false }) {
|
||||
_setSDKVersion(version);
|
||||
/**
|
||||
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
|
||||
* any actual function.
|
||||
*/
|
||||
const authProvider = new Provider('auth-internal', new ComponentContainer('database-standalone'));
|
||||
authProvider.setComponent(new Component('auth-internal', () => customAuthImpl, "PRIVATE" /* PRIVATE */));
|
||||
return {
|
||||
instance: new Database(_repoManagerDatabaseFromApp(app, authProvider,
|
||||
/* appCheckProvider= */ undefined, url, nodeAdmin), app),
|
||||
namespace
|
||||
};
|
||||
}
|
||||
|
||||
var INTERNAL = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
initStandalone: initStandalone
|
||||
});
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 ServerValue = Database.ServerValue;
|
||||
function registerDatabase(instance) {
|
||||
// Register the Database Service with the 'firebase' namespace.
|
||||
instance.INTERNAL.registerComponent(new Component('database-compat', (container, { instanceIdentifier: url }) => {
|
||||
/* Dependencies */
|
||||
// getImmediate for FirebaseApp will always succeed
|
||||
const app = container.getProvider('app-compat').getImmediate();
|
||||
const databaseExp = container
|
||||
.getProvider('database')
|
||||
.getImmediate({ identifier: url });
|
||||
return new Database(databaseExp, app);
|
||||
}, "PUBLIC" /* PUBLIC */)
|
||||
.setServiceProps(
|
||||
// firebase.database namespace properties
|
||||
{
|
||||
Reference,
|
||||
Query,
|
||||
Database,
|
||||
DataSnapshot,
|
||||
enableLogging,
|
||||
INTERNAL,
|
||||
ServerValue
|
||||
})
|
||||
.setMultipleInstances(true));
|
||||
instance.registerVersion(name, version);
|
||||
}
|
||||
registerDatabase(firebase);
|
||||
|
||||
export { registerDatabase };
|
||||
//# sourceMappingURL=index.esm2017.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+923
@@ -0,0 +1,923 @@
|
||||
import firebase from '@firebase/app-compat';
|
||||
import { Provider, ComponentContainer, Component } from '@firebase/component';
|
||||
import { _validatePathString, onChildMoved, onChildChanged, onChildRemoved, onChildAdded, onValue, off, get, query, limitToFirst, limitToLast, orderByChild, orderByKey, orderByPriority, orderByValue, startAt, startAfter, endAt, endBefore, equalTo, _ReferenceImpl, _QueryImpl, _QueryParams, child, set, _validateWritablePath, update, setWithPriority, remove, runTransaction, setPriority, push, OnDisconnect as OnDisconnect$1, connectDatabaseEmulator, refFromURL, ref, goOffline, goOnline, serverTimestamp, increment, _setSDKVersion, _repoManagerDatabaseFromApp, enableLogging } from '@firebase/database';
|
||||
import { errorPrefix, validateArgCount, validateCallback, validateContextObject, Deferred } from '@firebase/util';
|
||||
import { __extends } from 'tslib';
|
||||
import { Logger } from '@firebase/logger';
|
||||
|
||||
var name = "@firebase/database-compat";
|
||||
var version = "0.1.4";
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 logClient = new Logger('@firebase/database-compat');
|
||||
var warn = function (msg) {
|
||||
var message = 'FIREBASE WARNING: ' + msg;
|
||||
logClient.warn(message);
|
||||
};
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 validateBoolean = function (fnName, argumentName, bool, optional) {
|
||||
if (optional && bool === undefined) {
|
||||
return;
|
||||
}
|
||||
if (typeof bool !== 'boolean') {
|
||||
throw new Error(errorPrefix(fnName, argumentName) + 'must be a boolean.');
|
||||
}
|
||||
};
|
||||
var validateEventType = function (fnName, eventType, optional) {
|
||||
if (optional && eventType === undefined) {
|
||||
return;
|
||||
}
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
case 'child_added':
|
||||
case 'child_removed':
|
||||
case 'child_changed':
|
||||
case 'child_moved':
|
||||
break;
|
||||
default:
|
||||
throw new Error(errorPrefix(fnName, 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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 OnDisconnect = /** @class */ (function () {
|
||||
function OnDisconnect(_delegate) {
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
OnDisconnect.prototype.cancel = function (onComplete) {
|
||||
validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
|
||||
validateCallback('OnDisconnect.cancel', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.cancel();
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.remove = function (onComplete) {
|
||||
validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
|
||||
validateCallback('OnDisconnect.remove', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.remove();
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.set = function (value, onComplete) {
|
||||
validateArgCount('OnDisconnect.set', 1, 2, arguments.length);
|
||||
validateCallback('OnDisconnect.set', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.set(value);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.setWithPriority = function (value, priority, onComplete) {
|
||||
validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
|
||||
validateCallback('OnDisconnect.setWithPriority', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.setWithPriority(value, priority);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.update = function (objectToMerge, onComplete) {
|
||||
validateArgCount('OnDisconnect.update', 1, 2, arguments.length);
|
||||
if (Array.isArray(objectToMerge)) {
|
||||
var newObjectToMerge = {};
|
||||
for (var i = 0; i < objectToMerge.length; ++i) {
|
||||
newObjectToMerge['' + i] = objectToMerge[i];
|
||||
}
|
||||
objectToMerge = newObjectToMerge;
|
||||
warn('Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the ' +
|
||||
'existing data, or an Object with integer keys if you really do want to only update some of the children.');
|
||||
}
|
||||
validateCallback('OnDisconnect.update', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.update(objectToMerge);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return OnDisconnect;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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 TransactionResult = /** @class */ (function () {
|
||||
/**
|
||||
* A type for the resolve value of Firebase.transaction.
|
||||
*/
|
||||
function TransactionResult(committed, snapshot) {
|
||||
this.committed = committed;
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users
|
||||
TransactionResult.prototype.toJSON = function () {
|
||||
validateArgCount('TransactionResult.toJSON', 0, 1, arguments.length);
|
||||
return { committed: this.committed, snapshot: this.snapshot.toJSON() };
|
||||
};
|
||||
return TransactionResult;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Class representing a firebase data snapshot. It wraps a SnapshotNode and
|
||||
* surfaces the public methods (val, forEach, etc.) we want to expose.
|
||||
*/
|
||||
var DataSnapshot = /** @class */ (function () {
|
||||
function DataSnapshot(_database, _delegate) {
|
||||
this._database = _database;
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
/**
|
||||
* Retrieves the snapshot contents as JSON. Returns null if the snapshot is
|
||||
* empty.
|
||||
*
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
DataSnapshot.prototype.val = function () {
|
||||
validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
|
||||
return this._delegate.val();
|
||||
};
|
||||
/**
|
||||
* Returns the snapshot contents as JSON, including priorities of node. Suitable for exporting
|
||||
* the entire node contents.
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
DataSnapshot.prototype.exportVal = function () {
|
||||
validateArgCount('DataSnapshot.exportVal', 0, 0, arguments.length);
|
||||
return this._delegate.exportVal();
|
||||
};
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users
|
||||
DataSnapshot.prototype.toJSON = function () {
|
||||
// Optional spacer argument is unnecessary because we're depending on recursion rather than stringifying the content
|
||||
validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
|
||||
return this._delegate.toJSON();
|
||||
};
|
||||
/**
|
||||
* Returns whether the snapshot contains a non-null value.
|
||||
*
|
||||
* @returns Whether the snapshot contains a non-null value, or is empty.
|
||||
*/
|
||||
DataSnapshot.prototype.exists = function () {
|
||||
validateArgCount('DataSnapshot.exists', 0, 0, arguments.length);
|
||||
return this._delegate.exists();
|
||||
};
|
||||
/**
|
||||
* Returns a DataSnapshot of the specified child node's contents.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns DataSnapshot for child node.
|
||||
*/
|
||||
DataSnapshot.prototype.child = function (path) {
|
||||
validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
|
||||
// Ensure the childPath is a string (can be a number)
|
||||
path = String(path);
|
||||
_validatePathString('DataSnapshot.child', 'path', path, false);
|
||||
return new DataSnapshot(this._database, this._delegate.child(path));
|
||||
};
|
||||
/**
|
||||
* Returns whether the snapshot contains a child at the specified path.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns Whether the child exists.
|
||||
*/
|
||||
DataSnapshot.prototype.hasChild = function (path) {
|
||||
validateArgCount('DataSnapshot.hasChild', 1, 1, arguments.length);
|
||||
_validatePathString('DataSnapshot.hasChild', 'path', path, false);
|
||||
return this._delegate.hasChild(path);
|
||||
};
|
||||
/**
|
||||
* Returns the priority of the object, or null if no priority was set.
|
||||
*
|
||||
* @returns The priority.
|
||||
*/
|
||||
DataSnapshot.prototype.getPriority = function () {
|
||||
validateArgCount('DataSnapshot.getPriority', 0, 0, arguments.length);
|
||||
return this._delegate.priority;
|
||||
};
|
||||
/**
|
||||
* Iterates through child nodes and calls the specified action for each one.
|
||||
*
|
||||
* @param action - Callback function to be called
|
||||
* for each child.
|
||||
* @returns True if forEach was canceled by action returning true for
|
||||
* one of the child nodes.
|
||||
*/
|
||||
DataSnapshot.prototype.forEach = function (action) {
|
||||
var _this = this;
|
||||
validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length);
|
||||
validateCallback('DataSnapshot.forEach', 'action', action, false);
|
||||
return this._delegate.forEach(function (expDataSnapshot) {
|
||||
return action(new DataSnapshot(_this._database, expDataSnapshot));
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Returns whether this DataSnapshot has children.
|
||||
* @returns True if the DataSnapshot contains 1 or more child nodes.
|
||||
*/
|
||||
DataSnapshot.prototype.hasChildren = function () {
|
||||
validateArgCount('DataSnapshot.hasChildren', 0, 0, arguments.length);
|
||||
return this._delegate.hasChildren();
|
||||
};
|
||||
Object.defineProperty(DataSnapshot.prototype, "key", {
|
||||
get: function () {
|
||||
return this._delegate.key;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns the number of children for this DataSnapshot.
|
||||
* @returns The number of children that this DataSnapshot contains.
|
||||
*/
|
||||
DataSnapshot.prototype.numChildren = function () {
|
||||
validateArgCount('DataSnapshot.numChildren', 0, 0, arguments.length);
|
||||
return this._delegate.size;
|
||||
};
|
||||
/**
|
||||
* @returns The Firebase reference for the location this snapshot's data came
|
||||
* from.
|
||||
*/
|
||||
DataSnapshot.prototype.getRef = function () {
|
||||
validateArgCount('DataSnapshot.ref', 0, 0, arguments.length);
|
||||
return new Reference(this._database, this._delegate.ref);
|
||||
};
|
||||
Object.defineProperty(DataSnapshot.prototype, "ref", {
|
||||
get: function () {
|
||||
return this.getRef();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return DataSnapshot;
|
||||
}());
|
||||
/**
|
||||
* A Query represents a filter to be applied to a firebase location. This object purely represents the
|
||||
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
|
||||
*
|
||||
* Since every Firebase reference is a query, Firebase inherits from this object.
|
||||
*/
|
||||
var Query = /** @class */ (function () {
|
||||
function Query(database, _delegate) {
|
||||
this.database = database;
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
Query.prototype.on = function (eventType, callback, cancelCallbackOrContext, context) {
|
||||
var _this = this;
|
||||
var _a;
|
||||
validateArgCount('Query.on', 2, 4, arguments.length);
|
||||
validateCallback('Query.on', 'callback', callback, false);
|
||||
var ret = Query.getCancelAndContextArgs_('Query.on', cancelCallbackOrContext, context);
|
||||
var valueCallback = function (expSnapshot, previousChildName) {
|
||||
callback.call(ret.context, new DataSnapshot(_this.database, expSnapshot), previousChildName);
|
||||
};
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = ret.context;
|
||||
var cancelCallback = (_a = ret.cancel) === null || _a === void 0 ? void 0 : _a.bind(ret.context);
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
onValue(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_added':
|
||||
onChildAdded(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_removed':
|
||||
onChildRemoved(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_changed':
|
||||
onChildChanged(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_moved':
|
||||
onChildMoved(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
default:
|
||||
throw new Error(errorPrefix('Query.on', 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
};
|
||||
Query.prototype.off = function (eventType, callback, context) {
|
||||
validateArgCount('Query.off', 0, 3, arguments.length);
|
||||
validateEventType('Query.off', eventType, true);
|
||||
validateCallback('Query.off', 'callback', callback, true);
|
||||
validateContextObject('Query.off', 'context', context, true);
|
||||
if (callback) {
|
||||
var valueCallback = function () { };
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = context;
|
||||
off(this._delegate, eventType, valueCallback);
|
||||
}
|
||||
else {
|
||||
off(this._delegate, eventType);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get the server-value for this query, or return a cached value if not connected.
|
||||
*/
|
||||
Query.prototype.get = function () {
|
||||
var _this = this;
|
||||
return get(this._delegate).then(function (expSnapshot) {
|
||||
return new DataSnapshot(_this.database, expSnapshot);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Attaches a listener, waits for the first event, and then removes the listener
|
||||
*/
|
||||
Query.prototype.once = function (eventType, callback, failureCallbackOrContext, context) {
|
||||
var _this = this;
|
||||
validateArgCount('Query.once', 1, 4, arguments.length);
|
||||
validateCallback('Query.once', 'callback', callback, true);
|
||||
var ret = Query.getCancelAndContextArgs_('Query.once', failureCallbackOrContext, context);
|
||||
var deferred = new Deferred();
|
||||
var valueCallback = function (expSnapshot, previousChildName) {
|
||||
var result = new DataSnapshot(_this.database, expSnapshot);
|
||||
if (callback) {
|
||||
callback.call(ret.context, result, previousChildName);
|
||||
}
|
||||
deferred.resolve(result);
|
||||
};
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = ret.context;
|
||||
var cancelCallback = function (error) {
|
||||
if (ret.cancel) {
|
||||
ret.cancel.call(ret.context, error);
|
||||
}
|
||||
deferred.reject(error);
|
||||
};
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
onValue(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_added':
|
||||
onChildAdded(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_removed':
|
||||
onChildRemoved(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_changed':
|
||||
onChildChanged(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_moved':
|
||||
onChildMoved(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Error(errorPrefix('Query.once', 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
return deferred.promise;
|
||||
};
|
||||
/**
|
||||
* Set a limit and anchor it to the start of the window.
|
||||
*/
|
||||
Query.prototype.limitToFirst = function (limit) {
|
||||
validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, limitToFirst(limit)));
|
||||
};
|
||||
/**
|
||||
* Set a limit and anchor it to the end of the window.
|
||||
*/
|
||||
Query.prototype.limitToLast = function (limit) {
|
||||
validateArgCount('Query.limitToLast', 1, 1, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, limitToLast(limit)));
|
||||
};
|
||||
/**
|
||||
* Given a child path, return a new query ordered by the specified grandchild path.
|
||||
*/
|
||||
Query.prototype.orderByChild = function (path) {
|
||||
validateArgCount('Query.orderByChild', 1, 1, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByChild(path)));
|
||||
};
|
||||
/**
|
||||
* Return a new query ordered by the KeyIndex
|
||||
*/
|
||||
Query.prototype.orderByKey = function () {
|
||||
validateArgCount('Query.orderByKey', 0, 0, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByKey()));
|
||||
};
|
||||
/**
|
||||
* Return a new query ordered by the PriorityIndex
|
||||
*/
|
||||
Query.prototype.orderByPriority = function () {
|
||||
validateArgCount('Query.orderByPriority', 0, 0, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByPriority()));
|
||||
};
|
||||
/**
|
||||
* Return a new query ordered by the ValueIndex
|
||||
*/
|
||||
Query.prototype.orderByValue = function () {
|
||||
validateArgCount('Query.orderByValue', 0, 0, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, orderByValue()));
|
||||
};
|
||||
Query.prototype.startAt = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
validateArgCount('Query.startAt', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, startAt(value, name)));
|
||||
};
|
||||
Query.prototype.startAfter = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
validateArgCount('Query.startAfter', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, startAfter(value, name)));
|
||||
};
|
||||
Query.prototype.endAt = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
validateArgCount('Query.endAt', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, endAt(value, name)));
|
||||
};
|
||||
Query.prototype.endBefore = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
validateArgCount('Query.endBefore', 0, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, endBefore(value, name)));
|
||||
};
|
||||
/**
|
||||
* Load the selection of children with exactly the specified value, and, optionally,
|
||||
* the specified name.
|
||||
*/
|
||||
Query.prototype.equalTo = function (value, name) {
|
||||
validateArgCount('Query.equalTo', 1, 2, arguments.length);
|
||||
return new Query(this.database, query(this._delegate, equalTo(value, name)));
|
||||
};
|
||||
/**
|
||||
* @returns URL for this location.
|
||||
*/
|
||||
Query.prototype.toString = function () {
|
||||
validateArgCount('Query.toString', 0, 0, arguments.length);
|
||||
return this._delegate.toString();
|
||||
};
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users.
|
||||
Query.prototype.toJSON = function () {
|
||||
// An optional spacer argument is unnecessary for a string.
|
||||
validateArgCount('Query.toJSON', 0, 1, arguments.length);
|
||||
return this._delegate.toJSON();
|
||||
};
|
||||
/**
|
||||
* Return true if this query and the provided query are equivalent; otherwise, return false.
|
||||
*/
|
||||
Query.prototype.isEqual = function (other) {
|
||||
validateArgCount('Query.isEqual', 1, 1, arguments.length);
|
||||
if (!(other instanceof Query)) {
|
||||
var error = 'Query.isEqual failed: First argument must be an instance of firebase.database.Query.';
|
||||
throw new Error(error);
|
||||
}
|
||||
return this._delegate.isEqual(other._delegate);
|
||||
};
|
||||
/**
|
||||
* Helper used by .on and .once to extract the context and or cancel arguments.
|
||||
* @param fnName - The function name (on or once)
|
||||
*
|
||||
*/
|
||||
Query.getCancelAndContextArgs_ = function (fnName, cancelOrContext, context) {
|
||||
var ret = { cancel: undefined, context: undefined };
|
||||
if (cancelOrContext && context) {
|
||||
ret.cancel = cancelOrContext;
|
||||
validateCallback(fnName, 'cancel', ret.cancel, true);
|
||||
ret.context = context;
|
||||
validateContextObject(fnName, 'context', ret.context, true);
|
||||
}
|
||||
else if (cancelOrContext) {
|
||||
// we have either a cancel callback or a context.
|
||||
if (typeof cancelOrContext === 'object' && cancelOrContext !== null) {
|
||||
// it's a context!
|
||||
ret.context = cancelOrContext;
|
||||
}
|
||||
else if (typeof cancelOrContext === 'function') {
|
||||
ret.cancel = cancelOrContext;
|
||||
}
|
||||
else {
|
||||
throw new Error(errorPrefix(fnName, 'cancelOrContext') +
|
||||
' must either be a cancel callback or a context object.');
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
Object.defineProperty(Query.prototype, "ref", {
|
||||
get: function () {
|
||||
return new Reference(this.database, new _ReferenceImpl(this._delegate._repo, this._delegate._path));
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return Query;
|
||||
}());
|
||||
var Reference = /** @class */ (function (_super) {
|
||||
__extends(Reference, _super);
|
||||
/**
|
||||
* Call options:
|
||||
* new Reference(Repo, Path) or
|
||||
* new Reference(url: string, string|RepoManager)
|
||||
*
|
||||
* Externally - this is the firebase.database.Reference type.
|
||||
*/
|
||||
function Reference(database, _delegate) {
|
||||
var _this = _super.call(this, database, new _QueryImpl(_delegate._repo, _delegate._path, new _QueryParams(), false)) || this;
|
||||
_this.database = database;
|
||||
_this._delegate = _delegate;
|
||||
return _this;
|
||||
}
|
||||
/** @returns {?string} */
|
||||
Reference.prototype.getKey = function () {
|
||||
validateArgCount('Reference.key', 0, 0, arguments.length);
|
||||
return this._delegate.key;
|
||||
};
|
||||
Reference.prototype.child = function (pathString) {
|
||||
validateArgCount('Reference.child', 1, 1, arguments.length);
|
||||
if (typeof pathString === 'number') {
|
||||
pathString = String(pathString);
|
||||
}
|
||||
return new Reference(this.database, child(this._delegate, pathString));
|
||||
};
|
||||
/** @returns {?Reference} */
|
||||
Reference.prototype.getParent = function () {
|
||||
validateArgCount('Reference.parent', 0, 0, arguments.length);
|
||||
var parent = this._delegate.parent;
|
||||
return parent ? new Reference(this.database, parent) : null;
|
||||
};
|
||||
/** @returns {!Reference} */
|
||||
Reference.prototype.getRoot = function () {
|
||||
validateArgCount('Reference.root', 0, 0, arguments.length);
|
||||
return new Reference(this.database, this._delegate.root);
|
||||
};
|
||||
Reference.prototype.set = function (newVal, onComplete) {
|
||||
validateArgCount('Reference.set', 1, 2, arguments.length);
|
||||
validateCallback('Reference.set', 'onComplete', onComplete, true);
|
||||
var result = set(this._delegate, newVal);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.update = function (values, onComplete) {
|
||||
validateArgCount('Reference.update', 1, 2, arguments.length);
|
||||
if (Array.isArray(values)) {
|
||||
var newObjectToMerge = {};
|
||||
for (var i = 0; i < values.length; ++i) {
|
||||
newObjectToMerge['' + i] = values[i];
|
||||
}
|
||||
values = newObjectToMerge;
|
||||
warn('Passing an Array to Firebase.update() is deprecated. ' +
|
||||
'Use set() if you want to overwrite the existing data, or ' +
|
||||
'an Object with integer keys if you really do want to ' +
|
||||
'only update some of the children.');
|
||||
}
|
||||
_validateWritablePath('Reference.update', this._delegate._path);
|
||||
validateCallback('Reference.update', 'onComplete', onComplete, true);
|
||||
var result = update(this._delegate, values);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.setWithPriority = function (newVal, newPriority, onComplete) {
|
||||
validateArgCount('Reference.setWithPriority', 2, 3, arguments.length);
|
||||
validateCallback('Reference.setWithPriority', 'onComplete', onComplete, true);
|
||||
var result = setWithPriority(this._delegate, newVal, newPriority);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.remove = function (onComplete) {
|
||||
validateArgCount('Reference.remove', 0, 1, arguments.length);
|
||||
validateCallback('Reference.remove', 'onComplete', onComplete, true);
|
||||
var result = remove(this._delegate);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.transaction = function (transactionUpdate, onComplete, applyLocally) {
|
||||
var _this = this;
|
||||
validateArgCount('Reference.transaction', 1, 3, arguments.length);
|
||||
validateCallback('Reference.transaction', 'transactionUpdate', transactionUpdate, false);
|
||||
validateCallback('Reference.transaction', 'onComplete', onComplete, true);
|
||||
validateBoolean('Reference.transaction', 'applyLocally', applyLocally, true);
|
||||
var result = runTransaction(this._delegate, transactionUpdate, {
|
||||
applyLocally: applyLocally
|
||||
}).then(function (transactionResult) {
|
||||
return new TransactionResult(transactionResult.committed, new DataSnapshot(_this.database, transactionResult.snapshot));
|
||||
});
|
||||
if (onComplete) {
|
||||
result.then(function (transactionResult) {
|
||||
return onComplete(null, transactionResult.committed, transactionResult.snapshot);
|
||||
}, function (error) { return onComplete(error, false, null); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.setPriority = function (priority, onComplete) {
|
||||
validateArgCount('Reference.setPriority', 1, 2, arguments.length);
|
||||
validateCallback('Reference.setPriority', 'onComplete', onComplete, true);
|
||||
var result = setPriority(this._delegate, priority);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.push = function (value, onComplete) {
|
||||
var _this = this;
|
||||
validateArgCount('Reference.push', 0, 2, arguments.length);
|
||||
validateCallback('Reference.push', 'onComplete', onComplete, true);
|
||||
var expPromise = push(this._delegate, value);
|
||||
var promise = expPromise.then(function (expRef) { return new Reference(_this.database, expRef); });
|
||||
if (onComplete) {
|
||||
promise.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
var result = new Reference(this.database, expPromise);
|
||||
result.then = promise.then.bind(promise);
|
||||
result.catch = promise.catch.bind(promise, undefined);
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.onDisconnect = function () {
|
||||
_validateWritablePath('Reference.onDisconnect', this._delegate._path);
|
||||
return new OnDisconnect(new OnDisconnect$1(this._delegate._repo, this._delegate._path));
|
||||
};
|
||||
Object.defineProperty(Reference.prototype, "key", {
|
||||
get: function () {
|
||||
return this.getKey();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Reference.prototype, "parent", {
|
||||
get: function () {
|
||||
return this.getParent();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Reference.prototype, "root", {
|
||||
get: function () {
|
||||
return this.getRoot();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return Reference;
|
||||
}(Query));
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Class representing a firebase database.
|
||||
*/
|
||||
var Database = /** @class */ (function () {
|
||||
/**
|
||||
* The constructor should not be called by users of our public API.
|
||||
*/
|
||||
function Database(_delegate, app) {
|
||||
var _this = this;
|
||||
this._delegate = _delegate;
|
||||
this.app = app;
|
||||
this.INTERNAL = {
|
||||
delete: function () { return _this._delegate._delete(); }
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Modify this instance to communicate with the Realtime Database emulator.
|
||||
*
|
||||
* <p>Note: This method must be called before performing any other operation.
|
||||
*
|
||||
* @param host - the emulator host (ex: localhost)
|
||||
* @param port - the emulator port (ex: 8080)
|
||||
* @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
|
||||
*/
|
||||
Database.prototype.useEmulator = function (host, port, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
connectDatabaseEmulator(this._delegate, host, port, options);
|
||||
};
|
||||
Database.prototype.ref = function (path) {
|
||||
validateArgCount('database.ref', 0, 1, arguments.length);
|
||||
if (path instanceof Reference) {
|
||||
var childRef = refFromURL(this._delegate, path.toString());
|
||||
return new Reference(this, childRef);
|
||||
}
|
||||
else {
|
||||
var childRef = ref(this._delegate, path);
|
||||
return new Reference(this, childRef);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns a reference to the root or the path specified in url.
|
||||
* We throw a exception if the url is not in the same domain as the
|
||||
* current repo.
|
||||
* @returns Firebase reference.
|
||||
*/
|
||||
Database.prototype.refFromURL = function (url) {
|
||||
var apiName = 'database.refFromURL';
|
||||
validateArgCount(apiName, 1, 1, arguments.length);
|
||||
var childRef = refFromURL(this._delegate, url);
|
||||
return new Reference(this, childRef);
|
||||
};
|
||||
// Make individual repo go offline.
|
||||
Database.prototype.goOffline = function () {
|
||||
validateArgCount('database.goOffline', 0, 0, arguments.length);
|
||||
return goOffline(this._delegate);
|
||||
};
|
||||
Database.prototype.goOnline = function () {
|
||||
validateArgCount('database.goOnline', 0, 0, arguments.length);
|
||||
return goOnline(this._delegate);
|
||||
};
|
||||
Database.ServerValue = {
|
||||
TIMESTAMP: serverTimestamp(),
|
||||
increment: function (delta) { return increment(delta); }
|
||||
};
|
||||
return Database;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Used by console to create a database based on the app,
|
||||
* passed database URL and a custom auth implementation.
|
||||
*
|
||||
* @param app - A valid FirebaseApp-like object
|
||||
* @param url - A valid Firebase databaseURL
|
||||
* @param version - custom version e.g. firebase-admin version
|
||||
* @param customAuthImpl - custom auth implementation
|
||||
*/
|
||||
function initStandalone(_a) {
|
||||
var app = _a.app, url = _a.url, version = _a.version, customAuthImpl = _a.customAuthImpl, namespace = _a.namespace, _b = _a.nodeAdmin, nodeAdmin = _b === void 0 ? false : _b;
|
||||
_setSDKVersion(version);
|
||||
/**
|
||||
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
|
||||
* any actual function.
|
||||
*/
|
||||
var authProvider = new Provider('auth-internal', new ComponentContainer('database-standalone'));
|
||||
authProvider.setComponent(new Component('auth-internal', function () { return customAuthImpl; }, "PRIVATE" /* PRIVATE */));
|
||||
return {
|
||||
instance: new Database(_repoManagerDatabaseFromApp(app, authProvider,
|
||||
/* appCheckProvider= */ undefined, url, nodeAdmin), app),
|
||||
namespace: namespace
|
||||
};
|
||||
}
|
||||
|
||||
var INTERNAL = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
initStandalone: initStandalone
|
||||
});
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 ServerValue = Database.ServerValue;
|
||||
function registerDatabase(instance) {
|
||||
// Register the Database Service with the 'firebase' namespace.
|
||||
instance.INTERNAL.registerComponent(new Component('database-compat', function (container, _a) {
|
||||
var url = _a.instanceIdentifier;
|
||||
/* Dependencies */
|
||||
// getImmediate for FirebaseApp will always succeed
|
||||
var app = container.getProvider('app-compat').getImmediate();
|
||||
var databaseExp = container
|
||||
.getProvider('database')
|
||||
.getImmediate({ identifier: url });
|
||||
return new Database(databaseExp, app);
|
||||
}, "PUBLIC" /* PUBLIC */)
|
||||
.setServiceProps(
|
||||
// firebase.database namespace properties
|
||||
{
|
||||
Reference: Reference,
|
||||
Query: Query,
|
||||
Database: Database,
|
||||
DataSnapshot: DataSnapshot,
|
||||
enableLogging: enableLogging,
|
||||
INTERNAL: INTERNAL,
|
||||
ServerValue: ServerValue
|
||||
})
|
||||
.setMultipleInstances(true));
|
||||
instance.registerVersion(name, version);
|
||||
}
|
||||
registerDatabase(firebase);
|
||||
|
||||
export { registerDatabase };
|
||||
//# sourceMappingURL=index.esm5.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+927
@@ -0,0 +1,927 @@
|
||||
'use strict';
|
||||
|
||||
var firebase = require('@firebase/app-compat');
|
||||
var component = require('@firebase/component');
|
||||
var database = require('@firebase/database');
|
||||
var util = require('@firebase/util');
|
||||
var tslib = require('tslib');
|
||||
var logger = require('@firebase/logger');
|
||||
|
||||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
||||
|
||||
var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
|
||||
|
||||
var name = "@firebase/database-compat";
|
||||
var version = "0.1.4";
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 logClient = new logger.Logger('@firebase/database-compat');
|
||||
var warn = function (msg) {
|
||||
var message = 'FIREBASE WARNING: ' + msg;
|
||||
logClient.warn(message);
|
||||
};
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 validateBoolean = function (fnName, argumentName, bool, optional) {
|
||||
if (optional && bool === undefined) {
|
||||
return;
|
||||
}
|
||||
if (typeof bool !== 'boolean') {
|
||||
throw new Error(util.errorPrefix(fnName, argumentName) + 'must be a boolean.');
|
||||
}
|
||||
};
|
||||
var validateEventType = function (fnName, eventType, optional) {
|
||||
if (optional && eventType === undefined) {
|
||||
return;
|
||||
}
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
case 'child_added':
|
||||
case 'child_removed':
|
||||
case 'child_changed':
|
||||
case 'child_moved':
|
||||
break;
|
||||
default:
|
||||
throw new Error(util.errorPrefix(fnName, 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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 OnDisconnect = /** @class */ (function () {
|
||||
function OnDisconnect(_delegate) {
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
OnDisconnect.prototype.cancel = function (onComplete) {
|
||||
util.validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
|
||||
util.validateCallback('OnDisconnect.cancel', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.cancel();
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.remove = function (onComplete) {
|
||||
util.validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
|
||||
util.validateCallback('OnDisconnect.remove', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.remove();
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.set = function (value, onComplete) {
|
||||
util.validateArgCount('OnDisconnect.set', 1, 2, arguments.length);
|
||||
util.validateCallback('OnDisconnect.set', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.set(value);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.setWithPriority = function (value, priority, onComplete) {
|
||||
util.validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
|
||||
util.validateCallback('OnDisconnect.setWithPriority', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.setWithPriority(value, priority);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
OnDisconnect.prototype.update = function (objectToMerge, onComplete) {
|
||||
util.validateArgCount('OnDisconnect.update', 1, 2, arguments.length);
|
||||
if (Array.isArray(objectToMerge)) {
|
||||
var newObjectToMerge = {};
|
||||
for (var i = 0; i < objectToMerge.length; ++i) {
|
||||
newObjectToMerge['' + i] = objectToMerge[i];
|
||||
}
|
||||
objectToMerge = newObjectToMerge;
|
||||
warn('Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the ' +
|
||||
'existing data, or an Object with integer keys if you really do want to only update some of the children.');
|
||||
}
|
||||
util.validateCallback('OnDisconnect.update', 'onComplete', onComplete, true);
|
||||
var result = this._delegate.update(objectToMerge);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return OnDisconnect;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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 TransactionResult = /** @class */ (function () {
|
||||
/**
|
||||
* A type for the resolve value of Firebase.transaction.
|
||||
*/
|
||||
function TransactionResult(committed, snapshot) {
|
||||
this.committed = committed;
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users
|
||||
TransactionResult.prototype.toJSON = function () {
|
||||
util.validateArgCount('TransactionResult.toJSON', 0, 1, arguments.length);
|
||||
return { committed: this.committed, snapshot: this.snapshot.toJSON() };
|
||||
};
|
||||
return TransactionResult;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Class representing a firebase data snapshot. It wraps a SnapshotNode and
|
||||
* surfaces the public methods (val, forEach, etc.) we want to expose.
|
||||
*/
|
||||
var DataSnapshot = /** @class */ (function () {
|
||||
function DataSnapshot(_database, _delegate) {
|
||||
this._database = _database;
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
/**
|
||||
* Retrieves the snapshot contents as JSON. Returns null if the snapshot is
|
||||
* empty.
|
||||
*
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
DataSnapshot.prototype.val = function () {
|
||||
util.validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
|
||||
return this._delegate.val();
|
||||
};
|
||||
/**
|
||||
* Returns the snapshot contents as JSON, including priorities of node. Suitable for exporting
|
||||
* the entire node contents.
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
DataSnapshot.prototype.exportVal = function () {
|
||||
util.validateArgCount('DataSnapshot.exportVal', 0, 0, arguments.length);
|
||||
return this._delegate.exportVal();
|
||||
};
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users
|
||||
DataSnapshot.prototype.toJSON = function () {
|
||||
// Optional spacer argument is unnecessary because we're depending on recursion rather than stringifying the content
|
||||
util.validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
|
||||
return this._delegate.toJSON();
|
||||
};
|
||||
/**
|
||||
* Returns whether the snapshot contains a non-null value.
|
||||
*
|
||||
* @returns Whether the snapshot contains a non-null value, or is empty.
|
||||
*/
|
||||
DataSnapshot.prototype.exists = function () {
|
||||
util.validateArgCount('DataSnapshot.exists', 0, 0, arguments.length);
|
||||
return this._delegate.exists();
|
||||
};
|
||||
/**
|
||||
* Returns a DataSnapshot of the specified child node's contents.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns DataSnapshot for child node.
|
||||
*/
|
||||
DataSnapshot.prototype.child = function (path) {
|
||||
util.validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
|
||||
// Ensure the childPath is a string (can be a number)
|
||||
path = String(path);
|
||||
database._validatePathString('DataSnapshot.child', 'path', path, false);
|
||||
return new DataSnapshot(this._database, this._delegate.child(path));
|
||||
};
|
||||
/**
|
||||
* Returns whether the snapshot contains a child at the specified path.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns Whether the child exists.
|
||||
*/
|
||||
DataSnapshot.prototype.hasChild = function (path) {
|
||||
util.validateArgCount('DataSnapshot.hasChild', 1, 1, arguments.length);
|
||||
database._validatePathString('DataSnapshot.hasChild', 'path', path, false);
|
||||
return this._delegate.hasChild(path);
|
||||
};
|
||||
/**
|
||||
* Returns the priority of the object, or null if no priority was set.
|
||||
*
|
||||
* @returns The priority.
|
||||
*/
|
||||
DataSnapshot.prototype.getPriority = function () {
|
||||
util.validateArgCount('DataSnapshot.getPriority', 0, 0, arguments.length);
|
||||
return this._delegate.priority;
|
||||
};
|
||||
/**
|
||||
* Iterates through child nodes and calls the specified action for each one.
|
||||
*
|
||||
* @param action - Callback function to be called
|
||||
* for each child.
|
||||
* @returns True if forEach was canceled by action returning true for
|
||||
* one of the child nodes.
|
||||
*/
|
||||
DataSnapshot.prototype.forEach = function (action) {
|
||||
var _this = this;
|
||||
util.validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length);
|
||||
util.validateCallback('DataSnapshot.forEach', 'action', action, false);
|
||||
return this._delegate.forEach(function (expDataSnapshot) {
|
||||
return action(new DataSnapshot(_this._database, expDataSnapshot));
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Returns whether this DataSnapshot has children.
|
||||
* @returns True if the DataSnapshot contains 1 or more child nodes.
|
||||
*/
|
||||
DataSnapshot.prototype.hasChildren = function () {
|
||||
util.validateArgCount('DataSnapshot.hasChildren', 0, 0, arguments.length);
|
||||
return this._delegate.hasChildren();
|
||||
};
|
||||
Object.defineProperty(DataSnapshot.prototype, "key", {
|
||||
get: function () {
|
||||
return this._delegate.key;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns the number of children for this DataSnapshot.
|
||||
* @returns The number of children that this DataSnapshot contains.
|
||||
*/
|
||||
DataSnapshot.prototype.numChildren = function () {
|
||||
util.validateArgCount('DataSnapshot.numChildren', 0, 0, arguments.length);
|
||||
return this._delegate.size;
|
||||
};
|
||||
/**
|
||||
* @returns The Firebase reference for the location this snapshot's data came
|
||||
* from.
|
||||
*/
|
||||
DataSnapshot.prototype.getRef = function () {
|
||||
util.validateArgCount('DataSnapshot.ref', 0, 0, arguments.length);
|
||||
return new Reference(this._database, this._delegate.ref);
|
||||
};
|
||||
Object.defineProperty(DataSnapshot.prototype, "ref", {
|
||||
get: function () {
|
||||
return this.getRef();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return DataSnapshot;
|
||||
}());
|
||||
/**
|
||||
* A Query represents a filter to be applied to a firebase location. This object purely represents the
|
||||
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
|
||||
*
|
||||
* Since every Firebase reference is a query, Firebase inherits from this object.
|
||||
*/
|
||||
var Query = /** @class */ (function () {
|
||||
function Query(database, _delegate) {
|
||||
this.database = database;
|
||||
this._delegate = _delegate;
|
||||
}
|
||||
Query.prototype.on = function (eventType, callback, cancelCallbackOrContext, context) {
|
||||
var _this = this;
|
||||
var _a;
|
||||
util.validateArgCount('Query.on', 2, 4, arguments.length);
|
||||
util.validateCallback('Query.on', 'callback', callback, false);
|
||||
var ret = Query.getCancelAndContextArgs_('Query.on', cancelCallbackOrContext, context);
|
||||
var valueCallback = function (expSnapshot, previousChildName) {
|
||||
callback.call(ret.context, new DataSnapshot(_this.database, expSnapshot), previousChildName);
|
||||
};
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = ret.context;
|
||||
var cancelCallback = (_a = ret.cancel) === null || _a === void 0 ? void 0 : _a.bind(ret.context);
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
database.onValue(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_added':
|
||||
database.onChildAdded(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_removed':
|
||||
database.onChildRemoved(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_changed':
|
||||
database.onChildChanged(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
case 'child_moved':
|
||||
database.onChildMoved(this._delegate, valueCallback, cancelCallback);
|
||||
return callback;
|
||||
default:
|
||||
throw new Error(util.errorPrefix('Query.on', 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
};
|
||||
Query.prototype.off = function (eventType, callback, context) {
|
||||
util.validateArgCount('Query.off', 0, 3, arguments.length);
|
||||
validateEventType('Query.off', eventType, true);
|
||||
util.validateCallback('Query.off', 'callback', callback, true);
|
||||
util.validateContextObject('Query.off', 'context', context, true);
|
||||
if (callback) {
|
||||
var valueCallback = function () { };
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = context;
|
||||
database.off(this._delegate, eventType, valueCallback);
|
||||
}
|
||||
else {
|
||||
database.off(this._delegate, eventType);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get the server-value for this query, or return a cached value if not connected.
|
||||
*/
|
||||
Query.prototype.get = function () {
|
||||
var _this = this;
|
||||
return database.get(this._delegate).then(function (expSnapshot) {
|
||||
return new DataSnapshot(_this.database, expSnapshot);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Attaches a listener, waits for the first event, and then removes the listener
|
||||
*/
|
||||
Query.prototype.once = function (eventType, callback, failureCallbackOrContext, context) {
|
||||
var _this = this;
|
||||
util.validateArgCount('Query.once', 1, 4, arguments.length);
|
||||
util.validateCallback('Query.once', 'callback', callback, true);
|
||||
var ret = Query.getCancelAndContextArgs_('Query.once', failureCallbackOrContext, context);
|
||||
var deferred = new util.Deferred();
|
||||
var valueCallback = function (expSnapshot, previousChildName) {
|
||||
var result = new DataSnapshot(_this.database, expSnapshot);
|
||||
if (callback) {
|
||||
callback.call(ret.context, result, previousChildName);
|
||||
}
|
||||
deferred.resolve(result);
|
||||
};
|
||||
valueCallback.userCallback = callback;
|
||||
valueCallback.context = ret.context;
|
||||
var cancelCallback = function (error) {
|
||||
if (ret.cancel) {
|
||||
ret.cancel.call(ret.context, error);
|
||||
}
|
||||
deferred.reject(error);
|
||||
};
|
||||
switch (eventType) {
|
||||
case 'value':
|
||||
database.onValue(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_added':
|
||||
database.onChildAdded(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_removed':
|
||||
database.onChildRemoved(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_changed':
|
||||
database.onChildChanged(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
case 'child_moved':
|
||||
database.onChildMoved(this._delegate, valueCallback, cancelCallback, {
|
||||
onlyOnce: true
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Error(util.errorPrefix('Query.once', 'eventType') +
|
||||
'must be a valid event type = "value", "child_added", "child_removed", ' +
|
||||
'"child_changed", or "child_moved".');
|
||||
}
|
||||
return deferred.promise;
|
||||
};
|
||||
/**
|
||||
* Set a limit and anchor it to the start of the window.
|
||||
*/
|
||||
Query.prototype.limitToFirst = function (limit) {
|
||||
util.validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.limitToFirst(limit)));
|
||||
};
|
||||
/**
|
||||
* Set a limit and anchor it to the end of the window.
|
||||
*/
|
||||
Query.prototype.limitToLast = function (limit) {
|
||||
util.validateArgCount('Query.limitToLast', 1, 1, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.limitToLast(limit)));
|
||||
};
|
||||
/**
|
||||
* Given a child path, return a new query ordered by the specified grandchild path.
|
||||
*/
|
||||
Query.prototype.orderByChild = function (path) {
|
||||
util.validateArgCount('Query.orderByChild', 1, 1, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.orderByChild(path)));
|
||||
};
|
||||
/**
|
||||
* Return a new query ordered by the KeyIndex
|
||||
*/
|
||||
Query.prototype.orderByKey = function () {
|
||||
util.validateArgCount('Query.orderByKey', 0, 0, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.orderByKey()));
|
||||
};
|
||||
/**
|
||||
* Return a new query ordered by the PriorityIndex
|
||||
*/
|
||||
Query.prototype.orderByPriority = function () {
|
||||
util.validateArgCount('Query.orderByPriority', 0, 0, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.orderByPriority()));
|
||||
};
|
||||
/**
|
||||
* Return a new query ordered by the ValueIndex
|
||||
*/
|
||||
Query.prototype.orderByValue = function () {
|
||||
util.validateArgCount('Query.orderByValue', 0, 0, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.orderByValue()));
|
||||
};
|
||||
Query.prototype.startAt = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
util.validateArgCount('Query.startAt', 0, 2, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.startAt(value, name)));
|
||||
};
|
||||
Query.prototype.startAfter = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
util.validateArgCount('Query.startAfter', 0, 2, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.startAfter(value, name)));
|
||||
};
|
||||
Query.prototype.endAt = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
util.validateArgCount('Query.endAt', 0, 2, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.endAt(value, name)));
|
||||
};
|
||||
Query.prototype.endBefore = function (value, name) {
|
||||
if (value === void 0) { value = null; }
|
||||
util.validateArgCount('Query.endBefore', 0, 2, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.endBefore(value, name)));
|
||||
};
|
||||
/**
|
||||
* Load the selection of children with exactly the specified value, and, optionally,
|
||||
* the specified name.
|
||||
*/
|
||||
Query.prototype.equalTo = function (value, name) {
|
||||
util.validateArgCount('Query.equalTo', 1, 2, arguments.length);
|
||||
return new Query(this.database, database.query(this._delegate, database.equalTo(value, name)));
|
||||
};
|
||||
/**
|
||||
* @returns URL for this location.
|
||||
*/
|
||||
Query.prototype.toString = function () {
|
||||
util.validateArgCount('Query.toString', 0, 0, arguments.length);
|
||||
return this._delegate.toString();
|
||||
};
|
||||
// Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
|
||||
// for end-users.
|
||||
Query.prototype.toJSON = function () {
|
||||
// An optional spacer argument is unnecessary for a string.
|
||||
util.validateArgCount('Query.toJSON', 0, 1, arguments.length);
|
||||
return this._delegate.toJSON();
|
||||
};
|
||||
/**
|
||||
* Return true if this query and the provided query are equivalent; otherwise, return false.
|
||||
*/
|
||||
Query.prototype.isEqual = function (other) {
|
||||
util.validateArgCount('Query.isEqual', 1, 1, arguments.length);
|
||||
if (!(other instanceof Query)) {
|
||||
var error = 'Query.isEqual failed: First argument must be an instance of firebase.database.Query.';
|
||||
throw new Error(error);
|
||||
}
|
||||
return this._delegate.isEqual(other._delegate);
|
||||
};
|
||||
/**
|
||||
* Helper used by .on and .once to extract the context and or cancel arguments.
|
||||
* @param fnName - The function name (on or once)
|
||||
*
|
||||
*/
|
||||
Query.getCancelAndContextArgs_ = function (fnName, cancelOrContext, context) {
|
||||
var ret = { cancel: undefined, context: undefined };
|
||||
if (cancelOrContext && context) {
|
||||
ret.cancel = cancelOrContext;
|
||||
util.validateCallback(fnName, 'cancel', ret.cancel, true);
|
||||
ret.context = context;
|
||||
util.validateContextObject(fnName, 'context', ret.context, true);
|
||||
}
|
||||
else if (cancelOrContext) {
|
||||
// we have either a cancel callback or a context.
|
||||
if (typeof cancelOrContext === 'object' && cancelOrContext !== null) {
|
||||
// it's a context!
|
||||
ret.context = cancelOrContext;
|
||||
}
|
||||
else if (typeof cancelOrContext === 'function') {
|
||||
ret.cancel = cancelOrContext;
|
||||
}
|
||||
else {
|
||||
throw new Error(util.errorPrefix(fnName, 'cancelOrContext') +
|
||||
' must either be a cancel callback or a context object.');
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
Object.defineProperty(Query.prototype, "ref", {
|
||||
get: function () {
|
||||
return new Reference(this.database, new database._ReferenceImpl(this._delegate._repo, this._delegate._path));
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return Query;
|
||||
}());
|
||||
var Reference = /** @class */ (function (_super) {
|
||||
tslib.__extends(Reference, _super);
|
||||
/**
|
||||
* Call options:
|
||||
* new Reference(Repo, Path) or
|
||||
* new Reference(url: string, string|RepoManager)
|
||||
*
|
||||
* Externally - this is the firebase.database.Reference type.
|
||||
*/
|
||||
function Reference(database$1, _delegate) {
|
||||
var _this = _super.call(this, database$1, new database._QueryImpl(_delegate._repo, _delegate._path, new database._QueryParams(), false)) || this;
|
||||
_this.database = database$1;
|
||||
_this._delegate = _delegate;
|
||||
return _this;
|
||||
}
|
||||
/** @returns {?string} */
|
||||
Reference.prototype.getKey = function () {
|
||||
util.validateArgCount('Reference.key', 0, 0, arguments.length);
|
||||
return this._delegate.key;
|
||||
};
|
||||
Reference.prototype.child = function (pathString) {
|
||||
util.validateArgCount('Reference.child', 1, 1, arguments.length);
|
||||
if (typeof pathString === 'number') {
|
||||
pathString = String(pathString);
|
||||
}
|
||||
return new Reference(this.database, database.child(this._delegate, pathString));
|
||||
};
|
||||
/** @returns {?Reference} */
|
||||
Reference.prototype.getParent = function () {
|
||||
util.validateArgCount('Reference.parent', 0, 0, arguments.length);
|
||||
var parent = this._delegate.parent;
|
||||
return parent ? new Reference(this.database, parent) : null;
|
||||
};
|
||||
/** @returns {!Reference} */
|
||||
Reference.prototype.getRoot = function () {
|
||||
util.validateArgCount('Reference.root', 0, 0, arguments.length);
|
||||
return new Reference(this.database, this._delegate.root);
|
||||
};
|
||||
Reference.prototype.set = function (newVal, onComplete) {
|
||||
util.validateArgCount('Reference.set', 1, 2, arguments.length);
|
||||
util.validateCallback('Reference.set', 'onComplete', onComplete, true);
|
||||
var result = database.set(this._delegate, newVal);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.update = function (values, onComplete) {
|
||||
util.validateArgCount('Reference.update', 1, 2, arguments.length);
|
||||
if (Array.isArray(values)) {
|
||||
var newObjectToMerge = {};
|
||||
for (var i = 0; i < values.length; ++i) {
|
||||
newObjectToMerge['' + i] = values[i];
|
||||
}
|
||||
values = newObjectToMerge;
|
||||
warn('Passing an Array to Firebase.update() is deprecated. ' +
|
||||
'Use set() if you want to overwrite the existing data, or ' +
|
||||
'an Object with integer keys if you really do want to ' +
|
||||
'only update some of the children.');
|
||||
}
|
||||
database._validateWritablePath('Reference.update', this._delegate._path);
|
||||
util.validateCallback('Reference.update', 'onComplete', onComplete, true);
|
||||
var result = database.update(this._delegate, values);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.setWithPriority = function (newVal, newPriority, onComplete) {
|
||||
util.validateArgCount('Reference.setWithPriority', 2, 3, arguments.length);
|
||||
util.validateCallback('Reference.setWithPriority', 'onComplete', onComplete, true);
|
||||
var result = database.setWithPriority(this._delegate, newVal, newPriority);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.remove = function (onComplete) {
|
||||
util.validateArgCount('Reference.remove', 0, 1, arguments.length);
|
||||
util.validateCallback('Reference.remove', 'onComplete', onComplete, true);
|
||||
var result = database.remove(this._delegate);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.transaction = function (transactionUpdate, onComplete, applyLocally) {
|
||||
var _this = this;
|
||||
util.validateArgCount('Reference.transaction', 1, 3, arguments.length);
|
||||
util.validateCallback('Reference.transaction', 'transactionUpdate', transactionUpdate, false);
|
||||
util.validateCallback('Reference.transaction', 'onComplete', onComplete, true);
|
||||
validateBoolean('Reference.transaction', 'applyLocally', applyLocally, true);
|
||||
var result = database.runTransaction(this._delegate, transactionUpdate, {
|
||||
applyLocally: applyLocally
|
||||
}).then(function (transactionResult) {
|
||||
return new TransactionResult(transactionResult.committed, new DataSnapshot(_this.database, transactionResult.snapshot));
|
||||
});
|
||||
if (onComplete) {
|
||||
result.then(function (transactionResult) {
|
||||
return onComplete(null, transactionResult.committed, transactionResult.snapshot);
|
||||
}, function (error) { return onComplete(error, false, null); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.setPriority = function (priority, onComplete) {
|
||||
util.validateArgCount('Reference.setPriority', 1, 2, arguments.length);
|
||||
util.validateCallback('Reference.setPriority', 'onComplete', onComplete, true);
|
||||
var result = database.setPriority(this._delegate, priority);
|
||||
if (onComplete) {
|
||||
result.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.push = function (value, onComplete) {
|
||||
var _this = this;
|
||||
util.validateArgCount('Reference.push', 0, 2, arguments.length);
|
||||
util.validateCallback('Reference.push', 'onComplete', onComplete, true);
|
||||
var expPromise = database.push(this._delegate, value);
|
||||
var promise = expPromise.then(function (expRef) { return new Reference(_this.database, expRef); });
|
||||
if (onComplete) {
|
||||
promise.then(function () { return onComplete(null); }, function (error) { return onComplete(error); });
|
||||
}
|
||||
var result = new Reference(this.database, expPromise);
|
||||
result.then = promise.then.bind(promise);
|
||||
result.catch = promise.catch.bind(promise, undefined);
|
||||
return result;
|
||||
};
|
||||
Reference.prototype.onDisconnect = function () {
|
||||
database._validateWritablePath('Reference.onDisconnect', this._delegate._path);
|
||||
return new OnDisconnect(new database.OnDisconnect(this._delegate._repo, this._delegate._path));
|
||||
};
|
||||
Object.defineProperty(Reference.prototype, "key", {
|
||||
get: function () {
|
||||
return this.getKey();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Reference.prototype, "parent", {
|
||||
get: function () {
|
||||
return this.getParent();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Reference.prototype, "root", {
|
||||
get: function () {
|
||||
return this.getRoot();
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return Reference;
|
||||
}(Query));
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Class representing a firebase database.
|
||||
*/
|
||||
var Database = /** @class */ (function () {
|
||||
/**
|
||||
* The constructor should not be called by users of our public API.
|
||||
*/
|
||||
function Database(_delegate, app) {
|
||||
var _this = this;
|
||||
this._delegate = _delegate;
|
||||
this.app = app;
|
||||
this.INTERNAL = {
|
||||
delete: function () { return _this._delegate._delete(); }
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Modify this instance to communicate with the Realtime Database emulator.
|
||||
*
|
||||
* <p>Note: This method must be called before performing any other operation.
|
||||
*
|
||||
* @param host - the emulator host (ex: localhost)
|
||||
* @param port - the emulator port (ex: 8080)
|
||||
* @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
|
||||
*/
|
||||
Database.prototype.useEmulator = function (host, port, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
database.connectDatabaseEmulator(this._delegate, host, port, options);
|
||||
};
|
||||
Database.prototype.ref = function (path) {
|
||||
util.validateArgCount('database.ref', 0, 1, arguments.length);
|
||||
if (path instanceof Reference) {
|
||||
var childRef = database.refFromURL(this._delegate, path.toString());
|
||||
return new Reference(this, childRef);
|
||||
}
|
||||
else {
|
||||
var childRef = database.ref(this._delegate, path);
|
||||
return new Reference(this, childRef);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns a reference to the root or the path specified in url.
|
||||
* We throw a exception if the url is not in the same domain as the
|
||||
* current repo.
|
||||
* @returns Firebase reference.
|
||||
*/
|
||||
Database.prototype.refFromURL = function (url) {
|
||||
var apiName = 'database.refFromURL';
|
||||
util.validateArgCount(apiName, 1, 1, arguments.length);
|
||||
var childRef = database.refFromURL(this._delegate, url);
|
||||
return new Reference(this, childRef);
|
||||
};
|
||||
// Make individual repo go offline.
|
||||
Database.prototype.goOffline = function () {
|
||||
util.validateArgCount('database.goOffline', 0, 0, arguments.length);
|
||||
return database.goOffline(this._delegate);
|
||||
};
|
||||
Database.prototype.goOnline = function () {
|
||||
util.validateArgCount('database.goOnline', 0, 0, arguments.length);
|
||||
return database.goOnline(this._delegate);
|
||||
};
|
||||
Database.ServerValue = {
|
||||
TIMESTAMP: database.serverTimestamp(),
|
||||
increment: function (delta) { return database.increment(delta); }
|
||||
};
|
||||
return Database;
|
||||
}());
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
/**
|
||||
* Used by console to create a database based on the app,
|
||||
* passed database URL and a custom auth implementation.
|
||||
*
|
||||
* @param app - A valid FirebaseApp-like object
|
||||
* @param url - A valid Firebase databaseURL
|
||||
* @param version - custom version e.g. firebase-admin version
|
||||
* @param customAuthImpl - custom auth implementation
|
||||
*/
|
||||
function initStandalone(_a) {
|
||||
var app = _a.app, url = _a.url, version = _a.version, customAuthImpl = _a.customAuthImpl, namespace = _a.namespace, _b = _a.nodeAdmin, nodeAdmin = _b === void 0 ? false : _b;
|
||||
database._setSDKVersion(version);
|
||||
/**
|
||||
* ComponentContainer('database-standalone') is just a placeholder that doesn't perform
|
||||
* any actual function.
|
||||
*/
|
||||
var authProvider = new component.Provider('auth-internal', new component.ComponentContainer('database-standalone'));
|
||||
authProvider.setComponent(new component.Component('auth-internal', function () { return customAuthImpl; }, "PRIVATE" /* PRIVATE */));
|
||||
return {
|
||||
instance: new Database(database._repoManagerDatabaseFromApp(app, authProvider,
|
||||
/* appCheckProvider= */ undefined, url, nodeAdmin), app),
|
||||
namespace: namespace
|
||||
};
|
||||
}
|
||||
|
||||
var INTERNAL = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
initStandalone: initStandalone
|
||||
});
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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 ServerValue = Database.ServerValue;
|
||||
function registerDatabase(instance) {
|
||||
// Register the Database Service with the 'firebase' namespace.
|
||||
instance.INTERNAL.registerComponent(new component.Component('database-compat', function (container, _a) {
|
||||
var url = _a.instanceIdentifier;
|
||||
/* Dependencies */
|
||||
// getImmediate for FirebaseApp will always succeed
|
||||
var app = container.getProvider('app-compat').getImmediate();
|
||||
var databaseExp = container
|
||||
.getProvider('database')
|
||||
.getImmediate({ identifier: url });
|
||||
return new Database(databaseExp, app);
|
||||
}, "PUBLIC" /* PUBLIC */)
|
||||
.setServiceProps(
|
||||
// firebase.database namespace properties
|
||||
{
|
||||
Reference: Reference,
|
||||
Query: Query,
|
||||
Database: Database,
|
||||
DataSnapshot: DataSnapshot,
|
||||
enableLogging: database.enableLogging,
|
||||
INTERNAL: INTERNAL,
|
||||
ServerValue: ServerValue
|
||||
})
|
||||
.setMultipleInstances(true));
|
||||
instance.registerVersion(name, version, 'node');
|
||||
}
|
||||
registerDatabase(firebase__default["default"]);
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+18735
File diff suppressed because it is too large
Load Diff
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { FirebaseService } from '@firebase/app-types/private';
|
||||
import { Database as ModularDatabase } from '@firebase/database';
|
||||
import { Compat, EmulatorMockTokenOptions } from '@firebase/util';
|
||||
import { Reference } from './Reference';
|
||||
/**
|
||||
* Class representing a firebase database.
|
||||
*/
|
||||
export declare class Database implements FirebaseService, Compat<ModularDatabase> {
|
||||
readonly _delegate: ModularDatabase;
|
||||
readonly app: FirebaseApp;
|
||||
static readonly ServerValue: {
|
||||
TIMESTAMP: object;
|
||||
increment: (delta: number) => object;
|
||||
};
|
||||
/**
|
||||
* The constructor should not be called by users of our public API.
|
||||
*/
|
||||
constructor(_delegate: ModularDatabase, app: FirebaseApp);
|
||||
INTERNAL: {
|
||||
delete: () => Promise<void>;
|
||||
};
|
||||
/**
|
||||
* Modify this instance to communicate with the Realtime Database emulator.
|
||||
*
|
||||
* <p>Note: This method must be called before performing any other operation.
|
||||
*
|
||||
* @param host - the emulator host (ex: localhost)
|
||||
* @param port - the emulator port (ex: 8080)
|
||||
* @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
|
||||
*/
|
||||
useEmulator(host: string, port: number, options?: {
|
||||
mockUserToken?: EmulatorMockTokenOptions;
|
||||
}): void;
|
||||
/**
|
||||
* Returns a reference to the root or to the path specified in the provided
|
||||
* argument.
|
||||
*
|
||||
* @param path - The relative string path or an existing Reference to a database
|
||||
* location.
|
||||
* @throws If a Reference is provided, throws if it does not belong to the
|
||||
* same project.
|
||||
* @returns Firebase reference.
|
||||
*/
|
||||
ref(path?: string): Reference;
|
||||
ref(path?: Reference): Reference;
|
||||
/**
|
||||
* Returns a reference to the root or the path specified in url.
|
||||
* We throw a exception if the url is not in the same domain as the
|
||||
* current repo.
|
||||
* @returns Firebase reference.
|
||||
*/
|
||||
refFromURL(url: string): Reference;
|
||||
goOffline(): void;
|
||||
goOnline(): void;
|
||||
}
|
||||
Generated
Vendored
+201
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { DataSnapshot as ModularDataSnapshot, Query as ExpQuery, DatabaseReference as ModularReference } from '@firebase/database';
|
||||
import { Compat } from '@firebase/util';
|
||||
import { Database } from './Database';
|
||||
import { OnDisconnect } from './onDisconnect';
|
||||
import { TransactionResult } from './TransactionResult';
|
||||
/**
|
||||
* Class representing a firebase data snapshot. It wraps a SnapshotNode and
|
||||
* surfaces the public methods (val, forEach, etc.) we want to expose.
|
||||
*/
|
||||
export declare class DataSnapshot implements Compat<ModularDataSnapshot> {
|
||||
readonly _database: Database;
|
||||
readonly _delegate: ModularDataSnapshot;
|
||||
constructor(_database: Database, _delegate: ModularDataSnapshot);
|
||||
/**
|
||||
* Retrieves the snapshot contents as JSON. Returns null if the snapshot is
|
||||
* empty.
|
||||
*
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
val(): unknown;
|
||||
/**
|
||||
* Returns the snapshot contents as JSON, including priorities of node. Suitable for exporting
|
||||
* the entire node contents.
|
||||
* @returns JSON representation of the DataSnapshot contents, or null if empty.
|
||||
*/
|
||||
exportVal(): unknown;
|
||||
toJSON(): unknown;
|
||||
/**
|
||||
* Returns whether the snapshot contains a non-null value.
|
||||
*
|
||||
* @returns Whether the snapshot contains a non-null value, or is empty.
|
||||
*/
|
||||
exists(): boolean;
|
||||
/**
|
||||
* Returns a DataSnapshot of the specified child node's contents.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns DataSnapshot for child node.
|
||||
*/
|
||||
child(path: string): DataSnapshot;
|
||||
/**
|
||||
* Returns whether the snapshot contains a child at the specified path.
|
||||
*
|
||||
* @param path - Path to a child.
|
||||
* @returns Whether the child exists.
|
||||
*/
|
||||
hasChild(path: string): boolean;
|
||||
/**
|
||||
* Returns the priority of the object, or null if no priority was set.
|
||||
*
|
||||
* @returns The priority.
|
||||
*/
|
||||
getPriority(): string | number | null;
|
||||
/**
|
||||
* Iterates through child nodes and calls the specified action for each one.
|
||||
*
|
||||
* @param action - Callback function to be called
|
||||
* for each child.
|
||||
* @returns True if forEach was canceled by action returning true for
|
||||
* one of the child nodes.
|
||||
*/
|
||||
forEach(action: (snapshot: DataSnapshot) => boolean | void): boolean;
|
||||
/**
|
||||
* Returns whether this DataSnapshot has children.
|
||||
* @returns True if the DataSnapshot contains 1 or more child nodes.
|
||||
*/
|
||||
hasChildren(): boolean;
|
||||
get key(): string;
|
||||
/**
|
||||
* Returns the number of children for this DataSnapshot.
|
||||
* @returns The number of children that this DataSnapshot contains.
|
||||
*/
|
||||
numChildren(): number;
|
||||
/**
|
||||
* @returns The Firebase reference for the location this snapshot's data came
|
||||
* from.
|
||||
*/
|
||||
getRef(): Reference;
|
||||
get ref(): Reference;
|
||||
}
|
||||
export interface SnapshotCallback {
|
||||
(dataSnapshot: DataSnapshot, previousChildName?: string | null): unknown;
|
||||
}
|
||||
/**
|
||||
* A Query represents a filter to be applied to a firebase location. This object purely represents the
|
||||
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
|
||||
*
|
||||
* Since every Firebase reference is a query, Firebase inherits from this object.
|
||||
*/
|
||||
export declare class Query implements Compat<ExpQuery> {
|
||||
readonly database: Database;
|
||||
readonly _delegate: ExpQuery;
|
||||
constructor(database: Database, _delegate: ExpQuery);
|
||||
on(eventType: string, callback: SnapshotCallback, cancelCallbackOrContext?: ((a: Error) => unknown) | object | null, context?: object | null): SnapshotCallback;
|
||||
off(eventType?: string, callback?: SnapshotCallback, context?: object | null): void;
|
||||
/**
|
||||
* Get the server-value for this query, or return a cached value if not connected.
|
||||
*/
|
||||
get(): Promise<DataSnapshot>;
|
||||
/**
|
||||
* Attaches a listener, waits for the first event, and then removes the listener
|
||||
*/
|
||||
once(eventType: string, callback?: SnapshotCallback, failureCallbackOrContext?: ((a: Error) => void) | object | null, context?: object | null): Promise<DataSnapshot>;
|
||||
/**
|
||||
* Set a limit and anchor it to the start of the window.
|
||||
*/
|
||||
limitToFirst(limit: number): Query;
|
||||
/**
|
||||
* Set a limit and anchor it to the end of the window.
|
||||
*/
|
||||
limitToLast(limit: number): Query;
|
||||
/**
|
||||
* Given a child path, return a new query ordered by the specified grandchild path.
|
||||
*/
|
||||
orderByChild(path: string): Query;
|
||||
/**
|
||||
* Return a new query ordered by the KeyIndex
|
||||
*/
|
||||
orderByKey(): Query;
|
||||
/**
|
||||
* Return a new query ordered by the PriorityIndex
|
||||
*/
|
||||
orderByPriority(): Query;
|
||||
/**
|
||||
* Return a new query ordered by the ValueIndex
|
||||
*/
|
||||
orderByValue(): Query;
|
||||
startAt(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
startAfter(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
endAt(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
endBefore(value?: number | string | boolean | null, name?: string | null): Query;
|
||||
/**
|
||||
* Load the selection of children with exactly the specified value, and, optionally,
|
||||
* the specified name.
|
||||
*/
|
||||
equalTo(value: number | string | boolean | null, name?: string): Query;
|
||||
/**
|
||||
* @returns URL for this location.
|
||||
*/
|
||||
toString(): string;
|
||||
toJSON(): string;
|
||||
/**
|
||||
* Return true if this query and the provided query are equivalent; otherwise, return false.
|
||||
*/
|
||||
isEqual(other: Query): boolean;
|
||||
/**
|
||||
* Helper used by .on and .once to extract the context and or cancel arguments.
|
||||
* @param fnName - The function name (on or once)
|
||||
*
|
||||
*/
|
||||
private static getCancelAndContextArgs_;
|
||||
get ref(): Reference;
|
||||
}
|
||||
export declare class Reference extends Query implements Compat<ModularReference> {
|
||||
readonly database: Database;
|
||||
readonly _delegate: ModularReference;
|
||||
then: Promise<Reference>['then'];
|
||||
catch: Promise<Reference>['catch'];
|
||||
/**
|
||||
* Call options:
|
||||
* new Reference(Repo, Path) or
|
||||
* new Reference(url: string, string|RepoManager)
|
||||
*
|
||||
* Externally - this is the firebase.database.Reference type.
|
||||
*/
|
||||
constructor(database: Database, _delegate: ModularReference);
|
||||
/** @returns {?string} */
|
||||
getKey(): string | null;
|
||||
child(pathString: string): Reference;
|
||||
/** @returns {?Reference} */
|
||||
getParent(): Reference | null;
|
||||
/** @returns {!Reference} */
|
||||
getRoot(): Reference;
|
||||
set(newVal: unknown, onComplete?: (error: Error | null) => void): Promise<unknown>;
|
||||
update(values: object, onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
setWithPriority(newVal: unknown, newPriority: string | number | null, onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
remove(onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
transaction(transactionUpdate: (currentData: unknown) => unknown, onComplete?: (error: Error | null, committed: boolean, dataSnapshot: DataSnapshot | null) => void, applyLocally?: boolean): Promise<TransactionResult>;
|
||||
setPriority(priority: string | number | null, onComplete?: (a: Error | null) => void): Promise<unknown>;
|
||||
push(value?: unknown, onComplete?: (a: Error | null) => void): Reference;
|
||||
onDisconnect(): OnDisconnect;
|
||||
get key(): string | null;
|
||||
get parent(): Reference | null;
|
||||
get root(): Reference;
|
||||
}
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { DataSnapshot } from './Reference';
|
||||
export declare class TransactionResult {
|
||||
committed: boolean;
|
||||
snapshot: DataSnapshot;
|
||||
/**
|
||||
* A type for the resolve value of Firebase.transaction.
|
||||
*/
|
||||
constructor(committed: boolean, snapshot: DataSnapshot);
|
||||
toJSON(): object;
|
||||
}
|
||||
Generated
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
|
||||
import * as types from '@firebase/database-types';
|
||||
/**
|
||||
* Used by console to create a database based on the app,
|
||||
* passed database URL and a custom auth implementation.
|
||||
*
|
||||
* @param app - A valid FirebaseApp-like object
|
||||
* @param url - A valid Firebase databaseURL
|
||||
* @param version - custom version e.g. firebase-admin version
|
||||
* @param customAuthImpl - custom auth implementation
|
||||
*/
|
||||
export declare function initStandalone<T>({ app, url, version, customAuthImpl, namespace, nodeAdmin }: {
|
||||
app: FirebaseApp;
|
||||
url: string;
|
||||
version: string;
|
||||
customAuthImpl: FirebaseAuthInternal;
|
||||
namespace: T;
|
||||
nodeAdmin?: boolean;
|
||||
}): {
|
||||
instance: types.Database;
|
||||
namespace: T;
|
||||
};
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
import { OnDisconnect as ModularOnDisconnect } from '@firebase/database';
|
||||
import { Compat } from '@firebase/util';
|
||||
export declare class OnDisconnect implements Compat<ModularOnDisconnect> {
|
||||
readonly _delegate: ModularOnDisconnect;
|
||||
constructor(_delegate: ModularOnDisconnect);
|
||||
cancel(onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
remove(onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
set(value: unknown, onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
setWithPriority(value: unknown, priority: number | string | null, onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
update(objectToMerge: Record<string, unknown>, onComplete?: (a: Error | null) => void): Promise<void>;
|
||||
}
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
import { FirebaseNamespace } from '@firebase/app-compat';
|
||||
import * as types from '@firebase/database-types';
|
||||
export declare function registerDatabase(instance: FirebaseNamespace): void;
|
||||
declare module '@firebase/app-compat' {
|
||||
interface FirebaseNamespace {
|
||||
database?: {
|
||||
(app?: FirebaseApp): types.FirebaseDatabase;
|
||||
enableLogging: typeof types.enableLogging;
|
||||
ServerValue: types.ServerValue;
|
||||
Database: typeof types.FirebaseDatabase;
|
||||
};
|
||||
}
|
||||
interface FirebaseApp {
|
||||
database?(databaseURL?: string): types.FirebaseDatabase;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import * as types from '@firebase/database-types';
|
||||
declare module '@firebase/app-compat' {
|
||||
interface FirebaseNamespace {
|
||||
database?: {
|
||||
(app?: FirebaseApp): types.FirebaseDatabase;
|
||||
enableLogging: typeof types.enableLogging;
|
||||
ServerValue: types.ServerValue;
|
||||
Database: typeof types.FirebaseDatabase;
|
||||
};
|
||||
}
|
||||
interface FirebaseApp {
|
||||
database?(): types.FirebaseDatabase;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user