@outliant/sunrise-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc +53 -0
  3. package/.github/workflows/pr-dev-workflow.yml +16 -0
  4. package/.nvmrc +1 -0
  5. package/.release-it.js +26 -0
  6. package/.vscode/launch.json +24 -0
  7. package/.vscode/settings.json +7 -0
  8. package/CHANGELOG.md +12 -0
  9. package/README.md +19 -0
  10. package/changelog.hbs +13 -0
  11. package/helpers/es.js +6 -0
  12. package/helpers/projectFilter/projectFieldFilter.js +587 -0
  13. package/helpers/searchFilter.js +86 -0
  14. package/helpers/taskFilter/criticalPathFilter.js +144 -0
  15. package/helpers/taskFilter/index.js +228 -0
  16. package/helpers/taskFilter/onHoldFilter.js +101 -0
  17. package/helpers/taskFilter/ownerFilter.js +148 -0
  18. package/helpers/taskFilter/pathAgeFilter.js +18 -0
  19. package/helpers/taskFilter/regionFilter.js +82 -0
  20. package/helpers/taskFilter/statusFilter.js +177 -0
  21. package/helpers/taskFilter/taskFieldFilter.js +309 -0
  22. package/helpers/taskSortScript.js +356 -0
  23. package/index.d.ts +11 -0
  24. package/index.js +9 -0
  25. package/lib/fieldConditions.js +166 -0
  26. package/lib/logger.js +48 -0
  27. package/lib/taskPipeline.js +137 -0
  28. package/package.json +73 -0
  29. package/test/helpers/projectFilter/projectFieldFilter.spec.js +881 -0
  30. package/test/helpers/taskFilter/criticalPathFilter.spec.js +174 -0
  31. package/test/helpers/taskFilter/index.spec.js +339 -0
  32. package/test/helpers/taskFilter/onHoldFilter.spec.js +112 -0
  33. package/test/helpers/taskFilter/ownerFilter.spec.js +226 -0
  34. package/test/helpers/taskFilter/pathAgeFilter.spec.js +47 -0
  35. package/test/helpers/taskFilter/regionFilter.spec.js +131 -0
  36. package/test/helpers/taskFilter/statusFilter.spec.js +197 -0
  37. package/test/helpers/taskFilter/taskFieldFilter.spec.js +355 -0
  38. package/test/lib/fieldConditions.spec.js +17 -0
  39. package/test/lib/logger.spec.js +117 -0
  40. package/test/lib/taskPipeline.spec.js +162 -0
