@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.22.1",
3
+ "version": "1.22.2",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -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 re = /^([^\[]+)\[([^\]]+)\](.*)$/,
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 first = matches[1],
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 re = /^([^\[]+)\[([^\]]+)\](.*)$/,
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
- return this._baseParams.hasOwnProperty(name);
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
  /**