@yuneta/gobj-ui 7.25.26 → 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);
@@ -24974,7 +24976,7 @@ function answered_record$1(data) {
24974
24976
  * Command to remote service: one node, in the shape the table
24975
24977
  * reads its topic with (TABLE_READ_OPTIONS)
24976
24978
  ************************************************************/
24977
- function treedb_get_node$1(gobj, treedb_name, topic_name, node_id) {
24979
+ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id, reread_seq) {
24978
24980
  let gobj_remote_yuno = (0, _yuneta_gobj_js.gobj_read_pointer_attr)(gobj, "gobj_remote_yuno");
24979
24981
  let kw = {
24980
24982
  service: treedb_name,
@@ -24983,7 +24985,11 @@ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id) {
24983
24985
  node_id,
24984
24986
  options: Object.assign({}, TABLE_READ_OPTIONS)
24985
24987
  };
24986
- kw.__md_command__ = { topic_name };
24988
+ kw.__md_command__ = {
24989
+ topic_name,
24990
+ node_id,
24991
+ reread_seq
24992
+ };
24987
24993
  let ret = (0, _yuneta_gobj_js.gobj_command)(gobj_remote_yuno, "node", kw, gobj);
24988
24994
  if (ret) {
24989
24995
  (0, _yuneta_gobj_js.log_error)(ret);
@@ -24992,6 +24998,94 @@ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id) {
24992
24998
  return 0;
24993
24999
  }
24994
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
+ /************************************************************
24995
25089
  * Command to remote service
24996
25090
  ************************************************************/
24997
25091
  function treedb_update_node$1(gobj, treedb_name, topic_name, record, options, form_write, created) {
@@ -25323,6 +25417,7 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25323
25417
  }, gobj);
25324
25418
  return 0;
25325
25419
  }
25420
+ if (command === "node") return answer_linked_parent_reread(gobj, result, comment, data, kw_command);
25326
25421
  if (result < 0) {
25327
25422
  if (command === "descs") show_load_error$1(gobj, (0, i18next.t)(comment));
25328
25423
  else {
@@ -25356,18 +25451,20 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25356
25451
  let answer = nodes_answer(data);
25357
25452
  let req_id = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw_command, "req_id", "", 0);
25358
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);
25359
- else if (req_id) (0, _yuneta_gobj_js.gobj_send_event)(gobj_topic_form, "EV_PAGE_LOADED", {
25360
- req_id,
25361
- rows: answer.rows,
25362
- pages: answer.pages,
25363
- total: answer.total
25364
- }, gobj);
25365
- 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
+ }
25366
25466
  }
25367
25467
  break;
25368
- case "node":
25369
- (0, _yuneta_gobj_js.gobj_send_event)(get_gobj_formtable(gobj, (0, _yuneta_gobj_js.kw_get_str)(gobj, kw_command, "topic_name", "", 0)), "EV_LOAD_NODE_UPDATED", [data], gobj);
25370
- break;
25371
25468
  case "create-node":
25372
25469
  case "update-node":
25373
25470
  case "delete-node":
@@ -25541,6 +25638,7 @@ function ac_transport_state$2(gobj, event, kw, src) {
25541
25638
  refresh_toolbar_buttons(gobj, connected);
25542
25639
  if (!connected) {
25543
25640
  gobj.priv.reread_on_session = true;
25641
+ gobj.priv.parent_rereads.clear();
25544
25642
  answer_drills_in_flight$1(gobj);
25545
25643
  abandon_form_writes(gobj.priv.form_writes).forEach((w) => {
25546
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`);
@@ -25617,7 +25715,9 @@ function ac_treedb_node_updated$1(gobj, event, kw, src) {
25617
25715
  * EV_TREEDB_NODE_LINKED / EV_TREEDB_NODE_UNLINKED: the relationship
25618
25716
  * ({hook_name, parent_topic_name, child_topic_name, parent_id,
25619
25717
  * child_id, treedb_name}), not a node. The parent's hook changed and
25620
- * the event does not carry it: read the parent again.
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).
25621
25721
  ********************************************/
25622
25722
  function ac_treedb_node_linked$1(gobj, event, kw, src) {
25623
25723
  let treedb_name = (0, _yuneta_gobj_js.kw_get_str)(gobj, kw, "treedb_name", "", 0);
@@ -25628,7 +25728,8 @@ function ac_treedb_node_linked$1(gobj, event, kw, src) {
25628
25728
  (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: ${event} without parent_topic_name/parent_id`);
25629
25729
  return -1;
25630
25730
  }
25631
- return treedb_get_node$1(gobj, treedb_name, parent_topic_name, parent_id);
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);
25632
25733
  }
