Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sum-avg-release-4-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannas committed Oct 3, 2023
2 parents 4a8896f + 0afadef commit d2c2552
Show file tree
Hide file tree
Showing 23 changed files with 2,210 additions and 619 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

[1]: https://www.npmjs.com/package/@google-cloud/firestore?activeTab=versions

## [6.8.0](https://github.com/googleapis/nodejs-firestore/compare/v6.7.0...v6.8.0) (2023-09-26)


### Features

* Publish proto definitions for SUM/AVG in Firestore ([#1856](https://github.com/googleapis/nodejs-firestore/issues/1856)) ([ac35b37](https://github.com/googleapis/nodejs-firestore/commit/ac35b372faf32f093d83af18d487f1b3f23ee673))


### Bug Fixes

* **deps:** Use protobufjs v7.2.5 ([#1889](https://github.com/googleapis/nodejs-firestore/pull/1889))
* Add tests for multiple inequality support ([#1878](https://github.com/googleapis/nodejs-firestore/issues/1878)) ([8e621d5](https://github.com/googleapis/nodejs-firestore/commit/8e621d580396b7e3bc7e42dad0c63f91e999411f))

## [6.7.0](https://github.com/googleapis/nodejs-firestore/compare/v6.6.1...v6.7.0) (2023-07-20)


Expand Down
2 changes: 1 addition & 1 deletion dev/conformance/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const convertInput = {
}
return args;
},
snapshot: (snapshot: ConformanceProto) => {
snapshot: (snapshot: ConformanceProto): QuerySnapshot => {
const docs: QueryDocumentSnapshot[] = [];
const changes: DocumentChange[] = [];
const readTime = Timestamp.fromProto(snapshot.readTime);
Expand Down
7 changes: 6 additions & 1 deletion dev/src/backoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ export function setTimeoutHandler(
[Symbol.toPrimitive]: () => {
throw new Error('For tests only. Not Implemented');
},
};
} as unknown as NodeJS.Timeout;
// `NodeJS.Timeout` type signature change:
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/66176/files#diff-e838d0ace9cd5f6516bacfbd3ad00d02cd37bd60f9993ce6223f52d889a1fdbaR122-R126
//
// Adding `[Symbol.dispose](): void;` cannot be done on older versions of
// NodeJS. So we simply cast to `NodeJS.Timeout`.
return timeout;
};
}
Expand Down
41 changes: 20 additions & 21 deletions dev/src/bulk-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
MAX_RETRY_ATTEMPTS,
} from './backoff';
import {RateLimiter} from './rate-limiter';
import {DocumentReference} from './reference';
import {Timestamp} from './timestamp';
import {
Deferred,
Expand Down Expand Up @@ -337,7 +336,7 @@ export class BulkWriterError extends Error {
readonly message: string,

/** The document reference the operation was performed on. */
readonly documentRef: firestore.DocumentReference<unknown>,
readonly documentRef: firestore.DocumentReference<any, any>,

/** The type of operation performed. */
readonly operationType: 'create' | 'set' | 'update' | 'delete',
Expand Down Expand Up @@ -576,9 +575,9 @@ export class BulkWriter {
* });
* ```
*/
create<T>(
documentRef: firestore.DocumentReference<T>,
data: firestore.WithFieldValue<T>
create<AppModelType, DbModelType extends firestore.DocumentData>(
documentRef: firestore.DocumentReference<AppModelType, DbModelType>,
data: firestore.WithFieldValue<AppModelType>
): Promise<WriteResult> {
this._verifyNotClosed();
return this._enqueue(documentRef, 'create', bulkCommitBatch =>
Expand Down Expand Up @@ -616,8 +615,8 @@ export class BulkWriter {
* });
* ```
*/
delete<T>(
documentRef: firestore.DocumentReference<T>,
delete<AppModelType, DbModelType extends firestore.DocumentData>(
documentRef: firestore.DocumentReference<AppModelType, DbModelType>,
precondition?: firestore.Precondition
): Promise<WriteResult> {
this._verifyNotClosed();
Expand All @@ -626,14 +625,14 @@ export class BulkWriter {
);
}

set<T>(
documentRef: firestore.DocumentReference<T>,
data: Partial<T>,
set<AppModelType, DbModelType extends firestore.DocumentData>(
documentRef: firestore.DocumentReference<AppModelType, DbModelType>,
data: Partial<AppModelType>,
options: firestore.SetOptions
): Promise<WriteResult>;
set<T>(
documentRef: firestore.DocumentReference<T>,
data: T
set<AppModelType, DbModelType extends firestore.DocumentData>(
documentRef: firestore.DocumentReference<AppModelType, DbModelType>,
data: AppModelType
): Promise<WriteResult>;
/**
* Write to the document referred to by the provided
Expand Down Expand Up @@ -675,9 +674,9 @@ export class BulkWriter {
* });
* ```
*/
set<T>(
documentRef: firestore.DocumentReference<T>,
data: firestore.PartialWithFieldValue<T>,
set<AppModelType, DbModelType extends firestore.DocumentData>(
documentRef: firestore.DocumentReference<AppModelType, DbModelType>,
data: firestore.PartialWithFieldValue<AppModelType>,
options?: firestore.SetOptions
): Promise<WriteResult> {
this._verifyNotClosed();
Expand All @@ -687,7 +686,7 @@ export class BulkWriter {
} else {
return bulkCommitBatch.set(
documentRef,
data as firestore.WithFieldValue<T>
data as firestore.WithFieldValue<AppModelType>
);
}
});
Expand Down Expand Up @@ -737,9 +736,9 @@ export class BulkWriter {
* });
* ```
*/
update<T>(
documentRef: firestore.DocumentReference<T>,
dataOrField: firestore.UpdateData<T> | string | FieldPath,
update<AppModelType, DbModelType extends firestore.DocumentData>(
documentRef: firestore.DocumentReference<AppModelType, DbModelType>,
dataOrField: firestore.UpdateData<DbModelType> | string | FieldPath,
...preconditionOrValues: Array<
{lastUpdateTime?: Timestamp} | unknown | string | FieldPath
>
Expand Down Expand Up @@ -783,7 +782,7 @@ export class BulkWriter {
*/
onWriteResult(
successCallback: (
documentRef: firestore.DocumentReference<unknown>,
documentRef: firestore.DocumentReference<any, any>,
result: WriteResult
) => void
): void {
Expand Down
45 changes: 30 additions & 15 deletions dev/src/collection-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ import {compareArrays} from './order';
*
* @class CollectionGroup
*/
export class CollectionGroup<T = firestore.DocumentData>
extends Query<T>
implements firestore.CollectionGroup<T>
export class CollectionGroup<
AppModelType = firestore.DocumentData,
DbModelType extends firestore.DocumentData = firestore.DocumentData
>
extends Query<AppModelType, DbModelType>
implements firestore.CollectionGroup<AppModelType, DbModelType>
{
/** @private */
constructor(
firestore: Firestore,
collectionId: string,
converter: firestore.FirestoreDataConverter<T> | undefined
converter:
| firestore.FirestoreDataConverter<AppModelType, DbModelType>
| undefined
) {
super(
firestore,
Expand Down Expand Up @@ -74,7 +79,7 @@ export class CollectionGroup<T = firestore.DocumentData>
*/
async *getPartitions(
desiredPartitionCount: number
): AsyncIterable<QueryPartition<T>> {
): AsyncIterable<QueryPartition<AppModelType, DbModelType>> {
validateInteger('desiredPartitionCount', desiredPartitionCount, {
minValue: 1,
});
Expand Down Expand Up @@ -141,7 +146,8 @@ export class CollectionGroup<T = firestore.DocumentData>
* Applies a custom data converter to this `CollectionGroup`, allowing you
* to use your own custom model objects with Firestore. When you call get()
* on the returned `CollectionGroup`, the provided converter will convert
* between Firestore data and your custom type U.
* between Firestore data of type `NewDbModelType` and your custom type
* `NewAppModelType`.
*
* Using the converter allows you to specify generic type arguments when
* storing and retrieving objects from Firestore.
Expand Down Expand Up @@ -185,17 +191,26 @@ export class CollectionGroup<T = firestore.DocumentData>
* ```
* @param {FirestoreDataConverter | null} converter Converts objects to and
* from Firestore. Passing in `null` removes the current converter.
* @return {CollectionGroup} A `CollectionGroup<U>` that uses the provided
* @return {CollectionGroup} A `CollectionGroup` that uses the provided
* converter.
*/
withConverter(converter: null): CollectionGroup<firestore.DocumentData>;
withConverter<U>(
converter: firestore.FirestoreDataConverter<U>
): CollectionGroup<U>;
withConverter<U>(
converter: firestore.FirestoreDataConverter<U> | null
): CollectionGroup<U> {
return new CollectionGroup<U>(
withConverter(converter: null): CollectionGroup;
withConverter<
NewAppModelType,
NewDbModelType extends firestore.DocumentData = firestore.DocumentData
>(
converter: firestore.FirestoreDataConverter<NewAppModelType, NewDbModelType>
): CollectionGroup<NewAppModelType, NewDbModelType>;
withConverter<
NewAppModelType,
NewDbModelType extends firestore.DocumentData = firestore.DocumentData
>(
converter: firestore.FirestoreDataConverter<
NewAppModelType,
NewDbModelType
> | null
): CollectionGroup<NewAppModelType, NewDbModelType> {
return new CollectionGroup<NewAppModelType, NewDbModelType>(
this.firestore,
this._queryOptions.collectionId,
converter ?? defaultConverter()
Expand Down
14 changes: 8 additions & 6 deletions dev/src/document-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export type DocumentChangeType = 'added' | 'removed' | 'modified';
*
* @class DocumentChange
*/
export class DocumentChange<T = firestore.DocumentData>
implements firestore.DocumentChange<T>
export class DocumentChange<
AppModelType = firestore.DocumentData,
DbModelType extends firestore.DocumentData = firestore.DocumentData
> implements firestore.DocumentChange<AppModelType, DbModelType>
{
private readonly _type: DocumentChangeType;
private readonly _document: QueryDocumentSnapshot<T>;
private readonly _document: QueryDocumentSnapshot<AppModelType, DbModelType>;
private readonly _oldIndex: number;
private readonly _newIndex: number;

Expand All @@ -46,7 +48,7 @@ export class DocumentChange<T = firestore.DocumentData>
*/
constructor(
type: DocumentChangeType,
document: QueryDocumentSnapshot<T>,
document: QueryDocumentSnapshot<AppModelType, DbModelType>,
oldIndex: number,
newIndex: number
) {
Expand Down Expand Up @@ -103,7 +105,7 @@ export class DocumentChange<T = firestore.DocumentData>
* unsubscribe();
* ```
*/
get doc(): QueryDocumentSnapshot<T> {
get doc(): QueryDocumentSnapshot<AppModelType, DbModelType> {
return this._document;
}

Expand Down Expand Up @@ -181,7 +183,7 @@ export class DocumentChange<T = firestore.DocumentData>
* @param {*} other The value to compare against.
* @return true if this `DocumentChange` is equal to the provided value.
*/
isEqual(other: firestore.DocumentChange<T>): boolean {
isEqual(other: firestore.DocumentChange<AppModelType, DbModelType>): boolean {
if (this === other) {
return true;
}
Expand Down
13 changes: 8 additions & 5 deletions dev/src/document-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import api = google.firestore.v1;
* @private
* @internal
*/
export class DocumentReader<T> {
export class DocumentReader<AppModelType, DbModelType extends DocumentData> {
/** An optional field mask to apply to this read. */
fieldMask?: FieldPath[];
/** An optional transaction ID to use for this read. */
Expand All @@ -49,7 +49,7 @@ export class DocumentReader<T> {
*/
constructor(
private firestore: Firestore,
private allDocuments: Array<DocumentReference<T>>
private allDocuments: Array<DocumentReference<AppModelType, DbModelType>>
) {
for (const docRef of this.allDocuments) {
this.outstandingDocuments.add(docRef.formattedName);
Expand All @@ -61,20 +61,23 @@ export class DocumentReader<T> {
*
* @param requestTag A unique client-assigned identifier for this request.
*/
async get(requestTag: string): Promise<Array<DocumentSnapshot<T>>> {
async get(
requestTag: string
): Promise<Array<DocumentSnapshot<AppModelType, DbModelType>>> {
await this.fetchDocuments(requestTag);

// BatchGetDocuments doesn't preserve document order. We use the request
// order to sort the resulting documents.
const orderedDocuments: Array<DocumentSnapshot<T>> = [];
const orderedDocuments: Array<DocumentSnapshot<AppModelType, DbModelType>> =
[];

for (const docRef of this.allDocuments) {
const document = this.retrievedDocuments.get(docRef.formattedName);
if (document !== undefined) {
// Recreate the DocumentSnapshot with the DocumentReference
// containing the original converter.
const finalDoc = new DocumentSnapshotBuilder(
docRef as DocumentReference<T>
docRef as DocumentReference<AppModelType, DbModelType>
);
finalDoc.fieldsProto = document._fieldsProto;
finalDoc.readTime = document.readTime;
Expand Down
Loading

0 comments on commit d2c2552

Please sign in to comment.