Skip to content

Commit ac59a1c

Browse files
authored
Remove FieldValue factory methods (#342)
1 parent fbf7222 commit ac59a1c

20 files changed

+751
-763
lines changed

common/api-review/firestore-lite.api.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ export function average(field: string | FieldPath): AggregateField<number | null
6868
// @public
6969
export class BsonBinaryData {
7070
constructor(subtype: number, data: Uint8Array);
71+
// (undocumented)
7172
readonly data: Uint8Array;
7273
isEqual(other: BsonBinaryData): boolean;
74+
// (undocumented)
7375
readonly subtype: number;
7476
}
7577

76-
// @public
77-
export function bsonBinaryData(subtype: number, data: Uint8Array): BsonBinaryData;
78-
7978
// @public
8079
export class BsonObjectId {
8180
constructor(value: string);
@@ -84,9 +83,6 @@ export class BsonObjectId {
8483
readonly value: string;
8584
}
8685

87-
// @public
88-
export function bsonObjectId(value: string): BsonObjectId;
89-
9086
// @public
9187
export class BsonTimestamp {
9288
constructor(seconds: number, increment: number);
@@ -97,9 +93,6 @@ export class BsonTimestamp {
9793
readonly seconds: number;
9894
}
9995

100-
// @public
101-
export function bsonTimestamp(seconds: number, increment: number): BsonTimestamp;
102-
10396
// @public
10497
export class Bytes {
10598
static fromBase64String(base64: string): Bytes;
@@ -284,9 +277,6 @@ export function initializeFirestore(app: FirebaseApp, settings: Settings): Fires
284277
// @beta
285278
export function initializeFirestore(app: FirebaseApp, settings: Settings, databaseId?: string): Firestore;
286279

287-
// @public
288-
export function int32(value: number): Int32Value;
289-
290280
// @public
291281
export class Int32Value {
292282
constructor(value: number);
@@ -310,19 +300,13 @@ export class MaxKey {
310300
readonly type = "MaxKey";
311301
}
312302

313-
// @public
314-
export function maxKey(): MaxKey;
315-
316303
// @public
317304
export class MinKey {
318305
// (undocumented)
319306
static instance(): MinKey;
320307
readonly type = "MinKey";
321308
}
322309

323-
// @public
324-
export function minKey(): MinKey;
325-
326310
// @public
327311
export type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
328312
[K in keyof T & string]: ChildUpdateFields<K, T[K]>;
@@ -426,9 +410,6 @@ export class QueryStartAtConstraint extends QueryConstraint {
426410
// @public
427411
export function refEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>, right: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>): boolean;
428412

429-
// @public
430-
export function regex(pattern: string, options: string): RegexValue;
431-
432413
// @public
433414
export class RegexValue {
434415
constructor(pattern: string, options: string);

common/api-review/firestore.api.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ export function average(field: string | FieldPath): AggregateField<number | null
6868
// @public
6969
export class BsonBinaryData {
7070
constructor(subtype: number, data: Uint8Array);
71+
// (undocumented)
7172
readonly data: Uint8Array;
7273
isEqual(other: BsonBinaryData): boolean;
74+
// (undocumented)
7375
readonly subtype: number;
7476
}
7577

76-
// @public
77-
export function bsonBinaryData(subtype: number, data: Uint8Array): BsonBinaryData;
78-
7978
// @public
8079
export class BsonObjectId {
8180
constructor(value: string);
@@ -84,9 +83,6 @@ export class BsonObjectId {
8483
readonly value: string;
8584
}
8685

87-
// @public
88-
export function bsonObjectId(value: string): BsonObjectId;
89-
9086
// @public
9187
export class BsonTimestamp {
9288
constructor(seconds: number, increment: number);
@@ -97,9 +93,6 @@ export class BsonTimestamp {
9793
readonly seconds: number;
9894
}
9995

100-
// @public
101-
export function bsonTimestamp(seconds: number, increment: number): BsonTimestamp;
102-
10396
// @public
10497
export class Bytes {
10598
static fromBase64String(base64: string): Bytes;
@@ -379,9 +372,6 @@ export interface IndexField {
379372
// @public
380373
export function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings, databaseId?: string): Firestore;
381374

382-
// @public
383-
export function int32(value: number): Int32Value;
384-
385375
// @public
386376
export class Int32Value {
387377
constructor(value: number);
@@ -427,9 +417,6 @@ export class MaxKey {
427417
readonly type = "MaxKey";
428418
}
429419

430-
// @public
431-
export function maxKey(): MaxKey;
432-
433420
// @public
434421
export interface MemoryCacheSettings {
435422
garbageCollector?: MemoryGarbageCollector;
@@ -474,9 +461,6 @@ export class MinKey {
474461
readonly type = "MinKey";
475462
}
476463

477-
// @public
478-
export function minKey(): MinKey;
479-
480464
// @public
481465
export function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;
482466

@@ -686,9 +670,6 @@ export class QueryStartAtConstraint extends QueryConstraint {
686670
// @public
687671
export function refEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>, right: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>): boolean;
688672

689-
// @public
690-
export function regex(pattern: string, options: string): RegexValue;
691-
692673
// @public
693674
export class RegexValue {
694675
constructor(pattern: string, options: string);

packages/firestore/lite/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ export {
128128
arrayUnion,
129129
serverTimestamp,
130130
deleteField,
131-
vector,
132-
int32,
133-
regex,
134-
bsonBinaryData,
135-
bsonObjectId,
136-
bsonTimestamp,
137-
minKey,
138-
maxKey
131+
vector
139132
} from '../src/lite-api/field_value_impl';
140133

141134
export {
@@ -156,7 +149,7 @@ export { BsonBinaryData } from '../src/lite-api/bson_binary_data';
156149

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

159-
export { BsonTimestamp } from '../src/lite-api/bson_timestamp_value';
152+
export { BsonTimestamp } from '../src/lite-api/bson_timestamp';
160153

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

packages/firestore/src/api.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,7 @@ export {
173173
deleteField,
174174
increment,
175175
serverTimestamp,
176-
vector,
177-
int32,
178-
regex,
179-
bsonBinaryData,
180-
bsonObjectId,
181-
bsonTimestamp,
182-
minKey,
183-
maxKey
176+
vector
184177
} from './api/field_value_impl';
185178

186179
export { VectorValue } from './lite-api/vector_value';
@@ -193,7 +186,7 @@ export { BsonBinaryData } from './lite-api/bson_binary_data';
193186

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

196-
export { BsonTimestamp } from './lite-api/bson_timestamp_value';
189+
export { BsonTimestamp } from './lite-api/bson_timestamp';
197190

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

packages/firestore/src/api/field_value_impl.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,5 @@ export {
2121
arrayUnion,
2222
serverTimestamp,
2323
deleteField,
24-
vector,
25-
int32,
26-
regex,
27-
bsonBinaryData,
28-
bsonObjectId,
29-
bsonTimestamp,
30-
minKey,
31-
maxKey
24+
vector
3225
} from '../lite-api/field_value_impl';

packages/firestore/src/lite-api/bson_binary_data.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ import { Code, FirestoreError } from '../util/error';
2424
* @class BsonBinaryData
2525
*/
2626
export class BsonBinaryData {
27-
/** The subtype for the data */
28-
readonly subtype: number;
29-
30-
/** The binary data as a byte array */
3127
readonly data: Uint8Array;
3228

33-
constructor(subtype: number, data: Uint8Array) {
29+
constructor(readonly subtype: number, data: Uint8Array) {
3430
if (subtype < 0 || subtype > 255) {
3531
throw new FirestoreError(
3632
Code.INVALID_ARGUMENT,

packages/firestore/src/lite-api/bson_timestamp_value.ts renamed to packages/firestore/src/lite-api/bson_timestamp.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@
2121
* @class BsonTimestamp
2222
*/
2323
export class BsonTimestamp {
24-
constructor(readonly seconds: number, readonly increment: number) {}
24+
constructor(readonly seconds: number, readonly increment: number) {
25+
// Make sure 'seconds' and 'increment' are in the range of a 32-bit unsigned integer.
26+
if (seconds < 0 || seconds > 4294967295) {
27+
throw new Error(
28+
"BsonTimestamp 'seconds' must be in the range of a 32-bit unsigned integer."
29+
);
30+
}
31+
if (increment < 0 || increment > 4294967295) {
32+
throw new Error(
33+
"BsonTimestamp 'increment' must be in the range of a 32-bit unsigned integer."
34+
);
35+
}
36+
}
2537

2638
/**
2739
* Returns true if this `BsonTimestamp` is equal to the provided one.

packages/firestore/src/lite-api/field_value_impl.ts

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
18-
import { BsonBinaryData } from './bson_binary_data';
19-
import { BsonObjectId } from './bson_object_Id';
20-
import { BsonTimestamp } from './bson_timestamp_value';
2117
import { FieldValue } from './field_value';
22-
import { Int32Value } from './int32_value';
23-
import { MaxKey } from './max_key';
24-
import { MinKey } from './min_key';
25-
import { RegexValue } from './regex_value';
2618
import {
2719
ArrayRemoveFieldValueImpl,
2820
ArrayUnionFieldValueImpl,
@@ -116,85 +108,3 @@ export function increment(n: number): FieldValue {
116108
export function vector(values?: number[]): VectorValue {
117109
return new VectorValue(values);
118110
}
119-
120-
/**
121-
* Creates a new `Int32Value` constructed with the given number.
122-
*
123-
* @param value - The 32-bit number to be used for constructing the Int32Value
124-
*
125-
* @returns A new `Int32Value` constructed with the given number.
126-
*/
127-
export function int32(value: number): Int32Value {
128-
return new Int32Value(value);
129-
}
130-
131-
/**
132-
* Creates a new `RegexValue` constructed with the given pattern and options.
133-
*
134-
* @param subtype - The subtype of the BSON binary data.
135-
* @param data - The data to use for the BSON binary data.
136-
*
137-
* @returns A new `RegexValue` constructed with the given pattern and options.
138-
*/
139-
export function regex(pattern: string, options: string): RegexValue {
140-
return new RegexValue(pattern, options);
141-
}
142-
143-
/**
144-
* Creates a new `BsonBinaryData` constructed with the given subtype and data.
145-
*
146-
* @param subtype - Create a `BsonBinaryData` instance with the given subtype.
147-
* @param data - Create a `BsonBinaryData` instance with a copy of this array of numbers.
148-
*
149-
* @returns A new `BsonBinaryData` constructed with the given subtype and data.
150-
*/
151-
export function bsonBinaryData(
152-
subtype: number,
153-
data: Uint8Array
154-
): BsonBinaryData {
155-
return new BsonBinaryData(subtype, data);
156-
}
157-
158-
/**
159-
* Creates a new `BsonObjectId` constructed with the given string.
160-
*
161-
* @param value - The 24-character hex string representing the ObjectId.
162-
*
163-
* @returns A new `BsonObjectId` constructed with the given string.
164-
*/
165-
export function bsonObjectId(value: string): BsonObjectId {
166-
return new BsonObjectId(value);
167-
}
168-
169-
/**
170-
* Creates a new `BsonTimestamp` constructed with the given seconds and increment.
171-
*
172-
* @param seconds - The underlying unsigned 32-bit integer for seconds.
173-
* @param seconds - The underlying unsigned 32-bit integer for increment.
174-
*
175-
* @returns A new `BsonTimestamp` constructed with the given seconds and increment.
176-
*/
177-
export function bsonTimestamp(
178-
seconds: number,
179-
increment: number
180-
): BsonTimestamp {
181-
return new BsonTimestamp(seconds, increment);
182-
}
183-
184-
/**
185-
* Creates or returns a `MinKey` instance.
186-
*
187-
* @returns A `MinKey` instance.
188-
*/
189-
export function minKey(): MinKey {
190-
return MinKey.instance();
191-
}
192-
193-
/**
194-
* Creates or returns a `MaxKey` instance.
195-
*
196-
* @returns A `MaxKey` instance.
197-
*/
198-
export function maxKey(): MaxKey {
199-
return MaxKey.instance();
200-
}

packages/firestore/src/lite-api/user_data_reader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import { Dict, forEach, isEmpty } from '../util/obj';
7777

7878
import { BsonBinaryData } from './bson_binary_data';
7979
import { BsonObjectId } from './bson_object_Id';
80-
import { BsonTimestamp } from './bson_timestamp_value';
80+
import { BsonTimestamp } from './bson_timestamp';
8181
import { Bytes } from './bytes';
8282
import { Firestore } from './database';
8383
import { FieldPath } from './field_path';

packages/firestore/src/lite-api/user_data_writer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ import { forEach } from '../util/obj';
6060

6161
import { BsonBinaryData } from './bson_binary_data';
6262
import { BsonObjectId } from './bson_object_Id';
63-
import { BsonTimestamp } from './bson_timestamp_value';
64-
import { maxKey, minKey } from './field_value_impl';
63+
import { BsonTimestamp } from './bson_timestamp';
6564
import { GeoPoint } from './geo_point';
6665
import { Int32Value } from './int32_value';
66+
import { MaxKey } from './max_key';
67+
import { MinKey } from './min_key';
6768
import { RegexValue } from './regex_value';
6869
import { Timestamp } from './timestamp';
6970
import { VectorValue } from './vector_value';
@@ -118,9 +119,9 @@ export abstract class AbstractUserDataWriter {
118119
case TypeOrder.BsonTimestampValue:
119120
return this.convertToBsonTimestamp(value.mapValue!);
120121
case TypeOrder.MaxKeyValue:
121-
return maxKey();
122+
return MaxKey.instance();
122123
case TypeOrder.MinKeyValue:
123-
return minKey();
124+
return MinKey.instance();
124125
default:
125126
throw fail('Invalid value type: ' + JSON.stringify(value));
126127
}

0 commit comments

Comments
 (0)