@yuneta/gobj-js 7.26.0 → 7.26.1

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.
@@ -898,10 +898,13 @@
898
898
  break;
899
899
  case data_type_t.DTP_JSON:
900
900
  jn_value2 = jn_value_;
901
- if (is_string(jn_value_)) try {
902
- jn_value2 = JSON.parse(jn_value_);
903
- } catch (error) {
904
- jn_value2 = jn_value_;
901
+ if (is_string(jn_value_)) {
902
+ const t = jn_value_.trim();
903
+ if (t.startsWith("{") || t.startsWith("[")) try {
904
+ jn_value2 = JSON.parse(t);
905
+ } catch (error) {
906
+ jn_value2 = jn_value_;
907
+ }
905
908
  }
906
909
  break;
907
910
  case data_type_t.DTP_POINTER: jn_value2 = jn_value_;
@@ -2602,7 +2605,7 @@
2602
2605
  } catch (e) {
2603
2606
  __inside__--;
2604
2607
  if (!(e && e.__gobj_logged__)) {
2605
- log_error(`${gobj_short_name(dst)}: action of ${event} in ${dst.current_state.state_name} THREW: ${e && e.stack ? e.stack : e}`);
2608
+ log_error(`${gobj_short_name(dst)}: action of ${event} in ${state.state_name} THREW: ${e && e.stack ? e.stack : e}`);
2606
2609
  try {
2607
2610
  e.__gobj_logged__ = true;
2608
2611
  } catch (e2) {}
@@ -3610,7 +3613,7 @@
3610
3613
  if ((is_secret_name(key.slice(-128)) || value_is_secret && key === "value") && value !== void 0 && value !== null && value !== "") shown = "********";
3611
3614
  else shown = _json_mask_secrets(value, memo, depth + 1, budget);
3612
3615
  if (shown !== value) changed = true;
3613
- result[key] = shown;
3616
+ set_own_key(result, key, shown);
3614
3617
  }
3615
3618
  if (truncated) result["<more>"] = MASK_TOO_LARGE;
3616
3619
  }
@@ -3682,7 +3685,7 @@
3682
3685
  ************************************************************/
3683
3686
  function json_object_update(destination, source) {
3684
3687
  if (!source) return destination;
3685
- for (let property of Object.keys(source)) destination[property] = source[property];
3688
+ for (let property of Object.keys(source)) set_own_key(destination, property, source[property]);
3686
3689
  return destination;
3687
3690
  }
3688
3691
  /************************************************************
@@ -3691,7 +3694,7 @@
3691
3694
  ************************************************************/
3692
3695
  function json_object_update_existing(destination, source) {
3693
3696
  if (!source) return destination;
3694
- for (let property in source) if (source.hasOwnProperty(property) && destination.hasOwnProperty(property)) destination[property] = source[property];
3697
+ for (let property in source) if (Object.prototype.hasOwnProperty.call(source, property) && Object.prototype.hasOwnProperty.call(destination, property)) set_own_key(destination, property, source[property]);
3695
3698
  return destination;
3696
3699
  }
3697
3700
  /************************************************************
@@ -3700,32 +3703,32 @@
3700
3703
  ************************************************************/
3701
3704
  function json_object_update_missing(destination, source) {
3702
3705
  if (!source) return destination;
3703
- for (let property in source) if (source.hasOwnProperty(property) && !destination.hasOwnProperty(property)) destination[property] = source[property];
3706
+ for (let property in source) if (Object.prototype.hasOwnProperty.call(source, property) && !Object.prototype.hasOwnProperty.call(destination, property)) set_own_key(destination, property, source[property]);
3704
3707
  return destination;
3705
3708
  }
3706
3709
  /************************************************************
3707
3710
  * Simulate jansson function
3708
3711
  ************************************************************/
3709
3712
  function json_object_get(o, key) {
3710
- if (o && o.hasOwnProperty(key)) return o[key];
3713
+ if (o && Object.prototype.hasOwnProperty.call(o, key)) return o[key];
3711
3714
  }
