Skip to content

Refactor QueryParams #4485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions packages/database/src/api/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ import {
} from '../core/view/EventRegistration';

import { Repo } from '../core/Repo';
import { QueryParams } from '../core/view/QueryParams';
import {
QueryParams,
queryParamsLimitToFirst,
queryParamsLimitToLast,
queryParamsStartAfter,
queryParamsStartAt,
queryParamsEndAt,
queryParamsEndBefore,
queryParamsGetQueryObject,
queryParamsOrderBy
} from '../core/view/QueryParams';
import { Reference } from './Reference';
import { DataSnapshot } from './DataSnapshot';

Expand Down Expand Up @@ -355,7 +365,7 @@ export class Query {
return new Query(
this.repo,
this.path,
this.queryParams_.limitToFirst(limit),
queryParamsLimitToFirst(this.queryParams_, limit),
this.orderByCalled_
);
}
Expand Down Expand Up @@ -384,7 +394,7 @@ export class Query {
return new Query(
this.repo,
this.path,
this.queryParams_.limitToLast(limit),
queryParamsLimitToLast(this.queryParams_, limit),
this.orderByCalled_
);
}
Expand Down Expand Up @@ -416,7 +426,7 @@ export class Query {
);
}
const index = new PathIndex(parsedPath);
const newParams = this.queryParams_.orderBy(index);
const newParams = queryParamsOrderBy(this.queryParams_, index);
Query.validateQueryEndpoints_(newParams);

return new Query(this.repo, this.path, newParams, /*orderByCalled=*/ true);
Expand All @@ -428,7 +438,7 @@ export class Query {
orderByKey(): Query {
validateArgCount('Query.orderByKey', 0, 0, arguments.length);
this.validateNoPreviousOrderByCall_('Query.orderByKey');
const newParams = this.queryParams_.orderBy(KEY_INDEX);
const newParams = queryParamsOrderBy(this.queryParams_, KEY_INDEX);
Query.validateQueryEndpoints_(newParams);
return new Query(this.repo, this.path, newParams, /*orderByCalled=*/ true);
}
Expand All @@ -439,7 +449,7 @@ export class Query {
orderByPriority(): Query {
validateArgCount('Query.orderByPriority', 0, 0, arguments.length);
this.validateNoPreviousOrderByCall_('Query.orderByPriority');
const newParams = this.queryParams_.orderBy(PRIORITY_INDEX);
const newParams = queryParamsOrderBy(this.queryParams_, PRIORITY_INDEX);
Query.validateQueryEndpoints_(newParams);
return new Query(this.repo, this.path, newParams, /*orderByCalled=*/ true);
}
Expand All @@ -450,7 +460,7 @@ export class Query {
orderByValue(): Query {
validateArgCount('Query.orderByValue', 0, 0, arguments.length);
this.validateNoPreviousOrderByCall_('Query.orderByValue');
const newParams = this.queryParams_.orderBy(VALUE_INDEX);
const newParams = queryParamsOrderBy(this.queryParams_, VALUE_INDEX);
Query.validateQueryEndpoints_(newParams);
return new Query(this.repo, this.path, newParams, /*orderByCalled=*/ true);
}
Expand All @@ -463,7 +473,7 @@ export class Query {
validateFirebaseDataArg('Query.startAt', 1, value, this.path, true);
validateKey('Query.startAt', 2, name, true);

const newParams = this.queryParams_.startAt(value, name);
const newParams = queryParamsStartAt(this.queryParams_, value, name);
Query.validateLimit_(newParams);
Query.validateQueryEndpoints_(newParams);
if (this.queryParams_.hasStart()) {
Expand All @@ -490,7 +500,7 @@ export class Query {
validateFirebaseDataArg('Query.startAfter', 1, value, this.path, false);
validateKey('Query.startAfter', 2, name, true);

const newParams = this.queryParams_.startAfter(value, name);
const newParams = queryParamsStartAfter(this.queryParams_, value, name);
Query.validateLimit_(newParams);
Query.validateQueryEndpoints_(newParams);
if (this.queryParams_.hasStart()) {
Expand All @@ -511,7 +521,7 @@ export class Query {
validateFirebaseDataArg('Query.endAt', 1, value, this.path, true);
validateKey('Query.endAt', 2, name, true);

const newParams = this.queryParams_.endAt(value, name);
const newParams = queryParamsEndAt(this.queryParams_, value, name);
Query.validateLimit_(newParams);
Query.validateQueryEndpoints_(newParams);
if (this.queryParams_.hasEnd()) {
Expand All @@ -532,7 +542,7 @@ export class Query {
validateFirebaseDataArg('Query.endBefore', 1, value, this.path, false);
validateKey('Query.endBefore', 2, name, true);

const newParams = this.queryParams_.endBefore(value, name);
const newParams = queryParamsEndBefore(this.queryParams_, value, name);
Query.validateLimit_(newParams);
Query.validateQueryEndpoints_(newParams);
if (this.queryParams_.hasEnd()) {
Expand Down Expand Up @@ -589,7 +599,7 @@ export class Query {
* An object representation of the query parameters used by this Query.
*/
queryObject(): object {
return this.queryParams_.getQueryObject();
return queryParamsGetQueryObject(this.queryParams_);
}

queryIdentifier(): string {
Expand Down
13 changes: 7 additions & 6 deletions packages/database/src/core/ReadonlyRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ServerActions } from './ServerActions';
import { RepoInfo } from './RepoInfo';
import { AuthTokenProvider } from './AuthTokenProvider';
import { Query } from '../api/Query';
import { queryParamsToRestQueryStringParameters } from './view/QueryParams';

/**
* An implementation of ServerActions that communicates with the server via REST requests.
Expand Down Expand Up @@ -94,9 +95,9 @@ export class ReadonlyRestClient extends ServerActions {
const thisListen = {};
this.listens_[listenId] = thisListen;

const queryStringParameters = query
.getQueryParams()
.toRestQueryStringParameters();
const queryStringParameters = queryParamsToRestQueryStringParameters(
query.getQueryParams()
);

this.restRequest_(
pathString + '.json',
Expand Down Expand Up @@ -136,9 +137,9 @@ export class ReadonlyRestClient extends ServerActions {
}

get(query: Query): Promise<string> {
const queryStringParameters = query
.getQueryParams()
.toRestQueryStringParameters();
const queryStringParameters = queryParamsToRestQueryStringParameters(
query.getQueryParams()
);

const pathString = query.path.toString();

Expand Down
Loading