@yuneta/gobj-js 7.26.13 → 7.26.15

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.
@@ -3282,13 +3282,20 @@ var gobjJs = (function(exports) {
3282
3282
  }
3283
3283
  /************************************************************
3284
3284
  * JSON.stringify for a log line: a circular object (a gobj,
3285
- * a DOM node) must not make the log call itself throw.
3285
+ * a DOM node), a BigInt or a toJSON() that throws must not make
3286
+ * the log call itself throw -- and neither must the fallback:
3287
+ * String() throws too, on an object with no prototype or with a
3288
+ * toString() that throws.
3286
3289
  ************************************************************/
3287
3290
  function log_stringify(v) {
3288
3291
  try {
3289
3292
  return JSON.stringify(v);
3290
3293
  } catch (e) {
3291
- return String(v);
3294
+ try {
3295
+ return String(v);
3296
+ } catch (e2) {
3297
+ return `<${typeof v}: not printable>`;
3298
+ }
3292
3299
  }
3293
3300
  }
3294
3301
  function format_log(format) {
@@ -4338,8 +4345,10 @@ var gobjJs = (function(exports) {
4338
4345
  /************************************************************
4339
4346
  * As the C kw_get_dict(): a dict found is the answer, and
4340
4347
  * 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
4348
+ * null). KW_CREATE stores a dict default, never a null one, and
4349
+ * replaces a null at the path; over another type it logs and
4350
+ * gives the default back unwritten (C returns NULL there, SDK
4351
+ * 7.26.9). Before gobj-js 7.25.2 the answer went through Object(), so a
4343
4352
  * null default came back as {} and a 0 as a Number object.
4344
4353
  ************************************************************/
4345
4354
  function kw_get_dict(gobj, kw, path, default_value, flag) {
@@ -4360,8 +4369,12 @@ var gobjJs = (function(exports) {
4360
4369
  return default_value;
4361
4370
  }
4362
4371
  if (!is_object(v)) {
4363
- if (required) {
4364
- log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'`);
4372
+ if (create && v === null && is_object(default_value)) {
4373
+ kw_set_dict_value(gobj, kw, path, default_value);
4374
+ return default_value;
4375
+ }
4376
+ if (required || create) {
4377
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'` + (create ? ", cannot create" : ""));
4365
4378
  trace_json_masked(kw);
4366
4379
  }
4367
4380
  return default_value;
@@ -4395,7 +4408,9 @@ var gobjJs = (function(exports) {
4395
4408
  /************************************************************
4396
4409
  * As the C kw_get_list(): a list found is the answer, and
4397
4410
  * anything else gives the default back AS GIVEN. KW_CREATE
4398
- * stores a list default, never a null one. Before gobj-js
4411
+ * stores a list default, never a null one, and replaces a null
4412
+ * at the path; over another type it logs and gives the default
4413
+ * back unwritten (C returns NULL there, SDK 7.26.9). Before gobj-js
4399
4414
  * 7.25.2 the answer went through Array(), which WRAPS its
4400
4415
  * argument: a list found came back as [list], a default of []
4401
4416
  * as [[]] and a null one as [null].
@@ -4418,8 +4433,12 @@ var gobjJs = (function(exports) {
4418
4433
  return default_value;
4419
4434
  }
4420
4435
  if (!is_array(v)) {
4421
- if (required) {
4422
- log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'`);
4436
+ if (create && v === null && is_array(default_value)) {
4437
+ kw_set_dict_value(gobj, kw, path, default_value);
4438
+ return default_value;
4439
+ }
4440
+ if (required || create) {
4441
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'` + (create ? ", cannot create" : ""));
4423
4442
  trace_json_masked(kw);
4424
4443
  }
4425
4444
  return default_value;
@@ -5252,7 +5271,7 @@ var gobjJs = (function(exports) {
5252
5271
  return null;
5253
5272
  }
5254
5273
  if (!is_object(kw) || empty_string(kw["id"])) {
5255
- log_error(`jdb_update: record without id: ${JSON.stringify(kw)}`);
5274
+ log_error(`jdb_update: record without id: ${log_stringify(kw)}`);
5256
5275
  return null;
5257
5276
  }
5258
5277
  if (!is_string(path)) {
@@ -5305,7 +5324,7 @@ var gobjJs = (function(exports) {
5305
5324
  return null;
5306
5325
  }
5307
5326
  if (!is_object(kw) || empty_string(kw["id"])) {
5308
- log_error(`jdb_delete: record without id: ${JSON.stringify(kw)}`);
5327
+ log_error(`jdb_delete: record without id: ${log_stringify(kw)}`);
5309
5328
  return null;
5310
5329
  }
5311
5330
  if (!is_string(path)) {