-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathevent-source-filter.ts
More file actions
82 lines (73 loc) · 1.59 KB
/
event-source-filter.ts
File metadata and controls
82 lines (73 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Filter rules for Lambda event filtering
*/
export class FilterRule {
/**
* Null comparison operator
*/
public static null(): string[] {
return [];
}
/**
* Empty comparison operator
*/
public static empty(): string[] {
return [''];
}
/**
* Equals comparison operator
*/
public static isEqual(item: string | number): any {
if (typeof item === 'number') {
return [{ numeric: ['=', item] }];
}
return [item];
}
/**
* Or comparison operator
*/
public static or(...elem: string[]): string[] {
return elem;
}
/**
* Not equals comparison operator
*/
public static notEquals(elem: string): {[key:string]: string[]}[] {
return [{ 'anything-but': [elem] }];
}
/**
* Numeric range comparison operator
*/
public static between(first: number, second: number): {[key:string]: any[]}[] {
return [{ numeric: ['>', first, '<=', second] }];
}
/**
* Exists comparison operator
*/
public static exists(): {[key:string]: boolean}[] {
return [{ exists: true }];
}
/**
* Not exists comparison operator
*/
public static notExists(): {[key:string]: boolean}[] {
return [{ exists: false }];
}
/**
* Begins with comparison operator
*/
public static beginsWith(elem: string): {[key:string]: string}[] {
return [{ prefix: elem }];
}
}
/**
* Filter criteria for Lambda event filtering
*/
export class FilterCriteria {
/**
* Filter for event source
*/
public static filter(filter: {[key:string]: any}): {[key:string]: any} {
return { pattern: JSON.stringify(filter) };
}
}