|
| 1 | +const _ = require('lodash'); |
| 2 | + |
1 | 3 | const add = (key, value) => obj => {
|
2 | 4 | if (value === undefined || value === '' || (Array.isArray(value) && value.length === 0)) {
|
3 | 5 | return obj;
|
@@ -61,73 +63,65 @@ const filterDeactivated = items => {
|
61 | 63 | });
|
62 | 64 | };
|
63 | 65 |
|
64 |
| -const getIncludedPath = |
65 |
| - _ => |
66 |
| - (includedPaths = []) => { |
67 |
| - return filterDeactivated(includedPaths) |
68 |
| - .map(item => { |
69 |
| - return _.flow(add('path', getPath(item.indexIncludedPath)))({}); |
70 |
| - }) |
71 |
| - .filter(item => !_.isEmpty(item)); |
72 |
| - }; |
| 66 | +const getIncludedPath = (includedPaths = []) => { |
| 67 | + return filterDeactivated(includedPaths) |
| 68 | + .map(item => { |
| 69 | + return _.flow(add('path', getPath(item.indexIncludedPath)))({}); |
| 70 | + }) |
| 71 | + .filter(item => !_.isEmpty(item)); |
| 72 | +}; |
73 | 73 |
|
74 |
| -const getExcludedPath = |
75 |
| - _ => |
76 |
| - (excludedPaths = []) => { |
77 |
| - return filterDeactivated(excludedPaths) |
78 |
| - .map(item => { |
79 |
| - return _.flow(add('path', getPath(item.indexExcludedPath)))({}); |
80 |
| - }) |
81 |
| - .filter(item => !_.isEmpty(item)); |
82 |
| - }; |
| 74 | +const getExcludedPath = (excludedPaths = []) => { |
| 75 | + return filterDeactivated(excludedPaths) |
| 76 | + .map(item => { |
| 77 | + return _.flow(add('path', getPath(item.indexExcludedPath)))({}); |
| 78 | + }) |
| 79 | + .filter(item => !_.isEmpty(item)); |
| 80 | +}; |
83 | 81 |
|
84 |
| -const getCompositeIndexes = |
85 |
| - _ => |
86 |
| - (compositeIndexes = []) => { |
87 |
| - return filterDeactivated(compositeIndexes) |
88 |
| - .map(item => { |
89 |
| - if (!Array.isArray(item.compositeFieldPath)) { |
90 |
| - return; |
91 |
| - } |
92 |
| - |
93 |
| - return _.uniqWith( |
94 |
| - item.compositeFieldPath.map(item => { |
95 |
| - const path = item.name.split('/'); |
96 |
| - |
97 |
| - return { |
98 |
| - path: ['', ...path.slice(1).map(prepareName)].join('/'), |
99 |
| - order: item.type || 'ascending', |
100 |
| - }; |
101 |
| - }), |
102 |
| - (a, b) => a.path === b.path, |
103 |
| - ).filter(item => !_.isEmpty(item)); |
104 |
| - }) |
105 |
| - .filter(item => !_.isEmpty(item)); |
106 |
| - }; |
| 82 | +const getCompositeIndexes = (compositeIndexes = []) => { |
| 83 | + return filterDeactivated(compositeIndexes) |
| 84 | + .map(item => { |
| 85 | + if (!Array.isArray(item.compositeFieldPath)) { |
| 86 | + return; |
| 87 | + } |
107 | 88 |
|
108 |
| -const getSpatialIndexes = |
109 |
| - _ => |
110 |
| - (spatialIndexes = []) => { |
111 |
| - return filterDeactivated(spatialIndexes) |
112 |
| - .map(item => { |
113 |
| - return _.flow( |
114 |
| - add('path', getPath(item.indexIncludedPath)), |
115 |
| - add('types', (item.dataTypes || []).map(dataType => dataType.spatialType).filter(Boolean)), |
116 |
| - )({}); |
117 |
| - }) |
118 |
| - .filter(item => !_.isEmpty(item) && item.path); |
119 |
| - }; |
| 89 | + return _.uniqWith( |
| 90 | + item.compositeFieldPath.map(item => { |
| 91 | + const path = item.name.split('/'); |
| 92 | + |
| 93 | + return { |
| 94 | + path: ['', ...path.slice(1).map(prepareName)].join('/'), |
| 95 | + order: item.type || 'ascending', |
| 96 | + }; |
| 97 | + }), |
| 98 | + (a, b) => a.path === b.path, |
| 99 | + ).filter(item => !_.isEmpty(item)); |
| 100 | + }) |
| 101 | + .filter(item => !_.isEmpty(item)); |
| 102 | +}; |
| 103 | + |
| 104 | +const getSpatialIndexes = (spatialIndexes = []) => { |
| 105 | + return filterDeactivated(spatialIndexes) |
| 106 | + .map(item => { |
| 107 | + return _.flow( |
| 108 | + add('path', getPath(item.indexIncludedPath)), |
| 109 | + add('types', (item.dataTypes || []).map(dataType => dataType.spatialType).filter(Boolean)), |
| 110 | + )({}); |
| 111 | + }) |
| 112 | + .filter(item => !_.isEmpty(item) && item.path); |
| 113 | +}; |
120 | 114 |
|
121 |
| -const getIndexPolicyScript = _ => containerData => { |
| 115 | +const getIndexPolicyScript = containerData => { |
122 | 116 | const indexTab = containerData[1] || {};
|
123 | 117 |
|
124 | 118 | return _.flow(
|
125 | 119 | add('automatic', indexTab.indexingAutomatic === 'true'),
|
126 | 120 | add('indexingMode', indexTab.indexingMode),
|
127 |
| - add('includedPaths', getIncludedPath(_)(indexTab.includedPaths)), |
128 |
| - add('excludedPaths', getExcludedPath(_)(indexTab.excludedPaths)), |
129 |
| - add('spatialIndexes', getSpatialIndexes(_)(indexTab.spatialIndexes)), |
130 |
| - add('compositeIndexes', getCompositeIndexes(_)(indexTab.compositeIndexes)), |
| 121 | + add('includedPaths', getIncludedPath(indexTab.includedPaths)), |
| 122 | + add('excludedPaths', getExcludedPath(indexTab.excludedPaths)), |
| 123 | + add('spatialIndexes', getSpatialIndexes(indexTab.spatialIndexes)), |
| 124 | + add('compositeIndexes', getCompositeIndexes(indexTab.compositeIndexes)), |
131 | 125 | )({});
|
132 | 126 | };
|
133 | 127 |
|
|
0 commit comments