Skip to content

Commit

Permalink
fix: some code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultRuby authored and MarioArnt committed Nov 8, 2023
1 parent c39109e commit 27f8c47
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default abstract class Condition<T> {
});
}

protected combine(condition: Condition<T>, logicalOperator: 'AND' | 'OR'): Condition<T> {
protected combine(condition: Condition<T>, logicalOperator: 'AND' | 'OR'): this {
this.prepareExpression(condition);
this.expression = `${this.expression} ${logicalOperator} (${condition.expression})`;
return this;
Expand Down
4 changes: 2 additions & 2 deletions src/filter-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type IFilterConditionOperators =
| 'BEGINS_WITH';

export class FilterCondition extends Condition<FilterValue> {
public and(condition: FilterCondition): FilterCondition {
public and(condition: FilterCondition): this {
super.and(condition);
return this;
}
Expand All @@ -30,7 +30,7 @@ export class FilterCondition extends Condition<FilterValue> {
return this.combine(condition, 'OR') as FilterCondition;
}

public not(): FilterCondition {
public not(): this {
this.expression = `NOT (${this.expression})`;
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/key-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Condition from './conditions';
export type IKeyConditionsOperators = 'EQ' | 'LE' | 'LT' | 'GE' | 'GT' | 'BEGINS_WITH' | 'BETWEEN';

export class KeyCondition extends Condition<KeyValue> {
public and(condition: KeyCondition): KeyCondition {
public and(condition: KeyCondition): this {
super.and(condition);
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default abstract class Operation<T> {

projection(
fields: Array<string | { list: string; index: number } | { map: string; key: string }>,
): Operation<T> {
): this {
this.doProject(fields);
return this;
}
Expand Down
14 changes: 7 additions & 7 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Query<T> extends Operation<T> {
* and() and key operators method helpers
* eq(), le(), lt(), ge(), gt() and beginsWith()
*/
public keys(keyConditions: IKeyConditions | KeyCondition): Query<T> {
public keys(keyConditions: IKeyConditions | KeyCondition): this {
let builtConditions: IBuiltConditions;
if (isFluid(keyConditions)) {
builtConditions = keyConditions.build();
Expand All @@ -54,27 +54,27 @@ export default class Query<T> extends Operation<T> {
* Performs query using a specified index
* @param name: the name of the index to use
*/
public index(name: string): Query<T> {
public index(name: string): this {
this.params.IndexName = name;
return this;
}

public limit(limit: number): Query<T> {
public limit(limit: number): this {
this.doLimit(limit);
return this;
}

public consistent(isConsistent?: boolean): Query<T> {
public consistent(isConsistent?: boolean): this {
this.doConsistent(isConsistent);
return this;
}

public filter(filterConditions: IFilterConditions | FilterCondition): Query<T> {
public filter(filterConditions: IFilterConditions | FilterCondition): this {
this.doFilter(filterConditions);
return this;
}

public paginate(options: IPaginationOptions): Query<T> {
public paginate(options: IPaginationOptions): this {
this.doPaginate(options);
return this;
}
Expand All @@ -84,7 +84,7 @@ export default class Query<T> extends Operation<T> {
* Query is always sort on the table/index range key.
* @param direction 'asc' or 'desc'
*/
public sort(direction: 'asc' | 'desc'): Query<T> {
public sort(direction: 'asc' | 'desc'): this {
// According to documentation ScanIndexForward must be true if ascending
// @link https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
this.params.ScanIndexForward = direction === 'asc';
Expand Down
8 changes: 4 additions & 4 deletions src/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ export default class Scan<T> extends Operation<T> {
this.params = params;
}

public limit(limit: number): Scan<T> {
public limit(limit: number): this {
this.doLimit(limit);
return this;
}

public consistent(isConsistent?: boolean): Scan<T> {
public consistent(isConsistent?: boolean): this {
this.doConsistent(isConsistent);
return this;
}

public filter(filterConditions: IFilterConditions | FilterCondition): Scan<T> {
public filter(filterConditions: IFilterConditions | FilterCondition): this {
this.doFilter(filterConditions);
return this;
}

public paginate(options: IPaginationOptions): Scan<T> {
public paginate(options: IPaginationOptions): this {
this.doPaginate(options);
return this;
}
Expand Down

0 comments on commit 27f8c47

Please sign in to comment.