Skip to content

Tree-Shake Repo #4489

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

Merged
merged 11 commits into from
Feb 23, 2021
8 changes: 4 additions & 4 deletions packages/database/src/api/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { fatal } from '../core/util/util';
import { parseRepoInfo } from '../core/util/libs/parser';
import { newEmptyPath } from '../core/util/Path';
import { Reference } from './Reference';
import { Repo } from '../core/Repo';
import { Repo, repoInterrupt, repoResume, repoStart } from '../core/Repo';
import { RepoManager } from '../core/RepoManager';
import { validateArgCount } from '@firebase/util';
import { validateUrl } from '../core/util/validation';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class Database implements FirebaseService {

private get repo_(): Repo {
if (!this.instanceStarted_) {
this.repoInternal_.start();
repoStart(this.repoInternal_);
this.instanceStarted_ = true;
}
return this.repoInternal_;
Expand Down Expand Up @@ -180,12 +180,12 @@ export class Database implements FirebaseService {
goOffline(): void {
validateArgCount('database.goOffline', 0, 0, arguments.length);
this.checkDeleted_('goOffline');
this.repo_.interrupt();
repoInterrupt(this.repo_);
}

goOnline(): void {
validateArgCount('database.goOnline', 0, 0, arguments.length);
this.checkDeleted_('goOnline');
this.repo_.resume();
repoResume(this.repo_);
}
}
25 changes: 15 additions & 10 deletions packages/database/src/api/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ import {
ValueEventRegistration
} from '../core/view/EventRegistration';

import { Repo } from '../core/Repo';
import {
Repo,
repoAddEventCallbackForQuery,
repoGetValue,
repoRemoveEventCallbackForQuery
} from '../core/Repo';
import {
QueryParams,
queryParamsLimitToFirst,
queryParamsLimitToLast,
queryParamsStartAfter,
queryParamsStartAt,
queryParamsEndAt,
queryParamsEndBefore,
queryParamsGetQueryObject,
queryParamsOrderBy
queryParamsLimitToFirst,
queryParamsLimitToLast,
queryParamsOrderBy,
queryParamsStartAfter,
queryParamsStartAt
} from '../core/view/QueryParams';
import { Reference } from './Reference';
import { DataSnapshot } from './DataSnapshot';
Expand Down Expand Up @@ -231,7 +236,7 @@ export class Query {
cancelCallback || null,
context || null
);
this.repo.addEventCallbackForQuery(this, container);
repoAddEventCallbackForQuery(this.repo, this, container);
}

onChildEvent(
Expand All @@ -244,7 +249,7 @@ export class Query {
cancelCallback,
context
);
this.repo.addEventCallbackForQuery(this, container);
repoAddEventCallbackForQuery(this.repo, this, container);
}

off(
Expand Down Expand Up @@ -273,14 +278,14 @@ export class Query {
}
container = new ChildEventRegistration(callbacks, null, context || null);
}
this.repo.removeEventCallbackForQuery(this, container);
repoRemoveEventCallbackForQuery(this.repo, this, container);
}

/**
* Get the server-value for this query, or return a cached value if not connected.
*/
get(): Promise<DataSnapshot> {
return this.repo.getValue(this);
return repoGetValue(this.repo, this);
}

/**
Expand Down
30 changes: 21 additions & 9 deletions packages/database/src/api/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ import { TransactionResult } from './TransactionResult';
import { warn } from '../core/util/util';
import { nextPushId } from '../core/util/NextPushId';
import { Query } from './Query';
import { Repo } from '../core/Repo';
import {
Repo,
repoGetDatabase,
repoServerTime,
repoSetWithPriority,
repoStartTransaction,
repoUpdate
} from '../core/Repo';
import {
Path,
pathChild,
Expand Down Expand Up @@ -118,7 +125,7 @@ export class Reference extends Query {

/** @return {!Database} */
databaseProp(): Database {
return this.repo.database;
return repoGetDatabase(this.repo);
}

