@yuneta/gobj-ui 7.25.25 → 7.26.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.
@@ -23806,6 +23806,8 @@ function mt_create$6(gobj) {
23806
23806
  gobj.priv.reread_on_session = false;
23807
23807
  gobj.priv.conn_shell = null;
23808
23808
  gobj.priv.drills_in_flight = /* @__PURE__ */ new Set();
23809
+ gobj.priv.parent_rereads = /* @__PURE__ */ new Map();
23810
+ gobj.priv.reread_seq = 0;
23809
23811
  build_ui$6(gobj);
23810
23812
  let subscriber = (0, _yuneta_gobj_js.gobj_read_pointer_attr)(gobj, "subscriber");
23811
23813
  if (!subscriber) subscriber = (0, _yuneta_gobj_js.gobj_parent)(gobj);
@@ -24914,6 +24916,13 @@ function subscribe_treedb$1(gobj, topic_name) {
24914
24916
  "topic_name": topic_name
24915
24917
  }
24916
24918
  }, gobj);
24919
+ for (let event of ["EV_TREEDB_NODE_LINKED", "EV_TREEDB_NODE_UNLINKED"]) (0, _yuneta_gobj_js.gobj_subscribe_event)(gobj_remote_yuno, event, {
24920
+ __service__: treedb_name,
24921
+ __filter__: {
24922
+ "treedb_name": treedb_name,
24923
+ "parent_topic_name": topic_name
24924
+ }
24925
+ }, gobj);
24917
24926
  }
24918
24927
  /********************************************
24919
24928
  *
@@ -24964,6 +24973,119 @@ function answered_record$1(data) {
24964
24973
  return {};
24965
24974
  }
24966
24975
  /************************************************************
24976
+ * Command to remote service: one node, in the shape the table
24977
+ * reads its topic with (TABLE_READ_OPTIONS)
24978
+ ************************************************************/
24979
+ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id, reread_seq) {
24980
+ let gobj_remote_yuno = (0, _yuneta_gobj_js.gobj_read_pointer_attr)(gobj, "gobj_remote_yuno");
24981
+ let kw = {
24982
+ service: treedb_name,
24983
+ treedb_name,
24984
+ topic_name,
24985
+ node_id,
24986
+ options: Object.assign({}, TABLE_READ_OPTIONS)
24987
+ };
24988
+ kw.__md_command__ = {
24989
+ topic_name,
24990
+ node_id,
24991
+ reread_seq
24992
+ };
24993
+ let ret = (0, _yuneta_gobj_js.gobj_command)(gobj_remote_yuno, "node", kw, gobj);
24994
+ if (ret) {
24995
+ (0, _yuneta_gobj_js.log_error)(ret);
24996
+ return -1;
24997
+ }
24998
+ return 0;
24999
+ }
25000
+ /************************************************************
25001
+ * Is the row of `node_id` loaded in the table of its topic?
25002
+ * A table not open, or open on other rows (a page that does
25003
+ * not hold it), shows nothing of the node: there is nothing to
25004
+ * refresh, its rows are read when they are shown.
25005
+ ************************************************************/
25006
+ function is_row_loaded(gobj, topic_name, node_id) {
25007
+ let gobj_formtable = get_gobj_formtable(gobj, topic_name);
25008
+ if (!gobj_formtable) return false;
25009
+ let tabulator = (0, _yuneta_gobj_js.gobj_read_attr)(gobj_formtable, "tabulator");
25010
+ if (!tabulator) return false;
25011
+ return !!tabulator.getRow(node_id);
25012
+ }
25013
+ /************************************************************
25014
+ * Read again a parent whose hook a link or an unlink moved
25015
+ * (ac_treedb_node_linked), ONE read in flight per parent: a
25016
+ * link that comes while it is out only marks it dirty, and
25017
+ * its answer asks once more (answer_linked_parent_reread).
25018
+ * A burst of links to one parent costs two reads of it, not
25019
+ * one per link -- each read is the parent with every child.
25020
+ * Each request carries its `seq`: only its own answer settles
25021
+ * the entry.
25022
+ ************************************************************/
25023
+ function reread_linked_parent(gobj, treedb_name, topic_name, node_id) {
25024
+ let priv = gobj.priv;
25025
+ let key = `${topic_name}\u0000${node_id}`;
25026
+ let in_flight = priv.parent_rereads.get(key);
25027
+ if (in_flight) {
25028
+ in_flight.dirty = true;
25029
+ return 0;
25030
+ }
25031
+ let seq = ++priv.reread_seq;
25032
+ priv.parent_rereads.set(key, {
25033
+ dirty: false,
25034
+ seq
25035
+ });
25036
+ let ret = treedb_get_node$1(gobj, treedb_name, topic_name, node_id, seq);
25037
+ if (ret < 0) priv.parent_rereads.delete(key);
25038
+ return ret;
25039
+ }
25040
+ /************************************************************
25041
+ * A whole read of a topic brought every row as it is now: the
25042
+ * re-reads of its parents still out have nothing to add, and
25043
+ * their answers, when they come, are not taken. It is also
25044
+ * what bounds an entry whose answer never comes on a live
25045
+ * session (a request lost by the backend): the drop clears
25046
+ * every entry (ac_transport_state), the next read of the
25047
+ * topic (its refresh, its open, the reconnect) clears its own.
25048
+ ************************************************************/
25049
+ function forget_topic_rereads(gobj, topic_name) {
25050
+ let prefix = `${topic_name}\u0000`;
25051
+ for (const key of Array.from(gobj.priv.parent_rereads.keys())) if (key.startsWith(prefix)) gobj.priv.parent_rereads.delete(key);
25052
+ }
25053
+ /************************************************************
25054
+ * The answer of a parent's re-read. It is a refresh nobody
25055
+ * asked for, so a failure is a warning, never the app's error
25056
+ * modal: a force-delete of a loaded parent publishes UNLINKED
25057
+ * per child, and the re-read reaches the backend after the
25058
+ * delete ("Node not found") -- in every open viewer.
25059
+ *
25060
+ * Only the answer of the request in flight counts: one cut by
25061
+ * a drop, or superseded by a whole read of the topic, that
25062
+ * arrives after a new request went out must neither settle
25063
+ * the new one nor update the row with older data.
25064
+ *
25065
+ * Then, if links came while it was out, the parent is read
25066
+ * once more -- when its row is still loaded.
25067
+ ************************************************************/
25068
+ function answer_linked_parent_reread(gobj, result, comment, data, kw_command) {
25069
+ let priv = gobj.priv;
25070
+ let topic_name = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw_command, "topic_name", "", 0);
25071
+ let node_id = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw_command, "node_id", "", 0);
25072
+ let seq = (0, _yuneta_gobj_js.kw_get_int)(gobj, kw_command, "reread_seq", 0, 0);
25073
+ let key = `${topic_name}\u0000${node_id}`;
25074
+ let in_flight = priv.parent_rereads.get(key);
25075
+ if (!in_flight || in_flight.seq !== seq) {
25076
+ if (result < 0) (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: late failure of the re-read of the linked parent '${topic_name}^${node_id}' dropped, it was settled already (a drop, or a whole read of the topic): ${comment || ""}`);
25077
+ return 0;
25078
+ }
25079
+ priv.parent_rereads.delete(key);
25080
+ if (result < 0) (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: the re-read of the linked parent '${topic_name}^${node_id}' failed: ${comment || ""}`);
25081
+ else {
25082
+ let gobj_formtable = get_gobj_formtable(gobj, topic_name);
25083
+ if (gobj_formtable) (0, _yuneta_gobj_js.gobj_send_event)(gobj_formtable, "EV_LOAD_NODE_UPDATED", [data], gobj);
25084
+ }
25085
+ if (in_flight.dirty && is_connected$1(gobj) && is_row_loaded(gobj, topic_name, node_id)) reread_linked_parent(gobj, (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "treedb_name"), topic_name, node_id);
25086
+ return 0;
25087
+ }
25088
+ /************************************************************
24967
25089
  * Command to remote service
24968
25090
  ************************************************************/
