@rootintf/json-msg 2.0.6 → 2.1.6

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.
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var bitlogr = require('@knev/bitlogr');
4
+
3
5
  const schema_Msg = validate18;
4
6
  function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
5
7
  evaluated0.props = undefined;
@@ -169,105 +171,12 @@ function v4(options, buf, offset) {
169
171
  return _v4(options);
170
172
  }
171
173
 
172
- // console.log('OUT', __name({variableName}) );
173
-
174
-
175
174
  //-------------------------------------------------------------------------------------------------
176
-
177
- function handler_default_( /* ... */ ) {
178
- // https://stackoverflow.com/questions/18746440/passing-multiple-arguments-to-console-log
179
- var args = Array.prototype.slice.call(arguments);
180
- console.log.apply(console, args);
181
- }
182
-
175
+ const LOGR_ = bitlogr.LOGR.get_instance();
176
+ const logr_ = LOGR_.create({ labels: bitlogr.l_array(['VALIDATION', 'DROPS', 'HANDLERS']) });
177
+ const l_ = logr_.l;
178
+ // console.log('File location:', import.meta.url, '[Implementation]');
183
179
  //-------------------------------------------------------------------------------------------------
184
-
185
- function l_toBigInt_(obj_labels, obj, ignore= false) {
186
- if (! obj_labels || typeof obj_labels !== 'object')
187
- throw new Error('obj_labels must be an object');
188
- if (! obj || typeof obj !== 'object')
189
- throw new Error('obj must be an object');
190
-
191
- let bigInt = BigInt(0);
192
- for (const [k,v] of Object.entries(obj)) {
193
- if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
194
- bigInt|= BigInt( obj_labels[k] );
195
- // console.log('0b'+ bigInt.toString(2) );
196
- }
197
- return bigInt;
198
- }
199
-
200
- // console.log(l_toBigInt_({},{}))
201
-
202
- const LOGR = (function () {
203
- let _instance; // Private variable to hold the single instance
204
-
205
- function _create_instance() {
206
- // Private state (replacing constructor properties)
207
- let _handler_log = handler_default_;
208
- let _obj_labels = undefined;
209
- let _Bint_toggled = BigInt(0);
210
-
211
- function _log_fxn(nr_logged, argsFn /* args */) {
212
- if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
213
- return false;
214
-
215
- const args = argsFn();
216
- _handler_log.apply(this, args);
217
- // _handler_log.apply(this, args);
218
- return true;
219
- }
220
-
221
- return {
222
- set handler(fx) {
223
- _handler_log = fx;
224
- },
225
- get handler() {
226
- return _handler_log;
227
- },
228
-
229
- get labels() { return _obj_labels; },
230
- set labels(obj) {
231
- _obj_labels = obj;
232
- _Bint_toggled = BigInt(0);
233
- },
234
-
235
- // put= function(label, abbrv) {
236
- // let name= __name(label);
237
- // _labels[name]= label[name];
238
- // console.log(_labels);
239
- // }
240
-
241
- get toggled() { return _Bint_toggled; },
242
- set toggled(obj_toggled) {
243
- _Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
244
- },
245
-
246
- log(nr_logged, argsFn) {
247
-
248
- return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
249
- }
250
- };
251
- }
252
-
253
- // Public interface
254
- return {
255
- get_instance() {
256
- if (!_instance) {
257
- _instance = _create_instance(); // Lazy initialization
258
- }
259
- return _instance;
260
- }
261
- };
262
-
263
- })();
264
-
265
- let LOGR_ = LOGR.get_instance();
266
- const log_ = LOGR_.log;
267
- const l_ = {
268
- VALIDATION: 0b1 << 0,
269
- };
270
- LOGR_.labels = l_;
271
180
  // TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
272
181
  // "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
