@yuneta/gobj-js 7.26.7 → 7.26.9
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 +42 -9
- package/dist/gobj-js.cjs.js.map +1 -1
- package/dist/gobj-js.cjs.min.js +111 -93
- package/dist/gobj-js.cjs.min.js.map +1 -1
- package/dist/gobj-js.es.js +42 -9
- package/dist/gobj-js.es.js.map +1 -1
- package/dist/gobj-js.es.min.js +26 -8
- package/dist/gobj-js.es.min.js.map +1 -1
- package/dist/gobj-js.iife.js +42 -9
- package/dist/gobj-js.iife.js.map +1 -1
- package/dist/gobj-js.iife.min.js +168 -150
- package/dist/gobj-js.iife.min.js.map +1 -1
- package/dist/gobj-js.umd.js +42 -9
- package/dist/gobj-js.umd.js.map +1 -1
- package/dist/gobj-js.umd.min.js +168 -150
- package/dist/gobj-js.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/gobj-js.es.js
CHANGED
|
@@ -4464,6 +4464,26 @@ function kw_set_dict_value(gobj, kw, path, value) {
|
|
|
4464
4464
|
return 0;
|
|
4465
4465
|
}
|
|
4466
4466
|
/************************************************************
|
|
4467
|
+
* Whether walking `path` meets a value that is neither a dict nor
|
|
4468
|
+
* a list BEFORE its last segment: kw_find_path() logs that one
|
|
4469
|
+
* even when it is not verbose, so a writer that goes on to
|
|
4470
|
+
* kw_set_dict_value() would log it a second time.
|
|
4471
|
+
************************************************************/
|
|
4472
|
+
function path_crosses_a_scalar(kw, path) {
|
|
4473
|
+
let ss = path.split("`");
|
|
4474
|
+
let v = kw;
|
|
4475
|
+
for (let i = 0; i < ss.length - 1; i++) {
|
|
4476
|
+
if (is_array(v)) {
|
|
4477
|
+
const idx = list_segment_index(v, ss[i]);
|
|
4478
|
+
if (idx < 0) return false;
|
|
4479
|
+
v = v[idx];
|
|
4480
|
+
} else v = Object.prototype.hasOwnProperty.call(v, ss[i]) ? v[ss[i]] : void 0;
|
|
4481
|
+
if (v === void 0 || v === null) return false;
|
|
4482
|
+
if (!(is_object(v) || is_array(v))) return true;
|
|
4483
|
+
}
|
|
4484
|
+
return false;
|
|
4485
|
+
}
|
|
4486
|
+
/************************************************************
|
|
4467
4487
|
*
|
|
4468
4488
|
************************************************************/
|
|
4469
4489
|
function kw_set_subdict_value(gobj, kw, path, key, value) {
|
|
@@ -4472,9 +4492,14 @@ function kw_set_subdict_value(gobj, kw, path, key, value) {
|
|
|
4472
4492
|
log_error("kw is not an object");
|
|
4473
4493
|
return -1;
|
|
4474
4494
|
}
|
|
4475
|
-
let subdict =
|
|
4495
|
+
let subdict = kw_find_path(gobj, kw, path, false);
|
|
4496
|
+
if (subdict === void 0) {
|
|
4497
|
+
if (!is_string(path) || path_crosses_a_scalar(kw, path)) return -1;
|
|
4498
|
+
subdict = {};
|
|
4499
|
+
if (kw_set_dict_value(gobj, kw, path, subdict) < 0) return -1;
|
|
4500
|
+
}
|
|
4476
4501
|
if (!is_object(subdict)) {
|
|
4477
|
-
log_error(
|
|
4502
|
+
log_error(`subdict is not an object: '${path}'`);
|
|
4478
4503
|
return -1;
|
|
4479
4504
|
}
|
|
4480
4505
|
set_own_key(subdict, key, value);
|
|
@@ -5197,12 +5222,12 @@ jdb_init(jdb);
|
|
|
5197
5222
|
************************************************************/
|
|
5198
5223
|
function jdb_init(jdb, prefix, duplicate) {
|
|
5199
5224
|
if (duplicate) jdb = json_deep_copy(jdb);
|
|
5200
|
-
let type = kw_get_dict_value(null, jdb, "type", [],
|
|
5201
|
-
kw_get_str(null, jdb, "hook", "data",
|
|
5202
|
-
let schema = kw_get_dict_value(null, jdb, "schema", {},
|
|
5203
|
-
let topics = kw_get_dict_value(null, jdb, "topics", {},
|
|
5225
|
+
let type = kw_get_dict_value(null, jdb, "type", [], kw_flag_t.KW_CREATE);
|
|
5226
|
+
kw_get_str(null, jdb, "hook", "data", kw_flag_t.KW_CREATE);
|
|
5227
|
+
let schema = kw_get_dict_value(null, jdb, "schema", {}, kw_flag_t.KW_CREATE);
|
|
5228
|
+
let topics = kw_get_dict_value(null, jdb, "topics", {}, kw_flag_t.KW_CREATE);
|
|
5204
5229
|
let walk = function(obj, key, value, full_path) {
|
|
5205
|
-
if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type),
|
|
5230
|
+
if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type), kw_flag_t.KW_CREATE);
|
|
5206
5231
|
};
|
|
5207
5232
|
_traverse_dict(schema, walk, prefix);
|
|
5208
5233
|
return jdb;
|
|
@@ -5221,19 +5246,23 @@ function jdb_update(jdb, topic_name, path, kw) {
|
|
|
5221
5246
|
trace_msg(kw);
|
|
5222
5247
|
return null;
|
|
5223
5248
|
}
|
|
5249
|
+
if (!is_string(path)) {
|
|
5250
|
+
log_error(`jdb_update: path must be a string: ${String(path)}`);
|
|
5251
|
+
return null;
|
|
5252
|
+
}
|
|
5224
5253
|
let ids = path.split("`");
|
|
5225
5254
|
let id;
|
|
5226
5255
|
let v = topic;
|
|
5227
5256
|
while (id = ids.shift()) {
|
|
5228
5257
|
if (empty_string(id) || !v) break;
|
|
5229
|
-
if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [],
|
|
5258
|
+
if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
|
|
5230
5259
|
v = _jdb_get(v, null, id, false);
|
|
5231
5260
|
}
|
|
5232
5261
|
if (ids.length === 0 && v) {
|
|
5233
5262
|
if (is_array(v)) v.push(kw);
|
|
5234
5263
|
else if (v["id"] === kw["id"]) json_object_update(v, kw);
|
|
5235
5264
|
else {
|
|
5236
|
-
let v_ = kw_get_dict_value(null, v, jdb.hook, [],
|
|
5265
|
+
let v_ = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
|
|
5237
5266
|
let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
|
|
5238
5267
|
if (v__) json_object_update(v__, kw);
|
|
5239
5268
|
else v_.push(kw);
|
|
@@ -5255,6 +5284,10 @@ function jdb_delete(jdb, topic_name, path, kw) {
|
|
|
5255
5284
|
trace_msg(kw);
|
|
5256
5285
|
return null;
|
|
5257
5286
|
}
|
|
5287
|
+
if (!is_string(path)) {
|
|
5288
|
+
log_error(`jdb_delete: path must be a string: ${String(path)}`);
|
|
5289
|
+
return null;
|
|
5290
|
+
}
|
|
5258
5291
|
let ids = path.split("`");
|
|
5259
5292
|
let id;
|
|
5260
5293
|
let v = topic;
|