@rootintf/protocol-2phw 1.2.4-api.1 → 2.0.3-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/dev.txt +16 -0
- package/dist/ajv-gen-validate.d.cts +1 -0
- package/dist/twoPhW.cjs.js +546 -303
- package/dist/twoPhW.d.ts +22 -22
- package/dist/twoPhW.es.mjs +546 -303
- package/package.json +13 -13
- package/schema/schema_2PhW.json +1 -1
- package/src/twoPhW.ts +84 -114
- package/src/validate-esm.mjs +1 -1
- package/tests/twoPhW-new.spec.mjs +26 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rootintf/protocol-2phw",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.3-api.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/twoPhW.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"homepage": "https://gitlab.com/interface-x/npm-protocol-2PhW.git#readme",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@knev/bitlogr": "^2.0.11",
|
|
31
|
-
"@rootintf/json-msg": "^
|
|
32
|
-
"ajv": "^8.17.1"
|
|
33
|
-
"tslib": "^2.8.1"
|
|
31
|
+
"@rootintf/json-msg": "^2.0.6",
|
|
32
|
+
"ajv": "^8.17.1"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@rollup/plugin-commonjs": "^
|
|
35
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
37
36
|
"@rollup/plugin-json": "^6.1.0",
|
|
38
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
39
|
-
"@rollup/plugin-typescript": "^12.
|
|
37
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
38
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
40
39
|
"@types/ajv": "^0.0.5",
|
|
41
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^24.10.1",
|
|
42
41
|
"ajv-cli": "^5.0.0",
|
|
43
|
-
"del-cli": "^
|
|
44
|
-
"jasmine": "^5.
|
|
45
|
-
"rollup": "^4.
|
|
46
|
-
"
|
|
47
|
-
"
|
|
42
|
+
"del-cli": "^7.0.0",
|
|
43
|
+
"jasmine": "^5.13.0",
|
|
44
|
+
"rollup": "^4.53.3",
|
|
45
|
+
"tslib": "^2.8.1",
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
|
+
"uuid": "^13.0.0"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/schema/schema_2PhW.json
CHANGED
package/src/twoPhW.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
// import { v4 as uuidv4 } from 'uuid'; // uuid is already a dep of JSON_Msg, so why not
|
|
11
11
|
import { LOGR, l_array, l_concat, l_LL } from '@knev/bitlogr';
|
|
12
|
-
import { JSON_Msg,
|
|
12
|
+
import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, l as l_json_msg_ } from '@rootintf/json-msg'
|
|
13
13
|
|
|
14
14
|
import { EventLog, l as l_evtlog_ } from './EventLog-mem.mjs'
|
|
15
15
|
|
|
@@ -26,10 +26,6 @@ interface EventMinimal {
|
|
|
26
26
|
// timeout_id : NodeJS.Timeout | null;
|
|
27
27
|
// };
|
|
28
28
|
|
|
29
|
-
const k_ERROR = -1;
|
|
30
|
-
const k_NOP = 0;
|
|
31
|
-
// const k_HANDLED = 1;
|
|
32
|
-
|
|
33
29
|
const k_TTL= 20000;
|
|
34
30
|
|
|
35
31
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -52,7 +48,7 @@ LOGR_.labels= l_;
|
|
|
52
48
|
|
|
53
49
|
//-------------------------------------------------------------------------------------------------
|
|
54
50
|
|
|
55
|
-
type t_callback = (msg : t_msg, json_msg : JSON_Msg) =>
|
|
51
|
+
type t_callback = (msg : t_msg, json_msg : JSON_Msg) => boolean;
|
|
56
52
|
type t_callback_void = (msg : t_msg, json_msg : JSON_Msg) => void;
|
|
57
53
|
|
|
58
54
|
class Config {
|
|
@@ -66,16 +62,16 @@ class Config {
|
|
|
66
62
|
constructor() {
|
|
67
63
|
// Initialize callbacks as no-op functions
|
|
68
64
|
this._callback_msgWarp = (_msg : t_msg, _json_msg : JSON_Msg) => {
|
|
69
|
-
console.assert(false, 'callback_msgWarp uninitialized'); return
|
|
65
|
+
console.assert(false, 'callback_msgWarp uninitialized'); return false;
|
|
70
66
|
};
|
|
71
67
|
this._callback_msgEngage = (_msg : t_msg, _json_msg : JSON_Msg) => {
|
|
72
|
-
console.assert(false, 'callback_msgEngage uninitialized'); return
|
|
68
|
+
console.assert(false, 'callback_msgEngage uninitialized'); return false;
|
|
73
69
|
};
|
|
74
70
|
this._callback_msgAckWarp = (_msg : t_msg, _json_msg : JSON_Msg) => {
|
|
75
|
-
console.assert(false, 'callback_msgAckWarp uninitialized'); return
|
|
71
|
+
console.assert(false, 'callback_msgAckWarp uninitialized'); return false;
|
|
76
72
|
};
|
|
77
73
|
this._callback_msgAckEngage = (_msg : t_msg, _json_msg : JSON_Msg) => {
|
|
78
|
-
console.assert(false, 'callback_msgAckEngage uninitialized'); return
|
|
74
|
+
console.assert(false, 'callback_msgAckEngage uninitialized'); return false;
|
|
79
75
|
};
|
|
80
76
|
this._callback_msg_sent_expired = (_msg : t_msg, _json_msg : JSON_Msg) => {
|
|
81
77
|
console.assert(false, '_callback_msg_sent_expired uninitialized');
|
|
@@ -117,7 +113,7 @@ class Config {
|
|
|
117
113
|
|
|
118
114
|
//-------------------------------------------------------------------------------------------------
|
|
119
115
|
|
|
120
|
-
let k_VERSION= "
|
|
116
|
+
let k_VERSION= "2";
|
|
121
117
|
|
|
122
118
|
// rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
|
|
123
119
|
// t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
|
|
@@ -134,8 +130,8 @@ function time_ttl_rtt_(ttl_msec: number | undefined, rtt_msec?: number): number
|
|
|
134
130
|
|
|
135
131
|
var JSON_MsgOptions = (function() {
|
|
136
132
|
return {
|
|
137
|
-
|
|
138
|
-
return
|
|
133
|
+
create_with_cause_options : function(msg_cause, options) {
|
|
134
|
+
return JSON_MsgEffect.create_with_msg_merge(msg_cause, {
|
|
139
135
|
options: options,
|
|
140
136
|
"2PhW": k_VERSION
|
|
141
137
|
});
|
|
@@ -190,9 +186,9 @@ var JSON_MsgWarp = (function() {
|
|
|
190
186
|
|
|
191
187
|
var JSON_MsgEngage = (function() {
|
|
192
188
|
return {
|
|
193
|
-
|
|
189
|
+
create_with_Warp : function(json_msgWarp) {
|
|
194
190
|
console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
|
|
195
|
-
return
|
|
191
|
+
return JSON_MsgEffect.create_with_cause_merge(json_msgWarp, {
|
|
196
192
|
engage : {
|
|
197
193
|
"ok" : true,
|
|
198
194
|
"rtt_msec" : Date.now() - Date.parse(json_msgWarp.dt)
|
|
@@ -200,12 +196,12 @@ var JSON_MsgEngage = (function() {
|
|
|
200
196
|
"2PhW": k_VERSION
|
|
201
197
|
});
|
|
202
198
|
},
|
|
203
|
-
validate : function(
|
|
199
|
+
validate : function(json_msgEffect) {
|
|
204
200
|
// if (! JSON_Msg_msg.validate(json))
|
|
205
201
|
// return false;
|
|
206
|
-
if (! JSON_MsgWarp.validate(
|
|
202
|
+
if (! JSON_MsgWarp.validate(json_msgEffect._cause))
|
|
207
203
|
return false;
|
|
208
|
-
if (! schema_MsgEngage_(
|
|
204
|
+
if (! schema_MsgEngage_(json_msgEffect)) {
|
|
209
205
|
log_(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', (schema_MsgEngage_ as any).errors])
|
|
210
206
|
return false;
|
|
211
207
|
}
|
|
@@ -218,23 +214,23 @@ var JSON_MsgAckWarp = (function() {
|
|
|
218
214
|
return {
|
|
219
215
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
220
216
|
// const json_msgAckWarp= structuredClone(json_msgAck);
|
|
221
|
-
// json_msgAckWarp.
|
|
217
|
+
// json_msgAckWarp._cause= _cause;
|
|
222
218
|
// return json_msgAckWarp;
|
|
223
219
|
// }
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
return
|
|
220
|
+
create_with_Warp_Ok : function(json_msgWarp, b_ok= true) {
|
|
221
|
+
const json_msgAck= JSON_MsgAck.create_with_cause_Ok(json_msgWarp, b_ok);
|
|
222
|
+
json_msgAck["2PhW"]= k_VERSION;
|
|
223
|
+
return json_msgAck;
|
|
228
224
|
},
|
|
229
225
|
// create_with_msgExpired : function( json_msgWarp ) {
|
|
230
226
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp )
|
|
231
227
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
232
228
|
// return json_msgAck_msg;
|
|
233
229
|
// },
|
|
234
|
-
validate : function(
|
|
230
|
+
validate : function(json_msgAck) {
|
|
235
231
|
// if (! JSON_MsgAck_msg.validate(json))
|
|
236
232
|
// return false;
|
|
237
|
-
if (! JSON_MsgWarp.validate(
|
|
233
|
+
if (! JSON_MsgWarp.validate(json_msgAck._cause))
|
|
238
234
|
return false;
|
|
239
235
|
return true;
|
|
240
236
|
}
|
|
@@ -245,23 +241,23 @@ var JSON_MsgAckEngage = (function() {
|
|
|
245
241
|
return {
|
|
246
242
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
247
243
|
// const json_msgAckEngage= structuredClone(json_msgAck);
|
|
248
|
-
// json_msgAckEngage.
|
|
244
|
+
// json_msgAckEngage._cause= _cause;
|
|
249
245
|
// return json_msgAckEngage;
|
|
250
246
|
// }
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
return
|
|
247
|
+
create_with_Engage_Ok : function(json_msgEngage, b_ok= true) {
|
|
248
|
+
const json_msgAck= JSON_MsgAck.create_with_cause_Ok(json_msgEngage, b_ok);
|
|
249
|
+
json_msgAck["2PhW"]= k_VERSION;
|
|
250
|
+
return json_msgAck;
|
|
255
251
|
},
|
|
256
252
|
// create_with_msgExpired : function( json_msgEngage ) {
|
|
257
253
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage )
|
|
258
254
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
259
255
|
// return json_msgAck_msg;
|
|
260
256
|
// },
|
|
261
|
-
validate : function(
|
|
257
|
+
validate : function(json_msgAck) {
|
|
262
258
|
// if (! JSON_MsgAck_msg.validate(json_msgAck_msg))
|
|
263
259
|
// return false;
|
|
264
|
-
if (! JSON_MsgEngage.validate(
|
|
260
|
+
if (! JSON_MsgEngage.validate(json_msgAck._cause))
|
|
265
261
|
return false;
|
|
266
262
|
return true;
|
|
267
263
|
}
|
|
@@ -325,7 +321,7 @@ class StateEngage extends StateState {
|
|
|
325
321
|
return false;
|
|
326
322
|
|
|
327
323
|
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
328
|
-
const json_msgWarp= this.json_msgEngage.
|
|
324
|
+
const json_msgWarp= this.json_msgEngage._cause;
|
|
329
325
|
const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
330
326
|
log_(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`])
|
|
331
327
|
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
@@ -346,7 +342,7 @@ class StateAckWarp extends StateState {
|
|
|
346
342
|
if (! this.json_msgAckWarp.ack.ok)
|
|
347
343
|
return false;
|
|
348
344
|
|
|
349
|
-
if (this.json_msgAckWarp.
|
|
345
|
+
if (this.json_msgAckWarp._cause.warp.instantaneous)
|
|
350
346
|
return false;
|
|
351
347
|
|
|
352
348
|
// The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
|
|
@@ -354,7 +350,7 @@ class StateAckWarp extends StateState {
|
|
|
354
350
|
// - Engage: T0 +2TTL +RTT; RTT= STT+STT
|
|
355
351
|
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
356
352
|
// - STT: Date of the Ack minus date of the Warp.
|
|
357
|
-
const timeout_ms= time_ttl_rtt_(this.json_msgAckWarp.
|
|
353
|
+
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);
|
|
358
354
|
log_(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`])
|
|
359
355
|
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
360
356
|
return false;
|
|
@@ -443,7 +439,7 @@ class TwoPhW_EventLog {
|
|
|
443
439
|
|
|
444
440
|
_warp(json_msg) {
|
|
445
441
|
const b_Ack = json_msg.ack !== undefined;
|
|
446
|
-
const json = b_Ack ? json_msg["
|
|
442
|
+
const json = b_Ack ? json_msg["_cause"] : json_msg;
|
|
447
443
|
|
|
448
444
|
if (json.warp) {
|
|
449
445
|
return {
|
|
@@ -454,7 +450,7 @@ class TwoPhW_EventLog {
|
|
|
454
450
|
if (json.engage) {
|
|
455
451
|
return {
|
|
456
452
|
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
|
|
457
|
-
json_msgWarp: json["
|
|
453
|
+
json_msgWarp: json["_cause"]
|
|
458
454
|
};
|
|
459
455
|
}
|
|
460
456
|
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
@@ -540,7 +536,7 @@ class TwoPhW {
|
|
|
540
536
|
|
|
541
537
|
//-------------------------------------------------------------------------------------------------
|
|
542
538
|
|
|
543
|
-
_handler_msgOptions(cfg, msg, json_msgOptions) :
|
|
539
|
+
_handler_msgOptions(cfg, msg, json_msgOptions) : boolean
|
|
544
540
|
{
|
|
545
541
|
log_(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
|
|
546
542
|
|
|
@@ -548,8 +544,8 @@ class TwoPhW {
|
|
|
548
544
|
if (! validate_Options_delay_(json_msgOptions.options))
|
|
549
545
|
return false;
|
|
550
546
|
|
|
551
|
-
if (JSON_MsgWarp.validate(json_msgOptions.
|
|
552
|
-
const json_msgWarp= json_msgOptions.
|
|
547
|
+
if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
|
|
548
|
+
const json_msgWarp= json_msgOptions._cause;
|
|
553
549
|
|
|
554
550
|
const ctx= get_ctx(json_msgWarp.id);
|
|
555
551
|
if (!ctx )
|
|
@@ -571,13 +567,13 @@ class TwoPhW {
|
|
|
571
567
|
}
|
|
572
568
|
*/
|
|
573
569
|
|
|
574
|
-
return
|
|
570
|
+
return false;
|
|
575
571
|
}
|
|
576
572
|
|
|
577
573
|
//-------------------------------------------------------------------------------------------------
|
|
578
574
|
// sender Source (src)
|
|
579
575
|
|
|
580
|
-
register_msgWarp(msg : t_msg, json_msgWarp : JSON_Msg) :
|
|
576
|
+
register_msgWarp(msg : t_msg, json_msgWarp : JSON_Msg) : boolean
|
|
581
577
|
{
|
|
582
578
|
log_(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
|
|
583
579
|
|
|
@@ -589,7 +585,7 @@ class TwoPhW {
|
|
|
589
585
|
|
|
590
586
|
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
|
|
591
587
|
if (! b_changeState)
|
|
592
|
-
return
|
|
588
|
+
return false;
|
|
593
589
|
|
|
594
590
|
const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
595
591
|
const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
|
|
@@ -599,11 +595,11 @@ class TwoPhW {
|
|
|
599
595
|
});
|
|
600
596
|
}
|
|
601
597
|
|
|
602
|
-
_handler_msgAckWarp(msg : t_msg, json_msgAckWarp :
|
|
598
|
+
_handler_msgAckWarp(msg : t_msg, json_msgAckWarp : JSON_MsgAck) : boolean
|
|
603
599
|
{
|
|
604
600
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
|
|
605
601
|
|
|
606
|
-
const json_msgWarp= json_msgAckWarp.
|
|
602
|
+
const json_msgWarp= json_msgAckWarp._cause;
|
|
607
603
|
|
|
608
604
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
609
605
|
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
@@ -613,18 +609,18 @@ class TwoPhW {
|
|
|
613
609
|
|
|
614
610
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
|
|
615
611
|
if (! b_changeState)
|
|
616
|
-
return
|
|
612
|
+
return false;
|
|
617
613
|
|
|
618
614
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
619
615
|
this.eventLog._addEvent(msg, json_msgAckWarp);
|
|
620
616
|
return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
|
|
621
617
|
}
|
|
622
618
|
|
|
623
|
-
register_msgEngage(msg : t_msg, json_msgEngage :
|
|
619
|
+
register_msgEngage(msg : t_msg, json_msgEngage : JSON_MsgEffect) : boolean
|
|
624
620
|
{
|
|
625
621
|
log_(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
|
|
626
622
|
|
|
627
|
-
const json_msgWarp= json_msgEngage.
|
|
623
|
+
const json_msgWarp= json_msgEngage._cause;
|
|
628
624
|
|
|
629
625
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
630
626
|
const b_changeState = protocolState.canChangeState( new StateEngage(null, {
|
|
@@ -634,7 +630,7 @@ class TwoPhW {
|
|
|
634
630
|
|
|
635
631
|
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
|
|
636
632
|
if (! b_changeState)
|
|
637
|
-
return
|
|
633
|
+
return false;
|
|
638
634
|
|
|
639
635
|
const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
|
|
640
636
|
const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
|
|
@@ -644,11 +640,11 @@ class TwoPhW {
|
|
|
644
640
|
});
|
|
645
641
|
}
|
|
646
642
|
|
|
647
|
-
_handler_msgAckEngage(msg : t_msg, json_msgAckEngage :
|
|
643
|
+
_handler_msgAckEngage(msg : t_msg, json_msgAckEngage : JSON_MsgAck) : boolean
|
|
648
644
|
{
|
|
649
645
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
|
|
650
646
|
|
|
651
|
-
const json_msgWarp= json_msgAckEngage.
|
|
647
|
+
const json_msgWarp= json_msgAckEngage._cause._cause;
|
|
652
648
|
|
|
653
649
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
654
650
|
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
@@ -658,7 +654,7 @@ class TwoPhW {
|
|
|
658
654
|
|
|
659
655
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
|
|
660
656
|
if (! b_changeState)
|
|
661
|
-
return
|
|
657
|
+
return false;
|
|
662
658
|
|
|
663
659
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
664
660
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
@@ -668,7 +664,7 @@ class TwoPhW {
|
|
|
668
664
|
//-------------------------------------------------------------------------------------------------
|
|
669
665
|
// receiver Destination (dst)
|
|
670
666
|
|
|
671
|
-
_handler_msgWarp(msg : t_msg, json_msgWarp : JSON_Msg) :
|
|
667
|
+
_handler_msgWarp(msg : t_msg, json_msgWarp : JSON_Msg) : boolean
|
|
672
668
|
{
|
|
673
669
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: ', json_msgWarp]);
|
|
674
670
|
|
|
@@ -680,17 +676,17 @@ class TwoPhW {
|
|
|
680
676
|
|
|
681
677
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
|
|
682
678
|
if (! b_changeState)
|
|
683
|
-
return
|
|
679
|
+
return false;
|
|
684
680
|
|
|
685
681
|
this.eventLog._addEvent(msg, json_msgWarp);
|
|
686
682
|
return this.config._callback_msgWarp(msg, json_msgWarp)
|
|
687
683
|
}
|
|
688
684
|
|
|
689
|
-
register_msgAckWarp(msg: t_msg, json_msgAckWarp :
|
|
685
|
+
register_msgAckWarp(msg: t_msg, json_msgAckWarp : JSON_MsgAck) : boolean
|
|
690
686
|
{
|
|
691
687
|
log_(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
|
|
692
688
|
|
|
693
|
-
const json_msgWarp= json_msgAckWarp.
|
|
689
|
+
const json_msgWarp= json_msgAckWarp._cause;
|
|
694
690
|
|
|
695
691
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
696
692
|
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
@@ -700,7 +696,7 @@ class TwoPhW {
|
|
|
700
696
|
|
|
701
697
|
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
|
|
702
698
|
if (! b_changeState)
|
|
703
|
-
return
|
|
699
|
+
return false;
|
|
704
700
|
|
|
705
701
|
const elapsed_ms= Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
706
702
|
const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
|
|
@@ -710,11 +706,11 @@ class TwoPhW {
|
|
|
710
706
|
});
|
|
711
707
|
}
|
|
712
708
|
|
|
713
|
-
_handler_msgEngage(msg : t_msg, json_msgEngage :
|
|
709
|
+
_handler_msgEngage(msg : t_msg, json_msgEngage : JSON_MsgEffect) : boolean
|
|
714
710
|
{
|
|
715
711
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
|
|
716
712
|
|
|
717
|
-
const json_msgWarp= json_msgEngage
|
|
713
|
+
const json_msgWarp= json_msgEngage._cause;
|
|
718
714
|
|
|
719
715
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
720
716
|
const b_changeState= protocolState.canChangeState( new StateEngage(null, {
|
|
@@ -724,18 +720,18 @@ class TwoPhW {
|
|
|
724
720
|
|
|
725
721
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
|
|
726
722
|
if (! b_changeState)
|
|
727
|
-
return
|
|
723
|
+
return false;
|
|
728
724
|
|
|
729
725
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
730
726
|
this.eventLog._addEvent(msg, json_msgEngage);
|
|
731
727
|
return this.config._callback_msgEngage(msg, json_msgEngage)
|
|
732
728
|
}
|
|
733
729
|
|
|
734
|
-
register_msgAckEngage(msg : t_msg, json_msgAckEngage :
|
|
730
|
+
register_msgAckEngage(msg : t_msg, json_msgAckEngage : JSON_MsgAck) : boolean
|
|
735
731
|
{
|
|
736
732
|
log_(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
|
|
737
733
|
|
|
738
|
-
const json_msgWarp= json_msgAckEngage.
|
|
734
|
+
const json_msgWarp= json_msgAckEngage._cause._cause;
|
|
739
735
|
|
|
740
736
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
741
737
|
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
@@ -745,51 +741,48 @@ class TwoPhW {
|
|
|
745
741
|
|
|
746
742
|
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
|
|
747
743
|
if (! b_changeState)
|
|
748
|
-
return
|
|
744
|
+
return false;
|
|
749
745
|
|
|
750
746
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
751
747
|
}
|
|
752
748
|
|
|
753
749
|
//-------------------------------------------------------------------------------------------------
|
|
754
750
|
|
|
755
|
-
|
|
751
|
+
handler_json_msgAck(msg : t_msg, json_msgAck : JSON_MsgAck) : boolean
|
|
756
752
|
{
|
|
757
|
-
log_(l_.HANDLERS, () => ['
|
|
753
|
+
log_(l_.HANDLERS, () => ['handler_json_msgAck: ', json_msgAck]);
|
|
758
754
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (JSON_MsgAckWarp.validate(json_msgAck_msg) && (ret= this._handler_msgAckWarp(msg, json_msgAck_msg)) )
|
|
762
|
-
return ret;
|
|
755
|
+
if (JSON_MsgAckWarp.validate(json_msgAck) && this._handler_msgAckWarp(msg, json_msgAck) )
|
|
756
|
+
return true;
|
|
763
757
|
|
|
764
|
-
if (JSON_MsgAckEngage.validate(
|
|
765
|
-
return
|
|
758
|
+
if (JSON_MsgAckEngage.validate(json_msgAck) && this._handler_msgAckEngage(msg, json_msgAck) )
|
|
759
|
+
return true;
|
|
766
760
|
|
|
767
|
-
return
|
|
761
|
+
return false;
|
|
768
762
|
}
|
|
769
763
|
|
|
770
|
-
|
|
764
|
+
handler_json_msgEffect(msg : t_msg, json_msgEffect : JSON_MsgEffect) : boolean
|
|
771
765
|
{
|
|
772
|
-
log_(l_.HANDLERS, () => ['
|
|
766
|
+
log_(l_.HANDLERS, () => ['handler_json_msgEffect: ', json_msgEffect]);
|
|
773
767
|
|
|
774
|
-
|
|
768
|
+
if (JSON_MsgAck.validate(json_msgEffect) && this.handler_json_msgAck(msg, json_msgEffect) )
|
|
769
|
+
return true;
|
|
775
770
|
|
|
776
|
-
if (JSON_MsgEngage.validate(
|
|
777
|
-
return
|
|
771
|
+
if (JSON_MsgEngage.validate(json_msgEffect) && this._handler_msgEngage(msg, json_msgEffect) )
|
|
772
|
+
return true;
|
|
778
773
|
|
|
779
774
|
// if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
|
|
780
775
|
// return true;
|
|
781
776
|
|
|
782
|
-
return
|
|
777
|
+
return false;
|
|
783
778
|
}
|
|
784
779
|
|
|
785
|
-
handler_json_msg(msg : t_msg, json_msg : JSON_Msg) :
|
|
780
|
+
handler_json_msg(msg : t_msg, json_msg : JSON_Msg) : boolean
|
|
786
781
|
{
|
|
787
782
|
log_(l_.HANDLERS, () => ['handler_json_msg: ', json_msg]);
|
|
788
783
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
if (JSON_MsgWarp.validate(json_msg) && (ret= this._handler_msgWarp(msg, json_msg)) )
|
|
792
|
-
return ret;
|
|
784
|
+
if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg) )
|
|
785
|
+
return true;
|
|
793
786
|
|
|
794
787
|
// https://attacomsian.com/blog/javascript-iterate-objects
|
|
795
788
|
// Object.keys(json_msg).forEach((key, index) => {
|
|
@@ -800,43 +793,20 @@ class TwoPhW {
|
|
|
800
793
|
// console.log(`${key}: ${json_msg[key]}`);
|
|
801
794
|
// });
|
|
802
795
|
|
|
803
|
-
return
|
|
796
|
+
return false;
|
|
804
797
|
}
|
|
805
798
|
|
|
806
|
-
handler_json(msg : t_msg, json) :
|
|
799
|
+
handler_json(msg : t_msg, json) : boolean
|
|
807
800
|
{
|
|
808
|
-
|
|
809
|
-
{
|
|
810
|
-
if (JSON_Msg_msg.validate(json))
|
|
811
|
-
{
|
|
812
|
-
if (JSON_MsgAck_msg.validate(json))
|
|
813
|
-
{
|
|
814
|
-
let ret : number;
|
|
815
|
-
|
|
816
|
-
if (JSON_MsgAckWarp.validate(json) && (ret= this._handler_msgAckWarp(msg, json)) )
|
|
817
|
-
return ret;
|
|
818
|
-
|
|
819
|
-
if (JSON_MsgAckEngage.validate(json) && (ret= this._handler_msgAckEngage(msg, json)) )
|
|
820
|
-
return ret;
|
|
821
|
-
|
|
822
|
-
return k_NOP;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
let ret : number;
|
|
826
|
-
if (JSON_MsgEngage.validate(json) && (ret= this._handler_msgEngage(msg, json)) )
|
|
827
|
-
return ret;
|
|
828
|
-
|
|
829
|
-
return k_NOP;
|
|
830
|
-
}
|
|
801
|
+
log_(l_.HANDLERS, () => ['handler_json: ', json]);
|
|
831
802
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
return ret;
|
|
803
|
+
if (JSON_MsgEffect.validate(json) && this.handler_json_msgEffect(msg, json) )
|
|
804
|
+
return true;
|
|
835
805
|
|
|
836
|
-
|
|
837
|
-
|
|
806
|
+
if (JSON_Msg.validate(json) && this.handler_json_msg(msg, json) )
|
|
807
|
+
return true;
|
|
838
808
|
|
|
839
|
-
return
|
|
809
|
+
return false;
|
|
840
810
|
}
|
|
841
811
|
|
|
842
812
|
};
|
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};
|