Skip to content

Commit bac86bf

Browse files
committed
update Reference to DatabaseReference
1 parent eccfed7 commit bac86bf

File tree

5 files changed

+61
-55
lines changed

5 files changed

+61
-55
lines changed

common/api-review/database.api.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ import { EmulatorMockTokenOptions } from '@firebase/util';
88
import { FirebaseApp } from '@firebase/app';
99

1010
// @public
11-
export function child(parent: Reference, path: string): Reference;
11+
export function child(parent: DatabaseReference, path: string): DatabaseReference;
1212

1313
// @public
1414
export class Database {
1515
readonly app: FirebaseApp;
1616
readonly 'type' = "database";
1717
}
1818

19+
// @public
20+
export interface DatabaseReference extends Query {
21+
readonly key: string | null;
22+
readonly parent: DatabaseReference | null;
23+
readonly root: DatabaseReference;
24+
}
25+
1926
// @public
2027
export class DataSnapshot {
2128
child(path: string): DataSnapshot;
@@ -26,7 +33,7 @@ export class DataSnapshot {
2633
hasChildren(): boolean;
2734
get key(): string | null;
2835
get priority(): string | number | null;
29-
readonly ref: Reference;
36+
readonly ref: DatabaseReference;
3037
get size(): number;
3138
toJSON(): object | null;
3239
val(): any;
@@ -125,7 +132,7 @@ export class OnDisconnect {
125132
}
126133

127134
// @public
128-
export function onDisconnect(ref: Reference): OnDisconnect;
135+
export function onDisconnect(ref: DatabaseReference): OnDisconnect;
129136

130137
// @public
131138
export function onValue(query: Query, callback: (snapshot: DataSnapshot) => unknown, cancelCallback?: (error: Error) => unknown): Unsubscribe;
@@ -149,12 +156,12 @@ export function orderByPriority(): QueryConstraint;
149156
export function orderByValue(): QueryConstraint;
150157

151158
// @public
152-
export function push(parent: Reference, value?: unknown): ThenableReference;
159+
export function push(parent: DatabaseReference, value?: unknown): ThenableReference;
153160

154161
// @public
155162
export interface Query {
156163
isEqual(other: Query | null): boolean;
157-
readonly ref: Reference;
164+
readonly ref: DatabaseReference;
158165
toJSON(): string;
159166
toString(): string;
160167
}
@@ -171,35 +178,28 @@ export abstract class QueryConstraint {
171178
export type QueryConstraintType = 'endAt' | 'endBefore' | 'startAt' | 'startAfter' | 'limitToFirst' | 'limitToLast' | 'orderByChild' | 'orderByKey' | 'orderByPriority' | 'orderByValue' | 'equalTo';
172179

173180
// @public
174-
export function ref(db: Database, path?: string): Reference;
175-
176-
// @public
177-
export interface Reference extends Query {
178-
readonly key: string | null;
179-
readonly parent: Reference | null;
180-
readonly root: Reference;
181-
}
181+
export function ref(db: Database, path?: string): DatabaseReference;
182182

183183
// @public
184-
export function refFromURL(db: Database, url: string): Reference;
184+
export function refFromURL(db: Database, url: string): DatabaseReference;
185185

186186
// @public
187-
export function remove(ref: Reference): Promise<void>;
187+
export function remove(ref: DatabaseReference): Promise<void>;
188188

189189
// @public
190-
export function runTransaction(ref: Reference, transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions): Promise<TransactionResult>;
190+
export function runTransaction(ref: DatabaseReference, transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions): Promise<TransactionResult>;
191191

192192
// @public
193193
export function serverTimestamp(): object;
194194

195195
// @public
196-
export function set(ref: Reference, value: unknown): Promise<void>;
196+
export function set(ref: DatabaseReference, value: unknown): Promise<void>;
197197

198198
// @public
199-
export function setPriority(ref: Reference, priority: string | number | null): Promise<void>;
199+
export function setPriority(ref: DatabaseReference, priority: string | number | null): Promise<void>;
200200

201201
// @public
202-
export function setWithPriority(ref: Reference, value: unknown, priority: string | number | null): Promise<void>;
202+
export function setWithPriority(ref: DatabaseReference, value: unknown, priority: string | number | null): Promise<void>;
203203

204204
// @public
205205
export function startAfter(value: number | string | boolean | null, key?: string): QueryConstraint;
@@ -208,7 +208,7 @@ export function startAfter(value: number | string | boolean | null, key?: string
208208
export function startAt(value?: number | string | boolean | null, key?: string): QueryConstraint;
209209

210210
// @public
211-
export interface ThenableReference extends Reference, Pick<Promise<Reference>, 'then' | 'catch'> {
211+
export interface ThenableReference extends DatabaseReference, Pick<Promise<DatabaseReference>, 'then' | 'catch'> {
212212
}
213213

214214
// @public
@@ -227,7 +227,7 @@ export class TransactionResult {
227227
export type Unsubscribe = () => void;
228228

229229
// @public
230-
export function update(ref: Reference, values: object): Promise<void>;
230+
export function update(ref: DatabaseReference, values: object): Promise<void>;
231231

232232
// @public
233233
export function useDatabaseEmulator(db: Database, host: string, port: number, options?: {

packages/database/exp/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export {
2626
} from '../src/exp/Database';
2727
export {
2828
Query,
29-
Reference,
29+
DatabaseReference,
3030
ListenOptions,
3131
Unsubscribe,
3232
ThenableReference

packages/database/src/exp/Reference.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ import { QueryContext } from '../core/view/EventRegistration';
2727
* suitable for synchronizing to the client. Queries are created by chaining
2828
* together one or more of the filter methods defined here.
2929
*
30-
* Just as with a `Reference`, you can receive data from a `Query` by using the
30+
* Just as with a `DatabaseReference`, you can receive data from a `Query` by using the
3131
* `on*()` methods. You will only receive events and `DataSnapshot`s for the
3232
* subset of the data that matches your query.
3333
*
3434
* See {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data}
3535
* for more information.
3636
*/
3737
export interface Query extends QueryContext {
38-
/** The `Reference` for the `Query`'s location. */
39-
readonly ref: Reference;
38+
/** The `DatabaseReference` for the `Query`'s location. */
39+
readonly ref: DatabaseReference;
4040

4141
/**
4242
* Returns whether or not the current and provided queries represent the same
4343
* location, have the same query parameters, and are from the same instance of
4444
* `FirebaseApp`.
4545
*
46-
* Two `Reference` objects are equivalent if they represent the same location
46+
* Two `DatabaseReference` objects are equivalent if they represent the same location
4747
* and are from the same instance of `FirebaseApp`.
4848
*
4949
* Two `Query` objects are equivalent if they represent the same location,
@@ -80,7 +80,7 @@ export interface Query extends QueryContext {
8080
}
8181

8282
/**
83-
* A `Reference` represents a specific location in your Database and can be used
83+
* A `DatabaseReference` represents a specific location in your Database and can be used
8484
* for reading or writing data to that Database location.
8585
*
8686
* You can reference the root or child location in your Database by calling
@@ -90,36 +90,36 @@ export interface Query extends QueryContext {
9090
* `on*()` method. See {@link
9191
* https://firebase.google.com/docs/database/web/read-and-write}
9292
*/
93-
export interface Reference extends Query {
93+
export interface DatabaseReference extends Query {
9494
/**
95-
* The last part of the `Reference`'s path.
95+
* The last part of the `DatabaseReference`'s path.
9696
*
9797
* For example, `"ada"` is the key for
9898
* `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
9999
*
100-
* The key of a root `Reference` is `null`.
100+
* The key of a root `DatabaseReference` is `null`.
101101
*/
102102
readonly key: string | null;
103103

104104
/**
105-
* The parent location of a `Reference`.
105+
* The parent location of a `DatabaseReference`.
106106
*
107-
* The parent of a root `Reference` is `null`.
107+
* The parent of a root `DatabaseReference` is `null`.
108108
*/
109-
readonly parent: Reference | null;
109+
readonly parent: DatabaseReference | null;
110110

111-
/** The root `Reference` of the Database. */
112-
readonly root: Reference;
111+
/** The root `DatabaseReference` of the Database. */
112+
readonly root: DatabaseReference;
113113
}
114114

115115
/**
116-
* A `Promise` that can also act as a `Reference` when returned by
116+
* A `Promise` that can also act as a `DatabaseReference` when returned by
117117
* {@link push}. The reference is available immediately and the Promise resolves
118118
* as the write to the backend completes.
119119
*/
120120
export interface ThenableReference
121-
extends Reference,
122-
Pick<Promise<Reference>, 'then' | 'catch'> {}
121+
extends DatabaseReference,
122+
Pick<Promise<DatabaseReference>, 'then' | 'catch'> {}
123123

124124
/** A callback that can invoked to remove a listener. */
125125
export type Unsubscribe = () => void;
@@ -131,5 +131,5 @@ export interface ListenOptions {
131131
}
132132

133133
export interface ReferenceConstructor {
134-
new (repo: Repo, path: Path): Reference;
134+
new (repo: Repo, path: Path): DatabaseReference;
135135
}

packages/database/src/exp/Reference_impl.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import { OnDisconnect } from './OnDisconnect';
8989
import {
9090
ListenOptions,
9191
Query as Query,
92-
Reference as Reference,
92+
DatabaseReference,
9393
Unsubscribe,
9494
ThenableReference
9595
} from './Reference';
@@ -116,7 +116,7 @@ export class QueryImpl implements Query, QueryContext {
116116
}
117117
}
118118

119-
get ref(): Reference {
119+
get ref(): DatabaseReference {
120120
return new ReferenceImpl(this._repo, this._path);
121121
}
122122

@@ -250,7 +250,7 @@ function validateLimit(params: QueryParams) {
250250
/**
251251
* @internal
252252
*/
253-
export class ReferenceImpl extends QueryImpl implements Reference {
253+
export class ReferenceImpl extends QueryImpl implements DatabaseReference {
254254
/** @hideconstructor */
255255
constructor(repo: Repo, path: Path) {
256256
super(repo, path, new QueryParams(), false);
@@ -298,7 +298,7 @@ export class DataSnapshot {
298298
/**
299299
* The location of this DataSnapshot.
300300
*/
301-
readonly ref: Reference,
301+
readonly ref: DatabaseReference,
302302
readonly _index: Index
303303
) {}
304304

@@ -477,7 +477,7 @@ export class DataSnapshot {
477477
* pointing to the provided path. Otherwise, a `Reference` pointing to the
478478
* root of the Database.
479479
*/
480-
export function ref(db: Database, path?: string): Reference {
480+
export function ref(db: Database, path?: string): DatabaseReference {
481481
db = getModularInstance(db);
482482
db._checkNotDeleted('ref');
483483
return path !== undefined ? child(db._root, path) : db._root;
@@ -499,7 +499,7 @@ export function ref(db: Database, path?: string): Reference {
499499
* @returns A `Reference` pointing to the provided
500500
* Firebase URL.
501501
*/
502-
export function refFromURL(db: Database, url: string): Reference {
502+
export function refFromURL(db: Database, url: string): DatabaseReference {
503503
db = getModularInstance(db);
504504
db._checkNotDeleted('refFromURL');
505505
const parsedURL = parseRepoInfo(url, db._repo.repoInfo_.nodeAdmin);
@@ -535,7 +535,10 @@ export function refFromURL(db: Database, url: string): Reference {
535535
* location.
536536
* @returns The specified child location.
537537
*/
538-
export function child(parent: Reference, path: string): Reference {
538+
export function child(
539+
parent: DatabaseReference,
540+
path: string
541+
): DatabaseReference {
539542
parent = getModularInstance(parent);
540543
if (pathGetFront(parent._path) === null) {
541544
validateRootPathString('child', 'path', path, false);
@@ -552,7 +555,7 @@ export function child(parent: Reference, path: string): Reference {
552555
*
553556
* @param ref - The reference to add OnDisconnect triggers for.
554557
*/
555-
export function onDisconnect(ref: Reference): OnDisconnect {
558+
export function onDisconnect(ref: DatabaseReference): OnDisconnect {
556559
ref = getModularInstance(ref) as ReferenceImpl;
557560
return new OnDisconnect(ref._repo, ref._path);
558561
}
@@ -584,7 +587,10 @@ export interface ThenableReferenceImpl
584587
* @returns Combined `Promise` and `Reference`; resolves when write is complete,
585588
* but can be used immediately as the `Reference` to the child location.
586589
*/
587-
export function push(parent: Reference, value?: unknown): ThenableReference {
590+
export function push(
591+
parent: DatabaseReference,
592+
value?: unknown
593+
): ThenableReference {
588594
parent = getModularInstance(parent);
589595
validateWritablePath('push', parent._path);
590596
validateFirebaseDataArg('push', value, parent._path, true);
@@ -629,7 +635,7 @@ export function push(parent: Reference, value?: unknown): ThenableReference {
629635
* @param ref - The location to remove.
630636
* @returns Resolves when remove on server is complete.
631637
*/
632-
export function remove(ref: Reference): Promise<void> {
638+
export function remove(ref: DatabaseReference): Promise<void> {
633639
validateWritablePath('remove', ref._path);
634640
return set(ref, null);
635641
}
@@ -663,7 +669,7 @@ export function remove(ref: Reference): Promise<void> {
663669
* array, or null).
664670
* @returns Resolves when write to server is complete.
665671
*/
666-
export function set(ref: Reference, value: unknown): Promise<void> {
672+
export function set(ref: DatabaseReference, value: unknown): Promise<void> {
667673
ref = getModularInstance(ref);
668674
validateWritablePath('set', ref._path);
669675
validateFirebaseDataArg('set', value, ref._path, false);
@@ -691,7 +697,7 @@ export function set(ref: Reference, value: unknown): Promise<void> {
691697
* @returns Resolves when write to server is complete.
692698
*/
693699
export function setPriority(
694-
ref: Reference,
700+
ref: DatabaseReference,
695701
priority: string | number | null
696702
): Promise<void> {
697703
ref = getModularInstance(ref);
@@ -724,7 +730,7 @@ export function setPriority(
724730
* @returns Resolves when write to server is complete.
725731
*/
726732
export function setWithPriority(
727-
ref: Reference,
733+
ref: DatabaseReference,
728734
value: unknown,
729735
priority: string | number | null
730736
): Promise<void> {
@@ -781,7 +787,7 @@ export function setWithPriority(
781787
* @param values - Object containing multiple values.
782788
* @returns Resolves when update on server is complete.
783789
*/
784-
export function update(ref: Reference, values: object): Promise<void> {
790+
export function update(ref: DatabaseReference, values: object): Promise<void> {
785791
validateFirebaseMergeDataArg('update', values, ref._path, false);
786792
const deferred = new Deferred<void>();
787793
repoUpdate(

packages/database/src/exp/Transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { PRIORITY_INDEX } from '../core/snap/indexes/PriorityIndex';
2222
import { Node } from '../core/snap/Node';
2323
import { validateWritablePath } from '../core/util/validation';
2424

25-
import { Reference } from './Reference';
25+
import { DatabaseReference } from './Reference';
2626
import { DataSnapshot, onValue, ReferenceImpl } from './Reference_impl';
2727

2828
/** An options object to configure transactions. */
@@ -92,7 +92,7 @@ export class TransactionResult {
9292
* callback to handle success and failure.
9393
*/
9494
export function runTransaction(
95-
ref: Reference,
95+
ref: DatabaseReference,
9696
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9797
transactionUpdate: (currentData: any) => unknown,
9898
options?: TransactionOptions

0 commit comments

Comments
 (0)