@yuneta/gobj-js 7.26.9 → 7.26.11

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;
@@ -5257,19 +5261,31 @@ var gobjJs = (function(exports) {
5257
5261
  let v = topic;
5258
5262
  while (id = ids.shift()) {
5259
5263
  if (empty_string(id) || !v) break;
5260
- if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
5264
+ if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, null, 0);
5261
5265
  v = _jdb_get(v, null, id, false);
5262
5266
  }
5263
- if (ids.length === 0 && v) {
5264
- if (is_array(v)) v.push(kw);
5265
- else if (v["id"] === kw["id"]) json_object_update(v, kw);
5266
- else {
5267
- let v_ = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
5268
- let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
5269
- if (v__) json_object_update(v__, kw);
5270
- else v_.push(kw);
5267
+ if (!v || ids.length !== 0) {
5268
+ log_error(`jdb_update: path not found in topic '${topic_name}': '${path}'`);
5269
+ return null;
5270
+ }
5271
+ let list;
5272
+ if (is_array(v)) list = v;
5273
+ else if (v["id"] === kw["id"]) {
5274
+ json_object_update(v, kw);
5275
+ return topic;
5276
+ } else {
5277
+ list = kw_get_dict_value(null, v, jdb.hook, null, 0);
5278
+ if (list === null || list === void 0) {
5279
+ list = [];
5280
+ json_object_set(v, jdb.hook, list);
5281
+ } else if (!is_array(list)) {
5282
+ log_error(`jdb_update: the hook '${jdb.hook}' of '${path}' is not a list in topic '${topic_name}'`);
5283
+ return null;
5271
5284
  }
5272
5285
  }
5286
+ let found = _jdb_get(list, jdb.hook, kw["id"], false);
5287
+ if (found) json_object_update(found, kw);
5288
+ else list.push(kw);
5273
5289
  return topic;
5274
5290
  }
5275
5291
  /********************************************
@@ -5298,29 +5314,30 @@ var gobjJs = (function(exports) {
5298
5314
  if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, null, 0);
5299
5315
  v = _jdb_get(v, null, id, false);
5300
5316
  }
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
- }
5317
+ if (!v || ids.length !== 0) {
5318
+ log_error(`jdb_delete: path not found in topic '${topic_name}': '${path}'`);
5319
+ return null;
5320
+ }
5321
+ let list = is_array(v) ? v : kw_get_dict_value(null, v, jdb.hook, null, 0);
5322
+ let idx = id_index_in_obj_list(list, kw["id"]);
5323
+ if (idx < 0) {
5324
+ log_error(`jdb_delete: record not found in topic '${topic_name}': '${path}' '${kw["id"]}'`);
5325
+ return null;
5310
5326
  }
5327
+ list.splice(idx, 1);
5311
5328
  return topic;
5312
5329
  }
5313
5330
  /********************************************
5314
5331
  *
5315
5332
  ********************************************/
5316
5333
  function jdb_get_topic(jdb, topic_name) {
5317
- let topics = kw_get_dict_value(null, jdb, "topics", null, 0, false);
5334
+ let topics = kw_get_dict_value(null, jdb, "topics", null, 0);
5318
5335
  if (!topics) {
5319
5336
  log_error("jdb topics section not found");
5320
5337
  trace_msg(jdb);
5321
5338
  return null;
5322
5339
  }
5323
- let topic = kw_get_dict_value(null, topics, topic_name, null, 0, false);
5340
+ let topic = kw_get_dict_value(null, topics, topic_name, null, 0);
5324
5341
  if (!topic) {
5325
5342
  log_error("jdb topic not found: " + topic_name);
5326
5343
  trace_msg(topics);