@rootintf/protocol-2phw 1.2.4-api.1 → 1.3.3-api.1

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,4 +1,180 @@
1
- const schema_MsgWarp = validate19;function validate19(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate19.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.warp === undefined) && (missing0 = "warp")){validate19.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.warp !== undefined){let data0 = data.warp;const _errs1 = errors;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((((data0.id === undefined) && (missing1 = "id")) || ((data0.user === undefined) && (missing1 = "user"))) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))) || ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec"))){validate19.errors = [{instancePath:instancePath+"/warp",schemaPath:"#/properties/warp/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.id !== undefined){const _errs3 = errors;if(typeof data0.id !== "string"){validate19.errors = [{instancePath:instancePath+"/warp/id",schemaPath:"definitions#/definitions/warp_id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.ttl_msec !== undefined){let data2 = data0.ttl_msec;const _errs6 = errors;if(!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))){validate19.errors = [{instancePath:instancePath+"/warp/ttl_msec",schemaPath:"#/properties/warp/properties/ttl_msec/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid1 = _errs6 === errors;}else {var valid1 = true;}if(valid1){if(data0.instantaneous !== undefined){const _errs8 = errors;if(typeof data0.instantaneous !== "boolean"){validate19.errors = [{instancePath:instancePath+"/warp/instantaneous",schemaPath:"#/properties/warp/properties/instantaneous/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}var valid1 = _errs8 === errors;}else {var valid1 = true;}}}}}else {validate19.errors = [{instancePath:instancePath+"/warp",schemaPath:"#/properties/warp/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data["2PhW"] !== undefined){const _errs10 = errors;if("1" !== data["2PhW"]){validate19.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "1"},message:"must be equal to constant"}];return false;}var valid0 = _errs10 === errors;}else {var valid0 = true;}}}}else {validate19.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate19.errors = vErrors;return errors === 0;}validate19.evaluated = {"props":{"warp":true,"2PhW":true},"dynamicProps":false,"dynamicItems":false};const schema_MsgEngage = validate20;function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate20.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.engage === undefined) && (missing0 = "engage")){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.engage !== undefined){let data0 = data.engage;const _errs1 = errors;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((data0.ok === undefined) && (missing1 = "ok")) || ((data0.rtt_msec === undefined) && (missing1 = "rtt_msec"))){validate20.errors = [{instancePath:instancePath+"/engage",schemaPath:"#/properties/engage/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.ok !== undefined){const _errs3 = errors;if(typeof data0.ok !== "boolean"){validate20.errors = [{instancePath:instancePath+"/engage/ok",schemaPath:"#/properties/engage/properties/ok/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.rtt_msec !== undefined){let data2 = data0.rtt_msec;const _errs5 = errors;if(!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))){validate20.errors = [{instancePath:instancePath+"/engage/rtt_msec",schemaPath:"#/properties/engage/properties/rtt_msec/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid1 = _errs5 === errors;}else {var valid1 = true;}}}}else {validate20.errors = [{instancePath:instancePath+"/engage",schemaPath:"#/properties/engage/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data["2PhW"] !== undefined){const _errs7 = errors;if("1" !== data["2PhW"]){validate20.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "1"},message:"must be equal to constant"}];return false;}var valid0 = _errs7 === errors;}else {var valid0 = true;}}}}else {validate20.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate20.errors = vErrors;return errors === 0;}validate20.evaluated = {"props":{"engage":true,"2PhW":true},"dynamicProps":false,"dynamicItems":false};
1
+ const schema_MsgWarp = validate19;
2
+ function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
3
+ evaluated0.props = undefined;
4
+ } if (evaluated0.dynamicItems) {
5
+ evaluated0.items = undefined;
6
+ } {
7
+ if (data && typeof data == "object" && !Array.isArray(data)) {
8
+ let missing0;
9
+ if ((data.warp === undefined) && (missing0 = "warp")) {
10
+ validate19.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
11
+ return false;
12
+ }
13
+ else {
14
+ if (data.warp !== undefined) {
15
+ let data0 = data.warp;
16
+ const _errs1 = errors;
17
+ {
18
+ if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
19
+ let missing1;
20
+ if (((((data0.id === undefined) && (missing1 = "id")) || ((data0.user === undefined) && (missing1 = "user"))) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))) || ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec"))) {
21
+ validate19.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
22
+ return false;
23
+ }
24
+ else {
25
+ if (data0.id !== undefined) {
26
+ const _errs3 = errors;
27
+ if (typeof data0.id !== "string") {
28
+ validate19.errors = [{ instancePath: instancePath + "/warp/id", schemaPath: "definitions#/definitions/warp_id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
29
+ return false;
30
+ }
31
+ var valid1 = _errs3 === errors;
32
+ }
33
+ else {
34
+ var valid1 = true;
35
+ }
36
+ if (valid1) {
37
+ if (data0.ttl_msec !== undefined) {
38
+ let data2 = data0.ttl_msec;
39
+ const _errs6 = errors;
40
+ if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
41
+ validate19.errors = [{ instancePath: instancePath + "/warp/ttl_msec", schemaPath: "#/properties/warp/properties/ttl_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
42
+ return false;
43
+ }
44
+ var valid1 = _errs6 === errors;
45
+ }
46
+ else {
47
+ var valid1 = true;
48
+ }
49
+ if (valid1) {
50
+ if (data0.instantaneous !== undefined) {
51
+ const _errs8 = errors;
52
+ if (typeof data0.instantaneous !== "boolean") {
53
+ validate19.errors = [{ instancePath: instancePath + "/warp/instantaneous", schemaPath: "#/properties/warp/properties/instantaneous/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
54
+ return false;
55
+ }
56
+ var valid1 = _errs8 === errors;
57
+ }
58
+ else {
59
+ var valid1 = true;
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ else {
66
+ validate19.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
67
+ return false;
68
+ }
69
+ }
70
+ var valid0 = _errs1 === errors;
71
+ }
72
+ else {
73
+ var valid0 = true;
74
+ }
75
+ if (valid0) {
76
+ if (data["2PhW"] !== undefined) {
77
+ const _errs10 = errors;
78
+ if ("1" !== data["2PhW"]) {
79
+ validate19.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "1" }, message: "must be equal to constant" }];
80
+ return false;
81
+ }
82
+ var valid0 = _errs10 === errors;
83
+ }
84
+ else {
85
+ var valid0 = true;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ else {
91
+ validate19.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
92
+ return false;
93
+ }
94
+ } validate19.errors = vErrors; return errors === 0; }
95
+ validate19.evaluated = { "props": { "warp": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
96
+ const schema_MsgEngage = validate20;
97
+ function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
98
+ evaluated0.props = undefined;
99
+ } if (evaluated0.dynamicItems) {
100
+ evaluated0.items = undefined;
101
+ } {
102
+ if (data && typeof data == "object" && !Array.isArray(data)) {
103
+ let missing0;
104
+ if ((data.engage === undefined) && (missing0 = "engage")) {
105
+ validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
106
+ return false;
107
+ }
108
+ else {
109
+ if (data.engage !== undefined) {
110
+ let data0 = data.engage;
111
+ const _errs1 = errors;
112
+ {
113
+ if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
114
+ let missing1;
115
+ if (((data0.ok === undefined) && (missing1 = "ok")) || ((data0.rtt_msec === undefined) && (missing1 = "rtt_msec"))) {
116
+ validate20.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
117
+ return false;
118
+ }
119
+ else {
120
+ if (data0.ok !== undefined) {
121
+ const _errs3 = errors;
122
+ if (typeof data0.ok !== "boolean") {
123
+ validate20.errors = [{ instancePath: instancePath + "/engage/ok", schemaPath: "#/properties/engage/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
124
+ return false;
125
+ }
126
+ var valid1 = _errs3 === errors;
127
+ }
128
+ else {
129
+ var valid1 = true;
130
+ }
131
+ if (valid1) {
132
+ if (data0.rtt_msec !== undefined) {
133
+ let data2 = data0.rtt_msec;
134
+ const _errs5 = errors;
135
+ if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
136
+ validate20.errors = [{ instancePath: instancePath + "/engage/rtt_msec", schemaPath: "#/properties/engage/properties/rtt_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
137
+ return false;
138
+ }
139
+ var valid1 = _errs5 === errors;
140
+ }
141
+ else {
142
+ var valid1 = true;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ else {
148
+ validate20.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
149
+ return false;
150
+ }
151
+ }
152
+ var valid0 = _errs1 === errors;
153
+ }
154
+ else {
155
+ var valid0 = true;
156
+ }
157
+ if (valid0) {
158
+ if (data["2PhW"] !== undefined) {
159
+ const _errs7 = errors;
160
+ if ("1" !== data["2PhW"]) {
161
+ validate20.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "1" }, message: "must be equal to constant" }];
162
+ return false;
163
+ }
164
+ var valid0 = _errs7 === errors;
165
+ }
166
+ else {
167
+ var valid0 = true;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ else {
173
+ validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
174
+ return false;
175
+ }
176
+ } validate20.errors = vErrors; return errors === 0; }
177
+ validate20.evaluated = { "props": { "engage": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
2
178
 
3
179
  // console.log('OUT', __name({variableName}) );
4
180
 
@@ -431,139 +607,118 @@ function requireJsonMsg_cjs () {
431
607
 
432
608
  var jsonMsg_cjsExports = requireJsonMsg_cjs();
433
609
 
434
- //-------------------------------------------------------------------------------------------------
435
-
436
- let LOGR_$1= LOGR.get_instance();
437
- const log_$1= LOGR_$1.log;
438
-
439
- const l_$1= {
440
- EVENTS : 0b1 << 0,
441
- TIMEOUTS : 0b1 << 1,
442
- };
443
- LOGR_$1.labels= l_$1;
444
- // LOGR_.toggled= {
445
- // EVENTS : 1
446
- // }
447
-
448
-
449
- //-------------------------------------------------------------------------------------------------
450
-
451
- class EventLog {
452
- constructor() {
453
- this.arr_events = []; // In-memory event store
454
- this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
455
- this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
456
- }
457
-
458
- addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
459
- const evt = {
460
- type,
461
- dt: Date.now(),
462
- id,
463
- data,
464
- timeout_id: null // Will store timeout reference if set
465
- };
466
- const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
467
-
468
- let arr_indices = this.map_index_id.get(id);
469
- if (! arr_indices) {
470
- arr_indices = [];
471
- this.map_index_id.set(id, arr_indices);
472
- }
473
- arr_indices.push(idx);
474
-
475
- // Set timeout if specified
476
- if (timeout_ms && timeout_callback) {
477
- evt.timeout_id = setTimeout(() => {
478
- if (this.map_timeouts.delete(idx)) {
479
- evt.timeout_id = null;
480
- timeout_callback({idx, evt});
481
- log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
482
- }
483
- }, timeout_ms);
484
-
485
- this.map_timeouts.set(idx, evt.timeout_id);
486
- }
487
-
488
- // the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
489
- // 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().
490
- // Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
491
- log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
492
- return { idx, evt };
493
- }
494
-
495
- cancelTimeout(idx) {
496
- const timeout_id = this.map_timeouts.get(idx);
497
- if (timeout_id) {
498
- clearTimeout(timeout_id);
499
- this.map_timeouts.delete(idx);
500
- if (this.arr_events[idx])
501
- this.arr_events[idx].timeout_id = null;
502
- return true;
503
- }
504
- return false;
505
- }
506
-
507
- cancelAllTimeouts() {
508
- for (const [idx, timeout_id] of this.map_timeouts) {
509
- clearTimeout(timeout_id);
510
- if (this.arr_events[idx])
511
- this.arr_events[idx].timeout_id = null;
512
- }
513
- this.map_timeouts.clear();
514
- }
515
-
516
- getEventsById(id, lookback_ms = null) {
517
- const arr_indices = this.map_index_id.get(id);
518
- if (!arr_indices?.length) return [];
519
-
520
- const result = [];
521
- const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
522
-
523
- // Single loop with early cutoff
524
- for (let i = arr_indices.length - 1; i >= 0; i--) {
525
- const idx = arr_indices[i];
526
- const evt = this.arr_events[idx];
527
- if (evt.dt < cutoff)
528
- break;
529
- result.push({ idx, evt });
530
- }
531
-
532
- return result; // Newest to oldest order
533
- }
534
-
535
- // getRecentEvents(id, lookbackMs) {
536
- // const cutoff = Date.now() - lookbackMs;
537
- // return this.events.filter(e => e.id === id && e.dt >= cutoff);
538
- // }
539
-
540
- getEvents(lookback_ms, predicate) {
541
- const cutoff = Date.now() - lookback_ms;
542
- const result = [];
543
-
544
- // Iterate backwards from the end
545
- for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
546
- const evt = this.arr_events[idx];
547
- if (evt.dt < cutoff) {
548
- break; // Stop once we pass the cutoff
549
- }
550
- if (predicate(evt)) {
551
- result.push({ idx, evt });
552
- }
553
- }
554
-
555
- return result; // Newest to oldest order
556
- }
557
-
558
- // setLogr(obj_logr) {
559
- // this.logr.toggled = obj_logr;
560
- // }
561
-
562
- clear() {
563
- this.cancelAllTimeouts(); // Clear all timeouts before clearing events
564
- this.arr_events.length = 0;
565
- this.map_index_id.clear();
566
- }
610
+ //-------------------------------------------------------------------------------------------------
611
+ let LOGR_$1 = LOGR.get_instance();
612
+ const log_$1 = LOGR_$1.log;
613
+ const l_$1 = {
614
+ EVENTS: 0b1 << 0,
615
+ TIMEOUTS: 0b1 << 1,
616
+ };
617
+ LOGR_$1.labels = l_$1;
618
+ // LOGR_.toggled= {
619
+ // EVENTS : 1
620
+ // }
621
+ //-------------------------------------------------------------------------------------------------
622
+ class EventLog {
623
+ constructor() {
624
+ this.arr_events = []; // In-memory event store
625
+ this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
626
+ this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
627
+ }
628
+ addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
629
+ const evt = {
630
+ type,
631
+ dt: Date.now(),
632
+ id,
633
+ data,
634
+ timeout_id: null // Will store timeout reference if set
635
+ };
636
+ const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
637
+ let arr_indices = this.map_index_id.get(id);
638
+ if (!arr_indices) {
639
+ arr_indices = [];
640
+ this.map_index_id.set(id, arr_indices);
641
+ }
642
+ arr_indices.push(idx);
643
+ // Set timeout if specified
644
+ if (timeout_ms && timeout_callback) {
645
+ evt.timeout_id = setTimeout(() => {
646
+ if (this.map_timeouts.delete(idx)) {
647
+ evt.timeout_id = null;
648
+ timeout_callback({ idx, evt });
649
+ log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
650
+ }
651
+ }, timeout_ms);
652
+ this.map_timeouts.set(idx, evt.timeout_id);
653
+ }
654
+ // the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
655
+ // 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().
656
+ // Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
657
+ log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
658
+ return { idx, evt };
659
+ }
660
+ cancelTimeout(idx) {
661
+ const timeout_id = this.map_timeouts.get(idx);
662
+ if (timeout_id) {
663
+ clearTimeout(timeout_id);
664
+ this.map_timeouts.delete(idx);
665
+ if (this.arr_events[idx])
666
+ this.arr_events[idx].timeout_id = null;
667
+ return true;
668
+ }
669
+ return false;
670
+ }
671
+ cancelAllTimeouts() {
672
+ for (const [idx, timeout_id] of this.map_timeouts) {
673
+ clearTimeout(timeout_id);
674
+ if (this.arr_events[idx])
675
+ this.arr_events[idx].timeout_id = null;
676
+ }
677
+ this.map_timeouts.clear();
678
+ }
679
+ getEventsById(id, lookback_ms = null) {
680
+ const arr_indices = this.map_index_id.get(id);
681
+ if (!arr_indices?.length)
682
+ return [];
683
+ const result = [];
684
+ const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
685
+ // Single loop with early cutoff
686
+ for (let i = arr_indices.length - 1; i >= 0; i--) {
687
+ const idx = arr_indices[i];
688
+ const evt = this.arr_events[idx];
689
+ if (evt.dt < cutoff)
690
+ break;
691
+ result.push({ idx, evt });
692
+ }
693
+ return result; // Newest to oldest order
694
+ }
695
+ // getRecentEvents(id, lookbackMs) {
696
+ // const cutoff = Date.now() - lookbackMs;
697
+ // return this.events.filter(e => e.id === id && e.dt >= cutoff);
698
+ // }
699
+ getEvents(lookback_ms, predicate) {
700
+ const cutoff = Date.now() - lookback_ms;
701
+ const result = [];
702
+ // Iterate backwards from the end
703
+ for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
704
+ const evt = this.arr_events[idx];
705
+ if (evt.dt < cutoff) {
706
+ break; // Stop once we pass the cutoff
707
+ }
708
+ if (predicate(evt)) {
709
+ result.push({ idx, evt });
710
+ }
711
+ }
712
+ return result; // Newest to oldest order
713
+ }
714
+ // setLogr(obj_logr) {
715
+ // this.logr.toggled = obj_logr;
716
+ // }
717
+ clear() {
718
+ this.cancelAllTimeouts(); // Clear all timeouts before clearing events
719
+ this.arr_events.length = 0;
720
+ this.map_index_id.clear();
721
+ }
567
722
  }
568
723
 
569
724
  // interface Event extends Required<EventMinimal> {
@@ -571,9 +726,6 @@ class EventLog {
571
726
  // id : string | number;
572
727
  // timeout_id : NodeJS.Timeout | null;
573
728
  // };
574
- const k_ERROR = -1;
575
- const k_NOP = 0;
576
- // const k_HANDLED = 1;
577
729
  const k_TTL = 20000;
578
730
  //-------------------------------------------------------------------------------------------------
579
731
  const LOGR_ = LOGR.get_instance();
@@ -593,19 +745,19 @@ class Config {
593
745
  // Initialize callbacks as no-op functions
594
746
  this._callback_msgWarp = (_msg, _json_msg) => {
595
747
  console.assert(false, 'callback_msgWarp uninitialized');
596
- return k_ERROR;
748
+ return false;
597
749
  };
598
750
  this._callback_msgEngage = (_msg, _json_msg) => {
599
751
  console.assert(false, 'callback_msgEngage uninitialized');
600
- return k_ERROR;
752
+ return false;
601
753
  };
602
754
  this._callback_msgAckWarp = (_msg, _json_msg) => {
603
755
  console.assert(false, 'callback_msgAckWarp uninitialized');
604
- return k_ERROR;
756
+ return false;
605
757
  };
606
758
  this._callback_msgAckEngage = (_msg, _json_msg) => {
607
759
  console.assert(false, 'callback_msgAckEngage uninitialized');
608
- return k_ERROR;
760
+ return false;
609
761
  };
610
762
  this._callback_msg_sent_expired = (_msg, _json_msg) => {
611
763
  console.assert(false, '_callback_msg_sent_expired uninitialized');
@@ -1036,7 +1188,7 @@ class TwoPhW {
1036
1188
  return true;
1037
1189
  }
1038
1190
  */
1039
- return k_NOP;
1191
+ return false;
1040
1192
  }
1041
1193
  //-------------------------------------------------------------------------------------------------
1042
1194
  // sender Source (src)
@@ -1049,7 +1201,7 @@ class TwoPhW {
1049
1201
  }));
1050
1202
  log_(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
1051
1203
  if (!b_changeState)
1052
- return k_NOP;
1204
+ return false;
1053
1205
  const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
1054
1206
  const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
1055
1207
  this.eventLog._addEvent(msg, json_msgWarp, timeout_ms - elapsed_ms, () => {
@@ -1066,7 +1218,7 @@ class TwoPhW {
1066
1218
  }));
1067
1219
  log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
1068
1220
  if (!b_changeState)
1069
- return k_NOP;
1221
+ return false;
1070
1222
  this.eventLog._cancelTimeout(protocolState.state.idx_event);
1071
1223
  this.eventLog._addEvent(msg, json_msgAckWarp);
1072
1224
  return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
@@ -1081,7 +1233,7 @@ class TwoPhW {
1081
1233
  }));
1082
1234
  log_(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
1083
1235
  if (!b_changeState)
1084
- return k_NOP;
1236
+ return false;
1085
1237
  const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
1086
1238
  const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
1087
1239
  this.eventLog._addEvent(msg, json_msgEngage, timeout_ms - elapsed_ms, () => {
@@ -1098,7 +1250,7 @@ class TwoPhW {
1098
1250
  }));
1099
1251
  log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
1100
1252
  if (!b_changeState)
1101
- return k_NOP;
1253
+ return false;
1102
1254
  this.eventLog._cancelTimeout(protocolState.state.idx_event);
1103
1255
  this.eventLog._addEvent(msg, json_msgAckEngage);
1104
1256
  return this.config._callback_msgAckEngage(msg, json_msgAckEngage);
@@ -1114,7 +1266,7 @@ class TwoPhW {
1114
1266
  }));
1115
1267
  log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
1116
1268
  if (!b_changeState)
1117
- return k_NOP;
1269
+ return false;
1118
1270
  this.eventLog._addEvent(msg, json_msgWarp);
1119
1271
  return this.config._callback_msgWarp(msg, json_msgWarp);
1120
1272
  }
@@ -1128,7 +1280,7 @@ class TwoPhW {
1128
1280
  }));
1129
1281
  log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
1130
1282
  if (!b_changeState)
1131
- return k_NOP;
1283
+ return false;
1132
1284
  const elapsed_ms = Date.now() - Date.parse(json_msgAckWarp.dt);
1133
1285
  const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
1134
1286
  this.eventLog._addEvent(msg, json_msgAckWarp, timeout_ms - elapsed_ms, () => {
@@ -1145,7 +1297,7 @@ class TwoPhW {
1145
1297
  }));
1146
1298
  log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
1147
1299
  if (!b_changeState)
1148
- return k_NOP;
1300
+ return false;
1149
1301
  this.eventLog._cancelTimeout(protocolState.state.idx_event);
1150
1302
  this.eventLog._addEvent(msg, json_msgEngage);
1151
1303
  return this.config._callback_msgEngage(msg, json_msgEngage);
@@ -1160,33 +1312,32 @@ class TwoPhW {
1160
1312
  }));
1161
1313
  log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
1162
1314
  if (!b_changeState)
1163
- return k_NOP;
1315
+ return false;
1164
1316
  this.eventLog._addEvent(msg, json_msgAckEngage);
1165
1317
  }
1166
1318
  //-------------------------------------------------------------------------------------------------
1167
1319
  handler_json_msgAck_msg(msg, json_msgAck_msg) {
1168
1320
  log_(l_.HANDLERS, () => ['handler_json_msgAck_msg: ', json_msgAck_msg]);
1169
- let ret;
1170
- if (JSON_MsgAckWarp.validate(json_msgAck_msg) && (ret = this._handler_msgAckWarp(msg, json_msgAck_msg)))
1171
- return ret;
1172
- if (JSON_MsgAckEngage.validate(json_msgAck_msg) && (ret = this._handler_msgAckEngage(msg, json_msgAck_msg)))
1173
- return ret;
1174
- return k_NOP;
1321
+ if (JSON_MsgAckWarp.validate(json_msgAck_msg) && this._handler_msgAckWarp(msg, json_msgAck_msg))
1322
+ return true;
1323
+ if (JSON_MsgAckEngage.validate(json_msgAck_msg) && this._handler_msgAckEngage(msg, json_msgAck_msg))
1324
+ return true;
1325
+ return false;
1175
1326
  }
1176
1327
  handler_json_msg_msg(msg, json_msg_msg) {
1177
1328
  log_(l_.HANDLERS, () => ['handler_json_msg_msg: ', json_msg_msg]);
1178
- let ret;
1179
- if (JSON_MsgEngage.validate(json_msg_msg) && (ret = this._handler_msgEngage(msg, json_msg_msg)))
1180
- return ret;
1329
+ if (jsonMsg_cjsExports.JSON_MsgAck_msg.validate(json_msg_msg) && this.handler_json_msgAck_msg(msg, json_msg_msg))
1330
+ return true;
1331
+ if (JSON_MsgEngage.validate(json_msg_msg) && this._handler_msgEngage(msg, json_msg_msg))
1332
+ return true;
1181
1333
  // if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
1182
1334
  // return true;
1183
- return k_NOP;
1335
+ return false;
1184
1336
  }
1185
1337
  handler_json_msg(msg, json_msg) {
1186
1338
  log_(l_.HANDLERS, () => ['handler_json_msg: ', json_msg]);
1187
- let ret;
1188
- if (JSON_MsgWarp.validate(json_msg) && (ret = this._handler_msgWarp(msg, json_msg)))
1189
- return ret;
1339
+ if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg))
1340
+ return true;
1190
1341
  // https://attacomsian.com/blog/javascript-iterate-objects
1191
1342
  // Object.keys(json_msg).forEach((key, index) => {
1192
1343
  // if (key == 'dt')
@@ -1195,30 +1346,15 @@ class TwoPhW {
1195
1346
  // return;
1196
1347
  // console.log(`${key}: ${json_msg[key]}`);
1197
1348
  // });
1198
- return k_NOP;
1349
+ return false;
1199
1350
  }
1200
1351
  handler_json(msg, json) {
1201
- if (jsonMsg_cjsExports.JSON_Msg.validate(json)) {
1202
- if (jsonMsg_cjsExports.JSON_Msg_msg.validate(json)) {
1203
- if (jsonMsg_cjsExports.JSON_MsgAck_msg.validate(json)) {
1204
- let ret;
1205
- if (JSON_MsgAckWarp.validate(json) && (ret = this._handler_msgAckWarp(msg, json)))
1206
- return ret;
1207
- if (JSON_MsgAckEngage.validate(json) && (ret = this._handler_msgAckEngage(msg, json)))
1208
- return ret;
1209
- return k_NOP;
1210
- }
1211
- let ret;
1212
- if (JSON_MsgEngage.validate(json) && (ret = this._handler_msgEngage(msg, json)))
1213
- return ret;
1214
- return k_NOP;
1215
- }
1216
- let ret;
1217
- if (JSON_MsgWarp.validate(json) && (ret = this._handler_msgWarp(msg, json)))
1218
- return ret;
1219
- return k_NOP;
1220
- }
1221
- return k_NOP;
1352
+ log_(l_.HANDLERS, () => ['handler_json: ', json]);
1353
+ if (jsonMsg_cjsExports.JSON_Msg_msg.validate(json) && this.handler_json_msg_msg(msg, json))
1354
+ return true;
1355
+ if (jsonMsg_cjsExports.JSON_Msg.validate(json) && this.handler_json_msg(msg, json))
1356
+ return true;
1357
+ return false;
1222
1358
  }
1223
1359
  }
1224
1360