Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rtdb): Changed admin.database to use database-compat package #1437

Merged
merged 7 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ var paths = {
// emitted.
var buildProject = ts.createProject('tsconfig.json', { rootDir: 'src', declarationMap: true });

var buildTest = ts.createProject('tsconfig.json');
// Include dom libraries during test compilation since we use some web SDK
// libraries in our tests.
var buildTest = ts.createProject('tsconfig.json', { lib: ['es2018', 'dom'] });

var banner = `/*! firebase-admin v${pkg.version} */\n`;

Expand Down
5,122 changes: 2,697 additions & 2,425 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
],
"types": "./lib/index.d.ts",
"dependencies": {
"@firebase/database": "^0.10.0",
"@firebase/database-compat": "^0.1.1-2021823172527",
"@firebase/database-types": "^0.7.2",
"@types/node": ">=12.12.47",
"dicer": "^0.3.0",
Expand All @@ -69,15 +69,15 @@
"@google-cloud/storage": "^5.3.0"
},
"devDependencies": {
"@firebase/app": "^0.6.21",
"@firebase/auth": "^0.16.5",
"@firebase/app-compat": "^0.1.2-2021823172527",
"@firebase/auth-compat": "^0.1.3-2021823172527",
"@firebase/auth-types": "^0.10.3",
"@microsoft/api-extractor": "^7.11.2",
"@types/bcrypt": "^5.0.0",
"@types/chai": "^4.0.0",
"@types/chai-as-promised": "^7.1.0",
"@types/firebase-token-generator": "^2.0.28",
"@types/jsonwebtoken": "^8.5.0",
"@types/jsonwebtoken": "8.5.1",
"@types/lodash": "^4.14.104",
"@types/minimist": "^1.2.0",
"@types/mocha": "^8.2.2",
Expand Down
4 changes: 2 additions & 2 deletions src/database/database-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as path from 'path';

import { FirebaseApp } from '../firebase-app';
import { FirebaseDatabaseError, AppErrorCodes, FirebaseAppError } from '../utils/error';
import { Database as DatabaseImpl } from '@firebase/database';
import { Database as DatabaseImpl } from '@firebase/database-compat';
import { database } from './index';

import * as validator from '../utils/validator';
Expand Down Expand Up @@ -89,7 +89,7 @@ export class DatabaseService {

let db: Database = this.databases[dbUrl];
if (typeof db === 'undefined') {
const rtdb = require('@firebase/database'); // eslint-disable-line @typescript-eslint/no-var-requires
const rtdb = require('@firebase/database-compat'); // eslint-disable-line @typescript-eslint/no-var-requires
db = rtdb.initStandalone(this.appInternal, dbUrl, getSdkVersion()).instance;

const rulesClient = new DatabaseRulesClient(this.app, dbUrl);
Expand Down
2 changes: 1 addition & 1 deletion src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { app } from '../firebase-namespace-api';
import { ServerValue as sv } from '@firebase/database';
import { ServerValue as sv } from '@firebase/database-compat';
import * as rtdb from '@firebase/database-types';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/firebase-namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class FirebaseNamespace {
};

// eslint-disable-next-line @typescript-eslint/no-var-requires
return Object.assign(fn, require('@firebase/database'));
return Object.assign(fn, require('@firebase/database-compat'));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/integration/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('admin', () => {
});

it('does not load RTDB by default', () => {
const firebaseRtdb = require.cache[require.resolve('@firebase/database')];
const firebaseRtdb = require.cache[require.resolve('@firebase/database-compat')];
expect(firebaseRtdb).to.be.undefined;
const rtdbInternal = require.cache[require.resolve('../../lib/database/database-internal')];
expect(rtdbInternal).to.be.undefined;
Expand All @@ -37,7 +37,7 @@ describe('admin', () => {
it('loads RTDB when calling admin.database', () => {
const rtdbNamespace = admin.database;
expect(rtdbNamespace).to.not.be.null;
const firebaseRtdb = require.cache[require.resolve('@firebase/database')];
const firebaseRtdb = require.cache[require.resolve('@firebase/database-compat')];
expect(firebaseRtdb).to.not.be.undefined;
});

Expand Down
6 changes: 3 additions & 3 deletions test/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as crypto from 'crypto';
import * as bcrypt from 'bcrypt';
import firebase from '@firebase/app';
import '@firebase/auth';
import firebase from '@firebase/app-compat';
import '@firebase/auth-compat';
import { clone } from 'lodash';
import {
generateRandomString, projectId, apiKey, noServiceAccountApp, cmdArgs,
Expand Down Expand Up @@ -2075,7 +2075,7 @@ describe('admin.auth', () => {
// Ensure disabled field has been updated.
expect(userRecord.uid).to.equal(uid);
expect(userRecord.disabled).to.equal(true);

try {
// If it is in emulator mode, a user-disabled error will be thrown.
decodedIdToken = await admin.auth().verifySessionCookie(sessionCookie, false);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/app-check/token-generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe('AppCheckTokenGenerator', () => {
expect(appCheckError).to.have.property('code', 'app-check/invalid-argument');
expect(appCheckError).to.have.property('message', 'test error.');
});

it('should convert CryptoSignerError HttpError to FirebaseAppCheckError', () => {
const cryptoError = new CryptoSignerError({
code: CryptoSignerErrorCode.SERVER_ERROR,
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('AppCheckTokenGenerator', () => {
'Error returned from server while signing a custom token: '+
'{"status":500,"headers":{},"data":{"error":{}},"text":"{\\"error\\":{}}"}');
});

it('should convert CryptoSignerError HttpError with no errorcode to FirebaseAppCheckError', () => {
const cryptoError = new CryptoSignerError({
code: CryptoSignerErrorCode.SERVER_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/firebase-namespace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
Query,
Reference,
ServerValue,
} from '@firebase/database';
} from '@firebase/database-compat';

import {
FieldPath,
Expand Down