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