@yuneta/gobj-js 7.26.8 → 7.26.9

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.
@@ -4465,6 +4465,26 @@ function kw_set_dict_value(gobj, kw, path, value) {
4465
4465
  return 0;
4466
4466
  }
4467
4467
  /************************************************************
4468
+ * Whether walking `path` meets a value that is neither a dict nor
4469
+ * a list BEFORE its last segment: kw_find_path() logs that one
4470
+ * even when it is not verbose, so a writer that goes on to
4471
+ * kw_set_dict_value() would log it a second time.
4472
+ ************************************************************/
4473
+ function path_crosses_a_scalar(kw, path) {
4474
+ let ss = path.split("`");
4475
+ let v = kw;
4476
+ for (let i = 0; i < ss.length - 1; i++) {
4477
+ if (is_array(v)) {
4478
+ const idx = list_segment_index(v, ss[i]);
4479
+ if (idx < 0) return false;
4480
+ v = v[idx];
4481
+ } else v = Object.prototype.hasOwnProperty.call(v, ss[i]) ? v[ss[i]] : void 0;
4482
+ if (v === void 0 || v === null) return false;
4483
+ if (!(is_object(v) || is_array(v))) return true;
4484
+ }
4485
+ return false;
4486
+ }
4487
+ /************************************************************
4468
4488
  *
4469
4489
  ************************************************************/
4470
4490
  function kw_set_subdict_value(gobj, kw, path, key, value) {
@@ -4475,7 +4495,7 @@ function kw_set_subdict_value(gobj, kw, path, key, value) {
4475
4495
  }
4476
4496
  let subdict = kw_find_path(gobj, kw, path, false);
4477
4497
  if (subdict === void 0) {
4478
- if (!is_string(path)) return -1;
4498
+ if (!is_string(path) || path_crosses_a_scalar(kw, path)) return -1;
4479
4499
  subdict = {};
4480
4500
  if (kw_set_dict_value(gobj, kw, path, subdict) < 0) return -1;
4481
4501
  }
@@ -5203,12 +5223,12 @@ jdb_init(jdb);
5203
5223
  ************************************************************/
5204
5224
  function jdb_init(jdb, prefix, duplicate) {
5205
5225
  if (duplicate) jdb = json_deep_copy(jdb);
5206
- let type = kw_get_dict_value(null, jdb, "type", [], 1);
5207
- kw_get_str(null, jdb, "hook", "data", 1);
5208
- let schema = kw_get_dict_value(null, jdb, "schema", {}, 1);
5209
- let topics = kw_get_dict_value(null, jdb, "topics", {}, 1);
5226
+ let type = kw_get_dict_value(null, jdb, "type", [], kw_flag_t.KW_CREATE);
5227
+ kw_get_str(null, jdb, "hook", "data", kw_flag_t.KW_CREATE);
5228
+ let schema = kw_get_dict_value(null, jdb, "schema", {}, kw_flag_t.KW_CREATE);
5229
+ let topics = kw_get_dict_value(null, jdb, "topics", {}, kw_flag_t.KW_CREATE);
5210
5230
  let walk = function(obj, key, value, full_path) {
5211
- if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type), 1);
5231
+ if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type), kw_flag_t.KW_CREATE);
5212
5232
  };
5213
5233
  _traverse_dict(schema, walk, prefix);
5214
5234
  return jdb;
@@ -5236,14 +5256,14 @@ function jdb_update(jdb, topic_name, path, kw) {
5236
5256
  let v = topic;
5237
5257
  while (id = ids.shift()) {
5238
5258
  if (empty_string(id) || !v) break;
5239
- if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], 1);
5259
+ if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
5240
5260
  v = _jdb_get(v, null, id, false);
5241
5261
  }
5242
5262
  if (ids.length === 0 && v) {
5243
5263
  if (is_array(v)) v.push(kw);
5244
5264
  else if (v["id"] === kw["id"]) json_object_update(v, kw);
5245
5265
  else {
5246
- let v_ = kw_get_dict_value(null, v, jdb.hook, [], 1);
5266
+ let v_ = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
5247
5267
  let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
5248
5268
  if (v__) json_object_update(v__, kw);
5249
5269
  else v_.push(kw);