Skip to content

feat: Add support for new Firestore types #8994

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
rename BsonTimestampValue class to BsonTimestamp (#333)
  • Loading branch information
milaGGL authored Mar 14, 2025
commit 82f32ca7de9508352e26be16ad7b1ab2f0eb0d46
2 changes: 1 addition & 1 deletion packages/firestore/lite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export { BsonBinaryData } from '../src/lite-api/bson_binary_data';

export { BsonObjectId } from '../src/lite-api/bson_object_Id';

export { BsonTimestampValue } from '../src/lite-api/bson_timestamp_value';
export { BsonTimestamp } from '../src/lite-api/bson_timestamp_value';

export { MinKey } from '../src/lite-api/min_key';

Expand Down
12 changes: 6 additions & 6 deletions packages/firestore/src/lite-api/bson_timestamp_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
/**
* Represents a BSON Timestamp type in Firestore documents.
*
* @class BsonTimestampValue
* @class BsonTimestamp
*/
export class BsonTimestampValue {
export class BsonTimestamp {
constructor(readonly seconds: number, readonly increment: number) {}

/**
* Returns true if this `BsonTimestampValue` is equal to the provided one.
* Returns true if this `BsonTimestamp` is equal to the provided one.
*
* @param other - The `BsonTimestampValue` to compare against.
* @return 'true' if this `BsonTimestampValue` is equal to the provided one.
* @param other - The `BsonTimestamp` to compare against.
* @return 'true' if this `BsonTimestamp` is equal to the provided one.
*/
isEqual(other: BsonTimestampValue): boolean {
isEqual(other: BsonTimestamp): boolean {
return this.seconds === other.seconds && this.increment === other.increment;
}
}
10 changes: 5 additions & 5 deletions packages/firestore/src/lite-api/field_value_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { BsonBinaryData } from './bson_binary_data';
import { BsonObjectId } from './bson_object_Id';
import { BsonTimestampValue } from './bson_timestamp_value';
import { BsonTimestamp } from './bson_timestamp_value';
import { FieldValue } from './field_value';
import { Int32Value } from './int32_value';
import { MaxKey } from './max_key';
Expand Down Expand Up @@ -167,18 +167,18 @@ export function bsonObjectId(value: string): BsonObjectId {
}

/**
* Creates a new `BsonTimestampValue` constructed with the given seconds and increment.
* Creates a new `BsonTimestamp` constructed with the given seconds and increment.
*
* @param seconds - The underlying unsigned 32-bit integer for seconds.
* @param seconds - The underlying unsigned 32-bit integer for increment.
*
* @returns A new `BsonTimestampValue` constructed with the given seconds and increment.
* @returns A new `BsonTimestamp` constructed with the given seconds and increment.
*/
export function bsonTimestamp(
seconds: number,
increment: number
): BsonTimestampValue {
return new BsonTimestampValue(seconds, increment);
): BsonTimestamp {
return new BsonTimestamp(seconds, increment);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/firestore/src/lite-api/user_data_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import { Dict, forEach, isEmpty } from '../util/obj';

import { BsonBinaryData } from './bson_binary_data';
import { BsonObjectId } from './bson_object_Id';
import { BsonTimestampValue } from './bson_timestamp_value';
import { BsonTimestamp } from './bson_timestamp_value';
import { Bytes } from './bytes';
import { Firestore } from './database';
import { FieldPath } from './field_path';
Expand Down Expand Up @@ -934,7 +934,7 @@ function parseScalarValue(
return parseBsonObjectId(value);
} else if (value instanceof Int32Value) {
return parseInt32Value(value);
} else if (value instanceof BsonTimestampValue) {
} else if (value instanceof BsonTimestamp) {
return parseBsonTimestamp(value);
} else if (value instanceof BsonBinaryData) {
return parseBsonBinaryData(context.serializer, value);
Expand Down Expand Up @@ -1043,7 +1043,7 @@ export function parseInt32Value(value: Int32Value): ProtoValue {
return { mapValue };
}

export function parseBsonTimestamp(value: BsonTimestampValue): ProtoValue {
export function parseBsonTimestamp(value: BsonTimestamp): ProtoValue {
const mapValue: ProtoMapValue = {
fields: {
[RESERVED_BSON_TIMESTAMP_KEY]: {
Expand Down Expand Up @@ -1105,7 +1105,7 @@ function looksLikeJsonObject(input: unknown): boolean {
!(input instanceof Int32Value) &&
!(input instanceof RegexValue) &&
!(input instanceof BsonObjectId) &&
!(input instanceof BsonTimestampValue) &&
!(input instanceof BsonTimestamp) &&
!(input instanceof BsonBinaryData)
);
}
Expand Down
18 changes: 8 additions & 10 deletions packages/firestore/src/lite-api/user_data_writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { forEach } from '../util/obj';

import { BsonBinaryData } from './bson_binary_data';
import { BsonObjectId } from './bson_object_Id';
import { BsonTimestampValue } from './bson_timestamp_value';
import { BsonTimestamp } from './bson_timestamp_value';
import { maxKey, minKey } from './field_value_impl';
import { GeoPoint } from './geo_point';
import { Int32Value } from './int32_value';
Expand Down Expand Up @@ -112,11 +112,11 @@ export abstract class AbstractUserDataWriter {
case TypeOrder.RegexValue:
return this.convertToRegexValue(value.mapValue!);
case TypeOrder.BsonObjectIdValue:
return this.convertToBsonObjectIdValue(value.mapValue!);
return this.convertToBsonObjectId(value.mapValue!);
case TypeOrder.BsonBinaryValue:
return this.convertToBsonBinaryValue(value.mapValue!);
return this.convertToBsonBinaryData(value.mapValue!);
case TypeOrder.BsonTimestampValue:
return this.convertToBsonTimestampValue(value.mapValue!);
return this.convertToBsonTimestamp(value.mapValue!);
case TypeOrder.MaxKeyValue:
return maxKey();
case TypeOrder.MinKeyValue:
Expand Down Expand Up @@ -160,13 +160,13 @@ export abstract class AbstractUserDataWriter {
return new VectorValue(values);
}

private convertToBsonObjectIdValue(mapValue: ProtoMapValue): BsonObjectId {
private convertToBsonObjectId(mapValue: ProtoMapValue): BsonObjectId {
const oid =
mapValue!.fields?.[RESERVED_BSON_OBJECT_ID_KEY]?.stringValue ?? '';
return new BsonObjectId(oid);
}

private convertToBsonBinaryValue(mapValue: ProtoMapValue): BsonBinaryData {
private convertToBsonBinaryData(mapValue: ProtoMapValue): BsonBinaryData {
const fields = mapValue!.fields?.[RESERVED_BSON_BINARY_KEY];
const subtypeAndData = fields?.bytesValue;
if (!subtypeAndData) {
Expand All @@ -182,9 +182,7 @@ export abstract class AbstractUserDataWriter {
return new BsonBinaryData(Number(subtype), data);
}

private convertToBsonTimestampValue(
mapValue: ProtoMapValue
): BsonTimestampValue {
private convertToBsonTimestamp(mapValue: ProtoMapValue): BsonTimestamp {
const fields = mapValue!.fields?.[RESERVED_BSON_TIMESTAMP_KEY];
const seconds = Number(
fields?.mapValue?.fields?.[RESERVED_BSON_TIMESTAMP_SECONDS_KEY]
Expand All @@ -194,7 +192,7 @@ export abstract class AbstractUserDataWriter {
fields?.mapValue?.fields?.[RESERVED_BSON_TIMESTAMP_INCREMENT_KEY]
?.integerValue
);
return new BsonTimestampValue(seconds, increment);
return new BsonTimestamp(seconds, increment);
}

private convertToRegexValue(mapValue: ProtoMapValue): RegexValue {
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/test/unit/model/values.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { GeoPoint, Timestamp } from '../../../src';
import { DatabaseId } from '../../../src/core/database_info';
import { BsonBinaryData } from '../../../src/lite-api/bson_binary_data';
import { BsonObjectId } from '../../../src/lite-api/bson_object_Id';
import { BsonTimestampValue } from '../../../src/lite-api/bson_timestamp_value';
import { BsonTimestamp } from '../../../src/lite-api/bson_timestamp_value';
import {
vector,
regex,
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('Values', () => {
[wrap(vector([]))],
[wrap(vector([1, 2.3, -4.0]))],
[wrap(regex('^foo', 'i')), wrap(new RegexValue('^foo', 'i'))],
[wrap(bsonTimestamp(57, 4)), wrap(new BsonTimestampValue(57, 4))],
[wrap(bsonTimestamp(57, 4)), wrap(new BsonTimestamp(57, 4))],
[
wrap(bsonBinaryData(128, Uint8Array.from([7, 8, 9]))),
wrap(new BsonBinaryData(128, Uint8Array.from([7, 8, 9]))),
Expand Down