@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.
@@ -1,8 +1,13 @@
1
1
 
2
- import { EventLog } from '../src/EventLog-mem.mjs';
2
+ import { EventLog, logr as logr_ } from '../src/EventLog-mem.mjs';
3
3
  import { LOGR } from '@knev/bitlogr';
4
4
 
5
+ //-------------------------------------------------------------------------------------------------
6
+
5
7
  const LOGR_= LOGR.get_instance();
8
+ const l_= logr_.l;
9
+
10
+ //-------------------------------------------------------------------------------------------------
6
11
 
7
12
  // Helper to mock Date.now for consistent timestamps
8
13
  function mockDateNow(fixedTimestamp) {
@@ -168,9 +173,9 @@ describe('EventLog', () => {
168
173
  });
169
174
 
170
175
  it('should trigger all timeouts after specified time', () => {
171
- LOGR_.toggled= {
172
- // EVENTS : 1
173
- }
176
+ LOGR_.toggle(l_, {
177
+ EVENTS : true
178
+ });
174
179
  const cb1 = jasmine.createSpy('callback1');
175
180
  const cb2 = jasmine.createSpy('callback2');
176
181
  eventLog.addEvent('test1', 'id1', { value: 1 }, 5000, cb1);
@@ -2,14 +2,18 @@
2
2
  import { v4 as uuidv4 } from 'uuid';
3
3
  import { LOGR, l_concat } from '@knev/bitlogr';
4
4
  import {
5
- StateAckEngage, StateEngage, StateAckWarp, StateWarp, StateInitialState, StateINVALID,
6
- EventLog,
7
- t_ttl_rtt,
8
- TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage, l as l_twoPhW_,
9
- } from '../dist/twoPhW.es.mjs';
10
- import { JSON_Msg, JSON_Msg_msg, JSON_MsgAck_msg } from '@rootintf/json-msg'
5
+ StateAckEngage, StateEngage, StateAckWarp, StateWarp, StateInitialState, StateINVALID,
6
+ EventLog,
7
+ t_ttl_rtt,
8
+ TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage,
9
+ logr as logr_,
10
+ JSON_Msg, JSON_MsgEffect, JSON_MsgAck
11
+ } from '../dist/twoPhW.es.mjs';
11
12
 
12
- const k_VERSION= "1";
13
+ // this leads to two copies of l_ from '@rootintf/json-msg'; one copy from twoPhW
14
+ // import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, l as l_json_msg } from '@rootintf/json-msg'
15
+
16
+ const k_VERSION= "2";
13
17
 
14
18
  const kstr_REFERER_ = 'twoPhW-new.spec';
15
19
  const karr_referer_src = [kstr_REFERER_, uuidv4()];
@@ -22,14 +26,13 @@ const RTT_MSEC_2000= 2000;
22
26
 
23
27
  //-------------------------------------------------------------------------------------------------
24
28
 
25
- const LOGR_= LOGR.get_instance()
29
+ const LOGR_= LOGR.get_instance();
30
+ const l_= logr_.l;
26
31
 
27
- const l_ = l_concat(l_twoPhW_, ['LOG_TEST']);
28
- LOGR_.labels= l_;
29
- LOGR_.toggled= {
30
- LOG_TEST : true
31
- }
32
- LOGR_.log(l_.LOG_TEST, () => ['const l_ ', l_])
32
+ LOGR_.toggle(l_, {
33
+ VALIDATION : true
34
+ });
35
+ logr_.raw(() => ['twoPhW-new.spec: const l_ ', l_.get()])
33
36
 
34
37
  //-------------------------------------------------------------------------------------------------
35
38
 
@@ -37,12 +40,12 @@ describe("Initialization", function () {
37
40
  it("json_msgWarp", function () {
38
41
  const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
39
42
 
40
- const json_msgAckWarp_obj= JSON_MsgAckWarp.create_with_msgOk(json_msgWarp, true);
41
- const json_msgAckWarp_str= JSON_MsgAckWarp.create_with_msgOk( JSON.stringify(json_msgWarp), true);
43
+ const json_msgAckWarp_obj= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp, true);
44
+ const json_msgAckWarp_str= JSON_MsgAckWarp.create_with_Warp_Ok( JSON.stringify(json_msgWarp), true);
42
45
 
43
- expect(typeof json_msgAckWarp_obj._msg.warp.id === 'string').toBe(true);
46
+ expect(typeof json_msgAckWarp_obj._cause.warp.id === 'string').toBe(true);
44
47
  expect(() => {
45
- json_msgAckWarp_str._msg.warp.id;
48
+ json_msgAckWarp_str._cause.warp.id;
46
49
  }).toThrowError(TypeError, "Cannot read properties of undefined (reading 'id')");
47
50
 
48
51
  expect(() => {
@@ -78,7 +81,7 @@ describe("Validation", function () {
78
81
  "ok" : true,
79
82
  "rtt_msec" : 6000
80
83
  },
81
- "_msg" : json_msgWarp_,
84
+ "_cause" : json_msgWarp_,
82
85
  "2PhW": k_VERSION
83
86
  }
84
87
 
@@ -89,7 +92,7 @@ describe("Validation", function () {
89
92
  ack: {
90
93
  "ok" : true,
91
94
  },
92
- "_msg" : JSON.stringify( json_msgWarp_ ),
95
+ "_cause" : JSON.stringify( json_msgWarp_ ),
93
96
  "2PhW": k_VERSION
94
97
  }
95
98
 
@@ -100,7 +103,7 @@ describe("Validation", function () {
100
103
  ack: {
101
104
  "ok" : true,
102
105
  },
103
- "_msg" : json_msgWarp_,
106
+ "_cause" : json_msgWarp_,
104
107
  "2PhW": k_VERSION
105
108
  }
106
109
 
@@ -111,7 +114,7 @@ describe("Validation", function () {
111
114
  ack: {
112
115
  "ok" : false,
113
116
  },
114
- "_msg" : json_msgEngage_,
117
+ "_cause" : json_msgEngage_,
115
118
  "2PhW": k_VERSION
116
119
  }
117
120
 
@@ -124,7 +127,7 @@ describe("Validation", function () {
124
127
  ttl_msec_incr : [ 20000, 4000 ],
125
128
  reason : "it is taking too long"
126
129
  },
127
- "_msg" : json_msgWarp_,
130
+ "_cause" : json_msgWarp_,
128
131
  "2PhW": k_VERSION
129
132
  }
130
133
 
@@ -155,6 +158,22 @@ describe("Validation", function () {
155
158
  it("JSON_MsgAckEngage.validate(json_msgAckEngage_)", function () {
156
159
  expect( JSON_MsgAckEngage.validate(json_msgAckEngage_) ).toBe(true);
157
160
  });
161
+
162
+ it("LOGR test", function () {
163
+ const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(
164
+ "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
165
+ '',
166
+ '',
167
+ 3000
168
+ );
169
+
170
+ LOGR_.toggle(l_, {
171
+ VALIDATION : true
172
+ });
173
+
174
+ expect( JSON_MsgEffect.validate(json_msgWarp) ).toBe(false);
175
+ });
176
+
158
177
  });
159
178
 
160
179
  //-------------------------------------------------------------------------------------------------
@@ -181,10 +200,10 @@ describe('2PhW protocol', () => {
181
200
  const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
182
201
  json_msgWarp.referer= karr_referer_src;
183
202
 
184
- const json_msgEngage= JSON_MsgEngage.create_with_MsgWarp(json_msgWarp);
203
+ const json_msgEngage= JSON_MsgEngage.create_with_Warp(json_msgWarp);
185
204
  json_msgEngage.referer= karr_referer_src;
186
205
 
187
- const json_msgNackWarp= JSON_MsgAckWarp.create_with_msgOk(json_msgWarp, false);
206
+ const json_msgNackWarp= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp, false);
188
207
  json_msgNackWarp.referer= karr_referer_dst;
189
208
  const str_msgNackWarp = JSON.stringify(json_msgNackWarp);
190
209
  twoPhW.eventLog._addEvent(str_msgNackWarp, json_msgNackWarp)
@@ -208,7 +227,7 @@ describe('2PhW protocol', () => {
208
227
  "t_ttl_rtt_: INVALID rtt_msec ttl_msec[1500] rtt_msec[3001]"
209
228
  );
210
229
  });
211
-
230
+
212
231
  });
213
232
 
214
233
  // ,---, ___
@@ -240,11 +259,11 @@ describe('2PhW protocol', () => {
240
259
  callback_msg_sent_expired = jasmine.createSpy('callback_msg_sent_expired');
241
260
 
242
261
  twoPhW.config.receiver( callback_msgWarp, callback_msgEngage, callback_msg_sent_expired )
243
- LOGR_.toggled= {
262
+ LOGR_.toggle(l_, {
244
263
  // RECVER : 1,
245
264
  // PROTOCOL_STATE : 1,
246
265
  // DROPS : 1
247
- }
266
+ });
248
267
 
249
268
  expect(Date.now()-T0).toBe(0);
250
269
 
@@ -260,7 +279,7 @@ describe('2PhW protocol', () => {
260
279
  });
261
280
 
262
281
  afterEach(() => {
263
- LOGR_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
282
+ logr_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
264
283
  });
265
284
 
266
285
  it('receive JSON_MsgWarp', () => {
@@ -287,7 +306,7 @@ describe('2PhW protocol', () => {
287
306
  });
288
307
 
289
308
  it('receive premature JSON_MsgEngage', () => {
290
- const json_msgEngage_recvd= JSON_MsgEngage.create_with_MsgWarp(json_msgWarp_src);
309
+ const json_msgEngage_recvd= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
291
310
  json_msgEngage_recvd.referer= karr_referer_src;
292
311
 
293
312
  twoPhW.handler_json(json_msgEngage_recvd, json_msgEngage_recvd);
@@ -319,11 +338,11 @@ describe('2PhW protocol', () => {
319
338
  let str_msgNackWarp_dst;
320
339
 
321
340
  beforeEach(() => {
322
- json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_msgOk(json_msgWarp_src, true);
341
+ json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, true);
323
342
  json_msgAckWarp_dst.referer= karr_referer_dst;
324
343
  str_msgAckWarp_dst = JSON.stringify(json_msgAckWarp_dst);
325
344
 
326
- json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_msgOk(json_msgWarp_src, false);
345
+ json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, false);
327
346
  json_msgNackWarp_dst.referer= karr_referer_dst;
328
347
  str_msgNackWarp_dst = JSON.stringify(str_msgNackWarp_dst);
329
348
 
@@ -359,7 +378,7 @@ describe('2PhW protocol', () => {
359
378
  expect(eventLog.arr_events[1].data).toEqual({ msg: str_msgAckWarp_dst, json_msg : json_msgAckWarp_dst });
360
379
  expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
361
380
 
362
- const json_msgEngage_src= JSON_MsgEngage.create_with_MsgWarp(json_msgWarp_src);
381
+ const json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
363
382
  json_msgEngage_src.referer= karr_referer_src;
364
383
 
365
384
  twoPhW.handler_json(json_msgEngage_src, json_msgEngage_src);
@@ -373,7 +392,7 @@ describe('2PhW protocol', () => {
373
392
  expect(eventLog.arr_events[1].data).toEqual({ msg : str_msgNackWarp_dst, json_msg : json_msgNackWarp_dst });
374
393
 
375
394
  jasmine.clock().tick(STT_MSEC_1000); // 2000, STT_MSEC_1000 *2= RTT
376
- const json_msgEngage_src= JSON_MsgEngage.create_with_MsgWarp(json_msgWarp_src);
395
+ const json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
377
396
  json_msgEngage_src.referer= karr_referer_src;
378
397
 
379
398
  jasmine.clock().tick(STT_MSEC_1000); // 3000, STT_MSEC_1000 *3
@@ -386,12 +405,12 @@ describe('2PhW protocol', () => {
386
405
  let str_msgEngage_src;
387
406
 
388
407
  beforeEach(() => {
389
- LOGR_.toggled= {
408
+ LOGR_.toggle(l_, {
390
409
  // RECVER : 1,
391
410
  // PROTOCOL_STATE : 1,
392
411
  // DROPS : 1,
393
412
  // LOG_TEST : true
394
- }
413
+ });
395
414
 
396
415
  jasmine.clock().tick(0);
397
416
  expect(Date.now()-T0).toBe(STT_MSEC_1000);
@@ -404,7 +423,7 @@ describe('2PhW protocol', () => {
404
423
  expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
405
424
 
406
425
  jasmine.clock().tick(STT_MSEC_1000); // STT_MSEC_1000 *2= RTT
407
- json_msgEngage_src= JSON_MsgEngage.create_with_MsgWarp(json_msgWarp_src);
426
+ json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
408
427
  json_msgEngage_src.referer= karr_referer_src;
409
428
  str_msgEngage_src = JSON.stringify(json_msgEngage_src);
410
429
 
@@ -438,7 +457,7 @@ describe('2PhW protocol', () => {
438
457
  expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
439
458
 
440
459
  jasmine.clock().tick(STT_MSEC_1000); // 4000, STT_MSEC_1000 *4
441
- const json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_msgOk(json_msgEngage_src, false);
460
+ const json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, false);
442
461
  json_msgNackEngage_dst.referer= karr_referer_dst;
443
462
  twoPhW.register_msgAckEngage(JSON.stringify(json_msgNackEngage_dst), json_msgNackEngage_dst)
444
463
  expect(eventLog.arr_events.length).toBe(2);
@@ -450,11 +469,11 @@ describe('2PhW protocol', () => {
450
469
  let str_msgNackEngage_dst;
451
470
 
452
471
  beforeEach(() => {
453
- LOGR_.toggled= {
472
+ LOGR_.toggle(l_, {
454
473
  // RECVER : 1,
455
474
  // PROTOCOL_STATE : 1,
456
475
  // DROPS : 1
457
- }
476
+ });
458
477
 
459
478
  jasmine.clock().tick(STT_MSEC_1000); // 3000, STT_MSEC_1000 *3
460
479
 
@@ -466,7 +485,7 @@ describe('2PhW protocol', () => {
466
485
  expect(eventLog.arr_events[2].data).toEqual({ msg: str_msgEngage_src, json_msg : json_msgEngage_src });
467
486
  expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
468
487
 
469
- json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_msgOk(json_msgEngage_src, false);
488
+ json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, false);
470
489
  json_msgNackEngage_dst.referer= karr_referer_dst;
471
490
  str_msgNackEngage_dst = JSON.stringify(json_msgNackEngage_dst);
472
491
 
@@ -579,11 +598,11 @@ describe('2PhW protocol', () => {
579
598
  callback_msgAckEngage = jasmine.createSpy('callback_msgAckEngage').and.returnValue(true);
580
599
  callback_msg_sent_expired = jasmine.createSpy('callback_msg_sent_expired');
581
600
  twoPhW.config.sender( callback_msgAckWarp, callback_msgAckEngage, callback_msg_sent_expired )
582
- LOGR_.toggled= {
601
+ LOGR_.toggle(l_, {
583
602
  // SENDER : 1,
584
603
  // PROTOCOL_STATE : 1,
585
604
  // DROPS : 1
586
- }
605
+ });
587
606
 
588
607
  jasmine.clock().tick(0);
589
608
  expect(Date.now()-T0).toBe(0);
@@ -596,7 +615,7 @@ describe('2PhW protocol', () => {
596
615
  });
597
616
 
598
617
  afterEach(() => {
599
- LOGR_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
618
+ logr_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
600
619
  });
601
620
 
602
621
  it('send JSON_MsgWarp == can register a Warp', () => {
@@ -630,11 +649,11 @@ describe('2PhW protocol', () => {
630
649
  let str_msgEngage_src;
631
650
 
632
651
  beforeEach(() => {
633
- LOGR_.toggled= {
652
+ LOGR_.toggle(l_, {
634
653
  // SENDER : 1,
635
654
  // PROTOCOL_STATE : 1,
636
655
  // DROPS : 1
637
- }
656
+ });
638
657
 
639
658
  twoPhW.register_msgWarp(str_msgWarp_src, json_msgWarp_src);
640
659
  expect(eventLog.arr_events.length).toBe(1);
@@ -645,17 +664,17 @@ describe('2PhW protocol', () => {
645
664
  expect(Date.now()-T0).toBe(0);
646
665
 
647
666
  jasmine.clock().tick(STT_MSEC_1000); // 1000
648
- json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_msgOk(json_msgWarp_src, true);
667
+ json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, true);
649
668
  json_msgAckWarp_dst.referer= karr_referer_dst;
650
669
  str_msgAckWarp_dst = JSON.stringify(json_msgAckWarp_dst);
651
670
 
652
- json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_msgOk(json_msgWarp_src, false);
671
+ json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, false);
653
672
  json_msgNackWarp_dst.referer= karr_referer_dst;
654
673
  str_msgNackWarp_dst = JSON.stringify(json_msgNackWarp_dst);
655
674
 
656
675
  jasmine.clock().tick(STT_MSEC_1000); // 2000
657
676
 
658
- json_msgEngage_src= JSON_MsgEngage.create_with_MsgWarp(json_msgWarp_src);
677
+ json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
659
678
  json_msgEngage_src.referer= karr_referer_src;
660
679
  str_msgEngage_src = JSON.stringify(json_msgEngage_src);
661
680
 
@@ -694,7 +713,7 @@ describe('2PhW protocol', () => {
694
713
  expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
695
714
 
696
715
  jasmine.clock().tick(STT_MSEC_1000); // 3000
697
- const json_msgAckEngage_recv= JSON_MsgAckEngage.create_with_msgOk(json_msgEngage_src, true);
716
+ const json_msgAckEngage_recv= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, true);
698
717
  json_msgAckEngage_recv.referer= karr_referer_dst;
699
718
 
700
719
  jasmine.clock().tick(STT_MSEC_1000); // 4000
@@ -704,11 +723,11 @@ describe('2PhW protocol', () => {
704
723
 
705
724
  describe('register Engage!', () => {
706
725
  beforeEach(() => {
707
- LOGR_.toggled= {
726
+ LOGR_.toggle(l_, {
708
727
  // SENDER : 1,
709
728
  // PROTOCOL_STATE : 1,
710
729
  // DROPS : 1
711
- }
730
+ });
712
731
 
713
732
  expect(Date.now()-T0).toBe(RTT_MSEC_2000);
714
733
 
@@ -759,11 +778,11 @@ describe('2PhW protocol', () => {
759
778
  let str_msgAckEngage_dst;
760
779
 
761
780
  beforeEach(() => {
762
- LOGR_.toggled= {
781
+ LOGR_.toggle(l_, {
763
782
  // SENDER : 1,
764
783
  // PROTOCOL_STATE : 1,
765
784
  // DROPS : 1
766
- }
785
+ });
767
786
 
768
787
  expect(Date.now()-T0).toBe(RTT_MSEC_2000);
769
788
 
@@ -772,7 +791,7 @@ describe('2PhW protocol', () => {
772
791
  expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
773
792
 
774
793
  jasmine.clock().tick(STT_MSEC_1000); // 3000
775
- json_msgAckEngage_dst= JSON_MsgAckEngage.create_with_msgOk(json_msgEngage_src, true);
794
+ json_msgAckEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, true);
776
795
  json_msgAckEngage_dst.referer= karr_referer_dst;
777
796
  str_msgAckEngage_dst = JSON.stringify(json_msgAckEngage_dst);
778
797
 
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './twoPhW';