@rootintf/json-msg 1.1.1 → 1.1.3
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/json-msg.cjs.js +75 -53
- package/dist/json-msg.es.mjs +75 -54
- package/package.json +3 -3
- package/src/json_msg+ack.mjs +9 -6
package/dist/json-msg.cjs.js
CHANGED
|
@@ -60,16 +60,6 @@ function v4(options, buf, offset) {
|
|
|
60
60
|
|
|
61
61
|
// console.log('OUT', __name({variableName}) );
|
|
62
62
|
|
|
63
|
-
function l_toBigInt_(ref, obj, ignore= false) {
|
|
64
|
-
console.assert(ref !== BigInt(0), 'no labels initialized');
|
|
65
|
-
let bigInt = BigInt(0);
|
|
66
|
-
for (const [k,v] of Object.entries(obj)) {
|
|
67
|
-
if ( ( ignore || v ) && ref[k])
|
|
68
|
-
bigInt|= BigInt( ref[k] );
|
|
69
|
-
// console.log('0b'+ bigInt.toString(2) );
|
|
70
|
-
}
|
|
71
|
-
return bigInt;
|
|
72
|
-
}
|
|
73
63
|
|
|
74
64
|
//-------------------------------------------------------------------------------------------------
|
|
75
65
|
|
|
@@ -81,62 +71,93 @@ function handler_default_( /* ... */ ) {
|
|
|
81
71
|
|
|
82
72
|
//-------------------------------------------------------------------------------------------------
|
|
83
73
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
|
|
91
|
-
// console.log('NOP')
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
set handler(fx) {
|
|
96
|
-
this._handler_log= fx;
|
|
97
|
-
}
|
|
74
|
+
function l_toBigInt_(obj_labels, obj, ignore= false) {
|
|
75
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
76
|
+
throw new Error('obj_labels must be an object');
|
|
77
|
+
if (! obj || typeof obj !== 'object')
|
|
78
|
+
throw new Error('obj must be an object');
|
|
98
79
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
80
|
+
let bigInt = BigInt(0);
|
|
81
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
82
|
+
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
83
|
+
bigInt|= BigInt( obj_labels[k] );
|
|
84
|
+
// console.log('0b'+ bigInt.toString(2) );
|
|
103
85
|
}
|
|
86
|
+
return bigInt;
|
|
87
|
+
}
|
|
104
88
|
|
|
105
|
-
|
|
106
|
-
// let name= __name(label);
|
|
107
|
-
// _labels[name]= label[name];
|
|
108
|
-
// console.log(_labels);
|
|
109
|
-
// }
|
|
89
|
+
// console.log(l_toBigInt_({},{}))
|
|
110
90
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
|
|
91
|
+
const LOGR = (function () {
|
|
92
|
+
let _instance; // Private variable to hold the single instance
|
|
114
93
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
94
|
+
function _create_instance() {
|
|
95
|
+
// Private state (replacing constructor properties)
|
|
96
|
+
let _handler_log = handler_default_;
|
|
97
|
+
let _obj_labels = undefined;
|
|
98
|
+
let _Bint_toggled = BigInt(0);
|
|
119
99
|
|
|
120
|
-
|
|
121
|
-
if (
|
|
100
|
+
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
101
|
+
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
122
102
|
return false;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
103
|
+
|
|
104
|
+
const args = argsFn();
|
|
105
|
+
_handler_log.apply(this, args);
|
|
106
|
+
// _handler_log.apply(this, args);
|
|
128
107
|
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
set handler(fx) {
|
|
112
|
+
_handler_log = fx;
|
|
113
|
+
},
|
|
114
|
+
get handler() {
|
|
115
|
+
return _handler_log;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
get labels() { return _obj_labels; },
|
|
119
|
+
set labels(obj) {
|
|
120
|
+
_obj_labels = obj;
|
|
121
|
+
_Bint_toggled = BigInt(0);
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
// put= function(label, abbrv) {
|
|
125
|
+
// let name= __name(label);
|
|
126
|
+
// _labels[name]= label[name];
|
|
127
|
+
// console.log(_labels);
|
|
128
|
+
// }
|
|
129
|
+
|
|
130
|
+
get toggled() { return _Bint_toggled; },
|
|
131
|
+
set toggled(obj_toggled) {
|
|
132
|
+
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
log(nr_logged, argsFn) {
|
|
136
|
+
|
|
137
|
+
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
138
|
+
}
|
|
129
139
|
};
|
|
130
140
|
}
|
|
131
141
|
|
|
132
|
-
//
|
|
133
|
-
|
|
142
|
+
// Public interface
|
|
143
|
+
return {
|
|
144
|
+
get_instance() {
|
|
145
|
+
if (!_instance) {
|
|
146
|
+
_instance = _create_instance(); // Lazy initialization
|
|
147
|
+
}
|
|
148
|
+
return _instance;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
})();
|
|
134
153
|
|
|
135
|
-
let LOGR_=
|
|
154
|
+
let LOGR_= LOGR.get_instance();
|
|
155
|
+
const log_= LOGR_.log;
|
|
136
156
|
|
|
137
157
|
const l_= {
|
|
138
158
|
VALIDATION : 0b1 << 0,
|
|
139
159
|
};
|
|
160
|
+
LOGR_.labels= l_;
|
|
140
161
|
|
|
141
162
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
142
163
|
|
|
@@ -153,7 +174,7 @@ var JSON_Msg = (function() {
|
|
|
153
174
|
validate : function (json) {
|
|
154
175
|
const b_valid = schema_Msg(json);
|
|
155
176
|
if (!b_valid)
|
|
156
|
-
|
|
177
|
+
log_(l_.VALIDATION, 'JSON_Msg: validate: ', schema_Msg.errors);
|
|
157
178
|
return b_valid;
|
|
158
179
|
},
|
|
159
180
|
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
@@ -175,7 +196,7 @@ var JSON_Msg_msg = (function() {
|
|
|
175
196
|
return false;
|
|
176
197
|
const b_valid= schema_Msg_msg(json);
|
|
177
198
|
if (!b_valid)
|
|
178
|
-
|
|
199
|
+
log_(l_.VALIDATION, 'JSON_Msg_msg: validate: ', schema_Msg_msg.errors);
|
|
179
200
|
return b_valid;
|
|
180
201
|
}
|
|
181
202
|
}
|
|
@@ -203,7 +224,7 @@ var JSON_MsgAck_msg = (function() {
|
|
|
203
224
|
return false;
|
|
204
225
|
const b_valid= schema_MsgAck_msg(json);
|
|
205
226
|
if (!b_valid)
|
|
206
|
-
|
|
227
|
+
log_(l_.VALIDATION, 'JSON_MsgAck: validate: ', schema_MsgAck_msg.errors);
|
|
207
228
|
return b_valid;
|
|
208
229
|
}
|
|
209
230
|
}
|
|
@@ -212,3 +233,4 @@ var JSON_MsgAck_msg = (function() {
|
|
|
212
233
|
exports.JSON_Msg = JSON_Msg;
|
|
213
234
|
exports.JSON_MsgAck_msg = JSON_MsgAck_msg;
|
|
214
235
|
exports.JSON_Msg_msg = JSON_Msg_msg;
|
|
236
|
+
exports.l = l_;
|
package/dist/json-msg.es.mjs
CHANGED
|
@@ -58,16 +58,6 @@ function v4(options, buf, offset) {
|
|
|
58
58
|
|
|
59
59
|
// console.log('OUT', __name({variableName}) );
|
|
60
60
|
|
|
61
|
-
function l_toBigInt_(ref, obj, ignore= false) {
|
|
62
|
-
console.assert(ref !== BigInt(0), 'no labels initialized');
|
|
63
|
-
let bigInt = BigInt(0);
|
|
64
|
-
for (const [k,v] of Object.entries(obj)) {
|
|
65
|
-
if ( ( ignore || v ) && ref[k])
|
|
66
|
-
bigInt|= BigInt( ref[k] );
|
|
67
|
-
// console.log('0b'+ bigInt.toString(2) );
|
|
68
|
-
}
|
|
69
|
-
return bigInt;
|
|
70
|
-
}
|
|
71
61
|
|
|
72
62
|
//-------------------------------------------------------------------------------------------------
|
|
73
63
|
|
|
@@ -79,62 +69,93 @@ function handler_default_( /* ... */ ) {
|
|
|
79
69
|
|
|
80
70
|
//-------------------------------------------------------------------------------------------------
|
|
81
71
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
|
|
89
|
-
// console.log('NOP')
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
set handler(fx) {
|
|
94
|
-
this._handler_log= fx;
|
|
95
|
-
}
|
|
72
|
+
function l_toBigInt_(obj_labels, obj, ignore= false) {
|
|
73
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
74
|
+
throw new Error('obj_labels must be an object');
|
|
75
|
+
if (! obj || typeof obj !== 'object')
|
|
76
|
+
throw new Error('obj must be an object');
|
|
96
77
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
78
|
+
let bigInt = BigInt(0);
|
|
79
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
80
|
+
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
81
|
+
bigInt|= BigInt( obj_labels[k] );
|
|
82
|
+
// console.log('0b'+ bigInt.toString(2) );
|
|
101
83
|
}
|
|
84
|
+
return bigInt;
|
|
85
|
+
}
|
|
102
86
|
|
|
103
|
-
|
|
104
|
-
// let name= __name(label);
|
|
105
|
-
// _labels[name]= label[name];
|
|
106
|
-
// console.log(_labels);
|
|
107
|
-
// }
|
|
87
|
+
// console.log(l_toBigInt_({},{}))
|
|
108
88
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
|
|
89
|
+
const LOGR = (function () {
|
|
90
|
+
let _instance; // Private variable to hold the single instance
|
|
112
91
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
92
|
+
function _create_instance() {
|
|
93
|
+
// Private state (replacing constructor properties)
|
|
94
|
+
let _handler_log = handler_default_;
|
|
95
|
+
let _obj_labels = undefined;
|
|
96
|
+
let _Bint_toggled = BigInt(0);
|
|
117
97
|
|
|
118
|
-
|
|
119
|
-
if (
|
|
98
|
+
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
99
|
+
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
120
100
|
return false;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
101
|
+
|
|
102
|
+
const args = argsFn();
|
|
103
|
+
_handler_log.apply(this, args);
|
|
104
|
+
// _handler_log.apply(this, args);
|
|
126
105
|
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
set handler(fx) {
|
|
110
|
+
_handler_log = fx;
|
|
111
|
+
},
|
|
112
|
+
get handler() {
|
|
113
|
+
return _handler_log;
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
get labels() { return _obj_labels; },
|
|
117
|
+
set labels(obj) {
|
|
118
|
+
_obj_labels = obj;
|
|
119
|
+
_Bint_toggled = BigInt(0);
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// put= function(label, abbrv) {
|
|
123
|
+
// let name= __name(label);
|
|
124
|
+
// _labels[name]= label[name];
|
|
125
|
+
// console.log(_labels);
|
|
126
|
+
// }
|
|
127
|
+
|
|
128
|
+
get toggled() { return _Bint_toggled; },
|
|
129
|
+
set toggled(obj_toggled) {
|
|
130
|
+
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
log(nr_logged, argsFn) {
|
|
134
|
+
|
|
135
|
+
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
136
|
+
}
|
|
127
137
|
};
|
|
128
138
|
}
|
|
129
139
|
|
|
130
|
-
//
|
|
131
|
-
|
|
140
|
+
// Public interface
|
|
141
|
+
return {
|
|
142
|
+
get_instance() {
|
|
143
|
+
if (!_instance) {
|
|
144
|
+
_instance = _create_instance(); // Lazy initialization
|
|
145
|
+
}
|
|
146
|
+
return _instance;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
})();
|
|
132
151
|
|
|
133
|
-
let LOGR_=
|
|
152
|
+
let LOGR_= LOGR.get_instance();
|
|
153
|
+
const log_= LOGR_.log;
|
|
134
154
|
|
|
135
155
|
const l_= {
|
|
136
156
|
VALIDATION : 0b1 << 0,
|
|
137
157
|
};
|
|
158
|
+
LOGR_.labels= l_;
|
|
138
159
|
|
|
139
160
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
140
161
|
|
|
@@ -151,7 +172,7 @@ var JSON_Msg = (function() {
|
|
|
151
172
|
validate : function (json) {
|
|
152
173
|
const b_valid = schema_Msg(json);
|
|
153
174
|
if (!b_valid)
|
|
154
|
-
|
|
175
|
+
log_(l_.VALIDATION, 'JSON_Msg: validate: ', schema_Msg.errors);
|
|
155
176
|
return b_valid;
|
|
156
177
|
},
|
|
157
178
|
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
@@ -173,7 +194,7 @@ var JSON_Msg_msg = (function() {
|
|
|
173
194
|
return false;
|
|
174
195
|
const b_valid= schema_Msg_msg(json);
|
|
175
196
|
if (!b_valid)
|
|
176
|
-
|
|
197
|
+
log_(l_.VALIDATION, 'JSON_Msg_msg: validate: ', schema_Msg_msg.errors);
|
|
177
198
|
return b_valid;
|
|
178
199
|
}
|
|
179
200
|
}
|
|
@@ -201,10 +222,10 @@ var JSON_MsgAck_msg = (function() {
|
|
|
201
222
|
return false;
|
|
202
223
|
const b_valid= schema_MsgAck_msg(json);
|
|
203
224
|
if (!b_valid)
|
|
204
|
-
|
|
225
|
+
log_(l_.VALIDATION, 'JSON_MsgAck: validate: ', schema_MsgAck_msg.errors);
|
|
205
226
|
return b_valid;
|
|
206
227
|
}
|
|
207
228
|
}
|
|
208
229
|
})();
|
|
209
230
|
|
|
210
|
-
export { JSON_Msg, JSON_MsgAck_msg, JSON_Msg_msg };
|
|
231
|
+
export { JSON_Msg, JSON_MsgAck_msg, JSON_Msg_msg, l_ as l };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rootintf/json-msg",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/json-msg.cjs.js",
|
|
6
6
|
"browser": "dist/json-msg.es.mjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://gitlab.com/interface-x/npm-json-msg.git#readme",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@knev/bitlogr": "^0.
|
|
27
|
+
"@knev/bitlogr": "^2.0.11",
|
|
28
28
|
"ajv": "^8.17.1",
|
|
29
29
|
"uuid": "^11.1.0"
|
|
30
30
|
},
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"ajv-cli": "^5.0.0",
|
|
36
36
|
"del-cli": "^6.0.0",
|
|
37
37
|
"jasmine": "^5.6.0",
|
|
38
|
-
"rollup": "^4.
|
|
38
|
+
"rollup": "^4.39.0"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/json_msg+ack.mjs
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
import { schema_Msg, schema_Msg_msg, schema_MsgAck_msg } from './validate-esm.mjs';
|
|
3
3
|
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
-
import {
|
|
5
|
+
import { LOGR, l_LL } from '@knev/bitlogr';
|
|
6
6
|
|
|
7
|
-
let LOGR_=
|
|
7
|
+
let LOGR_= LOGR.get_instance();
|
|
8
|
+
const log_= LOGR_.log;
|
|
8
9
|
|
|
9
10
|
const l_= {
|
|
10
11
|
VALIDATION : 0b1 << 0,
|
|
11
12
|
}
|
|
13
|
+
LOGR_.labels= l_;
|
|
12
14
|
|
|
13
15
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
14
16
|
|
|
@@ -25,7 +27,7 @@ var JSON_Msg = (function() {
|
|
|
25
27
|
validate : function (json) {
|
|
26
28
|
const b_valid = schema_Msg(json);
|
|
27
29
|
if (!b_valid)
|
|
28
|
-
|
|
30
|
+
log_(l_.VALIDATION, 'JSON_Msg: validate: ', schema_Msg.errors)
|
|
29
31
|
return b_valid;
|
|
30
32
|
},
|
|
31
33
|
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
@@ -47,7 +49,7 @@ var JSON_Msg_msg = (function() {
|
|
|
47
49
|
return false;
|
|
48
50
|
const b_valid= schema_Msg_msg(json);
|
|
49
51
|
if (!b_valid)
|
|
50
|
-
|
|
52
|
+
log_(l_.VALIDATION, 'JSON_Msg_msg: validate: ', schema_Msg_msg.errors)
|
|
51
53
|
return b_valid;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -75,7 +77,7 @@ var JSON_MsgAck_msg = (function() {
|
|
|
75
77
|
return false;
|
|
76
78
|
const b_valid= schema_MsgAck_msg(json);
|
|
77
79
|
if (!b_valid)
|
|
78
|
-
|
|
80
|
+
log_(l_.VALIDATION, 'JSON_MsgAck: validate: ', schema_MsgAck_msg.errors)
|
|
79
81
|
return b_valid;
|
|
80
82
|
}
|
|
81
83
|
}
|
|
@@ -86,5 +88,6 @@ var JSON_MsgAck_msg = (function() {
|
|
|
86
88
|
export {
|
|
87
89
|
JSON_Msg,
|
|
88
90
|
JSON_Msg_msg,
|
|
89
|
-
JSON_MsgAck_msg
|
|
91
|
+
JSON_MsgAck_msg,
|
|
92
|
+
l_ as l
|
|
90
93
|
}
|