diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..e55370c --- /dev/null +++ b/index.d.ts @@ -0,0 +1,73 @@ +export type Operator = + | "eq" + | "and" + | "or" + | "gt" + | "ge" + | "lt" + | "le" + | "like" + | "is null" + | "ne"; + +export namespace Operators { + const EQUALS = "eq"; + const AND = "and"; + const OR = "or"; + const GREATER_THAN = "gt"; + const GREATER_THAN_EQUAL = "ge"; + const LESS_THAN = "lt"; + const LESS_THAN_EQUAL = "le"; + const LIKE = "like"; + const IS_NULL = "is null"; + const NOT_EQUAL = "ne"; + + /** + * Whether a defined operation is unary or binary. Will return true + * if the operation only supports a subject with no value. + * + * @param op the operation to check. + * @return whether the operation is an unary operation. + */ + export function isUnary(op: Operator): boolean; + + /** + * Whether a defined operation is a logical operators or not. + * + * @param op the operation to check. + * @return whether the operation is a logical operation. + */ + export function isLogical(op: Operator): boolean; +} + +export interface PredicateConfig { + subject: string | Predicate; + value?: string | number | Predicate; + operator: Operator; +} + +/** + * Predicate is the basic model construct of the odata expression + */ +export class Predicate { + subject: string | Predicate; + value?: string | number | Predicate; + operator: Operator; + + static concat(operator: Operator, p: Predicate): Predicate; + + constructor(config?: PredicateConfig); + + flatten(result?: Predicate[]): Predicate[]; + + /** + * Will serialie the predicate to an ODATA compliant serialized string. + * + * @return The compliant ODATA query string + */ + serialize(): string; +} + +export namespace Parser { + export function parse(filterStr?: string): null | Predicate; +} diff --git a/package.json b/package.json index 25e0753..1b9f767 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.5.4", "description": "Library for parsing and building OData filter strings", "main": "index.js", + "types": "index.d.ts", "scripts": { "test": "gulp test" }, @@ -45,4 +46,4 @@ "jest-createspyobj": "^2.0.0", "jest-junit": "^15.0.0" } -} +} \ No newline at end of file