@yuneta/gobj-js 7.26.10 → 7.26.12

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.
@@ -5249,37 +5249,48 @@
5249
5249
  log_error("jdb_update: topic not found: " + topic_name);
5250
5250
  return null;
5251
5251
  }
5252
- if (empty_string(kw["id"])) {
5253
- log_error("jdb_update: record without id: " + kw);
5254
- trace_msg(kw);
5252
+ if (!is_object(kw) || empty_string(kw["id"])) {
5253
+ log_error(`jdb_update: record without id: ${JSON.stringify(kw)}`);
5255
5254
  return null;
5256
5255
  }
5257
5256
  if (!is_string(path)) {
5258
5257
  log_error(`jdb_update: path must be a string: ${String(path)}`);
5259
5258
  return null;
5260
5259
  }
5260
+ if (path !== "" && path.split("`").includes("")) {
5261
+ log_error(`jdb_update: empty segment in path: '${path}'`);
5262
+ return null;
5263
+ }
5261
5264
  let ids = path.split("`");
5262
5265
  let id;
5263
5266
  let v = topic;
5264
5267
  while (id = ids.shift()) {
5265
5268
  if (empty_string(id) || !v) break;
5266
- if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
5269
+ if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, null, 0);
5267
5270
  v = _jdb_get(v, null, id, false);
5268
5271
  }
5269
5272
  if (!v || ids.length !== 0) {
5270
5273
  log_error(`jdb_update: path not found in topic '${topic_name}': '${path}'`);
5271
5274
  return null;
5272
5275
  }
5273
- if (ids.length === 0 && v) {
5274
- if (is_array(v)) v.push(kw);
5275
- else if (v["id"] === kw["id"]) json_object_update(v, kw);
5276
- else {
5277
- let v_ = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
5278
- let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
5279
- if (v__) json_object_update(v__, kw);
5280
- else v_.push(kw);
5276
+ let list;
5277
+ if (is_array(v)) list = v;
5278
+ else if (v["id"] === kw["id"]) {
5279
+ json_object_update(v, kw);
5280
+ return topic;
5281
+ } else {
5282
+ list = kw_get_dict_value(null, v, jdb.hook, null, 0);
5283
+ if (list === null || list === void 0) {
5284
+ list = [];
5285
+ json_object_set(v, jdb.hook, list);
5286
+ } else if (!is_array(list)) {
5287
+ log_error(`jdb_update: the hook '${jdb.hook}' of '${path}' is not a list in topic '${topic_name}'`);
5288
+ return null;
5281
5289
  }
5282
5290
  }
5291
+ let found = _jdb_get(list, jdb.hook, kw["id"], false);
5292
+ if (found) json_object_update(found, kw);
5293
+ else list.push(kw);
5283
5294
  return topic;
5284
5295
  }
5285
5296
  /********************************************
@@ -5291,15 +5302,18 @@
5291
5302
  log_error("jdb_delete: topic not found: " + topic_name);
5292
5303
  return null;
5293
5304
  }
5294
- if (empty_string(kw["id"])) {
5295
- log_error("jdb_delete: record without id: " + kw);
5296
- trace_msg(kw);
5305
+ if (!is_object(kw) || empty_string(kw["id"])) {
5306
+ log_error(`jdb_delete: record without id: ${JSON.stringify(kw)}`);
5297
5307
  return null;
5298
5308
  }
5299
5309
  if (!is_string(path)) {
5300
5310
  log_error(`jdb_delete: path must be a string: ${String(path)}`);
5301
5311
  return null;
5302
5312
  }
5313
+ if (path !== "" && path.split("`").includes("")) {
5314
+ log_error(`jdb_delete: empty segment in path: '${path}'`);
5315
+ return null;
5316
+ }
5303
5317
  let ids = path.split("`");
5304
5318
  let id;
5305
5319
  let v = topic;