@yuneta/gobj-js 7.16.5 → 7.21.0
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 +73 -14
- package/dist/gobj-js.cjs.js.map +1 -1
- package/dist/gobj-js.cjs.min.js +535 -518
- package/dist/gobj-js.cjs.min.js.map +1 -1
- package/dist/gobj-js.es.js +73 -15
- package/dist/gobj-js.es.js.map +1 -1
- package/dist/gobj-js.es.min.js +291 -273
- package/dist/gobj-js.es.min.js.map +1 -1
- package/dist/gobj-js.iife.js +73 -14
- package/dist/gobj-js.iife.js.map +1 -1
- package/dist/gobj-js.iife.min.js +658 -641
- package/dist/gobj-js.iife.min.js.map +1 -1
- package/dist/gobj-js.umd.js +73 -14
- package/dist/gobj-js.umd.js.map +1 -1
- package/dist/gobj-js.umd.min.js +765 -748
- package/dist/gobj-js.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/gobj-js.es.js
CHANGED
|
@@ -4020,10 +4020,18 @@ Being `kw` a:
|
|
|
4020
4020
|
- list of strings [s,...]
|
|
4021
4021
|
- list of dicts [{},...]
|
|
4022
4022
|
- dict of dicts {id:{},...}
|
|
4023
|
-
return a
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4023
|
+
return a NEW list holding the rows that match `ids` and the
|
|
4024
|
+
`jn_filter` (where). If match_fn is 0 then kw_match_simple is used.
|
|
4025
|
+
|
|
4026
|
+
WARNING the LIST is new; its elements are THE SAME objects, not
|
|
4027
|
+
copies. The C twin increfs each one and says "clone", which this
|
|
4028
|
+
comment repeated for years: javascript has no refcount, so a write
|
|
4029
|
+
through a collected row writes into `kw`. Copy what you mean to
|
|
4030
|
+
modify.
|
|
4031
|
+
|
|
4032
|
+
Returns null -- not an empty list -- for a `kw` that is neither a
|
|
4033
|
+
list nor a dict, so a caller that reads `.length` off the answer
|
|
4034
|
+
must check it first (kwid_find_one_record does).
|
|
4027
4035
|
*************************************************************/
|
|
4028
4036
|
function kwid_collect(gobj, kw, ids, jn_filter, match_fn) {
|
|
4029
4037
|
if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
|
|
@@ -4052,12 +4060,17 @@ function kwid_collect(gobj, kw, ids, jn_filter, match_fn) {
|
|
|
4052
4060
|
}
|
|
4053
4061
|
/*************************************************************
|
|
4054
4062
|
Utility for databases.
|
|
4055
|
-
Return a
|
|
4056
|
-
WARNING the "id" of a dict's record is
|
|
4063
|
+
Return a dict from a "dict of records" or "list of records".
|
|
4064
|
+
WARNING the "id" of a dict's record is hardcoded to its key.
|
|
4057
4065
|
Convention:
|
|
4058
|
-
- all arrays are
|
|
4066
|
+
- all arrays are lists of records (dicts) with "id" as primary key
|
|
4059
4067
|
- delimiter is '`' and '.'
|
|
4060
4068
|
If path is empty then use kw
|
|
4069
|
+
|
|
4070
|
+
WARNING "new" is the C twin's word, where it means a new REFERENCE:
|
|
4071
|
+
handed a dict, both return THAT dict and not a copy of it. Only the
|
|
4072
|
+
list case builds something new, and even then the records inside it
|
|
4073
|
+
are the same objects.
|
|
4061
4074
|
*************************************************************/
|
|
4062
4075
|
function kwid_new_dict(gobj, kw, path) {
|
|
4063
4076
|
if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
|
|
@@ -4066,20 +4079,59 @@ function kwid_new_dict(gobj, kw, path) {
|
|
|
4066
4079
|
if (is_object(kw)) new_dict = kw;
|
|
4067
4080
|
else if (is_array(kw)) for (let i = 0; i < kw.length; i++) {
|
|
4068
4081
|
let kv = kw[i];
|
|
4069
|
-
let id = kw_get_str(gobj, kv, "id", "",
|
|
4082
|
+
let id = kw_get_str(gobj, kv, "id", "", kw_flag_t.KW_REQUIRED);
|
|
4070
4083
|
if (!empty_string(id)) new_dict[id] = kv;
|
|
4071
4084
|
}
|
|
4072
4085
|
else log_error(`${gobj_short_name(gobj)} kwid_new_dict: data type unknown`);
|
|
4073
4086
|
return new_dict;
|
|
4074
4087
|
}
|
|
4075
4088
|
/*************************************************************
|
|
4089
|
+
Utility for databases.
|
|
4090
|
+
Return a list from a "dict of records" or "list of records".
|
|
4091
|
+
The NORMALIZING function of this family: whatever shape the data
|
|
4092
|
+
arrives in, what comes back is the shape a table indexed and
|
|
4093
|
+
sorted by `id` wants.
|
|
4094
|
+
Convention:
|
|
4095
|
+
- all arrays are lists of records (dicts) with "id" as primary key
|
|
4096
|
+
- delimiter is '`' and '.'
|
|
4097
|
+
If path is empty then use kw
|
|
4098
|
+
|
|
4099
|
+
WARNING handed a DICT it writes each record's key into the record
|
|
4100
|
+
as its `id`, OVERWRITING one that differs -- in the source records,
|
|
4101
|
+
which it does not copy. That is the C twin's behaviour
|
|
4102
|
+
(`json_object_set_new(v, "id", ...)` in kwid.c) and it is the point:
|
|
4103
|
+
a dict keyed by id whose records disagree with their own key is
|
|
4104
|
+
exactly what this is for. Handed a LIST it returns that same list,
|
|
4105
|
+
untouched, as C returns a new reference to it.
|
|
4106
|
+
*************************************************************/
|
|
4107
|
+
function kwid_new_list(gobj, kw, path) {
|
|
4108
|
+
if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
|
|
4109
|
+
if (!empty_string(path)) kw = kw_find_path(gobj, kw, path);
|
|
4110
|
+
if (is_array(kw)) return kw;
|
|
4111
|
+
if (is_object(kw)) {
|
|
4112
|
+
let new_list = [];
|
|
4113
|
+
for (let id of Object.keys(kw)) {
|
|
4114
|
+
let record = kw[id];
|
|
4115
|
+
if (!is_object(record)) {
|
|
4116
|
+
log_error(`${gobj_short_name(gobj)} kwid_new_list: not a record: '${id}'`);
|
|
4117
|
+
continue;
|
|
4118
|
+
}
|
|
4119
|
+
record["id"] = id;
|
|
4120
|
+
new_list.push(record);
|
|
4121
|
+
}
|
|
4122
|
+
return new_list;
|
|
4123
|
+
}
|
|
4124
|
+
log_error(`${gobj_short_name(gobj)} kwid_new_list: wrong type for list`);
|
|
4125
|
+
return [];
|
|
4126
|
+
}
|
|
4127
|
+
/*************************************************************
|
|
4076
4128
|
* Utility for databases. See kwid_collect parameters
|
|
4077
4129
|
*************************************************************/
|
|
4078
4130
|
function kwid_find_one_record(gobj, kw, ids, jn_filter, match_fn) {
|
|
4079
4131
|
if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
|
|
4080
4132
|
let list = kwid_collect(gobj, kw, ids, jn_filter, match_fn);
|
|
4081
|
-
if (list.length
|
|
4082
|
-
|
|
4133
|
+
if (!list || list.length === 0) return null;
|
|
4134
|
+
return list[0];
|
|
4083
4135
|
}
|
|
4084
4136
|
/*************************************************************
|
|
4085
4137
|
Utility for databases.
|
|
@@ -4944,7 +4996,13 @@ function refresh_language(element, t) {
|
|
|
4944
4996
|
return;
|
|
4945
4997
|
}
|
|
4946
4998
|
if (!element) element = document;
|
|
4947
|
-
|
|
4999
|
+
const matching = (selector) => {
|
|
5000
|
+
let out = [];
|
|
5001
|
+
if (typeof element.matches === "function" && element.matches(selector)) out.push(element);
|
|
5002
|
+
out.push(...element.querySelectorAll(selector));
|
|
5003
|
+
return out;
|
|
5004
|
+
};
|
|
5005
|
+
matching("[data-i18n]").forEach(function(elem) {
|
|
4948
5006
|
let value = elem.getAttribute("data-i18n");
|
|
4949
5007
|
for (let node of elem.childNodes) if (node.nodeType === Node.TEXT_NODE) {
|
|
4950
5008
|
if (!value) value = node.nodeValue;
|
|
@@ -4952,15 +5010,15 @@ function refresh_language(element, t) {
|
|
|
4952
5010
|
break;
|
|
4953
5011
|
}
|
|
4954
5012
|
});
|
|
4955
|
-
|
|
5013
|
+
matching("[data-i18n-title]").forEach(function(elem) {
|
|
4956
5014
|
let value = elem.getAttribute("data-i18n-title");
|
|
4957
5015
|
if (value) elem.setAttribute("title", t(value));
|
|
4958
5016
|
});
|
|
4959
|
-
|
|
5017
|
+
matching("[data-i18n-aria-label]").forEach(function(elem) {
|
|
4960
5018
|
let value = elem.getAttribute("data-i18n-aria-label");
|
|
4961
5019
|
if (value) elem.setAttribute("aria-label", t(value));
|
|
4962
5020
|
});
|
|
4963
|
-
|
|
5021
|
+
matching("[data-i18n-placeholder]").forEach(function(elem) {
|
|
4964
5022
|
let value = elem.getAttribute("data-i18n-placeholder");
|
|
4965
5023
|
if (value) elem.setAttribute("placeholder", t(value));
|
|
4966
5024
|
});
|
|
@@ -6900,6 +6958,6 @@ function register_c_ievent_cli() {
|
|
|
6900
6958
|
return create_gclass(GCLASS_NAME);
|
|
6901
6959
|
}
|
|
6902
6960
|
//#endregion
|
|
6903
|
-
export { GObj, SDATA, SDATAAUTHZ, SDATACM, SDATACM2, SDATADF, SDATAPM, SDATAPM0, SDATA_END, SDataDesc, YUNETA_VERSION, __yuno__, build_command_response, build_path, build_stats_response, clean_name, clear_timeout, cmp_two_simple_json, command_parser, createElement2, createOneHtml, create_json_record, create_template_record, current_timestamp, data_type_t, db_list_persistent_attrs, db_load_persistent_attrs, db_remove_persistent_attrs, db_save_persistent_attrs, debounce, delete_from_list, duplicate_objects, empty_json, empty_string, escapeHtml, event_flag_t, flat2json, flat_apply, flat_diff, flat_key_join, flat_key_split, gclass_add_ev_action, gclass_add_event_type, gclass_add_state, gclass_check_fsm, gclass_create, gclass_event_type, gclass_find_by_name, gclass_flag_t, gclass_unregister, getPositionRelativeToBody, get_function_name, get_now, gobj_bottom_gobj, gobj_change_parent, gobj_change_state, gobj_command, gobj_create, gobj_create2, gobj_create_default_service, gobj_create_pure_child, gobj_create_service, gobj_create_volatil, gobj_create_yuno, gobj_current_state, gobj_default_service, gobj_deliver_posted_events, gobj_destroy, gobj_find_child, gobj_find_gobj, gobj_find_service, gobj_find_subscribings, gobj_find_subscriptions, gobj_flag_t, gobj_full_name, gobj_gclass_name, gobj_global_trace_level, gobj_has_attr, gobj_has_event, gobj_has_output_event, gobj_hsdata, gobj_is_destroying, gobj_is_playing, gobj_is_pure_child, gobj_is_running, gobj_is_service, gobj_is_volatil, gobj_list_persistent_attrs, gobj_list_subscriptions, gobj_load_persistent_attrs, gobj_match_children, gobj_match_children_tree, gobj_match_gobj, gobj_name, gobj_parent, gobj_pause, gobj_play, gobj_post_event, gobj_posted_events_size, gobj_publish_event, gobj_read_attr, gobj_read_attrs, gobj_read_bool_attr, gobj_read_integer_attr, gobj_read_pointer_attr, gobj_read_str_attr, gobj_remove_persistent_attrs, gobj_repr_global_trace_levels, gobj_reset_volatil_attrs, gobj_save_persistent_attrs, gobj_search_path, gobj_send_event, gobj_services, gobj_set_bottom_gobj, gobj_set_deep_trace, gobj_set_gclass_no_trace, gobj_set_gclass_trace, gobj_set_global_no_trace, gobj_set_global_trace, gobj_set_gobj_no_trace, gobj_set_gobj_trace, gobj_set_trace_machine_format, gobj_short_name, gobj_start, gobj_start_children, gobj_start_tree, gobj_start_up, gobj_stats, gobj_stop, gobj_stop_children, gobj_stop_tree, gobj_subscribe_event, gobj_trace_level, gobj_trace_machine_format, gobj_trace_no_level, gobj_unsubscribe_event, gobj_unsubscribe_list, gobj_walk_gobj_children, gobj_walk_gobj_children_tree, gobj_write_attr, gobj_write_attrs, gobj_write_bool_attr, gobj_write_integer_attr, gobj_write_str_attr, gobj_yuno, gobj_yuno_id, gobj_yuno_name, gobj_yuno_role, id_index_in_obj_list, index_in_list, is_array, is_boolean, is_date, is_function, is_gobj, is_metadata_key, is_null, is_number, is_object, is_private_key, is_pure_number, is_string, jdb_delete, jdb_get, jdb_get_by_idx, jdb_get_topic, jdb_init, jdb_update, json2flat, json_array_append, json_array_append_new, json_array_extend, json_array_remove, json_array_size, json_deep_copy, json_is_identical, json_object_del, json_object_get, json_object_set, json_object_set_new, json_object_size, json_object_update, json_object_update_existing, json_object_update_missing, json_size, jwt2json, jwtDecode, kw_clone_by_keys, kw_clone_by_not_keys, kw_collect, kw_delete, kw_find_json_in_list, kw_find_path, kw_flag_t, kw_get_bool, kw_get_dict, kw_get_dict_value, kw_get_int, kw_get_list, kw_get_local_storage_value, kw_get_pointer, kw_get_real, kw_get_str, kw_has_key, kw_match_simple, kw_pop, kw_remove_local_storage_value, kw_select, kw_set_dict_value, kw_set_local_storage_value, kw_set_subdict_value, kwid_collect, kwid_find_one_record, kwid_get_ids, kwid_match_id, kwid_new_dict, list2options, load_json_file, log_debug, log_error, log_info, log_warning, msg_iev_get_msg_type, msg_iev_get_stack, msg_iev_push_stack, msg_iev_read_key, msg_iev_set_msg_type, msg_iev_write_key, node_uuid, parseBoolean, parseSVG, refresh_language, register_c_ievent_cli, register_c_timer, register_c_yuno, safeSrc, sdata_flag_t, send_http_json_post, set_console_log_enabled, set_console_log_filter, set_log_callback, set_remote_log_functions, set_timeout, set_timeout_periodic, sprintf, stats_parser, str_in_list, strcasecmp, strcmp, strncmp, strs_in_list, strstr, template_get_field_desc, timeTracker, trace_json, trace_level_t, trace_msg, treedb_decoder_fkey, treedb_decoder_hook, treedb_encoder_fkey, treedb_get_field_desc, treedb_hook_data_size, vsprintf, walk_type_t };
|
|
6961
|
+
export { GObj, SDATA, SDATAAUTHZ, SDATACM, SDATACM2, SDATADF, SDATAPM, SDATAPM0, SDATA_END, SDataDesc, YUNETA_VERSION, __yuno__, build_command_response, build_path, build_stats_response, clean_name, clear_timeout, cmp_two_simple_json, command_parser, createElement2, createOneHtml, create_json_record, create_template_record, current_timestamp, data_type_t, db_list_persistent_attrs, db_load_persistent_attrs, db_remove_persistent_attrs, db_save_persistent_attrs, debounce, delete_from_list, duplicate_objects, empty_json, empty_string, escapeHtml, event_flag_t, flat2json, flat_apply, flat_diff, flat_key_join, flat_key_split, gclass_add_ev_action, gclass_add_event_type, gclass_add_state, gclass_check_fsm, gclass_create, gclass_event_type, gclass_find_by_name, gclass_flag_t, gclass_unregister, getPositionRelativeToBody, get_function_name, get_now, gobj_bottom_gobj, gobj_change_parent, gobj_change_state, gobj_command, gobj_create, gobj_create2, gobj_create_default_service, gobj_create_pure_child, gobj_create_service, gobj_create_volatil, gobj_create_yuno, gobj_current_state, gobj_default_service, gobj_deliver_posted_events, gobj_destroy, gobj_find_child, gobj_find_gobj, gobj_find_service, gobj_find_subscribings, gobj_find_subscriptions, gobj_flag_t, gobj_full_name, gobj_gclass_name, gobj_global_trace_level, gobj_has_attr, gobj_has_event, gobj_has_output_event, gobj_hsdata, gobj_is_destroying, gobj_is_playing, gobj_is_pure_child, gobj_is_running, gobj_is_service, gobj_is_volatil, gobj_list_persistent_attrs, gobj_list_subscriptions, gobj_load_persistent_attrs, gobj_match_children, gobj_match_children_tree, gobj_match_gobj, gobj_name, gobj_parent, gobj_pause, gobj_play, gobj_post_event, gobj_posted_events_size, gobj_publish_event, gobj_read_attr, gobj_read_attrs, gobj_read_bool_attr, gobj_read_integer_attr, gobj_read_pointer_attr, gobj_read_str_attr, gobj_remove_persistent_attrs, gobj_repr_global_trace_levels, gobj_reset_volatil_attrs, gobj_save_persistent_attrs, gobj_search_path, gobj_send_event, gobj_services, gobj_set_bottom_gobj, gobj_set_deep_trace, gobj_set_gclass_no_trace, gobj_set_gclass_trace, gobj_set_global_no_trace, gobj_set_global_trace, gobj_set_gobj_no_trace, gobj_set_gobj_trace, gobj_set_trace_machine_format, gobj_short_name, gobj_start, gobj_start_children, gobj_start_tree, gobj_start_up, gobj_stats, gobj_stop, gobj_stop_children, gobj_stop_tree, gobj_subscribe_event, gobj_trace_level, gobj_trace_machine_format, gobj_trace_no_level, gobj_unsubscribe_event, gobj_unsubscribe_list, gobj_walk_gobj_children, gobj_walk_gobj_children_tree, gobj_write_attr, gobj_write_attrs, gobj_write_bool_attr, gobj_write_integer_attr, gobj_write_str_attr, gobj_yuno, gobj_yuno_id, gobj_yuno_name, gobj_yuno_role, id_index_in_obj_list, index_in_list, is_array, is_boolean, is_date, is_function, is_gobj, is_metadata_key, is_null, is_number, is_object, is_private_key, is_pure_number, is_string, jdb_delete, jdb_get, jdb_get_by_idx, jdb_get_topic, jdb_init, jdb_update, json2flat, json_array_append, json_array_append_new, json_array_extend, json_array_remove, json_array_size, json_deep_copy, json_is_identical, json_object_del, json_object_get, json_object_set, json_object_set_new, json_object_size, json_object_update, json_object_update_existing, json_object_update_missing, json_size, jwt2json, jwtDecode, kw_clone_by_keys, kw_clone_by_not_keys, kw_collect, kw_delete, kw_find_json_in_list, kw_find_path, kw_flag_t, kw_get_bool, kw_get_dict, kw_get_dict_value, kw_get_int, kw_get_list, kw_get_local_storage_value, kw_get_pointer, kw_get_real, kw_get_str, kw_has_key, kw_match_simple, kw_pop, kw_remove_local_storage_value, kw_select, kw_set_dict_value, kw_set_local_storage_value, kw_set_subdict_value, kwid_collect, kwid_find_one_record, kwid_get_ids, kwid_match_id, kwid_new_dict, kwid_new_list, list2options, load_json_file, log_debug, log_error, log_info, log_warning, msg_iev_get_msg_type, msg_iev_get_stack, msg_iev_push_stack, msg_iev_read_key, msg_iev_set_msg_type, msg_iev_write_key, node_uuid, parseBoolean, parseSVG, refresh_language, register_c_ievent_cli, register_c_timer, register_c_yuno, safeSrc, sdata_flag_t, send_http_json_post, set_console_log_enabled, set_console_log_filter, set_log_callback, set_remote_log_functions, set_timeout, set_timeout_periodic, sprintf, stats_parser, str_in_list, strcasecmp, strcmp, strncmp, strs_in_list, strstr, template_get_field_desc, timeTracker, trace_json, trace_level_t, trace_msg, treedb_decoder_fkey, treedb_decoder_hook, treedb_encoder_fkey, treedb_get_field_desc, treedb_hook_data_size, vsprintf, walk_type_t };
|
|
6904
6962
|
|
|
6905
6963
|
//# sourceMappingURL=gobj-js.es.js.map
|