@rootintf/protocol-2phw 0.7.1 → 0.7.5-api-0.7
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/README.md +1 -1
- package/dist/twoPhW.cjs.js +756 -758
- package/dist/twoPhW.es.mjs +756 -756
- package/jasmine.json +6 -6
- package/package.json +42 -42
- package/rollup.config.mjs +23 -23
- package/schema/schema_Msg2PhW.json +11 -11
- package/schema/schema_MsgEngage.json +11 -11
- package/schema/schema_MsgOptions.json +10 -10
- package/schema/schema_MsgWarp.json +19 -19
- package/schema/schema_Options_delay.json +16 -16
- package/src/ajv-gen-validate.cjs +23 -23
- package/src/twoPhW.mjs +582 -582
- package/tests/twoPhW-new.spec.mjs +173 -173
- package/tests/twoPhW.test.mjs +175 -175
package/tests/twoPhW.test.mjs
CHANGED
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
|
|
2
|
-
// throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
3
|
-
// https://stackoverflow.com/questions/69118216/crypto-getrandomvalues-not-supported-in-react-js
|
|
4
|
-
// - https://stackoverflow.com/questions/52612122/how-to-use-jest-to-test-functions-using-crypto-or-window-mscrypto
|
|
5
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
6
|
-
import crypto from 'crypto'
|
|
7
|
-
Object.defineProperty(globalThis, 'crypto', {
|
|
8
|
-
value: {
|
|
9
|
-
getRandomValues: arr => crypto.randomBytes(arr.length)
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
import { TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, l as l_2PhW } from '../src/twoPhW.mjs';
|
|
14
|
-
|
|
15
|
-
console.log('l_2PhW', l_2PhW, Object.keys(l_2PhW).length);
|
|
16
|
-
|
|
17
|
-
const recv_referer_= [ "recv", uuidv4()];
|
|
18
|
-
console.log('recv_referer_= ' + recv_referer_);
|
|
19
|
-
|
|
20
|
-
const send_referer_= [ "send", uuidv4()];
|
|
21
|
-
console.log('send_referer_= ' + send_referer_);
|
|
22
|
-
|
|
23
|
-
var twoPhW_recv_= new TwoPhW();
|
|
24
|
-
var twoPhW_send_= new TwoPhW();
|
|
25
|
-
|
|
26
|
-
twoPhW_recv_.config.receiver( callback_msgWarp_, callback_msgEngage_ );
|
|
27
|
-
twoPhW_recv_.config.callback_msgOptions= callback_msgOptions_;
|
|
28
|
-
twoPhW_recv_.config.logr= {
|
|
29
|
-
// HANDLERS : 1,
|
|
30
|
-
// VALIDATION : 1
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
twoPhW_send_.config.sender( callback_msgAckWarp_, callback_msgAckEngage_ );
|
|
34
|
-
twoPhW_send_.config.callback_msgOptions= callback_msgOptions_;
|
|
35
|
-
twoPhW_send_.config.logr= {
|
|
36
|
-
HANDLERS : 1,
|
|
37
|
-
// VALIDATION : 1
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//-------------------------------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
function callback_msgOptions_(msg, json_msgOptions)
|
|
43
|
-
{
|
|
44
|
-
console.log('callback_msgOptions_: ', json_msgOptions);
|
|
45
|
-
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//-------------------------------------------------------------------------------------------------
|
|
50
|
-
// Sender
|
|
51
|
-
|
|
52
|
-
function callback_msgAckWarp_(msg, json_msgAckWarp)
|
|
53
|
-
{
|
|
54
|
-
console.log('callback_msgAckWarp_: Ack: ', json_msgAckWarp);
|
|
55
|
-
|
|
56
|
-
// console.log('callback_msgAckWarp_: publish: Engage: ', json_Engage);
|
|
57
|
-
// IPSME_MsgEnv.publish( JSON.stringify(json_Engage) );
|
|
58
|
-
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function callback_msgAckEngage_(msg, json_msgAckEngage)
|
|
63
|
-
{
|
|
64
|
-
console.log('callback_msgAckEngage_: Ack: ', json_msgAckEngage);
|
|
65
|
-
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//-------------------------------------------------------------------------------------------------
|
|
70
|
-
// Receiver
|
|
71
|
-
|
|
72
|
-
function callback_msgWarp_(msg, json_msgWarp)
|
|
73
|
-
{
|
|
74
|
-
// console.log('callback_msgWarp_: Warp: ', json_Warp);
|
|
75
|
-
console.log('callback_msgWarp_: Warp: ...');
|
|
76
|
-
|
|
77
|
-
// console.log('callback_msgWarp_: publish Ack Warp: ', json_Ack);
|
|
78
|
-
// IPSME_MsgEnv.publish( JSON.stringify(json_Ack) );
|
|
79
|
-
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function callback_msgEngage_(msg, json_msgEngage)
|
|
84
|
-
{
|
|
85
|
-
// console.log('callback_msgEngage_: Engage: ', json_Engage);
|
|
86
|
-
console.log('callback_msgEngage_: Engage: ...');
|
|
87
|
-
|
|
88
|
-
// console.log('callback_msgEngage_: publish: Ack Engage: ', json_Ack);
|
|
89
|
-
// IPSME_MsgEnv.publish( JSON.stringify(json_Ack) );
|
|
90
|
-
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//-------------------------------------------------------------------------------------------------
|
|
95
|
-
|
|
96
|
-
function callback_Abort_()
|
|
97
|
-
{
|
|
98
|
-
console.log('callback_Abort: ... : ');
|
|
99
|
-
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//-------------------------------------------------------------------------------------------------
|
|
104
|
-
|
|
105
|
-
// const json_Warp_ = {
|
|
106
|
-
// id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
107
|
-
// referer: "af9447e3-4b36-424f-8d07-976a9216a298",
|
|
108
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
109
|
-
// warp: {
|
|
110
|
-
// user: {},
|
|
111
|
-
// hyperport: {},
|
|
112
|
-
// ttl_msec: 4000
|
|
113
|
-
// },
|
|
114
|
-
// "2PhW" : "0.6"
|
|
115
|
-
// }
|
|
116
|
-
|
|
117
|
-
// const json_Engage_ = {
|
|
118
|
-
// referer: "af9447e3-4b36-424f-8d07-976a9216a298",
|
|
119
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
120
|
-
// engage: {
|
|
121
|
-
// id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
122
|
-
// user: {},
|
|
123
|
-
// hyperport: {}
|
|
124
|
-
// }
|
|
125
|
-
// }
|
|
126
|
-
|
|
127
|
-
const json_msgWarp_= twoPhW_send_.create_MsgWarp_out(uuidv4(), { "user": "user"}, { "hyperport" : "hyperport" }, 4000);
|
|
128
|
-
json_msgWarp_.referer= send_referer_;
|
|
129
|
-
|
|
130
|
-
const ttl_warp= json_msgWarp_.warp.ttl_msec;
|
|
131
|
-
|
|
132
|
-
const json_msgOptions= JSON_MsgOptions.create_with_msg_options(json_msgWarp_, {
|
|
133
|
-
"ttl_msec_incr" : [ ttl_warp, 3000 ]
|
|
134
|
-
});
|
|
135
|
-
json_msgOptions.referer= recv_referer_;
|
|
136
|
-
|
|
137
|
-
// https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
|
|
138
|
-
await new Promise(r => setTimeout(r, 1500));
|
|
139
|
-
|
|
140
|
-
twoPhW_send_.handler_msg(json_msgOptions);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// twoPhW_recv_.handler_msg(json_msgWarp_);
|
|
144
|
-
// twoPhW.handler_msg(json_Engage_);
|
|
145
|
-
|
|
146
|
-
//-------------------------------------------------------------------------------------------------
|
|
147
|
-
|
|
148
|
-
// const json_Ack_str_ = {
|
|
149
|
-
// referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
150
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
151
|
-
// ack: {
|
|
152
|
-
// "ok" : true,
|
|
153
|
-
// "_msg" : JSON.stringify( json_Warp_ )
|
|
154
|
-
// }
|
|
155
|
-
// }
|
|
156
|
-
|
|
157
|
-
// const json_Ack_obj_ = {
|
|
158
|
-
// referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
159
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
160
|
-
// ack: {
|
|
161
|
-
// "ok" : true,
|
|
162
|
-
// "_msg" : json_Warp_.warp
|
|
163
|
-
// }
|
|
164
|
-
// }
|
|
165
|
-
|
|
166
|
-
// twoPhW.handler_msg(json_Ack_str_);
|
|
167
|
-
|
|
168
|
-
//-------------------------------------------------------------------------------------------------
|
|
169
|
-
|
|
170
|
-
twoPhW_recv_.config.options= {
|
|
171
|
-
logr : {
|
|
172
|
-
DROPS : 1
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// twoPhW.handler_msg('THIS msg SHOULD DROP');
|
|
1
|
+
|
|
2
|
+
// throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
3
|
+
// https://stackoverflow.com/questions/69118216/crypto-getrandomvalues-not-supported-in-react-js
|
|
4
|
+
// - https://stackoverflow.com/questions/52612122/how-to-use-jest-to-test-functions-using-crypto-or-window-mscrypto
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
|
+
import crypto from 'crypto'
|
|
7
|
+
Object.defineProperty(globalThis, 'crypto', {
|
|
8
|
+
value: {
|
|
9
|
+
getRandomValues: arr => crypto.randomBytes(arr.length)
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
import { TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, l as l_2PhW } from '../src/twoPhW.mjs';
|
|
14
|
+
|
|
15
|
+
console.log('l_2PhW', l_2PhW, Object.keys(l_2PhW).length);
|
|
16
|
+
|
|
17
|
+
const recv_referer_= [ "recv", uuidv4()];
|
|
18
|
+
console.log('recv_referer_= ' + recv_referer_);
|
|
19
|
+
|
|
20
|
+
const send_referer_= [ "send", uuidv4()];
|
|
21
|
+
console.log('send_referer_= ' + send_referer_);
|
|
22
|
+
|
|
23
|
+
var twoPhW_recv_= new TwoPhW();
|
|
24
|
+
var twoPhW_send_= new TwoPhW();
|
|
25
|
+
|
|
26
|
+
twoPhW_recv_.config.receiver( callback_msgWarp_, callback_msgEngage_ );
|
|
27
|
+
twoPhW_recv_.config.callback_msgOptions= callback_msgOptions_;
|
|
28
|
+
twoPhW_recv_.config.logr= {
|
|
29
|
+
// HANDLERS : 1,
|
|
30
|
+
// VALIDATION : 1
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
twoPhW_send_.config.sender( callback_msgAckWarp_, callback_msgAckEngage_ );
|
|
34
|
+
twoPhW_send_.config.callback_msgOptions= callback_msgOptions_;
|
|
35
|
+
twoPhW_send_.config.logr= {
|
|
36
|
+
HANDLERS : 1,
|
|
37
|
+
// VALIDATION : 1
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//-------------------------------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
function callback_msgOptions_(msg, json_msgOptions)
|
|
43
|
+
{
|
|
44
|
+
console.log('callback_msgOptions_: ', json_msgOptions);
|
|
45
|
+
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//-------------------------------------------------------------------------------------------------
|
|
50
|
+
// Sender
|
|
51
|
+
|
|
52
|
+
function callback_msgAckWarp_(msg, json_msgAckWarp)
|
|
53
|
+
{
|
|
54
|
+
console.log('callback_msgAckWarp_: Ack: ', json_msgAckWarp);
|
|
55
|
+
|
|
56
|
+
// console.log('callback_msgAckWarp_: publish: Engage: ', json_Engage);
|
|
57
|
+
// IPSME_MsgEnv.publish( JSON.stringify(json_Engage) );
|
|
58
|
+
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function callback_msgAckEngage_(msg, json_msgAckEngage)
|
|
63
|
+
{
|
|
64
|
+
console.log('callback_msgAckEngage_: Ack: ', json_msgAckEngage);
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//-------------------------------------------------------------------------------------------------
|
|
70
|
+
// Receiver
|
|
71
|
+
|
|
72
|
+
function callback_msgWarp_(msg, json_msgWarp)
|
|
73
|
+
{
|
|
74
|
+
// console.log('callback_msgWarp_: Warp: ', json_Warp);
|
|
75
|
+
console.log('callback_msgWarp_: Warp: ...');
|
|
76
|
+
|
|
77
|
+
// console.log('callback_msgWarp_: publish Ack Warp: ', json_Ack);
|
|
78
|
+
// IPSME_MsgEnv.publish( JSON.stringify(json_Ack) );
|
|
79
|
+
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function callback_msgEngage_(msg, json_msgEngage)
|
|
84
|
+
{
|
|
85
|
+
// console.log('callback_msgEngage_: Engage: ', json_Engage);
|
|
86
|
+
console.log('callback_msgEngage_: Engage: ...');
|
|
87
|
+
|
|
88
|
+
// console.log('callback_msgEngage_: publish: Ack Engage: ', json_Ack);
|
|
89
|
+
// IPSME_MsgEnv.publish( JSON.stringify(json_Ack) );
|
|
90
|
+
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//-------------------------------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
function callback_Abort_()
|
|
97
|
+
{
|
|
98
|
+
console.log('callback_Abort: ... : ');
|
|
99
|
+
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//-------------------------------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
// const json_Warp_ = {
|
|
106
|
+
// id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
107
|
+
// referer: "af9447e3-4b36-424f-8d07-976a9216a298",
|
|
108
|
+
// dt: "2022-10-28T06:26:19.692Z",
|
|
109
|
+
// warp: {
|
|
110
|
+
// user: {},
|
|
111
|
+
// hyperport: {},
|
|
112
|
+
// ttl_msec: 4000
|
|
113
|
+
// },
|
|
114
|
+
// "2PhW" : "0.6"
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
// const json_Engage_ = {
|
|
118
|
+
// referer: "af9447e3-4b36-424f-8d07-976a9216a298",
|
|
119
|
+
// dt: "2022-10-28T06:26:19.692Z",
|
|
120
|
+
// engage: {
|
|
121
|
+
// id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
122
|
+
// user: {},
|
|
123
|
+
// hyperport: {}
|
|
124
|
+
// }
|
|
125
|
+
// }
|
|
126
|
+
|
|
127
|
+
const json_msgWarp_= twoPhW_send_.create_MsgWarp_out(uuidv4(), { "user": "user"}, { "hyperport" : "hyperport" }, 4000);
|
|
128
|
+
json_msgWarp_.referer= send_referer_;
|
|
129
|
+
|
|
130
|
+
const ttl_warp= json_msgWarp_.warp.ttl_msec;
|
|
131
|
+
|
|
132
|
+
const json_msgOptions= JSON_MsgOptions.create_with_msg_options(json_msgWarp_, {
|
|
133
|
+
"ttl_msec_incr" : [ ttl_warp, 3000 ]
|
|
134
|
+
});
|
|
135
|
+
json_msgOptions.referer= recv_referer_;
|
|
136
|
+
|
|
137
|
+
// https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
|
|
138
|
+
await new Promise(r => setTimeout(r, 1500));
|
|
139
|
+
|
|
140
|
+
twoPhW_send_.handler_msg(json_msgOptions);
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
// twoPhW_recv_.handler_msg(json_msgWarp_);
|
|
144
|
+
// twoPhW.handler_msg(json_Engage_);
|
|
145
|
+
|
|
146
|
+
//-------------------------------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
// const json_Ack_str_ = {
|
|
149
|
+
// referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
150
|
+
// dt: "2022-10-28T06:26:19.692Z",
|
|
151
|
+
// ack: {
|
|
152
|
+
// "ok" : true,
|
|
153
|
+
// "_msg" : JSON.stringify( json_Warp_ )
|
|
154
|
+
// }
|
|
155
|
+
// }
|
|
156
|
+
|
|
157
|
+
// const json_Ack_obj_ = {
|
|
158
|
+
// referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
159
|
+
// dt: "2022-10-28T06:26:19.692Z",
|
|
160
|
+
// ack: {
|
|
161
|
+
// "ok" : true,
|
|
162
|
+
// "_msg" : json_Warp_.warp
|
|
163
|
+
// }
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// twoPhW.handler_msg(json_Ack_str_);
|
|
167
|
+
|
|
168
|
+
//-------------------------------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
twoPhW_recv_.config.options= {
|
|
171
|
+
logr : {
|
|
172
|
+
DROPS : 1
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// twoPhW.handler_msg('THIS msg SHOULD DROP');
|