24969
25091
  function treedb_update_node$1(gobj, treedb_name, topic_name, record, options, form_write, created) {
@@ -25295,6 +25417,7 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25295
25417
  }, gobj);
25296
25418
  return 0;
25297
25419
  }
25420
+ if (command === "node") return answer_linked_parent_reread(gobj, result, comment, data, kw_command);
25298
25421
  if (result < 0) {
25299
25422
  if (command === "descs") show_load_error$1(gobj, (0, i18next.t)(comment));
25300
25423
  else {
@@ -25328,13 +25451,18 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25328
25451
  let answer = nodes_answer(data);
25329
25452
  let req_id = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw_command, "req_id", "", 0);
25330
25453
  if ((0, _yuneta_gobj_js.kw_get_str)(gobj, kw_command, "purpose", "", 0) === "json") (0, _yuneta_gobj_js.gobj_send_event)(gobj_topic_form, "EV_JSON_LOADED", { rows: answer.rows }, gobj);
25331
- else if (req_id) (0, _yuneta_gobj_js.gobj_send_event)(gobj_topic_form, "EV_PAGE_LOADED", {
25332
- req_id,
25333
- rows: answer.rows,
25334
- pages: answer.pages,
25335
- total: answer.total
25336
- }, gobj);
25337
- else (0, _yuneta_gobj_js.gobj_send_event)(gobj_topic_form, "EV_LOAD_NODES", answer.rows, gobj);
25454
+ else if (req_id) {
25455
+ forget_topic_rereads(gobj, topic_name);
25456
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj_topic_form, "EV_PAGE_LOADED", {
25457
+ req_id,
25458
+ rows: answer.rows,
25459
+ pages: answer.pages,
25460
+ total: answer.total
25461
+ }, gobj);
25462
+ } else {
25463
+ forget_topic_rereads(gobj, topic_name);
25464
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj_topic_form, "EV_LOAD_NODES", answer.rows, gobj);
25465
+ }
25338
25466
  }
25339
25467
  break;
25340
25468
  case "create-node":
