@rootintf/json-msg 4.0.6-api.5 → 4.0.8-api.5
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 +13 -13
- package/dist/json-msg.cjs.js +29 -29
- package/dist/json-msg.es.mjs +29 -29
- package/dist/json_msg+ack.d.ts +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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,17 @@ 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, percent: 40, 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), `percent` (0 to 100) and `stage` are optional.
|
|
60
60
|
|
|
61
61
|
```js
|
|
62
|
-
const i_lease_msec =
|
|
62
|
+
const i_lease_msec = JSON_Hold.lease_epoch_msec(json_hold); // dt + ttl_msec, or null when dt does not read
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
The package defines the fields and this arithmetic, and no policy: how much of a lease is believed, and
|
|
@@ -72,12 +72,12 @@ TypeScript type predicate. A message that fails is not an error; it is somebody
|
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
74
|
if (JSON_Ack.validate(json)) { /* json.ack.ok, json._cause */ }
|
|
75
|
-
else if (
|
|
75
|
+
else if (JSON_Hold.validate(json)) { /* json.hold.ttl_msec, json._cause */ }
|
|
76
76
|
else if (JSON_Eff.validate(json)) { /* json._cause */ }
|
|
77
77
|
else if (JSON_Msg.validate(json)) { /* a message */ }
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
Test for an acknowledgement before a
|
|
80
|
+
Test for an acknowledgement before a hold: a message that carries both is an acknowledgement.
|
|
81
81
|
|
|
82
82
|
### Reading `dt`
|
|
83
83
|
|
|
@@ -102,9 +102,9 @@ the forms `cpp-json-msg` reads, and nothing else.
|
|
|
102
102
|
| `JSON_Ack.create_with_cause_Ok(msg_cause, b_ok = true)` | a new acknowledgement, with the verdict |
|
|
103
103
|
| `JSON_Ack.create_with_cause_Expired(msg_cause)` | a new acknowledgement, `ok: false` and `expired: true` |
|
|
104
104
|
| `JSON_Ack.validate(json)` | is it an acknowledgement? |
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
105
|
+
| `JSON_Hold.create_with_cause_ttl(msg_cause, ttl_msec, body = {})` | a new hold: the lease, with the members of `body` merged in |
|
|
106
|
+
| `JSON_Hold.lease_epoch_msec(json_hold)` | the instant the lease ends, or `null` |
|
|
107
|
+
| `JSON_Hold.validate(json)` | is it a hold? |
|
|
108
108
|
| `logr` | the package's `@knev/bitlogr` logger (name `npm:json-msg`, label `VALIDATION`) |
|
|
109
109
|
|
|
110
110
|
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,24 @@ 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.percent !== undefined) {
|
|
180
|
+
let data3 = data0.percent;
|
|
181
181
|
const _errs8 = errors;
|
|
182
182
|
{
|
|
183
183
|
if ((typeof data3 == "number") && (isFinite(data3))) {
|
|
184
184
|
if (data3 > 100 || isNaN(data3)) {
|
|
185
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
185
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/maximum", keyword: "maximum", params: { comparison: "<=", limit: 100 }, message: "must be <= 100" }];
|
|
186
186
|
return false;
|
|
187
187
|
}
|
|
188
188
|
else {
|
|
189
189
|
if (data3 < 0 || isNaN(data3)) {
|
|
190
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
190
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
|
|
191
191
|
return false;
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
else {
|
|
196
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
196
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
|
|
197
197
|
return false;
|
|
198
198
|
}
|
|
199
199
|
}
|
|
@@ -206,7 +206,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
206
206
|
if (data0.stage !== undefined) {
|
|
207
207
|
const _errs10 = errors;
|
|
208
208
|
if (typeof data0.stage !== "string") {
|
|
209
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
209
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/stage", schemaPath: "#/properties/hold/properties/stage/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
210
210
|
return false;
|
|
211
211
|
}
|
|
212
212
|
var valid1 = _errs10 === errors;
|
|
@@ -220,7 +220,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
else {
|
|
223
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
223
|
+
validate21.errors = [{ instancePath: instancePath + "/hold", schemaPath: "#/properties/hold/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
224
224
|
return false;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
@@ -232,7 +232,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
232
232
|
return false;
|
|
233
233
|
}
|
|
234
234
|
} validate21.errors = vErrors; return errors === 0; }
|
|
235
|
-
validate21.evaluated = { "props": { "
|
|
235
|
+
validate21.evaluated = { "props": { "hold": true }, "dynamicProps": false, "dynamicItems": false };
|
|
236
236
|
|
|
237
237
|
const byteToHex = [];
|
|
238
238
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -367,27 +367,27 @@ var JSON_Ack = (function () {
|
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
369
|
})();
|
|
370
|
-
var
|
|
370
|
+
var JSON_Hold = (function () {
|
|
371
371
|
return {
|
|
372
|
-
//
|
|
373
|
-
// protocol's own). The lease is the parameter, whatever `
|
|
374
|
-
create_with_cause_ttl: function (msg_cause, ttl_msec,
|
|
372
|
+
// hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, percent, stage, a
|
|
373
|
+
// protocol's own). The lease is the parameter, whatever `body` carried.
|
|
374
|
+
create_with_cause_ttl: function (msg_cause, ttl_msec, body) {
|
|
375
375
|
return JSON_Eff.create_with_cause_merge(msg_cause, {
|
|
376
|
-
|
|
376
|
+
hold: Object.assign({}, body || {}, { ttl_msec }),
|
|
377
377
|
});
|
|
378
378
|
},
|
|
379
|
-
// the instant the lease ends, as epoch milliseconds: the message's own dt +
|
|
379
|
+
// the instant the lease ends, as epoch milliseconds: the message's own dt + hold.ttl_msec. null when the
|
|
380
380
|
// 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 +
|
|
381
|
+
lease_epoch_msec: function (json_hold) {
|
|
382
|
+
const i_dt_msec = JSON_Msg.dt_epoch_msec(json_hold);
|
|
383
|
+
return (i_dt_msec === null) ? null : i_dt_msec + json_hold.hold.ttl_msec;
|
|
384
384
|
},
|
|
385
385
|
validate: function (json) {
|
|
386
386
|
if (!JSON_Eff.validate(json))
|
|
387
387
|
return false;
|
|
388
|
-
const b_valid =
|
|
388
|
+
const b_valid = schema_Hold(json);
|
|
389
389
|
if (!b_valid)
|
|
390
|
-
logr_.log(l_.VALIDATION, () => ['
|
|
390
|
+
logr_.log(l_.VALIDATION, () => ['JSON_Hold: validate: ', schema_Hold.errors]);
|
|
391
391
|
return b_valid;
|
|
392
392
|
}
|
|
393
393
|
};
|
|
@@ -395,6 +395,6 @@ var JSON_Prog = (function () {
|
|
|
395
395
|
|
|
396
396
|
exports.JSON_Ack = JSON_Ack;
|
|
397
397
|
exports.JSON_Eff = JSON_Eff;
|
|
398
|
+
exports.JSON_Hold = JSON_Hold;
|
|
398
399
|
exports.JSON_Msg = JSON_Msg;
|
|
399
|
-
exports.JSON_Prog = JSON_Prog;
|
|
400
400
|
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,24 @@ 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.percent !== undefined) {
|
|
178
|
+
let data3 = data0.percent;
|
|
179
179
|
const _errs8 = errors;
|
|
180
180
|
{
|
|
181
181
|
if ((typeof data3 == "number") && (isFinite(data3))) {
|
|
182
182
|
if (data3 > 100 || isNaN(data3)) {
|
|
183
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
183
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/maximum", keyword: "maximum", params: { comparison: "<=", limit: 100 }, message: "must be <= 100" }];
|
|
184
184
|
return false;
|
|
185
185
|
}
|
|
186
186
|
else {
|
|
187
187
|
if (data3 < 0 || isNaN(data3)) {
|
|
188
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
188
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
|
|
189
189
|
return false;
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
else {
|
|
194
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
194
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
|
|
195
195
|
return false;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -204,7 +204,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
204
204
|
if (data0.stage !== undefined) {
|
|
205
205
|
const _errs10 = errors;
|
|
206
206
|
if (typeof data0.stage !== "string") {
|
|
207
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
207
|
+
validate21.errors = [{ instancePath: instancePath + "/hold/stage", schemaPath: "#/properties/hold/properties/stage/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
208
208
|
return false;
|
|
209
209
|
}
|
|
210
210
|
var valid1 = _errs10 === errors;
|
|
@@ -218,7 +218,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
|
-
validate21.errors = [{ instancePath: instancePath + "/
|
|
221
|
+
validate21.errors = [{ instancePath: instancePath + "/hold", schemaPath: "#/properties/hold/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
222
222
|
return false;
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -230,7 +230,7 @@ function validate21(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
230
230
|
return false;
|
|
231
231
|
}
|
|
232
232
|
} validate21.errors = vErrors; return errors === 0; }
|
|
233
|
-
validate21.evaluated = { "props": { "
|
|
233
|
+
validate21.evaluated = { "props": { "hold": true }, "dynamicProps": false, "dynamicItems": false };
|
|
234
234
|
|
|
235
235
|
const byteToHex = [];
|
|
236
236
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -365,30 +365,30 @@ var JSON_Ack = (function () {
|
|
|
365
365
|
}
|
|
366
366
|
};
|
|
367
367
|
})();
|
|
368
|
-
var
|
|
368
|
+
var JSON_Hold = (function () {
|
|
369
369
|
return {
|
|
370
|
-
//
|
|
371
|
-
// protocol's own). The lease is the parameter, whatever `
|
|
372
|
-
create_with_cause_ttl: function (msg_cause, ttl_msec,
|
|
370
|
+
// hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, percent, stage, a
|
|
371
|
+
// protocol's own). The lease is the parameter, whatever `body` carried.
|
|
372
|
+
create_with_cause_ttl: function (msg_cause, ttl_msec, body) {
|
|
373
373
|
return JSON_Eff.create_with_cause_merge(msg_cause, {
|
|
374
|
-
|
|
374
|
+
hold: Object.assign({}, body || {}, { ttl_msec }),
|
|
375
375
|
});
|
|
376
376
|
},
|
|
377
|
-
// the instant the lease ends, as epoch milliseconds: the message's own dt +
|
|
377
|
+
// the instant the lease ends, as epoch milliseconds: the message's own dt + hold.ttl_msec. null when the
|
|
378
378
|
// 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 +
|
|
379
|
+
lease_epoch_msec: function (json_hold) {
|
|
380
|
+
const i_dt_msec = JSON_Msg.dt_epoch_msec(json_hold);
|
|
381
|
+
return (i_dt_msec === null) ? null : i_dt_msec + json_hold.hold.ttl_msec;
|
|
382
382
|
},
|
|
383
383
|
validate: function (json) {
|
|
384
384
|
if (!JSON_Eff.validate(json))
|
|
385
385
|
return false;
|
|
386
|
-
const b_valid =
|
|
386
|
+
const b_valid = schema_Hold(json);
|
|
387
387
|
if (!b_valid)
|
|
388
|
-
logr_.log(l_.VALIDATION, () => ['
|
|
388
|
+
logr_.log(l_.VALIDATION, () => ['JSON_Hold: validate: ', schema_Hold.errors]);
|
|
389
389
|
return b_valid;
|
|
390
390
|
}
|
|
391
391
|
};
|
|
392
392
|
})();
|
|
393
393
|
|
|
394
|
-
export { JSON_Ack, JSON_Eff,
|
|
394
|
+
export { JSON_Ack, JSON_Eff, JSON_Hold, JSON_Msg, logr_ as logr };
|
package/dist/json_msg+ack.d.ts
CHANGED
|
@@ -13,11 +13,11 @@ 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
|
+
percent?: number;
|
|
21
21
|
stage?: string;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -37,9 +37,9 @@ declare var JSON_Ack: {
|
|
|
37
37
|
create_with_cause_Expired: (msg_cause: JSON_Msg) => JSON_Ack;
|
|
38
38
|
validate: (json: unknown) => json is JSON_Ack;
|
|
39
39
|
};
|
|
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
|
|
40
|
+
declare var JSON_Hold: {
|
|
41
|
+
create_with_cause_ttl: <T extends object>(msg_cause: JSON_Msg, ttl_msec: number, body?: T) => JSON_Hold;
|
|
42
|
+
lease_epoch_msec: (json_hold: JSON_Hold) => number | null;
|
|
43
|
+
validate: (json: unknown) => json is JSON_Hold;
|
|
44
44
|
};
|
|
45
|
-
export { JSON_Msg, JSON_Eff, JSON_Ack,
|
|
45
|
+
export { JSON_Msg, JSON_Eff, JSON_Ack, JSON_Hold, logr_ as logr };
|