25633
25734
  /********************************************
25634
25735
  * Remote subscription response
@@ -68811,7 +68912,7 @@ function get_nodes(gobj, topic_name) {
68811
68912
  * filtered by treedb_name alone (a {topic_name} filter would match nothing).
68812
68913
  *
68813
68914
  * NOTE: the backend only publishes them when its C_NODE service runs
68814
- * with `with_link_events` (the default since SDK 7.25.23; a v1 backend
68915
+ * with `with_link_events` (the default since SDK 7.26.0; a v1 backend
68815
68916
  * sets it off). Without it, a link/unlink is announced the
68816
68917
  * backward-compatible way — an
68817
68918
  * EV_TREEDB_NODE_UPDATED of the PARENT — which cannot move an edge here:
@@ -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);
@@ -24969,7 +24971,7 @@ function answered_record$1(data) {
24969
24971
  * Command to remote service: one node, in the shape the table
24970
24972
  * reads its topic with (TABLE_READ_OPTIONS)
24971
24973
  ************************************************************/
24972
- function treedb_get_node$1(gobj, treedb_name, topic_name, node_id) {
24974
+ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id, reread_seq) {
24973
24975
  let gobj_remote_yuno = gobj_read_pointer_attr(gobj, "gobj_remote_yuno");
24974
24976
  let kw = {
24975
24977
  service: treedb_name,
@@ -24978,7 +24980,11 @@ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id) {
24978
24980
  node_id,
24979
24981
  options: Object.assign({}, TABLE_READ_OPTIONS)
24980
24982
  };
24981
- kw.__md_command__ = { topic_name };
24983
+ kw.__md_command__ = {
24984
+ topic_name,
24985
+ node_id,
24986
+ reread_seq
24987
+ };
24982
24988
  let ret = gobj_command(gobj_remote_yuno, "node", kw, gobj);
24983
24989
  if (ret) {
24984
24990
  log_error(ret);
@@ -24987,6 +24993,94 @@ function treedb_get_node$1(gobj, treedb_name, topic_name, node_id) {
24987
24993
  return 0;
24988
24994
  }
24989
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
+ /************************************************************
24990
25084
  * Command to remote service
24991
25085
  ************************************************************/
24992
25086
  function treedb_update_node$1(gobj, treedb_name, topic_name, record, options, form_write, created) {
@@ -25318,6 +25412,7 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25318
25412
  }, gobj);
25319
25413
  return 0;
25320
25414
  }
