@onehat/data 1.22.1 → 1.22.2
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/package.json +1 -1
- package/src/Repository/Ajax.js +25 -4
package/package.json
CHANGED
package/src/Repository/Ajax.js
CHANGED
|
@@ -216,18 +216,23 @@ class AjaxRepository extends Repository {
|
|
|
216
216
|
* @param {boolean} isBaseParam - Whether param is a base param (to be sent on every request).
|
|
217
217
|
*/
|
|
218
218
|
setParam(name, value, isBaseParam = false) {
|
|
219
|
-
const
|
|
219
|
+
const
|
|
220
|
+
re = /^([^\[]+)\[([^\]]+)\](.*)$/,
|
|
220
221
|
matches = name.match(re),
|
|
221
222
|
paramsToChange = isBaseParam ? this._baseParams : this._params;
|
|
222
223
|
|
|
223
224
|
if (matches) { // name has array notation like 'conditions[username]'
|
|
224
|
-
const
|
|
225
|
+
const
|
|
226
|
+
first = matches[1],
|
|
225
227
|
second = matches[2];
|
|
226
228
|
if (paramsToChange && !paramsToChange.hasOwnProperty(first)) {
|
|
227
229
|
paramsToChange[first] = {};
|
|
228
230
|
}
|
|
229
231
|
if (_.isNil(value) && paramsToChange[first] && paramsToChange[first].hasOwnProperty(second)) {
|
|
230
232
|
delete paramsToChange[first][second];
|
|
233
|
+
if (_.isEmpty(paramsToChange[first])) {
|
|
234
|
+
delete paramsToChange[first];
|
|
235
|
+
}
|
|
231
236
|
return;
|
|
232
237
|
}
|
|
233
238
|
paramsToChange[first][second] = value;
|
|
@@ -247,7 +252,8 @@ class AjaxRepository extends Repository {
|
|
|
247
252
|
* @param {boolean} isBaseParam - Whether param is a base param (to be sent on every request).
|
|
248
253
|
*/
|
|
249
254
|
setValuelessParam(name, isBaseParam = false) {
|
|
250
|
-
const
|
|
255
|
+
const
|
|
256
|
+
re = /^([^\[]+)\[([^\]]+)\](.*)$/,
|
|
251
257
|
matches = name.match(re),
|
|
252
258
|
paramsToChange = isBaseParam ? this._baseParams : this._params;
|
|
253
259
|
|
|
@@ -284,7 +290,22 @@ class AjaxRepository extends Repository {
|
|
|
284
290
|
* @param {string} name - Param name
|
|
285
291
|
*/
|
|
286
292
|
hasBaseParam(name) {
|
|
287
|
-
|
|
293
|
+
if (this._baseParams.hasOwnProperty(name)) {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Check for array notation
|
|
298
|
+
const keys = name.split(/[\[\].]+/).filter(Boolean);
|
|
299
|
+
let current = this._baseParams,
|
|
300
|
+
key;
|
|
301
|
+
|
|
302
|
+
for(key of keys) {
|
|
303
|
+
if (!current || !current.hasOwnProperty(key)) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
current = current[key];
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
288
309
|
}
|
|
289
310
|
|
|
290
311
|
/**
|