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