25415
+ if (command === "node") return answer_linked_parent_reread(gobj, result, comment, data, kw_command);
25321
25416
  if (result < 0) {
25322
25417
  if (command === "descs") show_load_error$1(gobj, t(comment));
25323
25418
  else {
@@ -25351,18 +25446,20 @@ function ac_mt_command_answer$2(gobj, event, kw, src) {
25351
25446
  let answer = nodes_answer(data);
25352
25447
  let req_id = kw_get_str(gobj, kw_command, "req_id", "", 0);
25353
25448
  if (kw_get_str(gobj, kw_command, "purpose", "", 0) === "json") gobj_send_event(gobj_topic_form, "EV_JSON_LOADED", { rows: answer.rows }, gobj);
25354
- else if (req_id) gobj_send_event(gobj_topic_form, "EV_PAGE_LOADED", {
25355
- req_id,
25356
- rows: answer.rows,
25357
- pages: answer.pages,
25358
- total: answer.total
25359
- }, gobj);
25360
- 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
+ }
25361
25461
  }
25362
25462
  break;
25363
- case "node":
25364
- gobj_send_event(get_gobj_formtable(gobj, kw_get_str(gobj, kw_command, "topic_name", "", 0)), "EV_LOAD_NODE_UPDATED", [data], gobj);
25365
- break;
25366
25463
  case "create-node":
25367
25464
  case "update-node":
25368
25465
  case "delete-node":
@@ -25536,6 +25633,7 @@ function ac_transport_state$2(gobj, event, kw, src) {
25536
25633
  refresh_toolbar_buttons(gobj, connected);
25537
25634
  if (!connected) {
25538
25635
  gobj.priv.reread_on_session = true;
25636
+ gobj.priv.parent_rereads.clear();
25539
25637
  answer_drills_in_flight$1(gobj);
25540
25638
  abandon_form_writes(gobj.priv.form_writes).forEach((w) => {
25541
25639
  log_warning(`${gobj_short_name(gobj)}: transport closed, the write ${w.form_write} of '${w.topic_name}' is lost`);
@@ -25612,7 +25710,9 @@ function ac_treedb_node_updated$1(gobj, event, kw, src) {
25612
25710
  * EV_TREEDB_NODE_LINKED / EV_TREEDB_NODE_UNLINKED: the relationship
25613
25711
  * ({hook_name, parent_topic_name, child_topic_name, parent_id,
25614
25712
  * child_id, treedb_name}), not a node. The parent's hook changed and
25615
- * the event does not carry it: read the parent again.
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).
25616
25716
  ********************************************/
25617
25717
  function ac_treedb_node_linked$1(gobj, event, kw, src) {
25618
25718
  let treedb_name = kw_get_str(gobj, kw, "treedb_name", "", 0);
@@ -25623,7 +25723,8 @@ function ac_treedb_node_linked$1(gobj, event, kw, src) {
25623
25723
  log_error(`${gobj_short_name(gobj)}: ${event} without parent_topic_name/parent_id`);
25624
25724
  return -1;
25625
25725
  }
25626
- return treedb_get_node$1(gobj, treedb_name, parent_topic_name, parent_id);
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);
25627
25728
  }
25628
25729
  /********************************************
25629
25730
  * Remote subscription response
@@ -68806,7 +68907,7 @@ function get_nodes(gobj, topic_name) {
68806
68907
  * filtered by treedb_name alone (a {topic_name} filter would match nothing).
68807
68908
  *
68808
68909
  * NOTE: the backend only publishes them when its C_NODE service runs
68809
- * with `with_link_events` (the default since SDK 7.25.23; a v1 backend
68910
+ * with `with_link_events` (the default since SDK 7.26.0; a v1 backend
68810
68911
  * sets it off). Without it, a link/unlink is announced the
68811
68912
  * backward-compatible way — an
68812
68913
  * EV_TREEDB_NODE_UPDATED of the PARENT — which cannot move an edge here:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.25.26",
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",
@@ -1890,7 +1890,7 @@ function get_nodes(gobj, topic_name)
1890
1890
  * filtered by treedb_name alone (a {topic_name} filter would match nothing).
1891
1891
  *
1892
1892
  * NOTE: the backend only publishes them when its C_NODE service runs
1893
- * with `with_link_events` (the default since SDK 7.25.23; a v1 backend
1893
+ * with `with_link_events` (the default since SDK 7.26.0; a v1 backend
1894
1894
  * sets it off). Without it, a link/unlink is announced the
1895
1895
  * backward-compatible way — an
1896
1896
  * EV_TREEDB_NODE_UPDATED of the PARENT — which cannot move an edge here:
@@ -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
 
@@ -1495,7 +1501,7 @@ function subscribe_treedb(gobj, topic_name)
1495
1501
 
1496
1502
  /*
1497
1503
  * A link/unlink changes the hook of the PARENT, and a backend with
1498
- * `with_link_events` (the default since SDK 7.25.23) tells it as the
1504
+ * `with_link_events` (the default since SDK 7.26.0) tells it as the
1499
1505
  * relationship, with no `topic_name`: the parent's topic is
1500
1506
  * `parent_topic_name`. The child's row moves on its own UPDATED.
1501
1507
  */
@@ -1683,7 +1689,7 @@ function answered_record(data)
1683
1689
  * Command to remote service: one node, in the shape the table
1684
1690
  * reads its topic with (TABLE_READ_OPTIONS)
1685
1691
  ************************************************************/
1686
- function treedb_get_node(gobj, treedb_name, topic_name, node_id)
1692
+ function treedb_get_node(gobj, treedb_name, topic_name, node_id, reread_seq)
1687
1693
  {
1688
1694
  let gobj_remote_yuno = gobj_read_pointer_attr(gobj, "gobj_remote_yuno");
1689
1695
  let kw = {
@@ -1696,6 +1702,8 @@ function treedb_get_node(gobj, treedb_name, topic_name, node_id)
1696
1702
 
1697
1703
  kw.__md_command__ = { // Data to be returned
1698
1704
  topic_name: topic_name,
1705
+ node_id: node_id,
1706
+ reread_seq: reread_seq
1699
1707
  };
1700
1708
 
1701
1709
  let ret = gobj_command(
@@ -1711,6 +1719,129 @@ function treedb_get_node(gobj, treedb_name, topic_name, node_id)
1711
1719
  return 0;
1712
1720
  }
1713
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
+
1714
1845
  /************************************************************
1715
1846
  * Command to remote service
1716
1847
  ************************************************************/
@@ -2252,6 +2383,15 @@ function ac_mt_command_answer(gobj, event, kw, src)
2252
2383
  return 0;
2253
2384
  }
2254
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
+
2255
2395
  if(result < 0) {
2256
2396
  if(command === "descs") {
2257
2397
  /* The schema couldn't load (not a treedb, no authz for it, backend
@@ -2346,6 +2486,7 @@ function ac_mt_command_answer(gobj, event, kw, src)
2346
2486
  gobj
2347
2487
  );
2348
2488
  } else if(req_id) {
2489
+ forget_topic_rereads(gobj, topic_name); // the rows a table shows, read now
2349
2490
  gobj_send_event(
2350
2491
  gobj_topic_form,
2351
2492
  "EV_PAGE_LOADED",
@@ -2358,6 +2499,7 @@ function ac_mt_command_answer(gobj, event, kw, src)
2358
2499
  gobj
2359
2500
  );
2360
2501
  } else {
2502
+ forget_topic_rereads(gobj, topic_name);
2361
2503
  gobj_send_event(
2362
2504
  gobj_topic_form,
2363
2505
  "EV_LOAD_NODES",
@@ -2368,19 +2510,6 @@ function ac_mt_command_answer(gobj, event, kw, src)
2368
2510
  }
2369
2511
  break;
2370
2512
 
2371
- case "node":
2372
- /*
2373
- * A parent re-read because a link or an unlink moved its hook
2374
- * (ac_treedb_node_linked): an update of its row.
2375
- */
2376
- gobj_send_event(
2377
- get_gobj_formtable(gobj, kw_get_str(gobj, kw_command, "topic_name", "", 0)),
2378
- "EV_LOAD_NODE_UPDATED",
2379
- [data],
2380
- gobj
2381
- );
2382
- break;
2383
-
2384
2513
  case "create-node":
2385
2514
  case "update-node":
2386
2515
  case "delete-node":
@@ -2679,6 +2808,7 @@ function ac_transport_state(gobj, event, kw, src)
2679
2808
  * no table: its node events are published to nobody. Every open
2680
2809
  * table is read again when the session is back. */
2681
2810
  gobj.priv.reread_on_session = true;
2811
+ gobj.priv.parent_rereads.clear(); /* the reconnect reads every open table */
2682
2812
  answer_drills_in_flight(gobj);
2683
2813
  abandon_form_writes(gobj.priv.form_writes).forEach((w) => {
2684
2814
  log_warning(`${gobj_short_name(gobj)}: transport closed, the write ${w.form_write} of '${w.topic_name}' is lost`);
@@ -2802,7 +2932,9 @@ function ac_treedb_node_updated(gobj, event, kw, src)
2802
2932
  * EV_TREEDB_NODE_LINKED / EV_TREEDB_NODE_UNLINKED: the relationship
2803
2933
  * ({hook_name, parent_topic_name, child_topic_name, parent_id,
2804
2934
  * child_id, treedb_name}), not a node. The parent's hook changed and
2805
- * the event does not carry it: read the parent again.
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).
2806
2938
  ********************************************/
2807
2939
  function ac_treedb_node_linked(gobj, event, kw, src)
2808
2940
  {
@@ -2818,7 +2950,11 @@ function ac_treedb_node_linked(gobj, event, kw, src)
2818
2950
  return -1;
2819
2951
  }
2820
2952
 
2821
- return treedb_get_node(gobj, treedb_name, parent_topic_name, parent_id); // Error already logged
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
2822
2958
  }
2823
2959
 
2824
2960
  /********************************************
@@ -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,
@@ -104,6 +117,7 @@ beforeAll(() => {
104
117
  [
105
118
  SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "topic"),
106
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"),
107
121
  SDATA_END()
108
122
  ],
109
123
  {}, 0, 0, 0, 0
@@ -139,6 +153,7 @@ beforeEach(() => {
139
153
  commands.length = 0;
140
154
  loaded.length = 0;
141
155
  updated.length = 0;
156
+ shown.length = 0;
142
157
  });
143
158
 
144
159
  function build(name)
@@ -162,9 +177,13 @@ function build(name)
162
177
  for(const topic of ["users", "roles"]) {
163
178
  /* Named as the view names its forms: the answer of a `nodes`
164
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();
165
183
  forms[topic] = gobj_create(`${name}_topics?${topic}`, "C_YUI_TREEDB_TOPIC_WITH_FORM",
166
- {topic_name: topic}, topics);
184
+ {topic_name: topic, tabulator: {getRow: (id) => (rows.has(id)? {id}: false)}}, topics);
167
185
  forms[topic].priv_topic = topic;
186
+ forms[topic].rows = rows;
168
187
  }
169
188
  /* What the start of a shell with no routes says is the fixture's,
170
189
  * not the behaviour under test: the check starts here. */
@@ -523,7 +542,7 @@ describe("what the drop hid is read again on the reconnect", () => {
523
542
  });
524
543
 
525
544
  /*
526
- * SDK 7.25.23 turns `with_link_events` on by default: a link or an unlink
545
+ * SDK 7.26.0 turns `with_link_events` on by default: a link or an unlink
527
546
  * no longer arrives as the parent's EV_TREEDB_NODE_UPDATED, but as the
528
547
  * relationship, which carries no node. The parent's row (its hook column)
529
548
  * must still move: the view reads the parent again.
@@ -532,8 +551,9 @@ describe("a link told as EV_TREEDB_NODE_LINKED / UNLINKED", () => {
532
551
 
533
552
  for(const event of ["EV_TREEDB_NODE_LINKED", "EV_TREEDB_NODE_UNLINKED"]) {
534
553
  test(`${event} re-reads the parent and updates its row`, () => {
535
- const {shell, topics} = build(`tl_${event}`);
554
+ const {shell, topics, forms} = build(`tl_${event}`);
536
555
  yui_shell_set_connection_state(shell, true);
556
+ forms.roles.rows.add("admin");
537
557
 
538
558
  gobj_send_event(topics, event, {
539
559
  treedb_name: "treedb_test",
@@ -572,4 +592,210 @@ describe("a link told as EV_TREEDB_NODE_LINKED / UNLINKED", () => {
572
592
  expect(commands.filter((c) => c.command === "node")).toEqual([]);
573
593
  expect(errors()).toEqual([]);
574
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
+ });
575
801
  });