diff --git a/packages/database/src/core/SyncTree.ts b/packages/database/src/core/SyncTree.ts index f1c5c0f12d4..04ecb14e495 100644 --- a/packages/database/src/core/SyncTree.ts +++ b/packages/database/src/core/SyncTree.ts @@ -22,7 +22,12 @@ import { ChildrenNode } from './snap/ChildrenNode'; import { ImmutableTree } from './util/ImmutableTree'; import { ListenComplete } from './operation/ListenComplete'; import { Merge } from './operation/Merge'; -import { Operation, OperationSource } from './operation/Operation'; +import { + newOperationSourceServer, + newOperationSourceServerTaggedQuery, + newOperationSourceUser, + Operation +} from './operation/Operation'; import { Overwrite } from './operation/Overwrite'; import { Path } from './util/Path'; import { SyncPoint } from './SyncPoint'; @@ -118,7 +123,7 @@ export class SyncTree { return []; } else { return this.applyOperationToSyncPoints_( - new Overwrite(OperationSource.user(), path, newData) + new Overwrite(newOperationSourceUser(), path, newData) ); } } @@ -139,7 +144,7 @@ export class SyncTree { const changeTree = ImmutableTree.fromObject(changedChildren); return this.applyOperationToSyncPoints_( - new Merge(OperationSource.user(), path, changeTree) + new Merge(newOperationSourceUser(), path, changeTree) ); } @@ -177,7 +182,7 @@ export class SyncTree { */ applyServerOverwrite(path: Path, newData: Node): Event[] { return this.applyOperationToSyncPoints_( - new Overwrite(OperationSource.server(), path, newData) + new Overwrite(newOperationSourceServer(), path, newData) ); } @@ -193,7 +198,7 @@ export class SyncTree { const changeTree = ImmutableTree.fromObject(changedChildren); return this.applyOperationToSyncPoints_( - new Merge(OperationSource.server(), path, changeTree) + new Merge(newOperationSourceServer(), path, changeTree) ); } @@ -204,7 +209,7 @@ export class SyncTree { */ applyListenComplete(path: Path): Event[] { return this.applyOperationToSyncPoints_( - new ListenComplete(OperationSource.server(), path) + new ListenComplete(newOperationSourceServer(), path) ); } @@ -221,7 +226,7 @@ export class SyncTree { queryId = r.queryId; const relativePath = Path.relativePath(queryPath, path); const op = new Overwrite( - OperationSource.forServerTaggedQuery(queryId), + newOperationSourceServerTaggedQuery(queryId), relativePath, snap ); @@ -250,7 +255,7 @@ export class SyncTree { const relativePath = Path.relativePath(queryPath, path); const changeTree = ImmutableTree.fromObject(changedChildren); const op = new Merge( - OperationSource.forServerTaggedQuery(queryId), + newOperationSourceServerTaggedQuery(queryId), relativePath, changeTree ); @@ -274,7 +279,7 @@ export class SyncTree { queryId = r.queryId; const relativePath = Path.relativePath(queryPath, path); const op = new ListenComplete( - OperationSource.forServerTaggedQuery(queryId), + newOperationSourceServerTaggedQuery(queryId), relativePath ); return this.applyTaggedOperation_(queryPath, op); diff --git a/packages/database/src/core/operation/AckUserWrite.ts b/packages/database/src/core/operation/AckUserWrite.ts index c1f500fc9be..f60f4ff2c22 100644 --- a/packages/database/src/core/operation/AckUserWrite.ts +++ b/packages/database/src/core/operation/AckUserWrite.ts @@ -17,7 +17,7 @@ import { assert } from '@firebase/util'; import { Path } from '../util/Path'; -import { Operation, OperationSource, OperationType } from './Operation'; +import { newOperationSourceUser, Operation, OperationType } from './Operation'; import { ImmutableTree } from '../util/ImmutableTree'; export class AckUserWrite implements Operation { @@ -25,7 +25,7 @@ export class AckUserWrite implements Operation { type = OperationType.ACK_USER_WRITE; /** @inheritDoc */ - source = OperationSource.user(); + source = newOperationSourceUser(); /** * @param affectedTree A tree containing true for each affected path. Affected paths can't overlap. diff --git a/packages/database/src/core/operation/Operation.ts b/packages/database/src/core/operation/Operation.ts index e29d05865b0..0154803b25a 100644 --- a/packages/database/src/core/operation/Operation.ts +++ b/packages/database/src/core/operation/Operation.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { assert } from '@firebase/util'; import { Path } from '../util/Path'; /** @@ -42,40 +41,38 @@ export interface Operation { operationForChild(childName: string): Operation | null; } -export class OperationSource { - constructor( - public fromUser: boolean, - public fromServer: boolean, - public queryId: string | null, - public tagged: boolean - ) { - assert(!tagged || fromServer, 'Tagged queries must be from server.'); - } +export interface OperationSource { + fromUser: boolean; + fromServer: boolean; + queryId: string | null; + tagged: boolean; +} - static user() { - return new OperationSource( - /*fromUser=*/ true, - false, - null, - /*tagged=*/ false - ); - } +export function newOperationSourceUser(): OperationSource { + return { + fromUser: true, + fromServer: false, + queryId: null, + tagged: false + }; +} - static server() { - return new OperationSource( - false, - /*fromServer=*/ true, - null, - /*tagged=*/ false - ); - } +export function newOperationSourceServer(): OperationSource { + return { + fromUser: false, + fromServer: true, + queryId: null, + tagged: false + }; +} - static forServerTaggedQuery = function (queryId: string): OperationSource { - return new OperationSource( - false, - /*fromServer=*/ true, - queryId, - /*tagged=*/ true - ); +export function newOperationSourceServerTaggedQuery( + queryId: string +): OperationSource { + return { + fromUser: false, + fromServer: true, + queryId, + tagged: true }; }