@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.umd.js
CHANGED
|
@@ -4468,6 +4468,26 @@
|
|
|
4468
4468
|
return 0;
|
|
4469
4469
|
}
|
|
4470
4470
|
/************************************************************
|
|
4471
|
+
* Whether walking `path` meets a value that is neither a dict nor
|
|
4472
|
+
* a list BEFORE its last segment: kw_find_path() logs that one
|
|
4473
|
+
* even when it is not verbose, so a writer that goes on to
|
|
4474
|
+
* kw_set_dict_value() would log it a second time.
|
|
4475
|
+
************************************************************/
|
|
4476
|
+
function path_crosses_a_scalar(kw, path) {
|
|
4477
|
+
let ss = path.split("`");
|
|
4478
|
+
let v = kw;
|
|
4479
|
+
for (let i = 0; i < ss.length - 1; i++) {
|
|
4480
|
+
if (is_array(v)) {
|
|
4481
|
+
const idx = list_segment_index(v, ss[i]);
|
|
4482
|
+
if (idx < 0) return false;
|
|
4483
|
+
v = v[idx];
|
|
4484
|
+
} else v = Object.prototype.hasOwnProperty.call(v, ss[i]) ? v[ss[i]] : void 0;
|
|
4485
|
+
if (v === void 0 || v === null) return false;
|
|
4486
|
+
if (!(is_object(v) || is_array(v))) return true;
|
|
4487
|
+
}
|
|
4488
|
+
return false;
|
|
4489
|
+
}
|
|
4490
|
+
/************************************************************
|
|
4471
4491
|
*
|
|
4472
4492
|
************************************************************/
|
|
4473
4493
|
function kw_set_subdict_value(gobj, kw, path, key, value) {
|
|
@@ -4476,9 +4496,14 @@
|
|
|
4476
4496
|
log_error("kw is not an object");
|
|
4477
4497
|
return -1;
|
|
4478
4498
|
}
|
|
4479
|
-
let subdict =
|
|
4499
|
+
let subdict = kw_find_path(gobj, kw, path, false);
|
|
4500
|
+
if (subdict === void 0) {
|
|
4501
|
+
if (!is_string(path) || path_crosses_a_scalar(kw, path)) return -1;
|
|
4502
|
+
subdict = {};
|
|
4503
|
+
if (kw_set_dict_value(gobj, kw, path, subdict) < 0) return -1;
|
|
4504
|
+
}
|
|
4480
4505
|
if (!is_object(subdict)) {
|
|
4481
|
-
log_error(
|
|
4506
|
+
log_error(`subdict is not an object: '${path}'`);
|
|
4482
4507
|
return -1;
|
|
4483
4508
|
}
|
|
4484
4509
|
set_own_key(subdict, key, value);
|
|
@@ -5201,12 +5226,12 @@
|
|
|
5201
5226
|
************************************************************/
|
|
5202
5227
|
function jdb_init(jdb, prefix, duplicate) {
|
|
5203
5228
|
if (duplicate) jdb = json_deep_copy(jdb);
|
|
5204
|
-
let type = kw_get_dict_value(null, jdb, "type", [],
|
|
5205
|
-
kw_get_str(null, jdb, "hook", "data",
|
|
5206
|
-
let schema = kw_get_dict_value(null, jdb, "schema", {},
|
|
5207
|
-
let topics = kw_get_dict_value(null, jdb, "topics", {},
|
|
5229
|
+
let type = kw_get_dict_value(null, jdb, "type", [], kw_flag_t.KW_CREATE);
|
|
5230
|
+
kw_get_str(null, jdb, "hook", "data", kw_flag_t.KW_CREATE);
|
|
5231
|
+
let schema = kw_get_dict_value(null, jdb, "schema", {}, kw_flag_t.KW_CREATE);
|
|
5232
|
+
let topics = kw_get_dict_value(null, jdb, "topics", {}, kw_flag_t.KW_CREATE);
|
|
5208
5233
|
let walk = function(obj, key, value, full_path) {
|
|
5209
|
-
if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type),
|
|
5234
|
+
if (key.substring(0, 2) !== "__") kw_get_dict_value(null, topics, full_path, json_deep_copy(type), kw_flag_t.KW_CREATE);
|
|
5210
5235
|
};
|
|
5211
5236
|
_traverse_dict(schema, walk, prefix);
|
|
5212
5237
|
return jdb;
|
|
@@ -5225,19 +5250,23 @@
|
|
|
5225
5250
|
trace_msg(kw);
|
|
5226
5251
|
return null;
|
|
5227
5252
|
}
|
|
5253
|
+
if (!is_string(path)) {
|
|
5254
|
+
log_error(`jdb_update: path must be a string: ${String(path)}`);
|
|
5255
|
+
return null;
|
|
5256
|
+
}
|
|
5228
5257
|
let ids = path.split("`");
|
|
5229
5258
|
let id;
|
|
5230
5259
|
let v = topic;
|
|
5231
5260
|
while (id = ids.shift()) {
|
|
5232
5261
|
if (empty_string(id) || !v) break;
|
|
5233
|
-
if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [],
|
|
5262
|
+
if (is_object(v)) v = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
|
|
5234
5263
|
v = _jdb_get(v, null, id, false);
|
|
5235
5264
|
}
|
|
5236
5265
|
if (ids.length === 0 && v) {
|
|
5237
5266
|
if (is_array(v)) v.push(kw);
|
|
5238
5267
|
else if (v["id"] === kw["id"]) json_object_update(v, kw);
|
|
5239
5268
|
else {
|
|
5240
|
-
let v_ = kw_get_dict_value(null, v, jdb.hook, [],
|
|
5269
|
+
let v_ = kw_get_dict_value(null, v, jdb.hook, [], kw_flag_t.KW_CREATE);
|
|
5241
5270
|
let v__ = _jdb_get(v_, jdb.hook, kw["id"], false);
|
|
5242
5271
|
if (v__) json_object_update(v__, kw);
|
|
5243
5272
|
else v_.push(kw);
|
|
@@ -5259,6 +5288,10 @@
|
|
|
5259
5288
|
trace_msg(kw);
|
|
5260
5289
|
return null;
|
|
5261
5290
|
}
|
|
5291
|
+
if (!is_string(path)) {
|
|
5292
|
+
log_error(`jdb_delete: path must be a string: ${String(path)}`);
|
|
5293
|
+
return null;
|
|
5294
|
+
}
|
|
5262
5295
|
let ids = path.split("`");
|
|
5263
5296
|
let id;
|
|
5264
5297
|
let v = topic;
|