@rootintf/json-msg 1.1.5 → 2.0.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.
@@ -1,4 +1,112 @@
1
- const schema_Msg = validate18;function validate18(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate18.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((((data.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))){validate18.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.id !== undefined){const _errs1 = errors;if(typeof data.id !== "string"){validate18.errors = [{instancePath:instancePath+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.dt !== undefined){const _errs3 = errors;if(typeof data.dt !== "string"){validate18.errors = [{instancePath:instancePath+"/dt",schemaPath:"#/properties/dt/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}}}}else {validate18.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate18.errors = vErrors;return errors === 0;}validate18.evaluated = {"props":{"id":true,"dt":true},"dynamicProps":false,"dynamicItems":false};const schema_Msg_msg = validate19;function validate19(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate19.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data._msg === undefined) && (missing0 = "_msg")){validate19.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}}else {validate19.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate19.errors = vErrors;return errors === 0;}validate19.evaluated = {"dynamicProps":false,"dynamicItems":false};const schema_MsgAck_msg = validate20;function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate20.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.ack === undefined) && (missing0 = "ack")){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.ack !== undefined){let data0 = data.ack;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if((data0.ok === undefined) && (missing1 = "ok")){validate20.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.ok !== undefined){if(typeof data0.ok !== "boolean"){validate20.errors = [{instancePath:instancePath+"/ack/ok",schemaPath:"#/properties/ack/properties/ok/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}else {validate20.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate20.errors = vErrors;return errors === 0;}validate20.evaluated = {"props":{"ack":true},"dynamicProps":false,"dynamicItems":false};
1
+ const schema_Msg = validate18;
2
+ function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
3
+ evaluated0.props = undefined;
4
+ } if (evaluated0.dynamicItems) {
5
+ evaluated0.items = undefined;
6
+ } {
7
+ if (data && typeof data == "object" && !Array.isArray(data)) {
8
+ let missing0;
9
+ if ((((data.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))) {
10
+ validate18.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
11
+ return false;
12
+ }
13
+ else {
14
+ if (data.id !== undefined) {
15
+ const _errs1 = errors;
16
+ if (typeof data.id !== "string") {
17
+ validate18.errors = [{ instancePath: instancePath + "/id", schemaPath: "#/properties/id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
18
+ return false;
19
+ }
20
+ var valid0 = _errs1 === errors;
21
+ }
22
+ else {
23
+ var valid0 = true;
24
+ }
25
+ if (valid0) {
26
+ if (data.dt !== undefined) {
27
+ const _errs3 = errors;
28
+ if (typeof data.dt !== "string") {
29
+ validate18.errors = [{ instancePath: instancePath + "/dt", schemaPath: "#/properties/dt/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
30
+ return false;
31
+ }
32
+ var valid0 = _errs3 === errors;
33
+ }
34
+ else {
35
+ var valid0 = true;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ else {
41
+ validate18.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
42
+ return false;
43
+ }
44
+ } validate18.errors = vErrors; return errors === 0; }
45
+ validate18.evaluated = { "props": { "id": true, "dt": true }, "dynamicProps": false, "dynamicItems": false };
46
+ const schema_MsgEffect = validate19;
47
+ function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
48
+ evaluated0.props = undefined;
49
+ } if (evaluated0.dynamicItems) {
50
+ evaluated0.items = undefined;
51
+ } {
52
+ if (data && typeof data == "object" && !Array.isArray(data)) {
53
+ let missing0;
54
+ if ((data._cause === undefined) && (missing0 = "_cause")) {
55
+ validate19.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
56
+ return false;
57
+ }
58
+ }
59
+ else {
60
+ validate19.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
61
+ return false;
62
+ }
63
+ } validate19.errors = vErrors; return errors === 0; }
64
+ validate19.evaluated = { "dynamicProps": false, "dynamicItems": false };
65
+ const schema_MsgAckEffect = validate20;
66
+ function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
67
+ evaluated0.props = undefined;
68
+ } if (evaluated0.dynamicItems) {
69
+ evaluated0.items = undefined;
70
+ } {
71
+ if (data && typeof data == "object" && !Array.isArray(data)) {
72
+ let missing0;
73
+ if ((data.ack === undefined) && (missing0 = "ack")) {
74
+ validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
75
+ return false;
76
+ }
77
+ else {
78
+ if (data.ack !== undefined) {
79
+ let data0 = data.ack;
80
+ {
81
+ if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
82
+ let missing1;
83
+ if ((data0.ok === undefined) && (missing1 = "ok")) {
84
+ validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
85
+ return false;
86
+ }
87
+ else {
88
+ if (data0.ok !== undefined) {
89
+ if (typeof data0.ok !== "boolean") {
90
+ validate20.errors = [{ instancePath: instancePath + "/ack/ok", schemaPath: "#/properties/ack/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
91
+ return false;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ else {
97
+ validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
98
+ return false;
99
+ }
100
+ }
101
+ }
102
+ }
103
+ }
104
+ else {
105
+ validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
106
+ return false;
107
+ }
108
+ } validate20.errors = vErrors; return errors === 0; }
109
+ validate20.evaluated = { "props": { "ack": true }, "dynamicProps": false, "dynamicItems": false };
2
110
 
3
111
  const byteToHex = [];
4
112
  for (let i = 0; i < 256; ++i) {
@@ -42,10 +150,7 @@ function rng() {
42
150
  const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
43
151
  var native = { randomUUID };
44
152
 
45
- function v4(options, buf, offset) {
46
- if (native.randomUUID && true && !options) {
47
- return native.randomUUID();
48
- }
153
+ function _v4(options, buf, offset) {
49
154
  options = options || {};
50
155
  const rnds = options.random ?? options.rng?.() ?? rng();
51
156
  if (rnds.length < 16) {
@@ -55,6 +160,12 @@ function v4(options, buf, offset) {
55
160
  rnds[8] = (rnds[8] & 0x3f) | 0x80;
56
161
  return unsafeStringify(rnds);
57
162
  }
163
+ function v4(options, buf, offset) {
164
+ if (native.randomUUID && true && !options) {
165
+ return native.randomUUID();
166
+ }
167
+ return _v4(options);
168
+ }
58
169
 
59
170
  // console.log('OUT', __name({variableName}) );
60
171
 
@@ -149,83 +260,79 @@ const LOGR = (function () {
149
260
 
150
261
  })();
151
262
 
152
- let LOGR_= LOGR.get_instance();
153
- const log_= LOGR_.log;
154
-
155
- const l_= {
156
- VALIDATION : 0b1 << 0,
263
+ let LOGR_ = LOGR.get_instance();
264
+ const log_ = LOGR_.log;
265
+ const l_ = {
266
+ VALIDATION: 0b1 << 0,
157
267
  };
158
- LOGR_.labels= l_;
159
-
268
+ LOGR_.labels = l_;
160
269
  // TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
161
-
162
270
  // "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
163
- var JSON_Msg = (function() {
164
- return {
165
- merge: function(json) {
166
- return Object.assign({
167
- id: v4(),
168
- referer: null,
169
- dt: new Date().toISOString()
170
- }, json || {});
171
- },
172
- validate : function (json) {
173
- const b_valid = schema_Msg(json);
174
- if (!b_valid)
175
- log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
176
- return b_valid;
177
- },
178
- // TODO: requires a separate ajv module require, and JTD specific schema
179
- // https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
180
- // static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
181
- // static parse(json) {
182
- // return this.#ajv_parse_(json);
183
- // }
184
- }
271
+ var JSON_Msg = (function () {
272
+ return {
273
+ merge: function (json) {
274
+ return Object.assign({
275
+ id: v4(),
276
+ referer: null,
277
+ dt: new Date().toISOString()
278
+ }, json || {});
279
+ },
280
+ validate: function (json) {
281
+ const b_valid = schema_Msg(json);
282
+ if (!b_valid)
283
+ log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
284
+ return b_valid;
285
+ },
286
+ // TODO: requires a separate ajv module require, and JTD specific schema
287
+ // https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
288
+ // static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
289
+ // static parse(json) {
290
+ // return this.#ajv_parse_(json);
291
+ // }
292
+ };
185
293
  })();
186
-
187
- var JSON_Msg_msg = (function() {
188
- return {
189
- create_with_msg_merge: function(_msg, json) {
190
- return Object.assign(JSON_Msg.merge(json), { _msg });
191
- },
192
- validate : function(json) {
193
- if (! JSON_Msg.validate(json))
194
- return false;
195
- const b_valid= schema_Msg_msg(json);
196
- if (!b_valid)
197
- log_(l_.VALIDATION, () => ['JSON_Msg_msg: validate: ', schema_Msg_msg.errors]);
198
- return b_valid;
199
- }
200
- }
294
+ var JSON_MsgEffect = (function () {
295
+ return {
296
+ create_with_cause_merge: function (msg_cause, json) {
297
+ const _cause = msg_cause;
298
+ return Object.assign(JSON_Msg.merge(json), { _cause });
299
+ },
300
+ validate: function (json) {
301
+ if (!JSON_Msg.validate(json))
302
+ return false;
303
+ const b_valid = schema_MsgEffect(json);
304
+ if (!b_valid)
305
+ log_(l_.VALIDATION, () => ['JSON_MsgEffect: validate: ', schema_MsgEffect.errors]);
306
+ return b_valid;
307
+ }
308
+ };
201
309
  })();
202
-
203
- var JSON_MsgAck_msg = (function() {
204
- return {
205
- create_with_msgOk : function(_msg, b_ok= true) {
206
- return JSON_Msg_msg.create_with_msg_merge(_msg, {
207
- ack : {
208
- "ok" : b_ok,
209
- },
210
- });
211
- },
212
- create_with_msgExpired : function(_msg) {
213
- return JSON_Msg_msg.create_with_msg_merge(_msg, {
214
- ack : {
215
- "ok" : false,
216
- "expired" : true
217
- },
218
- });
219
- },
220
- validate : function(json) {
221
- if (! JSON_Msg_msg.validate(json))
222
- return false;
223
- const b_valid= schema_MsgAck_msg(json);
224
- if (!b_valid)
225
- log_(l_.VALIDATION, () => ['JSON_MsgAck: validate: ', schema_MsgAck_msg.errors]);
226
- return b_valid;
227
- }
228
- }
310
+ var JSON_MsgAck = (function () {
311
+ return {
312
+ create_with_cause_Ok: function (msg_cause, b_ok = true) {
313
+ return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
314
+ ack: {
315
+ "ok": b_ok,
316
+ },
317
+ });
318
+ },
319
+ create_with_cause_Expired: function (msg_cause) {
320
+ return JSON_MsgEffect.create_with_cause_merge(msg_cause, {
321
+ ack: {
322
+ "ok": false,
323
+ "expired": true
324
+ },
325
+ });
326
+ },
327
+ validate: function (json) {
328
+ if (!JSON_MsgEffect.validate(json))
329
+ return false;
330
+ const b_valid = schema_MsgAckEffect(json);
331
+ if (!b_valid)
332
+ log_(l_.VALIDATION, () => ['JSON_MsgAckEffect: validate: ', schema_MsgAckEffect.errors]);
333
+ return b_valid;
334
+ }
335
+ };
229
336
  })();
230
337
 
231
- export { JSON_Msg, JSON_MsgAck_msg, JSON_Msg_msg, l_ as l };
338
+ export { JSON_Msg, JSON_MsgAck, JSON_MsgEffect, l_ as l };
@@ -0,0 +1,17 @@
1
+ declare const l_: {
2
+ VALIDATION: number;
3
+ };
4
+ declare var JSON_Msg: {
5
+ merge: (json: any) => any;
6
+ validate: (json: any) => boolean;
7
+ };
8
+ declare var JSON_MsgEffect: {
9
+ create_with_cause_merge: (msg_cause: any, json: any) => any;
10
+ validate: (json: any) => boolean;
11
+ };
12
+ declare var JSON_MsgAck: {
13
+ create_with_cause_Ok: (msg_cause: any, b_ok?: boolean) => any;
14
+ create_with_cause_Expired: (msg_cause: any) => any;
15
+ validate: (json: any) => boolean;
16
+ };
17
+ export { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, l_ as l };
@@ -0,0 +1,47 @@
1
+ export function schema_Msg(data: any, { instancePath, parentData, parentDataProperty, rootData, dynamicAnchors }?: {
2
+ instancePath?: string;
3
+ rootData?: any;
4
+ dynamicAnchors?: {};
5
+ }): boolean;
6
+ export namespace schema_Msg {
7
+ namespace evaluated {
8
+ namespace props {
9
+ let id: boolean;
10
+ let dt: boolean;
11
+ }
12
+ let dynamicProps: boolean;
13
+ let dynamicItems: boolean;
14
+ }
15
+ }
16
+ export function schema_MsgEffect(data: any, { instancePath, parentData, parentDataProperty, rootData, dynamicAnchors }?: {
17
+ instancePath?: string;
18
+ rootData?: any;
19
+ dynamicAnchors?: {};
20
+ }): boolean;
21
+ export namespace schema_MsgEffect {
22
+ export namespace evaluated_1 {
23
+ let dynamicProps_1: boolean;
24
+ export { dynamicProps_1 as dynamicProps };
25
+ let dynamicItems_1: boolean;
26
+ export { dynamicItems_1 as dynamicItems };
27
+ }
28
+ export { evaluated_1 as evaluated };
29
+ }
30
+ export function schema_MsgAckEffect(data: any, { instancePath, parentData, parentDataProperty, rootData, dynamicAnchors }?: {
31
+ instancePath?: string;
32
+ rootData?: any;
33
+ dynamicAnchors?: {};
34
+ }): boolean;
35
+ export namespace schema_MsgAckEffect {
36
+ export namespace evaluated_2 {
37
+ export namespace props_1 {
38
+ let ack: boolean;
39
+ }
40
+ export { props_1 as props };
41
+ let dynamicProps_2: boolean;
42
+ export { dynamicProps_2 as dynamicProps };
43
+ let dynamicItems_2: boolean;
44
+ export { dynamicItems_2 as dynamicItems };
45
+ }
46
+ export { evaluated_2 as evaluated };
47
+ }
package/jasmine.json CHANGED
@@ -1,7 +1,7 @@
1
- {
2
- "spec_dir": "tests",
3
- "spec_files": [
4
- "**/*[sS]pec.?(m)js",
5
- "!**/*nospec.js"
6
- ]
1
+ {
2
+ "spec_dir": "tests",
3
+ "spec_files": [
4
+ "**/*[sS]pec.?(m)js",
5
+ "!**/*nospec.js"
6
+ ]
7
7
  }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@rootintf/json-msg",
3
- "version": "1.1.5",
3
+ "version": "2.0.6",
4
4
  "description": "",
5
5
  "main": "dist/json-msg.cjs.js",
6
+ "types": "dist/index.d.ts",
6
7
  "browser": "dist/json-msg.es.mjs",
7
8
  "scripts": {
8
9
  "build": "node src/ajv-gen-validate.cjs && rollup --config",
@@ -26,15 +27,20 @@
26
27
  "dependencies": {
27
28
  "@knev/bitlogr": "^2.0.11",
28
29
  "ajv": "^8.17.1",
29
- "uuid": "^11.1.0"
30
+ "uuid": "^13.0.0"
30
31
  },
31
32
  "devDependencies": {
32
- "@rollup/plugin-commonjs": "^28.0.3",
33
+ "@rollup/plugin-commonjs": "^29.0.0",
33
34
  "@rollup/plugin-json": "^6.1.0",
34
- "@rollup/plugin-node-resolve": "^16.0.1",
35
+ "@rollup/plugin-node-resolve": "^16.0.3",
36
+ "@rollup/plugin-typescript": "^12.3.0",
37
+ "@types/ajv": "^1.0.4",
38
+ "@types/node": "^24.10.1",
35
39
  "ajv-cli": "^5.0.0",
36
- "del-cli": "^6.0.0",
37
- "jasmine": "^5.6.0",
38
- "rollup": "^4.39.0"
40
+ "del-cli": "^7.0.0",
41
+ "jasmine": "^5.13.0",
42
+ "rollup": "^4.53.3",
43
+ "tslib": "^2.8.1",
44
+ "typescript": "^5.9.3"
39
45
  }
40
46
  }
package/rollup.config.mjs CHANGED
@@ -1,24 +1,35 @@
1
-
2
- import resolve from '@rollup/plugin-node-resolve';
3
- import commonjs from '@rollup/plugin-commonjs';
4
- import json from '@rollup/plugin-json';
5
-
6
- export default [
7
- {
8
- input: 'src/json_msg+ack.mjs',
9
- output: {
10
- file: 'dist/json-msg.es.mjs',
11
- format: 'es'
12
- },
13
- plugins: [resolve(), commonjs(), json()]
14
- },
15
- {
16
- input: 'src/json_msg+ack.mjs',
17
- output: {
18
- file: 'dist/json-msg.cjs.js',
19
- format: 'cjs'
20
- },
21
- plugins: [resolve(), commonjs(), json()]
22
- }
23
-
1
+
2
+ import resolve from '@rollup/plugin-node-resolve';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+ import json from '@rollup/plugin-json';
5
+ import typescript from '@rollup/plugin-typescript';
6
+
7
+ export default [
8
+ {
9
+ input: 'src/json_msg+ack.ts',
10
+ output: {
11
+ file: 'dist/json-msg.es.mjs',
12
+ format: 'es'
13
+ },
14
+ plugins: [
15
+ resolve(),
16
+ commonjs(),
17
+ json(),
18
+ typescript({ tsconfig: './tsconfig.json' })
19
+ ]
20
+ },
21
+ {
22
+ input: 'src/json_msg+ack.ts',
23
+ output: {
24
+ file: 'dist/json-msg.cjs.js',
25
+ format: 'cjs'
26
+ },
27
+ plugins: [
28
+ resolve(),
29
+ commonjs(),
30
+ json(),
31
+ typescript({ tsconfig: './tsconfig.json' })
32
+ ]
33
+ }
34
+
24
35
  ];
@@ -0,0 +1,38 @@
1
+
2
+ {
3
+ "$id" : "https://root-interface.se/protocols/JSON_Msg",
4
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
5
+ "schemas": {
6
+ "https://root-interface.se/protocols/JSON_Msg/Msg" : {
7
+ "$id" : "https://root-interface.se/protocols/JSON_Msg/Msg",
8
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
9
+ "type" : "object",
10
+ "required" : ["id", "referer", "dt"],
11
+ "properties" : {
12
+ "id" : { "type" : "string"},
13
+ "dt" : { "type" : "string" }
14
+ }
15
+ },
16
+ "https://root-interface.se/protocols/JSON_Msg/Msg_effect" : {
17
+ "$id" : "https://root-interface.se/protocols/JSON_Msg/MsgEffect",
18
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
19
+ "type" : "object",
20
+ "required" : ["_cause"]
21
+ },
22
+ "https://root-interface.se/protocols/JSON_Msg/MsgAck_effect" : {
23
+ "$id" : "https://root-interface.se/protocols/JSON_Msg/MsgAckEffect",
24
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
25
+ "type" : "object",
26
+ "required" : ["ack"],
27
+ "properties" : {
28
+ "ack" : {
29
+ "type" : "object",
30
+ "required" : ["ok"],
31
+ "properties" : {
32
+ "ok" : { "type" : "boolean" }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
@@ -1,32 +1,29 @@
1
-
2
- var json_schema_msg_= require('../schema/schema_Msg.json');
3
- var json_schema_msg_msg_= require('../schema/schema_Msg_msg.json');
4
- var json_schema__msgAck_msg_= require('../schema/schema_MsgAck_msg.json');
5
-
6
- // https://ajv.js.org/standalone.html
7
-
8
- const fs = require("fs")
9
- const path = require("path")
10
- const Ajv2019 = require("ajv/dist/2019");
11
- const standaloneCode = require("ajv/dist/standalone").default
12
-
13
- // For ESM, the export name needs to be a valid export name, it can not be `export const #/definitions/Foo = ...;` so we
14
- // need to provide a mapping between a valid name and the $id field. Below will generate
15
- // `export const Foo = ...;export const Bar = ...;`
16
- // This mapping would not have been needed if the `$ids` was just `Bar` and `Foo` instead of `#/definitions/Foo`
17
- // and `#/definitions/Bar` respectfully
18
- const ajv = new Ajv2019({schemas: [
19
- json_schema_msg_,
20
- json_schema_msg_msg_,
21
- json_schema__msgAck_msg_
22
- ],
23
- code: {source: true, esm: true}
24
- });
25
- let moduleCode = standaloneCode(ajv, {
26
- "schema_Msg": "https://root-interface.se/protocols/JSON_Msg/schema_Msg",
27
- "schema_Msg_msg" : "https://root-interface.se/protocols/JSON_Msg/schema_Msg_msg",
28
- "schema_MsgAck_msg" : "https://root-interface.se/protocols/JSON_Msg/schema_MsgAck_msg"
29
- })
30
-
31
- // Now you can write the module code to file
1
+
2
+ // https://ajv.js.org/standalone.html
3
+
4
+ const fs = require("fs")
5
+ const path = require("path")
6
+ const Ajv2019 = require("ajv/dist/2019");
7
+ const standaloneCode = require("ajv/dist/standalone").default
8
+
9
+ // For ESM, the export name needs to be a valid export name, it can not be `export const #/definitions/Foo = ...;` so we
10
+ // need to provide a mapping between a valid name and the $id field. Below will generate
11
+ // `export const Foo = ...;export const Bar = ...;`
12
+ // This mapping would not have been needed if the `$ids` was just `Bar` and `Foo` instead of `#/definitions/Foo`
13
+ // and `#/definitions/Bar` respectfully
14
+ const ajv = new Ajv2019({
15
+ code: {source: true, esm: true}
16
+ });
17
+ var json_schema_JSON_Msg_= require('../schema/schema_JSON_Msg.json');
18
+ Object.values(json_schema_JSON_Msg_.schemas).forEach(schema => {
19
+ ajv.addSchema(schema);
20
+ });
21
+
22
+ let moduleCode = standaloneCode(ajv, {
23
+ "schema_Msg": "https://root-interface.se/protocols/JSON_Msg/Msg",
24
+ "schema_MsgEffect" : "https://root-interface.se/protocols/JSON_Msg/MsgEffect",
25
+ "schema_MsgAckEffect" : "https://root-interface.se/protocols/JSON_Msg/MsgAckEffect"
26
+ })
27
+
28
+ // Now you can write the module code to file
32
29
  fs.writeFileSync(path.join(__dirname, "./validate-esm.mjs"), moduleCode)
@@ -0,0 +1 @@
1
+ declare module '@knev/bitlogr';