273
182
  var JSON_Msg = (function () {
@@ -282,7 +191,7 @@ var JSON_Msg = (function () {
282
191
  validate: function (json) {
283
192
  const b_valid = schema_Msg(json);
284
193
  if (!b_valid)
285
- log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
194
+ logr_.log(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
286
195
  return b_valid;
287
196
  },
288
197
  // TODO: requires a separate ajv module require, and JTD specific schema
@@ -304,7 +213,7 @@ var JSON_MsgEffect = (function () {
304
213
  return false;
305
214
  const b_valid = schema_MsgEffect(json);
306
215
  if (!b_valid)
307
- log_(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
216
+ logr_.log(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
308
217
  return b_valid;
309
218
  }
310
219
  };
@@ -331,7 +240,7 @@ var JSON_MsgAck = (function () {
331
240
  return false;
332
241
  const b_valid = schema_MsgAckEffect(json);
333
242
  if (!b_valid)
334
- log_(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
243
+ logr_.log(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
335
244
  return b_valid;
336
245
  }
337
246
  };
@@ -340,4 +249,4 @@ var JSON_MsgAck = (function () {
340
249
  exports.JSON_Msg = JSON_Msg;
341
250
  exports.JSON_MsgAck = JSON_MsgAck;
342
251
  exports.JSON_MsgEffect = JSON_MsgEffect;
343
- exports.l = l_;
252
+ exports.logr = logr_;
@@ -1,3 +1,5 @@
1
+ import { LOGR, l_array } from '@knev/bitlogr';
2
+
1
3
  const schema_Msg = validate18;
2
4
  function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
3
5
  evaluated0.props = undefined;
@@ -167,105 +169,12 @@ function v4(options, buf, offset) {
167
169
  return _v4(options);
168
170
  }
169
171
 
170
- // console.log('OUT', __name({variableName}) );
171
-
172
-
173
172
  //-------------------------------------------------------------------------------------------------
174
-
175
- function handler_default_( /* ... */ ) {
176
- // https://stackoverflow.com/questions/18746440/passing-multiple-arguments-to-console-log
177
- var args = Array.prototype.slice.call(arguments);
178
- console.log.apply(console, args);
179
- }
180
-
173
+ const LOGR_ = LOGR.get_instance();
174
+ const logr_ = LOGR_.create({ labels: l_array(['VALIDATION', 'DROPS', 'HANDLERS']) });
175
+ const l_ = logr_.l;
176
+ // console.log('File location:', import.meta.url, '[Implementation]');
181
177
  //-------------------------------------------------------------------------------------------------
182
-
183
- function l_toBigInt_(obj_labels, obj, ignore= false) {
184
- if (! obj_labels || typeof obj_labels !== 'object')
185
- throw new Error('obj_labels must be an object');
186
- if (! obj || typeof obj !== 'object')
187
- throw new Error('obj must be an object');
188
-
189
- let bigInt = BigInt(0);
190
- for (const [k,v] of Object.entries(obj)) {
191
- if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
192
- bigInt|= BigInt( obj_labels[k] );
193
- // console.log('0b'+ bigInt.toString(2) );
194
- }
195
- return bigInt;
196
- }
197
-
198
- // console.log(l_toBigInt_({},{}))
199
-
200
- const LOGR = (function () {
201
- let _instance; // Private variable to hold the single instance
202
-
203
- function _create_instance() {
204
- // Private state (replacing constructor properties)
205
- let _handler_log = handler_default_;
206
- let _obj_labels = undefined;
207
- let _Bint_toggled = BigInt(0);
208
-
209
- function _log_fxn(nr_logged, argsFn /* args */) {
210
- if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
211
- return false;
212
-
213
- const args = argsFn();
214
- _handler_log.apply(this, args);
215
- // _handler_log.apply(this, args);
216
- return true;
217
- }
218
-
219
- return {
220
- set handler(fx) {
221
- _handler_log = fx;
222
- },
223
- get handler() {
224
- return _handler_log;
225
- },
226
-
227
- get labels() { return _obj_labels; },
228
- set labels(obj) {
229
- _obj_labels = obj;
230
- _Bint_toggled = BigInt(0);
231
- },
232
-
233
- // put= function(label, abbrv) {
234
- // let name= __name(label);
235
- // _labels[name]= label[name];
236
- // console.log(_labels);
237
- // }
238
-
239
- get toggled() { return _Bint_toggled; },
240
- set toggled(obj_toggled) {
241
- _Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
242
- },
243
-
244
- log(nr_logged, argsFn) {
245
-
246
- return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
247
- }
248
- };
249
- }
250
-
251
- // Public interface
252
- return {
253
- get_instance() {
254
- if (!_instance) {
255
- _instance = _create_instance(); // Lazy initialization
256
- }
257
- return _instance;
258
- }
259
- };
260
-
261
- })();
262
-
263
- let LOGR_ = LOGR.get_instance();
264
- const log_ = LOGR_.log;
265
- const l_ = {
266
- VALIDATION: 0b1 << 0,
267
- };
268
- LOGR_.labels = l_;
269
178
  // TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
270
179
  // "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
271
180
  var JSON_Msg = (function () {
@@ -280,7 +189,7 @@ var JSON_Msg = (function () {
280
189
  validate: function (json) {
281
190
  const b_valid = schema_Msg(json);
282
191
  if (!b_valid)
283
- log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
192
+ logr_.log(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
284
193
  return b_valid;
285
194
  },
286
195
  // TODO: requires a separate ajv module require, and JTD specific schema
@@ -302,7 +211,7 @@ var JSON_MsgEffect = (function () {
302
211
  return false;
303
212
  const b_valid = schema_MsgEffect(json);
304
213
  if (!b_valid)
305
- log_(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
214
+ logr_.log(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
306
215
  return b_valid;
307
216
  }
308
217
  };
@@ -329,10 +238,10 @@ var JSON_MsgAck = (function () {
329
238
  return false;
330
239
  const b_valid = schema_MsgAckEffect(json);
331
240
  if (!b_valid)
332
- log_(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
241
+ logr_.log(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
333
242
  return b_valid;
334
243
  }
335
244
  };
336
245
  })();
337
246
 
338
- export { JSON_Msg, JSON_MsgAck, JSON_MsgEffect, l_ as l };
247
+ export { JSON_Msg, JSON_MsgAck, JSON_MsgEffect, logr_ as logr };
@@ -1,6 +1,4 @@
1
- declare const l_: {
2
- VALIDATION: number;
3
- };
1
+ declare const logr_: any;
4
2
  declare var JSON_Msg: {
5
3
  merge: (json: any) => any;
6
4
  validate: (json: any) => boolean;
@@ -14,4 +12,4 @@ declare var JSON_MsgAck: {
14
12
  create_with_cause_Expired: (msg_cause: any) => any;
15
13
  validate: (json: any) => boolean;
16
14
  };
17
- export { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, l_ as l };
15
+ export { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, logr_ as logr };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootintf/json-msg",
3
- "version": "2.0.6",
3
+ "version": "2.1.6",
4
4
  "description": "",
5
5
  "main": "dist/json-msg.cjs.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "homepage": "https://gitlab.com/interface-x/npm-json-msg.git#readme",
27
27
  "dependencies": {
28
- "@knev/bitlogr": "^2.0.11",
28
+ "@knev/bitlogr": "^3.1.3",
29
29
  "ajv": "^8.17.1",
30
30
  "uuid": "^13.0.0"
31
31
  },
package/rollup.config.mjs CHANGED
@@ -16,7 +16,8 @@ export default [
16
16
  commonjs(),
17
17
  json(),
18
18
  typescript({ tsconfig: './tsconfig.json' })
19
- ]
19
+ ],
20
+ external: ['@knev/bitlogr'], // Don't bundle these
20
21
  },
21
22
  {
22
23
  input: 'src/json_msg+ack.ts',
@@ -29,7 +30,8 @@ export default [
29
30
  commonjs(),
30
31
  json(),
31
32
  typescript({ tsconfig: './tsconfig.json' })
32
- ]
33
+ ],
34
+ external: ['@knev/bitlogr'], // Don't bundle these
33
35
  }
34
36
 
35
37
  ];
@@ -2,15 +2,17 @@
2
2
  import { schema_Msg, schema_MsgEffect, schema_MsgAckEffect } from './validate-esm.mjs';
3
3
 
4
4
  import { v4 as uuidv4 } from 'uuid';
5
- import { LOGR, l_LL } from '@knev/bitlogr';
5
+ import { LOGR, lRef, l_array, l_LL } from '@knev/bitlogr';
6
6
 
7
- let LOGR_= LOGR.get_instance();
8
- const log_= LOGR_.log;
7
+ //-------------------------------------------------------------------------------------------------
8
+
9
+ const LOGR_= LOGR.get_instance();
10
+ const logr_= LOGR_.create({ labels: l_array(['VALIDATION', 'DROPS', 'HANDLERS']) });
11
+ const l_ = logr_.l;
9
12
 
10
- const l_= {
11
- VALIDATION : 0b1 << 0,
12
- }
13
- LOGR_.labels= l_;
13
+ // console.log('File location:', import.meta.url, '[Implementation]');
14
+
15
+ //-------------------------------------------------------------------------------------------------
14
16
 
15
17
  // TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
16
18
 
@@ -27,7 +29,7 @@ var JSON_Msg = (function() {
27
29
  validate : function (json) {
28
30
  const b_valid = schema_Msg(json);
29
31
  if (! b_valid)
30
- log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', (schema_Msg as any).errors])
32
+ logr_.log(l_.VALIDATION, () => ['JSON_Msg: validate: ', (schema_Msg as any).errors])
31
33
  return b_valid;
32
34
  },
33
35
  // TODO: requires a separate ajv module require, and JTD specific schema
@@ -50,7 +52,7 @@ var JSON_MsgEffect = (function() {
50
52
  return false;
51
53
  const b_valid= schema_MsgEffect(json);
52
54
  if (! b_valid)
53
- log_(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', (schema_MsgEffect as any).errors])
55
+ logr_.log(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', (schema_MsgEffect as any).errors])
54
56
  return b_valid;
55
57
  }
56
58
  }
@@ -78,7 +80,7 @@ var JSON_MsgAck = (function() {
78
80
  return false;
79
81
  const b_valid= schema_MsgAckEffect(json);
80
82
  if (! b_valid)
81
- log_(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', (schema_MsgAckEffect as any).errors])
83
+ logr_.log(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', (schema_MsgAckEffect as any).errors])
82
84
  return b_valid;
83
85
  }
84
86
  }
@@ -90,5 +92,5 @@ export {
90
92
  JSON_Msg,
91
93
  JSON_MsgEffect,
92
94
  JSON_MsgAck,
93
- l_ as l
95
+ logr_ as logr
94
96
  }
@@ -1,5 +1,26 @@
1
1
 
2
- import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck } from '../dist/json-msg.es.mjs';
2
+ import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, logr as logr_ } from '../dist/json-msg.es.mjs';
3
+ import { LOGR, l_concat } from '@knev/bitlogr';
4
+
5
+ //-------------------------------------------------------------------------------------------------
6
+
7
+ // const obj_labels_ = l_concat(l_json_msg, ['LOG_TEST']);
8
+ // const obj_labels_ = l_concat({}, ['LOG_TEST']);
9
+
10
+ const LOGR_= LOGR.get_instance();
11
+ // const logr_= LOGR_.create({ labels: obj_labels_ });
12
+
13
+ const l_= logr_.l;
14
+
15
+ LOGR_.toggle(l_, {
16
+ VALIDATION : true,
17
+ // LOG_TEST : true
18
+ });
19
+
20
+ // // console.log('File location:', import.meta.url, '[Test]');
21
+ // logr_.log(l_.LOG_TEST, () => ['const l_ ', l_])
22
+
23
+ //-------------------------------------------------------------------------------------------------
3
24
 
4
25
  const json_msgWarp_nomsg = {
5
26
  "id" : "C995A2D2-49BB-4D41-B1D3-C12648652B47",
@@ -55,12 +76,13 @@ describe("JSON_Msg validation", function () {
55
76
  // JSON_Msg_effect
56
77
 
57
78
  describe("JSON_Msg_effect validation", function () {
58
- fit("create_with_cause_merge", function () {
79
+ it("create_with_cause_merge", function () {
59
80
  const json= JSON_MsgEffect.create_with_cause_merge(json_msgWarp_nomsg, {
60
81
  "ack": {
61
82
  "ok": true,
62
83
  },
63
- })
84
+ });
85
+ logr_.log(l_.VALIDATION, () => ['JSON_Msg_effect validation: LOGR test', LOGR.get_instance()._id]);
64
86
 
65
87
  expect( json._cause !== undefined ).toBe(true);
66
88
  expect( JSON_MsgEffect.validate(json) ).toBe(true);