@rootintf/json-msg 1.0.4 → 1.1.1
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 +59 -65
- package/dist/json-msg.es.mjs +59 -65
- package/package.json +1 -1
- package/src/json_msg+ack.mjs +57 -63
- package/tests/json_msg+ack.spec.mjs +0 -3
package/dist/json-msg.cjs.js
CHANGED
|
@@ -142,77 +142,71 @@ const l_= {
|
|
|
142
142
|
|
|
143
143
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
144
144
|
var JSON_Msg = (function() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// static parse(json) {
|
|
167
|
-
// return this.#ajv_parse_(json);
|
|
168
|
-
// }
|
|
169
|
-
return new JSON_Msg();
|
|
145
|
+
return {
|
|
146
|
+
merge: function(json) {
|
|
147
|
+
return Object.assign({
|
|
148
|
+
id: v4(),
|
|
149
|
+
referer: null,
|
|
150
|
+
dt: new Date().toISOString()
|
|
151
|
+
}, json || {});
|
|
152
|
+
},
|
|
153
|
+
validate : function (json) {
|
|
154
|
+
const b_valid = schema_Msg(json);
|
|
155
|
+
if (!b_valid)
|
|
156
|
+
LOGR_.log(l_.VALIDATION, 'JSON_Msg: validate: ', schema_Msg.errors);
|
|
157
|
+
return b_valid;
|
|
158
|
+
},
|
|
159
|
+
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
160
|
+
// https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
|
|
161
|
+
// static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
|
|
162
|
+
// static parse(json) {
|
|
163
|
+
// return this.#ajv_parse_(json);
|
|
164
|
+
// }
|
|
165
|
+
}
|
|
170
166
|
})();
|
|
171
167
|
|
|
172
168
|
var JSON_Msg_msg = (function() {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
-
return new JSON_Msg_msg()
|
|
169
|
+
return {
|
|
170
|
+
create_with_msg_merge: function(_msg, json) {
|
|
171
|
+
return Object.assign(JSON_Msg.merge(json), { _msg });
|
|
172
|
+
},
|
|
173
|
+
validate : function(json) {
|
|
174
|
+
if (! JSON_Msg.validate(json))
|
|
175
|
+
return false;
|
|
176
|
+
const b_valid= schema_Msg_msg(json);
|
|
177
|
+
if (!b_valid)
|
|
178
|
+
LOGR_.log(l_.VALIDATION, 'JSON_Msg_msg: validate: ', schema_Msg_msg.errors);
|
|
179
|
+
return b_valid;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
188
182
|
})();
|
|
189
183
|
|
|
190
184
|
var JSON_MsgAck_msg = (function() {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
185
|
+
return {
|
|
186
|
+
create_with_msgOk : function(_msg, b_ok= true) {
|
|
187
|
+
return JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
188
|
+
ack : {
|
|
189
|
+
"ok" : b_ok,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
create_with_msgExpired : function(_msg) {
|
|
194
|
+
return JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
195
|
+
ack : {
|
|
196
|
+
"ok" : false,
|
|
197
|
+
"expired" : true
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
validate : function(json) {
|
|
202
|
+
if (! JSON_Msg_msg.validate(json))
|
|
203
|
+
return false;
|
|
204
|
+
const b_valid= schema_MsgAck_msg(json);
|
|
205
|
+
if (!b_valid)
|
|
206
|
+
LOGR_.log(l_.VALIDATION, 'JSON_MsgAck: validate: ', schema_MsgAck_msg.errors);
|
|
207
|
+
return b_valid;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
216
210
|
})();
|
|
217
211
|
|
|
218
212
|
exports.JSON_Msg = JSON_Msg;
|
package/dist/json-msg.es.mjs
CHANGED
|
@@ -140,77 +140,71 @@ const l_= {
|
|
|
140
140
|
|
|
141
141
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
142
142
|
var JSON_Msg = (function() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// static parse(json) {
|
|
165
|
-
// return this.#ajv_parse_(json);
|
|
166
|
-
// }
|
|
167
|
-
return new JSON_Msg();
|
|
143
|
+
return {
|
|
144
|
+
merge: function(json) {
|
|
145
|
+
return Object.assign({
|
|
146
|
+
id: v4(),
|
|
147
|
+
referer: null,
|
|
148
|
+
dt: new Date().toISOString()
|
|
149
|
+
}, json || {});
|
|
150
|
+
},
|
|
151
|
+
validate : function (json) {
|
|
152
|
+
const b_valid = schema_Msg(json);
|
|
153
|
+
if (!b_valid)
|
|
154
|
+
LOGR_.log(l_.VALIDATION, 'JSON_Msg: validate: ', schema_Msg.errors);
|
|
155
|
+
return b_valid;
|
|
156
|
+
},
|
|
157
|
+
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
158
|
+
// https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
|
|
159
|
+
// static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
|
|
160
|
+
// static parse(json) {
|
|
161
|
+
// return this.#ajv_parse_(json);
|
|
162
|
+
// }
|
|
163
|
+
}
|
|
168
164
|
})();
|
|
169
165
|
|
|
170
166
|
var JSON_Msg_msg = (function() {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
return new JSON_Msg_msg()
|
|
167
|
+
return {
|
|
168
|
+
create_with_msg_merge: function(_msg, json) {
|
|
169
|
+
return Object.assign(JSON_Msg.merge(json), { _msg });
|
|
170
|
+
},
|
|
171
|
+
validate : function(json) {
|
|
172
|
+
if (! JSON_Msg.validate(json))
|
|
173
|
+
return false;
|
|
174
|
+
const b_valid= schema_Msg_msg(json);
|
|
175
|
+
if (!b_valid)
|
|
176
|
+
LOGR_.log(l_.VALIDATION, 'JSON_Msg_msg: validate: ', schema_Msg_msg.errors);
|
|
177
|
+
return b_valid;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
186
180
|
})();
|
|
187
181
|
|
|
188
182
|
var JSON_MsgAck_msg = (function() {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
183
|
+
return {
|
|
184
|
+
create_with_msgOk : function(_msg, b_ok= true) {
|
|
185
|
+
return JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
186
|
+
ack : {
|
|
187
|
+
"ok" : b_ok,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
create_with_msgExpired : function(_msg) {
|
|
192
|
+
return JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
193
|
+
ack : {
|
|
194
|
+
"ok" : false,
|
|
195
|
+
"expired" : true
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
validate : function(json) {
|
|
200
|
+
if (! JSON_Msg_msg.validate(json))
|
|
201
|
+
return false;
|
|
202
|
+
const b_valid= schema_MsgAck_msg(json);
|
|
203
|
+
if (!b_valid)
|
|
204
|
+
LOGR_.log(l_.VALIDATION, 'JSON_MsgAck: validate: ', schema_MsgAck_msg.errors);
|
|
205
|
+
return b_valid;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
214
208
|
})();
|
|
215
209
|
|
|
216
210
|
export { JSON_Msg, JSON_MsgAck_msg, JSON_Msg_msg };
|
package/package.json
CHANGED
package/src/json_msg+ack.mjs
CHANGED
|
@@ -14,77 +14,71 @@ const l_= {
|
|
|
14
14
|
|
|
15
15
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
16
16
|
var JSON_Msg = (function() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// static parse(json) {
|
|
39
|
-
// return this.#ajv_parse_(json);
|
|
40
|
-
// }
|
|
41
|
-
return new JSON_Msg();
|
|
17
|
+
return {
|
|
18
|
+
merge: function(json) {
|
|
19
|
+
return Object.assign({
|
|
20
|
+
id: uuidv4(),
|
|
21
|
+
referer: null,
|
|
22
|
+
dt: new Date().toISOString()
|
|
23
|
+
}, json || {});
|
|
24
|
+
},
|
|
25
|
+
validate : function (json) {
|
|
26
|
+
const b_valid = schema_Msg(json);
|
|
27
|
+
if (!b_valid)
|
|
28
|
+
LOGR_.log(l_.VALIDATION, 'JSON_Msg: validate: ', schema_Msg.errors)
|
|
29
|
+
return b_valid;
|
|
30
|
+
},
|
|
31
|
+
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
32
|
+
// https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
|
|
33
|
+
// static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
|
|
34
|
+
// static parse(json) {
|
|
35
|
+
// return this.#ajv_parse_(json);
|
|
36
|
+
// }
|
|
37
|
+
}
|
|
42
38
|
})();
|
|
43
39
|
|
|
44
40
|
var JSON_Msg_msg = (function() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return b_valid;
|
|
41
|
+
return {
|
|
42
|
+
create_with_msg_merge: function(_msg, json) {
|
|
43
|
+
return Object.assign(JSON_Msg.merge(json), { _msg });
|
|
44
|
+
},
|
|
45
|
+
validate : function(json) {
|
|
46
|
+
if (! JSON_Msg.validate(json))
|
|
47
|
+
return false;
|
|
48
|
+
const b_valid= schema_Msg_msg(json);
|
|
49
|
+
if (!b_valid)
|
|
50
|
+
LOGR_.log(l_.VALIDATION, 'JSON_Msg_msg: validate: ', schema_Msg_msg.errors)
|
|
51
|
+
return b_valid;
|
|
52
|
+
}
|
|
58
53
|
}
|
|
59
|
-
return new JSON_Msg_msg()
|
|
60
54
|
})();
|
|
61
55
|
|
|
62
56
|
var JSON_MsgAck_msg = (function() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
return {
|
|
58
|
+
create_with_msgOk : function(_msg, b_ok= true) {
|
|
59
|
+
return JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
60
|
+
ack : {
|
|
61
|
+
"ok" : b_ok,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
create_with_msgExpired : function(_msg) {
|
|
66
|
+
return JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
67
|
+
ack : {
|
|
68
|
+
"ok" : false,
|
|
69
|
+
"expired" : true
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
validate : function(json) {
|
|
74
|
+
if (! JSON_Msg_msg.validate(json))
|
|
75
|
+
return false;
|
|
76
|
+
const b_valid= schema_MsgAck_msg(json);
|
|
77
|
+
if (!b_valid)
|
|
78
|
+
LOGR_.log(l_.VALIDATION, 'JSON_MsgAck: validate: ', schema_MsgAck_msg.errors)
|
|
79
|
+
return b_valid;
|
|
80
|
+
}
|
|
86
81
|
}
|
|
87
|
-
return new JSON_MsgAck_msg();
|
|
88
82
|
})();
|
|
89
83
|
|
|
90
84
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -42,13 +42,10 @@ describe("JSON_Msg validation", function () {
|
|
|
42
42
|
it("JSON_Msg.merge({ foo: \"bar\" })", function () {
|
|
43
43
|
const merged_msg = JSON_Msg.merge({ foo: "bar" });
|
|
44
44
|
|
|
45
|
-
expect( merged_msg.constructor.name ).toBe('JSON_Msg');
|
|
46
45
|
expect( merged_msg.foo ).toBe('bar');
|
|
47
46
|
expect( JSON_Msg.validate(merged_msg) ).toBe(true);
|
|
48
47
|
});
|
|
49
48
|
|
|
50
|
-
// console.log(); // true
|
|
51
|
-
|
|
52
49
|
it("JSON_Msg.validate(json_msgAckWarp)", function () {
|
|
53
50
|
expect( JSON_Msg.validate(json_msgAckWarp) ).toBe(true);
|
|
54
51
|
});
|