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