UNPKG

3.79 kBTypeScriptView Raw
1declare const OR: unique symbol;
2import { DynamoDB } from "aws-sdk";
3import { ObjectType } from "./General";
4export declare type ConditionFunction = (condition: Condition) => Condition;
5declare type ConditionStorageType = {
6 [key: string]: ConditionsConditionStorageObject;
7} | typeof OR;
8export declare type ConditionStorageTypeNested = ConditionStorageType | Array<ConditionStorageTypeNested>;
9declare type ConditionStorageSettingsConditions = ConditionStorageTypeNested[];
10declare type ConditionRequestObjectResult = {
11 ExpressionAttributeNames?: DynamoDB.Types.ExpressionAttributeNameMap;
12 ExpressionAttributeValues?: DynamoDB.Types.ExpressionAttributeValueMap;
13};
14interface ConditionComparisonType {
15 name: ConditionComparisonComparatorName;
16 typeName: ConditionComparisonComparatorDynamoName;
17 not?: ConditionComparisonComparatorDynamoName;
18 multipleArguments?: boolean;
19}
20declare enum ConditionComparisonComparatorName {
21 equals = "eq",
22 lessThan = "lt",
23 lessThanEquals = "le",
24 greaterThan = "gt",
25 greaterThanEquals = "ge",
26 beginsWith = "beginsWith",
27 contains = "contains",
28 exists = "exists",
29 in = "in",
30 between = "between"
31}
32declare enum ConditionComparisonComparatorDynamoName {
33 equals = "EQ",
34 notEquals = "NE",
35 lessThan = "LT",
36 lessThanEquals = "LE",
37 greaterThan = "GT",
38 greaterThanEquals = "GE",
39 beginsWith = "BEGINS_WITH",
40 contains = "CONTAINS",
41 notContains = "NOT_CONTAINS",
42 exists = "EXISTS",
43 notExists = "NOT_EXISTS",
44 in = "IN",
45 between = "BETWEEN"
46}
47export declare type ConditionInitalizer = Condition | ObjectType | string;
48export interface BasicOperators<T = Condition> {
49 and: () => T;
50 or: () => T;
51 not: () => T;
52 parenthesis: (value: Condition | ConditionFunction) => T;
53 group: (value: Condition | ConditionFunction) => T;
54 where: (key: string) => T;
55 filter: (key: string) => T;
56 attribute: (key: string) => T;
57 eq: (value: any) => T;
58 lt: (value: any) => T;
59 le: (value: any) => T;
60 gt: (value: any) => T;
61 ge: (value: any) => T;
62 beginsWith: (value: any) => T;
63 contains: (value: any) => T;
64 exists: () => T;
65 in: (value: any) => T;
66 between: (...values: any[]) => T;
67}
68export interface Condition extends BasicOperators {
69 settings: {
70 conditions: ConditionStorageSettingsConditions;
71 pending: {
72 key?: string;
73 type?: ConditionComparisonType;
74 value?: any;
75 not?: boolean;
76 };
77 raw?: ConditionInitalizer;
78 };
79 and: () => Condition;
80 or: () => Condition;
81 not: () => Condition;
82 parenthesis: (value: Condition | ConditionFunction) => Condition;
83 group: (value: Condition | ConditionFunction) => Condition;
84 where: (key: string) => Condition;
85 filter: (key: string) => Condition;
86 attribute: (key: string) => Condition;
87 eq: (value: any) => Condition;
88 lt: (value: any) => Condition;
89 le: (value: any) => Condition;
90 gt: (value: any) => Condition;
91 ge: (value: any) => Condition;
92 beginsWith: (value: any) => Condition;
93 contains: (value: any) => Condition;
94 exists: () => Condition;
95 in: (value: any) => Condition;
96 between: (...values: any[]) => Condition;
97 requestObject: (settings?: ConditionRequestObjectSettings) => ConditionRequestObjectResult;
98}
99export declare class Condition {
100 constructor(object?: ConditionInitalizer);
101}
102interface ConditionsConditionStorageObject {
103 type: ConditionComparisonComparatorDynamoName;
104 value: any;
105}
106interface ConditionRequestObjectSettings {
107 conditionString: string;
108 index?: {
109 start: number;
110 set: (newIndex: number) => void;
111 };
112 conditionStringType: "array" | "string";
113}
114export {};