@rootintf/json-msg 4.0.8-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 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.5: the envelope every message on an
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
 
@@ -49,14 +49,15 @@ 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 json_hold = JSON_Hold.create_with_cause_ttl(json_msg, 15000, { eta_msec: 240000, percent: 40, stage: 'downloading' });
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
55
  ### A hold
56
56
 
57
57
  `hold.ttl_msec` is a lease, measured from the hold's own `dt`: the next word about the cause,
58
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.
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
63
  const i_lease_msec = JSON_Hold.lease_epoch_msec(json_hold); // dt + ttl_msec, or null when dt does not read
@@ -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.percent !== undefined) {
180
- let data3 = data0.percent;
179
+ if (data0.progress !== undefined) {
180
+ let data3 = data0.progress;
181
181
  const _errs8 = errors;
182
182
  {
183
- if ((typeof data3 == "number") && (isFinite(data3))) {
184
- if (data3 > 100 || isNaN(data3)) {
185
- validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/maximum", keyword: "maximum", params: { comparison: "<=", limit: 100 }, message: "must be <= 100" }];
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 < 0 || isNaN(data3)) {
190
- validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
191
- return false;
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 + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
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 _errs10 = errors;
259
+ const _errs16 = errors;
208
260
  if (typeof data0.stage !== "string") {
209
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 = _errs10 === errors;
264
+ var valid1 = _errs16 === errors;
213
265
  }
214
266
  else {
215
267
  var valid1 = true;
@@ -369,7 +421,7 @@ var JSON_Ack = (function () {
369
421
  })();
370
422
  var JSON_Hold = (function () {
371
423
  return {
372
- // hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, percent, stage, a
424
+ // hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, progress, stage, a
373
425
  // protocol's own). The lease is the parameter, whatever `body` carried.
374
426
  create_with_cause_ttl: function (msg_cause, ttl_msec, body) {
375
427
  return JSON_Eff.create_with_cause_merge(msg_cause, {
@@ -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.percent !== undefined) {
178
- let data3 = data0.percent;
177
+ if (data0.progress !== undefined) {
178
+ let data3 = data0.progress;
179
179
  const _errs8 = errors;
180
180
  {
181
- if ((typeof data3 == "number") && (isFinite(data3))) {
182
- if (data3 > 100 || isNaN(data3)) {
183
- validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/maximum", keyword: "maximum", params: { comparison: "<=", limit: 100 }, message: "must be <= 100" }];
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 < 0 || isNaN(data3)) {
188
- validate21.errors = [{ instancePath: instancePath + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
189
- return false;
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 + "/hold/percent", schemaPath: "#/properties/hold/properties/percent/type", keyword: "type", params: { type: "number" }, message: "must be number" }];
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 _errs10 = errors;
257
+ const _errs16 = errors;
206
258
  if (typeof data0.stage !== "string") {
207
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 = _errs10 === errors;
262
+ var valid1 = _errs16 === errors;
211
263
  }
212
264
  else {
213
265
  var valid1 = true;
@@ -367,7 +419,7 @@ var JSON_Ack = (function () {
367
419
  })();
368
420
  var JSON_Hold = (function () {
369
421
  return {
370
- // hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, percent, stage, a
422
+ // hold: { ttl_msec }, with the members of `body` merged into it (eta_msec, progress, stage, a
371
423
  // protocol's own). The lease is the parameter, whatever `body` carried.
372
424
  create_with_cause_ttl: function (msg_cause, ttl_msec, body) {
373
425
  return JSON_Eff.create_with_cause_merge(msg_cause, {
@@ -17,7 +17,11 @@ interface JSON_Hold extends JSON_Eff {
17
17
  hold: {
18
18
  ttl_msec: number;
19
19
  eta_msec?: number;
20
- percent?: number;
20
+ progress?: {
21
+ done: number;
22
+ total?: number;
23
+ unit?: string;
24
+ };
21
25
  stage?: string;
22
26
  };
23
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootintf/json-msg",
3
- "version": "4.0.8-api.5",
3
+ "version": "4.0.11-api.6",
4
4
  "description": "",
5
5
  "main": "dist/json-msg.cjs.js",
6
6
  "module": "dist/json-msg.es.mjs",