Skip to content

Commit

Permalink
Merge 2b557d6 into d2d7d8a
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed Jun 20, 2020
2 parents d2d7d8a + 2b557d6 commit c93311a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
23 changes: 22 additions & 1 deletion lib/Condition.ts
Expand Up @@ -62,7 +62,28 @@ const types: ConditionComparisonType[] = [
];
export type ConditionInitalizer = Condition | ObjectType | string;

export class Condition {
export interface BasicOperators<T = Condition> {
and: () => T;
or: () => T;
not: () => T;
parenthesis: (value: T | ConditionFunction) => T;
group: (value: T | ConditionFunction) => T;
where: (key: string) => T;
filter: (key: string) => T;
attribute: (key: string) => T;
eq: (value: any) => T;
lt: (value: number) => T;
le: (value: number) => T;
gt: (value: number) => T;
ge: (value: number) => T;
beginsWith: (value: any) => T;
contains: (value: any) => T;
exists: (value: any) => T;
in: (value: any) => T;
between: (...values: any[]) => T;
}

export class Condition implements BasicOperators {
settings: {
// TODO: fix this below, it should be a reference to `OR` not Symbol, you are only allowed to pass in OR here, not any other Symbol.
conditions: ConditionStorageSettingsConditions;
Expand Down
32 changes: 4 additions & 28 deletions lib/DocumentRetriever.ts
@@ -1,7 +1,7 @@
import ddb = require("./aws/ddb/internal");
import CustomError = require("./Error");
import utils = require("./utils");
import {Condition, ConditionInitalizer, ConditionFunction} from "./Condition";
import {Condition, ConditionInitalizer, BasicOperators} from "./Condition";
import {Model} from "./Model";
import {Document} from "./Document";
import {CallbackType, ObjectType, DocumentArray, SortOrder} from "./General";
Expand All @@ -16,7 +16,10 @@ interface DocumentRetrieverTypeInformation {
type: DocumentRetrieverTypes;
pastTense: string;
}

// DocumentRetriever is used for both Scan and Query since a lot of the code is shared between the two
// type DocumentRetriever = BasicOperators;
interface DocumentRetriever extends BasicOperators {} // eslint-disable-line @typescript-eslint/no-empty-interface
abstract class DocumentRetriever {
internalSettings?: {
model: Model<Document>;
Expand Down Expand Up @@ -116,33 +119,6 @@ abstract class DocumentRetriever {
}
}



// TODO: this was all copied from Condition.ts, we need to figure out a better way to handle this --------------------------------------------------
and: () => Condition;
or: () => Condition;
not: () => Condition;
parenthesis: (value: Condition | ConditionFunction) => Condition;
group: (value: Condition | ConditionFunction) => Condition;
where: (key: string) => Condition;
filter: (key: string) => Condition;
attribute: (key: string) => Condition;
eq: (value: any) => Condition;
lt: (value: number) => Condition;
le: (value: number) => Condition;
gt: (value: number) => Condition;
ge: (value: number) => Condition;
beginsWith: (value: any) => Condition;
contains: (value: any) => Condition;
exists: (value: any) => Condition;
in: (value: any) => Condition;
between: (...values: any[]) => Condition;
// -------------------------------------------------------------------------------------------------------------------------------------------------





constructor (model: Model<Document>, typeInformation: DocumentRetrieverTypeInformation, object?: ConditionInitalizer) {
this.internalSettings = {model, typeInformation};

Expand Down

0 comments on commit c93311a

Please sign in to comment.