Skip to content

Field Value migration #2784

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 28 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
806f0a1
Use ByteString in model types (#2676)
schmidt-sebastian Feb 25, 2020
6dfb8b8
Merge branch 'master' into mrschmidt/rewritefieldvalue
schmidt-sebastian Feb 25, 2020
799bc96
Adding Proto-based equality and comparison (#2678)
schmidt-sebastian Feb 25, 2020
251a980
Adding test utilities to create Value types (#2680)
schmidt-sebastian Feb 26, 2020
c32a9a6
Protobuf-backed FieldValues (#2682)
schmidt-sebastian Mar 4, 2020
5a603db
Limit Timestamp normalization (#2684)
schmidt-sebastian Mar 4, 2020
d4602fd
Simplify Document (#2685)
schmidt-sebastian Mar 4, 2020
4083821
Canonical ID Schema Migration (#2686)
schmidt-sebastian Mar 4, 2020
346af4c
Add explicit FieldValue canonicalization (#2687)
schmidt-sebastian Mar 4, 2020
2eeb0eb
Explicit byte size accounting (#2689)
schmidt-sebastian Mar 4, 2020
1a0b08d
Introducing UserDataReader/UserDataWriter (#2713)
schmidt-sebastian Mar 6, 2020
3057e1b
Merge
schmidt-sebastian Mar 17, 2020
b54f28f
Add ServerTimestamp helpers (#2748)
schmidt-sebastian Mar 18, 2020
2d825a5
Merge branch 'master' into mrschmidt/rewritefieldvalue
schmidt-sebastian Mar 18, 2020
70be6ac
Add ProtoJS types to generated proto types (#2749)
schmidt-sebastian Mar 18, 2020
db12269
Merge
schmidt-sebastian Mar 18, 2020
80b2aa6
Rename proto_values->values, create values.test.ts (#2750)
schmidt-sebastian Mar 18, 2020
99618a1
Add small Proto helpers (#2753)
schmidt-sebastian Mar 19, 2020
512fc5f
Finish FieldValue migration (#2766)
schmidt-sebastian Mar 23, 2020
be10f14
Merge
schmidt-sebastian Mar 23, 2020
56199ad
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 23, 2020
60d982e
[AUTOMATED]: License Headers
schmidt-sebastian Mar 23, 2020
68062c1
Merge
schmidt-sebastian Mar 23, 2020
621cf8c
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 23, 2020
b6a3338
[AUTOMATED]: License Headers
schmidt-sebastian Mar 23, 2020
d9d527c
Update tests
schmidt-sebastian Mar 23, 2020
7fba9fe
Clean up merge
schmidt-sebastian Mar 23, 2020
97e87c0
FieldValue changelog (#2786)
schmidt-sebastian Mar 23, 2020
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
6 changes: 6 additions & 0 deletions packages/firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Unreleased
- [changed] Changed the in-memory representation of Firestore documents to
reduce memory allocations and improve performance. Calls to
`DocumentSnapshot.getData()` and `DocumentSnapshot.toObject()` will see
the biggest improvement.

# 1.10.1
- [fixed] Fixed an issue where the number value `-0.0` would lose its sign when
stored in Firestore.

Expand Down
46 changes: 12 additions & 34 deletions packages/firestore/src/api/blob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* 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.
Expand All @@ -23,11 +23,7 @@ import {
validateArgType,
validateExactNumberOfArgs
} from '../util/input_validation';
import { primitiveComparator } from '../util/misc';
import {
binaryStringFromUint8Array,
uint8ArrayFromBinaryString
} from '../util/byte_string';
import { ByteString } from '../util/byte_string';

/** Helper function to assert Uint8Array is available at runtime. */
function assertUint8ArrayAvailable(): void {
Expand Down Expand Up @@ -57,24 +53,21 @@ function assertBase64Available(): void {
* using the hack above to make sure no-one outside this module can call it.
*/
export class Blob {
// Prefix with underscore to signal this is a private variable in JS and
// prevent it showing up for autocompletion.
// A binary string is a string with each char as Unicode code point in the
// range of [0, 255], essentially simulating a byte array.
private _binaryString: string;
// Prefix with underscore to signal that we consider this not part of the
// public API and to prevent it from showing up for autocompletion.
_byteString: ByteString;

private constructor(binaryString: string) {
constructor(byteString: ByteString) {
assertBase64Available();
this._binaryString = binaryString;
this._byteString = byteString;
}

static fromBase64String(base64: string): Blob {
validateExactNumberOfArgs('Blob.fromBase64String', arguments, 1);
validateArgType('Blob.fromBase64String', 'string', 1, base64);
assertBase64Available();
try {
const binaryString = PlatformSupport.getPlatform().atob(base64);
return new Blob(binaryString);
return new Blob(ByteString.fromBase64String(base64));
} catch (e) {
throw new FirestoreError(
Code.INVALID_ARGUMENT,
Expand All @@ -89,42 +82,27 @@ export class Blob {
if (!(array instanceof Uint8Array)) {
throw invalidClassError('Blob.fromUint8Array', 'Uint8Array', 1, array);
}
const binaryString = binaryStringFromUint8Array(array);
return new Blob(binaryString);
return new Blob(ByteString.fromUint8Array(array));
}

toBase64(): string {
validateExactNumberOfArgs('Blob.toBase64', arguments, 0);
assertBase64Available();
return PlatformSupport.getPlatform().btoa(this._binaryString);
return this._byteString.toBase64();
}

toUint8Array(): Uint8Array {
validateExactNumberOfArgs('Blob.toUint8Array', arguments, 0);
assertUint8ArrayAvailable();
const buffer = uint8ArrayFromBinaryString(this._binaryString);
return buffer;
return this._byteString.toUint8Array();
}

toString(): string {
return 'Blob(base64: ' + this.toBase64() + ')';
}

isEqual(other: Blob): boolean {
return this._binaryString === other._binaryString;
}

_approximateByteSize(): number {
// Assume UTF-16 encoding in memory (see StringValue.approximateByteSize())
return this._binaryString.length * 2;
}

/**
* Actually private to JS consumers of our API, so this function is prefixed
* with an underscore.
*/
_compareTo(other: Blob): number {
return primitiveComparator(this._binaryString, other._binaryString);
return this._byteString.isEqual(other._byteString);
}
}

Expand Down
Loading