From d8db05d9fb72c19b4a93acdc2addd118f444f514 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 17 Aug 2022 15:38:25 -0700 Subject: [PATCH 1/6] Revert "Revert "Updated type of action parameter for DataSnapshot#forEach" (#6536)" This reverts commit 9f1e3c66747126c8e24894d73f7fa27480bec08d. --- .changeset/orange-doors-swim.md | 7 ------- common/api-review/database.api.md | 4 +++- packages/database-compat/src/api/Reference.ts | 4 +++- packages/database-types/index.d.ts | 4 +++- packages/database/src/api/Reference_impl.ts | 4 +++- packages/firebase/compat/index.d.ts | 4 +++- 6 files changed, 15 insertions(+), 12 deletions(-) delete mode 100644 .changeset/orange-doors-swim.md diff --git a/.changeset/orange-doors-swim.md b/.changeset/orange-doors-swim.md deleted file mode 100644 index 4b20eb3f200..00000000000 --- a/.changeset/orange-doors-swim.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"@firebase/database-compat": patch -"@firebase/database-types": patch -"@firebase/database": patch ---- - -Revert "Updated type of action parameter for DataSnapshot#forEach" diff --git a/common/api-review/database.api.md b/common/api-review/database.api.md index 8b3ef1ac7fb..5ce1fbeaf80 100644 --- a/common/api-review/database.api.md +++ b/common/api-review/database.api.md @@ -33,7 +33,9 @@ export class DataSnapshot { child(path: string): DataSnapshot; exists(): boolean; exportVal(): any; - forEach(action: (child: DataSnapshot) => boolean | void): boolean; + forEach(action: (child: DataSnapshot & { + key: string; + }) => boolean | void): boolean; hasChild(path: string): boolean; hasChildren(): boolean; get key(): string | null; diff --git a/packages/database-compat/src/api/Reference.ts b/packages/database-compat/src/api/Reference.ts index 3f9bb63b8ff..e2bbef4ef26 100644 --- a/packages/database-compat/src/api/Reference.ts +++ b/packages/database-compat/src/api/Reference.ts @@ -164,7 +164,9 @@ export class DataSnapshot implements Compat { * @returns True if forEach was canceled by action returning true for * one of the child nodes. */ - forEach(action: (snapshot: DataSnapshot) => boolean | void): boolean { + forEach( + action: (snapshot: DataSnapshot & { key: string }) => boolean | void + ): boolean { validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length); validateCallback('DataSnapshot.forEach', 'action', action, false); return this._delegate.forEach(expDataSnapshot => diff --git a/packages/database-types/index.d.ts b/packages/database-types/index.d.ts index 680a4a540b8..55d3d236f96 100644 --- a/packages/database-types/index.d.ts +++ b/packages/database-types/index.d.ts @@ -22,7 +22,9 @@ export interface DataSnapshot { child(path: string): DataSnapshot; exists(): boolean; exportVal(): any; - forEach(action: (a: DataSnapshot) => boolean | void): boolean; + forEach( + action: (a: DataSnapshot & { key: string }) => boolean | void + ): boolean; getPriority(): string | number | null; hasChild(path: string): boolean; hasChildren(): boolean; diff --git a/packages/database/src/api/Reference_impl.ts b/packages/database/src/api/Reference_impl.ts index ef98380d0d1..97e20ef635d 100644 --- a/packages/database/src/api/Reference_impl.ts +++ b/packages/database/src/api/Reference_impl.ts @@ -393,7 +393,9 @@ export class DataSnapshot { * @returns true if enumeration was canceled due to your callback returning * true. */ - forEach(action: (child: DataSnapshot) => boolean | void): boolean { + forEach( + action: (child: DataSnapshot & { key: string }) => boolean | void + ): boolean { if (this._node.isLeafNode()) { return false; } diff --git a/packages/firebase/compat/index.d.ts b/packages/firebase/compat/index.d.ts index ece18a5d1dd..a946c38ec9a 100644 --- a/packages/firebase/compat/index.d.ts +++ b/packages/firebase/compat/index.d.ts @@ -5819,7 +5819,9 @@ declare namespace firebase.database { * returning true. */ forEach( - action: (a: firebase.database.DataSnapshot) => boolean | void + action: ( + a: firebase.database.DataSnapshot & { key: string } + ) => boolean | void ): boolean; /** * Gets the priority value of the data in this `DataSnapshot`. From ebbccf851a249c9587f96ba937d18e85cb0b516b Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 17 Aug 2022 15:41:14 -0700 Subject: [PATCH 2/6] Create silly-eagles-unite.md --- .changeset/silly-eagles-unite.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/silly-eagles-unite.md diff --git a/.changeset/silly-eagles-unite.md b/.changeset/silly-eagles-unite.md new file mode 100644 index 00000000000..4b5989200b0 --- /dev/null +++ b/.changeset/silly-eagles-unite.md @@ -0,0 +1,7 @@ +--- +"@firebase/database-compat": major +"@firebase/database-types": major +"@firebase/database": major +--- + +Updated type of action parameter for DataSnapshot#forEach From 03606cc1f15a45a8506a6c9412568e82ce50840f Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 18 Aug 2022 15:44:49 -0700 Subject: [PATCH 3/6] Introduced new interface to represent iterated elements --- common/api-review/database.api.md | 10 +++++++--- packages/database-compat/src/api/Reference.ts | 8 +++++++- packages/database-types/index.d.ts | 9 ++++++++- packages/database/src/api.standalone.ts | 1 + packages/database/src/api/Reference_impl.ts | 11 +++++++++-- packages/firebase/compat/index.d.ts | 2 +- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/common/api-review/database.api.md b/common/api-review/database.api.md index 5ce1fbeaf80..4a98aea3d4e 100644 --- a/common/api-review/database.api.md +++ b/common/api-review/database.api.md @@ -33,9 +33,7 @@ export class DataSnapshot { child(path: string): DataSnapshot; exists(): boolean; exportVal(): any; - forEach(action: (child: DataSnapshot & { - key: string; - }) => boolean | void): boolean; + forEach(action: (child: IteratedDataSnapshot) => boolean | void): boolean; hasChild(path: string): boolean; hasChildren(): boolean; get key(): string | null; @@ -87,6 +85,12 @@ export function goOnline(db: Database): void; // @public export function increment(delta: number): object; +// @public +export interface IteratedDataSnapshot extends DataSnapshot { + // (undocumented) + key: string; +} + // @public export function limitToFirst(limit: number): QueryConstraint; diff --git a/packages/database-compat/src/api/Reference.ts b/packages/database-compat/src/api/Reference.ts index e2bbef4ef26..d6d44042c1b 100644 --- a/packages/database-compat/src/api/Reference.ts +++ b/packages/database-compat/src/api/Reference.ts @@ -156,6 +156,8 @@ export class DataSnapshot implements Compat { return this._delegate.priority; } + + /** * Iterates through child nodes and calls the specified action for each one. * @@ -165,7 +167,7 @@ export class DataSnapshot implements Compat { * one of the child nodes. */ forEach( - action: (snapshot: DataSnapshot & { key: string }) => boolean | void + action: (snapshot: IteratedDataSnapshot) => boolean | void ): boolean { validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length); validateCallback('DataSnapshot.forEach', 'action', action, false); @@ -210,6 +212,10 @@ export class DataSnapshot implements Compat { } } +export interface IteratedDataSnapshot extends DataSnapshot { + key: string; +} + export interface SnapshotCallback { (dataSnapshot: DataSnapshot, previousChildName?: string | null): unknown; } diff --git a/packages/database-types/index.d.ts b/packages/database-types/index.d.ts index 55d3d236f96..54ac2ff7881 100644 --- a/packages/database-types/index.d.ts +++ b/packages/database-types/index.d.ts @@ -18,12 +18,19 @@ import { FirebaseApp } from '@firebase/app-types'; import { EmulatorMockTokenOptions } from '@firebase/util'; +/** + * Represents a child snapshot of an iterated `Reference`. The key will never be undefined. + */ +export interface IteratedDataSnapshot extends DataSnapshot { + key: string; +} + export interface DataSnapshot { child(path: string): DataSnapshot; exists(): boolean; exportVal(): any; forEach( - action: (a: DataSnapshot & { key: string }) => boolean | void + action: (a: IteratedDataSnapshot) => boolean | void ): boolean; getPriority(): string | number | null; hasChild(path: string): boolean; diff --git a/packages/database/src/api.standalone.ts b/packages/database/src/api.standalone.ts index 876ec67c441..c7726143f16 100644 --- a/packages/database/src/api.standalone.ts +++ b/packages/database/src/api.standalone.ts @@ -37,6 +37,7 @@ export { OnDisconnect } from './api/OnDisconnect'; export { DataSnapshot, EventType, + IteratedDataSnapshot, QueryConstraint, QueryConstraintType, endAt, diff --git a/packages/database/src/api/Reference_impl.ts b/packages/database/src/api/Reference_impl.ts index 97e20ef635d..8cfffd3f92a 100644 --- a/packages/database/src/api/Reference_impl.ts +++ b/packages/database/src/api/Reference_impl.ts @@ -376,7 +376,7 @@ export class DataSnapshot { } /** - * Enumerates the top-level children in the `DataSnapshot`. + * Enumerates the top-level children in the `IteratorDataSnapshot`. * * Because of the way JavaScript objects work, the ordering of data in the * JavaScript object returned by `val()` is not guaranteed to match the @@ -394,7 +394,7 @@ export class DataSnapshot { * true. */ forEach( - action: (child: DataSnapshot & { key: string }) => boolean | void + action: (child: IteratedDataSnapshot) => boolean | void ): boolean { if (this._node.isLeafNode()) { return false; @@ -465,6 +465,13 @@ export class DataSnapshot { } } +/** + * Represents a child snapshot of an iterated `Reference`. The key will never be undefined. + */ +export interface IteratedDataSnapshot extends DataSnapshot { + key: string; +} + /** * * Returns a `Reference` representing the location in the Database diff --git a/packages/firebase/compat/index.d.ts b/packages/firebase/compat/index.d.ts index a946c38ec9a..cef278c5866 100644 --- a/packages/firebase/compat/index.d.ts +++ b/packages/firebase/compat/index.d.ts @@ -5820,7 +5820,7 @@ declare namespace firebase.database { */ forEach( action: ( - a: firebase.database.DataSnapshot & { key: string } + a: firebase.database.IteratorDataSnapshot ) => boolean | void ): boolean; /** From 87c407c3a61aa014fc7b0cfc11ccff06030a450d Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Fri, 19 Aug 2022 10:35:43 -0700 Subject: [PATCH 4/6] Updated formatting --- common/api-review/database.api.md | 3 ++- packages/database-compat/src/api/Reference.ts | 6 +----- packages/database-types/index.d.ts | 4 +--- packages/database/src/api/Reference_impl.ts | 4 +--- packages/firebase/compat/index.d.ts | 4 +--- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/common/api-review/database.api.md b/common/api-review/database.api.md index 4a98aea3d4e..4c1ee90a3f6 100644 --- a/common/api-review/database.api.md +++ b/common/api-review/database.api.md @@ -6,6 +6,7 @@ import { EmulatorMockTokenOptions } from '@firebase/util'; import { FirebaseApp } from '@firebase/app'; +import { _FirebaseService } from '@firebase/app'; // @public export function child(parent: DatabaseReference, path: string): DatabaseReference; @@ -16,7 +17,7 @@ export function connectDatabaseEmulator(db: Database, host: string, port: number }): void; // @public -export class Database { +export class Database implements _FirebaseService { readonly app: FirebaseApp; readonly 'type' = "database"; } diff --git a/packages/database-compat/src/api/Reference.ts b/packages/database-compat/src/api/Reference.ts index d6d44042c1b..53b5ec1465f 100644 --- a/packages/database-compat/src/api/Reference.ts +++ b/packages/database-compat/src/api/Reference.ts @@ -156,8 +156,6 @@ export class DataSnapshot implements Compat { return this._delegate.priority; } - - /** * Iterates through child nodes and calls the specified action for each one. * @@ -166,9 +164,7 @@ export class DataSnapshot implements Compat { * @returns True if forEach was canceled by action returning true for * one of the child nodes. */ - forEach( - action: (snapshot: IteratedDataSnapshot) => boolean | void - ): boolean { + forEach(action: (snapshot: IteratedDataSnapshot) => boolean | void): boolean { validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length); validateCallback('DataSnapshot.forEach', 'action', action, false); return this._delegate.forEach(expDataSnapshot => diff --git a/packages/database-types/index.d.ts b/packages/database-types/index.d.ts index 54ac2ff7881..a61ce885167 100644 --- a/packages/database-types/index.d.ts +++ b/packages/database-types/index.d.ts @@ -29,9 +29,7 @@ export interface DataSnapshot { child(path: string): DataSnapshot; exists(): boolean; exportVal(): any; - forEach( - action: (a: IteratedDataSnapshot) => boolean | void - ): boolean; + forEach(action: (a: IteratedDataSnapshot) => boolean | void): boolean; getPriority(): string | number | null; hasChild(path: string): boolean; hasChildren(): boolean; diff --git a/packages/database/src/api/Reference_impl.ts b/packages/database/src/api/Reference_impl.ts index 8cfffd3f92a..04b8610f978 100644 --- a/packages/database/src/api/Reference_impl.ts +++ b/packages/database/src/api/Reference_impl.ts @@ -393,9 +393,7 @@ export class DataSnapshot { * @returns true if enumeration was canceled due to your callback returning * true. */ - forEach( - action: (child: IteratedDataSnapshot) => boolean | void - ): boolean { + forEach(action: (child: IteratedDataSnapshot) => boolean | void): boolean { if (this._node.isLeafNode()) { return false; } diff --git a/packages/firebase/compat/index.d.ts b/packages/firebase/compat/index.d.ts index cef278c5866..12d16671c72 100644 --- a/packages/firebase/compat/index.d.ts +++ b/packages/firebase/compat/index.d.ts @@ -5819,9 +5819,7 @@ declare namespace firebase.database { * returning true. */ forEach( - action: ( - a: firebase.database.IteratorDataSnapshot - ) => boolean | void + action: (a: firebase.database.IteratorDataSnapshot) => boolean | void ): boolean; /** * Gets the priority value of the data in this `DataSnapshot`. From b132ae5ce898b78ae63e0378cea0411647154603 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Fri, 19 Aug 2022 10:42:17 -0700 Subject: [PATCH 5/6] Undid FirebaseService change --- common/api-review/database.api.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/api-review/database.api.md b/common/api-review/database.api.md index 4c1ee90a3f6..4a98aea3d4e 100644 --- a/common/api-review/database.api.md +++ b/common/api-review/database.api.md @@ -6,7 +6,6 @@ import { EmulatorMockTokenOptions } from '@firebase/util'; import { FirebaseApp } from '@firebase/app'; -import { _FirebaseService } from '@firebase/app'; // @public export function child(parent: DatabaseReference, path: string): DatabaseReference; @@ -17,7 +16,7 @@ export function connectDatabaseEmulator(db: Database, host: string, port: number }): void; // @public -export class Database implements _FirebaseService { +export class Database { readonly app: FirebaseApp; readonly 'type' = "database"; } From c17ed3052d87d9323ee7b1507e6c82d29598d43a Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Fri, 19 Aug 2022 10:54:18 -0700 Subject: [PATCH 6/6] Updated comments --- packages/database-compat/src/api/Reference.ts | 5 ++++- packages/database-types/index.d.ts | 4 ++-- packages/database/src/api/Reference_impl.ts | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/database-compat/src/api/Reference.ts b/packages/database-compat/src/api/Reference.ts index 53b5ec1465f..c4846b8ee60 100644 --- a/packages/database-compat/src/api/Reference.ts +++ b/packages/database-compat/src/api/Reference.ts @@ -208,8 +208,11 @@ export class DataSnapshot implements Compat { } } +/** + * Represents a child snapshot of a `Reference` that is being iterated over. The key will never be undefined. + */ export interface IteratedDataSnapshot extends DataSnapshot { - key: string; + key: string; // key of the location of this snapshot. } export interface SnapshotCallback { diff --git a/packages/database-types/index.d.ts b/packages/database-types/index.d.ts index a61ce885167..f304a4ed5b3 100644 --- a/packages/database-types/index.d.ts +++ b/packages/database-types/index.d.ts @@ -19,10 +19,10 @@ import { FirebaseApp } from '@firebase/app-types'; import { EmulatorMockTokenOptions } from '@firebase/util'; /** - * Represents a child snapshot of an iterated `Reference`. The key will never be undefined. + * Represents a child snapshot of a `Reference` that is being iterated over. The key will never be undefined. */ export interface IteratedDataSnapshot extends DataSnapshot { - key: string; + key: string; // key of the location of this snapshot. } export interface DataSnapshot { diff --git a/packages/database/src/api/Reference_impl.ts b/packages/database/src/api/Reference_impl.ts index 04b8610f978..f37e5a3b5fd 100644 --- a/packages/database/src/api/Reference_impl.ts +++ b/packages/database/src/api/Reference_impl.ts @@ -376,7 +376,7 @@ export class DataSnapshot { } /** - * Enumerates the top-level children in the `IteratorDataSnapshot`. + * Enumerates the top-level children in the `IteratedDataSnapshot`. * * Because of the way JavaScript objects work, the ordering of data in the * JavaScript object returned by `val()` is not guaranteed to match the @@ -464,10 +464,10 @@ export class DataSnapshot { } /** - * Represents a child snapshot of an iterated `Reference`. The key will never be undefined. + * Represents a child snapshot of a `Reference` that is being iterated over. The key will never be undefined. */ export interface IteratedDataSnapshot extends DataSnapshot { - key: string; + key: string; // key of the location of this snapshot. } /**