@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.
@@ -894,10 +894,13 @@ function json2item(gobj, sdata, it, jn_value_) {
894
894
  break;
895
895
  case data_type_t.DTP_JSON:
896
896
  jn_value2 = jn_value_;
897
- if (is_string(jn_value_)) try {
898
- jn_value2 = JSON.parse(jn_value_);
899
- } catch (error) {
900
- jn_value2 = jn_value_;
897
+ if (is_string(jn_value_)) {
898
+ const t = jn_value_.trim();
899
+ if (t.startsWith("{") || t.startsWith("[")) try {
900
+ jn_value2 = JSON.parse(t);
901
+ } catch (error) {
902
+ jn_value2 = jn_value_;
903
+ }
901
904
  }
902
905
  break;
903
906
  case data_type_t.DTP_POINTER: jn_value2 = jn_value_;
@@ -2598,7 +2601,7 @@ function gobj_send_event(dst, event, kw, src) {
2598
2601
  } catch (e) {
2599
2602
  __inside__--;
2600
2603
  if (!(e && e.__gobj_logged__)) {
2601
- log_error(`${gobj_short_name(dst)}: action of ${event} in ${dst.current_state.state_name} THREW: ${e && e.stack ? e.stack : e}`);
2604
+ log_error(`${gobj_short_name(dst)}: action of ${event} in ${state.state_name} THREW: ${e && e.stack ? e.stack : e}`);
2602
2605
  try {
2603
2606
  e.__gobj_logged__ = true;
2604
2607
  } catch (e2) {}
@@ -3606,7 +3609,7 @@ function _json_mask_secrets(jn, memo, depth, budget) {
3606
3609
  if ((is_secret_name(key.slice(-128)) || value_is_secret && key === "value") && value !== void 0 && value !== null && value !== "") shown = "********";
3607
3610
  else shown = _json_mask_secrets(value, memo, depth + 1, budget);
3608
3611
  if (shown !== value) changed = true;
3609
- result[key] = shown;
3612
+ set_own_key(result, key, shown);
3610
3613
  }
3611
3614
  if (truncated) result["<more>"] = MASK_TOO_LARGE;
3612
3615
  }
@@ -3678,7 +3681,7 @@ function json_is_identical(kw1, kw2) {
3678
3681
  ************************************************************/
3679
3682
  function json_object_update(destination, source) {
3680
3683
  if (!source) return destination;
3681
- for (let property of Object.keys(source)) destination[property] = source[property];
3684
+ for (let property of Object.keys(source)) set_own_key(destination, property, source[property]);
3682
3685
  return destination;
3683
3686
  }
3684
3687
  /************************************************************
@@ -3687,7 +3690,7 @@ function json_object_update(destination, source) {
3687
3690
  ************************************************************/
3688
3691
  function json_object_update_existing(destination, source) {
3689
3692
  if (!source) return destination;
3690
- for (let property in source) if (source.hasOwnProperty(property) && destination.hasOwnProperty(property)) destination[property] = source[property];
3693
+ 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]);
3691
3694
  return destination;
3692
3695
  }
3693
3696
  /************************************************************
@@ -3696,32 +3699,32 @@ function json_object_update_existing(destination, source) {
3696
3699
  ************************************************************/
3697
3700
  function json_object_update_missing(destination, source) {
3698
3701
  if (!source) return destination;
3699
- for (let property in source) if (source.hasOwnProperty(property) && !destination.hasOwnProperty(property)) destination[property] = source[property];
3702
+ 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]);
3700
3703
  return destination;
3701
3704
  }
3702
3705
  /************************************************************
3703
3706
  * Simulate jansson function
3704
3707
  ************************************************************/
3705
3708
  function json_object_get(o, key) {
3706
- if (o && o.hasOwnProperty(key)) return o[key];
3709
+ if (o && Object.prototype.hasOwnProperty.call(o, key)) return o[key];
3707
3710
  }
3708
3711
  /************************************************************
3709
3712
  * Simulate jansson function
3710
3713
  ************************************************************/
