@rootintf/protocol-2phw 0.7.5-api-0.7 → 1.0.34-api.0.8

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,25 +1,99 @@
1
1
  'use strict';
2
2
 
3
- const validate_Msg2PhW = validate10;const pattern0 = new RegExp("0\\.7", "u");function validate10(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data["2PhW"] === undefined) && (missing0 = "2PhW")){validate10.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data["2PhW"] !== undefined){let data0 = data["2PhW"];{if(typeof data0 === "string"){if(!pattern0.test(data0)){validate10.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"#/properties/2PhW/pattern",keyword:"pattern",params:{pattern: "0\\.7"},message:"must match pattern \""+"0\\.7"+"\""}];return false;}}else {validate10.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"#/properties/2PhW/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}}}}else {validate10.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate10.errors = vErrors;return errors === 0;}const validate_MsgOptions = validate11;function validate11(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.options === undefined) && (missing0 = "options")){validate11.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.options !== undefined){let data0 = data.options;if(!(data0 && typeof data0 == "object" && !Array.isArray(data0))){validate11.errors = [{instancePath:instancePath+"/options",schemaPath:"#/properties/options/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}else {validate11.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate11.errors = vErrors;return errors === 0;}const validate_Options_delay = validate12;function validate12(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.ttl_msec_incr === undefined) && (missing0 = "ttl_msec_incr")){validate12.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.ttl_msec_incr !== undefined){let data0 = data.ttl_msec_incr;const _errs1 = errors;{if(Array.isArray(data0)){var valid1 = true;const len0 = data0.length;for(let i0=0; i0<len0; i0++){let data1 = data0[i0];const _errs3 = errors;if(!(((typeof data1 == "number") && (!(data1 % 1) && !isNaN(data1))) && (isFinite(data1)))){validate12.errors = [{instancePath:instancePath+"/ttl_msec_incr/" + i0,schemaPath:"#/properties/ttl_msec_incr/items/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid1 = _errs3 === errors;if(!valid1){break;}}}else {validate12.errors = [{instancePath:instancePath+"/ttl_msec_incr",schemaPath:"#/properties/ttl_msec_incr/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.reason !== undefined){const _errs5 = errors;if(typeof data.reason !== "string"){validate12.errors = [{instancePath:instancePath+"/reason",schemaPath:"#/properties/reason/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs5 === errors;}else {var valid0 = true;}}}}else {validate12.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate12.errors = vErrors;return errors === 0;}const validate_MsgWarp = validate13;function validate13(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.warp === undefined) && (missing0 = "warp")){validate13.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;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((data0.user === undefined) && (missing1 = "user")) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))){validate13.errors = [{instancePath:instancePath+"/warp",schemaPath:"#/properties/warp/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.ttl_msec !== undefined){let data1 = data0.ttl_msec;const _errs3 = errors;if(!(((typeof data1 == "number") && (!(data1 % 1) && !isNaN(data1))) && (isFinite(data1)))){validate13.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 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.instantaneous !== undefined){const _errs5 = errors;if(typeof data0.instantaneous !== "boolean"){validate13.errors = [{instancePath:instancePath+"/warp/instantaneous",schemaPath:"#/properties/warp/properties/instantaneous/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}var valid1 = _errs5 === errors;}else {var valid1 = true;}}}}else {validate13.errors = [{instancePath:instancePath+"/warp",schemaPath:"#/properties/warp/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}else {validate13.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate13.errors = vErrors;return errors === 0;}const validate_MsgEngage = validate14;function validate14(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.engage === undefined) && (missing0 = "engage")){validate14.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;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((data0.user === undefined) && (missing1 = "user")) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))){validate14.errors = [{instancePath:instancePath+"/engage",schemaPath:"#/properties/engage/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}}else {validate14.errors = [{instancePath:instancePath+"/engage",schemaPath:"#/properties/engage/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}else {validate14.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate14.errors = vErrors;return errors === 0;}
3
+ 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_2PhW#/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("0.8" !== data["2PhW"]){validate19.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions_2PhW#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "0.8"},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("0.8" !== data["2PhW"]){validate20.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions_2PhW#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "0.8"},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};const schema_MsgOptions = validate21;function validate21(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate21.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.options === undefined) && (missing0 = "options")){validate21.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.options !== undefined){let data0 = data.options;const _errs1 = errors;if(!(data0 && typeof data0 == "object" && !Array.isArray(data0))){validate21.errors = [{instancePath:instancePath+"/options",schemaPath:"#/properties/options/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 _errs3 = errors;if("0.8" !== data["2PhW"]){validate21.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions_2PhW#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "0.8"},message:"must be equal to constant"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}}}}else {validate21.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate21.errors = vErrors;return errors === 0;}validate21.evaluated = {"props":{"options":true,"2PhW":true},"dynamicProps":false,"dynamicItems":false};
4
4
 
5
5
  // console.log('OUT', __name({variableName}) );
6
6
 
7
- function l_toBigInt_(ref, obj, ignore= false) {
8
- console.assert(ref !== BigInt(0), 'no labels initialized');
9
- let bigInt = BigInt(0);
10
- for (const [k,v] of Object.entries(obj)) {
11
- if ( ( ignore || v ) && ref[k])
12
- bigInt|= BigInt( ref[k] );
13
- // console.log('0b'+ bigInt.toString(2) );
7
+ //-------------------------------------------------------------------------------------------------
8
+
9
+ function l_length_(obj_labels) {
10
+ if (! obj_labels || typeof obj_labels !== 'object')
11
+ throw new Error('obj_labels must be an object');
12
+ const obj_1label = Object.values(obj_labels);
13
+ if (! obj_1label.every(v => typeof v === 'number' && Number.isFinite(v)))
14
+ throw new Error('All values must be finite numbers');
15
+
16
+ const labels = Object.values(obj_labels);
17
+ if (labels.length === 0)
18
+ return 1; // Empty object case, start at 1
19
+
20
+ const value_max = Math.max(...labels);
21
+ if (value_max <= 0) return 1
22
+
23
+ const bit_highest = Math.floor(Math.log2(value_max));
24
+ return 1 << (bit_highest + 1);
25
+ }
26
+
27
+ function l_array_(arr_labels, start = 1) {
28
+ if (! Array.isArray(arr_labels))
29
+ throw new Error('arr_labels must be an array');
30
+ if (! Number.isSafeInteger(start) || start < 0)
31
+ throw new Error('start must be a safe, non-negative integer');
32
+
33
+ return Object.freeze(arr_labels.reduce((acc, key, index) => {
34
+ acc[key] = start << index;
35
+ return acc;
36
+ }, {}));
37
+ }
38
+
39
+ function l_concat_(obj_labels, arg) {
40
+ if (! obj_labels || typeof obj_labels !== 'object')
41
+ throw new Error('obj_labels must be an object');
42
+ const obj_1label = Object.values(obj_labels);
43
+ if (! obj_1label.every(v => typeof v === 'number' && Number.isFinite(v)))
44
+ throw new Error('All values must be finite numbers');
45
+ if (! arg || (typeof arg !== 'object' && ! Array.isArray(arg)))
46
+ throw new Error('arg must be an object or array');
47
+
48
+ if (Array.isArray(arg)) {
49
+ const len = l_length_(obj_labels);
50
+ const arr_labels_new = l_array_(arg, len);
51
+ return l_concat_(obj_labels, arr_labels_new);
14
52
  }
15
- return bigInt;
53
+
54
+ const next_pos = l_length_(obj_labels);
55
+ const arg_entries = Object.entries(arg);
56
+ const result = Object.create(null);
57
+ Object.entries(obj_labels).forEach(([k, v]) => {
58
+ if (k !== '__proto__' && k !== 'constructor')
59
+ result[k] = v;
60
+ });
61
+
62
+ let min_arg = Infinity;
63
+ for (const [, value] of arg_entries) {
64
+ if (typeof value !== 'number' || ! Number.isFinite(value))
65
+ continue; // Skip non-numeric
66
+
67
+ if (value > 0 && value < min_arg)
68
+ min_arg = value;
69
+ }
70
+ // Shift only if min_arg is less than next_pos
71
+ const shift = min_arg === Infinity || min_arg >= next_pos
72
+ ? 0
73
+ : Math.floor(Math.log2(next_pos / min_arg));
74
+
75
+ for (const [key, value] of arg_entries) {
76
+ if (!(key in result)) {
77
+ result[key] = value === 0 ? 0 : value << shift;
78
+ }
79
+ }
80
+
81
+ return Object.freeze(result);
16
82
  }
17
83
 
18
84
  function l_LL_(obj, x) {
19
- let obj_new= {};
20
- for (var [k,v] of Object.entries(obj))
21
- obj_new[k]= v<<x;
22
- return obj_new;
85
+ if (! obj || typeof obj !== 'object')
86
+ throw new Error('obj must be an object');
87
+ if (! Number.isSafeInteger(x) || x < 0)
88
+ throw new Error('Shift value must be a safe, non-negative integer');
89
+
90
+ const obj_new= {};
91
+ for (const [k,v] of Object.entries(obj)) {
92
+ if (typeof v !== 'number' || ! Number.isFinite(v))
93
+ continue; // Skip non-numeric
94
+ obj_new[k] = v<<x;
95
+ }
96
+ return Object.freeze(obj_new);
23
97
  }
24
98
 
25
99
  //-------------------------------------------------------------------------------------------------
@@ -32,56 +106,85 @@ function handler_default_( /* ... */ ) {
32
106
 
33
107
  //-------------------------------------------------------------------------------------------------
34
108
 
35
- class BitLogr {
36
- constructor() {
37
- this._handler_log= handler_default_;
38
- this._Bint_labels= BigInt(0);
39
- this._Bint_toggled= BigInt(0);
40
-
41
- BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
42
- // console.log('NOP')
43
- };
44
- }
109
+ function l_toBigInt_(obj_labels, obj, ignore= false) {
110
+ if (! obj_labels || typeof obj_labels !== 'object')
111
+ throw new Error('obj_labels must be an object');
112
+ if (! obj || typeof obj !== 'object')
113
+ throw new Error('obj must be an object');
45
114
 
46
- set handler(fx) {
47
- this._handler_log= fx;
48
- }
49
-
50
- get labels() { return this._Bint_labels; }
51
- set labels(obj) {
52
- this._Bint_labels= obj;
53
- this._Bint_toggled= BigInt(0);
115
+ let bigInt = BigInt(0);
116
+ for (const [k,v] of Object.entries(obj)) {
117
+ if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
118
+ bigInt|= BigInt( obj_labels[k] );
119
+ // console.log('0b'+ bigInt.toString(2) );
54
120
  }
121
+ return bigInt;
122
+ }
55
123
 
56
- // put= function(label, abbrv) {
57
- // let name= __name(label);
58
- // _labels[name]= label[name];
59
- // console.log(_labels);
60
- // }
124
+ // console.log(l_toBigInt_({},{}))
61
125
 
62
- get toggled() { return this._Bint_toggled; }
63
- set toggled(obj) {
64
- this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
126
+ const LOGR = (function () {
127
+ let _instance; // Private variable to hold the single instance
65
128
 
66
- if (this._Bint_toggled === BigInt(0)) {
67
- console.log('adlkjasdlfk');
68
- return;
69
- }
129
+ function _create_instance() {
130
+ // Private state (replacing constructor properties)
131
+ let _handler_log = handler_default_;
132
+ let _obj_labels = undefined;
133
+ let _Bint_toggled = BigInt(0);
70
134
 
71
- BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
72
- if ( (BigInt(nr_logged) & this._Bint_toggled) === BigInt(0))
135
+ function _log_fxn(nr_logged, argsFn /* args */) {
136
+ if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
73
137
  return false;
74
-
75
- var args = Array.prototype.slice.call(arguments);
76
- args.shift(); // remove first arg: nr_logged
77
- this._handler_log.apply(this, args);
78
-
138
+
139
+ const args = argsFn();
140
+ _handler_log.apply(this, args);
141
+ // _handler_log.apply(this, args);
79
142
  return true;
143
+ }
144
+
145
+ return {
146
+ set handler(fx) {
147
+ _handler_log = fx;
148
+ },
149
+ get handler() {
150
+ return _handler_log;
151
+ },
152
+
153
+ get labels() { return _obj_labels; },
154
+ set labels(obj) {
155
+ _obj_labels = obj;
156
+ _Bint_toggled = BigInt(0);
157
+ },
158
+
159
+ // put= function(label, abbrv) {
160
+ // let name= __name(label);
161
+ // _labels[name]= label[name];
162
+ // console.log(_labels);
163
+ // }
164
+
165
+ get toggled() { return _Bint_toggled; },
166
+ set toggled(obj_toggled) {
167
+ _Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
168
+ },
169
+
170
+ log(nr_logged, argsFn) {
171
+
172
+ return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
173
+ }
80
174
  };
81
175
  }
82
176
 
83
- // log= function (nr_logged, /* ... */ ) {}
84
- }
177
+ // Public interface
178
+ return {
179
+ get_instance() {
180
+ if (!_instance) {
181
+ _instance = _create_instance(); // Lazy initialization
182
+ }
183
+ return _instance;
184
+ }
185
+ };
186
+
187
+ })();
85
188
 
86
189
  var jsonMsg_cjs = {};
87
190
 
@@ -91,77 +194,66 @@ function requireJsonMsg_cjs () {
91
194
  if (hasRequiredJsonMsg_cjs) return jsonMsg_cjs;
92
195
  hasRequiredJsonMsg_cjs = 1;
93
196
 
94
- Object.defineProperty(jsonMsg_cjs, '__esModule', { value: true });
197
+ const schema_Msg = validate18;function validate18(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate18.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.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))){validate18.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.id !== undefined){const _errs1 = errors;if(typeof data.id !== "string"){validate18.errors = [{instancePath:instancePath+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.dt !== undefined){const _errs3 = errors;if(typeof data.dt !== "string"){validate18.errors = [{instancePath:instancePath+"/dt",schemaPath:"#/properties/dt/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}}}}else {validate18.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate18.errors = vErrors;return errors === 0;}validate18.evaluated = {"props":{"id":true,"dt":true},"dynamicProps":false,"dynamicItems":false};const schema_Msg_msg = 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._msg === undefined) && (missing0 = "_msg")){validate19.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}}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 = {"dynamicProps":false,"dynamicItems":false};const schema_MsgAck_msg = 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.ack === undefined) && (missing0 = "ack")){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.ack !== undefined){let data0 = data.ack;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if((data0.ok === undefined) && (missing1 = "ok")){validate20.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.ok !== undefined){if(typeof data0.ok !== "boolean"){validate20.errors = [{instancePath:instancePath+"/ack/ok",schemaPath:"#/properties/ack/properties/ok/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}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":{"ack":true},"dynamicProps":false,"dynamicItems":false};
95
198
 
96
- const validate_Msg = validate10;function validate10(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((((data.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))){validate10.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.id !== undefined){const _errs1 = errors;if(typeof data.id !== "string"){validate10.errors = [{instancePath:instancePath+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.referer !== undefined){let data1 = data.referer;const _errs3 = errors;{if(Array.isArray(data1)){if(data1.length > 2){validate10.errors = [{instancePath:instancePath+"/referer",schemaPath:"#/properties/referer/maxItems",keyword:"maxItems",params:{limit: 2},message:"must NOT have more than 2 items"}];return false;}else {if(data1.length < 2){validate10.errors = [{instancePath:instancePath+"/referer",schemaPath:"#/properties/referer/minItems",keyword:"minItems",params:{limit: 2},message:"must NOT have fewer than 2 items"}];return false;}else {var valid1 = true;const len0 = data1.length;for(let i0=0; i0<len0; i0++){const _errs5 = errors;if(typeof data1[i0] !== "string"){validate10.errors = [{instancePath:instancePath+"/referer/" + i0,schemaPath:"#/properties/referer/items/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs5 === errors;if(!valid1){break;}}}}}else {validate10.errors = [{instancePath:instancePath+"/referer",schemaPath:"#/properties/referer/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid0 = _errs3 === errors;}else {var valid0 = true;}if(valid0){if(data.dt !== undefined){const _errs7 = errors;if(typeof data.dt !== "string"){validate10.errors = [{instancePath:instancePath+"/dt",schemaPath:"#/properties/dt/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs7 === errors;}else {var valid0 = true;}}}}}else {validate10.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate10.errors = vErrors;return errors === 0;}const validate_Msg_msg = validate11;function validate11(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data._msg === undefined) && (missing0 = "_msg")){validate11.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}}else {validate11.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate11.errors = vErrors;return errors === 0;}const validate_MsgAck = validate12;function validate12(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.ack === undefined) && (missing0 = "ack")){validate12.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.ack !== undefined){let data0 = data.ack;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if((data0.ok === undefined) && (missing1 = "ok")){validate12.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.ok !== undefined){if(typeof data0.ok !== "boolean"){validate12.errors = [{instancePath:instancePath+"/ack/ok",schemaPath:"#/properties/ack/properties/ok/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}}}}else {validate12.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}else {validate12.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate12.errors = vErrors;return errors === 0;}
199
+ const byteToHex = [];
200
+ for (let i = 0; i < 256; ++i) {
201
+ byteToHex.push((i + 0x100).toString(16).slice(1));
202
+ }
203
+ function unsafeStringify(arr, offset = 0) {
204
+ return (byteToHex[arr[offset + 0]] +
205
+ byteToHex[arr[offset + 1]] +
206
+ byteToHex[arr[offset + 2]] +
207
+ byteToHex[arr[offset + 3]] +
208
+ '-' +
209
+ byteToHex[arr[offset + 4]] +
210
+ byteToHex[arr[offset + 5]] +
211
+ '-' +
212
+ byteToHex[arr[offset + 6]] +
213
+ byteToHex[arr[offset + 7]] +
214
+ '-' +
215
+ byteToHex[arr[offset + 8]] +
216
+ byteToHex[arr[offset + 9]] +
217
+ '-' +
218
+ byteToHex[arr[offset + 10]] +
219
+ byteToHex[arr[offset + 11]] +
220
+ byteToHex[arr[offset + 12]] +
221
+ byteToHex[arr[offset + 13]] +
222
+ byteToHex[arr[offset + 14]] +
223
+ byteToHex[arr[offset + 15]]).toLowerCase();
224
+ }
97
225
 
98
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
99
- // require the crypto API and do not support built-in fallback to lower quality random number
100
- // generators (like Math.random()).
101
226
  let getRandomValues;
102
227
  const rnds8 = new Uint8Array(16);
103
228
  function rng() {
104
- // lazy load so that environments that need to polyfill have a chance to do so
105
- if (!getRandomValues) {
106
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
107
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
108
-
109
229
  if (!getRandomValues) {
110
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
230
+ if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
231
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
232
+ }
233
+ getRandomValues = crypto.getRandomValues.bind(crypto);
111
234
  }
112
- }
113
-
114
- return getRandomValues(rnds8);
115
- }
116
-
117
- /**
118
- * Convert array of 16 byte values to UUID string format of the form:
119
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
120
- */
121
-
122
- const byteToHex = [];
123
-
124
- for (let i = 0; i < 256; ++i) {
125
- byteToHex.push((i + 0x100).toString(16).slice(1));
126
- }
127
-
128
- function unsafeStringify(arr, offset = 0) {
129
- // Note: Be careful editing this code! It's been tuned for performance
130
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
131
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
235
+ return getRandomValues(rnds8);
132
236
  }
133
237
 
134
238
  const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
135
- var native = {
136
- randomUUID
137
- };
239
+ var native = { randomUUID };
138
240
 
139
241
  function v4(options, buf, offset) {
140
- if (native.randomUUID && true && !options) {
141
- return native.randomUUID();
142
- }
143
-
144
- options = options || {};
145
- const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
146
-
147
- rnds[6] = rnds[6] & 0x0f | 0x40;
148
- rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
149
-
150
- return unsafeStringify(rnds);
242
+ if (native.randomUUID && true && !options) {
243
+ return native.randomUUID();
244
+ }
245
+ options = options || {};
246
+ const rnds = options.random ?? options.rng?.() ?? rng();
247
+ if (rnds.length < 16) {
248
+ throw new Error('Random bytes length must be >= 16');
249
+ }
250
+ rnds[6] = (rnds[6] & 0x0f) | 0x40;
251
+ rnds[8] = (rnds[8] & 0x3f) | 0x80;
252
+ return unsafeStringify(rnds);
151
253
  }
152
254
 
153
255
  // console.log('OUT', __name({variableName}) );
154
256
 
155
- function l_toBigInt_(ref, obj, ignore= false) {
156
- console.assert(ref !== BigInt(0), 'no labels initialized');
157
- let bigInt = BigInt(0);
158
- for (const [k,v] of Object.entries(obj)) {
159
- if ( ( ignore || v ) && ref[k])
160
- bigInt|= BigInt( ref[k] );
161
- // console.log('0b'+ bigInt.toString(2) );
162
- }
163
- return bigInt;
164
- }
165
257
 
166
258
  //-------------------------------------------------------------------------------------------------
167
259
 
@@ -173,87 +265,112 @@ function requireJsonMsg_cjs () {
173
265
 
174
266
  //-------------------------------------------------------------------------------------------------
175
267
 
176
- class BitLogr {
177
- constructor() {
178
- this._handler_log= handler_default_;
179
- this._Bint_labels= BigInt(0);
180
- this._Bint_toggled= BigInt(0);
181
-
182
- BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
183
- // console.log('NOP')
184
- };
185
- }
186
-
187
- set handler(fx) {
188
- this._handler_log= fx;
189
- }
268
+ function l_toBigInt_(obj_labels, obj, ignore= false) {
269
+ if (! obj_labels || typeof obj_labels !== 'object')
270
+ throw new Error('obj_labels must be an object');
271
+ if (! obj || typeof obj !== 'object')
272
+ throw new Error('obj must be an object');
190
273
 
191
- get labels() { return this._Bint_labels; }
192
- set labels(obj) {
193
- this._Bint_labels= obj;
194
- this._Bint_toggled= BigInt(0);
274
+ let bigInt = BigInt(0);
275
+ for (const [k,v] of Object.entries(obj)) {
276
+ if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
277
+ bigInt|= BigInt( obj_labels[k] );
278
+ // console.log('0b'+ bigInt.toString(2) );
195
279
  }
280
+ return bigInt;
281
+ }
196
282
 
197
- // put= function(label, abbrv) {
198
- // let name= __name(label);
199
- // _labels[name]= label[name];
200
- // console.log(_labels);
201
- // }
283
+ // console.log(l_toBigInt_({},{}))
202
284
 
203
- get toggled() { return this._Bint_toggled; }
204
- set toggled(obj) {
205
- this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
285
+ const LOGR = (function () {
286
+ let _instance; // Private variable to hold the single instance
206
287
 
207
- if (this._Bint_toggled === BigInt(0)) {
208
- console.log('adlkjasdlfk');
209
- return;
210
- }
288
+ function _create_instance() {
289
+ // Private state (replacing constructor properties)
290
+ let _handler_log = handler_default_;
291
+ let _obj_labels = undefined;
292
+ let _Bint_toggled = BigInt(0);
211
293
 
212
- BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
213
- if ( (BigInt(nr_logged) & this._Bint_toggled) === BigInt(0))
294
+ function _log_fxn(nr_logged, argsFn /* args */) {
295
+ if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
214
296
  return false;
215
-
216
- var args = Array.prototype.slice.call(arguments);
217
- args.shift(); // remove first arg: nr_logged
218
- this._handler_log.apply(this, args);
219
-
297
+
298
+ const args = argsFn();
299
+ _handler_log.apply(this, args);
300
+ // _handler_log.apply(this, args);
220
301
  return true;
302
+ }
303
+
304
+ return {
305
+ set handler(fx) {
306
+ _handler_log = fx;
307
+ },
308
+ get handler() {
309
+ return _handler_log;
310
+ },
311
+
312
+ get labels() { return _obj_labels; },
313
+ set labels(obj) {
314
+ _obj_labels = obj;
315
+ _Bint_toggled = BigInt(0);
316
+ },
317
+
318
+ // put= function(label, abbrv) {
319
+ // let name= __name(label);
320
+ // _labels[name]= label[name];
321
+ // console.log(_labels);
322
+ // }
323
+
324
+ get toggled() { return _Bint_toggled; },
325
+ set toggled(obj_toggled) {
326
+ _Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
327
+ },
328
+
329
+ log(nr_logged, argsFn) {
330
+
331
+ return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
332
+ }
221
333
  };
222
334
  }
223
335
 
224
- // log= function (nr_logged, /* ... */ ) {}
225
- }
336
+ // Public interface
337
+ return {
338
+ get_instance() {
339
+ if (!_instance) {
340
+ _instance = _create_instance(); // Lazy initialization
341
+ }
342
+ return _instance;
343
+ }
344
+ };
226
345
 
227
- let LOGR_= new BitLogr();
346
+ })();
347
+
348
+ let LOGR_= LOGR.get_instance();
349
+ const log_= LOGR_.log;
228
350
 
229
351
  const l_= {
230
352
  VALIDATION : 0b1 << 0,
231
353
  };
354
+ LOGR_.labels= l_;
232
355
 
233
356
  // TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
234
357
 
235
358
  // "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
236
359
  var JSON_Msg = (function() {
237
360
  return {
238
- merge : function(json) {
239
- const dt_Msg= new Date();
240
- let json_msg= {
241
- id : v4(),
242
- referer : null,
243
- dt : dt_Msg.toISOString(),
244
- };
245
- // https://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object
246
- for (var key of Object.keys(json)) {
247
- json_msg[key]= json[key];
248
- }
249
- return json_msg;
361
+ merge: function(json) {
362
+ return Object.assign({
363
+ id: v4(),
364
+ referer: null,
365
+ dt: new Date().toISOString()
366
+ }, json || {});
250
367
  },
251
- validate : function(json) {
252
- const b_valid= validate_Msg(json);
253
- if (!b_valid)
254
- LOGR_.log(l_.VALIDATION, 'JSON_Msg: validate: ', validate_Msg.errors);
368
+ validate : function (json) {
369
+ const b_valid = schema_Msg(json);
370
+ if (!b_valid)
371
+ log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
255
372
  return b_valid;
256
- }
373
+ },
257
374
  // TODO: requires a separate ajv module require, and JTD specific schema
258
375
  // https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
259
376
  // static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
@@ -262,26 +379,24 @@ function requireJsonMsg_cjs () {
262
379
  // }
263
380
  }
264
381
  })();
265
-
382
+
266
383
  var JSON_Msg_msg = (function() {
267
384
  return {
268
- create_with_msg_merge : function(_msg, json) {
269
- let json_msg= JSON_Msg.merge(json);
270
- json_msg._msg= _msg;
271
- return json_msg;
385
+ create_with_msg_merge: function(_msg, json) {
386
+ return Object.assign(JSON_Msg.merge(json), { _msg });
272
387
  },
273
388
  validate : function(json) {
274
389
  if (! JSON_Msg.validate(json))
275
390
  return false;
276
- const b_valid= validate_Msg_msg(json);
391
+ const b_valid= schema_Msg_msg(json);
277
392
  if (!b_valid)
278
- LOGR_.log(l_.VALIDATION, 'JSON_Msg_msg: validate: ', validate_Msg_msg.errors);
393
+ log_(l_.VALIDATION, () => ['JSON_Msg_msg: validate: ', schema_Msg_msg.errors]);
279
394
  return b_valid;
280
395
  }
281
396
  }
282
397
  })();
283
398
 
284
- var JSON_MsgAck = (function() {
399
+ var JSON_MsgAck_msg = (function() {
285
400
  return {
286
401
  create_with_msgOk : function(_msg, b_ok= true) {
287
402
  return JSON_Msg_msg.create_with_msg_merge(_msg, {
@@ -301,53 +416,177 @@ function requireJsonMsg_cjs () {
301
416
  validate : function(json) {
302
417
  if (! JSON_Msg_msg.validate(json))
303
418
  return false;
304
- const b_valid= validate_MsgAck(json);
419
+ const b_valid= schema_MsgAck_msg(json);
305
420
  if (!b_valid)
306
- LOGR_.log(l_.VALIDATION, 'JSON_MsgAck: validate: ', validate_MsgAck.errors);
421
+ log_(l_.VALIDATION, () => ['JSON_MsgAck: validate: ', schema_MsgAck_msg.errors]);
307
422
  return b_valid;
308
423
  }
309
424
  }
310
425
  })();
311
426
 
312
427
  jsonMsg_cjs.JSON_Msg = JSON_Msg;
313
- jsonMsg_cjs.JSON_MsgAck = JSON_MsgAck;
428
+ jsonMsg_cjs.JSON_MsgAck_msg = JSON_MsgAck_msg;
314
429
  jsonMsg_cjs.JSON_Msg_msg = JSON_Msg_msg;
430
+ jsonMsg_cjs.l = l_;
315
431
  return jsonMsg_cjs;
316
432
  }
317
433
 
318
434
  var jsonMsg_cjsExports = requireJsonMsg_cjs();
319
435
 
436
+ //-------------------------------------------------------------------------------------------------
437
+
438
+ let LOGR_$1= LOGR.get_instance();
439
+ const log_$1= LOGR_$1.log;
440
+
441
+ const l_$1= {
442
+ EVENTS : 0b1 << 0,
443
+ TIMEOUTS : 0b1 << 1,
444
+ };
445
+ LOGR_$1.labels= l_$1;
446
+ // LOGR_.toggled= {
447
+ // EVENTS : 1
448
+ // }
449
+
450
+
451
+ //-------------------------------------------------------------------------------------------------
452
+
453
+ class EventLog {
454
+ constructor() {
455
+ this.arr_events = []; // In-memory event store
456
+ this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
457
+ this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
458
+ }
459
+
460
+ addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
461
+ const evt = {
462
+ type,
463
+ dt: Date.now(),
464
+ id,
465
+ data,
466
+ timeout_id: null // Will store timeout reference if set
467
+ };
468
+ const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
469
+
470
+ let arr_indices = this.map_index_id.get(id);
471
+ if (! arr_indices) {
472
+ arr_indices = [];
473
+ this.map_index_id.set(id, arr_indices);
474
+ }
475
+ arr_indices.push(idx);
476
+
477
+ // Set timeout if specified
478
+ if (timeout_ms && timeout_callback) {
479
+ evt.timeout_id = setTimeout(() => {
480
+ if (this.map_timeouts.delete(idx)) {
481
+ evt.timeout_id = null;
482
+ timeout_callback({idx, evt});
483
+ log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
484
+ }
485
+ }, timeout_ms);
486
+
487
+ this.map_timeouts.set(idx, evt.timeout_id);
488
+ }
489
+
490
+ // the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
491
+ // 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().
492
+ // Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
493
+ log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
494
+ return { idx, evt };
495
+ }
496
+
497
+ cancelTimeout(idx) {
498
+ const timeout_id = this.map_timeouts.get(idx);
499
+ if (timeout_id) {
500
+ clearTimeout(timeout_id);
501
+ this.map_timeouts.delete(idx);
502
+ if (this.arr_events[idx])
503
+ this.arr_events[idx].timeout_id = null;
504
+ return true;
505
+ }
506
+ return false;
507
+ }
508
+
509
+ cancelAllTimeouts() {
510
+ for (const [idx, timeout_id] of this.map_timeouts) {
511
+ clearTimeout(timeout_id);
512
+ if (this.arr_events[idx])
513
+ this.arr_events[idx].timeout_id = null;
514
+ }
515
+ this.map_timeouts.clear();
516
+ }
517
+
518
+ getEventById(id, lookback_ms = null) {
519
+ const arr_indices = this.map_index_id.get(id);
520
+ if (!arr_indices?.length) return [];
521
+
522
+ const result = [];
523
+ const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
524
+
525
+ // Single loop with early cutoff
526
+ for (let i = arr_indices.length - 1; i >= 0; i--) {
527
+ const idx = arr_indices[i];
528
+ const evt = this.arr_events[idx];
529
+ if (evt.dt < cutoff)
530
+ break;
531
+ result.push({ idx, evt });
532
+ }
533
+
534
+ return result; // Newest to oldest order
535
+ }
536
+
537
+ // getRecentEvents(id, lookbackMs) {
538
+ // const cutoff = Date.now() - lookbackMs;
539
+ // return this.events.filter(e => e.id === id && e.dt >= cutoff);
540
+ // }
541
+
542
+ getEvents(lookback_ms, predicate) {
543
+ const cutoff = Date.now() - lookback_ms;
544
+ const result = [];
545
+
546
+ // Iterate backwards from the end
547
+ for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
548
+ const evt = this.arr_events[idx];
549
+ if (evt.dt < cutoff) {
550
+ break; // Stop once we pass the cutoff
551
+ }
552
+ if (predicate(evt)) {
553
+ result.push({ idx, evt });
554
+ }
555
+ }
556
+
557
+ return result; // Newest to oldest order
558
+ }
559
+
560
+ // setLogr(obj_logr) {
561
+ // this.logr.toggled = obj_logr;
562
+ // }
563
+
564
+ clear() {
565
+ this.cancelAllTimeouts(); // Clear all timeouts before clearing events
566
+ this.arr_events.length = 0;
567
+ this.map_index_id.clear();
568
+ }
569
+ }
570
+
320
571
  const k_TTL= 20000;
321
572
 
322
573
  //-------------------------------------------------------------------------------------------------
323
574
 
324
- let LOGR_= new BitLogr();
325
575
 
326
- const l_msgs_ = {
327
- MSG : 0b1 << 0,
328
- WARP : 0b1 << 1,
329
- ENGAGE : 0b1 << 2,
330
- ACK : 0b1 << 3,
331
- };
576
+ const LOGR_= LOGR.get_instance();
577
+ const log_= LOGR_.log;
578
+
579
+ Object.assign(jsonMsg_cjsExports.l, l_LL_(jsonMsg_cjsExports.l, 2)); // VALIDATION : 4
580
+
581
+ const l_twoPhW_ = l_array_(['HANDLERS','DROPS', 'PROTOCOL_STATE','RECVER','SENDER']);
582
+ const l_ = l_concat_(l_$1, l_concat_(jsonMsg_cjsExports.l, l_twoPhW_) );
332
583
 
333
- const l_= {
334
- HANDLERS : 0b1 << 0,
335
- DROPS : 0b1 << 1,
336
- VALIDATION : 0b1 << 2,
337
- ... l_LL_(l_msgs_, 8)
338
- };
339
584
  LOGR_.labels= l_;
340
585
 
341
586
  //-------------------------------------------------------------------------------------------------
342
587
 
343
588
  let map_Context_= new Map();
344
589
 
345
- function set_ctx(key, ctx) {
346
- map_Context_.set(key, ctx);
347
- // console.log(map_Context_);
348
- return ctx;
349
- }
350
-
351
590
  function get_ctx(key) {
352
591
  return map_Context_.get(key);
353
592
  }
@@ -355,20 +594,30 @@ function get_ctx(key) {
355
594
  //-------------------------------------------------------------------------------------------------
356
595
 
357
596
  class Config {
358
- receiver(callback_msgWarp,callback_msgEngage) {
597
+ constructor() {
598
+ // Initialize callbacks as no-op functions
599
+ this._callback_msgWarp = () => { console.assert(false, 'callback_msgWarp uninitialized'); };
600
+ this._callback_msgEngage = () => { console.assert(false, 'callback_msgEngage uninitialized'); };
601
+ this._callback_msgAckWarp = () => { console.assert(false, 'callback_msgAckWarp uninitialized'); };
602
+ this._callback_msgAckEngage = () => { console.assert(false, 'callback_msgAckEngage uninitialized'); };
603
+ this._callback_msg_sent_expired = () => { console.assert(false, '_callback_msg_sent_expired uninitialized'); };
604
+ this._callback_msgOptions = () => { console.assert(false, 'callback_msgOptions uninitialized'); };
605
+ }
606
+
607
+ receiver(callback_msgWarp, callback_msgEngage, callback_msg_sent_expired) {
359
608
  this._callback_msgWarp= callback_msgWarp;
360
609
  this._callback_msgEngage= callback_msgEngage;
610
+ this._callback_msg_sent_expired= callback_msg_sent_expired;
361
611
  }
362
- sender(callback_msgAckWarp,callback_msgAckEngage ) {
612
+ sender(callback_msgAckWarp, callback_msgAckEngage, callback_msg_sent_expired ) {
363
613
  this._callback_msgAckWarp= callback_msgAckWarp;
364
614
  this._callback_msgAckEngage= callback_msgAckEngage;
615
+ this._callback_msg_sent_expired= callback_msg_sent_expired;
365
616
  }
617
+
366
618
  set callback_msgOptions(callback) {
367
619
  this._callback_msgOptions= callback;
368
620
  }
369
- set logr(obj_logr) {
370
- LOGR_.toggled= obj_logr;
371
- }
372
621
  }
373
622
 
374
623
  // var config = (function() {
@@ -387,11 +636,21 @@ class Config {
387
636
 
388
637
  //-------------------------------------------------------------------------------------------------
389
638
 
390
- let k_VERSION= "0.7";
639
+ let k_VERSION= "0.8";
640
+
641
+ function t_ttl_rtt_(ttl_msec, rtt_msec) {
642
+ if (ttl_msec === undefined)
643
+ return undefined;
644
+ if (rtt_msec === undefined)
645
+ return ttl_msec *2;
646
+
647
+ console.assert(rtt_msec <= ttl_msec *2, `t_ttl_rtt_: INVALID rtt_msec ttl_msec[${ttl_msec}] rtt_msec[${rtt_msec}]`);
648
+ return (ttl_msec *2) + rtt_msec;
649
+ }
391
650
 
392
651
  var JSON_MsgOptions = (function() {
393
652
  return {
394
- create_with_msg_options : function(_msg, options) {
653
+ create_with_msg_options : function(_msg, options) {
395
654
  return jsonMsg_cjsExports.JSON_Msg_msg.create_with_msg_merge(_msg, {
396
655
  options: options,
397
656
  "2PhW": k_VERSION
@@ -400,12 +659,8 @@ var JSON_MsgOptions = (function() {
400
659
  validate : function(json) {
401
660
  if (! jsonMsg_cjsExports.JSON_Msg_msg.validate(json))
402
661
  return false;
403
- if (! validate_Msg2PhW(json)) {
404
- LOGR_.log(l_.VALIDATION, 'JSON_MsgWarp: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
405
- return false;
406
- }
407
- if (! validate_MsgOptions(json)) {
408
- LOGR_.log(l_.VALIDATION, 'JSON_MsgOptions: validate_MsgOptions_: ', validate_MsgOptions.errors);
662
+ if (! schema_MsgOptions(json)) {
663
+ log_(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', schema_MsgOptions.errors]);
409
664
  return false;
410
665
  }
411
666
  return true;
@@ -415,9 +670,10 @@ var JSON_MsgOptions = (function() {
415
670
 
416
671
  var JSON_MsgWarp = (function() {
417
672
  return {
418
- create_with_user_hyperport : function(json_user, json_hyperport, nr_ttl_msec) {
673
+ create_with_id_user_hyperport : function(json_warp_id, json_user, json_hyperport, nr_ttl_msec) {
419
674
  return jsonMsg_cjsExports.JSON_Msg.merge({
420
675
  warp : {
676
+ id : json_warp_id,
421
677
  user : json_user,
422
678
  hyperport : json_hyperport,
423
679
  ttl_msec : nr_ttl_msec
@@ -425,15 +681,22 @@ var JSON_MsgWarp = (function() {
425
681
  "2PhW": k_VERSION
426
682
  });
427
683
  },
684
+ compare : function(json_L, json_R) {
685
+ if (json_L.dt !== json_R.dt)
686
+ return false;
687
+ if (json_L.warp.id !== json_R.warp.id)
688
+ return false;
689
+ if (json_L.referer[0] !== json_R.referer[0])
690
+ return false;
691
+ if (json_L.referer[1] !== json_R.referer[1])
692
+ return false;
693
+ return true;
694
+ },
428
695
  validate : function(json) {
429
696
  if (! jsonMsg_cjsExports.JSON_Msg.validate(json))
430
697
  return false;
431
- if (! validate_Msg2PhW(json)) {
432
- LOGR_.log(l_.VALIDATION, 'JSON_MsgWarp: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
433
- return false;
434
- }
435
- if (! validate_MsgWarp(json)) {
436
- LOGR_.log(l_.VALIDATION, 'JSON_MsgWarp: validate_MsgWarp_: ', validate_MsgWarp.errors);
698
+ if (! schema_MsgWarp(json)) {
699
+ log_(l_.VALIDATION, () => ['JSON_MsgWarp: schema_MsgWarp_: ', schema_MsgWarp.errors]);
437
700
  return false;
438
701
  }
439
702
  return true;
@@ -442,32 +705,29 @@ var JSON_MsgWarp = (function() {
442
705
  })();
443
706
 
444
707
  var JSON_MsgEngage = (function() {
445
- return {
708
+ return {
446
709
  create_with_MsgWarp : function(json_msgWarp) {
447
- let json_msgEngage= jsonMsg_cjsExports.JSON_Msg.merge({
710
+ console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
711
+ return jsonMsg_cjsExports.JSON_Msg_msg.create_with_msg_merge(json_msgWarp, {
448
712
  engage : {
449
- user : json_msgWarp.warp.user,
450
- hyperport : json_msgWarp.warp.hyperport,
713
+ "ok" : true,
714
+ "rtt_msec" : Date.now() - Date.parse(json_msgWarp.dt)
451
715
  },
452
716
  "2PhW": k_VERSION
453
717
  });
454
- json_msgEngage["id"]= json_msgWarp.id;
455
- return json_msgEngage;
456
718
  },
457
719
  validate : function(json) {
458
- if (! jsonMsg_cjsExports.JSON_Msg.validate(json))
720
+ if (! jsonMsg_cjsExports.JSON_Msg_msg.validate(json))
459
721
  return false;
460
- if (! validate_Msg2PhW(json)) {
461
- LOGR_.log(l_.VALIDATION, 'JSON_MsgWarp: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
722
+ if (! JSON_MsgWarp.validate(json._msg))
462
723
  return false;
463
- }
464
- if (! validate_MsgEngage(json)) {
465
- LOGR_.log(l_.VALIDATION, 'JSON_MsgEngage: validate_MsgEngage_: ', validate_MsgEngage.errors);
724
+ if (! schema_MsgEngage(json)) {
725
+ log_(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', schema_MsgEngage.errors]);
466
726
  return false;
467
727
  }
468
728
  return true;
469
729
  }
470
- }
730
+ };
471
731
  })();
472
732
 
473
733
  var JSON_MsgAckWarp = (function() {
@@ -478,21 +738,17 @@ var JSON_MsgAckWarp = (function() {
478
738
  // return json_msgAckWarp;
479
739
  // }
480
740
  create_with_msgOk : function(json_msgWarp, b_ok= true) {
481
- const json_msgAck= jsonMsg_cjsExports.JSON_MsgAck.create_with_msgOk(json_msgWarp, b_ok);
482
- json_msgAck["2PhW"]= k_VERSION;
483
- return json_msgAck;
741
+ const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgOk(json_msgWarp, b_ok);
742
+ json_msgAck_msg["2PhW"]= k_VERSION;
743
+ return json_msgAck_msg;
484
744
  },
485
745
  create_with_msgExpired : function( json_msgWarp ) {
486
- const json_msgAck= jsonMsg_cjsExports.JSON_MsgAck.create_with_msgExpired( json_msgWarp );
487
- json_msgAck["2PhW"]= k_VERSION;
488
- return json_msgAck;
746
+ const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp );
747
+ json_msgAck_msg["2PhW"]= k_VERSION;
748
+ return json_msgAck_msg;
489
749
  },
490
750
  validate : function(json) {
491
- if (! validate_Msg2PhW(json)) {
492
- LOGR_.log(l_.VALIDATION, 'JSON_MsgAckWarp: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
493
- return false;
494
- }
495
- if (! jsonMsg_cjsExports.JSON_MsgAck.validate(json))
751
+ if (! jsonMsg_cjsExports.JSON_MsgAck_msg.validate(json))
496
752
  return false;
497
753
  if (! JSON_MsgWarp.validate(json._msg))
498
754
  return false;
@@ -509,21 +765,17 @@ var JSON_MsgAckEngage = (function() {
509
765
  // return json_msgAckEngage;
510
766
  // }
511
767
  create_with_msgOk : function(json_msgEngage, b_ok= true) {
512
- const json_msgAck= jsonMsg_cjsExports.JSON_MsgAck.create_with_msgOk(json_msgEngage, b_ok);
513
- json_msgAck["2PhW"]= k_VERSION;
514
- return json_msgAck;
768
+ const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgOk(json_msgEngage, b_ok);
769
+ json_msgAck_msg["2PhW"]= k_VERSION;
770
+ return json_msgAck_msg;
515
771
  },
516
772
  create_with_msgExpired : function( json_msgEngage ) {
517
- const json_msgAck= jsonMsg_cjsExports.JSON_MsgAck.create_with_msgExpired( json_msgEngage );
518
- json_msgAck["2PhW"]= k_VERSION;
519
- return json_msgAck;
773
+ const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage );
774
+ json_msgAck_msg["2PhW"]= k_VERSION;
775
+ return json_msgAck_msg;
520
776
  },
521
777
  validate : function(json) {
522
- if (! validate_Msg2PhW(json)) {
523
- LOGR_.log(l_.VALIDATION, 'JSON_MsgAckEngage: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
524
- return false;
525
- }
526
- if (! jsonMsg_cjsExports.JSON_MsgAck.validate(json))
778
+ if (! jsonMsg_cjsExports.JSON_MsgAck_msg.validate(json))
527
779
  return false;
528
780
  if (! JSON_MsgEngage.validate(json._msg))
529
781
  return false;
@@ -532,305 +784,510 @@ var JSON_MsgAckEngage = (function() {
532
784
  }
533
785
  })();
534
786
 
535
-
536
787
  //-------------------------------------------------------------------------------------------------
537
- // State
788
+ // States
538
789
 
539
790
  class StateState {
540
- constructor(initState) {
541
- this.state_current_ = initState;
542
- this.dt_start_= null;
543
- this.nr_timeout_id_= -1;
544
- this.nr_remaining_msec_= 0;
545
- this.f_callback_= undefined;
546
- }
547
- start() {
548
- this.dt_start_= Date.now();
549
- console.log(`setTimeout: start ${this.dt_start_}, remaining ${this.nr_remaining_msec_}`);
550
- this.nr_timeout_id_= setTimeout(this.f_callback_, this.nr_remaining_msec_);
551
- }
552
- changeState(newState, nr_ttl_msec, f_callback) {
553
- if (! this.state_current_.changeState(newState))
554
- return false;
555
- this.state_current_ = newState;
556
-
557
- clearTimeout(this.nr_timeout_id_);
558
- if (nr_ttl_msec != undefined && f_callback != undefined) {
559
- this.f_callback_= f_callback;
560
- this.nr_remaining_msec_= nr_ttl_msec;
561
- this.start();
562
- }
563
- return true;
791
+ constructor(idx_event, event) {
792
+ this._protocol_parent = null;
793
+ this._idx_event = idx_event;
794
+ this._event = event;
795
+ }
796
+ get protocol() {
797
+ return this._protocol_parent;
564
798
  }
565
- delayTimeout(nr_delay_msec) {
566
- clearTimeout(this.nr_timeout_id_);
567
- const nr_elapsed_ms= Date.now() - this.dt_start_;
568
- this.nr_remaining_msec_= Math.max(this.nr_remaining_msec_ - nr_elapsed_ms, 0) + nr_delay_msec;
569
- this.start();
799
+ set protocol(parent) {
800
+ this._protocol_parent = parent;
570
801
  }
571
- inState(stateClass) {
572
- return this.state_current_ instanceof stateClass;
802
+ get idx_event() {
803
+ return this._idx_event;
804
+ }
805
+ get event() {
806
+ return this._event;
807
+ }
808
+ get json_msg() {
809
+ return this._event.data;
810
+ }
811
+ changeState(state_new) {
812
+ if (this.canChangeState(state_new))
813
+ this.protocol.state = state_new;
814
+ else
815
+ this.protocol.state = new StateINVALID(state_new._idx_event, state_new._event);
816
+ }
817
+ canChangeState(_state_new) {
818
+ throw new Error("Subclass must implement canChangeState()");
573
819
  }
574
820
  }
575
821
 
576
- class StateInitialState {
577
- changeState(newState) {
578
- return true;
822
+ class StateAckEngage extends StateState {
823
+ constructor(idx_event, event) { super(idx_event, event); }
824
+ get evt_AckEngage() { return this.event }
825
+ get json_msgAckEngage() { return this.json_msg }
826
+ canChangeState(_state_new) {
827
+ return false;
579
828
  }
580
829
  }
581
-
582
- // class State<Name> {
583
- // changeState= function(newState) {
584
- // return false;
585
- // }
586
- // }
587
830
 
588
- // if (newState instanceof State<Name>)
589
- // return true;
831
+ class StateEngage extends StateState {
832
+ constructor(idx_event, event) { super(idx_event, event); }
833
+ get evt_Engage() { return this.event }
834
+ get json_msgEngage() { return this.json_msg }
835
+ canChangeState(state_new) {
836
+ if (false === state_new instanceof StateAckEngage)
837
+ return false;
590
838
 
591
- // if (! <Class>.inState( State<Name> ))
592
- // if (! <Class>.changeState( new State<Name>() ))
593
-
594
- //-------------------------------------------------------------------------------------------------
839
+ // The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
840
+ const json_msgWarp= this.json_msgEngage._msg;
841
+ const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
842
+ log_(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`]);
843
+ if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
844
+ return false;
595
845
 
596
- class ProtocolStateState extends StateState {
597
- constructor(initState= new StateInitialState() ) {
598
- super(initState);
846
+ return true;
599
847
  }
600
848
  }
601
849
 
602
- class StateWarp {
603
- changeState(newState) {
604
- if (newState instanceof StateAckWarp)
605
- return true;
606
- if (newState instanceof StateComplete)
607
- return true;
608
- return false;
609
- }
610
- }
850
+ class StateAckWarp extends StateState {
851
+ constructor(idx_event, event) { super(idx_event, event); }
852
+ get evt_AckWarp() { return this.event }
853
+ get json_msgAckWarp() { return this.json_msg }
854
+ canChangeState(state_new) {
855
+ if (false === state_new instanceof StateEngage)
856
+ return false;
611
857
 
612
- class StateAckWarp {
613
- changeState(newState) {
614
- if (newState instanceof StateEngage)
615
- return true;
616
- if (newState instanceof StateComplete)
617
- return true;
618
- return false;
858
+ if (! this.json_msgAckWarp.ack.ok)
859
+ return false;
860
+
861
+ if (this.json_msgAckWarp._msg.warp.instantaneous)
862
+ return false;
863
+
864
+ // The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
865
+ // +STT, so lines up with the Engage timeout
866
+ // - Engage: T0 +2TTL +RTT; RTT= STT+STT
867
+ // - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
868
+ // - STT: Date of the Ack minus date of the Warp.
869
+ const timeout_ms= t_ttl_rtt_(this.json_msgAckWarp._msg.warp.ttl_msec) + Date.parse(this.json_msgAckWarp.dt) - Date.parse(this.json_msgAckWarp._msg.dt);
870
+ log_(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`]);
871
+ if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
872
+ return false;
873
+
874
+ return true;
619
875
  }
620
876
  }
621
877
 
622
- class StateEngage {
623
- changeState(newState) {
624
- if (newState instanceof StateComplete)
625
- return true;
626
- return false;
878
+ class StateWarp extends StateState {
879
+ constructor(idx_event, event) { super(idx_event, event); }
880
+ get evt_Warp() { return this.event }
881
+ get json_msgWarp() { return this.json_msg }
882
+ canChangeState(state_new) {
883
+ if (false === state_new instanceof StateAckWarp)
884
+ return false;
885
+
886
+ // The Warp gets to live for THE WARP'S creation time + TTL*2
887
+ const timeout_ms= t_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
888
+ log_(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`]);
889
+ if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
890
+ return false;
891
+
892
+ return true;
627
893
  }
628
894
  }
629
895
 
630
- class StateComplete {
631
- changeState(newState) {
896
+ class StateINVALID extends StateState {
897
+ constructor(idx_event, event) { super(idx_event, event); }
898
+ canChangeState(_state_new) {
899
+ // INVALID can't transition to any state
632
900
  return false;
633
901
  }
634
902
  }
635
903
 
636
- //-------------------------------------------------------------------------------------------------
637
-
638
- function handler_msgOptions_(cfg, msg, json_msgOptions)
639
- {
640
- LOGR_.log(l_.HANDLERS, 'handler_msgOptions_: ...');
641
-
642
- if (! validate_Options_delay(json_msgOptions.options))
643
- return false;
644
-
645
- if (JSON_MsgWarp.validate(json_msgOptions._msg)) {
646
- const json_msgWarp= json_msgOptions._msg;
647
-
648
- const ctx= get_ctx(json_msgWarp.id);
649
- if (!ctx )
904
+ class StateInitialState extends StateState {
905
+ constructor() { super(null, null); }
906
+ canChangeState(state_new) {
907
+ if (false === state_new instanceof StateWarp)
650
908
  return false;
651
909
 
652
- json_msgOptions.options.ttl_msec_incr[0];
653
- const ttl_incr= json_msgOptions.options.ttl_msec_incr[1];
654
-
655
- //TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
910
+ // The NEWLY created Warp only gets to live for its creation time + TTL
911
+ const timeout_ms= state_new.json_msgWarp.warp.ttl_msec;
912
+ log_(l_.PROTOCOL_STATE, () => [`StateInitialState: evt_Warp.dt@${state_new.evt_Warp.dt}, msgWarp.dt@${Date.parse(state_new.json_msgWarp.dt)} + ${timeout_ms}`]);
913
+ if (state_new.evt_Warp.dt >= Date.parse(state_new.json_msgWarp.dt) + timeout_ms)
914
+ return false;
656
915
 
657
- LOGR_.log(l_.HANDLERS, 'handler_msgOptions_: ', json_msgOptions);
916
+ return true;
917
+ }
918
+ }
658
919
 
659
- ctx.protocol.delayTimeout(ttl_incr);
920
+ //----
660
921
 
661
- if (cfg._callback_msgOptions)
662
- return cfg._callback_msgOptions(msg, json_msgOptions);
922
+ class ProtocolStateState {
923
+ constructor(state_initial) {
924
+ this.state = state_initial || new StateInitialState();
925
+ }
663
926
 
664
- return true;
927
+ set state(state_new) {
928
+ if (! (state_new instanceof StateState)) {
929
+ throw new Error("initState must be an instance of StateState or its subclasses");
930
+ }
931
+ this._state = state_new;
932
+ if (state_new && state_new.protocol !== this) {
933
+ state_new.protocol = this;
934
+ }
935
+ }
936
+ get state() {
937
+ return this._state;
665
938
  }
666
939
 
667
- return false;
940
+ canChangeState(state_new) {
941
+ return this._state.canChangeState(state_new);
942
+ }
668
943
  }
669
944
 
670
945
  //-------------------------------------------------------------------------------------------------
671
- // Sender
672
946
 
673
- function handler_msgAckWarp_(cfg, msg, json_msgAckWarp)
674
- {
675
- // NOTE: json_msgAck here has a string as _msg, instead of JSON.
947
+ class TwoPhW_EventLog {
948
+ constructor(eventLog) {
949
+ this._eventLog = eventLog;
950
+ }
676
951
 
677
- LOGR_.log(l_.HANDLERS, 'handler_msgAckWarp: ...');
952
+ _warp(json_msg) {
953
+ const b_Ack = json_msg.ack !== undefined;
954
+ const json = b_Ack ? json_msg["_msg"] : json_msg;
678
955
 
679
- const json_msgWarp= json_msgAckWarp._msg;
956
+ if (json.warp) {
957
+ return {
958
+ str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Warp]`,
959
+ json_msgWarp: json
960
+ };
961
+ }
962
+ if (json.engage) {
963
+ return {
964
+ str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
965
+ json_msgWarp: json["_msg"]
966
+ };
967
+ }
968
+ return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
969
+ }
680
970
 
681
- const ctx= get_ctx(json_msgWarp.id);
682
- if (!ctx || !ctx.protocol.changeState( new StateAckWarp() ))
683
- return false;
971
+ _addEvent(json_msg, timeout_ms, timeout_callback) {
972
+ const { str_type, json_msgWarp }= this._warp(json_msg);
973
+ const { idx }= this._eventLog.addEvent(str_type, json_msgWarp.warp.id, json_msg, timeout_ms, timeout_callback);
974
+ log_(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
975
+ }
684
976
 
685
- //TODO: check if multiple warps have been sent out with the same destination
977
+ _dropEvent(json_msg) {
978
+ const { json_msgWarp }= this._warp(json_msg);
979
+ if (! json_msgWarp)
980
+ return;
981
+ this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
982
+ }
686
983
 
687
- LOGR_.log(l_.HANDLERS, 'handler_msgAckWarp: ', json_msgAckWarp);
984
+ _cancelTimeout(idx_event) {
985
+ log_(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
986
+ this._eventLog.cancelTimeout(idx_event);
987
+ }
688
988
 
689
- // const json_msgAckWarp= JSON_MsgAckWarp.createWith_msgAck_msg(json_msgAck, json_msgWarp);
989
+ get_protocolState(json_msgWarp) {
990
+ const protocolState = new ProtocolStateState();
991
+
992
+ const arr_evts= this._eventLog.getEventById(json_msgWarp.warp.id, k_TTL);
993
+ log_(l_.EVENTS, () => ['get_protocolState: arr_evts: ', arr_evts]);
994
+
995
+ for (let i = arr_evts.length - 1; i >= 0; i--) {
996
+ const { idx, evt } = arr_evts[i];
997
+
998
+ if (evt.type === '2PhW[DROPPED!]')
999
+ continue;
1000
+
1001
+ const json_msg= evt.data;
1002
+ if (! JSON_MsgWarp.compare(json_msgWarp, this._warp(json_msg).json_msgWarp) )
1003
+ protocolState.state.changeState( new StateINVALID(idx, evt) );
1004
+
1005
+ switch(evt.type) {
1006
+ case '2PhW[JSON_MsgWarp]' :
1007
+ protocolState.state.changeState( new StateWarp(idx, evt) );
1008
+ break;
1009
+ case '2PhW[JSON_MsgAckWarp]' :
1010
+ protocolState.state.changeState( new StateAckWarp(idx, evt) );
1011
+ break;
1012
+ case '2PhW[JSON_MsgEngage]' :
1013
+ protocolState.state.changeState( new StateEngage(idx, evt) );
1014
+ break;
1015
+ case '2PhW[JSON_MsgAckEngage]' :
1016
+ protocolState.state.changeState( new StateAckEngage(idx, evt) );
1017
+ break;
1018
+ default :
1019
+ protocolState.state.changeState( new StateINVALID(idx, evt) );
1020
+ break;
1021
+ }
1022
+ log_(l_.PROTOCOL_STATE, () => ['get_protocolState: type,state: ',
1023
+ evt.type,
1024
+ (protocolState.state.json_msg.ack?.ok === false) ? '--NACK--' : '',
1025
+ protocolState.state
1026
+ ]);
1027
+ }
1028
+ return protocolState;
1029
+ }
690
1030
 
691
- if (! cfg._callback_msgAckWarp(msg, json_msgAckWarp))
692
- return false;
1031
+ }
693
1032
 
694
- if (json_msgWarp.warp.instantaneous) {
695
- const b_res= ctx.protocol.changeState( new StateComplete() );
696
- console.assert(b_res);
697
-
698
- return true;
1033
+ class TwoPhW {
1034
+ constructor(eventLog) {
1035
+ this._2PhW_eventLog = new TwoPhW_EventLog(eventLog);
1036
+ this._config= new Config();
699
1037
  }
700
1038
 
701
- const b_res= ctx.protocol.changeState( new StateEngage() );
702
- console.assert(b_res);
1039
+ get config() {
1040
+ return this._config;
1041
+ }
703
1042
 
704
- return true;
705
- }
1043
+ get eventLog() {
1044
+ return this._2PhW_eventLog;
1045
+ }
706
1046
 
707
- function handler_msgAckEngage_(cfg, msg, json_msgAckEngage)
708
- {
709
- // NOTE: json_msgAck here has a string as _msg, instead of JSON.
1047
+ //-------------------------------------------------------------------------------------------------
710
1048
 
711
- LOGR_.log(l_.HANDLERS, 'handler_msgAckEngage: ...');
1049
+ _handler_msgOptions(cfg, msg, json_msgOptions)
1050
+ {
1051
+ log_(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
1052
+
1053
+ if (! validate_Options_delay_(json_msgOptions.options))
1054
+ return false;
1055
+
1056
+ if (JSON_MsgWarp.validate(json_msgOptions._msg)) {
1057
+ const json_msgWarp= json_msgOptions._msg;
1058
+
1059
+ const ctx= get_ctx(json_msgWarp.id);
1060
+ if (!ctx )
1061
+ return false;
1062
+
1063
+ json_msgOptions.options.ttl_msec_incr[0];
1064
+ const ttl_incr= json_msgOptions.options.ttl_msec_incr[1];
1065
+
1066
+ //TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
1067
+
1068
+ log_(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
1069
+
1070
+ ctx.protocol.delayTimeout(ttl_incr);
1071
+
1072
+ if (cfg._callback_msgOptions)
1073
+ return cfg._callback_msgOptions(msg, json_msgOptions);
1074
+
1075
+ return true;
1076
+ }
1077
+
1078
+ return false;
1079
+ }
1080
+
1081
+ //-------------------------------------------------------------------------------------------------
1082
+ // sender Source (src)
1083
+
1084
+ register_msgWarp(json_msgWarp)
1085
+ {
1086
+ log_(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
712
1087
 
713
- const json_msgEngage= json_msgAckEngage._msg;
1088
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1089
+ const b_changeState= protocolState.canChangeState( new StateWarp(null, {
1090
+ dt: Date.now(),
1091
+ data: json_msgWarp
1092
+ }) );
714
1093
 
715
- const ctx= get_ctx(json_msgEngage.id);
716
- if (!ctx || !ctx.protocol.changeState( new StateAckEngage() ))
717
- return false;
1094
+ log_(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
1095
+ if (! b_changeState)
1096
+ return false;
718
1097
 
719
- LOGR_.log(l_.HANDLERS, 'handler_msgAckEngage: ', json_msgAckEngage);
1098
+ const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec);
1099
+ const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
720
1100
 
721
- // const json_msgAckEngage= JSON_MsgAckEngage.createWith_msgAck_msg(json_msgAck, json_msgEngage);
1101
+ this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
1102
+ this.config._callback_msg_sent_expired(json_msgWarp);
1103
+ });
1104
+ }
722
1105
 
723
- if (! cfg._callback_msgAckEngage(msg, json_msgAckEngage))
724
- return false;
1106
+ _handler_msgAckWarp(msg, json_msgAckWarp)
1107
+ {
1108
+ log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
1109
+
1110
+ const json_msgWarp= json_msgAckWarp._msg;
1111
+
1112
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1113
+ const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
1114
+ dt: Date.now(),
1115
+ data: json_msgAckWarp
1116
+ }) );
1117
+
1118
+ log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
1119
+ if (! b_changeState)
1120
+ return false;
725
1121
 
726
- return true;
727
- }
1122
+ this.eventLog._cancelTimeout(protocolState.state.idx_event);
1123
+ this.eventLog._addEvent(json_msgAckWarp);
1124
+ if (! this.config._callback_msgAckWarp(msg, json_msgAckWarp))
1125
+ return false;
1126
+
1127
+ return true;
1128
+ }
728
1129
 
729
- //-------------------------------------------------------------------------------------------------
730
- // Receiver
1130
+ register_msgEngage(json_msgEngage)
1131
+ {
1132
+ log_(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
731
1133
 
732
- function handler_msgWarp_(cfg, msg, json_msgWarp)
733
- {
734
- LOGR_.log(l_.HANDLERS, 'handler_msgWarp: ...');
1134
+ const json_msgWarp= json_msgEngage._msg;
735
1135
 
736
- let ctx= get_ctx(json_msgWarp.id);
737
- if (ctx === undefined)
738
- ctx= set_ctx(json_msgWarp.id, { protocol: new ProtocolStateState() });
1136
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1137
+ const b_changeState= protocolState.canChangeState( new StateEngage(null, {
1138
+ dt: Date.now(),
1139
+ data : json_msgEngage
1140
+ }) );
739
1141
 
740
- if (!ctx || !ctx.protocol.changeState( new StateWarp() ))
741
- return false;
1142
+ log_(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
1143
+ if (! b_changeState)
1144
+ return false;
1145
+
1146
+ const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
1147
+ const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
742
1148
 
743
- LOGR_.log(l_.HANDLERS, 'handler_msgWarp: ', json_msgWarp);
1149
+ this.eventLog._addEvent(json_msgEngage, timeout_ms-elapsed_ms, () => {
1150
+ this.config._callback_msg_sent_expired(json_msgEngage);
1151
+ });
1152
+ }
1153
+
1154
+ _handler_msgAckEngage(msg, json_msgAckEngage)
1155
+ {
1156
+ log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
1157
+
1158
+ const json_msgWarp= json_msgAckEngage._msg._msg;
744
1159
 
745
- if (! cfg._callback_msgWarp(msg, json_msgWarp))
746
- return false;
1160
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1161
+ const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
1162
+ dt: Date.now(),
1163
+ data : json_msgAckEngage
1164
+ }) );
1165
+
1166
+ log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
1167
+ if (! b_changeState)
1168
+ return false;
747
1169
 
748
- if (json_msgWarp.warp.instantaneous) {
749
- const b_res= ctx.protocol.changeState( new StateComplete() );
750
- console.assert(b_res);
1170
+ this.eventLog._cancelTimeout(protocolState.state.idx_event);
1171
+ this.eventLog._addEvent(json_msgAckEngage);
1172
+ if (! this.config._callback_msgAckEngage(msg, json_msgAckEngage))
1173
+ return false;
751
1174
 
752
1175
  return true;
753
1176
  }
1177
+
1178
+ //-------------------------------------------------------------------------------------------------
1179
+ // receiver Destination (dst)
754
1180
 
755
- const b_res= ctx.protocol.changeState( new StateAckWarp() );
756
- console.assert(b_res);
1181
+ _handler_msgWarp(msg, json_msgWarp)
1182
+ {
1183
+ log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: ', json_msgWarp]);
1184
+
1185
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1186
+ const b_changeState= protocolState.canChangeState( new StateWarp(null, {
1187
+ dt: Date.now(),
1188
+ data: json_msgWarp
1189
+ }) );
1190
+
1191
+ log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
1192
+ if (! b_changeState)
1193
+ return false;
757
1194
 
758
- return true;
759
- }
1195
+ this.eventLog._addEvent(json_msgWarp);
1196
+ if (! this.config._callback_msgWarp(msg, json_msgWarp))
1197
+ return false;
1198
+
1199
+ return true;
1200
+ }
1201
+
1202
+ register_msgAckWarp(json_msgAckWarp)
1203
+ {
1204
+ log_(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
760
1205
 
761
- function handler_msgEngage_(cfg, msg, json_msgEngage)
762
- {
763
- LOGR_.log(l_.HANDLERS, 'handler_msgEngage: ...');
1206
+ const json_msgWarp= json_msgAckWarp._msg;
764
1207
 
765
- const ctx= get_ctx(json_msgEngage.id);
766
- if (!ctx || !ctx.protocol.changeState( new StateEngage() ))
767
- return false;
1208
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1209
+ const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
1210
+ dt: Date.now(),
1211
+ data: json_msgAckWarp
1212
+ }) );
768
1213
 
769
- LOGR_.log(l_.HANDLERS, 'handler_msgEngage: ', json_msgEngage);
1214
+ log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
1215
+ if (! b_changeState)
1216
+ return false;
770
1217
 
771
- if (! cfg._callback_msgEngage(msg, json_msgEngage))
772
- return false;
1218
+ const elapsed_ms= Date.now() - Date.parse(json_msgAckWarp.dt);
1219
+ const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
773
1220
 
774
- const b_res= ctx.protocol.changeState( new StateComplete() );
775
- console.assert(b_res);
1221
+ this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
1222
+ this.config._callback_msg_sent_expired(json_msgAckWarp);
1223
+ });
1224
+ }
776
1225
 
777
- return true;
778
- }
1226
+ _handler_msgEngage(msg, json_msgEngage)
1227
+ {
1228
+ log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
779
1229
 
780
- //-------------------------------------------------------------------------------------------------
1230
+ const json_msgWarp= json_msgEngage["_msg"];
781
1231
 
782
- class TwoPhW {
783
- constructor() {
784
- this._config= new Config();
785
- }
1232
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1233
+ const b_changeState= protocolState.canChangeState( new StateEngage(null, {
1234
+ dt: Date.now(),
1235
+ data: json_msgEngage
1236
+ }) );
786
1237
 
787
- get config() {
788
- return this._config;
1238
+ log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
1239
+ if (! b_changeState)
1240
+ return false;
1241
+
1242
+ this.eventLog._cancelTimeout(protocolState.state.idx_event);
1243
+ this.eventLog._addEvent(json_msgEngage);
1244
+ if (! this.config._callback_msgEngage(msg, json_msgEngage))
1245
+ return false;
1246
+
1247
+ return true;
789
1248
  }
790
1249
 
791
- // this function need to be removed when a microservice db is used instead of a state machine
792
- create_MsgWarp_out(str_id, json_user, json_hyperport, nr_ttl_msec, b_instantaneous)
1250
+ register_msgAckEngage(json_msgAckEngage)
793
1251
  {
794
- if (nr_ttl_msec === undefined)
795
- nr_ttl_msec= k_TTL;
1252
+ log_(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
796
1253
 
797
- const json_msgWarp= JSON_MsgWarp.create_with_user_hyperport(json_user, json_hyperport, nr_ttl_msec);
798
- json_msgWarp.id= str_id;
799
-
800
- if (b_instantaneous !== undefined)
801
- json_msgWarp.warp.instantaneous= b_instantaneous;
1254
+ const json_msgWarp= json_msgAckEngage._msg._msg;
1255
+
1256
+ const protocolState= this.eventLog.get_protocolState(json_msgWarp);
1257
+ const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
1258
+ dt: Date.now(),
1259
+ data: json_msgAckEngage
1260
+ }) );
802
1261
 
803
- const ctx= set_ctx(json_msgWarp.id, { protocol: new ProtocolStateState() });
804
- const b_res= ctx.protocol.changeState( new StateWarp(), nr_ttl_msec, function() {
805
- const json_Nack= JSON_MsgAckWarp.create_with_msgExpired( json_msgWarp );
806
- //TODO: the referer is NULL here !
807
- this._config._callback_msgAckWarp(json_Nack, json_Nack);
808
- }.bind(this) );
1262
+ log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
1263
+ if (! b_changeState)
1264
+ return false;
809
1265
 
810
- console.assert(b_res);
811
- return json_msgWarp;
1266
+ this.eventLog._addEvent(json_msgAckEngage);
812
1267
  }
813
1268
 
1269
+ //-------------------------------------------------------------------------------------------------
1270
+
814
1271
  handler_msg_json(msg, json_msg)
815
1272
  {
816
- LOGR_.log(l_.HANDLERS, 'handler_msg_json: ', json_msg);
1273
+ log_(l_.HANDLERS, () => ['handler_msg_json: ', json_msg]);
817
1274
 
818
1275
  // ADR: I could parse json_Msg_msg first and then MsgAck or MsgOptions, but
819
1276
  // doing so means super classes get parsed multiple times for no reason
820
1277
 
821
- if (JSON_MsgOptions.validate(json_msg) && handler_msgOptions_(this._config, msg, json_msg))
822
- return true;
1278
+ // if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
1279
+ // return true;
823
1280
 
824
- if (JSON_MsgWarp.validate(json_msg) && handler_msgWarp_(this._config, msg, json_msg))
1281
+ if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg))
825
1282
  return true;
826
1283
 
827
- if (JSON_MsgEngage.validate(json_msg) && handler_msgEngage_(this._config, msg, json_msg))
1284
+ if (JSON_MsgEngage.validate(json_msg) && this._handler_msgEngage(msg, json_msg))
828
1285
  return true;
829
1286
 
830
- if (JSON_MsgAckWarp.validate(json_msg) && handler_msgAckWarp_(this._config, msg, json_msg))
1287
+ if (JSON_MsgAckWarp.validate(json_msg) && this._handler_msgAckWarp(msg, json_msg))
831
1288
  return true;
832
1289
 
833
- if (JSON_MsgAckEngage.validate(json_msg) && handler_msgAckEngage_(this._config, msg, json_msg))
1290
+ if (JSON_MsgAckEngage.validate(json_msg) && this._handler_msgAckEngage(msg, json_msg))
834
1291
  return true;
835
1292
 
836
1293
  // https://attacomsian.com/blog/javascript-iterate-objects
@@ -842,12 +1299,14 @@ class TwoPhW {
842
1299
  // console.log(`${key}: ${json_msg[key]}`);
843
1300
  // });
844
1301
 
1302
+ this.eventLog._dropEvent(json_msg);
1303
+ log_(l_.DROPS, () => ["TwoPhW: handler_msg: DROP! ", msg]);
845
1304
  return false;
846
1305
  }
847
1306
 
848
1307
  handler_msg_str(msg, str_msg)
849
1308
  {
850
- LOGR_.log(l_.HANDLERS, 'handler_msg_str: ['+ str_msg +']');
1309
+ log_(l_.HANDLERS, () => ['handler_msg_str: ['+ str_msg +']']);
851
1310
 
852
1311
  // ... test strings here
853
1312
 
@@ -864,24 +1323,31 @@ class TwoPhW {
864
1323
 
865
1324
  handler_msg(msg)
866
1325
  {
867
- LOGR_.log(l_.HANDLERS, 'handler_msg: ', msg);
1326
+ log_(l_.HANDLERS, () => ['handler_msg: ', msg]);
868
1327
 
869
1328
  if (typeof (msg) === 'string' && this.handler_msg_str(msg, msg))
870
1329
  return true;
871
1330
 
872
1331
  if (typeof (msg) === 'object' && this.handler_msg_json(msg, msg))
873
1332
  return true;
874
-
875
- LOGR_.log(l_.DROPS, "handler_msg: DROP! ", msg);
1333
+
876
1334
  return false
877
1335
  }
878
1336
 
879
1337
  }
880
1338
 
1339
+ exports.EventLog = EventLog;
881
1340
  exports.JSON_MsgAckEngage = JSON_MsgAckEngage;
882
1341
  exports.JSON_MsgAckWarp = JSON_MsgAckWarp;
883
1342
  exports.JSON_MsgEngage = JSON_MsgEngage;
884
1343
  exports.JSON_MsgOptions = JSON_MsgOptions;
885
1344
  exports.JSON_MsgWarp = JSON_MsgWarp;
1345
+ exports.StateAckEngage = StateAckEngage;
1346
+ exports.StateAckWarp = StateAckWarp;
1347
+ exports.StateEngage = StateEngage;
1348
+ exports.StateINVALID = StateINVALID;
1349
+ exports.StateInitialState = StateInitialState;
1350
+ exports.StateWarp = StateWarp;
886
1351
  exports.TwoPhW = TwoPhW;
887
1352
  exports.l = l_;
1353
+ exports.t_ttl_rtt = t_ttl_rtt_;