@rootintf/json-msg 4.0.6-api.5 → 4.0.11-api.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 +15 -14
- package/dist/json-msg.cjs.js +87 -35
- package/dist/json-msg.es.mjs +87 -35
- package/dist/json_msg+ack.d.ts +12 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# npm-json-msg (`@rootintf/json-msg`)
|
|
2
2
|
|
|
3
|
-
The npm implementation of the **`JSON_Msg` envelopes**, at api.
|
|
3
|
+
The npm implementation of the **`JSON_Msg` envelopes**, at api.6: the envelope every message on an
|
|
4
4
|
[IPSME](https://ipsme.dev) messaging environment (ME) travels in, and the three that build on it.
|
|
5
5
|
It is the npm twin of `cpp-json-msg`.
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ It is the npm twin of `cpp-json-msg`.
|
|
|
9
9
|
| `JSON_Msg` | | `id`, `referer`, `dt` | a message: which one, who published it, when |
|
|
10
10
|
| `JSON_Eff` | `JSON_Msg` | `_cause` | an effect: a message published because of another, which it carries whole |
|
|
11
11
|
| `JSON_Ack` | `JSON_Eff` | `ack` | an acknowledgement: the final answer to its cause, with a verdict (`ack.ok`) |
|
|
12
|
-
| `
|
|
12
|
+
| `JSON_Hold` | `JSON_Eff` | `hold` | a hold: an interim answer. The cause is being worked on and is not concluded |
|
|
13
13
|
|
|
14
14
|
What the fields mean is in the specification (`spec-json-msg` on <https://root-interface.se/protocols>).
|
|
15
15
|
How to use the package in full is in `antora-docs/modules/ROOT/pages/index.adoc`; this file is the short version.
|
|
@@ -25,7 +25,7 @@ npm i @rootintf/json-msg
|
|
|
25
25
|
Dual ESM and CJS, with types.
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
import { JSON_Msg, JSON_Eff, JSON_Ack,
|
|
28
|
+
import { JSON_Msg, JSON_Eff, JSON_Ack, JSON_Hold } from '@rootintf/json-msg';
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
A project rarely calls the package for its own messages. The interfaces `@rootintf/iface-gen` generates
|
|
@@ -49,17 +49,18 @@ const json_nack = JSON_Ack.create_with_cause_Ok(json_msg, false); // ack: { ok
|
|
|
49
49
|
const json_late = JSON_Ack.create_with_cause_Expired(json_msg); // ack: { ok: false, expired: true }
|
|
50
50
|
|
|
51
51
|
// an interim answer: "still on it; expect the next word within 15 s"
|
|
52
|
-
const
|
|
52
|
+
const json_hold = JSON_Hold.create_with_cause_ttl(json_msg, 15000, { eta_msec: 240000, progress: { done: 40, total: 100 }, stage: 'downloading' });
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
### A
|
|
55
|
+
### A hold
|
|
56
56
|
|
|
57
|
-
`
|
|
58
|
-
another
|
|
59
|
-
`eta_msec` (an estimate of the time left), `
|
|
57
|
+
`hold.ttl_msec` is a lease, measured from the hold's own `dt`: the next word about the cause,
|
|
58
|
+
another hold or the acknowledgement, is due before it runs out. It is the only required field.
|
|
59
|
+
`eta_msec` (an estimate of the time left), `progress` (`{ done, total?, unit? }`: how much of the work is
|
|
60
|
+
done, of how much, counted in what) and `stage` are optional.
|
|
60
61
|
|
|
61
62
|
```js
|
|
62
|
-
const i_lease_msec =
|
|
63
|
+
const i_lease_msec = JSON_Hold.lease_epoch_msec(json_hold); // dt + ttl_msec, or null when dt does not read
|
|
63
64
|
```
|
|
64
65
|
|
|
65
66
|
The package defines the fields and this arithmetic, and no policy: how much of a lease is believed, and
|
|
@@ -72,12 +73,12 @@ TypeScript type predicate. A message that fails is not an error; it is somebody
|
|
|
72
73
|
|
|
73
74
|
```js
|
|
74
75
|
if (JSON_Ack.validate(json)) { /* json.ack.ok, json._cause */ }
|
|
75
|
-
else if (
|
|
76
|
+
else if (JSON_Hold.validate(json)) { /* json.hold.ttl_msec, json._cause */ }
|
|
76
77
|
else if (JSON_Eff.validate(json)) { /* json._cause */ }
|
|
77
78
|
else if (JSON_Msg.validate(json)) { /* a message */ }
|
|
78
79
|
```
|
|
79
80
|
|
|
80
|
-
Test for an acknowledgement before a
|
|
81
|
+
Test for an acknowledgement before a hold: a message that carries both is an acknowledgement.
|
|
81
82
|
|
|
82
83
|
### Reading `dt`
|
|
83
84
|
|
|
@@ -102,9 +103,9 @@ the forms `cpp-json-msg` reads, and nothing else.
|
|
|
102
103
|
| `JSON_Ack.create_with_cause_Ok(msg_cause, b_ok = true)` | a new acknowledgement, with the verdict |
|
|
103
104
|
| `JSON_Ack.create_with_cause_Expired(msg_cause)` | a new acknowledgement, `ok: false` and `expired: true` |
|
|
104
105
|
| `JSON_Ack.validate(json)` | is it an acknowledgement? |
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
106
|
+
| `JSON_Hold.create_with_cause_ttl(msg_cause, ttl_msec, body = {})` | a new hold: the lease, with the members of `body` merged in |
|
|
107
|
+
| `JSON_Hold.lease_epoch_msec(json_hold)` | the instant the lease ends, or `null` |
|
|
108
|
+
| `JSON_Hold.validate(json)` | is it a hold? |
|
|
108
109
|
| `logr` | the package's `@knev/bitlogr` logger (name `npm:json-msg`, label `VALIDATION`) |
|
|
109
110
|
|
|
110
111
|
Each of the four names is also a TypeScript type, for a protocol's own messages to extend.
|
package/dist/json-msg.cjs.js
CHANGED
|
@@ -111,7 +111,7 @@ function validate20(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
111
111
|
}
|
|
112
112
|
} validate20.errors = vErrors; return errors === 0; }
|
|
113
113
|
validate20.evaluated = { "props": { "ack": true }, "dynamicProps": false, "dynamicItems": false };
|
|
114
|
-
const
|
|
114
|
+
const schema_Hold = validate21;
|
|
115
115
|
function validate21(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate21.evaluated; if (evaluated0.dynamicProps) {
|
|
116
116
|
evaluated0.props = undefined;
|
|
117
117
|
} if (evaluated0.dynamicItems) {
|
|
@@ -119,18 +119,18 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
119
119
|
} {
|
|
120
120
|
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
121
121
|
let missing0;
|
|
122
|
-
if ((data.
|
|
122
|
+
if ((data.hold === undefined) && (missing0 = "hold")) {
|
|
123
123
|
validate21.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
124
124
|
return false;
|
|
125
125
|
}
|
|
126
126
|
else {
|
|
127
|
-
if (data.
|
|
128
|
-
let data0 = data.
|
|
127
|
+
if (data.hold !== undefined) {
|
|
128
|
+
let data0 = data.hold;
|
|
129
129
|
{
|
|
130
130
|
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
131
131
|
let missing1;
|
|
132
132
|
if ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec")) {
|
|
133
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
133
|
+
validate21.errors = [{ instancePath: instancePath + "/hold", schemaPath: "#/properties/hold/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
134
134
|
return false;
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
@@ -138,13 +138,13 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
138
138
|
let data1 = data0.ttl_msec;
|
|
139
139
|
const _errs4 = errors;
|
|
140
140
|
if (!(((typeof data1 == "number") && (!(data1 % 1) && !isNaN(data1))) && (isFinite(data1)))) {
|
|
141
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
141
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/ttl_msec", schemaPath: "#/properties/hold/properties/ttl_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
142
142
|
return false;
|
|
143
143
|
}
|
|
144
144
|
{
|
|
145
145
|
if ((typeof data1 == "number") && (isFinite(data1))) {
|
|
146
146
|
if (data1 <= 0 || isNaN(data1)) {
|
|
147
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
147
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/ttl_msec", schemaPath: "#/properties/hold/properties/ttl_msec/exclusiveMinimum", keyword: "exclusiveMinimum", params: { comparison: ">", limit: 0 }, message: "must be > 0" }];
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -159,13 +159,13 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
159
159
|
let data2 = data0.eta_msec;
|
|
160
160
|
const _errs6 = errors;
|
|
161
161
|
if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
|
|
162
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
162
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/eta_msec", schemaPath: "#/properties/hold/properties/eta_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
163
163
|
return false;
|
|
164
164
|
}
|
|
165
165
|
{
|
|
166
166
|
if ((typeof data2 == "number") && (isFinite(data2))) {
|
|
167
167
|
if (data2 < 0 || isNaN(data2)) {
|
|
168
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
168
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/eta_msec", schemaPath: "#/properties/hold/properties/eta_msec/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
|
|
169
169
|
return false;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
@@ -176,24 +176,76 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
176
176
|
var valid1 = true;
|
|
177
177
|
}
|
|
178
178
|
if (valid1) {
|
|
179
|
-
if (data0.
|
|
180
|
-
let data3 = data0.
|
|
179
|
+
if (data0.progress !== undefined) {
|
|
180
|
+
let data3 = data0.progress;
|
|
181
181
|
const _errs8 = errors;
|
|
182
182
|
{
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
if (data3 && typeof data3 == "object" && !Array.isArray(data3)) {
|
|
184
|
+
let missing2;
|
|
185
|
+
if ((data3.done === undefined) && (missing2 = "done")) {
|
|
186
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress", schemaPath: "#/properties/hold/properties/progress/required", keyword: "required", params: { missingProperty: missing2 }, message: "must have required property '" + missing2 + "'" }];
|
|
186
187
|
return false;
|
|
187
188
|
}
|
|
188
189
|
else {
|
|
189
|
-
if (data3
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
if (data3.done !== undefined) {
|
|
191
|
+
let data4 = data3.done;
|
|
192
|
+
const _errs10 = errors;
|
|
193
|
+
{
|
|
194
|
+
if ((typeof data4 == "number") && (isFinite(data4))) {
|
|
195
|
+
if (data4 < 0 || isNaN(data4)) {
|
|
196
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/done", schemaPath: "#/properties/hold/properties/progress/properties/done/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/done", schemaPath: "#/properties/hold/properties/progress/properties/done/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
var valid2 = _errs10 === errors;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
var valid2 = true;
|
|
209
|
+
}
|
|
210
|
+
if (valid2) {
|
|
211
|
+
if (data3.total !== undefined) {
|
|
212
|
+
let data5 = data3.total;
|
|
213
|
+
const _errs12 = errors;
|
|
214
|
+
{
|
|
215
|
+
if ((typeof data5 == "number") && (isFinite(data5))) {
|
|
216
|
+
if (data5 <= 0 || isNaN(data5)) {
|
|
217
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/total", schemaPath: "#/properties/hold/properties/progress/properties/total/exclusiveMinimum", keyword: "exclusiveMinimum", params: { comparison: ">", limit: 0 }, message: "must be > 0" }];
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/total", schemaPath: "#/properties/hold/properties/progress/properties/total/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
var valid2 = _errs12 === errors;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
var valid2 = true;
|
|
230
|
+
}
|
|
231
|
+
if (valid2) {
|
|
232
|
+
if (data3.unit !== undefined) {
|
|
233
|
+
const _errs14 = errors;
|
|
234
|
+
if (typeof data3.unit !== "string") {
|
|
235
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/unit", schemaPath: "#/properties/hold/properties/progress/properties/unit/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
var valid2 = _errs14 === errors;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
var valid2 = true;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
192
244
|
}
|
|
193
245
|
}
|
|
194
246
|
}
|
|
195
247
|
else {
|
|
196
|
-
validate21.errors = [{ instancePath: instancePath + "/progress
|
|
248
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress", schemaPath: "#/properties/hold/properties/progress/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
197
249
|
return false;
|
|
198
250
|
}
|
|
199
251
|
}
|
|
@@ -204,12 +256,12 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
204
256
|
}
|
|
205
257
|
if (valid1) {
|
|
206
258
|
if (data0.stage !== undefined) {
|
|
207
|
-
const
|
|
259
|
+
const _errs16 = errors;
|
|
208
260
|
if (typeof data0.stage !== "string") {
|
|
209
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
261
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/stage", schemaPath: "#/properties/hold/properties/stage/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
210
262
|
return false;
|
|
211
263
|
}
|
|
212
|
-
var valid1 =
|
|
264
|
+
var valid1 = _errs16 === errors;
|
|
213
265
|
}
|
|
214
266
|
else {
|
|
215
267
|
var valid1 = true;
|
|
@@ -220,7 +272,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
220
272
|
}
|
|
221
273
|
}
|
|
222
274
|
else {
|
|
223
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
275
|
+
validate21.errors = [{ instancePath: instancePath + "/hold", schemaPath: "#/properties/hold/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
224
276
|
return false;
|
|
225
277
|
}
|
|
226
278
|
}
|
|
@@ -232,7 +284,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
232
284
|
return false;
|
|
233
285
|
}
|
|
234
286
|
} validate21.errors = vErrors; return errors === 0; }
|
|
235
|
-
validate21.evaluated = { "props": { "
|
|
287
|
+
validate21.evaluated = { "props": { "hold": true }, "dynamicProps": false, "dynamicItems": false };
|
|
236
288
|
|
|
237
289
|
const byteToHex = [];
|
|
238
290
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -367,27 +419,27 @@ var JSON_Ack = (function () {
|
|
|
367
419
|
}
|
|
368
420
|
};
|
|
369
421
|
})();
|
|
370
|
-
var
|
|
422
|
+
var JSON_Hold = (function () {
|
|
371
423
|
return {
|
|
372
|
-
//
|
|
373
|
-
// protocol's own). The lease is the parameter, whatever `
|
|
374
|
-
create_with_cause_ttl: function (msg_cause, ttl_msec,
|
|
424
|
+
// hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, progress, stage, a
|
|
425
|
+
// protocol's own). The lease is the parameter, whatever `body` carried.
|
|
426
|
+
create_with_cause_ttl: function (msg_cause, ttl_msec, body) {
|
|
375
427
|
return JSON_Eff.create_with_cause_merge(msg_cause, {
|
|
376
|
-
|
|
428
|
+
hold: Object.assign({}, body || {}, { ttl_msec }),
|
|
377
429
|
});
|
|
378
430
|
},
|
|
379
|
-
// the instant the lease ends, as epoch milliseconds: the message's own dt +
|
|
431
|
+
// the instant the lease ends, as epoch milliseconds: the message's own dt + hold.ttl_msec. null when the
|
|
380
432
|
// dt does not read: a lease with no anchor, which the caller cannot honour.
|
|
381
|
-
lease_epoch_msec: function (
|
|
382
|
-
const i_dt_msec = JSON_Msg.dt_epoch_msec(
|
|
383
|
-
return (i_dt_msec === null) ? null : i_dt_msec +
|
|
433
|
+
lease_epoch_msec: function (json_hold) {
|
|
434
|
+
const i_dt_msec = JSON_Msg.dt_epoch_msec(json_hold);
|
|
435
|
+
return (i_dt_msec === null) ? null : i_dt_msec + json_hold.hold.ttl_msec;
|
|
384
436
|
},
|
|
385
437
|
validate: function (json) {
|
|
386
438
|
if (!JSON_Eff.validate(json))
|
|
387
439
|
return false;
|
|
388
|
-
const b_valid =
|
|
440
|
+
const b_valid = schema_Hold(json);
|
|
389
441
|
if (!b_valid)
|
|
390
|
-
logr_.log(l_.VALIDATION, () => ['
|
|
442
|
+
logr_.log(l_.VALIDATION, () => ['JSON_Hold: validate: ', schema_Hold.errors]);
|
|
391
443
|
return b_valid;
|
|
392
444
|
}
|
|
393
445
|
};
|
|
@@ -395,6 +447,6 @@ var JSON_Prog = (function () {
|
|
|
395
447
|
|
|
396
448
|
exports.JSON_Ack = JSON_Ack;
|
|
397
449
|
exports.JSON_Eff = JSON_Eff;
|
|
450
|
+
exports.JSON_Hold = JSON_Hold;
|
|
398
451
|
exports.JSON_Msg = JSON_Msg;
|
|
399
|
-
exports.JSON_Prog = JSON_Prog;
|
|
400
452
|
exports.logr = logr_;
|
package/dist/json-msg.es.mjs
CHANGED
|
@@ -109,7 +109,7 @@ function validate20(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
109
109
|
}
|
|
110
110
|
} validate20.errors = vErrors; return errors === 0; }
|
|
111
111
|
validate20.evaluated = { "props": { "ack": true }, "dynamicProps": false, "dynamicItems": false };
|
|
112
|
-
const
|
|
112
|
+
const schema_Hold = validate21;
|
|
113
113
|
function validate21(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate21.evaluated; if (evaluated0.dynamicProps) {
|
|
114
114
|
evaluated0.props = undefined;
|
|
115
115
|
} if (evaluated0.dynamicItems) {
|
|
@@ -117,18 +117,18 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
117
117
|
} {
|
|
118
118
|
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
119
119
|
let missing0;
|
|
120
|
-
if ((data.
|
|
120
|
+
if ((data.hold === undefined) && (missing0 = "hold")) {
|
|
121
121
|
validate21.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
122
122
|
return false;
|
|
123
123
|
}
|
|
124
124
|
else {
|
|
125
|
-
if (data.
|
|
126
|
-
let data0 = data.
|
|
125
|
+
if (data.hold !== undefined) {
|
|
126
|
+
let data0 = data.hold;
|
|
127
127
|
{
|
|
128
128
|
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
129
129
|
let missing1;
|
|
130
130
|
if ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec")) {
|
|
131
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
131
|
+
validate21.errors = [{ instancePath: instancePath + "/hold", schemaPath: "#/properties/hold/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
132
132
|
return false;
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
@@ -136,13 +136,13 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
136
136
|
let data1 = data0.ttl_msec;
|
|
137
137
|
const _errs4 = errors;
|
|
138
138
|
if (!(((typeof data1 == "number") && (!(data1 % 1) && !isNaN(data1))) && (isFinite(data1)))) {
|
|
139
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
139
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/ttl_msec", schemaPath: "#/properties/hold/properties/ttl_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
140
140
|
return false;
|
|
141
141
|
}
|
|
142
142
|
{
|
|
143
143
|
if ((typeof data1 == "number") && (isFinite(data1))) {
|
|
144
144
|
if (data1 <= 0 || isNaN(data1)) {
|
|
145
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
145
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/ttl_msec", schemaPath: "#/properties/hold/properties/ttl_msec/exclusiveMinimum", keyword: "exclusiveMinimum", params: { comparison: ">", limit: 0 }, message: "must be > 0" }];
|
|
146
146
|
return false;
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -157,13 +157,13 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
157
157
|
let data2 = data0.eta_msec;
|
|
158
158
|
const _errs6 = errors;
|
|
159
159
|
if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
|
|
160
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
160
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/eta_msec", schemaPath: "#/properties/hold/properties/eta_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
161
161
|
return false;
|
|
162
162
|
}
|
|
163
163
|
{
|
|
164
164
|
if ((typeof data2 == "number") && (isFinite(data2))) {
|
|
165
165
|
if (data2 < 0 || isNaN(data2)) {
|
|
166
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
166
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/eta_msec", schemaPath: "#/properties/hold/properties/eta_msec/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
|
|
167
167
|
return false;
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -174,24 +174,76 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
174
174
|
var valid1 = true;
|
|
175
175
|
}
|
|
176
176
|
if (valid1) {
|
|
177
|
-
if (data0.
|
|
178
|
-
let data3 = data0.
|
|
177
|
+
if (data0.progress !== undefined) {
|
|
178
|
+
let data3 = data0.progress;
|
|
179
179
|
const _errs8 = errors;
|
|
180
180
|
{
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
if (data3 && typeof data3 == "object" && !Array.isArray(data3)) {
|
|
182
|
+
let missing2;
|
|
183
|
+
if ((data3.done === undefined) && (missing2 = "done")) {
|
|
184
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress", schemaPath: "#/properties/hold/properties/progress/required", keyword: "required", params: { missingProperty: missing2 }, message: "must have required property '" + missing2 + "'" }];
|
|
184
185
|
return false;
|
|
185
186
|
}
|
|
186
187
|
else {
|
|
187
|
-
if (data3
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
if (data3.done !== undefined) {
|
|
189
|
+
let data4 = data3.done;
|
|
190
|
+
const _errs10 = errors;
|
|
191
|
+
{
|
|
192
|
+
if ((typeof data4 == "number") && (isFinite(data4))) {
|
|
193
|
+
if (data4 < 0 || isNaN(data4)) {
|
|
194
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/done", schemaPath: "#/properties/hold/properties/progress/properties/done/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/done", schemaPath: "#/properties/hold/properties/progress/properties/done/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
var valid2 = _errs10 === errors;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
var valid2 = true;
|
|
207
|
+
}
|
|
208
|
+
if (valid2) {
|
|
209
|
+
if (data3.total !== undefined) {
|
|
210
|
+
let data5 = data3.total;
|
|
211
|
+
const _errs12 = errors;
|
|
212
|
+
{
|
|
213
|
+
if ((typeof data5 == "number") && (isFinite(data5))) {
|
|
214
|
+
if (data5 <= 0 || isNaN(data5)) {
|
|
215
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/total", schemaPath: "#/properties/hold/properties/progress/properties/total/exclusiveMinimum", keyword: "exclusiveMinimum", params: { comparison: ">", limit: 0 }, message: "must be > 0" }];
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/total", schemaPath: "#/properties/hold/properties/progress/properties/total/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
var valid2 = _errs12 === errors;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
var valid2 = true;
|
|
228
|
+
}
|
|
229
|
+
if (valid2) {
|
|
230
|
+
if (data3.unit !== undefined) {
|
|
231
|
+
const _errs14 = errors;
|
|
232
|
+
if (typeof data3.unit !== "string") {
|
|
233
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress/unit", schemaPath: "#/properties/hold/properties/progress/properties/unit/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
var valid2 = _errs14 === errors;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
var valid2 = true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
190
242
|
}
|
|
191
243
|
}
|
|
192
244
|
}
|
|
193
245
|
else {
|
|
194
|
-
validate21.errors = [{ instancePath: instancePath + "/progress
|
|
246
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/progress", schemaPath: "#/properties/hold/properties/progress/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
195
247
|
return false;
|
|
196
248
|
}
|
|
197
249
|
}
|
|
@@ -202,12 +254,12 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
202
254
|
}
|
|
203
255
|
if (valid1) {
|
|
204
256
|
if (data0.stage !== undefined) {
|
|
205
|
-
const
|
|
257
|
+
const _errs16 = errors;
|
|
206
258
|
if (typeof data0.stage !== "string") {
|
|
207
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
259
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/stage", schemaPath: "#/properties/hold/properties/stage/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
208
260
|
return false;
|
|
209
261
|
}
|
|
210
|
-
var valid1 =
|
|
262
|
+
var valid1 = _errs16 === errors;
|
|
211
263
|
}
|
|
212
264
|
else {
|
|
213
265
|
var valid1 = true;
|
|
@@ -218,7 +270,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
218
270
|
}
|
|
219
271
|
}
|
|
220
272
|
else {
|
|
221
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
273
|
+
validate21.errors = [{ instancePath: instancePath + "/hold", schemaPath: "#/properties/hold/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
222
274
|
return false;
|
|
223
275
|
}
|
|
224
276
|
}
|
|
@@ -230,7 +282,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
230
282
|
return false;
|
|
231
283
|
}
|
|
232
284
|
} validate21.errors = vErrors; return errors === 0; }
|
|
233
|
-
validate21.evaluated = { "props": { "
|
|
285
|
+
validate21.evaluated = { "props": { "hold": true }, "dynamicProps": false, "dynamicItems": false };
|
|
234
286
|
|
|
235
287
|
const byteToHex = [];
|
|
236
288
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -365,30 +417,30 @@ var JSON_Ack = (function () {
|
|
|
365
417
|
}
|
|
366
418
|
};
|
|
367
419
|
})();
|
|
368
|
-
var
|
|
420
|
+
var JSON_Hold = (function () {
|
|
369
421
|
return {
|
|
370
|
-
//
|
|
371
|
-
// protocol's own). The lease is the parameter, whatever `
|
|
372
|
-
create_with_cause_ttl: function (msg_cause, ttl_msec,
|
|
422
|
+
// hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, progress, stage, a
|
|
423
|
+
// protocol's own). The lease is the parameter, whatever `body` carried.
|
|
424
|
+
create_with_cause_ttl: function (msg_cause, ttl_msec, body) {
|
|
373
425
|
return JSON_Eff.create_with_cause_merge(msg_cause, {
|
|
374
|
-
|
|
426
|
+
hold: Object.assign({}, body || {}, { ttl_msec }),
|
|
375
427
|
});
|
|
376
428
|
},
|
|
377
|
-
// the instant the lease ends, as epoch milliseconds: the message's own dt +
|
|
429
|
+
// the instant the lease ends, as epoch milliseconds: the message's own dt + hold.ttl_msec. null when the
|
|
378
430
|
// dt does not read: a lease with no anchor, which the caller cannot honour.
|
|
379
|
-
lease_epoch_msec: function (
|
|
380
|
-
const i_dt_msec = JSON_Msg.dt_epoch_msec(
|
|
381
|
-
return (i_dt_msec === null) ? null : i_dt_msec +
|
|
431
|
+
lease_epoch_msec: function (json_hold) {
|
|
432
|
+
const i_dt_msec = JSON_Msg.dt_epoch_msec(json_hold);
|
|
433
|
+
return (i_dt_msec === null) ? null : i_dt_msec + json_hold.hold.ttl_msec;
|
|
382
434
|
},
|
|
383
435
|
validate: function (json) {
|
|
384
436
|
if (!JSON_Eff.validate(json))
|
|
385
437
|
return false;
|
|
386
|
-
const b_valid =
|
|
438
|
+
const b_valid = schema_Hold(json);
|
|
387
439
|
if (!b_valid)
|
|
388
|
-
logr_.log(l_.VALIDATION, () => ['
|
|
440
|
+
logr_.log(l_.VALIDATION, () => ['JSON_Hold: validate: ', schema_Hold.errors]);
|
|
389
441
|
return b_valid;
|
|
390
442
|
}
|
|
391
443
|
};
|
|
392
444
|
})();
|
|
393
445
|
|
|
394
|
-
export { JSON_Ack, JSON_Eff,
|
|
446
|
+
export { JSON_Ack, JSON_Eff, JSON_Hold, JSON_Msg, logr_ as logr };
|
package/dist/json_msg+ack.d.ts
CHANGED
|
@@ -13,11 +13,15 @@ interface JSON_Ack extends JSON_Eff {
|
|
|
13
13
|
expired?: boolean;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
interface
|
|
17
|
-
|
|
16
|
+
interface JSON_Hold extends JSON_Eff {
|
|
17
|
+
hold: {
|
|
18
18
|
ttl_msec: number;
|
|
19
19
|
eta_msec?: number;
|
|
20
|
-
|
|
20
|
+
progress?: {
|
|
21
|
+
done: number;
|
|
22
|
+
total?: number;
|
|
23
|
+
unit?: string;
|
|
24
|
+
};
|
|
21
25
|
stage?: string;
|
|
22
26
|
};
|
|
23
27
|
}
|
|
@@ -37,9 +41,9 @@ declare var JSON_Ack: {
|
|
|
37
41
|
create_with_cause_Expired: (msg_cause: JSON_Msg) => JSON_Ack;
|
|
38
42
|
validate: (json: unknown) => json is JSON_Ack;
|
|
39
43
|
};
|
|
40
|
-
declare var
|
|
41
|
-
create_with_cause_ttl: <T extends object>(msg_cause: JSON_Msg, ttl_msec: number,
|
|
42
|
-
lease_epoch_msec: (
|
|
43
|
-
validate: (json: unknown) => json is
|
|
44
|
+
declare var JSON_Hold: {
|
|
45
|
+
create_with_cause_ttl: <T extends object>(msg_cause: JSON_Msg, ttl_msec: number, body?: T) => JSON_Hold;
|
|
46
|
+
lease_epoch_msec: (json_hold: JSON_Hold) => number | null;
|
|
47
|
+
validate: (json: unknown) => json is JSON_Hold;
|
|
44
48
|
};
|
|
45
|
-
export { JSON_Msg, JSON_Eff, JSON_Ack,
|
|
49
|
+
export { JSON_Msg, JSON_Eff, JSON_Ack, JSON_Hold, logr_ as logr };
|