@yuneta/gobj-js 7.26.12 → 7.26.14

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.
@@ -4338,8 +4338,10 @@ var gobjJs = (function(exports) {
4338
4338
  /************************************************************
4339
4339
  * As the C kw_get_dict(): a dict found is the answer, and
4340
4340
  * anything else gives the default back AS GIVEN (null stays
4341
- * null). KW_CREATE stores a dict default, never a null one.
4342
- * Before gobj-js 7.25.2 the answer went through Object(), so a
4341
+ * null). KW_CREATE stores a dict default, never a null one, and
4342
+ * replaces a null at the path; over another type it logs and
4343
+ * gives the default back unwritten (C returns NULL there, SDK
4344
+ * 7.26.9). Before gobj-js 7.25.2 the answer went through Object(), so a
4343
4345
  * null default came back as {} and a 0 as a Number object.
4344
4346
  ************************************************************/
4345
4347
  function kw_get_dict(gobj, kw, path, default_value, flag) {
@@ -4360,8 +4362,12 @@ var gobjJs = (function(exports) {
4360
4362
  return default_value;
4361
4363
  }
4362
4364
  if (!is_object(v)) {
4363
- if (required) {
4364
- log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'`);
4365
+ if (create && v === null && is_object(default_value)) {
4366
+ kw_set_dict_value(gobj, kw, path, default_value);
4367
+ return default_value;
4368
+ }
4369
+ if (required || create) {
4370
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'` + (create ? ", cannot create" : ""));
4365
4371
  trace_json_masked(kw);
4366
4372
  }
4367
4373
  return default_value;
@@ -4395,7 +4401,9 @@ var gobjJs = (function(exports) {
4395
4401
  /************************************************************
4396
4402
  * As the C kw_get_list(): a list found is the answer, and
4397
4403
  * anything else gives the default back AS GIVEN. KW_CREATE
4398
- * stores a list default, never a null one. Before gobj-js
4404
+ * stores a list default, never a null one, and replaces a null
4405
+ * at the path; over another type it logs and gives the default
4406
+ * back unwritten (C returns NULL there, SDK 7.26.9). Before gobj-js
4399
4407
  * 7.25.2 the answer went through Array(), which WRAPS its
4400
4408
  * argument: a list found came back as [list], a default of []
4401
4409
  * as [[]] and a null one as [null].
@@ -4418,8 +4426,12 @@ var gobjJs = (function(exports) {
4418
4426
  return default_value;
4419
4427
  }
4420
4428
  if (!is_array(v)) {
4421
- if (required) {
4422
- log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'`);
4429
+ if (create && v === null && is_array(default_value)) {
4430
+ kw_set_dict_value(gobj, kw, path, default_value);
4431
+ return default_value;
4432
+ }
4433
+ if (required || create) {
4434
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'` + (create ? ", cannot create" : ""));
4423
4435
  trace_json_masked(kw);
4424
4436
  }
4425
4437
  return default_value;
@@ -4444,6 +4456,10 @@ var gobjJs = (function(exports) {
4444
4456
  log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): path empty`);
4445
4457
  return -1;
4446
4458
  }
4459
+ if (path.split("`").includes("")) {
4460
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): empty segment in path: '${path}'`);
4461
+ return -1;
4462
+ }
4447
4463
  let ss = path.split("`");
4448
4464
  let len = ss.length;
4449
4465
  for (let i = 0; i < len; i++) {
@@ -5239,6 +5255,17 @@ var gobjJs = (function(exports) {
5239
5255
  return jdb;
5240
5256
  }
5241
5257
  /********************************************
5258
+ * A value as json text for a log line: the error path must not throw
5259
+ * (a circular record, a BigInt).
5260
+ ********************************************/
5261
+ function safe_json_text(v) {
5262
+ try {
5263
+ return JSON.stringify(v);
5264
+ } catch (e) {
5265
+ return `<${typeof v}: not json (${e.message})>`;
5266
+ }
5267
+ }
5268
+ /********************************************
5242
5269
  *
5243
5270
  ********************************************/
5244
5271
  function jdb_update(jdb, topic_name, path, kw) {
@@ -5248,7 +5275,7 @@ var gobjJs = (function(exports) {
5248
5275
  return null;
5249
5276
  }
5250
5277
  if (!is_object(kw) || empty_string(kw["id"])) {
5251
- log_error(`jdb_update: record without id: ${JSON.stringify(kw)}`);
5278
+ log_error(`jdb_update: record without id: ${safe_json_text(kw)}`);
5252
5279
  return null;
5253
5280
  }
5254
5281
  if (!is_string(path)) {
@@ -5301,7 +5328,7 @@ var gobjJs = (function(exports) {
5301
5328
  return null;
5302
5329
  }
5303
5330
  if (!is_object(kw) || empty_string(kw["id"])) {
5304
- log_error(`jdb_delete: record without id: ${JSON.stringify(kw)}`);
5331
+ log_error(`jdb_delete: record without id: ${safe_json_text(kw)}`);
5305
5332
  return null;
5306
5333
  }
5307
5334
  if (!is_string(path)) {