@rootintf/json-msg 1.1.5 → 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.
- package/README.md +43 -43
- package/antora-docs/antora.yml +5 -5
- package/antora-docs/modules/ROOT/pages/index.adoc +76 -76
- package/dist/ajv-gen-validate.d.cts +1 -0
- package/dist/json-msg.cjs.js +188 -172
- package/dist/json-msg.es.mjs +186 -170
- package/dist/json_msg+ack.d.ts +15 -0
- package/dist/validate-esm.d.mts +47 -0
- package/jasmine.json +6 -6
- package/package.json +14 -8
- package/rollup.config.mjs +36 -23
- package/schema/schema_JSON_Msg.json +38 -0
- package/src/ajv-gen-validate.cjs +28 -31
- package/src/declarations.d.ts +1 -0
- package/src/json_msg+ack.ts +96 -0
- package/src/validate-esm.mjs +1 -1
- package/tests/json_msg+ack.spec.mjs +113 -80
- package/tsconfig.json +115 -0
- package/schema/schema_Msg.json +0 -10
- package/schema/schema_MsgAck_msg.json +0 -15
- package/schema/schema_Msg_msg.json +0 -6
- package/src/json_msg+ack.mjs +0 -93
package/README.md
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
```
|
|
3
|
-
{
|
|
4
|
-
"$id": "validate_Msg",
|
|
5
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
6
|
-
"type" : "object",
|
|
7
|
-
"required" : ["id", "referer", "dt"],
|
|
8
|
-
"properties" : {
|
|
9
|
-
"id" : { "type" : "string"},
|
|
10
|
-
"referer" : { "type" : "string"},
|
|
11
|
-
"dt" : { "type" : "string" }
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
{
|
|
18
|
-
"$id": "validate_Msg_msg",
|
|
19
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
20
|
-
"type" : "object",
|
|
21
|
-
"required" : ["_msg"]
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
{
|
|
27
|
-
"$id": "validate_MsgAck",
|
|
28
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
29
|
-
"type" : "object",
|
|
30
|
-
"required" : ["ack"],
|
|
31
|
-
"properties" : {
|
|
32
|
-
"ack" : {
|
|
33
|
-
"type" : "object",
|
|
34
|
-
"required" : ["ok"],
|
|
35
|
-
"properties" : {
|
|
36
|
-
"ok" : { "type" : "boolean" }
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
TODO: add optional expired property
|
|
1
|
+
|
|
2
|
+
```
|
|
3
|
+
{
|
|
4
|
+
"$id": "validate_Msg",
|
|
5
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
6
|
+
"type" : "object",
|
|
7
|
+
"required" : ["id", "referer", "dt"],
|
|
8
|
+
"properties" : {
|
|
9
|
+
"id" : { "type" : "string"},
|
|
10
|
+
"referer" : { "type" : "string"},
|
|
11
|
+
"dt" : { "type" : "string" }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
{
|
|
18
|
+
"$id": "validate_Msg_msg",
|
|
19
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
20
|
+
"type" : "object",
|
|
21
|
+
"required" : ["_msg"]
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
{
|
|
27
|
+
"$id": "validate_MsgAck",
|
|
28
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
29
|
+
"type" : "object",
|
|
30
|
+
"required" : ["ack"],
|
|
31
|
+
"properties" : {
|
|
32
|
+
"ack" : {
|
|
33
|
+
"type" : "object",
|
|
34
|
+
"required" : ["ok"],
|
|
35
|
+
"properties" : {
|
|
36
|
+
"ok" : { "type" : "boolean" }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
TODO: add optional expired property
|
package/antora-docs/antora.yml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
name: npm-json-msg
|
|
2
|
-
title: npm-json-msg
|
|
3
|
-
version: "0.2"
|
|
4
|
-
nav:
|
|
5
|
-
- modules/ROOT/nav.adoc
|
|
1
|
+
name: npm-json-msg
|
|
2
|
+
title: npm-json-msg
|
|
3
|
+
version: "0.2"
|
|
4
|
+
nav:
|
|
5
|
+
- modules/ROOT/nav.adoc
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
= npm-json-msg
|
|
2
|
-
|
|
3
|
-
Protocols: xref:protocols::JSON_Msg.adoc[]
|
|
4
|
-
|
|
5
|
-
[cols="24h,~"]
|
|
6
|
-
|===
|
|
7
|
-
|npm-json-msg
|
|
8
|
-
|https://gitlab.com/interop-protocols/npm-json-msg.git[^]
|
|
9
|
-
|===
|
|
10
|
-
|
|
11
|
-
== `JSON_Msg`
|
|
12
|
-
|
|
13
|
-
.JSON Schema, Draft-07
|
|
14
|
-
https://json-schema.org/specification-links.html#draft-7[^]
|
|
15
|
-
[source,json-schema/draft-07]
|
|
16
|
-
----
|
|
17
|
-
{
|
|
18
|
-
"$id": "validate_Msg",
|
|
19
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
20
|
-
"type" : "object",
|
|
21
|
-
"required" : ["id", "referer", "dt"],
|
|
22
|
-
"properties" : {
|
|
23
|
-
"id" : { "type" : "string"},
|
|
24
|
-
"referer" : {
|
|
25
|
-
"type" : "array",
|
|
26
|
-
"minItems" : 2,
|
|
27
|
-
"maxItems": 2,
|
|
28
|
-
"items": { "type" : "string" }
|
|
29
|
-
},
|
|
30
|
-
"dt" : { "type" : "string" }
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
----
|
|
34
|
-
|
|
35
|
-
* *referer* [_sic_] --
|
|
36
|
-
** `[0]` -- package, product or service name.
|
|
37
|
-
** `[1]` -- instance specifier.
|
|
38
|
-
|
|
39
|
-
== `JSON_Msg_msg`
|
|
40
|
-
|
|
41
|
-
[source,json-schema/draft-07]
|
|
42
|
-
----
|
|
43
|
-
{
|
|
44
|
-
"$id": "validate_Msg_msg",
|
|
45
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
46
|
-
"type" : "object",
|
|
47
|
-
"required" : ["_msg"]
|
|
48
|
-
|
|
49
|
-
// ... JSON_Msg format
|
|
50
|
-
}
|
|
51
|
-
----
|
|
52
|
-
|
|
53
|
-
* *_msg* -- original message this message is in regards to.
|
|
54
|
-
|
|
55
|
-
== `JSON_MsgAck`
|
|
56
|
-
|
|
57
|
-
[source,json-schema/draft-07]
|
|
58
|
-
----
|
|
59
|
-
{
|
|
60
|
-
"$id": "validate_MsgAck",
|
|
61
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
62
|
-
"type" : "object",
|
|
63
|
-
"required" : ["ack"],
|
|
64
|
-
"properties" : {
|
|
65
|
-
"ack" : {
|
|
66
|
-
"type" : "object",
|
|
67
|
-
"required" : ["ok"],
|
|
68
|
-
"properties" : {
|
|
69
|
-
"ok" : { "type" : "boolean" }
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ... JSON_Msg_msg format
|
|
75
|
-
}
|
|
76
|
-
----
|
|
1
|
+
= npm-json-msg
|
|
2
|
+
|
|
3
|
+
Protocols: xref:protocols::JSON_Msg.adoc[]
|
|
4
|
+
|
|
5
|
+
[cols="24h,~"]
|
|
6
|
+
|===
|
|
7
|
+
|npm-json-msg
|
|
8
|
+
|https://gitlab.com/interop-protocols/npm-json-msg.git[^]
|
|
9
|
+
|===
|
|
10
|
+
|
|
11
|
+
== `JSON_Msg`
|
|
12
|
+
|
|
13
|
+
.JSON Schema, Draft-07
|
|
14
|
+
https://json-schema.org/specification-links.html#draft-7[^]
|
|
15
|
+
[source,json-schema/draft-07]
|
|
16
|
+
----
|
|
17
|
+
{
|
|
18
|
+
"$id": "validate_Msg",
|
|
19
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
20
|
+
"type" : "object",
|
|
21
|
+
"required" : ["id", "referer", "dt"],
|
|
22
|
+
"properties" : {
|
|
23
|
+
"id" : { "type" : "string"},
|
|
24
|
+
"referer" : {
|
|
25
|
+
"type" : "array",
|
|
26
|
+
"minItems" : 2,
|
|
27
|
+
"maxItems": 2,
|
|
28
|
+
"items": { "type" : "string" }
|
|
29
|
+
},
|
|
30
|
+
"dt" : { "type" : "string" }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
----
|
|
34
|
+
|
|
35
|
+
* *referer* [_sic_] --
|
|
36
|
+
** `[0]` -- package, product or service name.
|
|
37
|
+
** `[1]` -- instance specifier.
|
|
38
|
+
|
|
39
|
+
== `JSON_Msg_msg`
|
|
40
|
+
|
|
41
|
+
[source,json-schema/draft-07]
|
|
42
|
+
----
|
|
43
|
+
{
|
|
44
|
+
"$id": "validate_Msg_msg",
|
|
45
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
46
|
+
"type" : "object",
|
|
47
|
+
"required" : ["_msg"]
|
|
48
|
+
|
|
49
|
+
// ... JSON_Msg format
|
|
50
|
+
}
|
|
51
|
+
----
|
|
52
|
+
|
|
53
|
+
* *_msg* -- original message this message is in regards to.
|
|
54
|
+
|
|
55
|
+
== `JSON_MsgAck`
|
|
56
|
+
|
|
57
|
+
[source,json-schema/draft-07]
|
|
58
|
+
----
|
|
59
|
+
{
|
|
60
|
+
"$id": "validate_MsgAck",
|
|
61
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
62
|
+
"type" : "object",
|
|
63
|
+
"required" : ["ack"],
|
|
64
|
+
"properties" : {
|
|
65
|
+
"ack" : {
|
|
66
|
+
"type" : "object",
|
|
67
|
+
"required" : ["ok"],
|
|
68
|
+
"properties" : {
|
|
69
|
+
"ok" : { "type" : "boolean" }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ... JSON_Msg_msg format
|
|
75
|
+
}
|
|
76
|
+
----
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/json-msg.cjs.js
CHANGED
|
@@ -1,6 +1,116 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var bitlogr = require('@knev/bitlogr');
|
|
4
|
+
|
|
5
|
+
const schema_Msg = validate18;
|
|
6
|
+
function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
|
|
7
|
+
evaluated0.props = undefined;
|
|
8
|
+
} if (evaluated0.dynamicItems) {
|
|
9
|
+
evaluated0.items = undefined;
|
|
10
|
+
} {
|
|
11
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
12
|
+
let missing0;
|
|
13
|
+
if ((((data.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))) {
|
|
14
|
+
validate18.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (data.id !== undefined) {
|
|
19
|
+
const _errs1 = errors;
|
|
20
|
+
if (typeof data.id !== "string") {
|
|
21
|
+
validate18.errors = [{ instancePath: instancePath + "/id", schemaPath: "#/properties/id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
var valid0 = _errs1 === errors;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
var valid0 = true;
|
|
28
|
+
}
|
|
29
|
+
if (valid0) {
|
|
30
|
+
if (data.dt !== undefined) {
|
|
31
|
+
const _errs3 = errors;
|
|
32
|
+
if (typeof data.dt !== "string") {
|
|
33
|
+
validate18.errors = [{ instancePath: instancePath + "/dt", schemaPath: "#/properties/dt/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
var valid0 = _errs3 === errors;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
var valid0 = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
validate18.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
} validate18.errors = vErrors; return errors === 0; }
|
|
49
|
+
validate18.evaluated = { "props": { "id": true, "dt": true }, "dynamicProps": false, "dynamicItems": false };
|
|
50
|
+
const schema_MsgEffect = validate19;
|
|
51
|
+
function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
|
|
52
|
+
evaluated0.props = undefined;
|
|
53
|
+
} if (evaluated0.dynamicItems) {
|
|
54
|
+
evaluated0.items = undefined;
|
|
55
|
+
} {
|
|
56
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
57
|
+
let missing0;
|
|
58
|
+
if ((data._cause === undefined) && (missing0 = "_cause")) {
|
|
59
|
+
validate19.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
validate19.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
} validate19.errors = vErrors; return errors === 0; }
|
|
68
|
+
validate19.evaluated = { "dynamicProps": false, "dynamicItems": false };
|
|
69
|
+
const schema_MsgAckEffect = validate20;
|
|
70
|
+
function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
|
|
71
|
+
evaluated0.props = undefined;
|
|
72
|
+
} if (evaluated0.dynamicItems) {
|
|
73
|
+
evaluated0.items = undefined;
|
|
74
|
+
} {
|
|
75
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
76
|
+
let missing0;
|
|
77
|
+
if ((data.ack === undefined) && (missing0 = "ack")) {
|
|
78
|
+
validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (data.ack !== undefined) {
|
|
83
|
+
let data0 = data.ack;
|
|
84
|
+
{
|
|
85
|
+
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
86
|
+
let missing1;
|
|
87
|
+
if ((data0.ok === undefined) && (missing1 = "ok")) {
|
|
88
|
+
validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (data0.ok !== undefined) {
|
|
93
|
+
if (typeof data0.ok !== "boolean") {
|
|
94
|
+
validate20.errors = [{ instancePath: instancePath + "/ack/ok", schemaPath: "#/properties/ack/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
} validate20.errors = vErrors; return errors === 0; }
|
|
113
|
+
validate20.evaluated = { "props": { "ack": true }, "dynamicProps": false, "dynamicItems": false };
|
|
4
114
|
|
|
5
115
|
const byteToHex = [];
|
|
6
116
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -44,10 +154,7 @@ function rng() {
|
|
|
44
154
|
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
45
155
|
var native = { randomUUID };
|
|
46
156
|
|
|
47
|
-
function
|
|
48
|
-
if (native.randomUUID && true && !options) {
|
|
49
|
-
return native.randomUUID();
|
|
50
|
-
}
|
|
157
|
+
function _v4(options, buf, offset) {
|
|
51
158
|
options = options || {};
|
|
52
159
|
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
53
160
|
if (rnds.length < 16) {
|
|
@@ -57,180 +164,89 @@ function v4(options, buf, offset) {
|
|
|
57
164
|
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
58
165
|
return unsafeStringify(rnds);
|
|
59
166
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function handler_default_( /* ... */ ) {
|
|
67
|
-
// https://stackoverflow.com/questions/18746440/passing-multiple-arguments-to-console-log
|
|
68
|
-
var args = Array.prototype.slice.call(arguments);
|
|
69
|
-
console.log.apply(console, args);
|
|
167
|
+
function v4(options, buf, offset) {
|
|
168
|
+
if (native.randomUUID && true && !options) {
|
|
169
|
+
return native.randomUUID();
|
|
170
|
+
}
|
|
171
|
+
return _v4(options);
|
|
70
172
|
}
|
|
71
173
|
|
|
72
174
|
//-------------------------------------------------------------------------------------------------
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
throw new Error('obj must be an object');
|
|
79
|
-
|
|
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) );
|
|
85
|
-
}
|
|
86
|
-
return bigInt;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// console.log(l_toBigInt_({},{}))
|
|
90
|
-
|
|
91
|
-
const LOGR = (function () {
|
|
92
|
-
let _instance; // Private variable to hold the single instance
|
|
93
|
-
|
|
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);
|
|
99
|
-
|
|
100
|
-
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
101
|
-
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
102
|
-
return false;
|
|
103
|
-
|
|
104
|
-
const args = argsFn();
|
|
105
|
-
_handler_log.apply(this, args);
|
|
106
|
-
// _handler_log.apply(this, args);
|
|
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
|
-
}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
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
|
-
})();
|
|
153
|
-
|
|
154
|
-
let LOGR_= LOGR.get_instance();
|
|
155
|
-
const log_= LOGR_.log;
|
|
156
|
-
|
|
157
|
-
const l_= {
|
|
158
|
-
VALIDATION : 0b1 << 0,
|
|
159
|
-
};
|
|
160
|
-
LOGR_.labels= l_;
|
|
161
|
-
|
|
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]');
|
|
179
|
+
//-------------------------------------------------------------------------------------------------
|
|
162
180
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
163
|
-
|
|
164
181
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
165
|
-
var JSON_Msg = (function() {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
var JSON_Msg = (function () {
|
|
183
|
+
return {
|
|
184
|
+
merge: function (json) {
|
|
185
|
+
return Object.assign({
|
|
186
|
+
id: v4(),
|
|
187
|
+
referer: null,
|
|
188
|
+
dt: new Date().toISOString()
|
|
189
|
+
}, json || {});
|
|
190
|
+
},
|
|
191
|
+
validate: function (json) {
|
|
192
|
+
const b_valid = schema_Msg(json);
|
|
193
|
+
if (!b_valid)
|
|
194
|
+
logr_.log(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
|
|
195
|
+
return b_valid;
|
|
196
|
+
},
|
|
197
|
+
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
198
|
+
// https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
|
|
199
|
+
// static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
|
|
200
|
+
// static parse(json) {
|
|
201
|
+
// return this.#ajv_parse_(json);
|
|
202
|
+
// }
|
|
203
|
+
};
|
|
187
204
|
})();
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
205
|
+
var JSON_MsgEffect = (function () {
|
|
206
|
+
return {
|
|
207
|
+
create_with_cause_merge: function (msg_cause, json) {
|
|
208
|
+
const _cause = msg_cause;
|
|
209
|
+
return Object.assign(JSON_Msg.merge(json), { _cause });
|
|
210
|
+
},
|
|
211
|
+
validate: function (json) {
|
|
212
|
+
if (!JSON_Msg.validate(json))
|
|
213
|
+
return false;
|
|
214
|
+
const b_valid = schema_MsgEffect(json);
|
|
215
|
+
if (!b_valid)
|
|
216
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
|
|
217
|
+
return b_valid;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
203
220
|
})();
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
221
|
+
var JSON_MsgAck = (function () {
|
|
222
|
+
return {
|
|
223
|
+
create_with_cause_Ok: function (msg_cause, b_ok = true) {
|
|
224
|
+
return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
|
|
225
|
+
ack: {
|
|
226
|
+
"ok": b_ok,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
create_with_cause_Expired: function (msg_cause) {
|
|
231
|
+
return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
|
|
232
|
+
ack: {
|
|
233
|
+
"ok": false,
|
|
234
|
+
"expired": true
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
validate: function (json) {
|
|
239
|
+
if (!JSON_MsgEffect.validate(json))
|
|
240
|
+
return false;
|
|
241
|
+
const b_valid = schema_MsgAckEffect(json);
|
|
242
|
+
if (!b_valid)
|
|
243
|
+
logr_.log(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
|
|
244
|
+
return b_valid;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
231
247
|
})();
|
|
232
248
|
|
|
233
249
|
exports.JSON_Msg = JSON_Msg;
|
|
234
|
-
exports.
|
|
235
|
-
exports.
|
|
236
|
-
exports.
|
|
250
|
+
exports.JSON_MsgAck = JSON_MsgAck;
|
|
251
|
+
exports.JSON_MsgEffect = JSON_MsgEffect;
|
|
252
|
+
exports.logr = logr_;
|