@@ -25510,6 +25638,7 @@ function ac_transport_state$2(gobj, event, kw, src) {
25510
25638
  refresh_toolbar_buttons(gobj, connected);
25511
25639
  if (!connected) {
25512
25640
  gobj.priv.reread_on_session = true;
25641
+ gobj.priv.parent_rereads.clear();
25513
25642
  answer_drills_in_flight$1(gobj);
25514
25643
  abandon_form_writes(gobj.priv.form_writes).forEach((w) => {
25515
25644
  (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: transport closed, the write ${w.form_write} of '${w.topic_name}' is lost`);
@@ -25583,6 +25712,27 @@ function ac_treedb_node_updated$1(gobj, event, kw, src) {
25583
25712
  }
25584
25713
  /********************************************
25585
25714
  * Remote subscription response
25715
+ * EV_TREEDB_NODE_LINKED / EV_TREEDB_NODE_UNLINKED: the relationship
25716
+ * ({hook_name, parent_topic_name, child_topic_name, parent_id,
25717
+ * child_id, treedb_name}), not a node. The parent's hook changed and
25718
+ * the event does not carry it: read the parent again -- only when its
25719
+ * row is loaded (a table not open, or on another page, has nothing to
25720
+ * refresh), and one read in flight per parent (reread_linked_parent).
25721
+ ********************************************/
25722
+ function ac_treedb_node_linked$1(gobj, event, kw, src) {
25723
+ let treedb_name = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "treedb_name", "", 0);
25724
+ let parent_topic_name = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "parent_topic_name", "", 0);
25725
+ let parent_id = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "parent_id", "", 0);
25726
+ if (treedb_name !== (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "treedb_name")) return 0;
25727
+ if (!parent_topic_name || !parent_id) {
25728
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: ${event} without parent_topic_name/parent_id`);
25729
+ return -1;
25730
+ }
25731
+ if (!is_row_loaded(gobj, parent_topic_name, parent_id)) return 0;
25732
+ return reread_linked_parent(gobj, treedb_name, parent_topic_name, parent_id);
25733
+ }
25734
+ /********************************************
25735
+ * Remote subscription response
25586
25736
  ********************************************/
25587
25737
  function ac_treedb_node_deleted$1(gobj, event, kw, src) {
25588
25738
  let treedb_name = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "treedb_name", "", 0);
@@ -25952,6 +26102,16 @@ function create_gclass$6(gclass_name) {
25952
26102
  ac_treedb_node_deleted$1,
25953
26103
  null
25954
26104
  ],
26105
+ [
26106
+ "EV_TREEDB_NODE_LINKED",
26107
+ ac_treedb_node_linked$1,
26108
+ null
26109
+ ],
26110
+ [
26111
+ "EV_TREEDB_NODE_UNLINKED",
26112
+ ac_treedb_node_linked$1,
26113
+ null
26114
+ ],
25955
26115
  [
25956
26116
  "EV_CREATE_RECORD",
25957
26117
  ac_create_record,
@@ -26073,6 +26233,8 @@ function create_gclass$6(gclass_name) {
26073
26233
  ["EV_TREEDB_NODE_CREATED", _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT],
26074
26234
  ["EV_TREEDB_NODE_UPDATED", _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT],
26075
26235
  ["EV_TREEDB_NODE_DELETED", _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT],
26236
+ ["EV_TREEDB_NODE_LINKED", _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT],
26237
+ ["EV_TREEDB_NODE_UNLINKED", _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT],
26076
26238
  ["EV_CREATE_RECORD", 0],
26077
26239
  ["EV_UPDATE_RECORD", 0],
26078
26240
  ["EV_UPDATE_FIELD", 0],
@@ -68749,9 +68911,10 @@ function get_nodes(gobj, topic_name) {
68749
68911
  * treedb_name}), with no `topic_name` — so they are subscribed ONCE, and
68750
68912
  * filtered by treedb_name alone (a {topic_name} filter would match nothing).
68751
68913
  *
68752
- * NOTE: the backend only publishes them when its C_NODE service is
68753
- * configured with `with_link_events` (SDF_RD, default FALSE). Without it,
68754
- * a link/unlink is announced the backward-compatible way — an
68914
+ * NOTE: the backend only publishes them when its C_NODE service runs
68915
+ * with `with_link_events` (the default since SDK 7.26.0; a v1 backend
68916
+ * sets it off). Without it, a link/unlink is announced the
68917
+ * backward-compatible way — an
68755
68918
  * EV_TREEDB_NODE_UPDATED of the PARENT — which cannot move an edge here:
68756
68919
  * an edge IS a fkey of the CHILD (link-saves-child), and the parent's fkeys
68757
68920
  * did not change. That is why an open Graph kept showing stale edges when
@@ -23801,6 +23801,8 @@ function mt_create$6(gobj) {
23801
23801
  gobj.priv.reread_on_session = false;
23802
23802
  gobj.priv.conn_shell = null;
23803
23803
  gobj.priv.drills_in_flight = /* @__PURE__ */ new Set();
23804
+ gobj.priv.parent_rereads = /* @__PURE__ */ new Map();
23805
+ gobj.priv.reread_seq = 0;
23804
23806
  build_ui$6(gobj);
23805
23807
  let subscriber = gobj_read_pointer_attr(gobj, "subscriber");
23806
23808
  if (!subscriber) subscriber = gobj_parent(gobj);
@@ -24909,6 +24911,13 @@ function subscribe_treedb$1(gobj, topic_name) {
24909
24911
  "topic_name": topic_name
24910
24912
  }
24911
24913
  }, gobj);
24914
+ for (let event of ["EV_TREEDB_NODE_LINKED", "EV_TREEDB_NODE_UNLINKED"]) gobj_subscribe_event(gobj_remote_yuno, event, {
24915
+ __service__: treedb_name,
24916
+ __filter__: {
24917
+ "treedb_name": treedb_name,
24918
+ "parent_topic_name": topic_name
24919
+ }
24920
+ }, gobj);
24912
24921
  }
24913
24922
  /********************************************
24914
24923
  *
@@ -24959,6 +24968,119 @@ function answered_record$1(data) {
24959
24968
  return {};
24960
24969
  }
24961
24970
  /************************************************************
24971
+ * Command to remote service: one node, in the shape the table
24972
+ * reads its topic with (TABLE_READ_OPTIONS)
24973
+ ************************************************************/
24974
+ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id, reread_seq) {
24975
+ let gobj_remote_yuno = gobj_read_pointer_attr(gobj, "gobj_remote_yuno");
24976
+ let kw = {
24977
+ service: treedb_name,
24978
+ treedb_name,
24979
+ topic_name,
24980
+ node_id,
24981
+ options: Object.assign({}, TABLE_READ_OPTIONS)
24982
+ };
24983
+ kw.__md_command__ = {
24984
+ topic_name,
24985
+ node_id,
24986
+ reread_seq
24987
+ };
24988
+ let ret = gobj_command(gobj_remote_yuno, "node", kw, gobj);
24989
+ if (ret) {
24990
+ log_error(ret);
24991
+ return -1;
24992
+ }
24993
+ return 0;
24994
+ }
24995
+ /************************************************************
24996
+ * Is the row of `node_id` loaded in the table of its topic?
24997
+ * A table not open, or open on other rows (a page that does
24998
+ * not hold it), shows nothing of the node: there is nothing to
24999
+ * refresh, its rows are read when they are shown.
25000
+ ************************************************************/
25001
+ function is_row_loaded(gobj, topic_name, node_id) {
25002
+ let gobj_formtable = get_gobj_formtable(gobj, topic_name);
25003
+ if (!gobj_formtable) return false;
25004
+ let tabulator = gobj_read_attr(gobj_formtable, "tabulator");
25005
+ if (!tabulator) return false;
25006
+ return !!tabulator.getRow(node_id);
25007
+ }
25008
+ /************************************************************
25009
+ * Read again a parent whose hook a link or an unlink moved
25010
+ * (ac_treedb_node_linked), ONE read in flight per parent: a
25011
+ * link that comes while it is out only marks it dirty, and
25012
+ * its answer asks once more (answer_linked_parent_reread).
25013
+ * A burst of links to one parent costs two reads of it, not
25014
+ * one per link -- each read is the parent with every child.
25015
+ * Each request carries its `seq`: only its own answer settles
25016
+ * the entry.
25017
+ ************************************************************/
25018
+ function reread_linked_parent(gobj, treedb_name, topic_name, node_id) {
25019
+ let priv = gobj.priv;
25020
+ let key = `${topic_name}\u0000${node_id}`;
25021
+ let in_flight = priv.parent_rereads.get(key);
25022
+ if (in_flight) {
25023
+ in_flight.dirty = true;
25024
+ return 0;
25025
+ }
25026
+ let seq = ++priv.reread_seq;
25027
+ priv.parent_rereads.set(key, {
25028
+ dirty: false,
25029
+ seq
25030
+ });
25031
+ let ret = treedb_get_node$1(gobj, treedb_name, topic_name, node_id, seq);
25032
+ if (ret < 0) priv.parent_rereads.delete(key);
25033
+ return ret;
25034
+ }
25035
+ /************************************************************
25036
+ * A whole read of a topic brought every row as it is now: the
25037
+ * re-reads of its parents still out have nothing to add, and
25038
+ * their answers, when they come, are not taken. It is also
25039
+ * what bounds an entry whose answer never comes on a live
25040
+ * session (a request lost by the backend): the drop clears
25041
+ * every entry (ac_transport_state), the next read of the
25042
+ * topic (its refresh, its open, the reconnect) clears its own.
25043
+ ************************************************************/
25044
+ function forget_topic_rereads(gobj, topic_name) {
25045
+ let prefix = `${topic_name}\u0000`;
25046
+ for (const key of Array.from(gobj.priv.parent_rereads.keys())) if (key.startsWith(prefix)) gobj.priv.parent_rereads.delete(key);
25047
+ }
25048
+ /************************************************************
25049
+ * The answer of a parent's re-read. It is a refresh nobody
25050
+ * asked for, so a failure is a warning, never the app's error
25051
+ * modal: a force-delete of a loaded parent publishes UNLINKED
25052
+ * per child, and the re-read reaches the backend after the
25053
+ * delete ("Node not found") -- in every open viewer.
25054
+ *
25055
+ * Only the answer of the request in flight counts: one cut by
25056
+ * a drop, or superseded by a whole read of the topic, that
25057
+ * arrives after a new request went out must neither settle
25058
+ * the new one nor update the row with older data.
25059
+ *
25060
+ * Then, if links came while it was out, the parent is read
25061
+ * once more -- when its row is still loaded.
25062
+ ************************************************************/
25063
+ function answer_linked_parent_reread(gobj, result, comment, data, kw_command) {
25064
+ let priv = gobj.priv;
25065
+ let topic_name = kw_get_str(gobj, kw_command, "topic_name", "", 0);
25066
+ let node_id = kw_get_str(gobj, kw_command, "node_id", "", 0);
25067
+ let seq = kw_get_int(gobj, kw_command, "reread_seq", 0, 0);
25068
+ let key = `${topic_name}\u0000${node_id}`;
25069
+ let in_flight = priv.parent_rereads.get(key);
25070
+ if (!in_flight || in_flight.seq !== seq) {
25071
+ if (result < 0) log_warning(`${gobj_short_name(gobj)}: late failure of the re-read of the linked parent '${topic_name}^${node_id}' dropped, it was settled already (a drop, or a whole read of the topic): ${comment || ""}`);
25072
+ return 0;
25073
+ }
25074
+ priv.parent_rereads.delete(key);
25075
+ if (result < 0) log_warning(`${gobj_short_name(gobj)}: the re-read of the linked parent '${topic_name}^${node_id}' failed: ${comment || ""}`);
25076
+ else {
25077
+ let gobj_formtable = get_gobj_formtable(gobj, topic_name);
25078
+ if (gobj_formtable) gobj_send_event(gobj_formtable, "EV_LOAD_NODE_UPDATED", [data], gobj);
25079
+ }
25080
+ if (in_flight.dirty && is_connected$1(gobj) && is_row_loaded(gobj, topic_name, node_id)) reread_linked_parent(gobj, gobj_read_str_attr(gobj, "treedb_name"), topic_name, node_id);
25081
+ return 0;
25082
+ }
25083
+ /************************************************************
24962
25084
  * Command to remote service
24963
25085
  ************************************************************/
24964
25086
  function treedb_update_node$1(gobj, treedb_name, topic_name, record, options, form_write, created) {
@@ -25290,6 +25412,7 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25290
25412
  }, gobj);
25291
25413
  return 0;
25292
25414
  }
