@yuneta/gobj-js 7.26.0 → 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.
- package/README.md +4 -3
- package/dist/gobj-js.cjs.js +80 -60
- package/dist/gobj-js.cjs.js.map +1 -1
- package/dist/gobj-js.cjs.min.js +1003 -993
- package/dist/gobj-js.cjs.min.js.map +1 -1
- package/dist/gobj-js.es.js +80 -60
- package/dist/gobj-js.es.js.map +1 -1
- package/dist/gobj-js.es.min.js +219 -210
- package/dist/gobj-js.es.min.js.map +1 -1
- package/dist/gobj-js.iife.js +80 -60
- package/dist/gobj-js.iife.js.map +1 -1
- package/dist/gobj-js.iife.min.js +1059 -1049
- package/dist/gobj-js.iife.min.js.map +1 -1
- package/dist/gobj-js.umd.js +80 -60
- package/dist/gobj-js.umd.js.map +1 -1
- package/dist/gobj-js.umd.min.js +1059 -1049
- package/dist/gobj-js.umd.min.js.map +1 -1
- package/package.json +3 -3
package/dist/gobj-js.es.js
CHANGED
|
@@ -894,17 +894,20 @@ 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_))
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
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_;
|
|
904
907
|
}
|
|
905
908
|
if (jn_value2 === void 0) log_error(`${gobj_short_name(gobj)}: attr undefined: ${it.name}`);
|
|
906
909
|
sdata[it.name] = jn_value2;
|
|
907
|
-
if (is_object(gobj.priv) &&
|
|
910
|
+
if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, it.name)) gobj.priv[it.name] = jn_value2;
|
|
908
911
|
if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
|
|
909
912
|
if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, it.name);
|
|
910
913
|
}
|
|
@@ -2107,7 +2110,7 @@ function gobj_has_attr(gobj, name) {
|
|
|
2107
2110
|
function gobj_read_attr(gobj, name, src) {
|
|
2108
2111
|
let jn_attrs = gobj.jn_attrs;
|
|
2109
2112
|
if (name in jn_attrs) {
|
|
2110
|
-
if (
|
|
2113
|
+
if (Object.prototype.hasOwnProperty.call(jn_attrs, name)) {
|
|
2111
2114
|
let value = jn_attrs[name];
|
|
2112
2115
|
if (gobj.gclass.gmt.mt_reading) return gobj.gclass.gmt.mt_reading(gobj, name, value);
|
|
2113
2116
|
return value;
|
|
@@ -2213,9 +2216,9 @@ function gobj_write_attr(gobj, path, value, src) {
|
|
|
2213
2216
|
if (ss.length <= 1) {
|
|
2214
2217
|
let key = path;
|
|
2215
2218
|
if (key in jn_attrs) {
|
|
2216
|
-
if (
|
|
2219
|
+
if (Object.prototype.hasOwnProperty.call(jn_attrs, key)) {
|
|
2217
2220
|
jn_attrs[key] = value;
|
|
2218
|
-
if (is_object(gobj.priv) &&
|
|
2221
|
+
if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, key)) gobj.priv[key] = value;
|
|
2219
2222
|
if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
|
|
2220
2223
|
if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, key);
|
|
2221
2224
|
}
|
|
@@ -2236,9 +2239,9 @@ function gobj_write_attr(gobj, path, value, src) {
|
|
|
2236
2239
|
}
|
|
2237
2240
|
let jn_attrs = gobj.jn_attrs;
|
|
2238
2241
|
if (key in jn_attrs) {
|
|
2239
|
-
if (
|
|
2242
|
+
if (Object.prototype.hasOwnProperty.call(jn_attrs, key)) {
|
|
2240
2243
|
jn_attrs[key] = value;
|
|
2241
|
-
if (is_object(gobj.priv) &&
|
|
2244
|
+
if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, key)) gobj.priv[key] = value;
|
|
2242
2245
|
if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
|
|
2243
2246
|
if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, key);
|
|
2244
2247
|
}
|
|
@@ -2265,7 +2268,7 @@ function sdata_write_default_values(gobj, include_flag, exclude_flag) {
|
|
|
2265
2268
|
if (exclude_flag && it.flag & exclude_flag) continue;
|
|
2266
2269
|
if (include_flag === -1 || it.flag & include_flag) {
|
|
2267
2270
|
set_default(gobj, gobj.jn_attrs, it);
|
|
2268
|
-
if (is_object(gobj.priv) &&
|
|
2271
|
+
if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, it.name)) gobj.priv[it.name] = gobj.jn_attrs[it.name];
|
|
2269
2272
|
if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, it.name);
|
|
2270
2273
|
}
|
|
2271
2274
|
}
|
|
@@ -2299,7 +2302,7 @@ function gobj_write_bool_attr(gobj, name, value) {
|
|
|
2299
2302
|
let hs = gobj_hsdata2(gobj, name, false);
|
|
2300
2303
|
if (hs) {
|
|
2301
2304
|
hs[name] = parseBoolean(value);
|
|
2302
|
-
if (is_object(gobj.priv) &&
|
|
2305
|
+
if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, name)) gobj.priv[name] = hs[name];
|
|
2303
2306
|
if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
|
|
2304
2307
|
if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, name);
|
|
2305
2308
|
}
|
|
@@ -2315,7 +2318,7 @@ function gobj_write_integer_attr(gobj, name, value) {
|
|
|
2315
2318
|
let hs = gobj_hsdata2(gobj, name, false);
|
|
2316
2319
|
if (hs) {
|
|
2317
2320
|
hs[name] = parseInt(value);
|
|
2318
|
-
if (is_object(gobj.priv) &&
|
|
2321
|
+
if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, name)) gobj.priv[name] = hs[name];
|
|
2319
2322
|
if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
|
|
2320
2323
|
if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, name);
|
|
2321
2324
|
}
|
|
@@ -2331,7 +2334,7 @@ function gobj_write_str_attr(gobj, name, value) {
|
|
|
2331
2334
|
let hs = gobj_hsdata2(gobj, name, false);
|
|
2332
2335
|
if (hs) {
|
|
2333
2336
|
hs[name] = String(value);
|
|
2334
|
-
if (is_object(gobj.priv) &&
|
|
2337
|
+
if (is_object(gobj.priv) && Object.prototype.hasOwnProperty.call(gobj.priv, name)) gobj.priv[name] = hs[name];
|
|
2335
2338
|
if (gobj.obflag & obflag_t.obflag_created && !(gobj.obflag & obflag_t.obflag_destroyed)) {
|
|
2336
2339
|
if (gobj.gclass.gmt.mt_writing) gobj.gclass.gmt.mt_writing(gobj, name);
|
|
2337
2340
|
}
|
|
@@ -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 ${
|
|
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) {}
|
|
@@ -2719,8 +2722,8 @@ function _subscription_match_kw(kw, event) {
|
|
|
2719
2722
|
kw,
|
|
2720
2723
|
renamed_event: ""
|
|
2721
2724
|
};
|
|
2722
|
-
let kw_match =
|
|
2723
|
-
let config_match =
|
|
2725
|
+
let kw_match = json_object_update({}, kw);
|
|
2726
|
+
let config_match = json_object_update({}, __config__);
|
|
2724
2727
|
kw_match.__config__ = config_match;
|
|
2725
2728
|
let renamed_event = "";
|
|
2726
2729
|
let rename = config_match.__rename_event_name__;
|
|
@@ -2728,7 +2731,7 @@ function _subscription_match_kw(kw, event) {
|
|
|
2728
2731
|
if (event_type) {
|
|
2729
2732
|
renamed_event = event_type.event_name;
|
|
2730
2733
|
delete config_match.__rename_event_name__;
|
|
2731
|
-
if (event && json_size(kw_match.__global__) > 0) kw_match.__global__ =
|
|
2734
|
+
if (event && json_size(kw_match.__global__) > 0) kw_match.__global__ = json_object_update(json_object_update({}, kw_match.__global__), { __original_event_name__: event });
|
|
2732
2735
|
}
|
|
2733
2736
|
delete config_match.__hard_subscription__;
|
|
2734
2737
|
delete config_match.__own_event__;
|
|
@@ -3104,7 +3107,7 @@ function gobj_publish_event(publisher, event, kw) {
|
|
|
3104
3107
|
}
|
|
3105
3108
|
}
|
|
3106
3109
|
let kw2publish = kw;
|
|
3107
|
-
if (json_size(__local__) > 0 || json_size(__global__) > 0) kw2publish =
|
|
3110
|
+
if (json_size(__local__) > 0 || json_size(__global__) > 0) kw2publish = json_object_update({}, kw);
|
|
3108
3111
|
if (json_size(__local__) > 0) kw_pop(kw2publish, __local__);
|
|
3109
3112
|
if (__config__) {}
|
|
3110
3113
|
if (json_size(__global__) > 0) json_object_update(kw2publish, json_deep_copy(__global__));
|
|
@@ -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
|
|
3612
|
+
set_own_key(result, key, shown);
|
|
3610
3613
|
}
|
|
3611
3614
|
if (truncated) result["<more>"] = MASK_TOO_LARGE;
|
|
3612
3615
|
}
|
|
@@ -3641,10 +3644,7 @@ function json_deep_copy(obj) {
|
|
|
3641
3644
|
************************************************************/
|
|
3642
3645
|
function duplicate_objects(...sourceObjects) {
|
|
3643
3646
|
const result = {};
|
|
3644
|
-
for (const obj of sourceObjects)
|
|
3645
|
-
const clonedObj = structuredClone(obj);
|
|
3646
|
-
Object.assign(result, clonedObj);
|
|
3647
|
-
}
|
|
3647
|
+
for (const obj of sourceObjects) json_object_update(result, structuredClone(obj));
|
|
3648
3648
|
return result;
|
|
3649
3649
|
}
|
|
3650
3650
|
/************************************************************
|
|
@@ -3678,7 +3678,7 @@ function json_is_identical(kw1, kw2) {
|
|
|
3678
3678
|
************************************************************/
|
|
3679
3679
|
function json_object_update(destination, source) {
|
|
3680
3680
|
if (!source) return destination;
|
|
3681
|
-
for (let property of Object.keys(source)) destination
|
|
3681
|
+
for (let property of Object.keys(source)) set_own_key(destination, property, source[property]);
|
|
3682
3682
|
return destination;
|
|
3683
3683
|
}
|
|
3684
3684
|
/************************************************************
|
|
@@ -3687,7 +3687,7 @@ function json_object_update(destination, source) {
|
|
|
3687
3687
|
************************************************************/
|
|
3688
3688
|
function json_object_update_existing(destination, source) {
|
|
3689
3689
|
if (!source) return destination;
|
|
3690
|
-
for (let property in source) if (
|
|
3690
|
+
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
3691
|
return destination;
|
|
3692
3692
|
}
|
|
3693
3693
|
/************************************************************
|
|
@@ -3696,32 +3696,32 @@ function json_object_update_existing(destination, source) {
|
|
|
3696
3696
|
************************************************************/
|
|
3697
3697
|
function json_object_update_missing(destination, source) {
|
|
3698
3698
|
if (!source) return destination;
|
|
3699
|
-
for (let property in source) if (
|
|
3699
|
+
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
3700
|
return destination;
|
|
3701
3701
|
}
|
|
3702
3702
|
/************************************************************
|
|
3703
3703
|
* Simulate jansson function
|
|
3704
3704
|
************************************************************/
|
|
3705
3705
|
function json_object_get(o, key) {
|
|
3706
|
-
if (o &&
|
|
3706
|
+
if (o && Object.prototype.hasOwnProperty.call(o, key)) return o[key];
|
|
3707
3707
|
}
|
|
3708
3708
|
/************************************************************
|
|
3709
3709
|
* Simulate jansson function
|
|
3710
3710
|
************************************************************/
|
|
3711
3711
|
function json_object_del(o, k) {
|
|
3712
|
-
if (o &&
|
|
3712
|
+
if (o && Object.prototype.hasOwnProperty.call(o, k)) delete o[k];
|
|
3713
3713
|
}
|
|
3714
3714
|
/************************************************************
|
|
3715
3715
|
* Simulate jansson function
|
|
3716
3716
|
************************************************************/
|
|
3717
3717
|
function json_object_set(o, k, v) {
|
|
3718
|
-
o
|
|
3718
|
+
set_own_key(o, k, v);
|
|
3719
3719
|
}
|
|
3720
3720
|
/************************************************************
|
|
3721
3721
|
* Simulate jansson function
|
|
3722
3722
|
************************************************************/
|
|
3723
3723
|
function json_object_set_new(o, k, v) {
|
|
3724
|
-
o
|
|
3724
|
+
set_own_key(o, k, v);
|
|
3725
3725
|
}
|
|
3726
3726
|
/************************************************************
|
|
3727
3727
|
* Simulate jansson function
|
|
@@ -3965,22 +3965,20 @@ function kw_pop(kw1, kw2) {
|
|
|
3965
3965
|
************************************************************/
|
|
3966
3966
|
function kw_has_key(kw, key) {
|
|
3967
3967
|
if (key in kw) {
|
|
3968
|
-
if (
|
|
3968
|
+
if (Object.prototype.hasOwnProperty.call(kw, key)) return true;
|
|
3969
3969
|
}
|
|
3970
3970
|
return false;
|
|
3971
3971
|
}
|
|
3972
3972
|
/************************************************************
|
|
3973
3973
|
* A key that reaches the prototype chain instead of the data:
|
|
3974
|
-
*
|
|
3975
|
-
* does not hold it as its OWN key. A walk through one of them
|
|
3974
|
+
* any key the object does not hold as its OWN key. A walk through one of them
|
|
3976
3975
|
* read, or WROTE, Object.prototype: the flat id
|
|
3977
3976
|
* "__proto__`polluted" set a key on every object of the page.
|
|
3978
3977
|
* In C they are keys like any other, so here too: read them
|
|
3979
3978
|
* only as own keys, and write "__proto__" as an own key.
|
|
3980
3979
|
************************************************************/
|
|
3981
3980
|
function is_prototype_segment(obj, key) {
|
|
3982
|
-
|
|
3983
|
-
return false;
|
|
3981
|
+
return !Object.prototype.hasOwnProperty.call(obj, key);
|
|
3984
3982
|
}
|
|
3985
3983
|
function set_own_key(obj, key, value) {
|
|
3986
3984
|
if (key === "__proto__") Object.defineProperty(obj, key, {
|
|
@@ -4019,6 +4017,13 @@ function kw_find_path(gobj, kw, path, verbose) {
|
|
|
4019
4017
|
let ss = path.split("`");
|
|
4020
4018
|
let len = ss.length;
|
|
4021
4019
|
for (let i = 0; i < len; i++) {
|
|
4020
|
+
if (is_array(kw)) {
|
|
4021
|
+
if (!/^[0-9]+$/.test(ss[i])) {
|
|
4022
|
+
if (verbose) log_error(`${prefix}path not found: '${path}'`);
|
|
4023
|
+
return;
|
|
4024
|
+
}
|
|
4025
|
+
ss[i] = String(Number(ss[i]));
|
|
4026
|
+
}
|
|
4022
4027
|
if (is_prototype_segment(kw, ss[i])) {
|
|
4023
4028
|
if (verbose) log_error(`${prefix}path not found: '${path}'`);
|
|
4024
4029
|
return;
|
|
@@ -4436,7 +4441,7 @@ function kw_set_subdict_value(gobj, kw, path, key, value) {
|
|
|
4436
4441
|
log_error("subdict is not an object");
|
|
4437
4442
|
return -1;
|
|
4438
4443
|
}
|
|
4439
|
-
subdict
|
|
4444
|
+
set_own_key(subdict, key, value);
|
|
4440
4445
|
return 0;
|
|
4441
4446
|
}
|
|
4442
4447
|
/***************************************************************************
|
|
@@ -4563,14 +4568,14 @@ function kw_clone_by_keys(gobj, kw, keys, verbose) {
|
|
|
4563
4568
|
let kw_clone = {};
|
|
4564
4569
|
if (is_string(keys) && !empty_string(keys)) {
|
|
4565
4570
|
let key = keys;
|
|
4566
|
-
if (
|
|
4571
|
+
if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
|
|
4567
4572
|
else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
|
|
4568
4573
|
} else if (is_object(keys) && json_object_size(keys) > 0) {
|
|
4569
|
-
for (let key of Object.keys(keys)) if (
|
|
4574
|
+
for (let key of Object.keys(keys)) if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
|
|
4570
4575
|
else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
|
|
4571
4576
|
} else if (is_array(keys) && json_array_size(keys) > 0) for (let j = 0; j < keys.length; j++) {
|
|
4572
4577
|
let key = keys[j];
|
|
4573
|
-
if (
|
|
4578
|
+
if (Object.prototype.hasOwnProperty.call(kw, key)) set_own_key(kw_clone, key, kw[key]);
|
|
4574
4579
|
else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
|
|
4575
4580
|
}
|
|
4576
4581
|
else return kw;
|
|
@@ -4592,14 +4597,14 @@ function kw_clone_by_not_keys(gobj, kw, keys, verbose) {
|
|
|
4592
4597
|
json_object_update(kw_clone, kw);
|
|
4593
4598
|
if (is_string(keys) && !empty_string(keys)) {
|
|
4594
4599
|
let key = keys;
|
|
4595
|
-
if (
|
|
4600
|
+
if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
|
|
4596
4601
|
else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
|
|
4597
4602
|
} else if (is_object(keys) && json_object_size(keys) > 0) {
|
|
4598
|
-
for (let key of Object.keys(keys)) if (
|
|
4603
|
+
for (let key of Object.keys(keys)) if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
|
|
4599
4604
|
else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
|
|
4600
4605
|
} else if (is_array(keys) && json_array_size(keys) > 0) for (let j = 0; j < keys.length; j++) {
|
|
4601
4606
|
let key = keys[j];
|
|
4602
|
-
if (
|
|
4607
|
+
if (Object.prototype.hasOwnProperty.call(kw, key)) json_object_del(kw_clone, key);
|
|
4603
4608
|
else if (verbose) log_error(`${gobj_short_name(gobj)}: key not found: ${key}`);
|
|
4604
4609
|
}
|
|
4605
4610
|
else return {};
|
|
@@ -4744,7 +4749,7 @@ function kwid_new_dict(gobj, kw, path) {
|
|
|
4744
4749
|
else if (is_array(kw)) for (let i = 0; i < kw.length; i++) {
|
|
4745
4750
|
let kv = kw[i];
|
|
4746
4751
|
let id = kw_get_str(gobj, kv, "id", "", kw_flag_t.KW_REQUIRED);
|
|
4747
|
-
if (!empty_string(id)) new_dict
|
|
4752
|
+
if (!empty_string(id)) set_own_key(new_dict, id, kv);
|
|
4748
4753
|
}
|
|
4749
4754
|
else log_error(`${gobj_short_name(gobj)} kwid_new_dict: data type unknown`);
|
|
4750
4755
|
return new_dict;
|
|
@@ -4830,7 +4835,7 @@ function kwid_get_ids(gobj, ids) {
|
|
|
4830
4835
|
let new_ids = [];
|
|
4831
4836
|
if (is_string(ids)) new_ids.push(ids);
|
|
4832
4837
|
else if (is_object(ids)) {
|
|
4833
|
-
for (let id in ids) if (
|
|
4838
|
+
for (let id in ids) if (Object.prototype.hasOwnProperty.call(ids, id)) new_ids.push(id);
|
|
4834
4839
|
} else if (is_array(ids)) ids.forEach(function(item) {
|
|
4835
4840
|
if (is_string(item)) {
|
|
4836
4841
|
if (!empty_string(item)) new_ids.push(item);
|
|
@@ -5083,7 +5088,7 @@ function send_http_json_post(url, data, on_response) {
|
|
|
5083
5088
|
function _traverse_dict(obj, callback, full_path) {
|
|
5084
5089
|
if (full_path === void 0 || !is_string(full_path)) full_path = "";
|
|
5085
5090
|
for (let key of Object.keys(obj)) {
|
|
5086
|
-
if (!
|
|
5091
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
5087
5092
|
let sufix = (full_path.length ? "`" : "") + key;
|
|
5088
5093
|
full_path += sufix;
|
|
5089
5094
|
callback.apply(this, [
|
|
@@ -5190,11 +5195,11 @@ function jdb_update(jdb, topic_name, path, kw) {
|
|
|
5190
5195
|
}
|
|
5191
5196
|
if (ids.length === 0 && v) {
|
|
5192
5197
|
if (is_array(v)) v.push(kw);
|
|
5193
|
-
else if (v["id"] === kw["id"])
|
|
5198
|
+
else if (v["id"] === kw["id"]) json_object_update(v, kw);
|
|
5194
5199
|
else {
|
|
5195
5200
|
let v_ = kw_get_dict_value(null, v, jdb.hook, [], 1);
|
|
5196
5201
|
let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
|
|
5197
|
-
if (v__)
|
|
5202
|
+
if (v__) json_object_update(v__, kw);
|
|
5198
5203
|
else v_.push(kw);
|
|
5199
5204
|
}
|
|
5200
5205
|
}
|
|
@@ -5561,6 +5566,10 @@ parent: document.body
|
|
|
5561
5566
|
* as a bare string, or "<img src=x onerror=...>" runs.
|
|
5562
5567
|
* Pass it as a Text node, which is always text:
|
|
5563
5568
|
* ['span', {}, document.createTextNode(value)]
|
|
5569
|
+
* In a LIST of children a node (element, svg, Text) is
|
|
5570
|
+
* appended as it is and a string is always text -- but a
|
|
5571
|
+
* list whose first item is a string is read as ONE
|
|
5572
|
+
* description (the string is its tag).
|
|
5564
5573
|
* if attrs['i18n'] is not empty then (or 'data-i18n' or 'data_i18next')
|
|
5565
5574
|
* it will be overridden with the translation
|
|
5566
5575
|
* content = translate(attrs['i18n']));
|
|
@@ -5613,8 +5622,11 @@ function createElement2(description, translate_fn) {
|
|
|
5613
5622
|
} else if (is_array(content)) {
|
|
5614
5623
|
if (content.length > 0) {
|
|
5615
5624
|
if (is_string(content[0])) el.appendChild(createElement2(content, translate_fn));
|
|
5616
|
-
else for (let child of content) if (Array.isArray(child)
|
|
5617
|
-
|
|
5625
|
+
else for (let child of content) if (Array.isArray(child)) {
|
|
5626
|
+
if (child.length > 0) el.appendChild(createElement2(child, translate_fn));
|
|
5627
|
+
} else if (child instanceof Node) el.appendChild(child);
|
|
5628
|
+
else if (is_string(child)) el.appendChild(document.createTextNode(child));
|
|
5629
|
+
else if (child !== null && child !== void 0 && child !== false) log_error(`createElement2: child ignored, type ${typeof child}`);
|
|
5618
5630
|
}
|
|
5619
5631
|
} else if (content instanceof HTMLElement || content instanceof Text || content instanceof SVGElement) el.appendChild(content);
|
|
5620
5632
|
else if (content != null) {
|
|
@@ -5964,7 +5976,7 @@ function json2flat(jn) {
|
|
|
5964
5976
|
return;
|
|
5965
5977
|
}
|
|
5966
5978
|
if (depth === 0) return;
|
|
5967
|
-
flat
|
|
5979
|
+
set_own_key(flat, path, value);
|
|
5968
5980
|
};
|
|
5969
5981
|
if (jn === void 0 || jn === null) return flat;
|
|
5970
5982
|
walk(jn, "", 0);
|
|
@@ -6047,12 +6059,12 @@ function flat_diff(flat1, flat2) {
|
|
|
6047
6059
|
removed: {},
|
|
6048
6060
|
changed: {}
|
|
6049
6061
|
};
|
|
6050
|
-
for (const key of Object.keys(a)) if (!Object.prototype.hasOwnProperty.call(b, key)) diff.removed
|
|
6051
|
-
else if (!flat_value_equal(a[key], b[key])) diff.changed
|
|
6062
|
+
for (const key of Object.keys(a)) if (!Object.prototype.hasOwnProperty.call(b, key)) set_own_key(diff.removed, key, a[key]);
|
|
6063
|
+
else if (!flat_value_equal(a[key], b[key])) set_own_key(diff.changed, key, {
|
|
6052
6064
|
from: a[key],
|
|
6053
6065
|
to: b[key]
|
|
6054
|
-
};
|
|
6055
|
-
for (const key of Object.keys(b)) if (!Object.prototype.hasOwnProperty.call(a, key)) diff.added
|
|
6066
|
+
});
|
|
6067
|
+
for (const key of Object.keys(b)) if (!Object.prototype.hasOwnProperty.call(a, key)) set_own_key(diff.added, key, b[key]);
|
|
6056
6068
|
return diff;
|
|
6057
6069
|
}
|
|
6058
6070
|
/************************************************************
|
|
@@ -6066,11 +6078,11 @@ function flat_apply(flat, diff) {
|
|
|
6066
6078
|
if (flat === null || typeof flat !== "object" || Array.isArray(flat)) throw new Error("flat_apply: a flat json is an object of id -> value");
|
|
6067
6079
|
if (diff === null || typeof diff !== "object") throw new Error("flat_apply: a diff is the object flat_diff() answers");
|
|
6068
6080
|
for (const key of Object.keys(diff.removed || {})) delete flat[key];
|
|
6069
|
-
for (const key of Object.keys(diff.added || {})) flat
|
|
6081
|
+
for (const key of Object.keys(diff.added || {})) set_own_key(flat, key, diff.added[key]);
|
|
6070
6082
|
for (const key of Object.keys(diff.changed || {})) {
|
|
6071
6083
|
const change = diff.changed[key];
|
|
6072
6084
|
if (!change || !Object.prototype.hasOwnProperty.call(change, "to")) throw new Error(`flat_apply: changed '${key}' without a 'to'`);
|
|
6073
|
-
flat
|
|
6085
|
+
set_own_key(flat, key, change.to);
|
|
6074
6086
|
}
|
|
6075
6087
|
return flat;
|
|
6076
6088
|
}
|
|
@@ -7160,7 +7172,7 @@ function mt_inject_event(gobj, event, kw, src) {
|
|
|
7160
7172
|
window.console.error(`Not in session`);
|
|
7161
7173
|
return -1;
|
|
7162
7174
|
}
|
|
7163
|
-
kw =
|
|
7175
|
+
kw = json_object_update({}, is_object(kw) ? kw : {});
|
|
7164
7176
|
if (is_object(kw["__md_iev__"])) kw["__md_iev__"] = json_deep_copy(kw["__md_iev__"]);
|
|
7165
7177
|
if (msg_iev_get_stack(gobj, kw, IEVENT_STACK_ID)) {} else {
|
|
7166
7178
|
let jn_ievent_id = build_cli_ievent_request(gobj, gobj_name(src), kw_get_str(gobj, kw, "__service__", 0, 0));
|
|
@@ -7212,18 +7224,25 @@ function setup_websocket(gobj) {
|
|
|
7212
7224
|
if (gobj.priv.websocket) log_error(`Websocket ALREADY setup`);
|
|
7213
7225
|
const url = gobj_read_str_attr(gobj, "url");
|
|
7214
7226
|
log_debug(`====> Starting WebSocket to '${url}' (${gobj_short_name(gobj)})`);
|
|
7227
|
+
const ws_seq = ++gobj.priv.ws_seq;
|
|
7215
7228
|
let websocket;
|
|
7216
7229
|
try {
|
|
7217
7230
|
websocket = new WebSocket(url);
|
|
7218
7231
|
} catch (e) {
|
|
7219
7232
|
log_error(`${gobj_short_name(gobj)}: Cannot open WebSocket to '${url}', Error: ${e.message}`);
|
|
7233
|
+
gobj_post_event(gobj, "EV_ON_CLOSE", {
|
|
7234
|
+
url,
|
|
7235
|
+
ws_seq,
|
|
7236
|
+
code: 1006,
|
|
7237
|
+
reason: e.message,
|
|
7238
|
+
was_clean: false
|
|
7239
|
+
}, gobj);
|
|
7220
7240
|
return null;
|
|
7221
7241
|
}
|
|
7222
7242
|
if (!websocket) {
|
|
7223
7243
|
log_error(`${gobj_short_name(gobj)}: Failed to initialize WebSocket.`);
|
|
7224
7244
|
return null;
|
|
7225
7245
|
}
|
|
7226
|
-
const ws_seq = ++gobj.priv.ws_seq;
|
|
7227
7246
|
websocket.onopen = () => {
|
|
7228
7247
|
if (ws_seq !== gobj.priv.ws_seq || gobj_is_destroying(gobj)) return;
|
|
7229
7248
|
gobj_send_event(gobj, "EV_ON_OPEN", {
|
|
@@ -7476,6 +7495,7 @@ function ac_on_open(gobj, event, kw, src) {
|
|
|
7476
7495
|
function ac_on_close(gobj, event, kw, src) {
|
|
7477
7496
|
let priv = gobj.priv;
|
|
7478
7497
|
let url = kw.url;
|
|
7498
|
+
if (kw.ws_seq !== void 0 && kw.ws_seq !== priv.ws_seq) return 0;
|
|
7479
7499
|
set_remote_log_functions();
|
|
7480
7500
|
log_warning(`${gobj_short_name(gobj)}: WebSocket closed ${url} (Code: ${kw.code}, Reason: "${kw.reason}", Clean: ${kw.was_clean})`);
|
|
7481
7501
|
if (priv.websocket) {
|
|
@@ -7493,7 +7513,7 @@ function ac_on_close(gobj, event, kw, src) {
|
|
|
7493
7513
|
remote_yuno_role: priv.remote_yuno_role,
|
|
7494
7514
|
remote_yuno_service: priv.remote_yuno_service
|
|
7495
7515
|
});
|
|
7496
|
-
} else {
|
|
7516
|
+
} else if (!gobj_is_running(gobj)) {} else {
|
|
7497
7517
|
log_warning(`${gobj_short_name(gobj)}: EV_ON_OPEN_ERROR cannot open ${url} (Code: ${kw.code}, Reason: "${kw.reason}", Clean: ${kw.was_clean})`);
|
|
7498
7518
|
gobj_publish_event(gobj, "EV_ON_OPEN_ERROR", {
|
|
7499
7519
|
url,
|