@yuneta/gobj-js 7.26.14 → 7.26.16

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,34 @@ 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) {
3294
+ try {
3295
+ return String(v);
3296
+ } catch (e2) {
3297
+ return `<${typeof v}: not printable>`;
3298
+ }
3299
+ }
3300
+ }
3301
+ function log_string(v) {
3302
+ try {
3291
3303
  return String(v);
3304
+ } catch (e) {
3305
+ return log_stringify(v);
3306
+ }
3307
+ }
3308
+ function log_number(parse, v) {
3309
+ try {
3310
+ return parse(v);
3311
+ } catch (e) {
3312
+ return log_string(v);
3292
3313
  }
3293
3314
  }
3294
3315
  function format_log(format) {
@@ -3300,18 +3321,18 @@ var gobjJs = (function(exports) {
3300
3321
  output = format.replace(/%[sdifoO]/g, (match) => {
3301
3322
  const val = args[i++];
3302
3323
  switch (match) {
3303
- case "%s": return String(val);
3324
+ case "%s": return log_string(val);
3304
3325
  case "%d":
3305
- case "%i": return parseInt(val);
3306
- case "%f": return parseFloat(val);
3326
+ case "%i": return log_number(parseInt, val);
3327
+ case "%f": return log_number(parseFloat, val);
3307
3328
  case "%o":
3308
- case "%O": return typeof val === "object" ? log_stringify(val) : String(val);
3329
+ case "%O": return typeof val === "object" ? log_stringify(val) : log_string(val);
3309
3330
  default: return match;
3310
3331
  }
3311
3332
  });
3312
- const rest = args.slice(i).map((arg) => typeof arg === "object" ? log_stringify(arg) : String(arg));
3333
+ const rest = args.slice(i).map((arg) => typeof arg === "object" ? log_stringify(arg) : log_string(arg));
3313
3334
  if (rest.length > 0) output += " " + rest.join(" ");
3314
- } else output = args.map((arg) => typeof arg === "object" ? log_stringify(arg) : String(arg)).join(" ");
3335
+ } else output = args.map((arg) => typeof arg === "object" ? log_stringify(arg) : log_string(arg)).join(" ");
3315
3336
  return output;
3316
3337
  }
3317
3338
  function log_error(format, ...args) {
@@ -4366,6 +4387,13 @@ var gobjJs = (function(exports) {
4366
4387
  kw_set_dict_value(gobj, kw, path, default_value);
4367
4388
  return default_value;
4368
4389
  }
4390
+ if (create && v === null) {
4391
+ if (required) {
4392
+ log_error(`path not found: '${path}'`);
4393
+ trace_json_masked(kw);
4394
+ }
4395
+ return default_value;
4396
+ }
4369
4397
  if (required || create) {
4370
4398
  log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'` + (create ? ", cannot create" : ""));
4371
4399
  trace_json_masked(kw);
@@ -4430,6 +4458,13 @@ var gobjJs = (function(exports) {
4430
4458
  kw_set_dict_value(gobj, kw, path, default_value);
4431
4459
  return default_value;
4432
4460
  }
4461
+ if (create && v === null) {
4462
+ if (required) {
4463
+ log_error(`path not found: '${path}'`);
4464
+ trace_json_masked(kw);
4465
+ }
4466
+ return default_value;
4467
+ }
4433
4468
  if (required || create) {
4434
4469
  log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'` + (create ? ", cannot create" : ""));
4435
4470
  trace_json_masked(kw);
@@ -4643,8 +4678,8 @@ var gobjJs = (function(exports) {
4643
4678
  ["$key1", "$key2", ...]
4644
4679
  {"$key1":*, "$key2":*, ...}
4645
4680
 
4646
- It's not a deep copy, new keys are the paths.
4647
- If paths are empty return kw
4681
+ It's not a deep copy. A key is a KEY, not a path (as C, SDK 7.26.9).
4682
+ If keys are empty return kw
4648
4683
  *************************************************************/
4649
4684
  function kw_clone_by_keys(gobj, kw, keys, verbose) {
4650
4685
  if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
@@ -4671,8 +4706,8 @@ var gobjJs = (function(exports) {
4671
4706
  ["$key1", "$key2", ...]
4672
4707
  {"$key1":*, "$key2":*, ...}
4673
4708
 
4674
- It's not a deep copy, new keys are the paths.
4675
- If paths are empty return empty
4709
+ It's not a deep copy. A key is a KEY, not a path (as C, SDK 7.26.9).
4710
+ If keys are empty return empty
4676
4711
  ***************************************************************************/
4677
4712
  function kw_clone_by_not_keys(gobj, kw, keys, verbose) {
4678
4713
  let kw_clone = {};
@@ -5255,17 +5290,6 @@ var gobjJs = (function(exports) {
5255
5290
  return jdb;
5256
5291
  }
5257
5292
  /********************************************
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
- /********************************************
5269
5293
  *
5270
5294
  ********************************************/
5271
5295
  function jdb_update(jdb, topic_name, path, kw) {
@@ -5275,7 +5299,7 @@ var gobjJs = (function(exports) {
5275
5299
  return null;
5276
5300
  }
5277
5301
  if (!is_object(kw) || empty_string(kw["id"])) {
5278
- log_error(`jdb_update: record without id: ${safe_json_text(kw)}`);
5302
+ log_error(`jdb_update: record without id: ${log_stringify(kw)}`);
5279
5303
  return null;
5280
5304
  }
5281
5305
  if (!is_string(path)) {
@@ -5328,7 +5352,7 @@ var gobjJs = (function(exports) {
5328
5352
  return null;
5329
5353
  }
5330
5354
  if (!is_object(kw) || empty_string(kw["id"])) {
5331
- log_error(`jdb_delete: record without id: ${safe_json_text(kw)}`);
5355
+ log_error(`jdb_delete: record without id: ${log_stringify(kw)}`);
5332
5356
  return null;
5333
5357
  }
5334
5358
  if (!is_string(path)) {