Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
toJSON(): unknown {
// Optional spacer argument is unnecessary because we're depending on recursion rather than stringifying the content
validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
return this.exportVal();
}
limitToFirst(limit: number): Query {
validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
if (
typeof limit !== 'number' ||
Math.floor(limit) !== limit ||
limit <= 0
) {
throw new Error(
'Query.limitToFirst: First argument must be a positive integer.'
);
}
if (this.queryParams_.hasLimit()) {
throw new Error(
'Query.limitToFirst: Limit was already set (by another call to limit, ' +
'limitToFirst, or limitToLast).'
);
}
setWithPriority(
value: unknown,
priority: number | string | null,
onComplete?: (a: Error | null) => void
): Promise {
validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
validateWritablePath('OnDisconnect.setWithPriority', this.path_);
validateFirebaseDataArg(
'OnDisconnect.setWithPriority',
1,
value,
this.path_,
false
);
validatePriority('OnDisconnect.setWithPriority', 2, priority, false);
validateCallback('OnDisconnect.setWithPriority', 3, onComplete, true);
const deferred = new Deferred();
this.repo_.onDisconnectSetWithPriority(
this.path_,
value,
priority,
goOnline() {
validateArgCount('database.goOnline', 0, 0, arguments.length);
this.checkDeleted_('goOnline');
this.repo_.resume();
}
}
child(pathString: string | Path): Reference {
validateArgCount('Reference.child', 1, 1, arguments.length);
if (typeof pathString === 'number') {
pathString = String(pathString);
} else if (!(pathString instanceof Path)) {
if (this.path.getFront() === null) {
validateRootPathString('Reference.child', 1, pathString, false);
} else {
validatePathString('Reference.child', 1, pathString, false);
}
}
return new Reference(this.repo, this.path.child(pathString));
}
isEqual(other: Query): boolean {
validateArgCount('Query.isEqual', 1, 1, arguments.length);
if (!(other instanceof Query)) {
const error =
'Query.isEqual failed: First argument must be an instance of firebase.database.Query.';
throw new Error(error);
}
const sameRepo = this.repo === other.repo;
const samePath = this.path.equals(other.path);
const sameQueryIdentifier =
this.queryIdentifier() === other.queryIdentifier();
return sameRepo && samePath && sameQueryIdentifier;
}
getParent(): Reference | null {
validateArgCount('Reference.parent', 0, 0, arguments.length);
const parentPath = this.path.parent();
return parentPath === null ? null : new Reference(this.repo, parentPath);
}
equalTo(value: number | string | boolean | null, name?: string) {
validateArgCount('Query.equalTo', 1, 2, arguments.length);
validateFirebaseDataArg('Query.equalTo', 1, value, this.path, false);
validateKey('Query.equalTo', 2, name, true);
if (this.queryParams_.hasStart()) {
throw new Error(
'Query.equalTo: Starting point was already set (by another call to startAt or ' +
'equalTo).'
);
}
if (this.queryParams_.hasEnd()) {
throw new Error(
'Query.equalTo: Ending point was already set (by another call to endAt or ' +
'equalTo).'
);
}
return this.startAt(value, name).endAt(value, name);
}
orderByKey(): Query {
validateArgCount('Query.orderByKey', 0, 0, arguments.length);
this.validateNoPreviousOrderByCall_('Query.orderByKey');
const newParams = this.queryParams_.orderBy(KEY_INDEX);
Query.validateQueryEndpoints_(newParams);
return new Query(this.repo, this.path, newParams, /*orderByCalled=*/ true);
}
off(
eventType?: string,
callback?: SnapshotCallback,
context?: Object | null
): void {
validateArgCount('Query.off', 0, 3, arguments.length);
validateEventType('Query.off', 1, eventType || '', true);
validateCallback('Query.off', 2, callback, true);
validateContextObject('Query.off', 3, context, true);
let container: EventRegistration | null = null;
let callbacks: { [k: string]: typeof callback } | null = null;
if (eventType === 'value') {
const valueCallback = callback || null;
container = new ValueEventRegistration(
valueCallback,
null,
context || null
);
} else if (eventType) {
if (callback) {
callbacks = {};