@yuneta/gobj-js 7.26.8 → 7.26.10
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.
- package/dist/gobj-js.cjs.js +48 -19
- package/dist/gobj-js.cjs.js.map +1 -1
- package/dist/gobj-js.cjs.min.js +177 -168
- package/dist/gobj-js.cjs.min.js.map +1 -1
- package/dist/gobj-js.es.js +48 -19
- package/dist/gobj-js.es.js.map +1 -1
- package/dist/gobj-js.es.min.js +24 -15
- package/dist/gobj-js.es.min.js.map +1 -1
- package/dist/gobj-js.iife.js +48 -19
- package/dist/gobj-js.iife.js.map +1 -1
- package/dist/gobj-js.iife.min.js +166 -157
- package/dist/gobj-js.iife.min.js.map +1 -1
- package/dist/gobj-js.umd.js +48 -19
- package/dist/gobj-js.umd.js.map +1 -1
- package/dist/gobj-js.umd.min.js +24 -15
- package/dist/gobj-js.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/gobj-js.iife.js
CHANGED
|
@@ -4440,6 +4440,10 @@ var gobjJs = (function(exports) {
|
|
|
4440
4440
|
log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): path must be a string: ${String(path)}`);
|
|
4441
4441
|
return -1;
|
|
4442
4442
|
}
|
|
4443
|
+
if (path === "") {
|
|
4444
|
+
log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): path empty`);
|
|
4445
|
+
return -1;
|
|
4446
|
+
}
|
|
4443
4447
|
let ss = path.split("`");
|
|
4444
4448
|
let len = ss.length;
|
|
4445
4449
|
for (let i = 0; i < len; i++) {
|
|
@@ -4466,6 +4470,26 @@ var gobjJs = (function(exports) {
|
|
|
4466
4470
|
return 0;
|
|
4467
4471
|
}
|
|
4468
4472
|
/************************************************************
|
|
4473
|
+
* Whether walking `path` meets a value that is neither a dict nor
|
|
4474
|
+
* a list BEFORE its last segment: kw_find_path() logs that one
|
|
4475
|
+
* even when it is not verbose, so a writer that goes on to
|
|
4476
|
+
* kw_set_dict_value() would log it a second time.
|
|
4477
|
+
************************************************************/
|
|
4478
|
+
function path_crosses_a_scalar(kw, path) {
|
|
4479
|
+
let ss = path.split("`");
|
|
4480
|
+
let v = kw;
|
|
4481
|
+
for (let i = 0; i < ss.length - 1; i++) {
|
|
4482
|
+
if (is_array(v)) {
|
|
4483
|
+
const idx = list_segment_index(v, ss[i]);
|
|
4484
|
+
if (idx < 0) return false;
|
|
4485
|
+
v = v[idx];
|
|
4486
|
+
} else v = Object.prototype.hasOwnProperty.call(v, ss[i]) ? v[ss[i]] : void 0;
|
|
4487
|
+
if (v === void 0 || v === null) return false;
|
|
4488
|
+
if (!(is_object(v) || is_array(v))) return true;
|
|
4489
|
+
}
|
|
4490
|
+
return false;
|
|
4491
|
+
}
|
|
4492
|
+
/************************************************************
|
|
4469
4493
|
*
|
|
4470
4494
|
************************************************************/
|
|
4471
4495
|
function kw_set_subdict_value(gobj, kw, path, key, value) {
|
|
@@ -4476,7 +4500,7 @@ var gobjJs = (function(exports) {
|
|
|
4476
4500
|
}
|
|
4477
4501
|
let subdict = kw_find_path(gobj, kw, path, false);
|
|
4478
4502
|
if (subdict === void 0) {
|
|
4479
|
-
if (!is_string(path)) return -1;
|
|
4503
|
+
if (!is_string(path) || path_crosses_a_scalar(kw, path)) return -1;
|
|
4480
4504
|
subdict = {};
|
|
4481
4505
|
if (kw_set_dict_value(gobj, kw, path, subdict) < 0) return -1;
|
|
4482
4506
|
}
|
|
@@ -5204,12 +5228,12 @@ var gobjJs = (function(exports) {
|
|
|
5204
5228
|
************************************************************/
|
|
5205
5229
|
function jdb_init(jdb, prefix, duplicate) {
|
|
5206
5230
|
if (duplicate) jdb = json_deep_copy(jdb);
|
|
5207
|
-
let type = kw_get_dict_value(null, jdb, "type", [],
|
|
5208
|
-
kw_get_str(null, jdb, "hook", "data",
|
|
5209
|
-
let schema = kw_get_dict_value(null, jdb, "schema", {},
|
|
5210
|
-
let topics = kw_get_dict_value(null, jdb, "topics", {},
|
|
5231
|
+
let type = kw_get_dict_value(null, jdb, "type", [], kw_flag_t.KW_CREATE);
|
|
5232
|
+
kw_get_str(null, jdb, "hook", "data", kw_flag_t.KW_CREATE);
|
|
5233
|
+
let schema = kw_get_dict_value(null, jdb, "schema", {}, kw_flag_t.KW_CREATE);
|
|
5234
|
+
let topics = kw_get_dict_value(null, jdb, "topics", {}, kw_flag_t.KW_CREATE);
|
|
5211
5235
|
let walk = function(obj, key, value, full_path) {
|
|
5212
|
-
if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type),
|
|
5236
|
+
if (key.substring(0, 2) !== "__" && !is_object(value)) kw_get_dict_value(null, topics, full_path, json_deep_copy(type), kw_flag_t.KW_CREATE);
|
|
5213
5237
|
};
|
|
5214
5238
|
_traverse_dict(schema, walk, prefix);
|
|
5215
5239
|
return jdb;
|
|
@@ -5237,14 +5261,18 @@ var gobjJs = (function(exports) {
|
|
|
5237
5261
|
let v = topic;
|
|
5238
5262
|
while (id = ids.shift()) {
|
|
5239
5263
|
if (empty_string(id) || !v) break;
|
|
5240
|
-
if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [],
|
|
5264
|
+
if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
|
|
5241
5265
|
v = _jdb_get(v, null, id, false);
|
|
5242
5266
|
}
|
|
5267
|
+
if (!v || ids.length !== 0) {
|
|
5268
|
+
log_error(`jdb_update: path not found in topic '${topic_name}': '${path}'`);
|
|
5269
|
+
return null;
|
|
5270
|
+
}
|
|
5243
5271
|
if (ids.length === 0 && v) {
|
|
5244
5272
|
if (is_array(v)) v.push(kw);
|
|
5245
5273
|
else if (v["id"] === kw["id"]) json_object_update(v, kw);
|
|
5246
5274
|
else {
|
|
5247
|
-
let v_ = kw_get_dict_value(null, v, jdb.hook, [],
|
|
5275
|
+
let v_ = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
|
|
5248
5276
|
let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
|
|
5249
5277
|
if (v__) json_object_update(v__, kw);
|
|
5250
5278
|
else v_.push(kw);
|
|
@@ -5278,29 +5306,30 @@ var gobjJs = (function(exports) {
|
|
|
5278
5306
|
if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, null, 0);
|
|
5279
5307
|
v = _jdb_get(v, null, id, false);
|
|
5280
5308
|
}
|
|
5281
|
-
if (ids.length
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5309
|
+
if (!v || ids.length !== 0) {
|
|
5310
|
+
log_error(`jdb_delete: path not found in topic '${topic_name}': '${path}'`);
|
|
5311
|
+
return null;
|
|
5312
|
+
}
|
|
5313
|
+
let list = is_array(v) ? v : kw_get_dict_value(null, v, jdb.hook, null, 0);
|
|
5314
|
+
let idx = id_index_in_obj_list(list, kw["id"]);
|
|
5315
|
+
if (idx < 0) {
|
|
5316
|
+
log_error(`jdb_delete: record not found in topic '${topic_name}': '${path}' '${kw["id"]}'`);
|
|
5317
|
+
return null;
|
|
5290
5318
|
}
|
|
5319
|
+
list.splice(idx, 1);
|
|
5291
5320
|
return topic;
|
|
5292
5321
|
}
|
|
5293
5322
|
/********************************************
|
|
5294
5323
|
*
|
|
5295
5324
|
********************************************/
|
|
5296
5325
|
function jdb_get_topic(jdb, topic_name) {
|
|
5297
|
-
let topics = kw_get_dict_value(null, jdb, "topics", null, 0
|
|
5326
|
+
let topics = kw_get_dict_value(null, jdb, "topics", null, 0);
|
|
5298
5327
|
if (!topics) {
|
|
5299
5328
|
log_error("jdb topics section not found");
|
|
5300
5329
|
trace_msg(jdb);
|
|
5301
5330
|
return null;
|
|
5302
5331
|
}
|
|
5303
|
-
let topic = kw_get_dict_value(null, topics, topic_name, null, 0
|
|
5332
|
+
let topic = kw_get_dict_value(null, topics, topic_name, null, 0);
|
|
5304
5333
|
if (!topic) {
|
|
5305
5334
|
log_error("jdb topic not found: " + topic_name);
|
|
5306
5335
|
trace_msg(topics);
|