@rootintf/protocol-2phw 1.3.3-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/dist/twoPhW.cjs.js +234 -127
- package/dist/twoPhW.d.ts +16 -16
- package/dist/twoPhW.es.mjs +234 -127
- package/package.json +5 -5
- package/schema/schema_2PhW.json +1 -1
- package/src/twoPhW.ts +51 -51
- package/src/validate-esm.mjs +1 -1
- package/tests/twoPhW-new.spec.mjs +26 -26
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
|
|
|
@@ -113,7 +113,7 @@ class Config {
|
|
|
113
113
|
|
|
114
114
|
//-------------------------------------------------------------------------------------------------
|
|
115
115
|
|
|
116
|
-
let k_VERSION= "
|
|
116
|
+
let k_VERSION= "2";
|
|
117
117
|
|
|
118
118
|
// rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
|
|
119
119
|
// t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
|
|
@@ -130,8 +130,8 @@ function time_ttl_rtt_(ttl_msec: number | undefined, rtt_msec?: number): number
|
|
|
130
130
|
|
|
131
131
|
var JSON_MsgOptions = (function() {
|
|
132
132
|
return {
|
|
133
|
-
|
|
134
|
-
return
|
|
133
|
+
create_with_cause_options : function(msg_cause, options) {
|
|
134
|
+
return JSON_MsgEffect.create_with_msg_merge(msg_cause, {
|
|
135
135
|
options: options,
|
|
136
136
|
"2PhW": k_VERSION
|
|
137
137
|
});
|
|
@@ -186,9 +186,9 @@ var JSON_MsgWarp = (function() {
|
|
|
186
186
|
|
|
187
187
|
var JSON_MsgEngage = (function() {
|
|
188
188
|
return {
|
|
189
|
-
|
|
189
|
+
create_with_Warp : function(json_msgWarp) {
|
|
190
190
|
console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
|
|
191
|
-
return
|
|
191
|
+
return JSON_MsgEffect.create_with_cause_merge(json_msgWarp, {
|
|
192
192
|
engage : {
|
|
193
193
|
"ok" : true,
|
|
194
194
|
"rtt_msec" : Date.now() - Date.parse(json_msgWarp.dt)
|
|
@@ -196,12 +196,12 @@ var JSON_MsgEngage = (function() {
|
|
|
196
196
|
"2PhW": k_VERSION
|
|
197
197
|
});
|
|
198
198
|
},
|
|
199
|
-
validate : function(
|
|
199
|
+
validate : function(json_msgEffect) {
|
|
200
200
|
// if (! JSON_Msg_msg.validate(json))
|
|
201
201
|
// return false;
|
|
202
|
-
if (! JSON_MsgWarp.validate(
|
|
202
|
+
if (! JSON_MsgWarp.validate(json_msgEffect._cause))
|
|
203
203
|
return false;
|
|
204
|
-
if (! schema_MsgEngage_(
|
|
204
|
+
if (! schema_MsgEngage_(json_msgEffect)) {
|
|
205
205
|
log_(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', (schema_MsgEngage_ as any).errors])
|
|
206
206
|
return false;
|
|
207
207
|
}
|
|
@@ -214,23 +214,23 @@ var JSON_MsgAckWarp = (function() {
|
|
|
214
214
|
return {
|
|
215
215
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
216
216
|
// const json_msgAckWarp= structuredClone(json_msgAck);
|
|
217
|
-
// json_msgAckWarp.
|
|
217
|
+
// json_msgAckWarp._cause= _cause;
|
|
218
218
|
// return json_msgAckWarp;
|
|
219
219
|
// }
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
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;
|
|
224
224
|
},
|
|
225
225
|
// create_with_msgExpired : function( json_msgWarp ) {
|
|
226
226
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp )
|
|
227
227
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
228
228
|
// return json_msgAck_msg;
|
|
229
229
|
// },
|
|
230
|
-
validate : function(
|
|
230
|
+
validate : function(json_msgAck) {
|
|
231
231
|
// if (! JSON_MsgAck_msg.validate(json))
|
|
232
232
|
// return false;
|
|
233
|
-
if (! JSON_MsgWarp.validate(
|
|
233
|
+
if (! JSON_MsgWarp.validate(json_msgAck._cause))
|
|
234
234
|
return false;
|
|
235
235
|
return true;
|
|
236
236
|
}
|
|
@@ -241,23 +241,23 @@ var JSON_MsgAckEngage = (function() {
|
|
|
241
241
|
return {
|
|
242
242
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
243
243
|
// const json_msgAckEngage= structuredClone(json_msgAck);
|
|
244
|
-
// json_msgAckEngage.
|
|
244
|
+
// json_msgAckEngage._cause= _cause;
|
|
245
245
|
// return json_msgAckEngage;
|
|
246
246
|
// }
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
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;
|
|
251
251
|
},
|
|
252
252
|
// create_with_msgExpired : function( json_msgEngage ) {
|
|
253
253
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage )
|
|
254
254
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
255
255
|
// return json_msgAck_msg;
|
|
256
256
|
// },
|
|
257
|
-
validate : function(
|
|
257
|
+
validate : function(json_msgAck) {
|
|
258
258
|
// if (! JSON_MsgAck_msg.validate(json_msgAck_msg))
|
|
259
259
|
// return false;
|
|
260
|
-
if (! JSON_MsgEngage.validate(
|
|
260
|
+
if (! JSON_MsgEngage.validate(json_msgAck._cause))
|
|
261
261
|
return false;
|
|
262
262
|
return true;
|
|
263
263
|
}
|
|
@@ -321,7 +321,7 @@ class StateEngage extends StateState {
|
|
|
321
321
|
return false;
|
|
322
322
|
|
|
323
323
|
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
324
|
-
const json_msgWarp= this.json_msgEngage.
|
|
324
|
+
const json_msgWarp= this.json_msgEngage._cause;
|
|
325
325
|
const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
326
326
|
log_(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`])
|
|
327
327
|
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
@@ -342,7 +342,7 @@ class StateAckWarp extends StateState {
|
|
|
342
342
|
if (! this.json_msgAckWarp.ack.ok)
|
|
343
343
|
return false;
|
|
344
344
|
|
|
345
|
-
if (this.json_msgAckWarp.
|
|
345
|
+
if (this.json_msgAckWarp._cause.warp.instantaneous)
|
|
346
346
|
return false;
|
|
347
347
|
|
|
348
348
|
// The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
|
|
@@ -350,7 +350,7 @@ class StateAckWarp extends StateState {
|
|
|
350
350
|
// - Engage: T0 +2TTL +RTT; RTT= STT+STT
|
|
351
351
|
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
352
352
|
// - STT: Date of the Ack minus date of the Warp.
|
|
353
|
-
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);
|
|
354
354
|
log_(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`])
|
|
355
355
|
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
356
356
|
return false;
|
|
@@ -439,7 +439,7 @@ class TwoPhW_EventLog {
|
|
|
439
439
|
|
|
440
440
|
_warp(json_msg) {
|
|
441
441
|
const b_Ack = json_msg.ack !== undefined;
|
|
442
|
-
const json = b_Ack ? json_msg["
|
|
442
|
+
const json = b_Ack ? json_msg["_cause"] : json_msg;
|
|
443
443
|
|
|
444
444
|
if (json.warp) {
|
|
445
445
|
return {
|
|
@@ -450,7 +450,7 @@ class TwoPhW_EventLog {
|
|
|
450
450
|
if (json.engage) {
|
|
451
451
|
return {
|
|
452
452
|
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
|
|
453
|
-
json_msgWarp: json["
|
|
453
|
+
json_msgWarp: json["_cause"]
|
|
454
454
|
};
|
|
455
455
|
}
|
|
456
456
|
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
@@ -544,8 +544,8 @@ class TwoPhW {
|
|
|
544
544
|
if (! validate_Options_delay_(json_msgOptions.options))
|
|
545
545
|
return false;
|
|
546
546
|
|
|
547
|
-
if (JSON_MsgWarp.validate(json_msgOptions.
|
|
548
|
-
const json_msgWarp= json_msgOptions.
|
|
547
|
+
if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
|
|
548
|
+
const json_msgWarp= json_msgOptions._cause;
|
|
549
549
|
|
|
550
550
|
const ctx= get_ctx(json_msgWarp.id);
|
|
551
551
|
if (!ctx )
|
|
@@ -595,11 +595,11 @@ class TwoPhW {
|
|
|
595
595
|
});
|
|
596
596
|
}
|
|
597
597
|
|
|
598
|
-
_handler_msgAckWarp(msg : t_msg, json_msgAckWarp :
|
|
598
|
+
_handler_msgAckWarp(msg : t_msg, json_msgAckWarp : JSON_MsgAck) : boolean
|
|
599
599
|
{
|
|
600
600
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
|
|
601
601
|
|
|
602
|
-
const json_msgWarp= json_msgAckWarp.
|
|
602
|
+
const json_msgWarp= json_msgAckWarp._cause;
|
|
603
603
|
|
|
604
604
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
605
605
|
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
@@ -616,11 +616,11 @@ class TwoPhW {
|
|
|
616
616
|
return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
|
|
617
617
|
}
|
|
618
618
|
|
|
619
|
-
register_msgEngage(msg : t_msg, json_msgEngage :
|
|
619
|
+
register_msgEngage(msg : t_msg, json_msgEngage : JSON_MsgEffect) : boolean
|
|
620
620
|
{
|
|
621
621
|
log_(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
|
|
622
622
|
|
|
623
|
-
const json_msgWarp= json_msgEngage.
|
|
623
|
+
const json_msgWarp= json_msgEngage._cause;
|
|
624
624
|
|
|
625
625
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
626
626
|
const b_changeState = protocolState.canChangeState( new StateEngage(null, {
|
|
@@ -640,11 +640,11 @@ class TwoPhW {
|
|
|
640
640
|
});
|
|
641
641
|
}
|
|
642
642
|
|
|
643
|
-
_handler_msgAckEngage(msg : t_msg, json_msgAckEngage :
|
|
643
|
+
_handler_msgAckEngage(msg : t_msg, json_msgAckEngage : JSON_MsgAck) : boolean
|
|
644
644
|
{
|
|
645
645
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
|
|
646
646
|
|
|
647
|
-
const json_msgWarp= json_msgAckEngage.
|
|
647
|
+
const json_msgWarp= json_msgAckEngage._cause._cause;
|
|
648
648
|
|
|
649
649
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
650
650
|
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
@@ -682,11 +682,11 @@ class TwoPhW {
|
|
|
682
682
|
return this.config._callback_msgWarp(msg, json_msgWarp)
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
-
register_msgAckWarp(msg: t_msg, json_msgAckWarp :
|
|
685
|
+
register_msgAckWarp(msg: t_msg, json_msgAckWarp : JSON_MsgAck) : boolean
|
|
686
686
|
{
|
|
687
687
|
log_(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
|
|
688
688
|
|
|
689
|
-
const json_msgWarp= json_msgAckWarp.
|
|
689
|
+
const json_msgWarp= json_msgAckWarp._cause;
|
|
690
690
|
|
|
691
691
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
692
692
|
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
@@ -706,11 +706,11 @@ class TwoPhW {
|
|
|
706
706
|
});
|
|
707
707
|
}
|
|
708
708
|
|
|
709
|
-
_handler_msgEngage(msg : t_msg, json_msgEngage :
|
|
709
|
+
_handler_msgEngage(msg : t_msg, json_msgEngage : JSON_MsgEffect) : boolean
|
|
710
710
|
{
|
|
711
711
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
|
|
712
712
|
|
|
713
|
-
const json_msgWarp= json_msgEngage
|
|
713
|
+
const json_msgWarp= json_msgEngage._cause;
|
|
714
714
|
|
|
715
715
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
716
716
|
const b_changeState= protocolState.canChangeState( new StateEngage(null, {
|
|
@@ -727,11 +727,11 @@ class TwoPhW {
|
|
|
727
727
|
return this.config._callback_msgEngage(msg, json_msgEngage)
|
|
728
728
|
}
|
|
729
729
|
|
|
730
|
-
register_msgAckEngage(msg : t_msg, json_msgAckEngage :
|
|
730
|
+
register_msgAckEngage(msg : t_msg, json_msgAckEngage : JSON_MsgAck) : boolean
|
|
731
731
|
{
|
|
732
732
|
log_(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
|
|
733
733
|
|
|
734
|
-
const json_msgWarp= json_msgAckEngage.
|
|
734
|
+
const json_msgWarp= json_msgAckEngage._cause._cause;
|
|
735
735
|
|
|
736
736
|
const protocolState= this.eventLog.traverse_State(json_msgWarp);
|
|
737
737
|
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
@@ -748,27 +748,27 @@ class TwoPhW {
|
|
|
748
748
|
|
|
749
749
|
//-------------------------------------------------------------------------------------------------
|
|
750
750
|
|
|
751
|
-
|
|
751
|
+
handler_json_msgAck(msg : t_msg, json_msgAck : JSON_MsgAck) : boolean
|
|
752
752
|
{
|
|
753
|
-
log_(l_.HANDLERS, () => ['
|
|
753
|
+
log_(l_.HANDLERS, () => ['handler_json_msgAck: ', json_msgAck]);
|
|
754
754
|
|
|
755
|
-
if (JSON_MsgAckWarp.validate(
|
|
755
|
+
if (JSON_MsgAckWarp.validate(json_msgAck) && this._handler_msgAckWarp(msg, json_msgAck) )
|
|
756
756
|
return true;
|
|
757
757
|
|
|
758
|
-
if (JSON_MsgAckEngage.validate(
|
|
758
|
+
if (JSON_MsgAckEngage.validate(json_msgAck) && this._handler_msgAckEngage(msg, json_msgAck) )
|
|
759
759
|
return true;
|
|
760
760
|
|
|
761
761
|
return false;
|
|
762
762
|
}
|
|
763
763
|
|
|
764
|
-
|
|
764
|
+
handler_json_msgEffect(msg : t_msg, json_msgEffect : JSON_MsgEffect) : boolean
|
|
765
765
|
{
|
|
766
|
-
log_(l_.HANDLERS, () => ['
|
|
766
|
+
log_(l_.HANDLERS, () => ['handler_json_msgEffect: ', json_msgEffect]);
|
|
767
767
|
|
|
768
|
-
if (
|
|
768
|
+
if (JSON_MsgAck.validate(json_msgEffect) && this.handler_json_msgAck(msg, json_msgEffect) )
|
|
769
769
|
return true;
|
|
770
770
|
|
|
771
|
-
if (JSON_MsgEngage.validate(
|
|
771
|
+
if (JSON_MsgEngage.validate(json_msgEffect) && this._handler_msgEngage(msg, json_msgEffect) )
|
|
772
772
|
return true;
|
|
773
773
|
|
|
774
774
|
// if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
|
|
@@ -800,7 +800,7 @@ class TwoPhW {
|
|
|
800
800
|
{
|
|
801
801
|
log_(l_.HANDLERS, () => ['handler_json: ', json]);
|
|
802
802
|
|
|
803
|
-
if (
|
|
803
|
+
if (JSON_MsgEffect.validate(json) && this.handler_json_msgEffect(msg, json) )
|
|
804
804
|
return true;
|
|
805
805
|
|
|
806
806
|
if (JSON_Msg.validate(json) && this.handler_json_msg(msg, json) )
|
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};
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
t_ttl_rtt,
|
|
8
8
|
TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage, l as l_twoPhW_,
|
|
9
9
|
} from '../dist/twoPhW.es.mjs';
|
|
10
|
-
import { JSON_Msg,
|
|
10
|
+
import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck } from '@rootintf/json-msg'
|
|
11
11
|
|
|
12
|
-
const k_VERSION= "
|
|
12
|
+
const k_VERSION= "2";
|
|
13
13
|
|
|
14
14
|
const kstr_REFERER_ = 'twoPhW-new.spec';
|
|
15
15
|
const karr_referer_src = [kstr_REFERER_, uuidv4()];
|
|
@@ -37,12 +37,12 @@ describe("Initialization", function () {
|
|
|
37
37
|
it("json_msgWarp", function () {
|
|
38
38
|
const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
|
|
39
39
|
|
|
40
|
-
const json_msgAckWarp_obj= JSON_MsgAckWarp.
|
|
41
|
-
const json_msgAckWarp_str= JSON_MsgAckWarp.
|
|
40
|
+
const json_msgAckWarp_obj= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp, true);
|
|
41
|
+
const json_msgAckWarp_str= JSON_MsgAckWarp.create_with_Warp_Ok( JSON.stringify(json_msgWarp), true);
|
|
42
42
|
|
|
43
|
-
expect(typeof json_msgAckWarp_obj.
|
|
43
|
+
expect(typeof json_msgAckWarp_obj._cause.warp.id === 'string').toBe(true);
|
|
44
44
|
expect(() => {
|
|
45
|
-
json_msgAckWarp_str.
|
|
45
|
+
json_msgAckWarp_str._cause.warp.id;
|
|
46
46
|
}).toThrowError(TypeError, "Cannot read properties of undefined (reading 'id')");
|
|
47
47
|
|
|
48
48
|
expect(() => {
|
|
@@ -78,7 +78,7 @@ describe("Validation", function () {
|
|
|
78
78
|
"ok" : true,
|
|
79
79
|
"rtt_msec" : 6000
|
|
80
80
|
},
|
|
81
|
-
"
|
|
81
|
+
"_cause" : json_msgWarp_,
|
|
82
82
|
"2PhW": k_VERSION
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -89,7 +89,7 @@ describe("Validation", function () {
|
|
|
89
89
|
ack: {
|
|
90
90
|
"ok" : true,
|
|
91
91
|
},
|
|
92
|
-
"
|
|
92
|
+
"_cause" : JSON.stringify( json_msgWarp_ ),
|
|
93
93
|
"2PhW": k_VERSION
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -100,7 +100,7 @@ describe("Validation", function () {
|
|
|
100
100
|
ack: {
|
|
101
101
|
"ok" : true,
|
|
102
102
|
},
|
|
103
|
-
"
|
|
103
|
+
"_cause" : json_msgWarp_,
|
|
104
104
|
"2PhW": k_VERSION
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -111,7 +111,7 @@ describe("Validation", function () {
|
|
|
111
111
|
ack: {
|
|
112
112
|
"ok" : false,
|
|
113
113
|
},
|
|
114
|
-
"
|
|
114
|
+
"_cause" : json_msgEngage_,
|
|
115
115
|
"2PhW": k_VERSION
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -124,7 +124,7 @@ describe("Validation", function () {
|
|
|
124
124
|
ttl_msec_incr : [ 20000, 4000 ],
|
|
125
125
|
reason : "it is taking too long"
|
|
126
126
|
},
|
|
127
|
-
"
|
|
127
|
+
"_cause" : json_msgWarp_,
|
|
128
128
|
"2PhW": k_VERSION
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -181,10 +181,10 @@ describe('2PhW protocol', () => {
|
|
|
181
181
|
const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
|
|
182
182
|
json_msgWarp.referer= karr_referer_src;
|
|
183
183
|
|
|
184
|
-
const json_msgEngage= JSON_MsgEngage.
|
|
184
|
+
const json_msgEngage= JSON_MsgEngage.create_with_Warp(json_msgWarp);
|
|
185
185
|
json_msgEngage.referer= karr_referer_src;
|
|
186
186
|
|
|
187
|
-
const json_msgNackWarp= JSON_MsgAckWarp.
|
|
187
|
+
const json_msgNackWarp= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp, false);
|
|
188
188
|
json_msgNackWarp.referer= karr_referer_dst;
|
|
189
189
|
const str_msgNackWarp = JSON.stringify(json_msgNackWarp);
|
|
190
190
|
twoPhW.eventLog._addEvent(str_msgNackWarp, json_msgNackWarp)
|
|
@@ -287,7 +287,7 @@ describe('2PhW protocol', () => {
|
|
|
287
287
|
});
|
|
288
288
|
|
|
289
289
|
it('receive premature JSON_MsgEngage', () => {
|
|
290
|
-
const json_msgEngage_recvd= JSON_MsgEngage.
|
|
290
|
+
const json_msgEngage_recvd= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
291
291
|
json_msgEngage_recvd.referer= karr_referer_src;
|
|
292
292
|
|
|
293
293
|
twoPhW.handler_json(json_msgEngage_recvd, json_msgEngage_recvd);
|
|
@@ -319,11 +319,11 @@ describe('2PhW protocol', () => {
|
|
|
319
319
|
let str_msgNackWarp_dst;
|
|
320
320
|
|
|
321
321
|
beforeEach(() => {
|
|
322
|
-
json_msgAckWarp_dst= JSON_MsgAckWarp.
|
|
322
|
+
json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, true);
|
|
323
323
|
json_msgAckWarp_dst.referer= karr_referer_dst;
|
|
324
324
|
str_msgAckWarp_dst = JSON.stringify(json_msgAckWarp_dst);
|
|
325
325
|
|
|
326
|
-
json_msgNackWarp_dst= JSON_MsgAckWarp.
|
|
326
|
+
json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, false);
|
|
327
327
|
json_msgNackWarp_dst.referer= karr_referer_dst;
|
|
328
328
|
str_msgNackWarp_dst = JSON.stringify(str_msgNackWarp_dst);
|
|
329
329
|
|
|
@@ -359,7 +359,7 @@ describe('2PhW protocol', () => {
|
|
|
359
359
|
expect(eventLog.arr_events[1].data).toEqual({ msg: str_msgAckWarp_dst, json_msg : json_msgAckWarp_dst });
|
|
360
360
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
361
361
|
|
|
362
|
-
const json_msgEngage_src= JSON_MsgEngage.
|
|
362
|
+
const json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
363
363
|
json_msgEngage_src.referer= karr_referer_src;
|
|
364
364
|
|
|
365
365
|
twoPhW.handler_json(json_msgEngage_src, json_msgEngage_src);
|
|
@@ -373,7 +373,7 @@ describe('2PhW protocol', () => {
|
|
|
373
373
|
expect(eventLog.arr_events[1].data).toEqual({ msg : str_msgNackWarp_dst, json_msg : json_msgNackWarp_dst });
|
|
374
374
|
|
|
375
375
|
jasmine.clock().tick(STT_MSEC_1000); // 2000, STT_MSEC_1000 *2= RTT
|
|
376
|
-
const json_msgEngage_src= JSON_MsgEngage.
|
|
376
|
+
const json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
377
377
|
json_msgEngage_src.referer= karr_referer_src;
|
|
378
378
|
|
|
379
379
|
jasmine.clock().tick(STT_MSEC_1000); // 3000, STT_MSEC_1000 *3
|
|
@@ -404,7 +404,7 @@ describe('2PhW protocol', () => {
|
|
|
404
404
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
405
405
|
|
|
406
406
|
jasmine.clock().tick(STT_MSEC_1000); // STT_MSEC_1000 *2= RTT
|
|
407
|
-
json_msgEngage_src= JSON_MsgEngage.
|
|
407
|
+
json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
408
408
|
json_msgEngage_src.referer= karr_referer_src;
|
|
409
409
|
str_msgEngage_src = JSON.stringify(json_msgEngage_src);
|
|
410
410
|
|
|
@@ -438,7 +438,7 @@ describe('2PhW protocol', () => {
|
|
|
438
438
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
439
439
|
|
|
440
440
|
jasmine.clock().tick(STT_MSEC_1000); // 4000, STT_MSEC_1000 *4
|
|
441
|
-
const json_msgNackEngage_dst= JSON_MsgAckEngage.
|
|
441
|
+
const json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, false);
|
|
442
442
|
json_msgNackEngage_dst.referer= karr_referer_dst;
|
|
443
443
|
twoPhW.register_msgAckEngage(JSON.stringify(json_msgNackEngage_dst), json_msgNackEngage_dst)
|
|
444
444
|
expect(eventLog.arr_events.length).toBe(2);
|
|
@@ -466,7 +466,7 @@ describe('2PhW protocol', () => {
|
|
|
466
466
|
expect(eventLog.arr_events[2].data).toEqual({ msg: str_msgEngage_src, json_msg : json_msgEngage_src });
|
|
467
467
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
468
468
|
|
|
469
|
-
json_msgNackEngage_dst= JSON_MsgAckEngage.
|
|
469
|
+
json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, false);
|
|
470
470
|
json_msgNackEngage_dst.referer= karr_referer_dst;
|
|
471
471
|
str_msgNackEngage_dst = JSON.stringify(json_msgNackEngage_dst);
|
|
472
472
|
|
|
@@ -645,17 +645,17 @@ describe('2PhW protocol', () => {
|
|
|
645
645
|
expect(Date.now()-T0).toBe(0);
|
|
646
646
|
|
|
647
647
|
jasmine.clock().tick(STT_MSEC_1000); // 1000
|
|
648
|
-
json_msgAckWarp_dst= JSON_MsgAckWarp.
|
|
648
|
+
json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, true);
|
|
649
649
|
json_msgAckWarp_dst.referer= karr_referer_dst;
|
|
650
650
|
str_msgAckWarp_dst = JSON.stringify(json_msgAckWarp_dst);
|
|
651
651
|
|
|
652
|
-
json_msgNackWarp_dst= JSON_MsgAckWarp.
|
|
652
|
+
json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, false);
|
|
653
653
|
json_msgNackWarp_dst.referer= karr_referer_dst;
|
|
654
654
|
str_msgNackWarp_dst = JSON.stringify(json_msgNackWarp_dst);
|
|
655
655
|
|
|
656
656
|
jasmine.clock().tick(STT_MSEC_1000); // 2000
|
|
657
657
|
|
|
658
|
-
json_msgEngage_src= JSON_MsgEngage.
|
|
658
|
+
json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
659
659
|
json_msgEngage_src.referer= karr_referer_src;
|
|
660
660
|
str_msgEngage_src = JSON.stringify(json_msgEngage_src);
|
|
661
661
|
|
|
@@ -694,7 +694,7 @@ describe('2PhW protocol', () => {
|
|
|
694
694
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
695
695
|
|
|
696
696
|
jasmine.clock().tick(STT_MSEC_1000); // 3000
|
|
697
|
-
const json_msgAckEngage_recv= JSON_MsgAckEngage.
|
|
697
|
+
const json_msgAckEngage_recv= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, true);
|
|
698
698
|
json_msgAckEngage_recv.referer= karr_referer_dst;
|
|
699
699
|
|
|
700
700
|
jasmine.clock().tick(STT_MSEC_1000); // 4000
|
|
@@ -772,7 +772,7 @@ describe('2PhW protocol', () => {
|
|
|
772
772
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
773
773
|
|
|
774
774
|
jasmine.clock().tick(STT_MSEC_1000); // 3000
|
|
775
|
-
json_msgAckEngage_dst= JSON_MsgAckEngage.
|
|
775
|
+
json_msgAckEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, true);
|
|
776
776
|
json_msgAckEngage_dst.referer= karr_referer_dst;
|
|
777
777
|
str_msgAckEngage_dst = JSON.stringify(json_msgAckEngage_dst);
|
|
778
778
|
|