Skip to content

Commit 95050c0

Browse files
fix(database): improve type definitions (#8373)
* fix(database): improve type definitions plus adds tests for new functions * fix(database): API not-implemented notes, unused var fixes, conflict resolution * style(database): `yarn lint` fixes --------- Co-authored-by: Mike Hardy <github@mikehardy.net>
1 parent c29ac3c commit 95050c0

File tree

5 files changed

+45
-66
lines changed

5 files changed

+45
-66
lines changed

packages/database/__tests__/database.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import database, {
1717
getServerTime,
1818
serverTimestamp,
1919
increment,
20+
enableLogging,
2021
endAt,
2122
endBefore,
2223
startAt,
@@ -38,6 +39,7 @@ import database, {
3839
setPriority,
3940
setWithPriority,
4041
get,
42+
off,
4143
child,
4244
onDisconnect,
4345
keepSynced,
@@ -165,6 +167,10 @@ describe('Database', function () {
165167
expect(increment).toBeDefined();
166168
});
167169

170+
it('`enableLogging` function is properly exposed to end user', function () {
171+
expect(enableLogging).toBeDefined();
172+
});
173+
168174
it('`endAt` function is properly exposed to end user', function () {
169175
expect(endAt).toBeDefined();
170176
});
@@ -245,6 +251,10 @@ describe('Database', function () {
245251
expect(setWithPriority).toBeDefined();
246252
});
247253

254+
it('`off` function is properly exposed to end user', function () {
255+
expect(off).toBeDefined();
256+
});
257+
248258
it('`get` function is properly exposed to end user', function () {
249259
expect(get).toBeDefined();
250260
});

packages/database/lib/modular/index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,5 +220,13 @@ export function getServerTime(db: Database): Promise<number>;
220220
*/
221221
export function increment(delta: number): object;
222222

223+
/**
224+
* Logs debugging information to the console. Not implemented on native.
225+
*
226+
* @param enabled
227+
* @param persistent
228+
*/
229+
export declare function enableLogging(enabled: boolean, persistent?: boolean): any;
230+
223231
export * from './query';
224232
export * from './transaction';

packages/database/lib/modular/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,9 @@ export function increment(delta) {
123123
return ServerValue.increment(delta);
124124
}
125125

126+
export function enableLogging(_enabled, _persistent) {
127+
throw new Error('enableLogging() is not implemented');
128+
}
129+
126130
export * from './query';
127131
export * from './transaction';

packages/database/lib/modular/query.d.ts

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,6 @@ export declare function equalTo(
124124
key?: string,
125125
): QueryConstraint;
126126

127-
/**
128-
* Creates a `QueryConstraint` that includes children that match the specified
129-
* value.
130-
*
131-
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
132-
* allows you to choose arbitrary starting and ending points for your queries.
133-
*
134-
* The optional key argument can be used to further limit the range of the
135-
* query. If it is specified, then children that have exactly the specified
136-
* value must also have exactly the specified key as their key name. This can be
137-
* used to filter result sets with many matches for the same value.
138-
*
139-
* @param value - The value to match for. The argument type depends on which
140-
* `orderBy*()` function was used in this query. Specify a value that matches
141-
* the `orderBy*()` type. When used in combination with `orderByKey()`, the
142-
* value must be a string.
143-
* @param key - The child key to start at, among the children with the
144-
* previously specified priority. This argument is only allowed if ordering by
145-
* child, value, or priority.
146-
*/
147-
export function equalTo(value: number | string | boolean | null, key?: string): QueryConstraint;
148-
149127
/**
150128
* Creates a QueryConstraint with the specified starting point.
151129
*
@@ -170,30 +148,6 @@ export declare function startAt(
170148
key?: string,
171149
): QueryConstraint;
172150

173-
/**
174-
* Creates a `QueryConstraint` with the specified starting point.
175-
*
176-
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
177-
* allows you to choose arbitrary starting and ending points for your queries.
178-
*
179-
* The starting point is inclusive, so children with exactly the specified value
180-
* will be included in the query. The optional key argument can be used to
181-
* further limit the range of the query. If it is specified, then children that
182-
* have exactly the specified value must also have a key name greater than or
183-
* equal to the specified key.
184-
*
185-
* @param value - The value to start at. The argument type depends on which
186-
* `orderBy*()` function was used in this query. Specify a value that matches
187-
* the `orderBy*()` type. When used in combination with `orderByKey()`, the
188-
* value must be a string.
189-
* @param key - The child key to start at. This argument is only allowed if
190-
* ordering by child, value, or priority.
191-
*/
192-
export function startAt(
193-
value: number | string | boolean | null = null,
194-
key?: string,
195-
): QueryConstraint;
196-
197151
/**
198152
* Creates a `QueryConstraint` with the specified starting point (exclusive).
199153
*
@@ -214,26 +168,6 @@ export function startAt(
214168
*/
215169
export function startAfter(value: number | string | boolean | null, key?: string): QueryConstraint;
216170

217-
/**
218-
* Creates a `QueryConstraint` with the specified starting point (exclusive).
219-
*
220-
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
221-
* allows you to choose arbitrary starting and ending points for your queries.
222-
*
223-
* The starting point is exclusive. If only a value is provided, children
224-
* with a value greater than the specified value will be included in the query.
225-
* If a key is specified, then children must have a value greater than or equal
226-
* to the specified value and a key name greater than the specified key.
227-
*
228-
* @param value - The value to start after. The argument type depends on which
229-
* `orderBy*()` function was used in this query. Specify a value that matches
230-
* the `orderBy*()` type. When used in combination with `orderByKey()`, the
231-
* value must be a string.
232-
* @param key - The child key to start after. This argument is only allowed if
233-
* ordering by child, value, or priority.
234-
*/
235-
export function startAfter(value: number | string | boolean | null, key?: string): QueryConstraint;
236-
237171
/**
238172
* Creates a new `QueryConstraint` that if limited to the first specific number
239173
* of children.
@@ -903,6 +837,25 @@ export function setWithPriority(
903837
*/
904838
export function get(query: Query): Promise<DataSnapshot>;
905839

840+
/**
841+
* Detaches a callback previously attached with the corresponding on*() (onValue, onChildAdded) listener.
842+
* Note: This is not the recommended way to remove a listener. Instead, please use the returned callback function from the respective on* callbacks.
843+
* Detach a callback previously attached with on*(). Calling off() on a parent listener will not automatically remove listeners registered on child nodes, off() must also be called on any child listeners to remove the callback.
844+
* If a callback is not specified, all callbacks for the specified eventType will be removed.
845+
* Similarly, if no eventType is specified, all callbacks for the Reference will be removed.
846+
* Individual listeners can also be removed by invoking their unsubscribe callbacks.
847+
* Note: Not implemented on native
848+
*
849+
* @param query - The query to run
850+
* @param eventType One of the following strings: "value", "child_added", "child_changed", "child_removed", or "child_moved.
851+
* @param callback
852+
*/
853+
export declare function off(
854+
query: Query,
855+
eventType?: EventType,
856+
callback?: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown,
857+
): void;
858+
906859
/**
907860
* Gets a `Reference` for the location at the specified relative path.
908861
*

packages/database/lib/modular/query.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ export function get(query) {
239239
return query.once('value');
240240
}
241241

242+
export function off(_query, _eventType, _callback) {
243+
throw new Error('off() is not implemented');
244+
}
245+
242246
/**
243247
* @param {DatabaseReference} parent
244248
* @param {string} path

0 commit comments

Comments
 (0)