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