Skip to content

Commit 0716bd7

Browse files
authored
Add new BSON types to public API (#330)
1 parent 51465ce commit 0716bd7

28 files changed

+2386
-116
lines changed

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,41 @@ export function arrayUnion(...elements: unknown[]): FieldValue;
6565
// @public
6666
export function average(field: string | FieldPath): AggregateField<number | null>;
6767

68+
// @public
69+
export class BsonBinaryData {
70+
constructor(subtype: number, data: Uint8Array);
71+
readonly data: Uint8Array;
72+
isEqual(other: BsonBinaryData): boolean;
73+
readonly subtype: number;
74+
}
75+
76+
// @public
77+
export function bsonBinaryData(subtype: number, data: Uint8Array): BsonBinaryData;
78+
79+
// @public
80+
export class BsonObjectId {
81+
constructor(value: string);
82+
isEqual(other: BsonObjectId): boolean;
83+
// (undocumented)
84+
readonly value: string;
85+
}
86+
87+
// @public
88+
export function bsonObjectId(value: string): BsonObjectId;
89+
90+
// @public
91+
export function bsonTimestamp(seconds: number, increment: number): BsonTimestampValue;
92+
93+
// @public
94+
export class BsonTimestampValue {
95+
constructor(seconds: number, increment: number);
96+
// (undocumented)
97+
readonly increment: number;
98+
isEqual(other: BsonTimestampValue): boolean;
99+
// (undocumented)
100+
readonly seconds: number;
101+
}
102+
68103
// @public
69104
export class Bytes {
70105
static fromBase64String(base64: string): Bytes;
@@ -249,6 +284,17 @@ export function initializeFirestore(app: FirebaseApp, settings: Settings): Fires
249284
// @beta
250285
export function initializeFirestore(app: FirebaseApp, settings: Settings, databaseId?: string): Firestore;
251286

287+
// @public
288+
export function int32(value: number): Int32Value;
289+
290+
// @public
291+
export class Int32Value {
292+
constructor(value: number);
293+
isEqual(other: Int32Value): boolean;
294+
// (undocumented)
295+
readonly value: number;
296+
}
297+
252298
// @public
253299
export function limit(limit: number): QueryLimitConstraint;
254300

@@ -257,6 +303,26 @@ export function limitToLast(limit: number): QueryLimitConstraint;
257303

258304
export { LogLevel }
259305

306+
// @public
307+
export class MaxKey {
308+
// (undocumented)
309+
static instance(): MaxKey;
310+
readonly type = "MaxKey";
311+
}
312+
313+
// @public
314+
export function maxKey(): MaxKey;
315+
316+
// @public
317+
export class MinKey {
318+
// (undocumented)
319+
static instance(): MinKey;
320+
readonly type = "MinKey";
321+
}
322+
323+
// @public
324+
export function minKey(): MinKey;
325+
260326
// @public
261327
export type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
262328
[K in keyof T & string]: ChildUpdateFields<K, T[K]>;
@@ -360,6 +426,19 @@ export class QueryStartAtConstraint extends QueryConstraint {
360426
// @public
361427
export function refEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>, right: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>): boolean;
362428

429+
// @public
430+
export function regex(pattern: string, options: string): RegexValue;
431+
432+
// @public
433+
export class RegexValue {
434+
constructor(pattern: string, options: string);
435+
isEqual(other: RegexValue): boolean;
436+
// (undocumented)
437+
readonly options: string;
438+
// (undocumented)
439+
readonly pattern: string;
440+
}
441+
363442
// @public
364443
export function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
365444

common/api-review/firestore.api.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,41 @@ export function arrayUnion(...elements: unknown[]): FieldValue;
6565
// @public
6666
export function average(field: string | FieldPath): AggregateField<number | null>;
6767

68+
// @public
69+
export class BsonBinaryData {
70+
constructor(subtype: number, data: Uint8Array);
71+
readonly data: Uint8Array;
72+
isEqual(other: BsonBinaryData): boolean;
73+
readonly subtype: number;
74+
}
75+
76+
// @public
77+
export function bsonBinaryData(subtype: number, data: Uint8Array): BsonBinaryData;
78+
79+
// @public
80+
export class BsonObjectId {
81+
constructor(value: string);
82+
isEqual(other: BsonObjectId): boolean;
83+
// (undocumented)
84+
readonly value: string;
85+
}
86+
87+
// @public
88+
export function bsonObjectId(value: string): BsonObjectId;
89+
90+
// @public
91+
export function bsonTimestamp(seconds: number, increment: number): BsonTimestampValue;
92+
93+
// @public
94+
export class BsonTimestampValue {
95+
constructor(seconds: number, increment: number);
96+
// (undocumented)
97+
readonly increment: number;
98+
isEqual(other: BsonTimestampValue): boolean;
99+
// (undocumented)
100+
readonly seconds: number;
101+
}
102+
68103
// @public
69104
export class Bytes {
70105
static fromBase64String(base64: string): Bytes;
@@ -344,6 +379,17 @@ export interface IndexField {
344379
// @public
345380
export function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings, databaseId?: string): Firestore;
346381

382+
// @public
383+
export function int32(value: number): Int32Value;
384+
385+
// @public
386+
export class Int32Value {
387+
constructor(value: number);
388+
isEqual(other: Int32Value): boolean;
389+
// (undocumented)
390+
readonly value: number;
391+
}
392+
347393
// @public
348394
export function limit(limit: number): QueryLimitConstraint;
349395

@@ -374,6 +420,16 @@ export interface LoadBundleTaskProgress {
374420

375421
export { LogLevel }
376422

423+
// @public
424+
export class MaxKey {
425+
// (undocumented)
426+
static instance(): MaxKey;
427+
readonly type = "MaxKey";
428+
}
429+
430+
// @public
431+
export function maxKey(): MaxKey;
432+
377433
// @public
378434
export interface MemoryCacheSettings {
379435
garbageCollector?: MemoryGarbageCollector;
@@ -411,6 +467,16 @@ export function memoryLruGarbageCollector(settings?: {
411467
cacheSizeBytes?: number;
412468
}): MemoryLruGarbageCollector;
413469

470+
// @public
471+
export class MinKey {
472+
// (undocumented)
473+
static instance(): MinKey;
474+
readonly type = "MinKey";
475+
}
476+
477+
// @public
478+
export function minKey(): MinKey;
479+
414480
// @public
415481
export function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;
416482

@@ -620,6 +686,19 @@ export class QueryStartAtConstraint extends QueryConstraint {
620686
// @public
621687
export function refEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>, right: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>): boolean;
622688

689+
// @public
690+
export function regex(pattern: string, options: string): RegexValue;
691+
692+
// @public
693+
export class RegexValue {
694+
constructor(pattern: string, options: string);
695+
isEqual(other: RegexValue): boolean;
696+
// (undocumented)
697+
readonly options: string;
698+
// (undocumented)
699+
readonly pattern: string;
700+
}
701+
623702
// @public
624703
export function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
625704

packages/firestore/lite/index.ts

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

134141
export {
@@ -141,6 +148,20 @@ export {
141148

142149
export { VectorValue } from '../src/lite-api/vector_value';
143150

151+
export { Int32Value } from '../src/lite-api/int32_value';
152+
153+
export { RegexValue } from '../src/lite-api/regex_value';
154+
155+
export { BsonBinaryData } from '../src/lite-api/bson_binary_data';
156+
157+
export { BsonObjectId } from '../src/lite-api/bson_object_Id';
158+
159+
export { BsonTimestampValue } from '../src/lite-api/bson_timestamp_value';
160+
161+
export { MinKey } from '../src/lite-api/min_key';
162+
163+
export { MaxKey } from '../src/lite-api/max_key';
164+
144165
export { WriteBatch, writeBatch } from '../src/lite-api/write_batch';
145166

146167
export { TransactionOptions } from '../src/lite-api/transaction_options';

packages/firestore/src/api.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,32 @@ export {
173173
deleteField,
174174
increment,
175175
serverTimestamp,
176-
vector
176+
vector,
177+
int32,
178+
regex,
179+
bsonBinaryData,
180+
bsonObjectId,
181+
bsonTimestamp,
182+
minKey,
183+
maxKey
177184
} from './api/field_value_impl';
178185

179186
export { VectorValue } from './lite-api/vector_value';
180187

188+
export { Int32Value } from './lite-api/int32_value';
189+
190+
export { RegexValue } from './lite-api/regex_value';
191+
192+
export { BsonBinaryData } from './lite-api/bson_binary_data';
193+
194+
export { BsonObjectId } from './lite-api/bson_object_Id';
195+
196+
export { BsonTimestampValue } from './lite-api/bson_timestamp_value';
197+
198+
export { MinKey } from './lite-api/min_key';
199+
200+
export { MaxKey } from './lite-api/max_key';
201+
181202
export { LogLevelString as LogLevel, setLogLevel } from './util/log';
182203

183204
export { Bytes } from './api/bytes';

packages/firestore/src/api/field_value_impl.ts

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

packages/firestore/src/core/target.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import {
2525
import { FieldPath, ResourcePath } from '../model/path';
2626
import {
2727
canonicalId,
28-
MAX_VALUE,
29-
MIN_VALUE,
28+
INTERNAL_MAX_VALUE,
29+
INTERNAL_MIN_VALUE,
3030
lowerBoundCompare,
3131
upperBoundCompare,
3232
valuesGetLowerBound,
@@ -302,7 +302,7 @@ export function targetGetNotInValues(
302302

303303
/**
304304
* Returns a lower bound of field values that can be used as a starting point to
305-
* scan the index defined by `fieldIndex`. Returns `MIN_VALUE` if no lower bound
305+
* scan the index defined by `fieldIndex`. Returns `INTERNAL_MIN_VALUE` if no lower bound
306306
* exists.
307307
*/
308308
export function targetGetLowerBound(
@@ -328,7 +328,7 @@ export function targetGetLowerBound(
328328

329329
/**
330330
* Returns an upper bound of field values that can be used as an ending point
331-
* when scanning the index defined by `fieldIndex`. Returns `MAX_VALUE` if no
331+
* when scanning the index defined by `fieldIndex`. Returns `INTERNAL_MAX_VALUE` if no
332332
* upper bound exists.
333333
*/
334334
export function targetGetUpperBound(
@@ -362,13 +362,13 @@ function targetGetAscendingBound(
362362
fieldPath: FieldPath,
363363
bound: Bound | null
364364
): { value: ProtoValue; inclusive: boolean } {
365-
let value: ProtoValue = MIN_VALUE;
365+
let value: ProtoValue = INTERNAL_MIN_VALUE;
366366

367367
let inclusive = true;
368368

369369
// Process all filters to find a value for the current field segment
370370
for (const fieldFilter of targetGetFieldFiltersForPath(target, fieldPath)) {
371-
let filterValue: ProtoValue = MIN_VALUE;
371+
let filterValue: ProtoValue = INTERNAL_MIN_VALUE;
372372
let filterInclusive = true;
373373

374374
switch (fieldFilter.op) {
@@ -387,7 +387,7 @@ function targetGetAscendingBound(
387387
break;
388388
case Operator.NOT_EQUAL:
389389
case Operator.NOT_IN:
390-
filterValue = MIN_VALUE;
390+
filterValue = INTERNAL_MIN_VALUE;
391391
break;
392392
default:
393393
// Remaining filters cannot be used as lower bounds.
@@ -437,12 +437,12 @@ function targetGetDescendingBound(
437437
fieldPath: FieldPath,
438438
bound: Bound | null
439439
): { value: ProtoValue; inclusive: boolean } {
440-
let value: ProtoValue = MAX_VALUE;
440+
let value: ProtoValue = INTERNAL_MAX_VALUE;
441441
let inclusive = true;
442442

443443
// Process all filters to find a value for the current field segment
444444
for (const fieldFilter of targetGetFieldFiltersForPath(target, fieldPath)) {
445-
let filterValue: ProtoValue = MAX_VALUE;
445+
let filterValue: ProtoValue = INTERNAL_MAX_VALUE;
446446
let filterInclusive = true;
447447

448448
switch (fieldFilter.op) {
@@ -462,7 +462,7 @@ function targetGetDescendingBound(
462462
break;
463463
case Operator.NOT_EQUAL:
464464
case Operator.NOT_IN:
465-
filterValue = MAX_VALUE;
465+
filterValue = INTERNAL_MAX_VALUE;
466466
break;
467467
default:
468468
// Remaining filters cannot be used as upper bounds.

packages/firestore/src/index/firestore_index_value_writer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class FirestoreIndexValueWriter {
124124
encoder.writeNumber(geoPoint.latitude || 0);
125125
encoder.writeNumber(geoPoint.longitude || 0);
126126
} else if ('mapValue' in indexValue) {
127+
// TODO(Mila/BSON): add bson types for indexing
127128
if (isMaxValue(indexValue)) {
128129
this.writeValueTypeLabel(encoder, Number.MAX_SAFE_INTEGER);
129130
} else if (isVectorValue(indexValue)) {

0 commit comments

Comments
 (0)