@rootintf/protocol-2phw 1.3.3-api.1 → 2.1.5-api.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EventLog-mem.d.mts +2 -5
- package/dist/twoPhW.cjs.js +640 -414
- package/dist/twoPhW.d.ts +31 -31
- package/dist/twoPhW.es.mjs +640 -414
- package/package.json +6 -6
- package/schema/schema_2PhW.json +1 -1
- package/src/EventLog-mem.mjs +9 -15
- package/src/index.ts +1 -1
- package/src/twoPhW.ts +110 -110
- package/src/validate-esm.mjs +1 -1
- package/tests/event-log-mem.spec.mjs +9 -4
- package/tests/twoPhW-new.spec.mjs +74 -55
- package/dist/index.d.ts +0 -1
package/dist/twoPhW.cjs.js
CHANGED
|
@@ -77,8 +77,8 @@ function validate19(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
77
77
|
if (valid0) {
|
|
78
78
|
if (data["2PhW"] !== undefined) {
|
|
79
79
|
const _errs10 = errors;
|
|
80
|
-
if ("
|
|
81
|
-
validate19.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "
|
|
80
|
+
if ("2" !== data["2PhW"]) {
|
|
81
|
+
validate19.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
|
|
82
82
|
return false;
|
|
83
83
|
}
|
|
84
84
|
var valid0 = _errs10 === errors;
|
|
@@ -159,8 +159,8 @@ function validate20(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
159
159
|
if (valid0) {
|
|
160
160
|
if (data["2PhW"] !== undefined) {
|
|
161
161
|
const _errs7 = errors;
|
|
162
|
-
if ("
|
|
163
|
-
validate20.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "
|
|
162
|
+
if ("2" !== data["2PhW"]) {
|
|
163
|
+
validate20.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
var valid0 = _errs7 === errors;
|
|
@@ -178,199 +178,520 @@ 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
|
|
|
373
|
-
|
|
584
|
+
var bitlogr = require$$0;
|
|
585
|
+
|
|
586
|
+
const schema_Msg = validate18;
|
|
587
|
+
function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
|
|
588
|
+
evaluated0.props = undefined;
|
|
589
|
+
} if (evaluated0.dynamicItems) {
|
|
590
|
+
evaluated0.items = undefined;
|
|
591
|
+
} {
|
|
592
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
593
|
+
let missing0;
|
|
594
|
+
if ((((data.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))) {
|
|
595
|
+
validate18.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
if (data.id !== undefined) {
|
|
600
|
+
const _errs1 = errors;
|
|
601
|
+
if (typeof data.id !== "string") {
|
|
602
|
+
validate18.errors = [{ instancePath: instancePath + "/id", schemaPath: "#/properties/id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
603
|
+
return false;
|
|
604
|
+
}
|
|
605
|
+
var valid0 = _errs1 === errors;
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
var valid0 = true;
|
|
609
|
+
}
|
|
610
|
+
if (valid0) {
|
|
611
|
+
if (data.dt !== undefined) {
|
|
612
|
+
const _errs3 = errors;
|
|
613
|
+
if (typeof data.dt !== "string") {
|
|
614
|
+
validate18.errors = [{ instancePath: instancePath + "/dt", schemaPath: "#/properties/dt/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
var valid0 = _errs3 === errors;
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
var valid0 = true;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
validate18.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
627
|
+
return false;
|
|
628
|
+
}
|
|
629
|
+
} validate18.errors = vErrors; return errors === 0; }
|
|
630
|
+
validate18.evaluated = { "props": { "id": true, "dt": true }, "dynamicProps": false, "dynamicItems": false };
|
|
631
|
+
const schema_MsgEffect = validate19;
|
|
632
|
+
function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
|
|
633
|
+
evaluated0.props = undefined;
|
|
634
|
+
} if (evaluated0.dynamicItems) {
|
|
635
|
+
evaluated0.items = undefined;
|
|
636
|
+
} {
|
|
637
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
638
|
+
let missing0;
|
|
639
|
+
if ((data._cause === undefined) && (missing0 = "_cause")) {
|
|
640
|
+
validate19.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
validate19.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
} validate19.errors = vErrors; return errors === 0; }
|
|
649
|
+
validate19.evaluated = { "dynamicProps": false, "dynamicItems": false };
|
|
650
|
+
const schema_MsgAckEffect = validate20;
|
|
651
|
+
function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
|
|
652
|
+
evaluated0.props = undefined;
|
|
653
|
+
} if (evaluated0.dynamicItems) {
|
|
654
|
+
evaluated0.items = undefined;
|
|
655
|
+
} {
|
|
656
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
657
|
+
let missing0;
|
|
658
|
+
if ((data.ack === undefined) && (missing0 = "ack")) {
|
|
659
|
+
validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
if (data.ack !== undefined) {
|
|
664
|
+
let data0 = data.ack;
|
|
665
|
+
{
|
|
666
|
+
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
667
|
+
let missing1;
|
|
668
|
+
if ((data0.ok === undefined) && (missing1 = "ok")) {
|
|
669
|
+
validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
if (data0.ok !== undefined) {
|
|
674
|
+
if (typeof data0.ok !== "boolean") {
|
|
675
|
+
validate20.errors = [{ instancePath: instancePath + "/ack/ok", schemaPath: "#/properties/ack/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
} validate20.errors = vErrors; return errors === 0; }
|
|
694
|
+
validate20.evaluated = { "props": { "ack": true }, "dynamicProps": false, "dynamicItems": false };
|
|
374
695
|
|
|
375
696
|
const byteToHex = [];
|
|
376
697
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -414,10 +735,7 @@ function requireJsonMsg_cjs () {
|
|
|
414
735
|
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
415
736
|
var native = { randomUUID };
|
|
416
737
|
|
|
417
|
-
function
|
|
418
|
-
if (native.randomUUID && true && !options) {
|
|
419
|
-
return native.randomUUID();
|
|
420
|
-
}
|
|
738
|
+
function _v4(options, buf, offset) {
|
|
421
739
|
options = options || {};
|
|
422
740
|
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
423
741
|
if (rnds.length < 16) {
|
|
@@ -427,183 +745,92 @@ function requireJsonMsg_cjs () {
|
|
|
427
745
|
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
428
746
|
return unsafeStringify(rnds);
|
|
429
747
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
function handler_default_( /* ... */ ) {
|
|
437
|
-
// https://stackoverflow.com/questions/18746440/passing-multiple-arguments-to-console-log
|
|
438
|
-
var args = Array.prototype.slice.call(arguments);
|
|
439
|
-
console.log.apply(console, args);
|
|
748
|
+
function v4(options, buf, offset) {
|
|
749
|
+
if (native.randomUUID && true && !options) {
|
|
750
|
+
return native.randomUUID();
|
|
751
|
+
}
|
|
752
|
+
return _v4(options);
|
|
440
753
|
}
|
|
441
754
|
|
|
442
755
|
//-------------------------------------------------------------------------------------------------
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
throw new Error('obj must be an object');
|
|
449
|
-
|
|
450
|
-
let bigInt = BigInt(0);
|
|
451
|
-
for (const [k,v] of Object.entries(obj)) {
|
|
452
|
-
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
453
|
-
bigInt|= BigInt( obj_labels[k] );
|
|
454
|
-
// console.log('0b'+ bigInt.toString(2) );
|
|
455
|
-
}
|
|
456
|
-
return bigInt;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// console.log(l_toBigInt_({},{}))
|
|
460
|
-
|
|
461
|
-
const LOGR = (function () {
|
|
462
|
-
let _instance; // Private variable to hold the single instance
|
|
463
|
-
|
|
464
|
-
function _create_instance() {
|
|
465
|
-
// Private state (replacing constructor properties)
|
|
466
|
-
let _handler_log = handler_default_;
|
|
467
|
-
let _obj_labels = undefined;
|
|
468
|
-
let _Bint_toggled = BigInt(0);
|
|
469
|
-
|
|
470
|
-
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
471
|
-
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
472
|
-
return false;
|
|
473
|
-
|
|
474
|
-
const args = argsFn();
|
|
475
|
-
_handler_log.apply(this, args);
|
|
476
|
-
// _handler_log.apply(this, args);
|
|
477
|
-
return true;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
return {
|
|
481
|
-
set handler(fx) {
|
|
482
|
-
_handler_log = fx;
|
|
483
|
-
},
|
|
484
|
-
get handler() {
|
|
485
|
-
return _handler_log;
|
|
486
|
-
},
|
|
487
|
-
|
|
488
|
-
get labels() { return _obj_labels; },
|
|
489
|
-
set labels(obj) {
|
|
490
|
-
_obj_labels = obj;
|
|
491
|
-
_Bint_toggled = BigInt(0);
|
|
492
|
-
},
|
|
493
|
-
|
|
494
|
-
// put= function(label, abbrv) {
|
|
495
|
-
// let name= __name(label);
|
|
496
|
-
// _labels[name]= label[name];
|
|
497
|
-
// console.log(_labels);
|
|
498
|
-
// }
|
|
499
|
-
|
|
500
|
-
get toggled() { return _Bint_toggled; },
|
|
501
|
-
set toggled(obj_toggled) {
|
|
502
|
-
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
503
|
-
},
|
|
504
|
-
|
|
505
|
-
log(nr_logged, argsFn) {
|
|
506
|
-
|
|
507
|
-
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// Public interface
|
|
513
|
-
return {
|
|
514
|
-
get_instance() {
|
|
515
|
-
if (!_instance) {
|
|
516
|
-
_instance = _create_instance(); // Lazy initialization
|
|
517
|
-
}
|
|
518
|
-
return _instance;
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
})();
|
|
523
|
-
|
|
524
|
-
let LOGR_= LOGR.get_instance();
|
|
525
|
-
const log_= LOGR_.log;
|
|
526
|
-
|
|
527
|
-
const l_= {
|
|
528
|
-
VALIDATION : 0b1 << 0,
|
|
529
|
-
};
|
|
530
|
-
LOGR_.labels= l_;
|
|
531
|
-
|
|
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]');
|
|
760
|
+
//-------------------------------------------------------------------------------------------------
|
|
532
761
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
533
|
-
|
|
534
762
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
535
|
-
var JSON_Msg = (function() {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
763
|
+
var JSON_Msg = (function () {
|
|
764
|
+
return {
|
|
765
|
+
merge: function (json) {
|
|
766
|
+
return Object.assign({
|
|
767
|
+
id: v4(),
|
|
768
|
+
referer: null,
|
|
769
|
+
dt: new Date().toISOString()
|
|
770
|
+
}, json || {});
|
|
771
|
+
},
|
|
772
|
+
validate: function (json) {
|
|
773
|
+
const b_valid = schema_Msg(json);
|
|
774
|
+
if (!b_valid)
|
|
775
|
+
logr_.log(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
|
|
776
|
+
return b_valid;
|
|
777
|
+
},
|
|
778
|
+
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
779
|
+
// https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
|
|
780
|
+
// static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
|
|
781
|
+
// static parse(json) {
|
|
782
|
+
// return this.#ajv_parse_(json);
|
|
783
|
+
// }
|
|
784
|
+
};
|
|
557
785
|
})();
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
786
|
+
var JSON_MsgEffect = (function () {
|
|
787
|
+
return {
|
|
788
|
+
create_with_cause_merge: function (msg_cause, json) {
|
|
789
|
+
const _cause = msg_cause;
|
|
790
|
+
return Object.assign(JSON_Msg.merge(json), { _cause });
|
|
791
|
+
},
|
|
792
|
+
validate: function (json) {
|
|
793
|
+
if (!JSON_Msg.validate(json))
|
|
794
|
+
return false;
|
|
795
|
+
const b_valid = schema_MsgEffect(json);
|
|
796
|
+
if (!b_valid)
|
|
797
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
|
|
798
|
+
return b_valid;
|
|
799
|
+
}
|
|
800
|
+
};
|
|
573
801
|
})();
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}
|
|
802
|
+
var JSON_MsgAck = (function () {
|
|
803
|
+
return {
|
|
804
|
+
create_with_cause_Ok: function (msg_cause, b_ok = true) {
|
|
805
|
+
return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
|
|
806
|
+
ack: {
|
|
807
|
+
"ok": b_ok,
|
|
808
|
+
},
|
|
809
|
+
});
|
|
810
|
+
},
|
|
811
|
+
create_with_cause_Expired: function (msg_cause) {
|
|
812
|
+
return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
|
|
813
|
+
ack: {
|
|
814
|
+
"ok": false,
|
|
815
|
+
"expired": true
|
|
816
|
+
},
|
|
817
|
+
});
|
|
818
|
+
},
|
|
819
|
+
validate: function (json) {
|
|
820
|
+
if (!JSON_MsgEffect.validate(json))
|
|
821
|
+
return false;
|
|
822
|
+
const b_valid = schema_MsgAckEffect(json);
|
|
823
|
+
if (!b_valid)
|
|
824
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
|
|
825
|
+
return b_valid;
|
|
826
|
+
}
|
|
827
|
+
};
|
|
601
828
|
})();
|
|
602
829
|
|
|
603
830
|
jsonMsg_cjs.JSON_Msg = JSON_Msg;
|
|
604
|
-
jsonMsg_cjs.
|
|
605
|
-
jsonMsg_cjs.
|
|
606
|
-
jsonMsg_cjs.
|
|
831
|
+
jsonMsg_cjs.JSON_MsgAck = JSON_MsgAck;
|
|
832
|
+
jsonMsg_cjs.JSON_MsgEffect = JSON_MsgEffect;
|
|
833
|
+
jsonMsg_cjs.logr = logr_;
|
|
607
834
|
return jsonMsg_cjs;
|
|
608
835
|
}
|
|
609
836
|
|
|
@@ -611,15 +838,8 @@ var jsonMsg_cjsExports = requireJsonMsg_cjs();
|
|
|
611
838
|
|
|
612
839
|
//-------------------------------------------------------------------------------------------------
|
|
613
840
|
let LOGR_$1 = LOGR.get_instance();
|
|
614
|
-
const
|
|
615
|
-
const l_$1 =
|
|
616
|
-
EVENTS: 0b1 << 0,
|
|
617
|
-
TIMEOUTS: 0b1 << 1,
|
|
618
|
-
};
|
|
619
|
-
LOGR_$1.labels = l_$1;
|
|
620
|
-
// LOGR_.toggled= {
|
|
621
|
-
// EVENTS : 1
|
|
622
|
-
// }
|
|
841
|
+
const logr_$1 = LOGR_$1.create({ labels: l_array_(['LOG_EVENTS', 'TIMEOUTS']) });
|
|
842
|
+
const l_$1 = logr_$1.l;
|
|
623
843
|
//-------------------------------------------------------------------------------------------------
|
|
624
844
|
class EventLog {
|
|
625
845
|
constructor() {
|
|
@@ -648,7 +868,7 @@ class EventLog {
|
|
|
648
868
|
if (this.map_timeouts.delete(idx)) {
|
|
649
869
|
evt.timeout_id = null;
|
|
650
870
|
timeout_callback({ idx, evt });
|
|
651
|
-
|
|
871
|
+
logr_$1.log(l_$1.LOG_EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
652
872
|
}
|
|
653
873
|
}, timeout_ms);
|
|
654
874
|
this.map_timeouts.set(idx, evt.timeout_id);
|
|
@@ -656,7 +876,7 @@ class EventLog {
|
|
|
656
876
|
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
657
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().
|
|
658
878
|
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
659
|
-
|
|
879
|
+
logr_$1.log(l_$1.LOG_EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
660
880
|
return { idx, evt };
|
|
661
881
|
}
|
|
662
882
|
cancelTimeout(idx) {
|
|
@@ -730,12 +950,15 @@ class EventLog {
|
|
|
730
950
|
// };
|
|
731
951
|
const k_TTL = 20000;
|
|
732
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_;
|
|
733
958
|
const LOGR_ = LOGR.get_instance();
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
const
|
|
737
|
-
const l_ = l_concat_(l_$1, l_concat_(jsonMsg_cjsExports.l, l_twoPhW_));
|
|
738
|
-
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;
|
|
739
962
|
class Config {
|
|
740
963
|
_callback_msgWarp;
|
|
741
964
|
_callback_msgEngage;
|
|
@@ -794,7 +1017,7 @@ class Config {
|
|
|
794
1017
|
// }
|
|
795
1018
|
// })();
|
|
796
1019
|
//-------------------------------------------------------------------------------------------------
|
|
797
|
-
let k_VERSION = "
|
|
1020
|
+
let k_VERSION = "2";
|
|
798
1021
|
// rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
|
|
799
1022
|
// t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
|
|
800
1023
|
function time_ttl_rtt_(ttl_msec, rtt_msec) {
|
|
@@ -807,8 +1030,8 @@ function time_ttl_rtt_(ttl_msec, rtt_msec) {
|
|
|
807
1030
|
}
|
|
808
1031
|
var JSON_MsgOptions = (function () {
|
|
809
1032
|
return {
|
|
810
|
-
|
|
811
|
-
return jsonMsg_cjsExports.
|
|
1033
|
+
create_with_cause_options: function (msg_cause, options) {
|
|
1034
|
+
return jsonMsg_cjsExports.JSON_MsgEffect.create_with_msg_merge(msg_cause, {
|
|
812
1035
|
options: options,
|
|
813
1036
|
"2PhW": k_VERSION
|
|
814
1037
|
});
|
|
@@ -817,7 +1040,7 @@ var JSON_MsgOptions = (function () {
|
|
|
817
1040
|
// if (! JSON_Msg_msg.validate(json))
|
|
818
1041
|
// return false;
|
|
819
1042
|
// if (! schema_MsgOptions_(json)) {
|
|
820
|
-
//
|
|
1043
|
+
// logr_.log(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', (schema_MsgOptions_ as any).errors])
|
|
821
1044
|
// return false;
|
|
822
1045
|
// }
|
|
823
1046
|
return true;
|
|
@@ -852,7 +1075,7 @@ var JSON_MsgWarp = (function () {
|
|
|
852
1075
|
// if (! JSON_Msg.validate(json))
|
|
853
1076
|
// return false;
|
|
854
1077
|
if (!schema_MsgWarp(json_msg)) {
|
|
855
|
-
|
|
1078
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgWarp: schema_MsgWarp_: ', schema_MsgWarp.errors]);
|
|
856
1079
|
return false;
|
|
857
1080
|
}
|
|
858
1081
|
return true;
|
|
@@ -861,9 +1084,9 @@ var JSON_MsgWarp = (function () {
|
|
|
861
1084
|
})();
|
|
862
1085
|
var JSON_MsgEngage = (function () {
|
|
863
1086
|
return {
|
|
864
|
-
|
|
1087
|
+
create_with_Warp: function (json_msgWarp) {
|
|
865
1088
|
console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
|
|
866
|
-
return jsonMsg_cjsExports.
|
|
1089
|
+
return jsonMsg_cjsExports.JSON_MsgEffect.create_with_cause_merge(json_msgWarp, {
|
|
867
1090
|
engage: {
|
|
868
1091
|
"ok": true,
|
|
869
1092
|
"rtt_msec": Date.now() - Date.parse(json_msgWarp.dt)
|
|
@@ -871,13 +1094,13 @@ var JSON_MsgEngage = (function () {
|
|
|
871
1094
|
"2PhW": k_VERSION
|
|
872
1095
|
});
|
|
873
1096
|
},
|
|
874
|
-
validate: function (
|
|
1097
|
+
validate: function (json_msgEffect) {
|
|
875
1098
|
// if (! JSON_Msg_msg.validate(json))
|
|
876
1099
|
// return false;
|
|
877
|
-
if (!JSON_MsgWarp.validate(
|
|
1100
|
+
if (!JSON_MsgWarp.validate(json_msgEffect._cause))
|
|
878
1101
|
return false;
|
|
879
|
-
if (!schema_MsgEngage(
|
|
880
|
-
|
|
1102
|
+
if (!schema_MsgEngage(json_msgEffect)) {
|
|
1103
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', schema_MsgEngage.errors]);
|
|
881
1104
|
return false;
|
|
882
1105
|
}
|
|
883
1106
|
return true;
|
|
@@ -888,23 +1111,23 @@ var JSON_MsgAckWarp = (function () {
|
|
|
888
1111
|
return {
|
|
889
1112
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
890
1113
|
// const json_msgAckWarp= structuredClone(json_msgAck);
|
|
891
|
-
// json_msgAckWarp.
|
|
1114
|
+
// json_msgAckWarp._cause= _cause;
|
|
892
1115
|
// return json_msgAckWarp;
|
|
893
1116
|
// }
|
|
894
|
-
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
return
|
|
1117
|
+
create_with_Warp_Ok: function (json_msgWarp, b_ok = true) {
|
|
1118
|
+
const json_msgAck = jsonMsg_cjsExports.JSON_MsgAck.create_with_cause_Ok(json_msgWarp, b_ok);
|
|
1119
|
+
json_msgAck["2PhW"] = k_VERSION;
|
|
1120
|
+
return json_msgAck;
|
|
898
1121
|
},
|
|
899
1122
|
// create_with_msgExpired : function( json_msgWarp ) {
|
|
900
1123
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp )
|
|
901
1124
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
902
1125
|
// return json_msgAck_msg;
|
|
903
1126
|
// },
|
|
904
|
-
validate: function (
|
|
1127
|
+
validate: function (json_msgAck) {
|
|
905
1128
|
// if (! JSON_MsgAck_msg.validate(json))
|
|
906
1129
|
// return false;
|
|
907
|
-
if (!JSON_MsgWarp.validate(
|
|
1130
|
+
if (!JSON_MsgWarp.validate(json_msgAck._cause))
|
|
908
1131
|
return false;
|
|
909
1132
|
return true;
|
|
910
1133
|
}
|
|
@@ -914,23 +1137,23 @@ var JSON_MsgAckEngage = (function () {
|
|
|
914
1137
|
return {
|
|
915
1138
|
// createWith_msgAck_msg : function(json_msgAck, _msg) {
|
|
916
1139
|
// const json_msgAckEngage= structuredClone(json_msgAck);
|
|
917
|
-
// json_msgAckEngage.
|
|
1140
|
+
// json_msgAckEngage._cause= _cause;
|
|
918
1141
|
// return json_msgAckEngage;
|
|
919
1142
|
// }
|
|
920
|
-
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
return
|
|
1143
|
+
create_with_Engage_Ok: function (json_msgEngage, b_ok = true) {
|
|
1144
|
+
const json_msgAck = jsonMsg_cjsExports.JSON_MsgAck.create_with_cause_Ok(json_msgEngage, b_ok);
|
|
1145
|
+
json_msgAck["2PhW"] = k_VERSION;
|
|
1146
|
+
return json_msgAck;
|
|
924
1147
|
},
|
|
925
1148
|
// create_with_msgExpired : function( json_msgEngage ) {
|
|
926
1149
|
// const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage )
|
|
927
1150
|
// json_msgAck_msg["2PhW"]= k_VERSION;
|
|
928
1151
|
// return json_msgAck_msg;
|
|
929
1152
|
// },
|
|
930
|
-
validate: function (
|
|
1153
|
+
validate: function (json_msgAck) {
|
|
931
1154
|
// if (! JSON_MsgAck_msg.validate(json_msgAck_msg))
|
|
932
1155
|
// return false;
|
|
933
|
-
if (!JSON_MsgEngage.validate(
|
|
1156
|
+
if (!JSON_MsgEngage.validate(json_msgAck._cause))
|
|
934
1157
|
return false;
|
|
935
1158
|
return true;
|
|
936
1159
|
}
|
|
@@ -988,9 +1211,9 @@ class StateEngage extends StateState {
|
|
|
988
1211
|
if (false === state_new instanceof StateAckEngage)
|
|
989
1212
|
return false;
|
|
990
1213
|
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
991
|
-
const json_msgWarp = this.json_msgEngage.
|
|
1214
|
+
const json_msgWarp = this.json_msgEngage._cause;
|
|
992
1215
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
993
|
-
|
|
1216
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
994
1217
|
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
995
1218
|
return false;
|
|
996
1219
|
return true;
|
|
@@ -1005,15 +1228,15 @@ class StateAckWarp extends StateState {
|
|
|
1005
1228
|
return false;
|
|
1006
1229
|
if (!this.json_msgAckWarp.ack.ok)
|
|
1007
1230
|
return false;
|
|
1008
|
-
if (this.json_msgAckWarp.
|
|
1231
|
+
if (this.json_msgAckWarp._cause.warp.instantaneous)
|
|
1009
1232
|
return false;
|
|
1010
1233
|
// The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
|
|
1011
1234
|
// +STT, so lines up with the Engage timeout
|
|
1012
1235
|
// - Engage: T0 +2TTL +RTT; RTT= STT+STT
|
|
1013
1236
|
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
1014
1237
|
// - STT: Date of the Ack minus date of the Warp.
|
|
1015
|
-
const timeout_ms = time_ttl_rtt_(this.json_msgAckWarp.
|
|
1016
|
-
|
|
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);
|
|
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}`]);
|
|
1017
1240
|
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
1018
1241
|
return false;
|
|
1019
1242
|
return true;
|
|
@@ -1028,7 +1251,7 @@ class StateWarp extends StateState {
|
|
|
1028
1251
|
return false;
|
|
1029
1252
|
// The Warp gets to live for THE WARP'S creation time + TTL*2
|
|
1030
1253
|
const timeout_ms = time_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
|
|
1031
|
-
|
|
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}`]);
|
|
1032
1255
|
if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
|
|
1033
1256
|
return false;
|
|
1034
1257
|
return true;
|
|
@@ -1048,7 +1271,7 @@ class StateInitialState extends StateState {
|
|
|
1048
1271
|
return false;
|
|
1049
1272
|
// The NEWLY created Warp only gets to live for its creation time + TTL
|
|
1050
1273
|
const timeout_ms = state_new.json_msgWarp.warp.ttl_msec;
|
|
1051
|
-
|
|
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}`]);
|
|
1052
1275
|
if (state_new.evt_Warp.dt >= Date.parse(state_new.json_msgWarp.dt) + timeout_ms)
|
|
1053
1276
|
return false;
|
|
1054
1277
|
return true;
|
|
@@ -1084,7 +1307,7 @@ class TwoPhW_EventLog {
|
|
|
1084
1307
|
}
|
|
1085
1308
|
_warp(json_msg) {
|
|
1086
1309
|
const b_Ack = json_msg.ack !== undefined;
|
|
1087
|
-
const json = b_Ack ? json_msg["
|
|
1310
|
+
const json = b_Ack ? json_msg["_cause"] : json_msg;
|
|
1088
1311
|
if (json.warp) {
|
|
1089
1312
|
return {
|
|
1090
1313
|
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Warp]`,
|
|
@@ -1094,7 +1317,7 @@ class TwoPhW_EventLog {
|
|
|
1094
1317
|
if (json.engage) {
|
|
1095
1318
|
return {
|
|
1096
1319
|
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
|
|
1097
|
-
json_msgWarp: json["
|
|
1320
|
+
json_msgWarp: json["_cause"]
|
|
1098
1321
|
};
|
|
1099
1322
|
}
|
|
1100
1323
|
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
@@ -1103,7 +1326,7 @@ class TwoPhW_EventLog {
|
|
|
1103
1326
|
_addEvent(msg, json_msg, timeout_ms, timeout_callback) {
|
|
1104
1327
|
const { str_type, json_msgWarp } = this._warp(json_msg);
|
|
1105
1328
|
const { idx } = this._eventLog.addEvent(str_type, json_msgWarp.warp.id, { msg, json_msg }, timeout_ms, timeout_callback);
|
|
1106
|
-
|
|
1329
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
|
|
1107
1330
|
}
|
|
1108
1331
|
_dropEvent(json_msg) {
|
|
1109
1332
|
const { json_msgWarp } = this._warp(json_msg);
|
|
@@ -1112,13 +1335,13 @@ class TwoPhW_EventLog {
|
|
|
1112
1335
|
this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
|
|
1113
1336
|
}
|
|
1114
1337
|
_cancelTimeout(idx_event) {
|
|
1115
|
-
|
|
1338
|
+
logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
|
|
1116
1339
|
this._eventLog.cancelTimeout(idx_event);
|
|
1117
1340
|
}
|
|
1118
1341
|
traverse_State(json_msgWarp) {
|
|
1119
1342
|
const protocolState = new ProtocolStateState();
|
|
1120
1343
|
const arr_evts = this._eventLog.getEventsById(json_msgWarp.warp.id, k_TTL);
|
|
1121
|
-
|
|
1344
|
+
logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
|
|
1122
1345
|
//TODO: what is the right TTL? should it be a constant or calculated
|
|
1123
1346
|
for (let i = arr_evts.length - 1; i >= 0; i--) {
|
|
1124
1347
|
const { idx, evt } = arr_evts[i];
|
|
@@ -1139,7 +1362,7 @@ class TwoPhW_EventLog {
|
|
|
1139
1362
|
protocolState.state.changeState(new StateAckEngage(idx, evt));
|
|
1140
1363
|
break;
|
|
1141
1364
|
}
|
|
1142
|
-
|
|
1365
|
+
logr_.log(l_.PROTOCOL_STATE, () => ['traverse_State: type,state: ',
|
|
1143
1366
|
evt.type,
|
|
1144
1367
|
(protocolState.state.json_msg.ack?.ok === false) ? '--NACK--' : '',
|
|
1145
1368
|
protocolState.state
|
|
@@ -1163,13 +1386,13 @@ class TwoPhW {
|
|
|
1163
1386
|
}
|
|
1164
1387
|
//-------------------------------------------------------------------------------------------------
|
|
1165
1388
|
_handler_msgOptions(cfg, msg, json_msgOptions) {
|
|
1166
|
-
|
|
1389
|
+
logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
|
|
1167
1390
|
/*
|
|
1168
1391
|
if (! validate_Options_delay_(json_msgOptions.options))
|
|
1169
1392
|
return false;
|
|
1170
1393
|
|
|
1171
|
-
if (JSON_MsgWarp.validate(json_msgOptions.
|
|
1172
|
-
const json_msgWarp= json_msgOptions.
|
|
1394
|
+
if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
|
|
1395
|
+
const json_msgWarp= json_msgOptions._cause;
|
|
1173
1396
|
|
|
1174
1397
|
const ctx= get_ctx(json_msgWarp.id);
|
|
1175
1398
|
if (!ctx )
|
|
@@ -1180,7 +1403,7 @@ class TwoPhW {
|
|
|
1180
1403
|
|
|
1181
1404
|
//TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
|
|
1182
1405
|
|
|
1183
|
-
|
|
1406
|
+
logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
|
|
1184
1407
|
|
|
1185
1408
|
ctx.protocol.delayTimeout(ttl_incr);
|
|
1186
1409
|
|
|
@@ -1195,13 +1418,13 @@ class TwoPhW {
|
|
|
1195
1418
|
//-------------------------------------------------------------------------------------------------
|
|
1196
1419
|
// sender Source (src)
|
|
1197
1420
|
register_msgWarp(msg, json_msgWarp) {
|
|
1198
|
-
|
|
1421
|
+
logr_.log(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
|
|
1199
1422
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1200
1423
|
const b_changeState = protocolState.canChangeState(new StateWarp(null, {
|
|
1201
1424
|
dt: Date.now(),
|
|
1202
1425
|
data: { msg, json_msg: json_msgWarp }
|
|
1203
1426
|
}));
|
|
1204
|
-
|
|
1427
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
|
|
1205
1428
|
if (!b_changeState)
|
|
1206
1429
|
return false;
|
|
1207
1430
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
@@ -1211,14 +1434,14 @@ class TwoPhW {
|
|
|
1211
1434
|
});
|
|
1212
1435
|
}
|
|
1213
1436
|
_handler_msgAckWarp(msg, json_msgAckWarp) {
|
|
1214
|
-
|
|
1215
|
-
const json_msgWarp = json_msgAckWarp.
|
|
1437
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
|
|
1438
|
+
const json_msgWarp = json_msgAckWarp._cause;
|
|
1216
1439
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1217
1440
|
const b_changeState = protocolState.canChangeState(new StateAckWarp(null, {
|
|
1218
1441
|
dt: Date.now(),
|
|
1219
1442
|
data: { msg, json_msg: json_msgAckWarp }
|
|
1220
1443
|
}));
|
|
1221
|
-
|
|
1444
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
|
|
1222
1445
|
if (!b_changeState)
|
|
1223
1446
|
return false;
|
|
1224
1447
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
@@ -1226,14 +1449,14 @@ class TwoPhW {
|
|
|
1226
1449
|
return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
|
|
1227
1450
|
}
|
|
1228
1451
|
register_msgEngage(msg, json_msgEngage) {
|
|
1229
|
-
|
|
1230
|
-
const json_msgWarp = json_msgEngage.
|
|
1452
|
+
logr_.log(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
|
|
1453
|
+
const json_msgWarp = json_msgEngage._cause;
|
|
1231
1454
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1232
1455
|
const b_changeState = protocolState.canChangeState(new StateEngage(null, {
|
|
1233
1456
|
dt: Date.now(),
|
|
1234
1457
|
data: { msg, json_msg: json_msgEngage }
|
|
1235
1458
|
}));
|
|
1236
|
-
|
|
1459
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
|
|
1237
1460
|
if (!b_changeState)
|
|
1238
1461
|
return false;
|
|
1239
1462
|
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
|
|
@@ -1243,14 +1466,14 @@ class TwoPhW {
|
|
|
1243
1466
|
});
|
|
1244
1467
|
}
|
|
1245
1468
|
_handler_msgAckEngage(msg, json_msgAckEngage) {
|
|
1246
|
-
|
|
1247
|
-
const json_msgWarp = json_msgAckEngage.
|
|
1469
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
|
|
1470
|
+
const json_msgWarp = json_msgAckEngage._cause._cause;
|
|
1248
1471
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1249
1472
|
const b_changeState = protocolState.canChangeState(new StateAckEngage(null, {
|
|
1250
1473
|
dt: Date.now(),
|
|
1251
1474
|
data: { msg, json_msg: json_msgAckEngage }
|
|
1252
1475
|
}));
|
|
1253
|
-
|
|
1476
|
+
logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
|
|
1254
1477
|
if (!b_changeState)
|
|
1255
1478
|
return false;
|
|
1256
1479
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
@@ -1260,27 +1483,27 @@ class TwoPhW {
|
|
|
1260
1483
|
//-------------------------------------------------------------------------------------------------
|
|
1261
1484
|
// receiver Destination (dst)
|
|
1262
1485
|
_handler_msgWarp(msg, json_msgWarp) {
|
|
1263
|
-
|
|
1486
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: ', json_msgWarp]);
|
|
1264
1487
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1265
1488
|
const b_changeState = protocolState.canChangeState(new StateWarp(null, {
|
|
1266
1489
|
dt: Date.now(),
|
|
1267
1490
|
data: { msg, json_msg: json_msgWarp }
|
|
1268
1491
|
}));
|
|
1269
|
-
|
|
1492
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1270
1493
|
if (!b_changeState)
|
|
1271
1494
|
return false;
|
|
1272
1495
|
this.eventLog._addEvent(msg, json_msgWarp);
|
|
1273
1496
|
return this.config._callback_msgWarp(msg, json_msgWarp);
|
|
1274
1497
|
}
|
|
1275
1498
|
register_msgAckWarp(msg, json_msgAckWarp) {
|
|
1276
|
-
|
|
1277
|
-
const json_msgWarp = json_msgAckWarp.
|
|
1499
|
+
logr_.log(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
|
|
1500
|
+
const json_msgWarp = json_msgAckWarp._cause;
|
|
1278
1501
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1279
1502
|
const b_changeState = protocolState.canChangeState(new StateAckWarp(null, {
|
|
1280
1503
|
dt: Date.now(),
|
|
1281
1504
|
data: { msg, json_msg: json_msgAckWarp }
|
|
1282
1505
|
}));
|
|
1283
|
-
|
|
1506
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1284
1507
|
if (!b_changeState)
|
|
1285
1508
|
return false;
|
|
1286
1509
|
const elapsed_ms = Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
@@ -1290,14 +1513,14 @@ class TwoPhW {
|
|
|
1290
1513
|
});
|
|
1291
1514
|
}
|
|
1292
1515
|
_handler_msgEngage(msg, json_msgEngage) {
|
|
1293
|
-
|
|
1294
|
-
const json_msgWarp = json_msgEngage
|
|
1516
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
|
|
1517
|
+
const json_msgWarp = json_msgEngage._cause;
|
|
1295
1518
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1296
1519
|
const b_changeState = protocolState.canChangeState(new StateEngage(null, {
|
|
1297
1520
|
dt: Date.now(),
|
|
1298
1521
|
data: { msg, json_msg: json_msgEngage }
|
|
1299
1522
|
}));
|
|
1300
|
-
|
|
1523
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1301
1524
|
if (!b_changeState)
|
|
1302
1525
|
return false;
|
|
1303
1526
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
@@ -1305,39 +1528,39 @@ class TwoPhW {
|
|
|
1305
1528
|
return this.config._callback_msgEngage(msg, json_msgEngage);
|
|
1306
1529
|
}
|
|
1307
1530
|
register_msgAckEngage(msg, json_msgAckEngage) {
|
|
1308
|
-
|
|
1309
|
-
const json_msgWarp = json_msgAckEngage.
|
|
1531
|
+
logr_.log(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
|
|
1532
|
+
const json_msgWarp = json_msgAckEngage._cause._cause;
|
|
1310
1533
|
const protocolState = this.eventLog.traverse_State(json_msgWarp);
|
|
1311
1534
|
const b_changeState = protocolState.canChangeState(new StateAckEngage(null, {
|
|
1312
1535
|
dt: Date.now(),
|
|
1313
1536
|
data: { msg, json_msg: json_msgAckEngage }
|
|
1314
1537
|
}));
|
|
1315
|
-
|
|
1538
|
+
logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1316
1539
|
if (!b_changeState)
|
|
1317
1540
|
return false;
|
|
1318
1541
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
1319
1542
|
}
|
|
1320
1543
|
//-------------------------------------------------------------------------------------------------
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
if (JSON_MsgAckWarp.validate(
|
|
1544
|
+
handler_json_msgAck(msg, json_msgAck) {
|
|
1545
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msgAck: ', json_msgAck]);
|
|
1546
|
+
if (JSON_MsgAckWarp.validate(json_msgAck) && this._handler_msgAckWarp(msg, json_msgAck))
|
|
1324
1547
|
return true;
|
|
1325
|
-
if (JSON_MsgAckEngage.validate(
|
|
1548
|
+
if (JSON_MsgAckEngage.validate(json_msgAck) && this._handler_msgAckEngage(msg, json_msgAck))
|
|
1326
1549
|
return true;
|
|
1327
1550
|
return false;
|
|
1328
1551
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
if (jsonMsg_cjsExports.
|
|
1552
|
+
handler_json_msgEffect(msg, json_msgEffect) {
|
|
1553
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msgEffect: ', json_msgEffect]);
|
|
1554
|
+
if (jsonMsg_cjsExports.JSON_MsgAck.validate(json_msgEffect) && this.handler_json_msgAck(msg, json_msgEffect))
|
|
1332
1555
|
return true;
|
|
1333
|
-
if (JSON_MsgEngage.validate(
|
|
1556
|
+
if (JSON_MsgEngage.validate(json_msgEffect) && this._handler_msgEngage(msg, json_msgEffect))
|
|
1334
1557
|
return true;
|
|
1335
1558
|
// if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
|
|
1336
1559
|
// return true;
|
|
1337
1560
|
return false;
|
|
1338
1561
|
}
|
|
1339
1562
|
handler_json_msg(msg, json_msg) {
|
|
1340
|
-
|
|
1563
|
+
logr_.log(l_.HANDLERS, () => ['handler_json_msg: ', json_msg]);
|
|
1341
1564
|
if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg))
|
|
1342
1565
|
return true;
|
|
1343
1566
|
// https://attacomsian.com/blog/javascript-iterate-objects
|
|
@@ -1351,8 +1574,8 @@ class TwoPhW {
|
|
|
1351
1574
|
return false;
|
|
1352
1575
|
}
|
|
1353
1576
|
handler_json(msg, json) {
|
|
1354
|
-
|
|
1355
|
-
if (jsonMsg_cjsExports.
|
|
1577
|
+
logr_.log(l_.HANDLERS, () => ['handler_json: ', json]);
|
|
1578
|
+
if (jsonMsg_cjsExports.JSON_MsgEffect.validate(json) && this.handler_json_msgEffect(msg, json))
|
|
1356
1579
|
return true;
|
|
1357
1580
|
if (jsonMsg_cjsExports.JSON_Msg.validate(json) && this.handler_json_msg(msg, json))
|
|
1358
1581
|
return true;
|
|
@@ -1361,8 +1584,11 @@ class TwoPhW {
|
|
|
1361
1584
|
}
|
|
1362
1585
|
|
|
1363
1586
|
exports.EventLog = EventLog;
|
|
1587
|
+
exports.JSON_Msg = jsonMsg_cjsExports.JSON_Msg;
|
|
1588
|
+
exports.JSON_MsgAck = jsonMsg_cjsExports.JSON_MsgAck;
|
|
1364
1589
|
exports.JSON_MsgAckEngage = JSON_MsgAckEngage;
|
|
1365
1590
|
exports.JSON_MsgAckWarp = JSON_MsgAckWarp;
|
|
1591
|
+
exports.JSON_MsgEffect = jsonMsg_cjsExports.JSON_MsgEffect;
|
|
1366
1592
|
exports.JSON_MsgEngage = JSON_MsgEngage;
|
|
1367
1593
|
exports.JSON_MsgOptions = JSON_MsgOptions;
|
|
1368
1594
|
exports.JSON_MsgWarp = JSON_MsgWarp;
|
|
@@ -1373,5 +1599,5 @@ exports.StateINVALID = StateINVALID;
|
|
|
1373
1599
|
exports.StateInitialState = StateInitialState;
|
|
1374
1600
|
exports.StateWarp = StateWarp;
|
|
1375
1601
|
exports.TwoPhW = TwoPhW;
|
|
1376
|
-
exports.
|
|
1602
|
+
exports.logr = logr_;
|
|
1377
1603
|
exports.t_ttl_rtt = time_ttl_rtt_;
|