@rootintf/protocol-2phw 1.3.3-api.1 → 2.1.5-api.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EventLog-mem.d.mts +2 -5
- package/dist/twoPhW.cjs.js +640 -414
- package/dist/twoPhW.d.ts +31 -31
- package/dist/twoPhW.es.mjs +640 -414
- package/package.json +6 -6
- package/schema/schema_2PhW.json +1 -1
- package/src/EventLog-mem.mjs +9 -15
- package/src/index.ts +1 -1
- package/src/twoPhW.ts +110 -110
- package/src/validate-esm.mjs +1 -1
- package/tests/event-log-mem.spec.mjs +9 -4
- package/tests/twoPhW-new.spec.mjs +74 -55
- package/dist/index.d.ts +0 -1
package/src/twoPhW.ts
CHANGED
|
@@ -8,16 +8,16 @@ import {
|
|
|
8
8
|
} from './validate-esm.mjs';
|
|
9
9
|
|
|
10
10
|
// import { v4 as uuidv4 } from 'uuid'; // uuid is already a dep of JSON_Msg, so why not
|
|
11
|
-
import { LOGR, l_array, l_concat, l_LL } from '@knev/bitlogr';
|
|
12
|
-
import { JSON_Msg,
|
|
11
|
+
import { LOGR, lRef, l_merge, l_array, l_concat, l_LL } from '@knev/bitlogr';
|
|
12
|
+
import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, logr as logr_json_msg_ } from '@rootintf/json-msg'
|
|
13
13
|
|
|
14
|
-
import { EventLog,
|
|
14
|
+
import { EventLog, logr as logr_evtlog_ } from './EventLog-mem.mjs'
|
|
15
15
|
|
|
16
16
|
type t_msg = string;
|
|
17
17
|
|
|
18
18
|
interface EventMinimal {
|
|
19
19
|
dt : number;
|
|
20
|
-
data : { msg : t_msg, json_msg
|
|
20
|
+
data : { msg : t_msg, json_msg };
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// interface Event extends Required<EventMinimal> {
|
|
@@ -30,26 +30,23 @@ const k_TTL= 20000;
|
|
|
30
30
|
|
|
31
31
|
//-------------------------------------------------------------------------------------------------
|
|
32
32
|
|
|
33
|
-
const
|
|
34
|
-
const
|
|
33
|
+
const obj_labels_merge_= l_merge(logr_evtlog_.lref.get(), logr_json_msg_.lref.get()); // VALIDATION : 4
|
|
34
|
+
const obj_labels_concat_= l_concat(obj_labels_merge_, l_array(['HANDLERS', 'DROPS', 'PROTOCOL_STATE', 'RECVER', 'SENDER']) );
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const lref_= lRef(obj_labels_concat_);
|
|
37
|
+
logr_json_msg_.lref= lref_;
|
|
38
|
+
logr_evtlog_.lref= lref_;
|
|
37
39
|
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
+
const LOGR_= LOGR.get_instance();
|
|
41
|
+
const logr_= LOGR_.create(); // don't let create() make a new ref, assign lref_ from here
|
|
42
|
+
logr_.lref= lref_;
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
// LOGR_.toggled= {
|
|
43
|
-
// HANDLERS : true,
|
|
44
|
-
// SENDER : true,
|
|
45
|
-
// PROTOCOL_STATE : true,
|
|
46
|
-
// // EVENTS : true
|
|
47
|
-
// }
|
|
44
|
+
const l_= logr_.l;
|
|
48
45
|
|
|
49
46
|
//-------------------------------------------------------------------------------------------------
|
|
50
47
|
|
|
51
|
-
type t_callback = (msg : t_msg, json_msg
|
|
52
|
-
type t_callback_void = (msg : t_msg, json_msg
|
|
48
|
+
type t_callback = (msg : t_msg, json_msg) => boolean;
|
|
49
|
+
type t_callback_void = (msg : t_msg, json_msg) => void;
|
|
53
50
|
|
|
54
51
|
class Config {
|
|
55
52
|
public _callback_msgWarp : t_callback
|
|
@@ -61,19 +58,19 @@ class Config {
|
|
|
61
58
|
|
|
62
59
|
constructor() {
|
|
63
60
|
// Initialize callbacks as no-op functions
|
|
64
|
-
this._callback_msgWarp = (_msg : t_msg, _json_msg
|
|
61
|
+
this._callback_msgWarp = (_msg : t_msg, _json_msg) => {
|
|
65
62
|
console.assert(false, 'callback_msgWarp uninitialized'); return false;
|
|
66
63
|
};
|
|
67
|
-
this._callback_msgEngage = (_msg : t_msg, _json_msg
|
|
64
|
+
this._callback_msgEngage = (_msg : t_msg, _json_msg) => {
|
|
68
65
|
console.assert(false, 'callback_msgEngage uninitialized'); return false;
|
|
69
66
|
};
|
|
70
|
-
this._callback_msgAckWarp = (_msg : t_msg, _json_msg
|
|
67
|
+
this._callback_msgAckWarp = (_msg : t_msg, _json_msg) => {
|
|
71
68
|
console.assert(false, 'callback_msgAckWarp uninitialized'); return false;
|
|
72
69
|
};
|
|
73
|
-
this._callback_msgAckEngage = (_msg : t_msg, _json_msg
|
|
70
|
+
this._callback_msgAckEngage = (_msg : t_msg, _json_msg) => {
|
|
74
71
|
console.assert(false, 'callback_msgAckEngage uninitialized'); return false;
|
|
75
72
|
};
|
|
76
|
-
this._callback_msg_sent_expired = (_msg : t_msg, _json_msg
|
|
73
|
+
this._callback_msg_sent_expired = (_msg : t_msg, _json_msg) => {
|
|
77
74
|
console.assert(false, '_callback_msg_sent_expired uninitialized');
|
|
78
75
|
};
|
|
79
76
|
this._callback_msgOptions = () => {
|
|
@@ -113,7 +110,7 @@ class Config {
|
|
|
113
110
|
|
|
114
111
|
//-------------------------------------------------------------------------------------------------
|
|
115
112
|
|
|
116
|
-
let k_VERSION= "
|
|
113
|
+
let k_VERSION= "2";
|
|
117
114
|
|
|
118
115
|
// rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
|
|
119
116
|
// t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
|
|
@@ -130,8 +127,8 @@ function time_ttl_rtt_(ttl_msec: number | undefined, rtt_msec?: number): number
|
|
|
130
127
|
|
|
131
128
|
var JSON_MsgOptions = (function() {
|
|
132
129
|
return {
|
|
133
|
-
|
|
134
|
-
return
|
|
130
|
+
create_with_cause_options : function(msg_cause, options) {
|
|
131
|
+
return JSON_MsgEffect.create_with_msg_merge(msg_cause, {
|
|
135
132
|
options: options,
|
|
136
133
|
"2PhW": k_VERSION
|
|
137
134
|
});
|
|
@@ -140,7 +137,7 @@ var JSON_MsgOptions = (function() {
|
|
|
140
137
|
// if (! JSON_Msg_msg.validate(json))
|
|
141
138
|
// return false;
|
|
142
139
|
// if (! schema_MsgOptions_(json)) {
|
|
143
|
-
//
|
|
140
|
+
// logr_.log(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', (schema_MsgOptions_ as any).errors])
|
|
144
141
|
// return false;
|
|
145
142
|
// }
|
|
146
143
|
return true;
|
|
@@ -161,7 +158,7 @@ var JSON_MsgWarp = (function() {
|
|
|
161
158
|
"2PhW": k_VERSION
|
|
162
159
|
});
|
|
163
160
|
},
|
|
164
|
-
compare : function(json_L
|
|
161
|
+
compare : function(json_L, json_R) {
|
|
165
162
|
if (json_L.dt !== json_R.dt)
|
|
166
163
|
return false;
|
|
167
164
|
if (json_L.warp.id !== json_R.warp.id)
|
|
@@ -176,7 +173,7 @@ var JSON_MsgWarp = (function() {
|
|
|
176
173
|
// if (! JSON_Msg.validate(json))
|
|
177
174
|
// return false;
|
|
178
175
|
if (! schema_MsgWarp_(json_msg)) {
|
|
179
|
-
|
|
176
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgWarp: schema_MsgWarp_: ', (schema_MsgWarp_ as any).errors])
|
|
180
177
|
return false;
|
|
181
178
|
}
|
|
182
179
|
return true;
|
|
@@ -186,9 +183,9 @@ var JSON_MsgWarp = (function() {
|
|
|
186
183
|
|
|
187
184
|
var JSON_MsgEngage = (function() {
|
|
188
185
|
return {
|
|
189
|
-
|
|
186
|
+
create_with_Warp : function(json_msgWarp) {
|
|
190
187
|
console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
|
|
191
|
-
return
|
|
188
|
+
return JSON_MsgEffect.create_with_cause_merge(json_msgWarp, {
|
|
192
189
|
engage : {
|
|
193
190
|
"ok" : true,
|
|
194
191
|
"rtt_msec" : Date.now() - Date.parse(json_msgWarp.dt)
|
|
@@ -196,13 +193,13 @@ var JSON_MsgEngage = (function() {
|
|
|
196
193
|
"2PhW": k_VERSION
|
|
197
194
|
});
|
|
198
195
|
},
|
|
199
|
-
validate : function(
|
|
196
|
+
validate : function(json_msgEffect) {
|
|
200
197
|
// if (! JSON_Msg_msg.validate(json))
|
|
201
198
|
// return false;
|
|
202
|
-
if (! JSON_MsgWarp.validate(
|
|
199
|
+
if (! JSON_MsgWarp.validate(json_msgEffect._cause))
|
|
203
200
|
return false;
|
|
204
|
-
if (! schema_MsgEngage_(
|
|
205
|
-
|
|
201
|
+
if (! schema_MsgEngage_(json_msgEffect)) {
|
|
202
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', (schema_MsgEngage_ as any).errors])
|
|
206
203
|
return false;
|
|
207
204
|
}
|
|
208
205
|
return true;
|
|
@@ -214,23 +211,23 @@ var JSON_MsgAckWarp = (function() {
|
|
|
214
211
|
return {
|
|
215
212
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
216
213
|
// const json_msgAckWarp= structuredClone(json_msgAck);
|
|
217
|
-
// json_msgAckWarp.
|
|
214
|
+
// json_msgAckWarp._cause= _cause;
|
|
218
215
|
// return json_msgAckWarp;
|
|
219
216
|
// }
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
return
|
|
217
|
+
create_with_Warp_Ok : function(json_msgWarp, b_ok= true) {
|
|
218
|
+
const json_msgAck= JSON_MsgAck.create_with_cause_Ok(json_msgWarp, b_ok);
|
|
219
|
+
json_msgAck["2PhW"]= k_VERSION;
|
|
220
|
+
return json_msgAck;
|
|
224
221
|
},
|
|
225
222
|
// create_with_msgExpired : function( json_msgWarp ) {
|
|
226
223
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp )
|
|
227
224
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
228
225
|
// return json_msgAck_msg;
|
|
229
226
|
// },
|
|
230
|
-
validate : function(
|
|
227
|
+
validate : function(json_msgAck) {
|
|
231
228
|
// if (! JSON_MsgAck_msg.validate(json))
|
|
232
229
|
// return false;
|
|
233
|
-
if (! JSON_MsgWarp.validate(
|
|
230
|
+
if (! JSON_MsgWarp.validate(json_msgAck._cause))
|
|
234
231
|
return false;
|
|
235
232
|
return true;
|
|
236
233
|
}
|
|
@@ -241,23 +238,23 @@ var JSON_MsgAckEngage = (function() {
|
|
|
241
238
|
return {
|
|
242
239
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
243
240
|
// const json_msgAckEngage= structuredClone(json_msgAck);
|
|
244
|
-
// json_msgAckEngage.
|
|
241
|
+
// json_msgAckEngage._cause= _cause;
|
|
245
242
|
// return json_msgAckEngage;
|
|
246
243
|
// }
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
return
|
|
244
|
+
create_with_Engage_Ok : function(json_msgEngage, b_ok= true) {
|
|
245
|
+
const json_msgAck= JSON_MsgAck.create_with_cause_Ok(json_msgEngage, b_ok);
|
|
246
|
+
json_msgAck["2PhW"]= k_VERSION;
|
|
247
|
+
return json_msgAck;
|
|
251
248
|
},
|
|
252
249
|
// create_with_msgExpired : function( json_msgEngage ) {
|
|
253
250
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage )
|
|
254
251
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
255
252
|
// return json_msgAck_msg;
|
|
256
253
|
// },
|
|
257
|
-
validate : function(
|
|
254
|
+
validate : function(json_msgAck) {
|
|
258
255
|
// if (! JSON_MsgAck_msg.validate(json_msgAck_msg))
|
|
259
256
|
// return false;
|
|
260
|
-
if (! JSON_MsgEngage.validate(
|
|
257
|
+
if (! JSON_MsgEngage.validate(json_msgAck._cause))
|
|
261
258
|
return false;
|
|
262
259
|
return true;
|
|
263
260
|
}
|
|
@@ -321,9 +318,9 @@ class StateEngage extends StateState {
|
|
|
321
318
|
return false;
|
|
322
319
|
|
|
323
320
|
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
324
|
-
const json_msgWarp= this.json_msgEngage.
|
|
321
|
+
const json_msgWarp= this.json_msgEngage._cause;
|
|
325
322
|
const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
326
|
-
|
|
323
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`])
|
|
327
324
|
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
328
325
|
return false;
|
|
329
326
|
|
|
@@ -342,7 +339,7 @@ class StateAckWarp extends StateState {
|
|
|
342
339
|
if (! this.json_msgAckWarp.ack.ok)
|
|
343
340
|
return false;
|
|
344
341
|
|
|
345
|
-
if (this.json_msgAckWarp.
|
|
342
|
+
if (this.json_msgAckWarp._cause.warp.instantaneous)
|
|
346
343
|
return false;
|
|
347
344
|
|
|
348
345
|
// The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
|
|
@@ -350,8 +347,8 @@ class StateAckWarp extends StateState {
|
|
|
350
347
|
// - Engage: T0 +2TTL +RTT; RTT= STT+STT
|
|
351
348
|
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
352
349
|
// - STT: Date of the Ack minus date of the Warp.
|
|
353
|
-
const timeout_ms= time_ttl_rtt_(this.json_msgAckWarp.
|
|
354
|
-
|
|
350
|
+
const timeout_ms= time_ttl_rtt_(this.json_msgAckWarp._cause.warp.ttl_msec) + Date.parse(this.json_msgAckWarp.dt) - Date.parse(this.json_msgAckWarp._cause.dt);
|
|
351
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`])
|
|
355
352
|
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
356
353
|
return false;
|
|
357
354
|
|
|
@@ -369,7 +366,7 @@ class StateWarp extends StateState {
|
|
|
369
366
|
|
|
370
367
|
// The Warp gets to live for THE WARP'S creation time + TTL*2
|
|
371
368
|
const timeout_ms= time_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
|
|
372
|
-
|
|
369
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`])
|
|
373
370
|
if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
|
|
374
371
|
return false;
|
|
375
372
|
|
|
@@ -393,7 +390,7 @@ class StateInitialState extends StateState {
|
|
|
393
390
|
|
|
394
391
|
// The NEWLY created Warp only gets to live for its creation time + TTL
|
|
395
392
|
const timeout_ms= state_new.json_msgWarp.warp.ttl_msec;
|
|
396
|
-
|
|
393
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateInitialState: evt_Warp.dt@${state_new.evt_Warp.dt}, msgWarp.dt@${Date.parse(state_new.json_msgWarp.dt)} + ${timeout_ms}`])
|
|
397
394
|
if (state_new.evt_Warp.dt >= Date.parse(state_new.json_msgWarp.dt) + timeout_ms)
|
|
398
395
|
return false;
|
|
399
396
|
|
|
@@ -439,7 +436,7 @@ class TwoPhW_EventLog {
|
|
|
439
436
|
|
|
440
437
|
_warp(json_msg) {
|
|
441
438
|
const b_Ack = json_msg.ack !== undefined;
|
|
442
|
-
const json = b_Ack ? json_msg["
|
|
439
|
+
const json = b_Ack ? json_msg["_cause"] : json_msg;
|
|
443
440
|
|
|
444
441
|
if (json.warp) {
|
|
445
442
|
return {
|
|
@@ -450,17 +447,17 @@ class TwoPhW_EventLog {
|
|
|
450
447
|
if (json.engage) {
|
|
451
448
|
return {
|
|
452
449
|
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
|
|
453
|
-
json_msgWarp: json["
|
|
450
|
+
json_msgWarp: json["_cause"]
|
|
454
451
|
};
|
|
455
452
|
}
|
|
456
453
|
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
457
454
|
}
|
|
458
455
|
|
|
459
456
|
// _addEvent(msg: t_msg, json_msg : JSON_Msg, timeout_ms? : number, timeout_callback? : ( args? : {idx_event : number, event : EventMinimal} ) => {}) {
|
|
460
|
-
_addEvent(msg: t_msg, json_msg
|
|
457
|
+
_addEvent(msg: t_msg, json_msg, timeout_ms? : number, timeout_callback? : () => void) {
|
|
461
458
|
const { str_type, json_msgWarp }= this._warp(json_msg);
|
|
462
459
|
const { idx }= this._eventLog.addEvent(str_type, json_msgWarp.warp.id, {msg, json_msg}, timeout_ms, timeout_callback);
|
|
463
|
-
|
|
460
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
|
|
464
461
|
}
|
|
465
462
|
|
|
466
463
|
_dropEvent(json_msg) {
|
|
@@ -471,7 +468,7 @@ class TwoPhW_EventLog {
|
|
|
471
468
|
}
|
|
472
469
|
|
|
473
470
|
_cancelTimeout(idx_event) {
|
|
474
|
-
|
|
471
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
|
|
475
472
|
this._eventLog.cancelTimeout(idx_event);
|
|
476
473
|
}
|
|
477
474
|
|
|
@@ -479,7 +476,7 @@ class TwoPhW_EventLog {
|
|
|
479
476
|
const protocolState = new ProtocolStateState();
|
|
480
477
|
|
|
481
478
|
const arr_evts= this._eventLog.getEventsById(json_msgWarp.warp.id, k_TTL);
|
|
482
|
-
|
|
479
|
+
logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
|
|
483
480
|
//TODO: what is the right TTL? should it be a constant or calculated
|
|
484
481
|
|
|
485
482
|
for (let i = arr_evts.length - 1; i >= 0; i--) {
|
|
@@ -506,7 +503,7 @@ class TwoPhW_EventLog {
|
|
|
506
503
|
break;
|
|
507
504
|
}
|
|
508
505
|
|
|
509
|
-
|
|
506
|
+
logr_.log(l_.PROTOCOL_STATE, () => ['traverse_State: type,state: ',
|
|
510
507
|
evt.type,
|
|
511
508
|
(protocolState.state.json_msg.ack?.ok === false) ? '--NACK--' : '',
|
|
512
509
|
protocolState.state
|
|
@@ -538,14 +535,14 @@ class TwoPhW {
|
|
|
538
535
|
|
|
539
536
|
_handler_msgOptions(cfg, msg, json_msgOptions) : boolean
|
|
540
537
|
{
|
|
541
|
-
|
|
538
|
+
logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
|
|
542
539
|
|
|
543
540
|
/*
|
|
544
541
|
if (! validate_Options_delay_(json_msgOptions.options))
|
|
545
542
|
return false;
|
|
546
543
|
|
|
547
|
-
if (JSON_MsgWarp.validate(json_msgOptions.
|
|
548
|
-
const json_msgWarp= json_msgOptions.
|
|
544
|
+
if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
|
|
545
|
+
const json_msgWarp= json_msgOptions._cause;
|
|
549
546
|
|
|
550
547
|
const ctx= get_ctx(json_msgWarp.id);
|
|
551
548
|
if (!ctx )
|
|
@@ -556,7 +553,7 @@ class TwoPhW {
|
|
|
556
553
|
|
|
557
554
|
//TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
|
|
558
555
|
|
|
559
|
-
|
|
556
|
+
logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
|
|
560
557
|
|
|
561
558
|
ctx.protocol.delayTimeout(ttl_incr);
|
|
562
559
|
|
|
@@ -573,9 +570,9 @@ class TwoPhW {
|
|
|
573
570
|
//-------------------------------------------------------------------------------------------------
|
|
574
571
|
// sender Source (src)
|
|
575
572
|
|
|
576
|
-
register_msgWarp(msg : t_msg, json_msgWarp
|
|
573
|
+
register_msgWarp(msg : t_msg, json_msgWarp) : boolean
|
|
577
574
|
{
|
|
578
|
-
|
|
575
|
+
logr_.log(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
|
|
579
576
|
|
|
580
577
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
581
578
|
const b_changeState= protocolState.canChangeState( new StateWarp(null, {
|
|
@@ -583,7 +580,7 @@ class TwoPhW {
|
|
|
583
580
|
data: { msg, json_msg: json_msgWarp }
|
|
584
581
|
}) );
|
|
585
582
|
|
|
586
|
-
|
|
583
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
|
|
587
584
|
if (! b_changeState)
|
|
588
585
|
return false;
|
|
589
586
|
|
|
@@ -595,11 +592,11 @@ class TwoPhW {
|
|
|
595
592
|
});
|
|
596
593
|
}
|
|
597
594
|
|
|
598
|
-
_handler_msgAckWarp(msg : t_msg, json_msgAckWarp
|
|
595
|
+
_handler_msgAckWarp(msg : t_msg, json_msgAckWarp) : boolean
|
|
599
596
|
{
|
|
600
|
-
|
|
597
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
|
|
601
598
|
|
|
602
|
-
const json_msgWarp= json_msgAckWarp.
|
|
599
|
+
const json_msgWarp= json_msgAckWarp._cause;
|
|
603
600
|
|
|
604
601
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
605
602
|
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
@@ -607,7 +604,7 @@ class TwoPhW {
|
|
|
607
604
|
data: { msg, json_msg: json_msgAckWarp }
|
|
608
605
|
}) );
|
|
609
606
|
|
|
610
|
-
|
|
607
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
|
|
611
608
|
if (! b_changeState)
|
|
612
609
|
return false;
|
|
613
610
|
|
|
@@ -616,11 +613,11 @@ class TwoPhW {
|
|
|
616
613
|
return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
|
|
617
614
|
}
|
|
618
615
|
|
|
619
|
-
register_msgEngage(msg : t_msg, json_msgEngage
|
|
616
|
+
register_msgEngage(msg : t_msg, json_msgEngage) : boolean
|
|
620
617
|
{
|
|
621
|
-
|
|
618
|
+
logr_.log(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
|
|
622
619
|
|
|
623
|
-
const json_msgWarp= json_msgEngage.
|
|
620
|
+
const json_msgWarp= json_msgEngage._cause;
|
|
624
621
|
|
|
625
622
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
626
623
|
const b_changeState = protocolState.canChangeState( new StateEngage(null, {
|
|
@@ -628,7 +625,7 @@ class TwoPhW {
|
|
|
628
625
|
data : { msg, json_msg: json_msgEngage }
|
|
629
626
|
}) );
|
|
630
627
|
|
|
631
|
-
|
|
628
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
|
|
632
629
|
if (! b_changeState)
|
|
633
630
|
return false;
|
|
634
631
|
|
|
@@ -640,11 +637,11 @@ class TwoPhW {
|
|
|
640
637
|
});
|
|
641
638
|
}
|
|
642
639
|
|
|
643
|
-
_handler_msgAckEngage(msg : t_msg, json_msgAckEngage
|
|
640
|
+
_handler_msgAckEngage(msg : t_msg, json_msgAckEngage) : boolean
|
|
644
641
|
{
|
|
645
|
-
|
|
642
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
|
|
646
643
|
|
|
647
|
-
const json_msgWarp= json_msgAckEngage.
|
|
644
|
+
const json_msgWarp= json_msgAckEngage._cause._cause;
|
|
648
645
|
|
|
649
646
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
650
647
|
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
@@ -652,7 +649,7 @@ class TwoPhW {
|
|
|
652
649
|
data : { msg, json_msg: json_msgAckEngage }
|
|
653
650
|
}) );
|
|
654
651
|
|
|
655
|
-
|
|
652
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
|
|
656
653
|
if (! b_changeState)
|
|
657
654
|
return false;
|
|
658
655
|
|
|
@@ -664,9 +661,9 @@ class TwoPhW {
|
|
|
664
661
|
//-------------------------------------------------------------------------------------------------
|
|
665
662
|
// receiver Destination (dst)
|
|
666
663
|
|
|
667
|
-
_handler_msgWarp(msg : t_msg, json_msgWarp
|
|
664
|
+
_handler_msgWarp(msg : t_msg, json_msgWarp) : boolean
|
|
668
665
|
{
|
|
669
|
-
|
|
666
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: ', json_msgWarp]);
|
|
670
667
|
|
|
671
668
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
672
669
|
const b_changeState= protocolState.canChangeState( new StateWarp(null, {
|
|
@@ -674,7 +671,7 @@ class TwoPhW {
|
|
|
674
671
|
data: { msg, json_msg: json_msgWarp }
|
|
675
672
|
}) );
|
|
676
673
|
|
|
677
|
-
|
|
674
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
|
|
678
675
|
if (! b_changeState)
|
|
679
676
|
return false;
|
|
680
677
|
|
|
@@ -682,11 +679,11 @@ class TwoPhW {
|
|
|
682
679
|
return this.config._callback_msgWarp(msg, json_msgWarp)
|
|
683
680
|
}
|
|
684
681
|
|
|
685
|
-
register_msgAckWarp(msg: t_msg, json_msgAckWarp
|
|
682
|
+
register_msgAckWarp(msg: t_msg, json_msgAckWarp) : boolean
|
|
686
683
|
{
|
|
687
|
-
|
|
684
|
+
logr_.log(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
|
|
688
685
|
|
|
689
|
-
const json_msgWarp= json_msgAckWarp.
|
|
686
|
+
const json_msgWarp= json_msgAckWarp._cause;
|
|
690
687
|
|
|
691
688
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
692
689
|
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
@@ -694,7 +691,7 @@ class TwoPhW {
|
|
|
694
691
|
data: { msg, json_msg: json_msgAckWarp }
|
|
695
692
|
}) );
|
|
696
693
|
|
|
697
|
-
|
|
694
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
|
|
698
695
|
if (! b_changeState)
|
|
699
696
|
return false;
|
|
700
697
|
|
|
@@ -706,11 +703,11 @@ class TwoPhW {
|
|
|
706
703
|
});
|
|
707
704
|
}
|
|
708
705
|
|
|
709
|
-
_handler_msgEngage(msg : t_msg, json_msgEngage
|
|
706
|
+
_handler_msgEngage(msg : t_msg, json_msgEngage) : boolean
|
|
710
707
|
{
|
|
711
|
-
|
|
708
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
|
|
712
709
|
|
|
713
|
-
const json_msgWarp= json_msgEngage
|
|
710
|
+
const json_msgWarp= json_msgEngage._cause;
|
|
714
711
|
|
|
715
712
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
716
713
|
const b_changeState= protocolState.canChangeState( new StateEngage(null, {
|
|
@@ -718,7 +715,7 @@ class TwoPhW {
|
|
|
718
715
|
data: { msg, json_msg: json_msgEngage }
|
|
719
716
|
}) );
|
|
720
717
|
|
|
721
|
-
|
|
718
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
|
|
722
719
|
if (! b_changeState)
|
|
723
720
|
return false;
|
|
724
721
|
|
|
@@ -727,11 +724,11 @@ class TwoPhW {
|
|
|
727
724
|
return this.config._callback_msgEngage(msg, json_msgEngage)
|
|
728
725
|
}
|
|
729
726
|
|
|
730
|
-
register_msgAckEngage(msg : t_msg, json_msgAckEngage
|
|
727
|
+
register_msgAckEngage(msg : t_msg, json_msgAckEngage) : boolean
|
|
731
728
|
{
|
|
732
|
-
|
|
729
|
+
logr_.log(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
|
|
733
730
|
|
|
734
|
-
const json_msgWarp= json_msgAckEngage.
|
|
731
|
+
const json_msgWarp= json_msgAckEngage._cause._cause;
|
|
735
732
|
|
|
736
733
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
737
734
|
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
@@ -739,7 +736,7 @@ class TwoPhW {
|
|
|
739
736
|
data: { msg, json_msg: json_msgAckEngage }
|
|
740
737
|
}) );
|
|
741
738
|
|
|
742
|
-
|
|
739
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
|
|
743
740
|
if (! b_changeState)
|
|
744
741
|
return false;
|
|
745
742
|
|
|
@@ -748,27 +745,27 @@ class TwoPhW {
|
|
|
748
745
|
|
|
749
746
|
//-------------------------------------------------------------------------------------------------
|
|
750
747
|
|
|
751
|
-
|
|
748
|
+
handler_json_msgAck(msg : t_msg, json_msgAck) : boolean
|
|
752
749
|
{
|
|
753
|
-
|
|
750
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msgAck: ', json_msgAck]);
|
|
754
751
|
|
|
755
|
-
if (JSON_MsgAckWarp.validate(
|
|
752
|
+
if (JSON_MsgAckWarp.validate(json_msgAck) && this._handler_msgAckWarp(msg, json_msgAck) )
|
|
756
753
|
return true;
|
|
757
754
|
|
|
758
|
-
if (JSON_MsgAckEngage.validate(
|
|
755
|
+
if (JSON_MsgAckEngage.validate(json_msgAck) && this._handler_msgAckEngage(msg, json_msgAck) )
|
|
759
756
|
return true;
|
|
760
757
|
|
|
761
758
|
return false;
|
|
762
759
|
}
|
|
763
760
|
|
|
764
|
-
|
|
761
|
+
handler_json_msgEffect(msg : t_msg, json_msgEffect) : boolean
|
|
765
762
|
{
|
|
766
|
-
|
|
763
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msgEffect: ', json_msgEffect]);
|
|
767
764
|
|
|
768
|
-
if (
|
|
765
|
+
if (JSON_MsgAck.validate(json_msgEffect) && this.handler_json_msgAck(msg, json_msgEffect) )
|
|
769
766
|
return true;
|
|
770
767
|
|
|
771
|
-
if (JSON_MsgEngage.validate(
|
|
768
|
+
if (JSON_MsgEngage.validate(json_msgEffect) && this._handler_msgEngage(msg, json_msgEffect) )
|
|
772
769
|
return true;
|
|
773
770
|
|
|
774
771
|
// if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
|
|
@@ -777,9 +774,9 @@ class TwoPhW {
|
|
|
777
774
|
return false;
|
|
778
775
|
}
|
|
779
776
|
|
|
780
|
-
handler_json_msg(msg : t_msg, json_msg
|
|
777
|
+
handler_json_msg(msg : t_msg, json_msg) : boolean
|
|
781
778
|
{
|
|
782
|
-
|
|
779
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msg: ', json_msg]);
|
|
783
780
|
|
|
784
781
|
if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg) )
|
|
785
782
|
return true;
|
|
@@ -798,9 +795,9 @@ class TwoPhW {
|
|
|
798
795
|
|
|
799
796
|
handler_json(msg : t_msg, json) : boolean
|
|
800
797
|
{
|
|
801
|
-
|
|
798
|
+
logr_.log(l_.HANDLERS, () => ['handler_json: ', json]);
|
|
802
799
|
|
|
803
|
-
if (
|
|
800
|
+
if (JSON_MsgEffect.validate(json) && this.handler_json_msgEffect(msg, json) )
|
|
804
801
|
return true;
|
|
805
802
|
|
|
806
803
|
if (JSON_Msg.validate(json) && this.handler_json_msg(msg, json) )
|
|
@@ -822,7 +819,10 @@ export {
|
|
|
822
819
|
JSON_MsgEngage,
|
|
823
820
|
JSON_MsgAckWarp,
|
|
824
821
|
JSON_MsgAckEngage,
|
|
825
|
-
|
|
822
|
+
logr_ as logr,
|
|
823
|
+
JSON_Msg,
|
|
824
|
+
JSON_MsgEffect,
|
|
825
|
+
JSON_MsgAck,
|
|
826
826
|
// -----
|
|
827
827
|
StateAckEngage,
|
|
828
828
|
StateEngage,
|
package/src/validate-esm.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export const definitions_2PhW = validate18;const schema21 = {"$id":"https://root-interface.se/protocols/2PhW/definitions","$schema":"https://json-schema.org/draft/2019-09/schema","definitions":{"2PhW":{"const":"
|
|
1
|
+
"use strict";export const definitions_2PhW = validate18;const schema21 = {"$id":"https://root-interface.se/protocols/2PhW/definitions","$schema":"https://json-schema.org/draft/2019-09/schema","definitions":{"2PhW":{"const":"2"},"warp_id":{"type":"string"}}};function validate18(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){/*# sourceURL="https://root-interface.se/protocols/2PhW/definitions" */;validate18.errors = null;return true;}validate18.evaluated = {"dynamicProps":false,"dynamicItems":false};export const schema_MsgWarp = validate19;const schema22 = {"$id":"https://root-interface.se/protocols/2PhW/MsgWarp","$schema":"https://json-schema.org/draft/2019-09/schema","type":"object","required":["warp"],"properties":{"warp":{"type":"object","required":["id","user","hyperport","ttl_msec"],"properties":{"id":{"$ref":"definitions#/definitions/warp_id"},"ttl_msec":{"type":"integer"},"instantaneous":{"type":"boolean"}}},"2PhW":{"$ref":"definitions#/definitions/2PhW"}}};const schema23 = {"type":"string"};const schema24 = {"const":"2"};function validate19(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){/*# sourceURL="https://root-interface.se/protocols/2PhW/MsgWarp" */;let vErrors = null;let errors = 0;const evaluated0 = validate19.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}if(errors === 0){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(errors === _errs1){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("2" !== data["2PhW"]){validate19.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "2"},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};export const schema_MsgEngage = validate20;const schema25 = {"$id":"https://root-interface.se/protocols/2PhW/MsgEngage","$schema":"https://json-schema.org/draft/2019-09/schema","type":"object","required":["engage"],"properties":{"engage":{"type":"object","required":["ok","rtt_msec"],"properties":{"ok":{"type":"boolean"},"rtt_msec":{"type":"integer"}}},"2PhW":{"$ref":"definitions#/definitions/2PhW"}}};function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){/*# sourceURL="https://root-interface.se/protocols/2PhW/MsgEngage" */;let vErrors = null;let errors = 0;const evaluated0 = validate20.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}if(errors === 0){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(errors === _errs1){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("2" !== data["2PhW"]){validate20.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "2"},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};
|