Skip to content

Rename Bundle metadata type to BundleMetadata #4268

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 2 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/firestore/src/core/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class BundleLoadResult {
/**
* Represents a Firestore bundle saved by the SDK in its local storage.
*/
export interface Bundle {
export interface BundleMetadata {
/**
* Id of the bundle. It is used together with `createTime` to determine if a
* bundle has been loaded by the SDK.
Expand Down
8 changes: 4 additions & 4 deletions packages/firestore/src/local/bundle_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Bundle, NamedQuery } from '../core/bundle';
import { BundleMetadata, NamedQuery } from '../core/bundle';
import {
NamedQuery as ProtoNamedQuery,
BundleMetadata as ProtoBundleMetadata
Expand All @@ -29,13 +29,13 @@ import { PersistenceTransaction } from './persistence_transaction';
*/
export interface BundleCache {
/**
* Gets a saved `Bundle` for a given `bundleId`, returns undefined if
* no bundles are found under the given id.
* Gets the saved `BundleMetadata` for a given `bundleId`, returns undefined
* if no bundle metadata is found under the given id.
*/
getBundleMetadata(
transaction: PersistenceTransaction,
bundleId: string
): PersistencePromise<Bundle | undefined>;
): PersistencePromise<BundleMetadata | undefined>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Bundle/BundleMetadata in L32

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* Saves a `BundleMetadata` from a bundle into local storage, using its id as
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/local/indexeddb_bundle_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Bundle, NamedQuery } from '../core/bundle';
import { BundleMetadata, NamedQuery } from '../core/bundle';
import {
BundleMetadata as ProtoBundleMetadata,
NamedQuery as ProtoNamedQuery
Expand Down Expand Up @@ -43,7 +43,7 @@ export class IndexedDbBundleCache implements BundleCache {
getBundleMetadata(
transaction: PersistenceTransaction,
bundleId: string
): PersistencePromise<Bundle | undefined> {
): PersistencePromise<BundleMetadata | undefined> {
return bundlesStore(transaction)
.get(bundleId)
.next(bundle => {
Expand Down
12 changes: 7 additions & 5 deletions packages/firestore/src/local/local_serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Timestamp } from '../api/timestamp';
import { Bundle, NamedQuery } from '../core/bundle';
import { BundleMetadata, NamedQuery } from '../core/bundle';
import { LimitType, Query, queryWithLimit } from '../core/query';
import { SnapshotVersion } from '../core/snapshot_version';
import { canonifyTarget, isDocumentTarget, Target } from '../core/target';
Expand Down Expand Up @@ -306,8 +306,8 @@ function isDocumentQuery(dbQuery: DbQuery): dbQuery is PublicDocumentsTarget {
return (dbQuery as PublicDocumentsTarget).documents !== undefined;
}

/** Encodes a DbBundle to a Bundle. */
export function fromDbBundle(dbBundle: DbBundle): Bundle {
/** Encodes a DbBundle to a BundleMetadata object. */
export function fromDbBundle(dbBundle: DbBundle): BundleMetadata {
return {
id: dbBundle.bundleId,
createTime: fromDbTimestamp(dbBundle.createTime),
Expand Down Expand Up @@ -372,8 +372,10 @@ export function fromProtoNamedQuery(namedQuery: ProtoNamedQuery): NamedQuery {
};
}

/** Encodes a BundleMetadata proto object to a Bundle model object. */
export function fromBundleMetadata(metadata: ProtoBundleMetadata): Bundle {
/** Decodes a BundleMetadata proto into a BundleMetadata object. */
export function fromBundleMetadata(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional jsdoc rename here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

metadata: ProtoBundleMetadata
): BundleMetadata {
return {
id: metadata.id!,
version: metadata.version!,
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/local/memory_bundle_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Bundle, NamedQuery } from '../core/bundle';
import { BundleMetadata, NamedQuery } from '../core/bundle';
import {
NamedQuery as ProtoNamedQuery,
BundleMetadata as ProtoBundleMetadata
Expand All @@ -31,15 +31,15 @@ import { PersistencePromise } from './persistence_promise';
import { PersistenceTransaction } from './persistence_transaction';

export class MemoryBundleCache implements BundleCache {
private bundles = new Map<string, Bundle>();
private bundles = new Map<string, BundleMetadata>();
private namedQueries = new Map<string, NamedQuery>();

constructor(private serializer: LocalSerializer) {}

getBundleMetadata(
transaction: PersistenceTransaction,
bundleId: string
): PersistencePromise<Bundle | undefined> {
): PersistencePromise<BundleMetadata | undefined> {
return PersistencePromise.resolve(this.bundles.get(bundleId));
}

Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/test/unit/local/bundle_cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function genericBundleCacheTests(cacheFn: () => TestBundleCache): void {
}

it('returns undefined when bundle id is not found', async () => {
expect(await cache.getBundle('bundle-1')).to.be.undefined;
expect(await cache.getBundleMetadata('bundle-1')).to.be.undefined;
});

it('returns saved bundle', async () => {
Expand All @@ -111,7 +111,7 @@ function genericBundleCacheTests(cacheFn: () => TestBundleCache): void {
version: 1,
createTime: { seconds: 1, nanos: 9999 }
});
expect(await cache.getBundle('bundle-1')).to.deep.equal({
expect(await cache.getBundleMetadata('bundle-1')).to.deep.equal({
id: 'bundle-1',
version: 1,
createTime: SnapshotVersion.fromTimestamp(new Timestamp(1, 9999))
Expand All @@ -123,7 +123,7 @@ function genericBundleCacheTests(cacheFn: () => TestBundleCache): void {
version: 2,
createTime: { seconds: 2, nanos: 1111 }
});
expect(await cache.getBundle('bundle-1')).to.deep.equal({
expect(await cache.getBundleMetadata('bundle-1')).to.deep.equal({
id: 'bundle-1',
version: 2,
createTime: SnapshotVersion.fromTimestamp(new Timestamp(2, 1111))
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/test/unit/local/test_bundle_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Bundle, NamedQuery } from '../../../src/core/bundle';
import { BundleMetadata, NamedQuery } from '../../../src/core/bundle';
import { BundleCache } from '../../../src/local/bundle_cache';
import { Persistence } from '../../../src/local/persistence';
import {
Expand All @@ -34,9 +34,9 @@ export class TestBundleCache {
this.cache = persistence.getBundleCache();
}

getBundle(bundleId: string): Promise<Bundle | undefined> {
getBundleMetadata(bundleId: string): Promise<BundleMetadata | undefined> {
return this.persistence.runTransaction(
'getBundle',
'getBundleMetadata',
'readonly',
transaction => {
return this.cache.getBundleMetadata(transaction, bundleId);
Expand Down