3711
3714
  function json_object_del(o, k) {
3712
- if (o && o.hasOwnProperty(k)) delete o[k];
3715
+ if (o && Object.prototype.hasOwnProperty.call(o, k)) delete o[k];
3713
3716
  }
3714
3717
  /************************************************************
3715
3718
  * Simulate jansson function
3716
3719
  ************************************************************/
3717
3720
  function json_object_set(o, k, v) {
3718
- o[k] = v;
3721
+ set_own_key(o, k, v);
3719
3722
  }
3720
3723
  /************************************************************
3721
3724
  * Simulate jansson function
3722
3725
  ************************************************************/
3723
3726
  function json_object_set_new(o, k, v) {
3724
- o[k] = v;
3727
+ set_own_key(o, k, v);
3725
3728
  }
3726
3729
  /************************************************************
3727
3730
  * Simulate jansson function
@@ -3965,22 +3968,20 @@ function kw_pop(kw1, kw2) {
3965
3968
  ************************************************************/
3966
3969
  function kw_has_key(kw, key) {
3967
3970
  if (key in kw) {
3968
- if (kw.hasOwnProperty(key)) return true;
3971
+ if (Object.prototype.hasOwnProperty.call(kw, key)) return true;
3969
3972
  }
3970
3973
  return false;
3971
3974
  }
3972
3975
  /************************************************************
3973
3976
  * A key that reaches the prototype chain instead of the data:
3974
- * "__proto__", "constructor" or "prototype" when the object
3975
- * does not hold it as its OWN key. A walk through one of them
3977
+ * any key the object does not hold as its OWN key. A walk through one of them
3976
3978
  * read, or WROTE, Object.prototype: the flat id
3977
3979
  * "__proto__`polluted" set a key on every object of the page.
3978
3980
  * In C they are keys like any other, so here too: read them
3979
3981
  * only as own keys, and write "__proto__" as an own key.
3980
3982
  ************************************************************/
3981
3983
  function is_prototype_segment(obj, key) {
3982
- if (key === "__proto__" || key === "constructor" || key === "prototype") return !Object.prototype.hasOwnProperty.call(obj, key);
3983
- return false;
3984
+ return !Object.prototype.hasOwnProperty.call(obj, key);
3984
3985
  }