25415
+ if (command === "node") return answer_linked_parent_reread(gobj, result, comment, data, kw_command);
25293
25416
  if (result < 0) {
25294
25417
  if (command === "descs") show_load_error$1(gobj, t(comment));
25295
25418
  else {
@@ -25323,13 +25446,18 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25323
25446
  let answer = nodes_answer(data);
25324
25447
  let req_id = kw_get_str(gobj, kw_command, "req_id", "", 0);
25325
25448
  if (kw_get_str(gobj, kw_command, "purpose", "", 0) === "json") gobj_send_event(gobj_topic_form, "EV_JSON_LOADED", { rows: answer.rows }, gobj);
25326
- else if (req_id) gobj_send_event(gobj_topic_form, "EV_PAGE_LOADED", {
25327
- req_id,
25328
- rows: answer.rows,
25329
- pages: answer.pages,
25330
- total: answer.total
25331
- }, gobj);
25332
- else gobj_send_event(gobj_topic_form, "EV_LOAD_NODES", answer.rows, gobj);
25449
+ else if (req_id) {
25450
+ forget_topic_rereads(gobj, topic_name);
25451
+ gobj_send_event(gobj_topic_form, "EV_PAGE_LOADED", {
25452
+ req_id,
25453
+ rows: answer.rows,
25454
+ pages: answer.pages,
25455
+ total: answer.total
25456
+ }, gobj);
25457
+ } else {
25458
+ forget_topic_rereads(gobj, topic_name);
25459
+ gobj_send_event(gobj_topic_form, "EV_LOAD_NODES", answer.rows, gobj);
25460
+ }
25333
25461
  }
25334
25462
  break;
25335
25463
  case "create-node":
@@ -25505,6 +25633,7 @@ function ac_transport_state$2(gobj, event, kw, src) {
25505
25633
  refresh_toolbar_buttons(gobj, connected);
25506
25634
  if (!connected) {
25507
25635
  gobj.priv.reread_on_session = true;
25636
+ gobj.priv.parent_rereads.clear();
25508
25637
  answer_drills_in_flight$1(gobj);
25509
25638
  abandon_form_writes(gobj.priv.form_writes).forEach((w) => {
25510
25639
  log_warning(`${gobj_short_name(gobj)}: transport closed, the write ${w.form_write} of '${w.topic_name}' is lost`);
@@ -25578,6 +25707,27 @@ function ac_treedb_node_updated$1(gobj, event, kw, src) {
25578
25707
  }
25579
25708
  /********************************************
25580
25709
  * Remote subscription response
25710
+ * EV_TREEDB_NODE_LINKED / EV_TREEDB_NODE_UNLINKED: the relationship
25711
+ * ({hook_name, parent_topic_name, child_topic_name, parent_id,
25712
+ * child_id, treedb_name}), not a node. The parent's hook changed and
25713
+ * the event does not carry it: read the parent again -- only when its
25714
+ * row is loaded (a table not open, or on another page, has nothing to
25715
+ * refresh), and one read in flight per parent (reread_linked_parent).
25716
+ ********************************************/
25717
+ function ac_treedb_node_linked$1(gobj, event, kw, src) {
25718
+ let treedb_name = kw_get_str(gobj, kw, "treedb_name", "", 0);
25719
+ let parent_topic_name = kw_get_str(gobj, kw, "parent_topic_name", "", 0);
25720
+ let parent_id = kw_get_str(gobj, kw, "parent_id", "", 0);
25721
+ if (treedb_name !== gobj_read_str_attr(gobj, "treedb_name")) return 0;
25722
+ if (!parent_topic_name || !parent_id) {
25723
+ log_error(`${gobj_short_name(gobj)}: ${event} without parent_topic_name/parent_id`);
25724
+ return -1;
25725
+ }
25726
+ if (!is_row_loaded(gobj, parent_topic_name, parent_id)) return 0;
25727
+ return reread_linked_parent(gobj, treedb_name, parent_topic_name, parent_id);
25728
+ }
25729
+ /********************************************
25730
+ * Remote subscription response
25581
25731
  ********************************************/
25582
25732
  function ac_treedb_node_deleted$1(gobj, event, kw, src) {
25583
25733
  let treedb_name = kw_get_str(gobj, kw, "treedb_name", "", 0);
@@ -25947,6 +26097,16 @@ function create_gclass$6(gclass_name) {
25947
26097
  ac_treedb_node_deleted$1,
25948
26098
  null
25949
26099
  ],
26100
+ [
26101
+ "EV_TREEDB_NODE_LINKED",
26102
+ ac_treedb_node_linked$1,
26103
+ null
26104
+ ],
26105
+ [
26106
+ "EV_TREEDB_NODE_UNLINKED",
26107
+ ac_treedb_node_linked$1,
26108
+ null
26109
+ ],
25950
26110
  [
25951
26111
  "EV_CREATE_RECORD",
25952
26112
  ac_create_record,
@@ -26068,6 +26228,8 @@ function create_gclass$6(gclass_name) {
26068
26228
  ["EV_TREEDB_NODE_CREATED", event_flag_t.EVF_PUBLIC_EVENT],
26069
26229
  ["EV_TREEDB_NODE_UPDATED", event_flag_t.EVF_PUBLIC_EVENT],
26070
26230
  ["EV_TREEDB_NODE_DELETED", event_flag_t.EVF_PUBLIC_EVENT],
26231
+ ["EV_TREEDB_NODE_LINKED", event_flag_t.EVF_PUBLIC_EVENT],
26232
+ ["EV_TREEDB_NODE_UNLINKED", event_flag_t.EVF_PUBLIC_EVENT],
26071
26233
  ["EV_CREATE_RECORD", 0],
26072
26234
  ["EV_UPDATE_RECORD", 0],
26073
26235
  ["EV_UPDATE_FIELD", 0],
@@ -68744,9 +68906,10 @@ function get_nodes(gobj, topic_name) {
68744
68906
  * treedb_name}), with no `topic_name` — so they are subscribed ONCE, and
68745
68907
  * filtered by treedb_name alone (a {topic_name} filter would match nothing).
68746
68908
  *
68747
- * NOTE: the backend only publishes them when its C_NODE service is
68748
- * configured with `with_link_events` (SDF_RD, default FALSE). Without it,
68749
- * a link/unlink is announced the backward-compatible way — an
68909
+ * NOTE: the backend only publishes them when its C_NODE service runs
68910
+ * with `with_link_events` (the default since SDK 7.26.0; a v1 backend
68911
+ * sets it off). Without it, a link/unlink is announced the
68912
+ * backward-compatible way — an
68750
68913
  * EV_TREEDB_NODE_UPDATED of the PARENT — which cannot move an edge here:
68751
68914
  * an edge IS a fkey of the CHILD (link-saves-child), and the parent's fkeys
68752
68915
  * did not change. That is why an open Graph kept showing stale edges when
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.25.25",
3
+ "version": "7.26.0",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -1889,9 +1889,10 @@ function get_nodes(gobj, topic_name)
1889
1889
  * treedb_name}), with no `topic_name` — so they are subscribed ONCE, and
1890
1890
  * filtered by treedb_name alone (a {topic_name} filter would match nothing).
1891
1891
  *
1892
- * NOTE: the backend only publishes them when its C_NODE service is
1893
- * configured with `with_link_events` (SDF_RD, default FALSE). Without it,
1894
- * a link/unlink is announced the backward-compatible way — an
1892
+ * NOTE: the backend only publishes them when its C_NODE service runs
1893
+ * with `with_link_events` (the default since SDK 7.26.0; a v1 backend
1894
+ * sets it off). Without it, a link/unlink is announced the
1895
+ * backward-compatible way — an
1895
1896
  * EV_TREEDB_NODE_UPDATED of the PARENT — which cannot move an edge here:
1896
1897
  * an edge IS a fkey of the CHILD (link-saves-child), and the parent's fkeys
1897
1898
  * did not change. That is why an open Graph kept showing stale edges when
@@ -170,6 +170,12 @@ function mt_create(gobj)
170
170
  /* The drills of the raw-json viewer sent and not yet answered:
171
171
  * answered on the disconnect edge (answer_drills_in_flight). */
172
172
  gobj.priv.drills_in_flight = new Set();
173
+ /* The parents re-read because a link moved their hook, by
174
+ * "<topic>\u0000<id>", each with `dirty` when another link came
175
+ * while its read was out, and the `seq` of its request: an
176
+ * answer of another request is not its (reread_linked_parent). */
177
+ gobj.priv.parent_rereads = new Map();
178
+ gobj.priv.reread_seq = 0;
173
179
 
174
180
  build_ui(gobj);
175
181
 
@@ -1492,6 +1498,27 @@ function subscribe_treedb(gobj, topic_name)
1492
1498
  },
1493
1499
  gobj
1494
1500
  );
1501
+
1502
+ /*
1503
+ * A link/unlink changes the hook of the PARENT, and a backend with
1504
+ * `with_link_events` (the default since SDK 7.26.0) tells it as the
1505
+ * relationship, with no `topic_name`: the parent's topic is
1506
+ * `parent_topic_name`. The child's row moves on its own UPDATED.
1507
+ */
1508
+ for(let event of ["EV_TREEDB_NODE_LINKED", "EV_TREEDB_NODE_UNLINKED"]) {
1509
+ gobj_subscribe_event(
1510
+ gobj_remote_yuno,
1511
+ event,
1512
+ {
1513
+ __service__: treedb_name,
1514
+ __filter__: {
1515
+ "treedb_name": treedb_name,
1516
+ "parent_topic_name": topic_name
1517
+ }
1518
+ },
1519
+ gobj
1520
+ );
1521
+ }
1495
1522
  }
1496
1523
 
1497
1524
  /************************************************************
@@ -1502,9 +1529,9 @@ function subscribe_treedb(gobj, topic_name)
1502
1529
  * fix, and no caller to add on that account.
1503
1530
  *
1504
1531
  * It is kept deliberately. It is the only place that knows the
1505
- * exact shape the remote subscription was made with — the three
1506
- * events, `__service__` and the `treedb_name`+`topic_name`
1507
- * filter — and a remote unsubscribe only lands if it matches
1532
+ * exact shape the remote subscription was made with — the five
1533
+ * events, `__service__` and the `treedb_name`+`topic_name` (or
1534
+ * `parent_topic_name`) filter — and a remote unsubscribe only lands if it matches
1508
1535
  * the subscribe verbatim. Deleting it would not remove that
1509
1536
  * knowledge, it would move it to whoever needs it next, to be
1510
1537
  * rederived from the subscribe side and got right again.
@@ -1556,6 +1583,19 @@ function unsubscribe_treedb(gobj, topic_name)
1556
1583
  },
1557
1584
  gobj
1558
1585
  );
1586
+ for(let event of ["EV_TREEDB_NODE_LINKED", "EV_TREEDB_NODE_UNLINKED"]) {
1587
+ gobj_unsubscribe_event(gobj_remote_yuno,
1588
+ event,
1589
+ {
1590
+ __service__: treedb_name,
1591
+ __filter__: {
1592
+ "treedb_name": treedb_name,
1593
+ "parent_topic_name": topic_name
1594
+ }
1595
+ },
1596
+ gobj
1597
+ );
1598
+ }
1559
1599
  }
1560
1600
 
1561
1601
  /********************************************
@@ -1645,6 +1685,163 @@ function answered_record(data)
1645
1685
  return {};
1646
1686
  }
1647
1687
 
1688
+ /************************************************************
1689
+ * Command to remote service: one node, in the shape the table
1690
+ * reads its topic with (TABLE_READ_OPTIONS)
1691
+ ************************************************************/
1692
+ function treedb_get_node(gobj, treedb_name, topic_name, node_id, reread_seq)
1693
+ {
1694
+ let gobj_remote_yuno = gobj_read_pointer_attr(gobj, "gobj_remote_yuno");
1695
+ let kw = {
1696
+ service: treedb_name,
1697
+ treedb_name: treedb_name,
1698
+ topic_name: topic_name,
1699
+ node_id: node_id,
1700
+ options: Object.assign({}, TABLE_READ_OPTIONS)
1701
+ };
1702
+
1703
+ kw.__md_command__ = { // Data to be returned
1704
+ topic_name: topic_name,
1705
+ node_id: node_id,
1706
+ reread_seq: reread_seq
1707
+ };
1708
+
1709
+ let ret = gobj_command(
1710
+ gobj_remote_yuno,
1711
+ "node",
1712
+ kw,
1713
+ gobj
1714
+ );
1715
+ if(ret) {
1716
+ log_error(ret);
1717
+ return -1;
1718
+ }
1719
+ return 0;
1720
+ }
1721
+
1722
+ /************************************************************
1723
+ * Is the row of `node_id` loaded in the table of its topic?
1724
+ * A table not open, or open on other rows (a page that does
1725
+ * not hold it), shows nothing of the node: there is nothing to
1726
+ * refresh, its rows are read when they are shown.
1727
+ ************************************************************/
1728
+ function is_row_loaded(gobj, topic_name, node_id)
1729
+ {
1730
+ let gobj_formtable = get_gobj_formtable(gobj, topic_name);
1731
+ if(!gobj_formtable) {
1732
+ return false;
1733
+ }
1734
+ let tabulator = gobj_read_attr(gobj_formtable, "tabulator");
1735
+ if(!tabulator) {
1736
+ return false;
1737
+ }
1738
+ return !!tabulator.getRow(node_id);
1739
+ }
1740
+
1741
+ /************************************************************
1742
+ * Read again a parent whose hook a link or an unlink moved
1743
+ * (ac_treedb_node_linked), ONE read in flight per parent: a
1744
+ * link that comes while it is out only marks it dirty, and
1745
+ * its answer asks once more (answer_linked_parent_reread).
1746
+ * A burst of links to one parent costs two reads of it, not
1747
+ * one per link -- each read is the parent with every child.
1748
+ * Each request carries its `seq`: only its own answer settles
1749
+ * the entry.
1750
+ ************************************************************/
1751
+ function reread_linked_parent(gobj, treedb_name, topic_name, node_id)
1752
+ {
1753
+ let priv = gobj.priv;
1754
+ let key = `${topic_name}\u0000${node_id}`;
1755
+ let in_flight = priv.parent_rereads.get(key);
1756
+ if(in_flight) {
1757
+ in_flight.dirty = true;
1758
+ return 0;
1759
+ }
1760
+ let seq = ++priv.reread_seq;
1761
+ priv.parent_rereads.set(key, {dirty: false, seq: seq});
1762
+ let ret = treedb_get_node(gobj, treedb_name, topic_name, node_id, seq);
1763
+ if(ret < 0) {
1764
+ priv.parent_rereads.delete(key); // Error already logged
1765
+ }
1766
+ return ret;
1767
+ }
1768
+
1769
+ /************************************************************
1770
+ * A whole read of a topic brought every row as it is now: the
1771
+ * re-reads of its parents still out have nothing to add, and
1772
+ * their answers, when they come, are not taken. It is also
1773
+ * what bounds an entry whose answer never comes on a live
1774
+ * session (a request lost by the backend): the drop clears
1775
+ * every entry (ac_transport_state), the next read of the
1776
+ * topic (its refresh, its open, the reconnect) clears its own.
1777
+ ************************************************************/
1778
+ function forget_topic_rereads(gobj, topic_name)
1779
+ {
1780
+ let prefix = `${topic_name}\u0000`;
1781
+ for(const key of Array.from(gobj.priv.parent_rereads.keys())) {
1782
+ if(key.startsWith(prefix)) {
1783
+ gobj.priv.parent_rereads.delete(key);
1784
+ }
1785
+ }
1786
+ }
1787
+
1788
+ /************************************************************
1789
+ * The answer of a parent's re-read. It is a refresh nobody
1790
+ * asked for, so a failure is a warning, never the app's error
1791
+ * modal: a force-delete of a loaded parent publishes UNLINKED
1792
+ * per child, and the re-read reaches the backend after the
1793
+ * delete ("Node not found") -- in every open viewer.
1794
+ *
1795
+ * Only the answer of the request in flight counts: one cut by
1796
+ * a drop, or superseded by a whole read of the topic, that
1797
+ * arrives after a new request went out must neither settle
1798
+ * the new one nor update the row with older data.
1799
+ *
1800
+ * Then, if links came while it was out, the parent is read
1801
+ * once more -- when its row is still loaded.
1802
+ ************************************************************/
1803
+ function answer_linked_parent_reread(gobj, result, comment, data, kw_command)
1804
+ {
1805
+ let priv = gobj.priv;
1806
+ let topic_name = kw_get_str(gobj, kw_command, "topic_name", "", 0);
1807
+ let node_id = kw_get_str(gobj, kw_command, "node_id", "", 0);
1808
+ let seq = kw_get_int(gobj, kw_command, "reread_seq", 0, 0);
1809
+ let key = `${topic_name}\u0000${node_id}`;
1810
+ let in_flight = priv.parent_rereads.get(key);
1811
+ if(!in_flight || in_flight.seq !== seq) {
1812
+ if(result < 0) {
1813
+ log_warning(`${gobj_short_name(gobj)}: late failure of the re-read of ` +
1814
+ `the linked parent '${topic_name}^${node_id}' dropped, it was ` +
1815
+ `settled already (a drop, or a whole read of the topic): ${comment || ""}`);
1816
+ }
1817
+ return 0;
1818
+ }
1819
+ priv.parent_rereads.delete(key);
1820
+
1821
+ if(result < 0) {
1822
+ log_warning(`${gobj_short_name(gobj)}: the re-read of the linked parent ` +
1823
+ `'${topic_name}^${node_id}' failed: ${comment || ""}`);
1824
+ } else {
1825
+ /* A table closed while the read was out has no row to update. */
1826
+ let gobj_formtable = get_gobj_formtable(gobj, topic_name);
1827
+ if(gobj_formtable) {
1828
+ gobj_send_event(
1829
+ gobj_formtable,
1830
+ "EV_LOAD_NODE_UPDATED",
1831
+ [data],
1832
+ gobj
1833
+ );
1834
+ }
1835
+ }
1836
+
1837
+ if(in_flight.dirty && is_connected(gobj) && is_row_loaded(gobj, topic_name, node_id)) {
1838
+ reread_linked_parent(
1839
+ gobj, gobj_read_str_attr(gobj, "treedb_name"), topic_name, node_id
1840
+ ); // Error already logged
1841
+ }
1842
+ return 0;
1843
+ }
1844
+
1648
1845
  /************************************************************
1649
1846
  * Command to remote service
1650
1847
  ************************************************************/
@@ -2186,6 +2383,15 @@ function ac_mt_command_answer(gobj, event, kw, src)
2186
2383
  return 0;
2187
2384
  }
2188
2385
 
2386
+ /*
2387
+ * A parent re-read because a link or an unlink moved its hook
2388
+ * (ac_treedb_node_linked). Before the generic error path: its
2389
+ * failure is a warning, never the app-wide modal.
2390
+ */
2391
+ if(command === "node") {
2392
+ return answer_linked_parent_reread(gobj, result, comment, data, kw_command);
2393
+ }
2394
+
2189
2395
  if(result < 0) {
2190
2396
  if(command === "descs") {
2191
2397
  /* The schema couldn't load (not a treedb, no authz for it, backend
@@ -2280,6 +2486,7 @@ function ac_mt_command_answer(gobj, event, kw, src)
2280
2486
  gobj
2281
2487
  );
2282
2488
  } else if(req_id) {
2489
+ forget_topic_rereads(gobj, topic_name); // the rows a table shows, read now
2283
2490
  gobj_send_event(
2284
2491
  gobj_topic_form,
2285
2492
  "EV_PAGE_LOADED",
@@ -2292,6 +2499,7 @@ function ac_mt_command_answer(gobj, event, kw, src)
2292
2499
  gobj
2293
2500
  );
2294
2501
  } else {
2502
+ forget_topic_rereads(gobj, topic_name);
2295
2503
  gobj_send_event(
2296
2504
  gobj_topic_form,
2297
2505
  "EV_LOAD_NODES",
@@ -2600,6 +2808,7 @@ function ac_transport_state(gobj, event, kw, src)
2600
2808
  * no table: its node events are published to nobody. Every open
2601
2809
  * table is read again when the session is back. */
2602
2810
  gobj.priv.reread_on_session = true;
2811
+ gobj.priv.parent_rereads.clear(); /* the reconnect reads every open table */
2603
2812
  answer_drills_in_flight(gobj);
2604
2813
  abandon_form_writes(gobj.priv.form_writes).forEach((w) => {
2605
2814
  log_warning(`${gobj_short_name(gobj)}: transport closed, the write ${w.form_write} of '${w.topic_name}' is lost`);
@@ -2718,6 +2927,36 @@ function ac_treedb_node_updated(gobj, event, kw, src)
2718
2927
  return 0;
2719
2928
  }
2720
2929
 
2930
+ /********************************************
2931
+ * Remote subscription response
2932
+ * EV_TREEDB_NODE_LINKED / EV_TREEDB_NODE_UNLINKED: the relationship
2933
+ * ({hook_name, parent_topic_name, child_topic_name, parent_id,
2934
+ * child_id, treedb_name}), not a node. The parent's hook changed and
2935
+ * the event does not carry it: read the parent again -- only when its
2936
+ * row is loaded (a table not open, or on another page, has nothing to
2937
+ * refresh), and one read in flight per parent (reread_linked_parent).
2938
+ ********************************************/
2939
+ function ac_treedb_node_linked(gobj, event, kw, src)
2940
+ {
2941
+ let treedb_name = kw_get_str(gobj, kw, "treedb_name", "", 0);
2942
+ let parent_topic_name = kw_get_str(gobj, kw, "parent_topic_name", "", 0);
2943
+ let parent_id = kw_get_str(gobj, kw, "parent_id", "", 0);
2944
+
2945
+ if(treedb_name !== gobj_read_str_attr(gobj, "treedb_name")) {
2946
+ return 0;
2947
+ }
2948
+ if(!parent_topic_name || !parent_id) {
2949
+ log_error(`${gobj_short_name(gobj)}: ${event} without parent_topic_name/parent_id`);
2950
+ return -1;
2951
+ }
2952
+
2953
+ if(!is_row_loaded(gobj, parent_topic_name, parent_id)) {
2954
+ return 0;
2955
+ }
2956
+
2957
+ return reread_linked_parent(gobj, treedb_name, parent_topic_name, parent_id); // Error already logged
2958
+ }
2959
+
2721
2960
  /********************************************
2722
2961
  * Remote subscription response
2723
2962
  ********************************************/
@@ -3222,6 +3461,8 @@ function create_gclass(gclass_name)
3222
3461
  ["EV_TREEDB_NODE_CREATED", ac_treedb_node_created, null],
3223
3462
  ["EV_TREEDB_NODE_UPDATED", ac_treedb_node_updated, null],
3224
3463
  ["EV_TREEDB_NODE_DELETED", ac_treedb_node_deleted, null],
3464
+ ["EV_TREEDB_NODE_LINKED", ac_treedb_node_linked, null],
3465
+ ["EV_TREEDB_NODE_UNLINKED", ac_treedb_node_linked, null],
3225
3466
  ["EV_CREATE_RECORD", ac_create_record, null],
3226
3467
  ["EV_UPDATE_RECORD", ac_update_record, null],
3227
3468
  ["EV_UPDATE_FIELD", ac_update_field, null],
@@ -3256,6 +3497,8 @@ function create_gclass(gclass_name)
3256
3497
  ["EV_TREEDB_NODE_CREATED", event_flag_t.EVF_PUBLIC_EVENT],
3257
3498
  ["EV_TREEDB_NODE_UPDATED", event_flag_t.EVF_PUBLIC_EVENT],
3258
3499
  ["EV_TREEDB_NODE_DELETED", event_flag_t.EVF_PUBLIC_EVENT],
3500
+ ["EV_TREEDB_NODE_LINKED", event_flag_t.EVF_PUBLIC_EVENT],
3501
+ ["EV_TREEDB_NODE_UNLINKED", event_flag_t.EVF_PUBLIC_EVENT],
3259
3502
  ["EV_CREATE_RECORD", 0],
3260
3503
  ["EV_UPDATE_RECORD", 0],
3261
3504
  ["EV_UPDATE_FIELD", 0],
@@ -11,11 +11,24 @@
11
11
  * Copyright (c) 2026, ArtGins.
12
12
  * All Rights Reserved.
13
13
  ***********************************************************************/
14
- import {describe, test, expect, beforeAll, beforeEach} from "vitest";
14
+ import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
15
15
  import {install_dom_double} from "../test/dom_double.js";
16
16
 
17
17
  install_dom_double();
18
18
 
19
+ /* The app-wide error modal: what it is asked to show is asserted. */
20
+ const shown = vi.hoisted(() => []);
21
+ vi.mock("./shell_modals.js", async (importOriginal) => {
22
+ const original = await importOriginal();
23
+ return {
24
+ ...original,
25
+ yui_shell_show_error: (shell, message) => {
26
+ shown.push(message);
27
+ return {close() {}};
28
+ },
29
+ };
30
+ });
31
+
19
32
  const gobj_js = await import("@yuneta/gobj-js");
20
33
  const {
21
34
  SDATA, SDATA_END, data_type_t, event_flag_t,
@@ -32,6 +45,7 @@ const logged = [];
32
45
  const written = []; /* the EV_RECORD_WRITTEN the host heard */
33
46
  const answers = []; /* what the fake forms were told */
34
47
  const loaded = []; /* the rows each fake form was loaded with */
48
+ const updated = []; /* the rows each fake form was told changed */
35
49
  const commands = []; /* what the fake transport was asked */
36
50
 
37
51
  /*
@@ -65,6 +79,12 @@ function ac_form_load(gobj, event, kw, src)
65
79
  return 0;
66
80
  }
67
81
 
82
+ function ac_form_update(gobj, event, kw, src)
83
+ {
84
+ updated.push({topic: gobj.priv_topic, rows: kw});
85
+ return 0;
86
+ }
87
+
68
88
  let yuno = null;
69
89
  let remote = null;
70
90
 
@@ -84,17 +104,20 @@ beforeAll(() => {
84
104
  );
85
105
  gclass_create(
86
106
  "C_YUI_TREEDB_TOPIC_WITH_FORM",
87
- [["EV_WRITE_DONE", 0], ["EV_WRITE_REFUSED", 0], ["EV_LOAD_NODES", 0]],
107
+ [["EV_WRITE_DONE", 0], ["EV_WRITE_REFUSED", 0], ["EV_LOAD_NODES", 0],
108
+ ["EV_LOAD_NODE_UPDATED", 0]],
88
109
  [["ST_IDLE", [
89
110
  ["EV_WRITE_DONE", ac_form_answer, null],
90
111
  ["EV_WRITE_REFUSED", ac_form_answer, null],
91
- ["EV_LOAD_NODES", ac_form_load, null]
112
+ ["EV_LOAD_NODES", ac_form_load, null],
113
+ ["EV_LOAD_NODE_UPDATED", ac_form_update, null]
92
114
  ]]],
93
115
  {},
94
116
  0,
95
117
  [
96
118
  SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "topic"),
97
119
  SDATA(data_type_t.DTP_BOOLEAN, "with_remote_paging", 0, false, "pulls its pages"),
120
+ SDATA(data_type_t.DTP_POINTER, "tabulator", 0, null, "the table: only getRow() is read"),
98
121
  SDATA_END()
99
122
  ],
100
123
  {}, 0, 0, 0, 0
@@ -129,6 +152,8 @@ beforeEach(() => {
129
152
  answers.length = 0;
130
153
  commands.length = 0;
131
154
  loaded.length = 0;
155
+ updated.length = 0;
156
+ shown.length = 0;
132
157
  });
133
158
 
134
159
  function build(name)
@@ -152,9 +177,13 @@ function build(name)
152
177
  for(const topic of ["users", "roles"]) {
153
178
  /* Named as the view names its forms: the answer of a `nodes`
154
179
  * finds its table by that name. */
180
+ /* The ids of the rows the table holds: what a link reads
181
+ * again is a parent whose row is loaded. */
182
+ const rows = new Set();
155
183
  forms[topic] = gobj_create(`${name}_topics?${topic}`, "C_YUI_TREEDB_TOPIC_WITH_FORM",
156
- {topic_name: topic}, topics);
184
+ {topic_name: topic, tabulator: {getRow: (id) => (rows.has(id)? {id}: false)}}, topics);
157
185
  forms[topic].priv_topic = topic;
186
+ forms[topic].rows = rows;
158
187
  }
159
188
  /* What the start of a shell with no routes says is the fixture's,
160
189
  * not the behaviour under test: the check starts here. */
@@ -511,3 +540,262 @@ describe("what the drop hid is read again on the reconnect", () => {
511
540
  expect(nodes_asked().sort()).toEqual(["roles", "users"]);
512
541
  });
513
542
  });
543
+
544
+ /*
545
+ * SDK 7.26.0 turns `with_link_events` on by default: a link or an unlink
546
+ * no longer arrives as the parent's EV_TREEDB_NODE_UPDATED, but as the
547
+ * relationship, which carries no node. The parent's row (its hook column)
548
+ * must still move: the view reads the parent again.
549
+ */
550
+ describe("a link told as EV_TREEDB_NODE_LINKED / UNLINKED", () => {
551
+
552
+ for(const event of ["EV_TREEDB_NODE_LINKED", "EV_TREEDB_NODE_UNLINKED"]) {
553
+ test(`${event} re-reads the parent and updates its row`, () => {
554
+ const {shell, topics, forms} = build(`tl_${event}`);
555
+ yui_shell_set_connection_state(shell, true);
556
+ forms.roles.rows.add("admin");
557
+
558
+ gobj_send_event(topics, event, {
559
+ treedb_name: "treedb_test",
560
+ hook_name: "users",
561
+ parent_topic_name: "roles",
562
+ parent_id: "admin",
563
+ child_topic_name: "users",
564
+ child_id: "alice"
565
+ }, remote);
566
+
567
+ const request = commands.find((c) => c.command === "node");
568
+ expect(request.kw.topic_name).toBe("roles");
569
+ expect(request.kw.node_id).toBe("admin");
570
+ expect(request.kw.options).toEqual({list_dict: true, hook_size: true});
571
+
572
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
573
+ answer_ok(request, {id: "admin", users: [{size: 1}]}), remote);
574
+ expect(updated).toEqual([
575
+ {topic: "roles", rows: [{id: "admin", users: [{size: 1}]}]}
576
+ ]);
577
+ expect(errors()).toEqual([]);
578
+ });
579
+ }
580
+
581
+ test("a link of another treedb reads nothing", () => {
582
+ const {shell, topics} = build("tl_other");
583
+ yui_shell_set_connection_state(shell, true);
584
+ gobj_send_event(topics, "EV_TREEDB_NODE_LINKED", {
585
+ treedb_name: "treedb_other",
586
+ hook_name: "users",
587
+ parent_topic_name: "roles",
588
+ parent_id: "admin",
589
+ child_topic_name: "users",
590
+ child_id: "alice"
591
+ }, remote);
592
+ expect(commands.filter((c) => c.command === "node")).toEqual([]);
593
+ expect(errors()).toEqual([]);
594
+ });
595
+
596
+ /*
597
+ * Each read of a parent is the parent with every child. A burst of
598
+ * links to one parent (a bulk link, an import) must not cost one read
599
+ * per link per open view: one read in flight per parent, and one more
600
+ * when links came while it was out.
601
+ */
602
+ function link(topics, parent_id, child_id)
603
+ {
604
+ gobj_send_event(topics, "EV_TREEDB_NODE_LINKED", {
605
+ treedb_name: "treedb_test",
606
+ hook_name: "users",
607
+ parent_topic_name: "roles",
608
+ parent_id: parent_id,
609
+ child_topic_name: "users",
610
+ child_id: child_id
611
+ }, remote);
612
+ }
613
+
614
+ function node_reads()
615
+ {
616
+ return commands.filter((c) => c.command === "node");
617
+ }
618
+
619
+ test("a burst of links to one loaded parent: at most two reads", () => {
620
+ const {shell, topics, forms} = build("tl_burst");
621
+ yui_shell_set_connection_state(shell, true);
622
+ forms.roles.rows.add("admin");
623
+
624
+ for(let i = 0; i < 50; i++) {
625
+ link(topics, "admin", `user${i}`);
626
+ }
627
+ expect(node_reads().length).toBe(1);
628
+
629
+ /* The first answer: links came while it was out, one more read. */
630
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
631
+ answer_ok(node_reads()[0], {id: "admin"}), remote);
632
+ expect(node_reads().length).toBe(2);
633
+
634
+ /* The second: nothing came meanwhile, the burst is over. */
635
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
636
+ answer_ok(node_reads()[1], {id: "admin"}), remote);
637
+ expect(node_reads().length).toBe(2);
638
+ expect(updated.length).toBe(2);
639
+
640
+ /* A link after the burst reads again. */
641
+ link(topics, "admin", "late");
642
+ expect(node_reads().length).toBe(3);
643
+ expect(errors()).toEqual([]);
644
+ });
645
+
646
+ test("a link to a parent not loaded reads nothing", () => {
647
+ const {shell, topics, forms} = build("tl_unloaded");
648
+ yui_shell_set_connection_state(shell, true);
649
+ forms.roles.rows.add("other");
650
+
651
+ link(topics, "admin", "alice");
652
+ expect(node_reads()).toEqual([]);
653
+ expect(errors()).toEqual([]);
654
+ });
655
+
656
+ test("a link to a parent of a topic with no table reads nothing", () => {
657
+ const {shell, topics} = build("tl_notable");
658
+ yui_shell_set_connection_state(shell, true);
659
+ gobj_send_event(topics, "EV_TREEDB_NODE_LINKED", {
660
+ treedb_name: "treedb_test",
661
+ hook_name: "items",
662
+ parent_topic_name: "groups",
663
+ parent_id: "g1",
664
+ child_topic_name: "items",
665
+ child_id: "i1"
666
+ }, remote);
667
+ expect(node_reads()).toEqual([]);
668
+ expect(errors()).toEqual([]);
669
+ });
670
+
671
+ test("a drop abandons the read in flight: the next link reads again", () => {
672
+ const {shell, topics, forms} = build("tl_drop");
673
+ yui_shell_set_connection_state(shell, true);
674
+ forms.roles.rows.add("admin");
675
+ link(topics, "admin", "alice");
676
+ link(topics, "admin", "bob");
677
+ expect(node_reads().length).toBe(1);
678
+
679
+ gobj_change_state(remote, "ST_DISCONNECTED");
680
+ gobj_send_event(topics, "EV_TRANSPORT_STATE", {connected: false}, topics);
681
+ /* The adapter settles the read it had in flight: no second read
682
+ * out of session, no modal. */
683
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER", {
684
+ result: -1, comment: "the session closed", data: null, __md_iev__: {
685
+ command_stack: [{command: "node", kw: node_reads()[0].kw.__md_command__}]
686
+ }
687
+ }, remote);
688
+ expect(node_reads().length).toBe(1);
689
+
690
+ gobj_change_state(remote, "ST_SESSION");
691
+ gobj_send_event(topics, "EV_TRANSPORT_STATE", {connected: true}, topics);
692
+ link(topics, "admin", "carol");
693
+ expect(node_reads().length).toBe(2);
694
+ expect(errors()).toEqual([]);
695
+ expect(shown).toEqual([]);
696
+ });
697
+
698
+ function failed_read(request, comment)
699
+ {
700
+ return {result: -1, comment: comment, data: null, __md_iev__: {
701
+ command_stack: [{command: "node", kw: request.kw.__md_command__}]
702
+ }};
703
+ }
704
+
705
+ function warnings()
706
+ {
707
+ return logged.filter((l) => l.level === "warning").map((l) => l.msg);
708
+ }
709
+
710
+ /*
711
+ * A force-delete of a loaded parent publishes UNLINKED per child, and
712
+ * the re-read reaches the backend after the delete: "Node not found".
713
+ * A refresh nobody asked for: a warning, never the app-wide modal.
714
+ */
715
+ test("a re-read that fails while connected: a warning, no modal, settled", () => {
716
+ const {shell, topics, forms} = build("tl_fail");
717
+ yui_shell_set_connection_state(shell, true);
718
+ forms.roles.rows.add("admin");
719
+ link(topics, "admin", "alice");
720
+ link(topics, "admin", "bob"); /* dirty */
721
+ expect(node_reads().length).toBe(1);
722
+
723
+ /* The row is gone meanwhile: the dirty entry asks nothing more. */
724
+ forms.roles.rows.delete("admin");
725
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
726
+ failed_read(node_reads()[0], "Node not found"), remote);
727
+ expect(shown).toEqual([]);
728
+ expect(errors()).toEqual([]);
729
+ expect(warnings().some((m) => m.includes("re-read of the linked parent") &&
730
+ m.includes("Node not found"))).toBe(true);
731
+ expect(node_reads().length).toBe(1);
732
+ expect(updated).toEqual([]);
733
+
734
+ /* Settled: the next link of a loaded parent reads again. */
735
+ forms.roles.rows.add("admin");
736
+ link(topics, "admin", "carol");
737
+ expect(node_reads().length).toBe(2);
738
+ });
739
+
740
+ /*
741
+ * A read cut by a drop answers -1 LATE, after the reconnect and after
742
+ * a new read of the same parent went out: it is not the new read's
743
+ * answer, and settles nothing of it.
744
+ */
745
+ test("a late failure of a read cut by a drop does not settle the new read", () => {
746
+ const {shell, topics, forms} = build("tl_late");
747
+ yui_shell_set_connection_state(shell, true);
748
+ forms.roles.rows.add("admin");
749
+ link(topics, "admin", "alice");
750
+ const first = node_reads()[0];
751
+
752
+ gobj_change_state(remote, "ST_DISCONNECTED");
753
+ gobj_send_event(topics, "EV_TRANSPORT_STATE", {connected: false}, topics);
754
+ gobj_change_state(remote, "ST_SESSION");
755
+ gobj_send_event(topics, "EV_TRANSPORT_STATE", {connected: true}, topics);
756
+
757
+ link(topics, "admin", "bob");
758
+ expect(node_reads().length).toBe(2);
759
+ const second = node_reads()[1];
760
+
761
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
762
+ failed_read(first, "the session closed"), remote);
763
+ expect(shown).toEqual([]);
764
+ expect(errors()).toEqual([]);
765
+
766
+ /* The second read is still the one in flight: a link only marks it. */
767
+ link(topics, "admin", "carol");
768
+ expect(node_reads().length).toBe(2);
769
+
770
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
771
+ answer_ok(second, {id: "admin"}), remote);
772
+ expect(updated).toEqual([{topic: "roles", rows: [{id: "admin"}]}]);
773
+ expect(node_reads().length).toBe(3); /* dirty: one more */
774
+ });
775
+
776
+ /*
777
+ * A whole read of the topic brings every row as it is now: a re-read
778
+ * still out is moot, its late answer is not taken (older data), and
779
+ * the parent is free to be read on the next link -- which is also
780
+ * what releases an entry whose answer never comes.
781
+ */
782
+ test("a whole read of the topic settles its re-reads still out", () => {
783
+ const {shell, topics, forms} = build("tl_whole");
784
+ yui_shell_set_connection_state(shell, true);
785
+ forms.roles.rows.add("admin");
786
+ link(topics, "admin", "alice");
787
+ const lost = node_reads()[0];
788
+
789
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
790
+ nodes_answer_of("roles", [{id: "admin"}]), remote);
791
+
792
+ link(topics, "admin", "bob");
793
+ expect(node_reads().length).toBe(2);
794
+
795
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER",
796
+ answer_ok(lost, {id: "admin", stale: true}), remote);
797
+ expect(updated).toEqual([]);
798
+ expect(errors()).toEqual([]);
799
+ expect(shown).toEqual([]);
800
+ });
801
+ });