@yuneta/gobj-js 7.26.9 → 7.26.10

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.
@@ -4440,6 +4440,10 @@ var gobjJs = (function(exports) {
4440
4440
  log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): path must be a string: ${String(path)}`);
4441
4441
  return -1;
4442
4442
  }
4443
+ if (path === "") {
4444
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): path empty`);
4445
+ return -1;
4446
+ }
4443
4447
  let ss = path.split("`");
4444
4448
  let len = ss.length;
4445
4449
  for (let i = 0; i < len; i++) {
@@ -5229,7 +5233,7 @@ var gobjJs = (function(exports) {
5229
5233
  let schema = kw_get_dict_value(null, jdb, "schema", {}, kw_flag_t.KW_CREATE);
5230
5234
  let topics = kw_get_dict_value(null, jdb, "topics", {}, kw_flag_t.KW_CREATE);
5231
5235
  let walk = function(obj, key, value, full_path) {
5232
- if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type), kw_flag_t.KW_CREATE);
5236
+ if (key.substring(0, 2) !== "__" && !is_object(value)) kw_get_dict_value(null, topics, full_path, json_deep_copy(type), kw_flag_t.KW_CREATE);
5233
5237
  };
5234
5238
  _traverse_dict(schema, walk, prefix);
5235
5239
  return jdb;
@@ -5260,6 +5264,10 @@ var gobjJs = (function(exports) {
5260
5264
  if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
5261
5265
  v = _jdb_get(v, null, id, false);
5262
5266
  }
5267
+ if (!v || ids.length !== 0) {
5268
+ log_error(`jdb_update: path not found in topic '${topic_name}': '${path}'`);
5269
+ return null;
5270
+ }
5263
5271
  if (ids.length === 0 && v) {
5264
5272
  if (is_array(v)) v.push(kw);
5265
5273
  else if (v["id"] === kw["id"]) json_object_update(v, kw);
@@ -5298,29 +5306,30 @@ var gobjJs = (function(exports) {
5298
5306
  if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, null, 0);
5299
5307
  v = _jdb_get(v, null, id, false);
5300
5308
  }
5301
- if (ids.length === 0 && v) {
5302
- if (is_array(v)) {
5303
- let idx = id_index_in_obj_list(v, kw["id"]);
5304
- if (idx >= 0) v.splice(idx, 1);
5305
- } else {
5306
- let v_ = kw_get_dict_value(null, v, jdb.hook, null, 0);
5307
- let idx = id_index_in_obj_list(v_, kw["id"]);
5308
- if (idx >= 0) v_.splice(idx, 1);
5309
- }
5309
+ if (!v || ids.length !== 0) {
5310
+ log_error(`jdb_delete: path not found in topic '${topic_name}': '${path}'`);
5311
+ return null;
5312
+ }
5313
+ let list = is_array(v) ? v : kw_get_dict_value(null, v, jdb.hook, null, 0);
5314
+ let idx = id_index_in_obj_list(list, kw["id"]);
5315
+ if (idx < 0) {
5316
+ log_error(`jdb_delete: record not found in topic '${topic_name}': '${path}' '${kw["id"]}'`);
5317
+ return null;
5310
5318
  }
5319
+ list.splice(idx, 1);
5311
5320
  return topic;
5312
5321
  }
5313
5322
  /********************************************
5314
5323
  *
5315
5324
  ********************************************/
5316
5325
  function jdb_get_topic(jdb, topic_name) {
5317
- let topics = kw_get_dict_value(null, jdb, "topics", null, 0, false);
5326
+ let topics = kw_get_dict_value(null, jdb, "topics", null, 0);
5318
5327
  if (!topics) {
5319
5328
  log_error("jdb topics section not found");
5320
5329
  trace_msg(jdb);
5321
5330
  return null;
5322
5331
  }
5323
- let topic = kw_get_dict_value(null, topics, topic_name, null, 0, false);
5332
+ let topic = kw_get_dict_value(null, topics, topic_name, null, 0);
5324
5333
  if (!topic) {
5325
5334
  log_error("jdb topic not found: " + topic_name);
5326
5335
  trace_msg(topics);