@yuneta/gobj-js 7.26.1 → 7.26.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.
@@ -909,7 +909,7 @@ var gobjJs = (function(exports) {
909
909
  }
910
910
  if (jn_value2 === void 0) log_error(`${gobj_short_name(gobj)}: attr undefined: ${it.name}`);
911
911
  sdata[it.name] = jn_value2;
912
- if (is_object(gobj.priv) && gobj.priv.hasOwnProperty(it.name)) gobj.priv[it.name] = jn_value2;
912
+ if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, it.name)) gobj.priv[it.name] = jn_value2;
913
913
  if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
914
914
  if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, it.name);
915
915
  }
@@ -2112,7 +2112,7 @@ var gobjJs = (function(exports) {
2112
2112
  function gobj_read_attr(gobj, name, src) {
2113
2113
  let jn_attrs = gobj.jn_attrs;
2114
2114
  if (name in jn_attrs) {
2115
- if (jn_attrs.hasOwnProperty(name)) {
2115
+ if (Object.prototype.hasOwnProperty.call(jn_attrs, name)) {
2116
2116
  let value = jn_attrs[name];
2117
2117
  if (gobj.gclass.gmt.mt_reading) return gobj.gclass.gmt.mt_reading(gobj, name, value);
2118
2118
  return value;
@@ -2218,9 +2218,9 @@ var gobjJs = (function(exports) {
2218
2218
  if (ss.length <= 1) {
2219
2219
  let key = path;
2220
2220
  if (key in jn_attrs) {
2221
- if (jn_attrs.hasOwnProperty(key)) {
2221
+ if (Object.prototype.hasOwnProperty.call(jn_attrs, key)) {
2222
2222
  jn_attrs[key] = value;
2223
- if (is_object(gobj.priv) && gobj.priv.hasOwnProperty(key)) gobj.priv[key] = value;
2223
+ if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, key)) gobj.priv[key] = value;
2224
2224
  if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
2225
2225
  if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, key);
2226
2226
  }
@@ -2241,9 +2241,9 @@ var gobjJs = (function(exports) {
2241
2241
  }
2242
2242
  let jn_attrs = gobj.jn_attrs;
2243
2243
  if (key in jn_attrs) {
2244
- if (jn_attrs.hasOwnProperty(key)) {
2244
+ if (Object.prototype.hasOwnProperty.call(jn_attrs, key)) {
2245
2245
  jn_attrs[key] = value;
2246
- if (is_object(gobj.priv) && gobj.priv.hasOwnProperty(key)) gobj.priv[key] = value;
2246
+ if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, key)) gobj.priv[key] = value;
2247
2247
  if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
2248
2248
  if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, key);
2249
2249
  }
@@ -2270,7 +2270,7 @@ var gobjJs = (function(exports) {
2270
2270
  if (exclude_flag && it.flag & exclude_flag) continue;
2271
2271
  if (include_flag === -1 || it.flag & include_flag) {
2272
2272
  set_default(gobj, gobj.jn_attrs, it);
2273
- if (is_object(gobj.priv) && gobj.priv.hasOwnProperty(it.name)) gobj.priv[it.name] = gobj.jn_attrs[it.name];
2273
+ if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, it.name)) gobj.priv[it.name] = gobj.jn_attrs[it.name];
2274
2274
  if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, it.name);
2275
2275
  }
2276
2276
  }
@@ -2304,7 +2304,7 @@ var gobjJs = (function(exports) {
2304
2304
  let hs = gobj_hsdata2(gobj, name, false);
2305
2305
  if (hs) {
2306
2306
  hs[name] = parseBoolean(value);
2307
- if (is_object(gobj.priv) && gobj.priv.hasOwnProperty(name)) gobj.priv[name] = hs[name];
2307
+ if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, name)) gobj.priv[name] = hs[name];
2308
2308
  if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
2309
2309
  if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, name);
2310
2310
  }
@@ -2320,7 +2320,7 @@ var gobjJs = (function(exports) {
2320
2320
  let hs = gobj_hsdata2(gobj, name, false);
2321
2321
  if (hs) {
2322
2322
  hs[name] = parseInt(value);
2323
- if (is_object(gobj.priv) && gobj.priv.hasOwnProperty(name)) gobj.priv[name] = hs[name];
2323
+ if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, name)) gobj.priv[name] = hs[name];
2324
2324
  if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
2325
2325
  if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, name);
2326
2326
  }
@@ -2336,7 +2336,7 @@ var gobjJs = (function(exports) {
2336
2336
  let hs = gobj_hsdata2(gobj, name, false);
2337
2337
  if (hs) {
2338
2338
  hs[name] = String(value);
2339
- if (is_object(gobj.priv) && gobj.priv.hasOwnProperty(name)) gobj.priv[name] = hs[name];
2339
+ if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, name)) gobj.priv[name] = hs[name];
2340
2340
  if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
2341
2341
  if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, name);
2342
2342
  }
@@ -2724,8 +2724,8 @@ var gobjJs = (function(exports) {
2724
2724
  kw,
2725
2725
  renamed_event: ""
2726
2726
  };
2727
- let kw_match = Object.assign({}, kw);
2728
- let config_match = Object.assign({}, __config__);
2727
+ let kw_match = json_object_update({}, kw);
2728
+ let config_match = json_object_update({}, __config__);
2729
2729
  kw_match.__config__ = config_match;
2730
2730
  let renamed_event = "";
2731
2731
  let rename = config_match.__rename_event_name__;
@@ -2733,7 +2733,7 @@ var gobjJs = (function(exports) {
2733
2733
  if (event_type) {
2734
2734
  renamed_event = event_type.event_name;
2735
2735
  delete config_match.__rename_event_name__;
2736
- if (event && json_size(kw_match.__global__) > 0) kw_match.__global__ = Object.assign({}, kw_match.__global__, { __original_event_name__: event });
2736
+ if (event && json_size(kw_match.__global__) > 0) kw_match.__global__ = json_object_update(json_object_update({}, kw_match.__global__), { __original_event_name__: event });
2737
2737
  }
2738
2738
  delete config_match.__hard_subscription__;
2739
2739
  delete config_match.__own_event__;
@@ -3109,7 +3109,7 @@ var gobjJs = (function(exports) {
3109
3109
  }
3110
3110
  }
3111
3111
  let kw2publish = kw;
3112
- if (json_size(__local__) > 0 || json_size(__global__) > 0) kw2publish = Object.assign({}, kw);
3112
+ if (json_size(__local__) > 0 || json_size(__global__) > 0) kw2publish = json_object_update({}, kw);
3113
3113
  if (json_size(__local__) > 0) kw_pop(kw2publish, __local__);
3114
3114
  if (__config__) {}
3115
3115
  if (json_size(__global__) > 0) json_object_update(kw2publish, json_deep_copy(__global__));
@@ -3646,10 +3646,7 @@ var gobjJs = (function(exports) {
3646
3646
  ************************************************************/
3647
3647
  function duplicate_objects(...sourceObjects) {
3648
3648
  const result = {};
3649
- for (const obj of sourceObjects) {
3650
- const clonedObj = structuredClone(obj);
3651
- Object.assign(result, clonedObj);
3652
- }
3649
+ for (const obj of sourceObjects) json_object_update(result, structuredClone(obj));
3653
3650
  return result;
3654
3651
  }
3655
3652
  /************************************************************
@@ -4022,6 +4019,13 @@ var gobjJs = (function(exports) {
4022
4019
  let ss = path.split("`");
4023
4020
  let len = ss.length;
4024
4021
  for (let i = 0; i < len; i++) {
4022
+ if (is_array(kw)) {
4023
+ if (!/^[0-9]+$/.test(ss[i])) {
4024
+ if (verbose) log_error(`${prefix}path not found: '${path}'`);
4025
+ return;
4026
+ }
4027
+ ss[i] = String(Number(ss[i]));
4028
+ }
4025
4029
  if (is_prototype_segment(kw, ss[i])) {
4026
4030
  if (verbose) log_error(`${prefix}path not found: '${path}'`);
4027
4031
  return;
@@ -4439,7 +4443,7 @@ var gobjJs = (function(exports) {
4439
4443
  log_error("subdict is not an object");
4440
4444
  return -1;
4441
4445
  }
4442
- subdict[key] = value;
4446
+ set_own_key(subdict, key, value);
4443
4447
  return 0;
4444
4448
  }
4445
4449
  /***************************************************************************
@@ -4747,7 +4751,7 @@ var gobjJs = (function(exports) {
4747
4751
  else if (is_array(kw)) for (let i = 0; i < kw.length; i++) {
4748
4752
  let kv = kw[i];
4749
4753
  let id = kw_get_str(gobj, kv, "id", "", kw_flag_t.KW_REQUIRED);
4750
- if (!empty_string(id)) new_dict[id] = kv;
4754
+ if (!empty_string(id)) set_own_key(new_dict, id, kv);
4751
4755
  }
4752
4756
  else log_error(`${gobj_short_name(gobj)} kwid_new_dict: data type unknown`);
4753
4757
  return new_dict;
@@ -5193,11 +5197,11 @@ var gobjJs = (function(exports) {
5193
5197
  }
5194
5198
  if (ids.length === 0 && v) {
5195
5199
  if (is_array(v)) v.push(kw);
5196
- else if (v["id"] === kw["id"]) Object.assign(v, kw);
5200
+ else if (v["id"] === kw["id"]) json_object_update(v, kw);
5197
5201
  else {
5198
5202
  let v_ = kw_get_dict_value(null, v, jdb.hook, [], 1);
5199
5203
  let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
5200
- if (v__) Object.assign(v__, kw);
5204
+ if (v__) json_object_update(v__, kw);
5201
5205
  else v_.push(kw);
5202
5206
  }
5203
5207
  }
@@ -5564,6 +5568,10 @@ var gobjJs = (function(exports) {
5564
5568
  * as a bare string, or "<img src=x onerror=...>" runs.
5565
5569
  * Pass it as a Text node, which is always text:
5566
5570
  * ['span', {}, document.createTextNode(value)]
5571
+ * In a LIST of children a node (element, svg, Text) is
5572
+ * appended as it is and a string is always text -- but a
5573
+ * list whose first item is a string is read as ONE
5574
+ * description (the string is its tag).
5567
5575
  * if attrs['i18n'] is not empty then (or 'data-i18n' or 'data_i18next')
5568
5576
  * it will be overridden with the translation
5569
5577
  * content = translate(attrs['i18n']));
@@ -5616,8 +5624,11 @@ var gobjJs = (function(exports) {
5616
5624
  } else if (is_array(content)) {
5617
5625
  if (content.length > 0) {
5618
5626
  if (is_string(content[0])) el.appendChild(createElement2(content, translate_fn));
5619
- else for (let child of content) if (Array.isArray(child) && child.length > 0) el.appendChild(createElement2(child, translate_fn));
5620
- else if (child instanceof HTMLElement) el.appendChild(child);
5627
+ else for (let child of content) if (Array.isArray(child)) {
5628
+ if (child.length > 0) el.appendChild(createElement2(child, translate_fn));
5629
+ } else if (child instanceof Node) el.appendChild(child);
5630
+ else if (is_string(child)) el.appendChild(document.createTextNode(child));
5631
+ else if (child !== null && child !== void 0 && child !== false) log_error(`createElement2: child ignored, type ${typeof child}`);
5621
5632
  }
5622
5633
  } else if (content instanceof HTMLElement || content instanceof Text || content instanceof SVGElement) el.appendChild(content);
5623
5634
  else if (content != null) {
@@ -6050,12 +6061,12 @@ var gobjJs = (function(exports) {
6050
6061
  removed: {},
6051
6062
  changed: {}
6052
6063
  };
6053
- for (const key of Object.keys(a)) if (!Object.prototype.hasOwnProperty.call(b, key)) diff.removed[key] = a[key];
6054
- else if (!flat_value_equal(a[key], b[key])) diff.changed[key] = {
6064
+ for (const key of Object.keys(a)) if (!Object.prototype.hasOwnProperty.call(b, key)) set_own_key(diff.removed, key, a[key]);
6065
+ else if (!flat_value_equal(a[key], b[key])) set_own_key(diff.changed, key, {
6055
6066
  from: a[key],
6056
6067
  to: b[key]
6057
- };
6058
- for (const key of Object.keys(b)) if (!Object.prototype.hasOwnProperty.call(a, key)) diff.added[key] = b[key];
6068
+ });
6069
+ for (const key of Object.keys(b)) if (!Object.prototype.hasOwnProperty.call(a, key)) set_own_key(diff.added, key, b[key]);
6059
6070
  return diff;
6060
6071
  }
6061
6072
  /************************************************************
@@ -7163,7 +7174,7 @@ var gobjJs = (function(exports) {
7163
7174
  window.console.error(`Not in session`);
7164
7175
  return -1;
7165
7176
  }
7166
- kw = Object.assign({}, is_object(kw) ? kw : {});
7177
+ kw = json_object_update({}, is_object(kw) ? kw : {});
7167
7178
  if (is_object(kw["__md_iev__"])) kw["__md_iev__"] = json_deep_copy(kw["__md_iev__"]);
7168
7179
  if (msg_iev_get_stack(gobj, kw, IEVENT_STACK_ID)) {} else {
7169
7180
  let jn_ievent_id = build_cli_ievent_request(gobj, gobj_name(src), kw_get_str(gobj, kw, "__service__", 0, 0));
@@ -7221,6 +7232,13 @@ var gobjJs = (function(exports) {
7221
7232
  websocket = new WebSocket(url);
7222
7233
  } catch (e) {
7223
7234
  log_error(`${gobj_short_name(gobj)}: Cannot open WebSocket to '${url}', Error: ${e.message}`);
7235
+ gobj_post_event(gobj, "EV_ON_CLOSE", {
7236
+ url,
7237
+ ws_seq,
7238
+ code: 1006,
7239
+ reason: e.message,
7240
+ was_clean: false
7241
+ }, gobj);
7224
7242
  return null;
7225
7243
  }
7226
7244
  if (!websocket) {
@@ -7479,6 +7497,7 @@ var gobjJs = (function(exports) {
7479
7497
  function ac_on_close(gobj, event, kw, src) {
7480
7498
  let priv = gobj.priv;
7481
7499
  let url = kw.url;
7500
+ if (kw.ws_seq !== void 0 && kw.ws_seq !== priv.ws_seq) return 0;
7482
7501
  set_remote_log_functions();
7483
7502
  log_warning(`${gobj_short_name(gobj)}: WebSocket closed ${url} (Code: ${kw.code}, Reason: "${kw.reason}", Clean: ${kw.was_clean})`);
7484
7503
  if (priv.websocket) {
@@ -7496,7 +7515,7 @@ var gobjJs = (function(exports) {
7496
7515
  remote_yuno_role: priv.remote_yuno_role,
7497
7516
  remote_yuno_service: priv.remote_yuno_service
7498
7517
  });
7499
- } else {
7518
+ } else if (!gobj_is_running(gobj)) {} else {
7500
7519
  log_warning(`${gobj_short_name(gobj)}: EV_ON_OPEN_ERROR cannot open ${url} (Code: ${kw.code}, Reason: "${kw.reason}", Clean: ${kw.was_clean})`);
7501
7520
  gobj_publish_event(gobj, "EV_ON_OPEN_ERROR", {
7502
7521
  url,