@rootintf/protocol-2phw 2.0.3-api.2 → 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.
- package/dist/EventLog-mem.d.mts +2 -5
- package/dist/twoPhW.cjs.js +416 -297
- package/dist/twoPhW.d.ts +23 -23
- package/dist/twoPhW.es.mjs +416 -297
- package/package.json +3 -3
- package/src/EventLog-mem.mjs +9 -15
- package/src/index.ts +1 -1
- package/src/twoPhW.ts +70 -70
- package/tests/event-log-mem.spec.mjs +9 -4
- package/tests/twoPhW-new.spec.mjs +49 -30
- package/dist/index.d.ts +0 -1
package/dist/twoPhW.cjs.js
CHANGED
|
@@ -178,198 +178,411 @@ function validate20(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
178
178
|
} validate20.errors = vErrors; return errors === 0; }
|
|
179
179
|
validate20.evaluated = { "props": { "engage": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
|
|
180
180
|
|
|
181
|
+
// https://stackoverflow.com/questions/4602141/variable-name-as-a-string-in-javascript
|
|
181
182
|
// console.log('OUT', __name({variableName}) );
|
|
182
|
-
|
|
183
183
|
//-------------------------------------------------------------------------------------------------
|
|
184
|
-
|
|
185
184
|
function l_length_(obj_labels) {
|
|
186
|
-
if (!
|
|
187
|
-
|
|
185
|
+
if (!obj_labels || typeof obj_labels !== 'object')
|
|
186
|
+
throw new Error('obj_labels must be an object');
|
|
188
187
|
const obj_1label = Object.values(obj_labels);
|
|
189
|
-
if (!
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
if (!obj_1label.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
189
|
+
throw new Error('All values must be finite numbers');
|
|
192
190
|
const labels = Object.values(obj_labels);
|
|
193
|
-
if (labels.length === 0)
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
if (labels.length === 0)
|
|
192
|
+
return 1; // Empty object case, start at 1
|
|
196
193
|
const value_max = Math.max(...labels);
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
if (value_max <= 0)
|
|
195
|
+
return 1;
|
|
199
196
|
const bit_highest = Math.floor(Math.log2(value_max));
|
|
200
197
|
return 1 << (bit_highest + 1);
|
|
201
198
|
}
|
|
202
|
-
|
|
203
199
|
function l_array_(arr_labels, start = 1) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (!
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
if (!Array.isArray(arr_labels))
|
|
201
|
+
throw new Error('arr_labels must be an array');
|
|
202
|
+
if (!Number.isSafeInteger(start) || start < 0)
|
|
203
|
+
throw new Error('start must be a safe, non-negative integer');
|
|
209
204
|
return Object.freeze(arr_labels.reduce((acc, key, index) => {
|
|
210
205
|
acc[key] = start << index;
|
|
211
206
|
return acc;
|
|
212
207
|
}, {}));
|
|
213
208
|
}
|
|
214
|
-
|
|
215
209
|
function l_concat_(obj_labels, arg) {
|
|
216
|
-
if (!
|
|
217
|
-
|
|
210
|
+
if (!obj_labels || typeof obj_labels !== 'object')
|
|
211
|
+
throw new Error('obj_labels must be an object');
|
|
218
212
|
const obj_1label = Object.values(obj_labels);
|
|
219
|
-
if (!
|
|
220
|
-
|
|
221
|
-
if (!
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const next_pos = l_length_(obj_labels);
|
|
231
|
-
const arg_entries = Object.entries(arg);
|
|
213
|
+
if (!obj_1label.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
214
|
+
throw new Error('All values must be finite numbers');
|
|
215
|
+
if (!arg || (typeof arg !== 'object' && !Array.isArray(arg)))
|
|
216
|
+
throw new Error('arg must be an object or array');
|
|
217
|
+
if (Array.isArray(arg)) {
|
|
218
|
+
const len = l_length_(obj_labels);
|
|
219
|
+
const arr_labels_new = l_array_(arg, len);
|
|
220
|
+
return l_concat_(obj_labels, arr_labels_new);
|
|
221
|
+
}
|
|
222
|
+
const next_pos = l_length_(obj_labels);
|
|
223
|
+
const arg_entries = Object.entries(arg);
|
|
232
224
|
const result = Object.create(null);
|
|
233
225
|
Object.entries(obj_labels).forEach(([k, v]) => {
|
|
234
|
-
if (k !== '__proto__' && k !== 'constructor')
|
|
235
|
-
|
|
226
|
+
if (k !== '__proto__' && k !== 'constructor')
|
|
227
|
+
result[k] = v;
|
|
236
228
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
min_arg = value;
|
|
245
|
-
}
|
|
229
|
+
let min_arg = Infinity;
|
|
230
|
+
for (const [, value] of arg_entries) {
|
|
231
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
232
|
+
continue; // Skip non-numeric
|
|
233
|
+
if (value > 0 && value < min_arg)
|
|
234
|
+
min_arg = value;
|
|
235
|
+
}
|
|
246
236
|
// Shift only if min_arg is less than next_pos
|
|
247
|
-
const shift = min_arg === Infinity || min_arg >= next_pos
|
|
248
|
-
? 0
|
|
237
|
+
const shift = min_arg === Infinity || min_arg >= next_pos
|
|
238
|
+
? 0
|
|
249
239
|
: Math.floor(Math.log2(next_pos / min_arg));
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
240
|
+
for (const [key, value] of arg_entries) {
|
|
241
|
+
if (!(key in result)) {
|
|
242
|
+
result[key] = value === 0 ? 0 : value << shift;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return Object.freeze(result);
|
|
246
|
+
}
|
|
247
|
+
function l_merge_(obj_labels1, obj_labels2) {
|
|
248
|
+
if (!obj_labels1 || typeof obj_labels1 !== 'object')
|
|
249
|
+
throw new Error('obj_labels must be an object');
|
|
250
|
+
const obj_1label1 = Object.values(obj_labels1);
|
|
251
|
+
if (!obj_1label1.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
252
|
+
throw new Error('All values must be finite numbers');
|
|
253
|
+
if (!obj_labels2 || typeof obj_labels2 !== 'object')
|
|
254
|
+
throw new Error('obj_labels must be an object');
|
|
255
|
+
const obj_1label2 = Object.values(obj_labels2);
|
|
256
|
+
if (!obj_1label2.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
257
|
+
throw new Error('All values must be finite numbers');
|
|
258
|
+
const result = Object.create(null);
|
|
259
|
+
Object.entries(obj_labels1).forEach(([k, v]) => {
|
|
260
|
+
if (k !== '__proto__' && k !== 'constructor')
|
|
261
|
+
result[k] = v;
|
|
262
|
+
});
|
|
263
|
+
const set_values = new Set(Object.values(obj_labels1)); // Track all used bit values
|
|
264
|
+
// Find the highest bit position to start shifting from if needed
|
|
265
|
+
const value_highest = Math.max(0, ...Array.from(set_values));
|
|
266
|
+
let next_shift = value_highest ? Math.floor(Math.log2(value_highest)) + 1 : 0;
|
|
267
|
+
// Process second set
|
|
268
|
+
for (const [key, value] of Object.entries(obj_labels2)) {
|
|
269
|
+
if (key in result) {
|
|
270
|
+
// Same key: Values must match
|
|
271
|
+
if (result[key] !== value) {
|
|
272
|
+
throw new Error(`Key '${key}' has conflicting values: ${result[key]} (obj_labels1) vs ${value} (obj_labels2)`);
|
|
273
|
+
}
|
|
274
|
+
// No action needed if values match, already in result
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
let maxIterations = 1000;
|
|
278
|
+
// New key: Add if value is unique, otherwise shift
|
|
279
|
+
let value_new = value;
|
|
280
|
+
while (set_values.has(value_new) && maxIterations--) {
|
|
281
|
+
value_new = 1 << next_shift++;
|
|
282
|
+
}
|
|
283
|
+
if (maxIterations <= 0)
|
|
284
|
+
throw new Error('Too many collisions in l_merge_');
|
|
285
|
+
result[key] = value_new;
|
|
286
|
+
set_values.add(value_new);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return Object.freeze(result);
|
|
258
290
|
}
|
|
259
|
-
|
|
260
291
|
function l_LL_(obj, x) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return Object.freeze(obj_new);
|
|
292
|
+
if (!obj || typeof obj !== 'object')
|
|
293
|
+
throw new Error('obj must be an object');
|
|
294
|
+
if (!Number.isSafeInteger(x) || x < 0)
|
|
295
|
+
throw new Error('Shift value must be a safe, non-negative integer');
|
|
296
|
+
const obj_new = {};
|
|
297
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
298
|
+
if (typeof v !== 'number' || !Number.isFinite(v))
|
|
299
|
+
continue; // Skip non-numeric
|
|
300
|
+
obj_new[k] = v << x;
|
|
301
|
+
}
|
|
302
|
+
return Object.freeze(obj_new);
|
|
273
303
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
304
|
+
function l_RR_(obj, x) {
|
|
305
|
+
if (!obj || typeof obj !== 'object')
|
|
306
|
+
throw new Error('obj must be an object');
|
|
307
|
+
if (!Number.isSafeInteger(x) || x < 0)
|
|
308
|
+
throw new Error('Shift value must be a safe, non-negative integer');
|
|
309
|
+
const obj_new = {};
|
|
310
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
311
|
+
if (typeof v !== 'number' || !Number.isFinite(v))
|
|
312
|
+
continue; // Skip non-numeric
|
|
313
|
+
obj_new[k] = v >> x;
|
|
314
|
+
}
|
|
315
|
+
return Object.freeze(obj_new);
|
|
281
316
|
}
|
|
282
|
-
|
|
283
317
|
//-------------------------------------------------------------------------------------------------
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
318
|
+
function handler_default_( /* ... */) {
|
|
319
|
+
// https://stackoverflow.com/questions/18746440/passing-multiple-arguments-to-console-log
|
|
320
|
+
var args = Array.prototype.slice.call(arguments);
|
|
321
|
+
console.log.apply(console, args);
|
|
322
|
+
}
|
|
323
|
+
function l_toBigInt_(obj_labels, obj, ignore = false) {
|
|
324
|
+
if (!obj_labels || typeof obj_labels !== 'object')
|
|
325
|
+
throw new Error('obj_labels must be an object');
|
|
326
|
+
if (!obj || typeof obj !== 'object')
|
|
327
|
+
throw new Error('obj must be an object');
|
|
328
|
+
let bigint_l = BigInt(0);
|
|
329
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
330
|
+
if ((ignore || v) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
331
|
+
bigint_l |= BigInt(obj_labels[k]);
|
|
332
|
+
// console.log('0b'+ bigInt.toString(2) );
|
|
333
|
+
}
|
|
334
|
+
return bigint_l;
|
|
335
|
+
}
|
|
336
|
+
function lRef(initial) {
|
|
337
|
+
if (arguments.length === 0 || initial === undefined) {
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
let value = initial;
|
|
341
|
+
return {
|
|
342
|
+
get: () => value,
|
|
343
|
+
set: (newVal) => { value = newVal; }
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/*
|
|
347
|
+
const l_ = {
|
|
348
|
+
get VALIDATION() { return logr_.lref.get().VALIDATION; }
|
|
298
349
|
}
|
|
299
350
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
313
|
-
return false;
|
|
314
|
-
|
|
315
|
-
const args = argsFn();
|
|
316
|
-
_handler_log.apply(this, args);
|
|
317
|
-
// _handler_log.apply(this, args);
|
|
318
|
-
return true;
|
|
319
|
-
}
|
|
351
|
+
function createBitFlags(ref) {
|
|
352
|
+
// Create a proxy so that any property access computes the current bit
|
|
353
|
+
return new Proxy({}, {
|
|
354
|
+
get(target, prop, receiver) {
|
|
355
|
+
const positions = ref.get(); // get current { VALIDATION: n, ... }
|
|
356
|
+
const position = positions[prop]; // e.g., positions['VALIDATION']
|
|
357
|
+
|
|
358
|
+
if (position === undefined) {
|
|
359
|
+
// Optional: warn or return 0 for unknown keys
|
|
360
|
+
console.warn(`Unknown bitflag key: ${String(prop)}`);
|
|
361
|
+
return 0;
|
|
362
|
+
}
|
|
320
363
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
_handler_log = fx;
|
|
324
|
-
},
|
|
325
|
-
get handler() {
|
|
326
|
-
return _handler_log;
|
|
327
|
-
},
|
|
364
|
+
return 0b1 << position; // or 1 << position
|
|
365
|
+
},
|
|
328
366
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
},
|
|
367
|
+
// Optional: make Object.keys(l_) show the actual keys
|
|
368
|
+
ownKeys(target) {
|
|
369
|
+
return Object.keys(ref.get());
|
|
370
|
+
},
|
|
334
371
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
372
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
373
|
+
return {
|
|
374
|
+
enumerable: true,
|
|
375
|
+
configurable: true,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
340
380
|
|
|
341
|
-
|
|
342
|
-
set toggled(obj_toggled) {
|
|
343
|
-
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
344
|
-
},
|
|
381
|
+
type BitPositions = Record<string, number>;
|
|
345
382
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
383
|
+
function createBitFlags<T extends BitPositions>(ref: { get: () => T }) {
|
|
384
|
+
return new Proxy({} as { [K in keyof T]: number }, {
|
|
385
|
+
get(target, prop: string | symbol) {
|
|
386
|
+
if (typeof prop !== 'string') return undefined;
|
|
387
|
+
const positions = ref.get();
|
|
388
|
+
const position = positions[prop as keyof T];
|
|
389
|
+
if (position === undefined) return 0;
|
|
390
|
+
return 1 << position;
|
|
391
|
+
},
|
|
392
|
+
ownKeys() {
|
|
393
|
+
return Object.keys(ref.get());
|
|
394
|
+
},
|
|
395
|
+
getOwnPropertyDescriptor() {
|
|
396
|
+
return { enumerable: true, configurable: true };
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
*/
|
|
401
|
+
function create_Referenced_l_(ref) {
|
|
402
|
+
return new Proxy({}, {
|
|
403
|
+
get(target, prop) {
|
|
404
|
+
if (typeof prop !== 'string')
|
|
405
|
+
return undefined;
|
|
406
|
+
// if (prop === 'get') {
|
|
407
|
+
// return () => {
|
|
408
|
+
// const positions = ref.get();
|
|
409
|
+
// const result: Partial<Record<keyof T, number>> = {};
|
|
410
|
+
// for (const key in positions) {
|
|
411
|
+
// result[key as keyof T] = positions[key];
|
|
412
|
+
// }
|
|
413
|
+
// return result as Record<keyof T, number>;
|
|
414
|
+
// };
|
|
415
|
+
// }
|
|
416
|
+
if (prop === 'get')
|
|
417
|
+
return () => ref.get();
|
|
418
|
+
const positions = ref.get();
|
|
419
|
+
const value = positions[prop];
|
|
420
|
+
if (value === undefined)
|
|
421
|
+
return 0;
|
|
422
|
+
return value;
|
|
423
|
+
},
|
|
424
|
+
ownKeys() {
|
|
425
|
+
return Object.keys(ref.get());
|
|
426
|
+
},
|
|
427
|
+
getOwnPropertyDescriptor() {
|
|
428
|
+
return { enumerable: true, configurable: true };
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
const LOGR = (function () {
|
|
433
|
+
let _instance; // Private variable to hold the single instance
|
|
434
|
+
// Module-level state would work - but only when the module is loaded once.
|
|
435
|
+
// Your bundler is currently bundling @knev/bitlogr into your distribution file,
|
|
436
|
+
// creating a second copy. The Global Symbol approach would work around this,
|
|
437
|
+
// but it's treating the symptom, not the cause.
|
|
438
|
+
const GLOBAL_KEY = Symbol.for('@knev/bitlogr/LOGR');
|
|
439
|
+
// The real issue is your build configuration bundling dependencies that should remain external.
|
|
440
|
+
// rollup.config.mjs: external: ['@knev/bitlogr', 'uuid'], // Don't bundle these
|
|
441
|
+
function _create_instance() {
|
|
442
|
+
const _id = Math.random();
|
|
443
|
+
if (globalThis.LOGR_ENABLED ?? true)
|
|
444
|
+
console.log('creating LOGR instance:', _id);
|
|
445
|
+
// Private state (replacing constructor properties)
|
|
446
|
+
let _Bint_toggled = BigInt(0);
|
|
447
|
+
let _handler_log = handler_default_;
|
|
448
|
+
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
449
|
+
// console.log('_log_fxn: ', BigInt(nr_logged), _Bint_toggled, (BigInt(nr_logged) & _Bint_toggled));
|
|
450
|
+
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
451
|
+
return;
|
|
452
|
+
const args = argsFn();
|
|
453
|
+
_handler_log.apply(this, args);
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
_id, // for testing
|
|
457
|
+
get handler() { return _handler_log; },
|
|
458
|
+
set handler(fx) {
|
|
459
|
+
_handler_log = fx;
|
|
460
|
+
},
|
|
461
|
+
get toggled() { return _Bint_toggled; },
|
|
462
|
+
// toggle(obj_labels, obj_toggled) {
|
|
463
|
+
// _Bint_toggled= l_toBigInt_(obj_labels, obj_toggled);
|
|
464
|
+
// },
|
|
465
|
+
toggle(labels, obj_toggled) {
|
|
466
|
+
const obj_labels = typeof labels?.get === 'function'
|
|
467
|
+
? labels.get()
|
|
468
|
+
: labels;
|
|
469
|
+
// console.log('obj_labels', obj_labels)
|
|
470
|
+
_Bint_toggled = l_toBigInt_(obj_labels, obj_toggled);
|
|
471
|
+
},
|
|
472
|
+
// Core internal log function (exposed only to created loggers)
|
|
473
|
+
_log_fxn,
|
|
474
|
+
create(options = {}) {
|
|
475
|
+
// This constant will be replaced at build time
|
|
476
|
+
if (!(globalThis.LOGR_ENABLED ?? true)) {
|
|
477
|
+
return {
|
|
478
|
+
_obj_labels: undefined, // optional: keep shape compatible if needed
|
|
479
|
+
log: () => { }, // does nothing
|
|
480
|
+
raw: () => { }, // does nothing
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const _logger = {
|
|
484
|
+
// _lref_labels: (options.arr_labels === undefined) ? undefined : lRef( l_array_(options.arr_labels) ),
|
|
485
|
+
_lref_labels: (options.labels === undefined)
|
|
486
|
+
? undefined
|
|
487
|
+
: lRef(options.labels),
|
|
488
|
+
get l() {
|
|
489
|
+
// Always create a fresh proxy pointing to the current labels
|
|
490
|
+
return create_Referenced_l_({
|
|
491
|
+
get: () => this._lref_labels?.get() || {}
|
|
492
|
+
});
|
|
493
|
+
},
|
|
494
|
+
get lref() { return this._lref_labels; },
|
|
495
|
+
set lref(lref_labels_new) {
|
|
496
|
+
this._lref_labels = lref_labels_new;
|
|
497
|
+
},
|
|
498
|
+
log(nr_logged, argsFn) {
|
|
499
|
+
// This constant will be replaced at build time
|
|
500
|
+
if (!(globalThis.LOGR_ENABLED ?? true))
|
|
501
|
+
return;
|
|
502
|
+
_log_fxn.call(this, nr_logged, argsFn);
|
|
503
|
+
},
|
|
504
|
+
// Optional shorthand for common cases
|
|
505
|
+
raw(...args) {
|
|
506
|
+
_handler_log.apply(this, args);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
return _logger;
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
// Public interface
|
|
514
|
+
return {
|
|
515
|
+
get_instance() {
|
|
516
|
+
if (!(globalThis.LOGR_USE_GLOBAL_KEY ?? true)) {
|
|
517
|
+
if (!_instance)
|
|
518
|
+
_instance = _create_instance(); // Lazy initialization
|
|
519
|
+
return _instance;
|
|
349
520
|
}
|
|
350
|
-
|
|
351
|
-
|
|
521
|
+
if (!globalThis[GLOBAL_KEY])
|
|
522
|
+
globalThis[GLOBAL_KEY] = _create_instance();
|
|
523
|
+
return globalThis[GLOBAL_KEY];
|
|
524
|
+
},
|
|
525
|
+
// For testing only - reset the singleton
|
|
526
|
+
_reset_for_testing() {
|
|
527
|
+
delete globalThis[GLOBAL_KEY];
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
})();
|
|
352
531
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
532
|
+
var logr_es = /*#__PURE__*/Object.freeze({
|
|
533
|
+
__proto__: null,
|
|
534
|
+
LOGR: LOGR,
|
|
535
|
+
_create_Referenced_l: create_Referenced_l_,
|
|
536
|
+
lRef: lRef,
|
|
537
|
+
l_LL: l_LL_,
|
|
538
|
+
l_RR: l_RR_,
|
|
539
|
+
l_array: l_array_,
|
|
540
|
+
l_concat: l_concat_,
|
|
541
|
+
l_length: l_length_,
|
|
542
|
+
l_merge: l_merge_
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
function getAugmentedNamespace(n) {
|
|
546
|
+
if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
|
|
547
|
+
var f = n.default;
|
|
548
|
+
if (typeof f == "function") {
|
|
549
|
+
var a = function a () {
|
|
550
|
+
var isInstance = false;
|
|
551
|
+
try {
|
|
552
|
+
isInstance = this instanceof a;
|
|
553
|
+
} catch {}
|
|
554
|
+
if (isInstance) {
|
|
555
|
+
return Reflect.construct(f, arguments, this.constructor);
|
|
358
556
|
}
|
|
359
|
-
return
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
})
|
|
557
|
+
return f.apply(this, arguments);
|
|
558
|
+
};
|
|
559
|
+
a.prototype = f.prototype;
|
|
560
|
+
} else a = {};
|
|
561
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
|
562
|
+
Object.keys(n).forEach(function (k) {
|
|
563
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
564
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
565
|
+
enumerable: true,
|
|
566
|
+
get: function () {
|
|
567
|
+
return n[k];
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
return a;
|
|
572
|
+
}
|
|
364
573
|
|
|
365
574
|
var jsonMsg_cjs = {};
|
|
366
575
|
|
|
576
|
+
var require$$0 = /*@__PURE__*/getAugmentedNamespace(logr_es);
|
|
577
|
+
|
|
367
578
|
var hasRequiredJsonMsg_cjs;
|
|
368
579
|
|
|
369
580
|
function requireJsonMsg_cjs () {
|
|
370
581
|
if (hasRequiredJsonMsg_cjs) return jsonMsg_cjs;
|
|
371
582
|
hasRequiredJsonMsg_cjs = 1;
|
|
372
583
|
|
|
584
|
+
var bitlogr = require$$0;
|
|
585
|
+
|
|
373
586
|
const schema_Msg = validate18;
|
|
374
587
|
function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
|
|
375
588
|
evaluated0.props = undefined;
|
|
@@ -539,105 +752,12 @@ function requireJsonMsg_cjs () {
|
|
|
539
752
|
return _v4(options);
|
|
540
753
|
}
|
|
541
754
|
|
|
542
|
-
// console.log('OUT', __name({variableName}) );
|
|
543
|
-
|
|
544
|
-
|
|
545
755
|
//-------------------------------------------------------------------------------------------------
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
console.log.apply(console, args);
|
|
551
|
-
}
|
|
552
|
-
|
|
756
|
+
const LOGR_ = bitlogr.LOGR.get_instance();
|
|
757
|
+
const logr_ = LOGR_.create({ labels: bitlogr.l_array(['VALIDATION', 'DROPS', 'HANDLERS']) });
|
|
758
|
+
const l_ = logr_.l;
|
|
759
|
+
// console.log('File location:', import.meta.url, '[Implementation]');
|
|
553
760
|
//-------------------------------------------------------------------------------------------------
|
|
554
|
-
|
|
555
|
-
function l_toBigInt_(obj_labels, obj, ignore= false) {
|
|
556
|
-
if (! obj_labels || typeof obj_labels !== 'object')
|
|
557
|
-
throw new Error('obj_labels must be an object');
|
|
558
|
-
if (! obj || typeof obj !== 'object')
|
|
559
|
-
throw new Error('obj must be an object');
|
|
560
|
-
|
|
561
|
-
let bigInt = BigInt(0);
|
|
562
|
-
for (const [k,v] of Object.entries(obj)) {
|
|
563
|
-
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
564
|
-
bigInt|= BigInt( obj_labels[k] );
|
|
565
|
-
// console.log('0b'+ bigInt.toString(2) );
|
|
566
|
-
}
|
|
567
|
-
return bigInt;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// console.log(l_toBigInt_({},{}))
|
|
571
|
-
|
|
572
|
-
const LOGR = (function () {
|
|
573
|
-
let _instance; // Private variable to hold the single instance
|
|
574
|
-
|
|
575
|
-
function _create_instance() {
|
|
576
|
-
// Private state (replacing constructor properties)
|
|
577
|
-
let _handler_log = handler_default_;
|
|
578
|
-
let _obj_labels = undefined;
|
|
579
|
-
let _Bint_toggled = BigInt(0);
|
|
580
|
-
|
|
581
|
-
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
582
|
-
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
583
|
-
return false;
|
|
584
|
-
|
|
585
|
-
const args = argsFn();
|
|
586
|
-
_handler_log.apply(this, args);
|
|
587
|
-
// _handler_log.apply(this, args);
|
|
588
|
-
return true;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
return {
|
|
592
|
-
set handler(fx) {
|
|
593
|
-
_handler_log = fx;
|
|
594
|
-
},
|
|
595
|
-
get handler() {
|
|
596
|
-
return _handler_log;
|
|
597
|
-
},
|
|
598
|
-
|
|
599
|
-
get labels() { return _obj_labels; },
|
|
600
|
-
set labels(obj) {
|
|
601
|
-
_obj_labels = obj;
|
|
602
|
-
_Bint_toggled = BigInt(0);
|
|
603
|
-
},
|
|
604
|
-
|
|
605
|
-
// put= function(label, abbrv) {
|
|
606
|
-
// let name= __name(label);
|
|
607
|
-
// _labels[name]= label[name];
|
|
608
|
-
// console.log(_labels);
|
|
609
|
-
// }
|
|
610
|
-
|
|
611
|
-
get toggled() { return _Bint_toggled; },
|
|
612
|
-
set toggled(obj_toggled) {
|
|
613
|
-
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
614
|
-
},
|
|
615
|
-
|
|
616
|
-
log(nr_logged, argsFn) {
|
|
617
|
-
|
|
618
|
-
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
// Public interface
|
|
624
|
-
return {
|
|
625
|
-
get_instance() {
|
|
626
|
-
if (!_instance) {
|
|
627
|
-
_instance = _create_instance(); // Lazy initialization
|
|
628
|
-
}
|
|
629
|
-
return _instance;
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
})();
|
|
634
|
-
|
|
635
|
-
let LOGR_ = LOGR.get_instance();
|
|
636
|
-
const log_ = LOGR_.log;
|
|
637
|
-
const l_ = {
|
|
638
|
-
VALIDATION: 0b1 << 0,
|
|
639
|
-
};
|
|
640
|
-
LOGR_.labels = l_;
|
|
641
761
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
642
762
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
643
763
|
var JSON_Msg = (function () {
|
|
@@ -652,7 +772,7 @@ function requireJsonMsg_cjs () {
|
|
|
652
772
|
validate: function (json) {
|
|
653
773
|
const b_valid = schema_Msg(json);
|
|
654
774
|
if (!b_valid)
|
|
655
|
-
|
|
775
|
+
logr_.log(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
|
|
656
776
|
return b_valid;
|
|
657
777
|
},
|
|
658
778
|
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
@@ -674,7 +794,7 @@ function requireJsonMsg_cjs () {
|
|
|
674
794
|
return false;
|
|
675
795
|
const b_valid = schema_MsgEffect(json);
|
|
676
796
|
if (!b_valid)
|
|
677
|
-
|
|
797
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
|
|
678
798
|
return b_valid;
|
|
679
799
|
}
|
|
680
800
|
};
|
|
@@ -701,7 +821,7 @@ function requireJsonMsg_cjs () {
|
|
|
701
821
|
return false;
|
|
702
822
|
const b_valid = schema_MsgAckEffect(json);
|
|
703
823
|
if (!b_valid)
|
|
704
|
-
|
|
824
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
|
|
705
825
|
return b_valid;
|
|
706
826
|
}
|
|
707
827
|
};
|
|
@@ -710,7 +830,7 @@ function requireJsonMsg_cjs () {
|
|
|
710
830
|
jsonMsg_cjs.JSON_Msg = JSON_Msg;
|
|
711
831
|
jsonMsg_cjs.JSON_MsgAck = JSON_MsgAck;
|
|
712
832
|
jsonMsg_cjs.JSON_MsgEffect = JSON_MsgEffect;
|
|
713
|
-
jsonMsg_cjs.
|
|
833
|
+
jsonMsg_cjs.logr = logr_;
|
|
714
834
|
return jsonMsg_cjs;
|
|
715
835
|
}
|
|
716
836
|
|
|
@@ -718,15 +838,8 @@ var jsonMsg_cjsExports = requireJsonMsg_cjs();
|
|
|
718
838
|
|
|
719
839
|
//-------------------------------------------------------------------------------------------------
|
|
720
840
|
let LOGR_$1 = LOGR.get_instance();
|
|
721
|
-
const
|
|
722
|
-
const l_$1 =
|
|
723
|
-
EVENTS: 0b1 << 0,
|
|
724
|
-
TIMEOUTS: 0b1 << 1,
|
|
725
|
-
};
|
|
726
|
-
LOGR_$1.labels = l_$1;
|
|
727
|
-
// LOGR_.toggled= {
|
|
728
|
-
// EVENTS : 1
|
|
729
|
-
// }
|
|
841
|
+
const logr_$1 = LOGR_$1.create({ labels: l_array_(['LOG_EVENTS', 'TIMEOUTS']) });
|
|
842
|
+
const l_$1 = logr_$1.l;
|
|
730
843
|
//-------------------------------------------------------------------------------------------------
|
|
731
844
|
class EventLog {
|
|
732
845
|
constructor() {
|
|
@@ -755,7 +868,7 @@ class EventLog {
|
|
|
755
868
|
if (this.map_timeouts.delete(idx)) {
|
|
756
869
|
evt.timeout_id = null;
|
|
757
870
|
timeout_callback({ idx, evt });
|
|
758
|
-
|
|
871
|
+
logr_$1.log(l_$1.LOG_EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
759
872
|
}
|
|
760
873
|
}, timeout_ms);
|
|
761
874
|
this.map_timeouts.set(idx, evt.timeout_id);
|
|
@@ -763,7 +876,7 @@ class EventLog {
|
|
|
763
876
|
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
764
877
|
// 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().
|
|
765
878
|
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
766
|
-
|
|
879
|
+
logr_$1.log(l_$1.LOG_EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
767
880
|
return { idx, evt };
|
|
768
881
|
}
|
|
769
882
|
cancelTimeout(idx) {
|
|
@@ -837,12 +950,15 @@ class EventLog {
|
|
|
837
950
|
// };
|
|
838
951
|
const k_TTL = 20000;
|
|
839
952
|
//-------------------------------------------------------------------------------------------------
|
|
953
|
+
const obj_labels_merge_ = l_merge_(logr_$1.lref.get(), jsonMsg_cjsExports.logr.lref.get()); // VALIDATION : 4
|
|
954
|
+
const obj_labels_concat_ = l_concat_(obj_labels_merge_, l_array_(['HANDLERS', 'DROPS', 'PROTOCOL_STATE', 'RECVER', 'SENDER']));
|
|
955
|
+
const lref_ = lRef(obj_labels_concat_);
|
|
956
|
+
jsonMsg_cjsExports.logr.lref = lref_;
|
|
957
|
+
logr_$1.lref = lref_;
|
|
840
958
|
const LOGR_ = LOGR.get_instance();
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
const
|
|
844
|
-
const l_ = l_concat_(l_$1, l_concat_(jsonMsg_cjsExports.l, l_twoPhW_));
|
|
845
|
-
LOGR_.labels = l_;
|
|
959
|
+
const logr_ = LOGR_.create(); // don't let create() make a new ref, assign lref_ from here
|
|
960
|
+
logr_.lref = lref_;
|
|
961
|
+
const l_ = logr_.l;
|
|
846
962
|
class Config {
|
|
847
963
|
_callback_msgWarp;
|
|
848
964
|
_callback_msgEngage;
|
|
@@ -924,7 +1040,7 @@ var JSON_MsgOptions = (function () {
|
|
|
924
1040
|
// if (! JSON_Msg_msg.validate(json))
|
|
925
1041
|
// return false;
|
|
926
1042
|
// if (! schema_MsgOptions_(json)) {
|
|
927
|
-
//
|
|
1043
|
+
// logr_.log(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', (schema_MsgOptions_ as any).errors])
|
|
928
1044
|
// return false;
|
|
929
1045
|
// }
|
|
930
1046
|
return true;
|
|
@@ -959,7 +1075,7 @@ var JSON_MsgWarp = (function () {
|
|
|
959
1075
|
// if (! JSON_Msg.validate(json))
|
|
960
1076
|
// return false;
|
|
961
1077
|
if (!schema_MsgWarp(json_msg)) {
|
|
962
|
-
|
|
1078
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgWarp: schema_MsgWarp_: ', schema_MsgWarp.errors]);
|
|
963
1079
|
return false;
|
|
964
1080
|
}
|
|
965
1081
|
return true;
|
|
@@ -984,7 +1100,7 @@ var JSON_MsgEngage = (function () {
|
|
|
984
1100
|
if (!JSON_MsgWarp.validate(json_msgEffect._cause))
|
|
985
1101
|
return false;
|
|
986
1102
|
if (!schema_MsgEngage(json_msgEffect)) {
|
|
987
|
-
|
|
1103
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', schema_MsgEngage.errors]);
|
|
988
1104
|
return false;
|
|
989
1105
|
}
|
|
990
1106
|
return true;
|
|
@@ -1097,7 +1213,7 @@ class StateEngage extends StateState {
|
|
|
1097
1213
|
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
1098
1214
|
const json_msgWarp = this.json_msgEngage._cause;
|
|
1099
1215
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
1100
|
-
|
|
1216
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
1101
1217
|
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
1102
1218
|
return false;
|
|
1103
1219
|
return true;
|
|
@@ -1120,7 +1236,7 @@ class StateAckWarp extends StateState {
|
|
|
1120
1236
|
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
1121
1237
|
// - STT: Date of the Ack minus date of the Warp.
|
|
1122
1238
|
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);
|
|
1123
|
-
|
|
1239
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`]);
|
|
1124
1240
|
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
1125
1241
|
return false;
|
|
1126
1242
|
return true;
|
|
@@ -1135,7 +1251,7 @@ class StateWarp extends StateState {
|
|
|
1135
1251
|
return false;
|
|
1136
1252
|
// The Warp gets to live for THE WARP'S creation time + TTL*2
|
|
1137
1253
|
const timeout_ms = time_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
|
|
1138
|
-
|
|
1254
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
1139
1255
|
if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
|
|
1140
1256
|
return false;
|
|
1141
1257
|
return true;
|
|
@@ -1155,7 +1271,7 @@ class StateInitialState extends StateState {
|
|
|
1155
1271
|
return false;
|
|
1156
1272
|
// The NEWLY created Warp only gets to live for its creation time + TTL
|
|
1157
1273
|
const timeout_ms = state_new.json_msgWarp.warp.ttl_msec;
|
|
1158
|
-
|
|
1274
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateInitialState: evt_Warp.dt@${state_new.evt_Warp.dt}, msgWarp.dt@${Date.parse(state_new.json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
1159
1275
|
if (state_new.evt_Warp.dt >= Date.parse(state_new.json_msgWarp.dt) + timeout_ms)
|
|
1160
1276
|
return false;
|
|
1161
1277
|
return true;
|
|
@@ -1210,7 +1326,7 @@ class TwoPhW_EventLog {
|
|
|
1210
1326
|
_addEvent(msg, json_msg, timeout_ms, timeout_callback) {
|
|
1211
1327
|
const { str_type, json_msgWarp } = this._warp(json_msg);
|
|
1212
1328
|
const { idx } = this._eventLog.addEvent(str_type, json_msgWarp.warp.id, { msg, json_msg }, timeout_ms, timeout_callback);
|
|
1213
|
-
|
|
1329
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
|
|
1214
1330
|
}
|
|
1215
1331
|
_dropEvent(json_msg) {
|
|
1216
1332
|
const { json_msgWarp } = this._warp(json_msg);
|
|
@@ -1219,13 +1335,13 @@ class TwoPhW_EventLog {
|
|
|
1219
1335
|
this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
|
|
1220
1336
|
}
|
|
1221
1337
|
_cancelTimeout(idx_event) {
|
|
1222
|
-
|
|
1338
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
|
|
1223
1339
|
this._eventLog.cancelTimeout(idx_event);
|
|
1224
1340
|
}
|
|
1225
1341
|
traverse_State(json_msgWarp) {
|
|
1226
1342
|
const protocolState = new ProtocolStateState();
|
|
1227
1343
|
const arr_evts = this._eventLog.getEventsById(json_msgWarp.warp.id, k_TTL);
|
|
1228
|
-
|
|
1344
|
+
logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
|
|
1229
1345
|
//TODO: what is the right TTL? should it be a constant or calculated
|
|
1230
1346
|
for (let i = arr_evts.length - 1; i >= 0; i--) {
|
|
1231
1347
|
const { idx, evt } = arr_evts[i];
|
|
@@ -1246,7 +1362,7 @@ class TwoPhW_EventLog {
|
|
|
1246
1362
|
protocolState.state.changeState(new StateAckEngage(idx, evt));
|
|
1247
1363
|
break;
|
|
1248
1364
|
}
|
|
1249
|
-
|
|
1365
|
+
logr_.log(l_.PROTOCOL_STATE, () => ['traverse_State: type,state: ',
|
|
1250
1366
|
evt.type,
|
|
1251
1367
|
(protocolState.state.json_msg.ack?.ok === false) ? '--NACK--' : '',
|
|
1252
1368
|
protocolState.state
|
|
@@ -1270,7 +1386,7 @@ class TwoPhW {
|
|
|
1270
1386
|
}
|
|
1271
1387
|
//-------------------------------------------------------------------------------------------------
|
|
1272
1388
|
_handler_msgOptions(cfg, msg, json_msgOptions) {
|
|
1273
|
-
|
|
1389
|
+
logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
|
|
1274
1390
|
/*
|
|
1275
1391
|
if (! validate_Options_delay_(json_msgOptions.options))
|
|
1276
1392
|
return false;
|
|
@@ -1287,7 +1403,7 @@ class TwoPhW {
|
|
|
1287
1403
|
|
|
1288
1404
|
//TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
|
|
1289
1405
|
|
|
1290
|
-
|
|
1406
|
+
logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
|
|
1291
1407
|
|
|
1292
1408
|
ctx.protocol.delayTimeout(ttl_incr);
|
|
1293
1409
|
|
|
@@ -1302,13 +1418,13 @@ class TwoPhW {
|
|
|
1302
1418
|
//-------------------------------------------------------------------------------------------------
|
|
1303
1419
|
// sender Source (src)
|
|
1304
1420
|
register_msgWarp(msg, json_msgWarp) {
|
|
1305
|
-
|
|
1421
|
+
logr_.log(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
|
|
1306
1422
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1307
1423
|
const b_changeState = protocolState.canChangeState(new StateWarp(null, {
|
|
1308
1424
|
dt: Date.now(),
|
|
1309
1425
|
data: { msg, json_msg: json_msgWarp }
|
|
1310
1426
|
}));
|
|
1311
|
-
|
|
1427
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
|
|
1312
1428
|
if (!b_changeState)
|
|
1313
1429
|
return false;
|
|
1314
1430
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
@@ -1318,14 +1434,14 @@ class TwoPhW {
|
|
|
1318
1434
|
});
|
|
1319
1435
|
}
|
|
1320
1436
|
_handler_msgAckWarp(msg, json_msgAckWarp) {
|
|
1321
|
-
|
|
1437
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
|
|
1322
1438
|
const json_msgWarp = json_msgAckWarp._cause;
|
|
1323
1439
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1324
1440
|
const b_changeState = protocolState.canChangeState(new StateAckWarp(null, {
|
|
1325
1441
|
dt: Date.now(),
|
|
1326
1442
|
data: { msg, json_msg: json_msgAckWarp }
|
|
1327
1443
|
}));
|
|
1328
|
-
|
|
1444
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
|
|
1329
1445
|
if (!b_changeState)
|
|
1330
1446
|
return false;
|
|
1331
1447
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
@@ -1333,14 +1449,14 @@ class TwoPhW {
|
|
|
1333
1449
|
return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
|
|
1334
1450
|
}
|
|
1335
1451
|
register_msgEngage(msg, json_msgEngage) {
|
|
1336
|
-
|
|
1452
|
+
logr_.log(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
|
|
1337
1453
|
const json_msgWarp = json_msgEngage._cause;
|
|
1338
1454
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1339
1455
|
const b_changeState = protocolState.canChangeState(new StateEngage(null, {
|
|
1340
1456
|
dt: Date.now(),
|
|
1341
1457
|
data: { msg, json_msg: json_msgEngage }
|
|
1342
1458
|
}));
|
|
1343
|
-
|
|
1459
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
|
|
1344
1460
|
if (!b_changeState)
|
|
1345
1461
|
return false;
|
|
1346
1462
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
|
|
@@ -1350,14 +1466,14 @@ class TwoPhW {
|
|
|
1350
1466
|
});
|
|
1351
1467
|
}
|
|
1352
1468
|
_handler_msgAckEngage(msg, json_msgAckEngage) {
|
|
1353
|
-
|
|
1469
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
|
|
1354
1470
|
const json_msgWarp = json_msgAckEngage._cause._cause;
|
|
1355
1471
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1356
1472
|
const b_changeState = protocolState.canChangeState(new StateAckEngage(null, {
|
|
1357
1473
|
dt: Date.now(),
|
|
1358
1474
|
data: { msg, json_msg: json_msgAckEngage }
|
|
1359
1475
|
}));
|
|
1360
|
-
|
|
1476
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
|
|
1361
1477
|
if (!b_changeState)
|
|
1362
1478
|
return false;
|
|
1363
1479
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
@@ -1367,27 +1483,27 @@ class TwoPhW {
|
|
|
1367
1483
|
//-------------------------------------------------------------------------------------------------
|
|
1368
1484
|
// receiver Destination (dst)
|
|
1369
1485
|
_handler_msgWarp(msg, json_msgWarp) {
|
|
1370
|
-
|
|
1486
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: ', json_msgWarp]);
|
|
1371
1487
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1372
1488
|
const b_changeState = protocolState.canChangeState(new StateWarp(null, {
|
|
1373
1489
|
dt: Date.now(),
|
|
1374
1490
|
data: { msg, json_msg: json_msgWarp }
|
|
1375
1491
|
}));
|
|
1376
|
-
|
|
1492
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1377
1493
|
if (!b_changeState)
|
|
1378
1494
|
return false;
|
|
1379
1495
|
this.eventLog._addEvent(msg, json_msgWarp);
|
|
1380
1496
|
return this.config._callback_msgWarp(msg, json_msgWarp);
|
|
1381
1497
|
}
|
|
1382
1498
|
register_msgAckWarp(msg, json_msgAckWarp) {
|
|
1383
|
-
|
|
1499
|
+
logr_.log(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
|
|
1384
1500
|
const json_msgWarp = json_msgAckWarp._cause;
|
|
1385
1501
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1386
1502
|
const b_changeState = protocolState.canChangeState(new StateAckWarp(null, {
|
|
1387
1503
|
dt: Date.now(),
|
|
1388
1504
|
data: { msg, json_msg: json_msgAckWarp }
|
|
1389
1505
|
}));
|
|
1390
|
-
|
|
1506
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1391
1507
|
if (!b_changeState)
|
|
1392
1508
|
return false;
|
|
1393
1509
|
const elapsed_ms = Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
@@ -1397,14 +1513,14 @@ class TwoPhW {
|
|
|
1397
1513
|
});
|
|
1398
1514
|
}
|
|
1399
1515
|
_handler_msgEngage(msg, json_msgEngage) {
|
|
1400
|
-
|
|
1516
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
|
|
1401
1517
|
const json_msgWarp = json_msgEngage._cause;
|
|
1402
1518
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1403
1519
|
const b_changeState = protocolState.canChangeState(new StateEngage(null, {
|
|
1404
1520
|
dt: Date.now(),
|
|
1405
1521
|
data: { msg, json_msg: json_msgEngage }
|
|
1406
1522
|
}));
|
|
1407
|
-
|
|
1523
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1408
1524
|
if (!b_changeState)
|
|
1409
1525
|
return false;
|
|
1410
1526
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
@@ -1412,21 +1528,21 @@ class TwoPhW {
|
|
|
1412
1528
|
return this.config._callback_msgEngage(msg, json_msgEngage);
|
|
1413
1529
|
}
|
|
1414
1530
|
register_msgAckEngage(msg, json_msgAckEngage) {
|
|
1415
|
-
|
|
1531
|
+
logr_.log(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
|
|
1416
1532
|
const json_msgWarp = json_msgAckEngage._cause._cause;
|
|
1417
1533
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1418
1534
|
const b_changeState = protocolState.canChangeState(new StateAckEngage(null, {
|
|
1419
1535
|
dt: Date.now(),
|
|
1420
1536
|
data: { msg, json_msg: json_msgAckEngage }
|
|
1421
1537
|
}));
|
|
1422
|
-
|
|
1538
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1423
1539
|
if (!b_changeState)
|
|
1424
1540
|
return false;
|
|
1425
1541
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
1426
1542
|
}
|
|
1427
1543
|
//-------------------------------------------------------------------------------------------------
|
|
1428
1544
|
handler_json_msgAck(msg, json_msgAck) {
|
|
1429
|
-
|
|
1545
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msgAck: ', json_msgAck]);
|
|
1430
1546
|
if (JSON_MsgAckWarp.validate(json_msgAck) && this._handler_msgAckWarp(msg, json_msgAck))
|
|
1431
1547
|
return true;
|
|
1432
1548
|
if (JSON_MsgAckEngage.validate(json_msgAck) && this._handler_msgAckEngage(msg, json_msgAck))
|
|
@@ -1434,7 +1550,7 @@ class TwoPhW {
|
|
|
1434
1550
|
return false;
|
|
1435
1551
|
}
|
|
1436
1552
|
handler_json_msgEffect(msg, json_msgEffect) {
|
|
1437
|
-
|
|
1553
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msgEffect: ', json_msgEffect]);
|
|
1438
1554
|
if (jsonMsg_cjsExports.JSON_MsgAck.validate(json_msgEffect) && this.handler_json_msgAck(msg, json_msgEffect))
|
|
1439
1555
|
return true;
|
|
1440
1556
|
if (JSON_MsgEngage.validate(json_msgEffect) && this._handler_msgEngage(msg, json_msgEffect))
|
|
@@ -1444,7 +1560,7 @@ class TwoPhW {
|
|
|
1444
1560
|
return false;
|
|
1445
1561
|
}
|
|
1446
1562
|
handler_json_msg(msg, json_msg) {
|
|
1447
|
-
|
|
1563
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msg: ', json_msg]);
|
|
1448
1564
|
if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg))
|
|
1449
1565
|
return true;
|
|
1450
1566
|
// https://attacomsian.com/blog/javascript-iterate-objects
|
|
@@ -1458,7 +1574,7 @@ class TwoPhW {
|
|
|
1458
1574
|
return false;
|
|
1459
1575
|
}
|
|
1460
1576
|
handler_json(msg, json) {
|
|
1461
|
-
|
|
1577
|
+
logr_.log(l_.HANDLERS, () => ['handler_json: ', json]);
|
|
1462
1578
|
if (jsonMsg_cjsExports.JSON_MsgEffect.validate(json) && this.handler_json_msgEffect(msg, json))
|
|
1463
1579
|
return true;
|
|
1464
1580
|
if (jsonMsg_cjsExports.JSON_Msg.validate(json) && this.handler_json_msg(msg, json))
|
|
@@ -1468,8 +1584,11 @@ class TwoPhW {
|
|
|
1468
1584
|
}
|
|
1469
1585
|
|
|
1470
1586
|
exports.EventLog = EventLog;
|
|
1587
|
+
exports.JSON_Msg = jsonMsg_cjsExports.JSON_Msg;
|
|
1588
|
+
exports.JSON_MsgAck = jsonMsg_cjsExports.JSON_MsgAck;
|
|
1471
1589
|
exports.JSON_MsgAckEngage = JSON_MsgAckEngage;
|
|
1472
1590
|
exports.JSON_MsgAckWarp = JSON_MsgAckWarp;
|
|
1591
|
+
exports.JSON_MsgEffect = jsonMsg_cjsExports.JSON_MsgEffect;
|
|
1473
1592
|
exports.JSON_MsgEngage = JSON_MsgEngage;
|
|
1474
1593
|
exports.JSON_MsgOptions = JSON_MsgOptions;
|
|
1475
1594
|
exports.JSON_MsgWarp = JSON_MsgWarp;
|
|
@@ -1480,5 +1599,5 @@ exports.StateINVALID = StateINVALID;
|
|
|
1480
1599
|
exports.StateInitialState = StateInitialState;
|
|
1481
1600
|
exports.StateWarp = StateWarp;
|
|
1482
1601
|
exports.TwoPhW = TwoPhW;
|
|
1483
|
-
exports.
|
|
1602
|
+
exports.logr = logr_;
|
|
1484
1603
|
exports.t_ttl_rtt = time_ttl_rtt_;
|