@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/dist/twoPhW.es.mjs
CHANGED
|
@@ -1,4 +1,180 @@
|
|
|
1
|
-
const schema_MsgWarp = validate19;
|
|
1
|
+
const schema_MsgWarp = validate19;
|
|
2
|
+
function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
|
|
3
|
+
evaluated0.props = undefined;
|
|
4
|
+
} if (evaluated0.dynamicItems) {
|
|
5
|
+
evaluated0.items = undefined;
|
|
6
|
+
} {
|
|
7
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
8
|
+
let missing0;
|
|
9
|
+
if ((data.warp === undefined) && (missing0 = "warp")) {
|
|
10
|
+
validate19.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (data.warp !== undefined) {
|
|
15
|
+
let data0 = data.warp;
|
|
16
|
+
const _errs1 = errors;
|
|
17
|
+
{
|
|
18
|
+
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
19
|
+
let missing1;
|
|
20
|
+
if (((((data0.id === undefined) && (missing1 = "id")) || ((data0.user === undefined) && (missing1 = "user"))) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))) || ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec"))) {
|
|
21
|
+
validate19.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (data0.id !== undefined) {
|
|
26
|
+
const _errs3 = errors;
|
|
27
|
+
if (typeof data0.id !== "string") {
|
|
28
|
+
validate19.errors = [{ instancePath: instancePath + "/warp/id", schemaPath: "definitions#/definitions/warp_id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
var valid1 = _errs3 === errors;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
var valid1 = true;
|
|
35
|
+
}
|
|
36
|
+
if (valid1) {
|
|
37
|
+
if (data0.ttl_msec !== undefined) {
|
|
38
|
+
let data2 = data0.ttl_msec;
|
|
39
|
+
const _errs6 = errors;
|
|
40
|
+
if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
|
|
41
|
+
validate19.errors = [{ instancePath: instancePath + "/warp/ttl_msec", schemaPath: "#/properties/warp/properties/ttl_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
var valid1 = _errs6 === errors;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
var valid1 = true;
|
|
48
|
+
}
|
|
49
|
+
if (valid1) {
|
|
50
|
+
if (data0.instantaneous !== undefined) {
|
|
51
|
+
const _errs8 = errors;
|
|
52
|
+
if (typeof data0.instantaneous !== "boolean") {
|
|
53
|
+
validate19.errors = [{ instancePath: instancePath + "/warp/instantaneous", schemaPath: "#/properties/warp/properties/instantaneous/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
var valid1 = _errs8 === errors;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
var valid1 = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
validate19.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
var valid0 = _errs1 === errors;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
var valid0 = true;
|
|
74
|
+
}
|
|
75
|
+
if (valid0) {
|
|
76
|
+
if (data["2PhW"] !== undefined) {
|
|
77
|
+
const _errs10 = errors;
|
|
78
|
+
if ("2" !== data["2PhW"]) {
|
|
79
|
+
validate19.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
var valid0 = _errs10 === errors;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
var valid0 = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
validate19.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
} validate19.errors = vErrors; return errors === 0; }
|
|
95
|
+
validate19.evaluated = { "props": { "warp": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
|
|
96
|
+
const schema_MsgEngage = validate20;
|
|
97
|
+
function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
|
|
98
|
+
evaluated0.props = undefined;
|
|
99
|
+
} if (evaluated0.dynamicItems) {
|
|
100
|
+
evaluated0.items = undefined;
|
|
101
|
+
} {
|
|
102
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
103
|
+
let missing0;
|
|
104
|
+
if ((data.engage === undefined) && (missing0 = "engage")) {
|
|
105
|
+
validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (data.engage !== undefined) {
|
|
110
|
+
let data0 = data.engage;
|
|
111
|
+
const _errs1 = errors;
|
|
112
|
+
{
|
|
113
|
+
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
114
|
+
let missing1;
|
|
115
|
+
if (((data0.ok === undefined) && (missing1 = "ok")) || ((data0.rtt_msec === undefined) && (missing1 = "rtt_msec"))) {
|
|
116
|
+
validate20.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
if (data0.ok !== undefined) {
|
|
121
|
+
const _errs3 = errors;
|
|
122
|
+
if (typeof data0.ok !== "boolean") {
|
|
123
|
+
validate20.errors = [{ instancePath: instancePath + "/engage/ok", schemaPath: "#/properties/engage/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
var valid1 = _errs3 === errors;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
var valid1 = true;
|
|
130
|
+
}
|
|
131
|
+
if (valid1) {
|
|
132
|
+
if (data0.rtt_msec !== undefined) {
|
|
133
|
+
let data2 = data0.rtt_msec;
|
|
134
|
+
const _errs5 = errors;
|
|
135
|
+
if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
|
|
136
|
+
validate20.errors = [{ instancePath: instancePath + "/engage/rtt_msec", schemaPath: "#/properties/engage/properties/rtt_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
var valid1 = _errs5 === errors;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
var valid1 = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
validate20.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
var valid0 = _errs1 === errors;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
var valid0 = true;
|
|
156
|
+
}
|
|
157
|
+
if (valid0) {
|
|
158
|
+
if (data["2PhW"] !== undefined) {
|
|
159
|
+
const _errs7 = errors;
|
|
160
|
+
if ("2" !== data["2PhW"]) {
|
|
161
|
+
validate20.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
var valid0 = _errs7 === errors;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
var valid0 = true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
} validate20.errors = vErrors; return errors === 0; }
|
|
177
|
+
validate20.evaluated = { "props": { "engage": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
|
|
2
178
|
|
|
3
179
|
// console.log('OUT', __name({variableName}) );
|
|
4
180
|
|
|
@@ -192,7 +368,115 @@ function requireJsonMsg_cjs () {
|
|
|
192
368
|
if (hasRequiredJsonMsg_cjs) return jsonMsg_cjs;
|
|
193
369
|
hasRequiredJsonMsg_cjs = 1;
|
|
194
370
|
|
|
195
|
-
const schema_Msg = validate18;
|
|
371
|
+
const schema_Msg = validate18;
|
|
372
|
+
function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
|
|
373
|
+
evaluated0.props = undefined;
|
|
374
|
+
} if (evaluated0.dynamicItems) {
|
|
375
|
+
evaluated0.items = undefined;
|
|
376
|
+
} {
|
|
377
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
378
|
+
let missing0;
|
|
379
|
+
if ((((data.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))) {
|
|
380
|
+
validate18.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
if (data.id !== undefined) {
|
|
385
|
+
const _errs1 = errors;
|
|
386
|
+
if (typeof data.id !== "string") {
|
|
387
|
+
validate18.errors = [{ instancePath: instancePath + "/id", schemaPath: "#/properties/id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
var valid0 = _errs1 === errors;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
var valid0 = true;
|
|
394
|
+
}
|
|
395
|
+
if (valid0) {
|
|
396
|
+
if (data.dt !== undefined) {
|
|
397
|
+
const _errs3 = errors;
|
|
398
|
+
if (typeof data.dt !== "string") {
|
|
399
|
+
validate18.errors = [{ instancePath: instancePath + "/dt", schemaPath: "#/properties/dt/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
var valid0 = _errs3 === errors;
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
var valid0 = true;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
validate18.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
} validate18.errors = vErrors; return errors === 0; }
|
|
415
|
+
validate18.evaluated = { "props": { "id": true, "dt": true }, "dynamicProps": false, "dynamicItems": false };
|
|
416
|
+
const schema_MsgEffect = validate19;
|
|
417
|
+
function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
|
|
418
|
+
evaluated0.props = undefined;
|
|
419
|
+
} if (evaluated0.dynamicItems) {
|
|
420
|
+
evaluated0.items = undefined;
|
|
421
|
+
} {
|
|
422
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
423
|
+
let missing0;
|
|
424
|
+
if ((data._cause === undefined) && (missing0 = "_cause")) {
|
|
425
|
+
validate19.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
validate19.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
} validate19.errors = vErrors; return errors === 0; }
|
|
434
|
+
validate19.evaluated = { "dynamicProps": false, "dynamicItems": false };
|
|
435
|
+
const schema_MsgAckEffect = validate20;
|
|
436
|
+
function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
|
|
437
|
+
evaluated0.props = undefined;
|
|
438
|
+
} if (evaluated0.dynamicItems) {
|
|
439
|
+
evaluated0.items = undefined;
|
|
440
|
+
} {
|
|
441
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
442
|
+
let missing0;
|
|
443
|
+
if ((data.ack === undefined) && (missing0 = "ack")) {
|
|
444
|
+
validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
if (data.ack !== undefined) {
|
|
449
|
+
let data0 = data.ack;
|
|
450
|
+
{
|
|
451
|
+
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
452
|
+
let missing1;
|
|
453
|
+
if ((data0.ok === undefined) && (missing1 = "ok")) {
|
|
454
|
+
validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
if (data0.ok !== undefined) {
|
|
459
|
+
if (typeof data0.ok !== "boolean") {
|
|
460
|
+
validate20.errors = [{ instancePath: instancePath + "/ack/ok", schemaPath: "#/properties/ack/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
} validate20.errors = vErrors; return errors === 0; }
|
|
479
|
+
validate20.evaluated = { "props": { "ack": true }, "dynamicProps": false, "dynamicItems": false };
|
|
196
480
|
|
|
197
481
|
const byteToHex = [];
|
|
198
482
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -236,10 +520,7 @@ function requireJsonMsg_cjs () {
|
|
|
236
520
|
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
237
521
|
var native = { randomUUID };
|
|
238
522
|
|
|
239
|
-
function
|
|
240
|
-
if (native.randomUUID && true && !options) {
|
|
241
|
-
return native.randomUUID();
|
|
242
|
-
}
|
|
523
|
+
function _v4(options, buf, offset) {
|
|
243
524
|
options = options || {};
|
|
244
525
|
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
245
526
|
if (rnds.length < 16) {
|
|
@@ -249,6 +530,12 @@ function requireJsonMsg_cjs () {
|
|
|
249
530
|
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
250
531
|
return unsafeStringify(rnds);
|
|
251
532
|
}
|
|
533
|
+
function v4(options, buf, offset) {
|
|
534
|
+
if (native.randomUUID && true && !options) {
|
|
535
|
+
return native.randomUUID();
|
|
536
|
+
}
|
|
537
|
+
return _v4(options);
|
|
538
|
+
}
|
|
252
539
|
|
|
253
540
|
// console.log('OUT', __name({variableName}) );
|
|
254
541
|
|
|
@@ -343,227 +630,202 @@ function requireJsonMsg_cjs () {
|
|
|
343
630
|
|
|
344
631
|
})();
|
|
345
632
|
|
|
346
|
-
let LOGR_= LOGR.get_instance();
|
|
347
|
-
const log_= LOGR_.log;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
VALIDATION : 0b1 << 0,
|
|
633
|
+
let LOGR_ = LOGR.get_instance();
|
|
634
|
+
const log_ = LOGR_.log;
|
|
635
|
+
const l_ = {
|
|
636
|
+
VALIDATION: 0b1 << 0,
|
|
351
637
|
};
|
|
352
|
-
LOGR_.labels= l_;
|
|
353
|
-
|
|
638
|
+
LOGR_.labels = l_;
|
|
354
639
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
355
|
-
|
|
356
640
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
357
|
-
var JSON_Msg = (function() {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
641
|
+
var JSON_Msg = (function () {
|
|
642
|
+
return {
|
|
643
|
+
merge: function (json) {
|
|
644
|
+
return Object.assign({
|
|
645
|
+
id: v4(),
|
|
646
|
+
referer: null,
|
|
647
|
+
dt: new Date().toISOString()
|
|
648
|
+
}, json || {});
|
|
649
|
+
},
|
|
650
|
+
validate: function (json) {
|
|
651
|
+
const b_valid = schema_Msg(json);
|
|
652
|
+
if (!b_valid)
|
|
653
|
+
log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
|
|
654
|
+
return b_valid;
|
|
655
|
+
},
|
|
656
|
+
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
657
|
+
// https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
|
|
658
|
+
// static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
|
|
659
|
+
// static parse(json) {
|
|
660
|
+
// return this.#ajv_parse_(json);
|
|
661
|
+
// }
|
|
662
|
+
};
|
|
379
663
|
})();
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
664
|
+
var JSON_MsgEffect = (function () {
|
|
665
|
+
return {
|
|
666
|
+
create_with_cause_merge: function (msg_cause, json) {
|
|
667
|
+
const _cause = msg_cause;
|
|
668
|
+
return Object.assign(JSON_Msg.merge(json), { _cause });
|
|
669
|
+
},
|
|
670
|
+
validate: function (json) {
|
|
671
|
+
if (!JSON_Msg.validate(json))
|
|
672
|
+
return false;
|
|
673
|
+
const b_valid = schema_MsgEffect(json);
|
|
674
|
+
if (!b_valid)
|
|
675
|
+
log_(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
|
|
676
|
+
return b_valid;
|
|
677
|
+
}
|
|
678
|
+
};
|
|
395
679
|
})();
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
680
|
+
var JSON_MsgAck = (function () {
|
|
681
|
+
return {
|
|
682
|
+
create_with_cause_Ok: function (msg_cause, b_ok = true) {
|
|
683
|
+
return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
|
|
684
|
+
ack: {
|
|
685
|
+
"ok": b_ok,
|
|
686
|
+
},
|
|
687
|
+
});
|
|
688
|
+
},
|
|
689
|
+
create_with_cause_Expired: function (msg_cause) {
|
|
690
|
+
return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
|
|
691
|
+
ack: {
|
|
692
|
+
"ok": false,
|
|
693
|
+
"expired": true
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
},
|
|
697
|
+
validate: function (json) {
|
|
698
|
+
if (!JSON_MsgEffect.validate(json))
|
|
699
|
+
return false;
|
|
700
|
+
const b_valid = schema_MsgAckEffect(json);
|
|
701
|
+
if (!b_valid)
|
|
702
|
+
log_(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
|
|
703
|
+
return b_valid;
|
|
704
|
+
}
|
|
705
|
+
};
|
|
423
706
|
})();
|
|
424
707
|
|
|
425
708
|
jsonMsg_cjs.JSON_Msg = JSON_Msg;
|
|
426
|
-
jsonMsg_cjs.
|
|
427
|
-
jsonMsg_cjs.
|
|
709
|
+
jsonMsg_cjs.JSON_MsgAck = JSON_MsgAck;
|
|
710
|
+
jsonMsg_cjs.JSON_MsgEffect = JSON_MsgEffect;
|
|
428
711
|
jsonMsg_cjs.l = l_;
|
|
429
712
|
return jsonMsg_cjs;
|
|
430
713
|
}
|
|
431
714
|
|
|
432
715
|
var jsonMsg_cjsExports = requireJsonMsg_cjs();
|
|
433
716
|
|
|
434
|
-
//-------------------------------------------------------------------------------------------------
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
//
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const timeout_id
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const evt = this.arr_events[idx];
|
|
547
|
-
if (evt.dt < cutoff) {
|
|
548
|
-
break; // Stop once we pass the cutoff
|
|
549
|
-
}
|
|
550
|
-
if (predicate(evt)) {
|
|
551
|
-
result.push({ idx, evt });
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
return result; // Newest to oldest order
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// setLogr(obj_logr) {
|
|
559
|
-
// this.logr.toggled = obj_logr;
|
|
560
|
-
// }
|
|
561
|
-
|
|
562
|
-
clear() {
|
|
563
|
-
this.cancelAllTimeouts(); // Clear all timeouts before clearing events
|
|
564
|
-
this.arr_events.length = 0;
|
|
565
|
-
this.map_index_id.clear();
|
|
566
|
-
}
|
|
717
|
+
//-------------------------------------------------------------------------------------------------
|
|
718
|
+
let LOGR_$1 = LOGR.get_instance();
|
|
719
|
+
const log_$1 = LOGR_$1.log;
|
|
720
|
+
const l_$1 = {
|
|
721
|
+
EVENTS: 0b1 << 0,
|
|
722
|
+
TIMEOUTS: 0b1 << 1,
|
|
723
|
+
};
|
|
724
|
+
LOGR_$1.labels = l_$1;
|
|
725
|
+
// LOGR_.toggled= {
|
|
726
|
+
// EVENTS : 1
|
|
727
|
+
// }
|
|
728
|
+
//-------------------------------------------------------------------------------------------------
|
|
729
|
+
class EventLog {
|
|
730
|
+
constructor() {
|
|
731
|
+
this.arr_events = []; // In-memory event store
|
|
732
|
+
this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
|
|
733
|
+
this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
|
|
734
|
+
}
|
|
735
|
+
addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
|
|
736
|
+
const evt = {
|
|
737
|
+
type,
|
|
738
|
+
dt: Date.now(),
|
|
739
|
+
id,
|
|
740
|
+
data,
|
|
741
|
+
timeout_id: null // Will store timeout reference if set
|
|
742
|
+
};
|
|
743
|
+
const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
|
|
744
|
+
let arr_indices = this.map_index_id.get(id);
|
|
745
|
+
if (!arr_indices) {
|
|
746
|
+
arr_indices = [];
|
|
747
|
+
this.map_index_id.set(id, arr_indices);
|
|
748
|
+
}
|
|
749
|
+
arr_indices.push(idx);
|
|
750
|
+
// Set timeout if specified
|
|
751
|
+
if (timeout_ms && timeout_callback) {
|
|
752
|
+
evt.timeout_id = setTimeout(() => {
|
|
753
|
+
if (this.map_timeouts.delete(idx)) {
|
|
754
|
+
evt.timeout_id = null;
|
|
755
|
+
timeout_callback({ idx, evt });
|
|
756
|
+
log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
757
|
+
}
|
|
758
|
+
}, timeout_ms);
|
|
759
|
+
this.map_timeouts.set(idx, evt.timeout_id);
|
|
760
|
+
}
|
|
761
|
+
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
762
|
+
// When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
|
|
763
|
+
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
764
|
+
log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
765
|
+
return { idx, evt };
|
|
766
|
+
}
|
|
767
|
+
cancelTimeout(idx) {
|
|
768
|
+
const timeout_id = this.map_timeouts.get(idx);
|
|
769
|
+
if (timeout_id) {
|
|
770
|
+
clearTimeout(timeout_id);
|
|
771
|
+
this.map_timeouts.delete(idx);
|
|
772
|
+
if (this.arr_events[idx])
|
|
773
|
+
this.arr_events[idx].timeout_id = null;
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
cancelAllTimeouts() {
|
|
779
|
+
for (const [idx, timeout_id] of this.map_timeouts) {
|
|
780
|
+
clearTimeout(timeout_id);
|
|
781
|
+
if (this.arr_events[idx])
|
|
782
|
+
this.arr_events[idx].timeout_id = null;
|
|
783
|
+
}
|
|
784
|
+
this.map_timeouts.clear();
|
|
785
|
+
}
|
|
786
|
+
getEventsById(id, lookback_ms = null) {
|
|
787
|
+
const arr_indices = this.map_index_id.get(id);
|
|
788
|
+
if (!arr_indices?.length)
|
|
789
|
+
return [];
|
|
790
|
+
const result = [];
|
|
791
|
+
const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
|
|
792
|
+
// Single loop with early cutoff
|
|
793
|
+
for (let i = arr_indices.length - 1; i >= 0; i--) {
|
|
794
|
+
const idx = arr_indices[i];
|
|
795
|
+
const evt = this.arr_events[idx];
|
|
796
|
+
if (evt.dt < cutoff)
|
|
797
|
+
break;
|
|
798
|
+
result.push({ idx, evt });
|
|
799
|
+
}
|
|
800
|
+
return result; // Newest to oldest order
|
|
801
|
+
}
|
|
802
|
+
// getRecentEvents(id, lookbackMs) {
|
|
803
|
+
// const cutoff = Date.now() - lookbackMs;
|
|
804
|
+
// return this.events.filter(e => e.id === id && e.dt >= cutoff);
|
|
805
|
+
// }
|
|
806
|
+
getEvents(lookback_ms, predicate) {
|
|
807
|
+
const cutoff = Date.now() - lookback_ms;
|
|
808
|
+
const result = [];
|
|
809
|
+
// Iterate backwards from the end
|
|
810
|
+
for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
|
|
811
|
+
const evt = this.arr_events[idx];
|
|
812
|
+
if (evt.dt < cutoff) {
|
|
813
|
+
break; // Stop once we pass the cutoff
|
|
814
|
+
}
|
|
815
|
+
if (predicate(evt)) {
|
|
816
|
+
result.push({ idx, evt });
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return result; // Newest to oldest order
|
|
820
|
+
}
|
|
821
|
+
// setLogr(obj_logr) {
|
|
822
|
+
// this.logr.toggled = obj_logr;
|
|
823
|
+
// }
|
|
824
|
+
clear() {
|
|
825
|
+
this.cancelAllTimeouts(); // Clear all timeouts before clearing events
|
|
826
|
+
this.arr_events.length = 0;
|
|
827
|
+
this.map_index_id.clear();
|
|
828
|
+
}
|
|
567
829
|
}
|
|
568
830
|
|
|
569
831
|
// interface Event extends Required<EventMinimal> {
|
|
@@ -571,9 +833,6 @@ class EventLog {
|
|
|
571
833
|
// id : string | number;
|
|
572
834
|
// timeout_id : NodeJS.Timeout | null;
|
|
573
835
|
// };
|
|
574
|
-
const k_ERROR = -1;
|
|
575
|
-
const k_NOP = 0;
|
|
576
|
-
// const k_HANDLED = 1;
|
|
577
836
|
const k_TTL = 20000;
|
|
578
837
|
//-------------------------------------------------------------------------------------------------
|
|
579
838
|
const LOGR_ = LOGR.get_instance();
|
|
@@ -593,19 +852,19 @@ class Config {
|
|
|
593
852
|
// Initialize callbacks as no-op functions
|
|
594
853
|
this._callback_msgWarp = (_msg, _json_msg) => {
|
|
595
854
|
console.assert(false, 'callback_msgWarp uninitialized');
|
|
596
|
-
return
|
|
855
|
+
return false;
|
|
597
856
|
};
|
|
598
857
|
this._callback_msgEngage = (_msg, _json_msg) => {
|
|
599
858
|
console.assert(false, 'callback_msgEngage uninitialized');
|
|
600
|
-
return
|
|
859
|
+
return false;
|
|
601
860
|
};
|
|
602
861
|
this._callback_msgAckWarp = (_msg, _json_msg) => {
|
|
603
862
|
console.assert(false, 'callback_msgAckWarp uninitialized');
|
|
604
|
-
return
|
|
863
|
+
return false;
|
|
605
864
|
};
|
|
606
865
|
this._callback_msgAckEngage = (_msg, _json_msg) => {
|
|
607
866
|
console.assert(false, 'callback_msgAckEngage uninitialized');
|
|
608
|
-
return
|
|
867
|
+
return false;
|
|
609
868
|
};
|
|
610
869
|
this._callback_msg_sent_expired = (_msg, _json_msg) => {
|
|
611
870
|
console.assert(false, '_callback_msg_sent_expired uninitialized');
|
|
@@ -640,7 +899,7 @@ class Config {
|
|
|
640
899
|
// }
|
|
641
900
|
// })();
|
|
642
901
|
//-------------------------------------------------------------------------------------------------
|
|
643
|
-
let k_VERSION = "
|
|
902
|
+
let k_VERSION = "2";
|
|
644
903
|
// rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
|
|
645
904
|
// t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
|
|
646
905
|
function time_ttl_rtt_(ttl_msec, rtt_msec) {
|
|
@@ -653,8 +912,8 @@ function time_ttl_rtt_(ttl_msec, rtt_msec) {
|
|
|
653
912
|
}
|
|
654
913
|
var JSON_MsgOptions = (function () {
|
|
655
914
|
return {
|
|
656
|
-
|
|
657
|
-
return jsonMsg_cjsExports.
|
|
915
|
+
create_with_cause_options: function (msg_cause, options) {
|
|
916
|
+
return jsonMsg_cjsExports.JSON_MsgEffect.create_with_msg_merge(msg_cause, {
|
|
658
917
|
options: options,
|
|
659
918
|
"2PhW": k_VERSION
|
|
660
919
|
});
|
|
@@ -707,9 +966,9 @@ var JSON_MsgWarp = (function () {
|
|
|
707
966
|
})();
|
|
708
967
|
var JSON_MsgEngage = (function () {
|
|
709
968
|
return {
|
|
710
|
-
|
|
969
|
+
create_with_Warp: function (json_msgWarp) {
|
|
711
970
|
console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
|
|
712
|
-
return jsonMsg_cjsExports.
|
|
971
|
+
return jsonMsg_cjsExports.JSON_MsgEffect.create_with_cause_merge(json_msgWarp, {
|
|
713
972
|
engage: {
|
|
714
973
|
"ok": true,
|
|
715
974
|
"rtt_msec": Date.now() - Date.parse(json_msgWarp.dt)
|
|
@@ -717,12 +976,12 @@ var JSON_MsgEngage = (function () {
|
|
|
717
976
|
"2PhW": k_VERSION
|
|
718
977
|
});
|
|
719
978
|
},
|
|
720
|
-
validate: function (
|
|
979
|
+
validate: function (json_msgEffect) {
|
|
721
980
|
// if (! JSON_Msg_msg.validate(json))
|
|
722
981
|
// return false;
|
|
723
|
-
if (!JSON_MsgWarp.validate(
|
|
982
|
+
if (!JSON_MsgWarp.validate(json_msgEffect._cause))
|
|
724
983
|
return false;
|
|
725
|
-
if (!schema_MsgEngage(
|
|
984
|
+
if (!schema_MsgEngage(json_msgEffect)) {
|
|
726
985
|
log_(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', schema_MsgEngage.errors]);
|
|
727
986
|
return false;
|
|
728
987
|
}
|
|
@@ -734,23 +993,23 @@ var JSON_MsgAckWarp = (function () {
|
|
|
734
993
|
return {
|
|
735
994
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
736
995
|
// const json_msgAckWarp= structuredClone(json_msgAck);
|
|
737
|
-
// json_msgAckWarp.
|
|
996
|
+
// json_msgAckWarp._cause= _cause;
|
|
738
997
|
// return json_msgAckWarp;
|
|
739
998
|
// }
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
return
|
|
999
|
+
create_with_Warp_Ok: function (json_msgWarp, b_ok = true) {
|
|
1000
|
+
const json_msgAck = jsonMsg_cjsExports.JSON_MsgAck.create_with_cause_Ok(json_msgWarp, b_ok);
|
|
1001
|
+
json_msgAck["2PhW"] = k_VERSION;
|
|
1002
|
+
return json_msgAck;
|
|
744
1003
|
},
|
|
745
1004
|
// create_with_msgExpired : function( json_msgWarp ) {
|
|
746
1005
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp )
|
|
747
1006
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
748
1007
|
// return json_msgAck_msg;
|
|
749
1008
|
// },
|
|
750
|
-
validate: function (
|
|
1009
|
+
validate: function (json_msgAck) {
|
|
751
1010
|
// if (! JSON_MsgAck_msg.validate(json))
|
|
752
1011
|
// return false;
|
|
753
|
-
if (!JSON_MsgWarp.validate(
|
|
1012
|
+
if (!JSON_MsgWarp.validate(json_msgAck._cause))
|
|
754
1013
|
return false;
|
|
755
1014
|
return true;
|
|
756
1015
|
}
|
|
@@ -760,23 +1019,23 @@ var JSON_MsgAckEngage = (function () {
|
|
|
760
1019
|
return {
|
|
761
1020
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
762
1021
|
// const json_msgAckEngage= structuredClone(json_msgAck);
|
|
763
|
-
// json_msgAckEngage.
|
|
1022
|
+
// json_msgAckEngage._cause= _cause;
|
|
764
1023
|
// return json_msgAckEngage;
|
|
765
1024
|
// }
|
|
766
|
-
|
|
767
|
-
const
|
|
768
|
-
|
|
769
|
-
return
|
|
1025
|
+
create_with_Engage_Ok: function (json_msgEngage, b_ok = true) {
|
|
1026
|
+
const json_msgAck = jsonMsg_cjsExports.JSON_MsgAck.create_with_cause_Ok(json_msgEngage, b_ok);
|
|
1027
|
+
json_msgAck["2PhW"] = k_VERSION;
|
|
1028
|
+
return json_msgAck;
|
|
770
1029
|
},
|
|
771
1030
|
// create_with_msgExpired : function( json_msgEngage ) {
|
|
772
1031
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage )
|
|
773
1032
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
774
1033
|
// return json_msgAck_msg;
|
|
775
1034
|
// },
|
|
776
|
-
validate: function (
|
|
1035
|
+
validate: function (json_msgAck) {
|
|
777
1036
|
// if (! JSON_MsgAck_msg.validate(json_msgAck_msg))
|
|
778
1037
|
// return false;
|
|
779
|
-
if (!JSON_MsgEngage.validate(
|
|
1038
|
+
if (!JSON_MsgEngage.validate(json_msgAck._cause))
|
|
780
1039
|
return false;
|
|
781
1040
|
return true;
|
|
782
1041
|
}
|
|
@@ -834,7 +1093,7 @@ class StateEngage extends StateState {
|
|
|
834
1093
|
if (false === state_new instanceof StateAckEngage)
|
|
835
1094
|
return false;
|
|
836
1095
|
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
837
|
-
const json_msgWarp = this.json_msgEngage.
|
|
1096
|
+
const json_msgWarp = this.json_msgEngage._cause;
|
|
838
1097
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
839
1098
|
log_(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
840
1099
|
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
@@ -851,14 +1110,14 @@ class StateAckWarp extends StateState {
|
|
|
851
1110
|
return false;
|
|
852
1111
|
if (!this.json_msgAckWarp.ack.ok)
|
|
853
1112
|
return false;
|
|
854
|
-
if (this.json_msgAckWarp.
|
|
1113
|
+
if (this.json_msgAckWarp._cause.warp.instantaneous)
|
|
855
1114
|
return false;
|
|
856
1115
|
// The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
|
|
857
1116
|
// +STT, so lines up with the Engage timeout
|
|
858
1117
|
// - Engage: T0 +2TTL +RTT; RTT= STT+STT
|
|
859
1118
|
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
860
1119
|
// - STT: Date of the Ack minus date of the Warp.
|
|
861
|
-
const timeout_ms = time_ttl_rtt_(this.json_msgAckWarp.
|
|
1120
|
+
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);
|
|
862
1121
|
log_(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`]);
|
|
863
1122
|
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
864
1123
|
return false;
|
|
@@ -930,7 +1189,7 @@ class TwoPhW_EventLog {
|
|
|
930
1189
|
}
|
|
931
1190
|
_warp(json_msg) {
|
|
932
1191
|
const b_Ack = json_msg.ack !== undefined;
|
|
933
|
-
const json = b_Ack ? json_msg["
|
|
1192
|
+
const json = b_Ack ? json_msg["_cause"] : json_msg;
|
|
934
1193
|
if (json.warp) {
|
|
935
1194
|
return {
|
|
936
1195
|
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Warp]`,
|
|
@@ -940,7 +1199,7 @@ class TwoPhW_EventLog {
|
|
|
940
1199
|
if (json.engage) {
|
|
941
1200
|
return {
|
|
942
1201
|
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
|
|
943
|
-
json_msgWarp: json["
|
|
1202
|
+
json_msgWarp: json["_cause"]
|
|
944
1203
|
};
|
|
945
1204
|
}
|
|
946
1205
|
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
@@ -1014,8 +1273,8 @@ class TwoPhW {
|
|
|
1014
1273
|
if (! validate_Options_delay_(json_msgOptions.options))
|
|
1015
1274
|
return false;
|
|
1016
1275
|
|
|
1017
|
-
if (JSON_MsgWarp.validate(json_msgOptions.
|
|
1018
|
-
const json_msgWarp= json_msgOptions.
|
|
1276
|
+
if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
|
|
1277
|
+
const json_msgWarp= json_msgOptions._cause;
|
|
1019
1278
|
|
|
1020
1279
|
const ctx= get_ctx(json_msgWarp.id);
|
|
1021
1280
|
if (!ctx )
|
|
@@ -1036,7 +1295,7 @@ class TwoPhW {
|
|
|
1036
1295
|
return true;
|
|
1037
1296
|
}
|
|
1038
1297
|
*/
|
|
1039
|
-
return
|
|
1298
|
+
return false;
|
|
1040
1299
|
}
|
|
1041
1300
|
//-------------------------------------------------------------------------------------------------
|
|
1042
1301
|
// sender Source (src)
|
|
@@ -1049,7 +1308,7 @@ class TwoPhW {
|
|
|
1049
1308
|
}));
|
|
1050
1309
|
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
|
|
1051
1310
|
if (!b_changeState)
|
|
1052
|
-
return
|
|
1311
|
+
return false;
|
|
1053
1312
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
1054
1313
|
const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
|
|
1055
1314
|
this.eventLog._addEvent(msg, json_msgWarp, timeout_ms - elapsed_ms, () => {
|
|
@@ -1058,7 +1317,7 @@ class TwoPhW {
|
|
|
1058
1317
|
}
|
|
1059
1318
|
_handler_msgAckWarp(msg, json_msgAckWarp) {
|
|
1060
1319
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
|
|
1061
|
-
const json_msgWarp = json_msgAckWarp.
|
|
1320
|
+
const json_msgWarp = json_msgAckWarp._cause;
|
|
1062
1321
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1063
1322
|
const b_changeState = protocolState.canChangeState(new StateAckWarp(null, {
|
|
1064
1323
|
dt: Date.now(),
|
|
@@ -1066,14 +1325,14 @@ class TwoPhW {
|
|
|
1066
1325
|
}));
|
|
1067
1326
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
|
|
1068
1327
|
if (!b_changeState)
|
|
1069
|
-
return
|
|
1328
|
+
return false;
|
|
1070
1329
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1071
1330
|
this.eventLog._addEvent(msg, json_msgAckWarp);
|
|
1072
1331
|
return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
|
|
1073
1332
|
}
|
|
1074
1333
|
register_msgEngage(msg, json_msgEngage) {
|
|
1075
1334
|
log_(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
|
|
1076
|
-
const json_msgWarp = json_msgEngage.
|
|
1335
|
+
const json_msgWarp = json_msgEngage._cause;
|
|
1077
1336
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1078
1337
|
const b_changeState = protocolState.canChangeState(new StateEngage(null, {
|
|
1079
1338
|
dt: Date.now(),
|
|
@@ -1081,7 +1340,7 @@ class TwoPhW {
|
|
|
1081
1340
|
}));
|
|
1082
1341
|
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
|
|
1083
1342
|
if (!b_changeState)
|
|
1084
|
-
return
|
|
1343
|
+
return false;
|
|
1085
1344
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
|
|
1086
1345
|
const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
|
|
1087
1346
|
this.eventLog._addEvent(msg, json_msgEngage, timeout_ms - elapsed_ms, () => {
|
|
@@ -1090,7 +1349,7 @@ class TwoPhW {
|
|
|
1090
1349
|
}
|
|
1091
1350
|
_handler_msgAckEngage(msg, json_msgAckEngage) {
|
|
1092
1351
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
|
|
1093
|
-
const json_msgWarp = json_msgAckEngage.
|
|
1352
|
+
const json_msgWarp = json_msgAckEngage._cause._cause;
|
|
1094
1353
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1095
1354
|
const b_changeState = protocolState.canChangeState(new StateAckEngage(null, {
|
|
1096
1355
|
dt: Date.now(),
|
|
@@ -1098,7 +1357,7 @@ class TwoPhW {
|
|
|
1098
1357
|
}));
|
|
1099
1358
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
|
|
1100
1359
|
if (!b_changeState)
|
|
1101
|
-
return
|
|
1360
|
+
return false;
|
|
1102
1361
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1103
1362
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
1104
1363
|
return this.config._callback_msgAckEngage(msg, json_msgAckEngage);
|
|
@@ -1114,13 +1373,13 @@ class TwoPhW {
|
|
|
1114
1373
|
}));
|
|
1115
1374
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1116
1375
|
if (!b_changeState)
|
|
1117
|
-
return
|
|
1376
|
+
return false;
|
|
1118
1377
|
this.eventLog._addEvent(msg, json_msgWarp);
|
|
1119
1378
|
return this.config._callback_msgWarp(msg, json_msgWarp);
|
|
1120
1379
|
}
|
|
1121
1380
|
register_msgAckWarp(msg, json_msgAckWarp) {
|
|
1122
1381
|
log_(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
|
|
1123
|
-
const json_msgWarp = json_msgAckWarp.
|
|
1382
|
+
const json_msgWarp = json_msgAckWarp._cause;
|
|
1124
1383
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1125
1384
|
const b_changeState = protocolState.canChangeState(new StateAckWarp(null, {
|
|
1126
1385
|
dt: Date.now(),
|
|
@@ -1128,7 +1387,7 @@ class TwoPhW {
|
|
|
1128
1387
|
}));
|
|
1129
1388
|
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1130
1389
|
if (!b_changeState)
|
|
1131
|
-
return
|
|
1390
|
+
return false;
|
|
1132
1391
|
const elapsed_ms = Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
1133
1392
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
|
|
1134
1393
|
this.eventLog._addEvent(msg, json_msgAckWarp, timeout_ms - elapsed_ms, () => {
|
|
@@ -1137,7 +1396,7 @@ class TwoPhW {
|
|
|
1137
1396
|
}
|
|
1138
1397
|
_handler_msgEngage(msg, json_msgEngage) {
|
|
1139
1398
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
|
|
1140
|
-
const json_msgWarp = json_msgEngage
|
|
1399
|
+
const json_msgWarp = json_msgEngage._cause;
|
|
1141
1400
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1142
1401
|
const b_changeState = protocolState.canChangeState(new StateEngage(null, {
|
|
1143
1402
|
dt: Date.now(),
|
|
@@ -1145,14 +1404,14 @@ class TwoPhW {
|
|
|
1145
1404
|
}));
|
|
1146
1405
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1147
1406
|
if (!b_changeState)
|
|
1148
|
-
return
|
|
1407
|
+
return false;
|
|
1149
1408
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1150
1409
|
this.eventLog._addEvent(msg, json_msgEngage);
|
|
1151
1410
|
return this.config._callback_msgEngage(msg, json_msgEngage);
|
|
1152
1411
|
}
|
|
1153
1412
|
register_msgAckEngage(msg, json_msgAckEngage) {
|
|
1154
1413
|
log_(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
|
|
1155
|
-
const json_msgWarp = json_msgAckEngage.
|
|
1414
|
+
const json_msgWarp = json_msgAckEngage._cause._cause;
|
|
1156
1415
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1157
1416
|
const b_changeState = protocolState.canChangeState(new StateAckEngage(null, {
|
|
1158
1417
|
dt: Date.now(),
|
|
@@ -1160,33 +1419,32 @@ class TwoPhW {
|
|
|
1160
1419
|
}));
|
|
1161
1420
|
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1162
1421
|
if (!b_changeState)
|
|
1163
|
-
return
|
|
1422
|
+
return false;
|
|
1164
1423
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
1165
1424
|
}
|
|
1166
1425
|
//-------------------------------------------------------------------------------------------------
|
|
1167
|
-
|
|
1168
|
-
log_(l_.HANDLERS, () => ['
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
return k_NOP;
|
|
1426
|
+
handler_json_msgAck(msg, json_msgAck) {
|
|
1427
|
+
log_(l_.HANDLERS, () => ['handler_json_msgAck: ', json_msgAck]);
|
|
1428
|
+
if (JSON_MsgAckWarp.validate(json_msgAck) && this._handler_msgAckWarp(msg, json_msgAck))
|
|
1429
|
+
return true;
|
|
1430
|
+
if (JSON_MsgAckEngage.validate(json_msgAck) && this._handler_msgAckEngage(msg, json_msgAck))
|
|
1431
|
+
return true;
|
|
1432
|
+
return false;
|
|
1175
1433
|
}
|
|
1176
|
-
|
|
1177
|
-
log_(l_.HANDLERS, () => ['
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1434
|
+
handler_json_msgEffect(msg, json_msgEffect) {
|
|
1435
|
+
log_(l_.HANDLERS, () => ['handler_json_msgEffect: ', json_msgEffect]);
|
|
1436
|
+
if (jsonMsg_cjsExports.JSON_MsgAck.validate(json_msgEffect) && this.handler_json_msgAck(msg, json_msgEffect))
|
|
1437
|
+
return true;
|
|
1438
|
+
if (JSON_MsgEngage.validate(json_msgEffect) && this._handler_msgEngage(msg, json_msgEffect))
|
|
1439
|
+
return true;
|
|
1181
1440
|
// if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
|
|
1182
1441
|
// return true;
|
|
1183
|
-
return
|
|
1442
|
+
return false;
|
|
1184
1443
|
}
|
|
1185
1444
|
handler_json_msg(msg, json_msg) {
|
|
1186
1445
|
log_(l_.HANDLERS, () => ['handler_json_msg: ', json_msg]);
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
return ret;
|
|
1446
|
+
if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg))
|
|
1447
|
+
return true;
|
|
1190
1448
|
// https://attacomsian.com/blog/javascript-iterate-objects
|
|
1191
1449
|
// Object.keys(json_msg).forEach((key, index) => {
|
|
1192
1450
|
// if (key == 'dt')
|
|
@@ -1195,30 +1453,15 @@ class TwoPhW {
|
|
|
1195
1453
|
// return;
|
|
1196
1454
|
// console.log(`${key}: ${json_msg[key]}`);
|
|
1197
1455
|
// });
|
|
1198
|
-
return
|
|
1456
|
+
return false;
|
|
1199
1457
|
}
|
|
1200
1458
|
handler_json(msg, json) {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
if (JSON_MsgAckEngage.validate(json) && (ret = this._handler_msgAckEngage(msg, json)))
|
|
1208
|
-
return ret;
|
|
1209
|
-
return k_NOP;
|
|
1210
|
-
}
|
|
1211
|
-
let ret;
|
|
1212
|
-
if (JSON_MsgEngage.validate(json) && (ret = this._handler_msgEngage(msg, json)))
|
|
1213
|
-
return ret;
|
|
1214
|
-
return k_NOP;
|
|
1215
|
-
}
|
|
1216
|
-
let ret;
|
|
1217
|
-
if (JSON_MsgWarp.validate(json) && (ret = this._handler_msgWarp(msg, json)))
|
|
1218
|
-
return ret;
|
|
1219
|
-
return k_NOP;
|
|
1220
|
-
}
|
|
1221
|
-
return k_NOP;
|
|
1459
|
+
log_(l_.HANDLERS, () => ['handler_json: ', json]);
|
|
1460
|
+
if (jsonMsg_cjsExports.JSON_MsgEffect.validate(json) && this.handler_json_msgEffect(msg, json))
|
|
1461
|
+
return true;
|
|
1462
|
+
if (jsonMsg_cjsExports.JSON_Msg.validate(json) && this.handler_json_msg(msg, json))
|
|
1463
|
+
return true;
|
|
1464
|
+
return false;
|
|
1222
1465
|
}
|
|
1223
1466
|
}
|
|
1224
1467
|
|