@@ -0,0 +1,226 @@
1
+ 'use strict';
2
+
3
+ /* eslint-env node, mocha */
4
+ const { expect } = require('chai');
5
+
6
+ // To test
7
+ const ownerFilter = require('../../../helpers/taskFilter/ownerFilter');
8
+
9
+ describe('taskFilter/ownerFilter', function () {
10
+ const filters = [
11
+ {
12
+ input: {
13
+ condition: 'is_equal',
14
+ field_id: '',
15
+ type: 'owner',
16
+ field_type: 'select',
17
+ value: '7744bfdb-b798-400f-9d82-b157722afd8b',
18
+ second_value: ''
19
+ },
20
+ output: {
21
+ bool: {
22
+ must: [
23
+ {
24
+ term: {
25
+ user_id: { value: '7744bfdb-b798-400f-9d82-b157722afd8b' }
26
+ }
27
+ }
28
+ ]
29
+ }
30
+ }
31
+ },
32
+ {
33
+ input: {
34
+ condition: 'not_equal',
35
+ field_id: '',
36
+ type: 'owner',
37
+ field_type: 'select',
38
+ value: '7744bfdb-b798-400f-9d82-b157722afd8b',
39
+ second_value: ''
40
+ },
41
+ output: {
42
+ bool: {
43
+ must_not: {
44
+ bool: {
45
+ must: [
46
+ {
47
+ term: {
48
+ user_id: { value: '7744bfdb-b798-400f-9d82-b157722afd8b' }
49
+ }
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ }
55
+ }
56
+ },
57
+ {
58
+ input: {
59
+ condition: 'is_empty',
60
+ field_id: '',
61
+ type: 'owner',
62
+ field_type: 'select',
63
+ value: '',
64
+ second_value: ''
65
+ },
66
+ output: {
67
+ bool: {
68
+ should: [
69
+ {
70
+ bool: {
71
+ must: [{ term: { user_id: '' } }, { term: { team_id: '' } }]
72
+ }
73
+ },
74
+ {
75
+ bool: {
76
+ must_not: [
77
+ { exists: { field: 'user_id' } },
78
+ { exists: { field: 'team_id' } }
79
+ ]
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ }
85
+ },
86
+ {
87
+ input: {
88
+ condition: 'is_not_empty',
89
+ field_id: '',
90
+ type: 'owner',
91
+ field_type: 'select',
92
+ value: '',
93
+ second_value: ''
94
+ },
95
+ output: {
96
+ bool: {
97
+ must_not: {
98
+ bool: {
99
+ should: [
100
+ {
101
+ bool: {
102
+ must: [{ term: { user_id: '' } }, { term: { team_id: '' } }]
103
+ }
104
+ },
105
+ {
106
+ bool: {
107
+ must_not: [
108
+ { exists: { field: 'user_id' } },
109
+ { exists: { field: 'team_id' } }
110
+ ]
111
+ }
112
+ }
113
+ ]
114
+ }
115
+ }
116
+ }
117
+ }
118
+ },
119
+ {
120
+ input: {
121
+ condition: 'is_any_of',
122
+ field_id: '',
123
+ type: 'owner',
124
+ field_type: 'select',
125
+ value:
126
+ '7ffe331f-64e3-4e27-923d-36a61246e2c3;61eb8a86-4467-4188-adef-5fd06575afdf',
127
+ second_value: ''
128
+ },
129
+ output: {
130
+ bool: {
131
+ should: [
132
+ {
133
+ term: {
134
+ user_id: { value: '7ffe331f-64e3-4e27-923d-36a61246e2c3' }
135
+ }
136
+ },
137
+ {
138
+ term: {
139
+ user_id: { value: '61eb8a86-4467-4188-adef-5fd06575afdf' }
140
+ }
141
+ }
142
+ ]
143
+ }
144
+ }
145
+ },
146
+ {
147
+ input: {
148
+ condition: 'is_any_of',
149
+ field_id: '',
150
+ type: 'owner',
151
+ field_type: 'select',
152
+ value: [
153
+ '7ffe331f-64e3-4e27-923d-36a61246e2c3',
154
+ '61eb8a86-4467-4188-adef-5fd06575afdf'
155
+ ],
156
+ second_value: ''
157
+ },
158
+ output: {
159
+ bool: {
160
+ should: [
161
+ {
162
+ term: {
163
+ user_id: { value: '7ffe331f-64e3-4e27-923d-36a61246e2c3' }
164
+ }
165
+ },
166
+ {
167
+ term: {
168
+ user_id: { value: '61eb8a86-4467-4188-adef-5fd06575afdf' }
169
+ }
170
+ }
171
+ ]
172
+ }
173
+ }
174
+ },
175
+ {
176
+ input: {
177
+ condition: 'unknown_condition',
178
+ field_id: '',
179
+ type: 'owner',
180
+ field_type: 'select',
181
+ value: '',
182
+ second_value: ''
183
+ },
184
+ output: null
185
+ },
186
+ {
187
+ input: {
188
+ condition: 'is_any_of',
189
+ field_id: '',
190
+ type: 'owner',
191
+ field_type: 'select',
192
+ value: 'LlrJx3gBfTAqAzzhrb2J',
193
+ second_value: ''
194
+ },
195
+ output: {
196
+ bool: {
197
+ should: [{ term: { team_id: { value: 'LlrJx3gBfTAqAzzhrb2J' } } }]
198
+ }
199
+ }
200
+ },
201
+ {
202
+ input: {
203
+ condition: 'is_equal',
204
+ field_id: '',
205
+ type: 'owner',
206
+ field_type: 'select',
207
+ value: 'LlrJx3gBfTAqAzzhrb2J',
208
+ second_value: ''
209
+ },
210
+ output: {
211
+ bool: {
212
+ must: [{ term: { team_id: { value: 'LlrJx3gBfTAqAzzhrb2J' } } }]
213
+ }
214
+ }
215
+ }
216
+ ];
217
+
218
+ filters.forEach((filter) => {
219
+ it(`${filter.input.condition}: ${JSON.stringify(
220
+ filter.input.value
221
+ )}`, (done) => {
222
+ expect(ownerFilter(filter.input)).to.deep.equal(filter.output);
223
+ done();
224
+ });
225
+ });
226
+ });
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ /* eslint-env node, mocha */
4
+ const { expect } = require('chai');
5
+
6
+ // To test
7
+ const pathAgeFilter = require('../../../helpers/taskFilter/pathAgeFilter');
8
+
9
+ describe('taskFilter/pathAgeFilter', function () {
10
+ const filters = [
11
+ {
12
+ input: {
13
+ condition: 'is_equal',
14
+ field_id: '',
15
+ field_type: 'select',
16
+ type: 'path_age',
17
+ value: 'b3fd91b3-ecc9-41ae-b770-912a34e02e70'
18
+ },
19
+ output: {
20
+ term: {
21
+ 'critical_path.color_id': {
22
+ value: 'b3fd91b3-ecc9-41ae-b770-912a34e02e70'
23
+ }
24
+ }
25
+ }
26
+ },
27
+ {
28
+ input: {
29
+ condition: 'unknown_condition',
30
+ field_id: '',
31
+ field_type: 'select',
32
+ type: 'path_age',
33
+ value: 'b3fd91b3-ecc9-41ae-b770-912a34e02e70'
34
+ },
35
+ output: null
36
+ }
37
+ ];
38
+
39
+ filters.forEach((filter) => {
40
+ it(`${filter.input.condition}: ${JSON.stringify(
41
+ filter.input.value
42
+ )}`, (done) => {
43
+ expect(pathAgeFilter(filter.input)).to.deep.equal(filter.output);
44
+ done();
45
+ });
46
+ });
47
+ });
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ /* eslint-env node, mocha */
4
+ const { expect } = require('chai');
5
+
6
+ // To test
7
+ const regionFilter = require('../../../helpers/taskFilter/regionFilter');
8
+
9
+ describe('taskFilter/regionFilter', function () {
10
+ const filters = [
11
+ {
12
+ input: {
13
+ condition: 'is_equal',
14
+ field_id: '',
15
+ type: 'region',
16
+ field_type: 'checkbox',
17
+ value: [
18
+ '0PbPSnUBiH_7DigZLwM_',
19
+ '1fbPSnUBiH_7DigZTgMZ',
20
+ '0fbPSnUBiH_7DigZNQOZ'
21
+ ],
22
+ second_value: ''
23
+ },
24
+ output: {
25
+ bool: {
26
+ should: [
27
+ { term: { region_id: { value: '0PbPSnUBiH_7DigZLwM_' } } },
28
+ { term: { region_id: { value: '1fbPSnUBiH_7DigZTgMZ' } } },
29
+ { term: { region_id: { value: '0fbPSnUBiH_7DigZNQOZ' } } }
30
+ ]
31
+ }
32
+ }
33
+ },
34
+ {
35
+ input: {
36
+ condition: 'is_equal',
37
+ field_id: '',
38
+ type: 'region',
39
+ field_type: 'checkbox',
40
+ value: '0PbPSnUBiH_7DigZLwM_;1fbPSnUBiH_7DigZTgMZ',
41
+ second_value: ''
42
+ },
43
+ output: {
44
+ bool: {
45
+ should: [
46
+ { term: { region_id: { value: '0PbPSnUBiH_7DigZLwM_' } } },
47
+ { term: { region_id: { value: '1fbPSnUBiH_7DigZTgMZ' } } }
48
+ ]
49
+ }
50
+ }
51
+ },
52
+ {
53
+ input: {
54
+ condition: 'is_equal',
55
+ field_id: '',
56
+ type: 'region',
57
+ field_type: 'checkbox',
58
+ value: 'is_empty',
59
+ second_value: ''
60
+ },
61
+ output: {
62
+ bool: {
63
+ should: [{ bool: { must_not: [{ exists: { field: 'region_id' } }] } }]
64
+ }
65
+ }
66
+ },
67
+ {
68
+ input: {
69
+ condition: 'not_equal',
70
+ field_id: '',
71
+ type: 'region',
72
+ field_type: 'checkbox',
73
+ value: ['1PbPSnUBiH_7DigZSAN3'],
74
+ second_value: ''
75
+ },
76
+ output: {
77
+ bool: {
78
+ must_not: {
79
+ bool: {
80
+ should: [
81
+ { term: { region_id: { value: '1PbPSnUBiH_7DigZSAN3' } } }
82
+ ]
83
+ }
84
+ }
85
+ }
86
+ }
87
+ },
88
+ {
89
+ input: {
90
+ condition: 'is_empty',
91
+ field_id: '',
92
+ type: 'region',
93
+ field_type: 'checkbox',
94
+ value: '',
95
+ second_value: ''
96
+ },
97
+ output: { bool: { must_not: [{ exists: { field: 'region_id' } }] } }
98
+ },
99
+ {
100
+ input: {
101
+ condition: 'is_not_empty',
102
+ field_id: '',
103
+ type: 'region',
104
+ field_type: 'checkbox',
105
+ value: '',
106
+ second_value: ''
107
+ },
108
+ output: { bool: { must: [{ exists: { field: 'region_id' } }] } }
109
+ },
110
+ {
111
+ input: {
112
+ condition: 'unknown_condition',
113
+ field_id: '',
114
+ type: 'region',
115
+ field_type: 'checkbox',
116
+ value: '',
117
+ second_value: ''
118
+ },
119
+ output: null
120
+ }
121
+ ];
122
+
123
+ filters.forEach((filter) => {
124
+ it(`${filter.input.condition}: ${JSON.stringify(
125
+ filter.input.value
126
+ )}`, (done) => {
127
+ expect(regionFilter(filter.input)).to.deep.equal(filter.output);
128
+ done();
129
+ });
130
+ });
131
+ });
@@ -0,0 +1,197 @@
1
+ 'use strict';
2
+
3
+ /* eslint-env node, mocha */
4
+ const { expect } = require('chai');
5
+ const sinon = require('sinon');
6
+
7
+ // To test
8
+ const statusFilter = require('../../../helpers/taskFilter/statusFilter');
9
+
10
+ describe('taskFilter/statusFilter', function () {
11
+ let sandbox;
12
+
13
+ beforeEach(() => {
14
+ sandbox = sinon.createSandbox();
15
+ sandbox.stub(Date, 'now').returns(111111111);
16
+ });
17
+
18
+ afterEach(() => {
19
+ sandbox.restore();
20
+ });
21
+
22
+ const filters = [
23
+ {
24
+ input: {
25
+ condition: 'is_equal',
26
+ field_id: '',
27
+ type: 'status',
28
+ field_type: 'select',
29
+ value: 'pending',
30
+ second_value: ''
31
+ },
32
+ output: {
33
+ bool: {
34
+ must: [{ term: { is_ready: true } }, { term: { is_complete: false } }]
35
+ }
36
+ }
37
+ },
38
+ {
39
+ input: {
40
+ condition: 'is_equal',
41
+ field_id: '',
42
+ type: 'status',
43
+ field_type: 'select',
44
+ value: 'overdue',
45
+ second_value: ''
46
+ },
47
+ output: {
48
+ bool: {
49
+ must: [
50
+ { term: { is_complete: false } },
51
+ { exists: { field: 'due_date' } },
52
+ { range: { due_date: { lte: 111111111 } } }
53
+ ]
54
+ }
55
+ }
56
+ },
57
+ {
58
+ input: {
59
+ condition: 'is_equal',
60
+ field_id: '',
61
+ type: 'status',
62
+ field_type: 'select',
63
+ value: 'unkown',
64
+ second_value: ''
65
+ },
66
+ output: null
67
+ },
68
+ {
69
+ input: {
70
+ condition: 'not_equal',
71
+ field_id: '',
72
+ type: 'status',
73
+ field_type: 'select',
74
+ value: 'completed',
75
+ second_value: ''
76
+ },
77
+ output: {
78
+ bool: {
79
+ must_not: { bool: { must: [{ term: { is_complete: true } }] } }
80
+ }
81
+ }
82
+ },
83
+ {
84
+ input: {
85
+ condition: 'is_empty',
86
+ field_id: '',
87
+ type: 'status',
88
+ field_type: 'select',
89
+ value: '',
90
+ second_value: ''
91
+ },
92
+ output: {
93
+ bool: {
94
+ must_not: [
95
+ { exists: { field: 'is_complete' } },
96
+ { exists: { field: 'is_ready' } },
97
+ { exists: { field: 'on_hold' } }
98
+ ]
99
+ }
100
+ }
101
+ },
102
+ {
103
+ input: {
104
+ condition: 'is_not_empty',
105
+ field_id: '',
106
+ type: 'status',
107
+ field_type: 'select',
108
+ value: '',
109
+ second_value: ''
110
+ },
111
+ output: {
112
+ bool: {
113
+ must_not: {
114
+ bool: {
115
+ must_not: [
116
+ { exists: { field: 'is_complete' } },
117
+ { exists: { field: 'is_ready' } },
118
+ { exists: { field: 'on_hold' } }
119
+ ]
120
+ }
121
+ }
122
+ }
123
+ }
124
+ },
125
+ {
126
+ input: {
127
+ condition: 'is_any_of',
128
+ field_id: '',
129
+ type: 'status',
130
+ field_type: 'select',
131
+ value: 'new;on_hold',
132
+ second_value: ''
133
+ },
134
+ output: {
135
+ bool: {
136
+ should: [
137
+ {
138
+ bool: {
139
+ must: [
140
+ { term: { is_ready: false } },
141
+ { term: { is_complete: false } }
142
+ ]
143
+ }
144
+ },
145
+ { bool: { must: [{ term: { on_hold: true } }] } }
146
+ ]
147
+ }
148
+ }
149
+ },
150
+ {
151
+ input: {
152
+ condition: 'is_any_of',
153
+ field_id: '',
154
+ type: 'status',
155
+ field_type: 'select',
156
+ value: ['new', 'on_hold'],
157
+ second_value: ''
158
+ },
159
+ output: {
160
+ bool: {
161
+ should: [
162
+ {
163
+ bool: {
164
+ must: [
165
+ { term: { is_ready: false } },
166
+ { term: { is_complete: false } }
167
+ ]
168
+ }
169
+ },
170
+ { bool: { must: [{ term: { on_hold: true } }] } }
171
+ ]
172
+ }
173
+ }
174
+ },
175
+ {
176
+ input: {
177
+ condition: 'unknown_condition',
178
+ field_id: '',
179
+ type: 'status',
180
+ field_type: 'select',
181
+ value: 'new;on_hold',
182
+ second_value: ''
183
+ },
184
+ output: null
185
+ }
186
+ ];
187
+
188
+ filters.forEach((filter) => {
189
+ it(`${filter.input.condition}: ${JSON.stringify(
190
+ filter.input.value
191
+ )}`, (done) => {
192
+ expect(statusFilter(filter.input)).to.deep.equal(filter.output);
193
+
194
+ done();
195
+ });
196
+ });
197
+ });