@yuneta/gobj-js 7.26.3 → 7.26.5

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.
@@ -4007,6 +4007,12 @@
4007
4007
  * called gobj_short_name() on a null gobj ("gobj bad type"), and a
4008
4008
  * null middle segment threw a TypeError.
4009
4009
  ************************************************************/
4010
+ function list_segment_index(list, seg) {
4011
+ if (!/^[0-9]+$/.test(seg)) return -1;
4012
+ const idx = Number(seg);
4013
+ if (idx >= list.length) return -1;
4014
+ return idx;
4015
+ }
4010
4016
  function kw_find_path(gobj, kw, path, verbose) {
4011
4017
  if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
4012
4018
  const prefix = gobj ? `${gobj_short_name(gobj)}: ` : "";
@@ -4022,11 +4028,12 @@
4022
4028
  let len = ss.length;
4023
4029
  for (let i = 0; i < len; i++) {
4024
4030
  if (is_array(kw)) {
4025
- if (!/^[0-9]+$/.test(ss[i])) {
4031
+ const idx = list_segment_index(kw, ss[i]);
4032
+ if (idx < 0) {
4026
4033
  if (verbose) log_error(`${prefix}path not found: '${path}'`);
4027
4034
  return;
4028
4035
  }
4029
- ss[i] = String(Number(ss[i]));
4036
+ ss[i] = String(idx);
4030
4037
  }
4031
4038
  if (is_prototype_segment(kw, ss[i])) {
4032
4039
  if (verbose) log_error(`${prefix}path not found: '${path}'`);
@@ -4061,8 +4068,14 @@
4061
4068
  function kw_delete(gobj, kw, path) {
4062
4069
  if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
4063
4070
  let [path_, k] = strrchr_split(path, "`");
4064
- if (!empty_string(k)) json_object_del(kw_find_path(gobj, kw, path_, true), k);
4065
- else json_object_del(kw, path);
4071
+ if (!empty_string(k)) {
4072
+ let v = kw_find_path(gobj, kw, path_, true);
4073
+ if (is_array(v)) {
4074
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_delete(): cannot delete an item of a list: '${path}'`);
4075
+ return -1;
4076
+ }
4077
+ json_object_del(v, k);
4078
+ } else json_object_del(kw, path);
4066
4079
  return 0;
4067
4080
  }
4068
4081
  /************************************************************
@@ -4418,6 +4431,14 @@
4418
4431
  let len = ss.length;
4419
4432
  for (let i = 0; i < len; i++) {
4420
4433
  let key = ss[i];
4434
+ if (is_array(kw)) {
4435
+ const idx = list_segment_index(kw, key);
4436
+ if (idx < 0) {
4437
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): segment '${key}' is not an index of its list: '${path}'`);
4438
+ return -1;
4439
+ }
4440
+ key = String(idx);
4441
+ }
4421
4442
  if (i === len - 1) set_own_key(kw, key, value);
4422
4443
  else {
4423
4444
  let seg = is_prototype_segment(kw, key) ? void 0 : kw[key];
@@ -6582,7 +6603,7 @@
6582
6603
  let default_value;
6583
6604
  if (is_object(col)) default_value = col.default;
6584
6605
  let value = kw_get_dict_value(null, kw, field, default_value);
6585
- new_record[field] = value;
6606
+ json_object_set(new_record, field, value);
6586
6607
  });
6587
6608
  return new_record;
6588
6609
  }
@@ -7304,13 +7325,13 @@
7304
7325
  websocket = new WebSocket(url);
7305
7326
  } catch (e) {
7306
7327
  log_error(`${gobj_short_name(gobj)}: Cannot open WebSocket to '${url}', Error: ${e.message}`);
7307
- gobj_post_event(gobj, "EV_ON_CLOSE", {
7328
+ if (gobj_post_event(gobj, "EV_ON_CLOSE", {
7308
7329
  url,
7309
7330
  ws_seq,
7310
7331
  code: 1006,
7311
7332
  reason: e.message,
7312
7333
  was_clean: false
7313
- }, gobj);
7334
+ }, gobj) < 0) set_timeout(gobj.priv.gobj_timer, next_retry(gobj));
7314
7335
  return null;
7315
7336
  }
7316
7337
  if (!websocket) {