set(
Expand All @@ -131,10 +138,11 @@ export class Reference extends Query {
validateCallback('Reference.set', 2, onComplete, true);

const deferred = new Deferred();
this.repo.setWithPriority(
repoSetWithPriority(
this.repo,
this.path,
newVal,
/*priority=*/ null,
null,
deferred.wrapCallback(onComplete)
);
return deferred.promise;
Expand Down Expand Up @@ -169,7 +177,8 @@ export class Reference extends Query {
);
validateCallback('Reference.update', 2, onComplete, true);
const deferred = new Deferred();
this.repo.update(
repoUpdate(
this.repo,
this.path,
objectToMerge as { [k: string]: unknown },
deferred.wrapCallback(onComplete)
Expand Down Expand Up @@ -203,7 +212,8 @@ export class Reference extends Query {
}

const deferred = new Deferred();
this.repo.setWithPriority(
repoSetWithPriority(
this.repo,
this.path,
newVal,
newPriority,
Expand Down Expand Up @@ -264,7 +274,8 @@ export class Reference extends Query {
onComplete(error, committed, snapshot);
}
};
this.repo.startTransaction(
repoStartTransaction(
this.repo,
this.path,
transactionUpdate,
promiseComplete,
Expand All @@ -284,7 +295,8 @@ export class Reference extends Query {
validateCallback('Reference.setPriority', 2, onComplete, true);

const deferred = new Deferred();
this.repo.setWithPriority(
repoSetWithPriority(
this.repo,
pathChild(this.path, '.priority'),
priority,
null,
Expand All @@ -299,7 +311,7 @@ export class Reference extends Query {
validateFirebaseDataArg('Reference.push', 1, value, this.path, true);
validateCallback('Reference.push', 2, onComplete, true);

const now = this.repo.serverTime();
const now = repoServerTime(this.repo);
const name = nextPushId(now);

// push() returns a ThennableReference whose promise is fulfilled with a regular Reference.
Expand Down
11 changes: 8 additions & 3 deletions packages/database/src/api/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import {
Component,
ComponentType
} from '@firebase/component';
import {
repoInterceptServerData,
repoStats,
repoStatsIncrementCounter
} from '../core/Repo';

/**
* INTERNAL methods for internal-use only (tests, etc.).
Expand Down Expand Up @@ -62,11 +67,11 @@ export const setSecurityDebugCallback = function (
};

export const stats = function (ref: Reference, showDelta?: boolean) {
ref.repo.stats(showDelta);
repoStats(ref.repo, showDelta);
};

export const statsIncrementCounter = function (ref: Reference, metric: string) {
ref.repo.statsIncrementCounter(metric);
repoStatsIncrementCounter(ref.repo, metric);
};

export const dataUpdateCount = function (ref: Reference): number {
Expand All @@ -77,7 +82,7 @@ export const interceptServerData = function (
ref: Reference,
callback: ((a: string, b: unknown) => void) | null
) {
return ref.repo.interceptServerData_(callback);
return repoInterceptServerData(ref.repo, callback);
};

/**
Expand Down
25 changes: 18 additions & 7 deletions packages/database/src/api/onDisconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { validateArgCount, validateCallback, Deferred } from '@firebase/util';
import { Deferred, validateArgCount, validateCallback } from '@firebase/util';
import {
validateWritablePath,
validateFirebaseDataArg,
Expand All @@ -24,7 +24,13 @@ import {
} from '../core/util/validation';
import { warn } from '../core/util/util';

import { Repo } from '../core/Repo';
import {
Repo,
repoOnDisconnectCancel,
repoOnDisconnectSet,
repoOnDisconnectSetWithPriority,
repoOnDisconnectUpdate
} from '../core/Repo';
import { Path } from '../core/util/Path';
import { Indexable } from '../core/util/misc';

Expand All @@ -35,7 +41,8 @@ export class OnDisconnect {
validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
validateCallback('OnDisconnect.cancel', 1, onComplete, true);
const deferred = new Deferred<void>();
this.repo_.onDisconnectCancel(
repoOnDisconnectCancel(
this.repo_,
this.path_,
deferred.wrapCallback(onComplete)
);
Expand All @@ -47,7 +54,8 @@ export class OnDisconnect {
validateWritablePath('OnDisconnect.remove', this.path_);
validateCallback('OnDisconnect.remove', 1, onComplete, true);
const deferred = new Deferred<void>();
this.repo_.onDisconnectSet(
repoOnDisconnectSet(
this.repo_,
this.path_,
null,
deferred.wrapCallback(onComplete)
Expand All @@ -61,7 +69,8 @@ export class OnDisconnect {
validateFirebaseDataArg('OnDisconnect.set', 1, value, this.path_, false);
validateCallback('OnDisconnect.set', 2, onComplete, true);
const deferred = new Deferred<void>();
this.repo_.onDisconnectSet(
repoOnDisconnectSet(
this.repo_,
this.path_,
value,
deferred.wrapCallback(onComplete)
Expand All @@ -87,7 +96,8 @@ export class OnDisconnect {
validateCallback('OnDisconnect.setWithPriority', 3, onComplete, true);

const deferred = new Deferred<void>();
this.repo_.onDisconnectSetWithPriority(
repoOnDisconnectSetWithPriority(
this.repo_,
this.path_,
value,
priority,
Expand Down Expand Up @@ -122,7 +132,8 @@ export class OnDisconnect {
);
validateCallback('OnDisconnect.update', 2, onComplete, true);
const deferred = new Deferred<void>();
this.repo_.onDisconnectUpdate(
repoOnDisconnectUpdate(
this.repo_,
this.path_,
objectToMerge,
deferred.wrapCallback(onComplete)
Expand Down
Loading