Skip to content

Commit

Permalink
Fixed issue where queryConstraint.type was undefined (#7973)
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht authored Jan 23, 2024
1 parent 9ea0e3b commit 046ac8a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-apes-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/database": patch
---

Fixed issue where queryConstraint.type was undefined
22 changes: 11 additions & 11 deletions packages/database/src/api/Reference_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ export abstract class QueryConstraint {
}

class QueryEndAtConstraint extends QueryConstraint {
readonly type: 'endAt';
readonly type = 'endAt';

constructor(
private readonly _value: number | string | boolean | null,
Expand Down Expand Up @@ -1748,7 +1748,7 @@ export function endAt(
}

class QueryEndBeforeConstraint extends QueryConstraint {
readonly type: 'endBefore';
readonly type = 'endBefore';

constructor(
private readonly _value: number | string | boolean | null,
Expand Down Expand Up @@ -1809,7 +1809,7 @@ export function endBefore(
}

class QueryStartAtConstraint extends QueryConstraint {
readonly type: 'startAt';
readonly type = 'startAt';

constructor(
private readonly _value: number | string | boolean | null,
Expand Down Expand Up @@ -1873,7 +1873,7 @@ export function startAt(
}

class QueryStartAfterConstraint extends QueryConstraint {
readonly type: 'startAfter';
readonly type = 'startAfter';

constructor(
private readonly _value: number | string | boolean | null,
Expand Down Expand Up @@ -1933,7 +1933,7 @@ export function startAfter(
}

class QueryLimitToFirstConstraint extends QueryConstraint {
readonly type: 'limitToFirst';
readonly type = 'limitToFirst';

constructor(private readonly _limit: number) {
super();
Expand Down Expand Up @@ -1981,7 +1981,7 @@ export function limitToFirst(limit: number): QueryConstraint {
}

class QueryLimitToLastConstraint extends QueryConstraint {
readonly type: 'limitToLast';
readonly type = 'limitToLast';

constructor(private readonly _limit: number) {
super();
Expand Down Expand Up @@ -2030,7 +2030,7 @@ export function limitToLast(limit: number): QueryConstraint {
}

class QueryOrderByChildConstraint extends QueryConstraint {
readonly type: 'orderByChild';
readonly type = 'orderByChild';

constructor(private readonly _path: string) {
super();
Expand Down Expand Up @@ -2093,7 +2093,7 @@ export function orderByChild(path: string): QueryConstraint {
}

class QueryOrderByKeyConstraint extends QueryConstraint {
readonly type: 'orderByKey';
readonly type = 'orderByKey';

_apply<T>(query: QueryImpl): QueryImpl {
validateNoPreviousOrderByCall(query, 'orderByKey');
Expand Down Expand Up @@ -2121,7 +2121,7 @@ export function orderByKey(): QueryConstraint {
}

class QueryOrderByPriorityConstraint extends QueryConstraint {
readonly type: 'orderByPriority';
readonly type = 'orderByPriority';

_apply<T>(query: QueryImpl): QueryImpl {
validateNoPreviousOrderByCall(query, 'orderByPriority');
Expand Down Expand Up @@ -2149,7 +2149,7 @@ export function orderByPriority(): QueryConstraint {
}

class QueryOrderByValueConstraint extends QueryConstraint {
readonly type: 'orderByValue';
readonly type = 'orderByValue';

_apply<T>(query: QueryImpl): QueryImpl {
validateNoPreviousOrderByCall(query, 'orderByValue');
Expand Down Expand Up @@ -2178,7 +2178,7 @@ export function orderByValue(): QueryConstraint {
}

class QueryEqualToValueConstraint extends QueryConstraint {
readonly type: 'equalTo';
readonly type = 'equalTo';

constructor(
private readonly _value: number | string | boolean | null,
Expand Down
60 changes: 60 additions & 0 deletions packages/database/test/queryconstraint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { expect } from 'chai';

import {
endAt,
endBefore,
equalTo,
limitToFirst,
limitToLast,
orderByChild,
orderByKey,
orderByPriority,
orderByValue,
startAfter,
startAt
} from '../src';

import { createTestApp } from './exp/integration.test';

describe('Query Constraints', () => {
let defaultApp;

beforeEach(() => {
defaultApp = createTestApp();
});
it('query constraint types are exposed', () => {
const queryConstraintTypes = [
{ qc: endAt(0), name: 'endAt' },
{ qc: endBefore(0), name: 'endBefore' },
{ qc: startAt(0), name: 'startAt' },
{ qc: startAfter(0), name: 'startAfter' },
{ qc: limitToFirst(1), name: 'limitToFirst' },
{ qc: limitToLast(1), name: 'limitToLast' },
{ qc: orderByChild('a'), name: 'orderByChild' },
{ qc: orderByKey(), name: 'orderByKey' },
{ qc: orderByPriority(), name: 'orderByPriority' },
{ qc: orderByValue(), name: 'orderByValue' },
{ qc: equalTo(''), name: 'equalTo' }
];
queryConstraintTypes.forEach(({ qc, name }) => {
expect(qc.type).to.equal(name);
});
});
});

0 comments on commit 046ac8a

Please sign in to comment.