forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
53 lines (43 loc) · 1.63 KB
/
utils.js
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
const _ = require('lodash');
exports.getEntries = ({ partitionKey, rowKey, condition }, entries) => {
entries = [...entries.values()];
entries = _.sortBy(entries, e => [e.partition_key_out, e.row_key_out]);
if (!partitionKey && !rowKey && !condition) {
return entries;
}
return entries.filter(entry => {
let flag = false;
if (entry.partition_key_out === partitionKey && entry.row_key_out === rowKey) {
flag = true;
}
if (entry.partition_key_out === partitionKey && !rowKey) {
flag = true;
}
if (entry.row_key_out === rowKey && !partitionKey) {
flag = true;
}
if (!rowKey && !partitionKey) {
flag = true;
}
if (condition) {
const cond = condition.replace('value ->>', '').trim();
const operator = cond.match(/(=|>|<|>=|<=|<>)/)[1];
const date = condition.match(/(\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}Z)/)[1];
const property = condition.match(/'([a-zA-Z]+)'/)[1];
if (operator === "=" && entry.value[property] !== date) {
return false;
} else if (operator === ">" && new Date(entry.value[property]) <= new Date(date)) {
return false;
} else if (operator === "<" && new Date(entry.value[property]) >= new Date(date)) {
return false;
} else if (operator === ">=" && new Date(entry.value[property]) < new Date(date)) {
return false;
} else if (operator === "<=" && new Date(entry.value[property]) > new Date(date)) {
return false;
} else if (operator === "<>" && new Date(entry.value[property]) === new Date(date)) {
return false;
}
}
return flag;
});
};