3985
3986
  function set_own_key(obj, key, value) {
3986
3987
  if (key === "__proto__") Object.defineProperty(obj, key, {
@@ -4563,14 +4564,14 @@ function kw_clone_by_keys(gobj, kw, keys, verbose) {
4563
4564
  let kw_clone = {};
4564
4565
  if (is_string(keys) && !empty_string(keys)) {
4565
4566
  let key = keys;
4566
- if (kw.hasOwnProperty(key)) kw_clone[key] = kw[key];
4567
+ if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
4567
4568
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4568
4569
  } else if (is_object(keys) && json_object_size(keys) > 0) {
4569
- for (let key of Object.keys(keys)) if (kw.hasOwnProperty(key)) kw_clone[key] = kw[key];
4570
+ for (let key of Object.keys(keys)) if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
4570
4571
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4571
4572
  } else if (is_array(keys) && json_array_size(keys) > 0) for (let j = 0; j < keys.length; j++) {
4572
4573
  let key = keys[j];
4573
- if (kw.hasOwnProperty(key)) kw_clone[key] = kw[key];
4574
+ 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
  }
4576
4577
  else return kw;
@@ -4592,14 +4593,14 @@ function kw_clone_by_not_keys(gobj, kw, keys, verbose) {
4592
4593
  json_object_update(kw_clone, kw);
4593
4594
  if (is_string(keys) && !empty_string(keys)) {
4594
4595
  let key = keys;
4595
- if (kw.hasOwnProperty(key)) json_object_del(kw_clone, key);
4596
+ if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
4596
4597
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4597
4598
  } else if (is_object(keys) && json_object_size(keys) > 0) {
4598
- for (let key of Object.keys(keys)) if (kw.hasOwnProperty(key)) json_object_del(kw_clone, key);
4599
+ for (let key of Object.keys(keys)) if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
4599
4600
  else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
4600
4601
  } else if (is_array(keys) && json_array_size(keys) > 0) for (let j = 0; j < keys.length; j++) {
4601
4602
  let key = keys[j];
4602
- if (kw.hasOwnProperty(key)) json_object_del(kw_clone, key);
4603
+ 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
  }
4605
4606
  else return {};
@@ -4830,7 +4831,7 @@ function kwid_get_ids(gobj, ids) {
4830
4831
  let new_ids = [];
4831
4832
  if (is_string(ids)) new_ids.push(ids);
4832
4833
  else if (is_object(ids)) {
4833
- for (let id in ids) if (ids.hasOwnProperty(id)) new_ids.push(id);
4834
+ for (let id in ids) if (Object.prototype.hasOwnProperty.call(ids, id)) new_ids.push(id);
4834
4835
  } else if (is_array(ids)) ids.forEach(function(item) {
4835
4836
  if (is_string(item)) {
4836
4837
  if (!empty_string(item)) new_ids.push(item);
@@ -5083,7 +5084,7 @@ function send_http_json_post(url, data, on_response) {
5083
5084
  function _traverse_dict(obj, callback, full_path) {
5084
5085
  if (full_path === void 0 || !is_string(full_path)) full_path = "";
5085
5086
  for (let key of Object.keys(obj)) {
5086
- if (!obj.hasOwnProperty(key)) continue;
5087
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
5087
5088
  let sufix = (full_path.length ? "`" : "") + key;
5088
5089
  full_path += sufix;
5089
5090
  callback.apply(this, [
@@ -5964,7 +5965,7 @@ function json2flat(jn) {
5964
5965
  return;
5965
5966
  }
5966
5967
  if (depth === 0) return;
5967
- flat[path] = value;
5968
+ set_own_key(flat, path, value);
5968
5969
  };
5969
5970
  if (jn === void 0 || jn === null) return flat;
5970
5971
  walk(jn, "", 0);
@@ -6066,11 +6067,11 @@ function flat_apply(flat, diff) {
6066
6067
  if (flat === null || typeof flat !== "object" || Array.isArray(flat)) throw new Error("flat_apply: a flat json is an object of id -> value");
6067
6068
  if (diff === null || typeof diff !== "object") throw new Error("flat_apply: a diff is the object flat_diff() answers");
6068
6069
  for (const key of Object.keys(diff.removed || {})) delete flat[key];
6069
- for (const key of Object.keys(diff.added || {})) flat[key] = diff.added[key];
6070
+ for (const key of Object.keys(diff.added || {})) set_own_key(flat, key, diff.added[key]);
6070
6071
  for (const key of Object.keys(diff.changed || {})) {
6071
6072
  const change = diff.changed[key];
6072
6073
  if (!change || !Object.prototype.hasOwnProperty.call(change, "to")) throw new Error(`flat_apply: changed '${key}' without a 'to'`);
6073
- flat[key] = change.to;
6074
+ set_own_key(flat, key, change.to);
6074
6075
  }
6075
6076
  return flat;
6076
6077
  }
@@ -7212,6 +7213,7 @@ function setup_websocket(gobj) {
7212
7213
  if (gobj.priv.websocket) log_error(`Websocket ALREADY setup`);
7213
7214
  const url = gobj_read_str_attr(gobj, "url");
7214
7215
  log_debug(`====> Starting WebSocket to '${url}' (${gobj_short_name(gobj)})`);
7216
+ const ws_seq = ++gobj.priv.ws_seq;
7215
7217
  let websocket;
7216
7218
  try {
7217
7219
  websocket = new WebSocket(url);
@@ -7223,7 +7225,6 @@ function setup_websocket(gobj) {
7223
7225
  log_error(`${gobj_short_name(gobj)}: Failed to initialize WebSocket.`);
7224
7226
  return null;
7225
7227
  }
7226
- const ws_seq = ++gobj.priv.ws_seq;
7227
7228
  websocket.onopen = () => {
7228
7229
  if (ws_seq !== gobj.priv.ws_seq || gobj_is_destroying(gobj)) return;
7229
7230
  gobj_send_event(gobj, "EV_ON_OPEN", {