3712
3715
  /************************************************************
3713
3716
  * Simulate jansson function
3714
3717
  ************************************************************/
3715
3718
  function json_object_del(o, k) {
3716
- if (o && o.hasOwnProperty(k)) delete o[k];
3719
+ if (o && Object.prototype.hasOwnProperty.call(o, k)) delete o[k];
3717
3720
  }
3718
3721
  /************************************************************
3719
3722
  * Simulate jansson function
3720
3723
  ************************************************************/
3721
3724
  function json_object_set(o, k, v) {
3722
- o[k] = v;
3725
+ set_own_key(o, k, v);
3723
3726
  }
3724
3727
  /************************************************************
3725
3728
  * Simulate jansson function
3726
3729
  ************************************************************/
3727
3730
  function json_object_set_new(o, k, v) {
3728
- o[k] = v;
3731
+ set_own_key(o, k, v);
3729
3732
  }
3730
3733
  /************************************************************
3731
3734
  * Simulate jansson function
@@ -3969,22 +3972,20 @@
3969
3972
  ************************************************************/
3970
3973
  function kw_has_key(kw, key) {
3971
3974
  if (key in kw) {
3972
- if (kw.hasOwnProperty(key)) return true;
3975
+ if (Object.prototype.hasOwnProperty.call(kw, key)) return true;
3973
3976
  }
3974
3977
  return false;
3975
3978
  }
3976
3979
  /************************************************************
3977
3980
  * A key that reaches the prototype chain instead of the data:
3978
- * "__proto__", "constructor" or "prototype" when the object
3979
- * does not hold it as its OWN key. A walk through one of them
3981
+ * any key the object does not hold as its OWN key. A walk through one of them
3980
3982
  * read, or WROTE, Object.prototype: the flat id
3981
3983
  * "__proto__`polluted" set a key on every object of the page.
3982
3984
  * In C they are keys like any other, so here too: read them
3983
3985
  * only as own keys, and write "__proto__" as an own key.
3984
3986
  ************************************************************/
3985
3987
  function is_prototype_segment(obj, key) {
3986
- if (key === "__proto__" || key === "constructor" || key === "prototype") return !Object.prototype.hasOwnProperty.call(obj, key);
3987
- return false;
3988
+ return !Object.prototype.hasOwnProperty.call(obj, key);
3988
3989
  }
