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