mage-remote-run 1.0.0 → 1.2.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.
- package/lib/utils.js +49 -27
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -105,36 +105,58 @@ export function buildSearchCriteria(options) {
|
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
if (options.filter && options.filter.length > 0) {
|
|
108
|
-
for (const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
else
|
|
108
|
+
for (const group of options.filter) {
|
|
109
|
+
const orFilters = group.split(/\s*\|\|\s*/);
|
|
110
|
+
let addedAny = false;
|
|
111
|
+
let orIndex = 0;
|
|
112
|
+
|
|
113
|
+
for (const f of orFilters) {
|
|
114
|
+
let match = f.match(/^([\w\.]+)(?::([a-z!]+))?(?:(<=|>=|<|>|=|!=|!~|~|\?|!|@@)(.*))?$/);
|
|
115
|
+
if (match) {
|
|
116
|
+
const field = match[1];
|
|
117
|
+
const opString = match[2];
|
|
118
|
+
const shorthand = match[3];
|
|
119
|
+
let value = match[4] || '';
|
|
120
|
+
|
|
121
|
+
let condition = 'eq';
|
|
122
|
+
|
|
123
|
+
if (opString) {
|
|
124
|
+
condition = opString === '!in' ? 'nin' : opString;
|
|
125
|
+
} else if (shorthand) {
|
|
126
|
+
switch (shorthand) {
|
|
127
|
+
case '>': condition = 'gt'; break;
|
|
128
|
+
case '<': condition = 'lt'; break;
|
|
129
|
+
case '>=': condition = 'gteq'; break;
|
|
130
|
+
case '<=': condition = 'lteq'; break;
|
|
131
|
+
case '!=': condition = 'neq'; break;
|
|
132
|
+
case '~': condition = 'like'; break;
|
|
133
|
+
case '!~': condition = 'nlike'; break;
|
|
134
|
+
case '@@': condition = 'finset'; break;
|
|
135
|
+
case '?': condition = 'null'; value = '1'; break;
|
|
136
|
+
case '!': condition = 'notnull'; value = '1'; break;
|
|
137
|
+
default: condition = 'eq';
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
console.error(chalk.yellow(`Warning: Invalid filter format "${f}". Expected formats like "field=value", "field:like=value", etc.`));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if ((condition === 'like' || condition === 'nlike') && value.includes('*')) {
|
|
145
|
+
value = value.replaceAll('*', '%');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
params[`searchCriteria[filter_groups][${filterIndex}][filters][${orIndex}][field]`] = field;
|
|
149
|
+
params[`searchCriteria[filter_groups][${filterIndex}][filters][${orIndex}][value]`] = value;
|
|
150
|
+
params[`searchCriteria[filter_groups][${filterIndex}][filters][${orIndex}][condition_type]`] = condition;
|
|
151
|
+
|
|
152
|
+
orIndex++;
|
|
153
|
+
addedAny = true;
|
|
126
154
|
} else {
|
|
127
155
|
console.error(chalk.yellow(`Warning: Invalid filter format "${f}". Expected formats like "field=value", "field:like=value", etc.`));
|
|
128
|
-
continue;
|
|
129
156
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
addFilter(field, value, condition);
|
|
136
|
-
} else {
|
|
137
|
-
console.error(chalk.yellow(`Warning: Invalid filter format "${f}". Expected formats like "field=value", "field:like=value", etc.`));
|
|
157
|
+
}
|
|
158
|
+
if (addedAny) {
|
|
159
|
+
filterIndex++;
|
|
138
160
|
}
|
|
139
161
|
}
|
|
140
162
|
}
|