3989
3990
  function set_own_key(obj, key, value) {
3990
3991
  if (key === "__proto__") Object.defineProperty(obj, key, {
@@ -4567,14 +4568,14 @@
4567
4568
  let kw_clone = {};
4568
4569
  if (is_string(keys) && !empty_string(keys)) {
4569
4570
  let key = keys;
4570
- if (kw.hasOwnProperty(key)) kw_clone[key] = kw[key];
4571
+ if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
4571
4572
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4572
4573
  } else if (is_object(keys) && json_object_size(keys) > 0) {
4573
- for (let key of Object.keys(keys)) if (kw.hasOwnProperty(key)) kw_clone[key] = kw[key];
4574
+ for (let key of Object.keys(keys)) if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
4574
4575
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4575
4576
  } else if (is_array(keys) && json_array_size(keys) > 0) for (let j = 0; j < keys.length; j++) {
4576
4577
  let key = keys[j];
4577
- if (kw.hasOwnProperty(key)) kw_clone[key] = kw[key];
4578
+ if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
4578
4579
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4579
4580
  }
4580
4581
  else return kw;
@@ -4596,14 +4597,14 @@
4596
4597
  json_object_update(kw_clone, kw);
4597
4598
  if (is_string(keys) && !empty_string(keys)) {
4598
4599
  let key = keys;
4599
- if (kw.hasOwnProperty(key)) json_object_del(kw_clone, key);
4600
+ if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
4600
4601
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4601
4602
  } else if (is_object(keys) && json_object_size(keys) > 0) {
4602
- for (let key of Object.keys(keys)) if (kw.hasOwnProperty(key)) json_object_del(kw_clone, key);
4603
+ for (let key of Object.keys(keys)) if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
4603
4604
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4604
4605
  } else if (is_array(keys) && json_array_size(keys) > 0) for (let j = 0; j < keys.length; j++) {
4605
4606
  let key = keys[j];
4606
- if (kw.hasOwnProperty(key)) json_object_del(kw_clone, key);
4607
+ if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
4607
4608
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4608
4609
  }
4609
4610
  else return {};
@@ -4834,7 +4835,7 @@
4834
4835
  let new_ids = [];
4835
4836
  if (is_string(ids)) new_ids.push(ids);
4836
4837
  else if (is_object(ids)) {
4837
- for (let id in ids) if (ids.hasOwnProperty(id)) new_ids.push(id);
4838
+ for (let id in ids) if (Object.prototype.hasOwnProperty.call(ids, id)) new_ids.push(id);
4838
4839
  } else if (is_array(ids)) ids.forEach(function(item) {
4839
4840
  if (is_string(item)) {
4840
4841
  if (!empty_string(item)) new_ids.push(item);
@@ -5087,7 +5088,7 @@
5087
5088
  function _traverse_dict(obj, callback, full_path) {
5088
5089
  if (full_path === void 0 || !is_string(full_path)) full_path = "";
5089
5090
  for (let key of Object.keys(obj)) {
5090
- if (!obj.hasOwnProperty(key)) continue;
5091
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
5091
5092
  let sufix = (full_path.length ? "`" : "") + key;
5092
5093
  full_path += sufix;
5093
5094
  callback.apply(this, [
@@ -5968,7 +5969,7 @@
5968
5969
  return;
5969
5970
  }
5970
5971
  if (depth === 0) return;
5971
- flat[path] = value;
5972
+ set_own_key(flat, path, value);
5972
5973
  };
5973
5974
  if (jn === void 0 || jn === null) return flat;
5974
5975
  walk(jn, "", 0);
@@ -6070,11 +6071,11 @@
6070
6071
  if (flat === null || typeof flat !== "object" || Array.isArray(flat)) throw new Error("flat_apply: a flat json is an object of id -> value");
6071
6072
  if (diff === null || typeof diff !== "object") throw new Error("flat_apply: a diff is the object flat_diff() answers");
6072
6073
  for (const key of Object.keys(diff.removed || {})) delete flat[key];
6073
- for (const key of Object.keys(diff.added || {})) flat[key] = diff.added[key];
6074
+ for (const key of Object.keys(diff.added || {})) set_own_key(flat, key, diff.added[key]);
6074
6075
  for (const key of Object.keys(diff.changed || {})) {
6075
6076
  const change = diff.changed[key];
6076
6077
  if (!change || !Object.prototype.hasOwnProperty.call(change, "to")) throw new Error(`flat_apply: changed '${key}' without a 'to'`);
6077
- flat[key] = change.to;
6078
+ set_own_key(flat, key, change.to);
6078
6079
  }
6079
6080
  return flat;
6080
6081
  }
@@ -7216,6 +7217,7 @@
7216
7217
  if (gobj.priv.websocket) log_error(`Websocket ALREADY setup`);
7217
7218
  const url = gobj_read_str_attr(gobj, "url");
7218
7219
  log_debug(`====> Starting WebSocket to '${url}' (${gobj_short_name(gobj)})`);
7220
+ const ws_seq = ++gobj.priv.ws_seq;
7219
7221
  let websocket;
7220
7222
  try {
7221
7223
  websocket = new WebSocket(url);
@@ -7227,7 +7229,6 @@
7227
7229
  log_error(`${gobj_short_name(gobj)}: Failed to initialize WebSocket.`);
7228
7230
  return null;
7229
7231
  }
7230
- const ws_seq = ++gobj.priv.ws_seq;
7231
7232
  websocket.onopen = () => {
7232
7233
  if (ws_seq !== gobj.priv.ws_seq || gobj_is_destroying(gobj)) return;
7233
7234
  gobj_send_event(gobj, "EV_ON_OPEN", {