@rootintf/protocol-2phw 2.2.2-api.2 → 2.3.7-api.2

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.
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var eventlog = require('@rootintf/eventlog');
4
+
3
5
  const schema_MsgWarp = validate19;
4
6
  function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
5
7
  evaluated0.props = undefined;
@@ -870,113 +872,6 @@ function requireJsonMsg_cjs () {
870
872
 
871
873
  var jsonMsg_cjsExports = requireJsonMsg_cjs();
872
874
 
873
- //-------------------------------------------------------------------------------------------------
874
- let LOGR_$1 = LOGR.get_instance();
875
- const logr_$1 = LOGR_$1.create({ labels: l_array_(['LOG_EVENTS', 'TIMEOUTS']) });
876
- const l_$1 = logr_$1.l;
877
- //-------------------------------------------------------------------------------------------------
878
- class EventLog {
879
- constructor() {
880
- this.arr_events = []; // In-memory event store
881
- this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
882
- this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
883
- }
884
- addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
885
- const evt = {
886
- type,
887
- dt: Date.now(),
888
- id,
889
- data,
890
- timeout_id: null // Will store timeout reference if set
891
- };
892
- const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
893
- let arr_indices = this.map_index_id.get(id);
894
- if (!arr_indices) {
895
- arr_indices = [];
896
- this.map_index_id.set(id, arr_indices);
897
- }
898
- arr_indices.push(idx);
899
- // Set timeout if specified
900
- if (timeout_ms && timeout_callback) {
901
- evt.timeout_id = setTimeout(() => {
902
- if (this.map_timeouts.delete(idx)) {
903
- evt.timeout_id = null;
904
- timeout_callback({ idx, evt });
905
- logr_$1.log(l_$1.LOG_EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
906
- }
907
- }, timeout_ms);
908
- this.map_timeouts.set(idx, evt.timeout_id);
909
- }
910
- // the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
911
- // When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
912
- // Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
913
- logr_$1.log(l_$1.LOG_EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
914
- return { idx, evt };
915
- }
916
- cancelTimeout(idx) {
917
- const timeout_id = this.map_timeouts.get(idx);
918
- if (timeout_id) {
919
- clearTimeout(timeout_id);
920
- this.map_timeouts.delete(idx);
921
- if (this.arr_events[idx])
922
- this.arr_events[idx].timeout_id = null;
923
- return true;
924
- }
925
- return false;
926
- }
927
- cancelAllTimeouts() {
928
- for (const [idx, timeout_id] of this.map_timeouts) {
929
- clearTimeout(timeout_id);
930
- if (this.arr_events[idx])
931
- this.arr_events[idx].timeout_id = null;
932
- }
933
- this.map_timeouts.clear();
934
- }
935
- getEventsById(id, lookback_ms = null) {
936
- const arr_indices = this.map_index_id.get(id);
937
- if (!arr_indices?.length)
938
- return [];
939
- const result = [];
940
- const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
941
- // Single loop with early cutoff
942
- for (let i = arr_indices.length - 1; i >= 0; i--) {
943
- const idx = arr_indices[i];
944
- const evt = this.arr_events[idx];
945
- if (evt.dt < cutoff)
946
- break;
947
- result.push({ idx, evt });
948
- }
949
- return result; // Newest to oldest order
950
- }
951
- // getRecentEvents(id, lookbackMs) {
952
- // const cutoff = Date.now() - lookbackMs;
953
- // return this.events.filter(e => e.id === id && e.dt >= cutoff);
954
- // }
955
- getEvents(lookback_ms, predicate) {
956
- const cutoff = Date.now() - lookback_ms;
957
- const result = [];
958
- // Iterate backwards from the end
959
- for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
960
- const evt = this.arr_events[idx];
961
- if (evt.dt < cutoff) {
962
- break; // Stop once we pass the cutoff
963
- }
964
- if (predicate(evt)) {
965
- result.push({ idx, evt });
966
- }
967
- }
968
- return result; // Newest to oldest order
969
- }
970
- // setLogr(obj_logr) {
971
- // this.logr.toggled = obj_logr;
972
- // }
973
- clear() {
974
- this.cancelAllTimeouts(); // Clear all timeouts before clearing events
975
- this.arr_events.length = 0;
976
- this.map_index_id.clear();
977
- }
978
- }
979
-
980
875
  // interface Event extends Required<EventMinimal> {
981
876
  // type : string;
982
877
  // id : string | number;
@@ -984,11 +879,11 @@ class EventLog {
984
879
  // };
985
880
  const k_TTL = 20000;
986
881
  //-------------------------------------------------------------------------------------------------
987
- const obj_labels_merge_ = l_merge_(logr_$1.lref.get(), jsonMsg_cjsExports.logr.lref.get()); // VALIDATION : 4
882
+ const obj_labels_merge_ = l_merge_(eventlog.logr.lref.get(), jsonMsg_cjsExports.logr.lref.get()); // VALIDATION : 4
988
883
  const obj_labels_concat_ = l_concat_(obj_labels_merge_, l_array_(['HANDLERS', 'DROPS', 'PROTOCOL_STATE', 'RECVER', 'SENDER']));
989
884
  const lref_ = lRef(obj_labels_concat_);
990
885
  jsonMsg_cjsExports.logr.lref = lref_;
991
- logr_$1.lref = lref_;
886
+ eventlog.logr.lref = lref_;
992
887
  const LOGR_ = LOGR.get_instance();
993
888
  const logr_ = LOGR_.create(); // don't let create() make a new ref, assign lref_ from here
994
889
  logr_.lref = lref_;
@@ -1359,22 +1254,22 @@ class TwoPhW_EventLog {
1359
1254
  // _addEvent(msg: t_msg, json_msg : JSON_Msg, timeout_ms? : number, timeout_callback? : ( args? : {idx_event : number, event : EventMinimal} ) => {}) {
1360
1255
  _addEvent(msg, json_msg, timeout_ms, timeout_callback) {
1361
1256
  const { str_type, json_msgWarp } = this._warp(json_msg);
1362
- const { idx } = this._eventLog.addEvent(str_type, json_msgWarp.warp.id, { msg, json_msg }, timeout_ms, timeout_callback);
1257
+ const { idx } = this._eventLog.add_Event(str_type, json_msgWarp.warp.id, { msg, json_msg }, timeout_ms, timeout_callback);
1363
1258
  logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
1364
1259
  }
1365
1260
  _dropEvent(json_msg) {
1366
1261
  const { json_msgWarp } = this._warp(json_msg);
1367
1262
  if (!json_msgWarp)
1368
1263
  return;
1369
- this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
1264
+ this._eventLog.add_Event('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
1370
1265
  }
1371
1266
  _cancelTimeout(idx_event) {
1372
1267
  logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
1373
- this._eventLog.cancelTimeout(idx_event);
1268
+ this._eventLog.cancel_timeout(idx_event);
1374
1269
  }
1375
1270
  traverse_State(json_msgWarp) {
1376
1271
  const protocolState = new ProtocolStateState();
1377
- const arr_evts = this._eventLog.getEventsById(json_msgWarp.warp.id, k_TTL);
1272
+ const arr_evts = this._eventLog.get_Events_by_id(json_msgWarp.warp.id, k_TTL);
1378
1273
  logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
1379
1274
  //TODO: what is the right TTL? should it be a constant or calculated
1380
1275
  for (let i = arr_evts.length - 1; i >= 0; i--) {
@@ -1609,7 +1504,6 @@ class TwoPhW {
1609
1504
  }
1610
1505
  }
1611
1506
 
1612
- exports.EventLog = EventLog;
1613
1507
  exports.JSON_Msg = jsonMsg_cjsExports.JSON_Msg;
1614
1508
  exports.JSON_MsgAck = jsonMsg_cjsExports.JSON_MsgAck;
1615
1509
  exports.JSON_MsgAckEngage = JSON_MsgAckEngage;
package/dist/twoPhW.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck } from '@rootintf/json-msg';
2
- import { EventLog } from './EventLog-mem.mjs';
2
+ import { EventLog } from '@rootintf/eventlog';
3
3
  type t_msg = string;
4
4
  interface EventMinimal {
5
5
  dt: number;
@@ -128,4 +128,4 @@ declare class TwoPhW {
128
128
  handler_json_msgEffect(msg: t_msg, json_msgEffect: any): boolean;
129
129
  handler_json_msg(msg: t_msg, json_msg: any): boolean;
130
130
  }
131
- export { EventLog, time_ttl_rtt_ as t_ttl_rtt, TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage, logr_ as logr, JSON_Msg, JSON_MsgEffect, JSON_MsgAck, StateAckEngage, StateEngage, StateAckWarp, StateWarp, StateINVALID, StateInitialState };
131
+ export { time_ttl_rtt_ as t_ttl_rtt, TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage, logr_ as logr, JSON_Msg, JSON_MsgEffect, JSON_MsgAck, StateAckEngage, StateEngage, StateAckWarp, StateWarp, StateINVALID, StateInitialState };
@@ -1,3 +1,5 @@
1
+ import { logr } from '@rootintf/eventlog';
2
+
1
3
  const schema_MsgWarp = validate19;
2
4
  function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
3
5
  evaluated0.props = undefined;
@@ -868,113 +870,6 @@ function requireJsonMsg_cjs () {
868
870
 
869
871
  var jsonMsg_cjsExports = requireJsonMsg_cjs();
870
872
 
871
- //-------------------------------------------------------------------------------------------------
872
- let LOGR_$1 = LOGR.get_instance();
873
- const logr_$1 = LOGR_$1.create({ labels: l_array_(['LOG_EVENTS', 'TIMEOUTS']) });
874
- const l_$1 = logr_$1.l;
875
- //-------------------------------------------------------------------------------------------------
876
- class EventLog {
877
- constructor() {
878
- this.arr_events = []; // In-memory event store
879
- this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
880
- this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
881
- }
882
- addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
883
- const evt = {
884
- type,
885
- dt: Date.now(),
886
- id,
887
- data,
888
- timeout_id: null // Will store timeout reference if set
889
- };
890
- const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
891
- let arr_indices = this.map_index_id.get(id);
892
- if (!arr_indices) {
893
- arr_indices = [];
894
- this.map_index_id.set(id, arr_indices);
895
- }
896
- arr_indices.push(idx);
897
- // Set timeout if specified
898
- if (timeout_ms && timeout_callback) {
899
- evt.timeout_id = setTimeout(() => {
900
- if (this.map_timeouts.delete(idx)) {
901
- evt.timeout_id = null;
902
- timeout_callback({ idx, evt });
903
- logr_$1.log(l_$1.LOG_EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
904
- }
905
- }, timeout_ms);
906
- this.map_timeouts.set(idx, evt.timeout_id);
907
- }
908
- // the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
909
- // When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
910
- // Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
911
- logr_$1.log(l_$1.LOG_EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
912
- return { idx, evt };
913
- }
914
- cancelTimeout(idx) {
915
- const timeout_id = this.map_timeouts.get(idx);
916
- if (timeout_id) {
917
- clearTimeout(timeout_id);
918
- this.map_timeouts.delete(idx);
919
- if (this.arr_events[idx])
920
- this.arr_events[idx].timeout_id = null;
921
- return true;
922
- }
923
- return false;
924
- }
925
- cancelAllTimeouts() {
926
- for (const [idx, timeout_id] of this.map_timeouts) {
927
- clearTimeout(timeout_id);
928
- if (this.arr_events[idx])
929
- this.arr_events[idx].timeout_id = null;
930
- }
931
- this.map_timeouts.clear();
932
- }
933
- getEventsById(id, lookback_ms = null) {
934
- const arr_indices = this.map_index_id.get(id);
935
- if (!arr_indices?.length)
936
- return [];
937
- const result = [];
938
- const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
939
- // Single loop with early cutoff
940
- for (let i = arr_indices.length - 1; i >= 0; i--) {
941
- const idx = arr_indices[i];
942
- const evt = this.arr_events[idx];
943
- if (evt.dt < cutoff)
944
- break;
945
- result.push({ idx, evt });
946
- }
947
- return result; // Newest to oldest order
948
- }
949
- // getRecentEvents(id, lookbackMs) {
950
- // const cutoff = Date.now() - lookbackMs;
951
- // return this.events.filter(e => e.id === id && e.dt >= cutoff);
952
- // }
953
- getEvents(lookback_ms, predicate) {
954
- const cutoff = Date.now() - lookback_ms;
955
- const result = [];
956
- // Iterate backwards from the end
957
- for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
958
- const evt = this.arr_events[idx];
959
- if (evt.dt < cutoff) {
960
- break; // Stop once we pass the cutoff
961
- }
962
- if (predicate(evt)) {
963
- result.push({ idx, evt });
964
- }
965
- }
966
- return result; // Newest to oldest order
967
- }
968
- // setLogr(obj_logr) {
969
- // this.logr.toggled = obj_logr;
970
- // }
971
- clear() {
972
- this.cancelAllTimeouts(); // Clear all timeouts before clearing events
973
- this.arr_events.length = 0;
974
- this.map_index_id.clear();
975
- }
976
- }
977
-
978
873
  // interface Event extends Required<EventMinimal> {
979
874
  // type : string;
980
875
  // id : string | number;
@@ -982,11 +877,11 @@ class EventLog {
982
877
  // };
983
878
  const k_TTL = 20000;
984
879
  //-------------------------------------------------------------------------------------------------
985
- const obj_labels_merge_ = l_merge_(logr_$1.lref.get(), jsonMsg_cjsExports.logr.lref.get()); // VALIDATION : 4
880
+ const obj_labels_merge_ = l_merge_(logr.lref.get(), jsonMsg_cjsExports.logr.lref.get()); // VALIDATION : 4
986
881
  const obj_labels_concat_ = l_concat_(obj_labels_merge_, l_array_(['HANDLERS', 'DROPS', 'PROTOCOL_STATE', 'RECVER', 'SENDER']));
987
882
  const lref_ = lRef(obj_labels_concat_);
988
883
  jsonMsg_cjsExports.logr.lref = lref_;
989
- logr_$1.lref = lref_;
884
+ logr.lref = lref_;
990
885
  const LOGR_ = LOGR.get_instance();
991
886
  const logr_ = LOGR_.create(); // don't let create() make a new ref, assign lref_ from here
992
887
  logr_.lref = lref_;
@@ -1357,22 +1252,22 @@ class TwoPhW_EventLog {
1357
1252
  // _addEvent(msg: t_msg, json_msg : JSON_Msg, timeout_ms? : number, timeout_callback? : ( args? : {idx_event : number, event : EventMinimal} ) => {}) {
1358
1253
  _addEvent(msg, json_msg, timeout_ms, timeout_callback) {
1359
1254
  const { str_type, json_msgWarp } = this._warp(json_msg);
1360
- const { idx } = this._eventLog.addEvent(str_type, json_msgWarp.warp.id, { msg, json_msg }, timeout_ms, timeout_callback);
1255
+ const { idx } = this._eventLog.add_Event(str_type, json_msgWarp.warp.id, { msg, json_msg }, timeout_ms, timeout_callback);
1361
1256
  logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
1362
1257
  }
1363
1258
  _dropEvent(json_msg) {
1364
1259
  const { json_msgWarp } = this._warp(json_msg);
1365
1260
  if (!json_msgWarp)
1366
1261
  return;
1367
- this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
1262
+ this._eventLog.add_Event('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
1368
1263
  }
1369
1264
  _cancelTimeout(idx_event) {
1370
1265
  logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
1371
- this._eventLog.cancelTimeout(idx_event);
1266
+ this._eventLog.cancel_timeout(idx_event);
1372
1267
  }
1373
1268
  traverse_State(json_msgWarp) {
1374
1269
  const protocolState = new ProtocolStateState();
1375
- const arr_evts = this._eventLog.getEventsById(json_msgWarp.warp.id, k_TTL);
1270
+ const arr_evts = this._eventLog.get_Events_by_id(json_msgWarp.warp.id, k_TTL);
1376
1271
  logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
1377
1272
  //TODO: what is the right TTL? should it be a constant or calculated
1378
1273
  for (let i = arr_evts.length - 1; i >= 0; i--) {
@@ -1610,4 +1505,4 @@ class TwoPhW {
1610
1505
  var JSON_Msg = jsonMsg_cjsExports.JSON_Msg;
1611
1506
  var JSON_MsgAck = jsonMsg_cjsExports.JSON_MsgAck;
1612
1507
  var JSON_MsgEffect = jsonMsg_cjsExports.JSON_MsgEffect;
1613
- export { EventLog, JSON_Msg, JSON_MsgAck, JSON_MsgAckEngage, JSON_MsgAckWarp, JSON_MsgEffect, JSON_MsgEngage, JSON_MsgOptions, JSON_MsgWarp, StateAckEngage, StateAckWarp, StateEngage, StateINVALID, StateInitialState, StateWarp, TwoPhW, logr_ as logr, time_ttl_rtt_ as t_ttl_rtt };
1508
+ export { JSON_Msg, JSON_MsgAck, JSON_MsgAckEngage, JSON_MsgAckWarp, JSON_MsgEffect, JSON_MsgEngage, JSON_MsgOptions, JSON_MsgWarp, StateAckEngage, StateAckWarp, StateEngage, StateINVALID, StateInitialState, StateWarp, TwoPhW, logr_ as logr, time_ttl_rtt_ as t_ttl_rtt };
package/package.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "@rootintf/protocol-2phw",
3
- "version": "2.2.2-api.2",
3
+ "version": "2.3.7-api.2",
4
4
  "description": "",
5
5
  "main": "dist/twoPhW.cjs.js",
6
- "types": "dist/index.d.ts",
6
+ "types": "dist/twoPhW.d.ts",
7
7
  "browser": "dist/twoPhW.es.mjs",
8
+ "files": [
9
+ "dist",
10
+ "src",
11
+ "schema"
12
+ ],
8
13
  "scripts": {
14
+ "gv:all" : "gv --js --antora --tag api && git add package.json ./antora-docs/antora.yml",
9
15
  "build": "node src/ajv-gen-validate.cjs && rollup --config",
10
16
  "script": "node --experimental-json-modules tests/twoPhW.test.mjs",
11
17
  "test": "jasmine --config=jasmine.json",
@@ -28,6 +34,7 @@
28
34
  "homepage": "https://gitlab.com/interface-x/npm-protocol-2PhW.git#readme",
29
35
  "dependencies": {
30
36
  "@knev/bitlogr": "^3.2.2",
37
+ "@rootintf/eventlog": "^0.0.3",
31
38
  "@rootintf/json-msg": "^2.1.7",
32
39
  "ajv": "^8.17.1"
33
40
  },
package/src/twoPhW.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  import { LOGR, lRef, l_merge, l_array, l_concat, l_LL } from '@knev/bitlogr';
12
12
  import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, logr as logr_json_msg_ } from '@rootintf/json-msg'
13
13
 
14
- import { EventLog, logr as logr_evtlog_ } from './EventLog-mem.mjs'
14
+ import { EventLog, logr as logr_evtlog_ } from '@rootintf/eventlog'
15
15
 
16
16
  type t_msg = string;
17
17
 
@@ -456,7 +456,7 @@ class TwoPhW_EventLog {
456
456
  // _addEvent(msg: t_msg, json_msg : JSON_Msg, timeout_ms? : number, timeout_callback? : ( args? : {idx_event : number, event : EventMinimal} ) => {}) {
457
457
  _addEvent(msg: t_msg, json_msg, timeout_ms? : number, timeout_callback? : () => void) {
458
458
  const { str_type, json_msgWarp }= this._warp(json_msg);
459
- const { idx }= this._eventLog.addEvent(str_type, json_msgWarp.warp.id, {msg, json_msg}, timeout_ms, timeout_callback);
459
+ const { idx }= this._eventLog.add_Event(str_type, json_msgWarp.warp.id, {msg, json_msg}, timeout_ms, timeout_callback);
460
460
  logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
461
461
  }
462
462
 
@@ -464,18 +464,18 @@ class TwoPhW_EventLog {
464
464
  const { json_msgWarp }= this._warp(json_msg);
465
465
  if (! json_msgWarp)
466
466
  return;
467
- this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
467
+ this._eventLog.add_Event('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
468
468
  }
469
469
 
470
470
  _cancelTimeout(idx_event) {
471
471
  logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
472
- this._eventLog.cancelTimeout(idx_event);
472
+ this._eventLog.cancel_timeout(idx_event);
473
473
  }
474
474
 
475
475
  traverse_State(json_msgWarp) {
476
476
  const protocolState = new ProtocolStateState();
477
477
 
478
- const arr_evts= this._eventLog.getEventsById(json_msgWarp.warp.id, k_TTL);
478
+ const arr_evts= this._eventLog.get_Events_by_id(json_msgWarp.warp.id, k_TTL);
479
479
  logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
480
480
  //TODO: what is the right TTL? should it be a constant or calculated
481
481
 
@@ -810,8 +810,7 @@ class TwoPhW {
810
810
 
811
811
  //-------------------------------------------------------------------------------------------------
812
812
 
813
- export {
814
- EventLog,
813
+ export {
815
814
  time_ttl_rtt_ as t_ttl_rtt,
816
815
  TwoPhW,
817
816
  JSON_MsgOptions,
package/dev.txt DELETED
@@ -1,23 +0,0 @@
1
-
2
- npm outdated
3
- npm audit
4
-
5
- npm i
6
- npm run build
7
- npm run test
8
-
9
- gv --js --tag api
10
- npm i
11
- npm run build
12
- (npm run test)
13
- git commit
14
- npm publish --tag api
15
-
16
-
17
-
18
- TODO
19
- - what to do if:
20
- - AckWarp is lost? resend Warp?
21
- - Engage is lost? resend AckWarp? drop it?
22
- - AckEngage is lost? resend Engage?
23
-
@@ -1,28 +0,0 @@
1
- export class EventLog {
2
- arr_events: any[];
3
- map_index_id: Map<any, any>;
4
- map_timeouts: Map<any, any>;
5
- addEvent(type: any, id: any, data: any, timeout_ms?: any, timeout_callback?: any): {
6
- idx: number;
7
- evt: {
8
- type: any;
9
- dt: number;
10
- id: any;
11
- data: any;
12
- timeout_id: any;
13
- };
14
- };
15
- cancelTimeout(idx: any): boolean;
16
- cancelAllTimeouts(): void;
17
- getEventsById(id: any, lookback_ms?: any): {
18
- idx: any;
19
- evt: any;
20
- }[];
21
- getEvents(lookback_ms: any, predicate: any): {
22
- idx: number;
23
- evt: any;
24
- }[];
25
- clear(): void;
26
- }
27
- declare const logr_: any;
28
- export { logr_ as logr };
package/jasmine.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "spec_dir": "tests",
3
- "spec_files": [
4
- "**/*[sS]pec.?(m)js",
5
- "!**/*nospec.js"
6
- ]
7
- }
package/rollup.config.mjs DELETED
@@ -1,35 +0,0 @@
1
-
2
- import resolve from '@rollup/plugin-node-resolve';
3
- import commonjs from '@rollup/plugin-commonjs';
4
- import json from '@rollup/plugin-json';
5
- import typescript from '@rollup/plugin-typescript';
6
-
7
- export default [
8
- {
9
- input: 'src/twoPhW.ts',
10
- output: {
11
- file: 'dist/twoPhW.es.mjs',
12
- format: 'es'
13
- },
14
- plugins: [
15
- resolve(),
16
- commonjs(),
17
- json(),
18
- typescript({ tsconfig: './tsconfig.json' })
19
- ]
20
- },
21
- {
22
- input: 'src/twoPhW.ts',
23
- output: {
24
- file: 'dist/twoPhW.cjs.js',
25
- format: 'cjs'
26
- },
27
- plugins: [
28
- resolve(),
29
- commonjs(),
30
- json(),
31
- typescript({ tsconfig: './tsconfig.json' })
32
- ]
33
- }
34
-
35
- ];
@@ -1,133 +0,0 @@
1
-
2
- import { LOGR, l_array } from '@knev/bitlogr';
3
-
4
- //-------------------------------------------------------------------------------------------------
5
-
6
- let LOGR_= LOGR.get_instance();
7
- const logr_= LOGR_.create({ labels: l_array(['LOG_EVENTS', 'TIMEOUTS']) });
8
- const l_= logr_.l;
9
-
10
- //-------------------------------------------------------------------------------------------------
11
-
12
- class EventLog {
13
- constructor() {
14
- this.arr_events = []; // In-memory event store
15
- this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
16
- this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
17
- }
18
-
19
- addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
20
- const evt = {
21
- type,
22
- dt: Date.now(),
23
- id,
24
- data,
25
- timeout_id: null // Will store timeout reference if set
26
- };
27
- const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
28
-
29
- let arr_indices = this.map_index_id.get(id);
30
- if (! arr_indices) {
31
- arr_indices = [];
32
- this.map_index_id.set(id, arr_indices);
33
- }
34
- arr_indices.push(idx);
35
-
36
- // Set timeout if specified
37
- if (timeout_ms && timeout_callback) {
38
- evt.timeout_id = setTimeout(() => {
39
- if (this.map_timeouts.delete(idx)) {
40
- evt.timeout_id = null;
41
- timeout_callback({idx, evt});
42
- logr_.log(l_.LOG_EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
43
- }
44
- }, timeout_ms);
45
-
46
- this.map_timeouts.set(idx, evt.timeout_id);
47
- }
48
-
49
- // the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
50
- // When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
51
- // Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
52
- logr_.log(l_.LOG_EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
53
- return { idx, evt };
54
- }
55
-
56
- cancelTimeout(idx) {
57
- const timeout_id = this.map_timeouts.get(idx);
58
- if (timeout_id) {
59
- clearTimeout(timeout_id);
60
- this.map_timeouts.delete(idx);
61
- if (this.arr_events[idx])
62
- this.arr_events[idx].timeout_id = null;
63
- return true;
64
- }
65
- return false;
66
- }
67
-
68
- cancelAllTimeouts() {
69
- for (const [idx, timeout_id] of this.map_timeouts) {
70
- clearTimeout(timeout_id);
71
- if (this.arr_events[idx])
72
- this.arr_events[idx].timeout_id = null;
73
- }
74
- this.map_timeouts.clear();
75
- }
76
-
77
- getEventsById(id, lookback_ms = null) {
78
- const arr_indices = this.map_index_id.get(id);
79
- if (!arr_indices?.length) return [];
80
-
81
- const result = [];
82
- const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
83
-
84
- // Single loop with early cutoff
85
- for (let i = arr_indices.length - 1; i >= 0; i--) {
86
- const idx = arr_indices[i];
87
- const evt = this.arr_events[idx];
88
- if (evt.dt < cutoff)
89
- break;
90
- result.push({ idx, evt });
91
- }
92
-
93
- return result; // Newest to oldest order
94
- }
95
-
96
- // getRecentEvents(id, lookbackMs) {
97
- // const cutoff = Date.now() - lookbackMs;
98
- // return this.events.filter(e => e.id === id && e.dt >= cutoff);
99
- // }
100
-
101
- getEvents(lookback_ms, predicate) {
102
- const cutoff = Date.now() - lookback_ms;
103
- const result = [];
104
-
105
- // Iterate backwards from the end
106
- for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
107
- const evt = this.arr_events[idx];
108
- if (evt.dt < cutoff) {
109
- break; // Stop once we pass the cutoff
110
- }
111
- if (predicate(evt)) {
112
- result.push({ idx, evt });
113
- }
114
- }
115
-
116
- return result; // Newest to oldest order
117
- }
118
-
119
- // setLogr(obj_logr) {
120
- // this.logr.toggled = obj_logr;
121
- // }
122
-
123
- clear() {
124
- this.cancelAllTimeouts(); // Clear all timeouts before clearing events
125
- this.arr_events.length = 0;
126
- this.map_index_id.clear();
127
- }
128
- }
129
-
130
- export {
131
- EventLog,
132
- logr_ as logr
133
- };