@rootintf/protocol-subverseinfo 0.0.4-api-0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+
2
+ var json_definitions_SubverseInfo_ = require('../schema/definitions_SubverseInfo.json');
3
+
4
+ var josn_schema_SubverseInfo_discovery_= require('../schema/schema_SubverseInfo_discovery.json');
5
+ var json_schema_SubverseInfo_expanse_= require('../schema/schema_SubverseInfo_expanse.json');
6
+ var json_schema_expanse_instances_= require('../schema/schema_expanse_instances.json');
7
+
8
+ // https://ajv.js.org/standalone.html
9
+ // https://ajv.js.org/guide/schema-language.html
10
+
11
+ const fs = require("fs")
12
+ const path = require("path")
13
+ const Ajv2019 = require("ajv/dist/2019");
14
+ const standaloneCode = require("ajv/dist/standalone").default
15
+
16
+ // ajv draft07, draft/2019-09 requires id URIs
17
+ // For ESM, the export name needs to be a valid export name, it can not be `export const #/definitions/Foo = ...;` so we
18
+ // need to provide a mapping between a valid name and the $id field. Below will generate
19
+ // `export const Foo = ...;export const Bar = ...;`
20
+ // This mapping would not have been needed if the `$ids` was just `Bar` and `Foo` instead of `#/definitions/Foo`
21
+ // and `#/definitions/Bar` respectfully
22
+ const ajv = new Ajv2019({
23
+ schemas: [
24
+ json_definitions_SubverseInfo_,
25
+ josn_schema_SubverseInfo_discovery_,
26
+ json_schema_SubverseInfo_expanse_,
27
+ // json_schema_expanse_instances_,
28
+ ],
29
+ code: {
30
+ source: true,
31
+ esm: true
32
+ }
33
+ });
34
+
35
+ let moduleCode = standaloneCode(ajv, {
36
+ "definitions_SubverseInfo": "https://root-interface.se/schemas/definitions_SubverseInfo",
37
+ "schema_SubverseInfo_discovery": "https://root-interface.se/schemas/schema_SubverseInfo_discovery",
38
+ "schema_SubverseInfo_expanse": "https://root-interface.se/schemas/schema_SubverseInfo_expanse",
39
+ // "schema_expanse_instances": "https://root-interface.se/schemas/schema_expanse_instances",
40
+ })
41
+
42
+ // Now you can write the module code to file
43
+ fs.writeFileSync(path.join(__dirname, "./validate-esm.mjs"), moduleCode)
@@ -0,0 +1,134 @@
1
+
2
+ import {
3
+ definitions_SubverseInfo as definitions_SubverseInfo_,
4
+ schema_SubverseInfo_discovery as schema_SubverseInfo_discovery_,
5
+ schema_SubverseInfo_expanse as schema_SubverseInfo_expanse_,
6
+ // schema_expanse_instances as schema_expanse_instances_,
7
+ } from './validate-esm.mjs';
8
+
9
+ import { BitLogr, l_LL } from '@knev/bitlogr';
10
+ import { JSON_Msg, JSON_Msg_msg } from '@rootintf/json-msg';
11
+
12
+ let LOGR_= new BitLogr();
13
+
14
+ const l_= {
15
+ VALIDATION : 0b1 << 0,
16
+ }
17
+ LOGR_.labels= l_;
18
+
19
+ LOGR_.toggled= {
20
+ // VALIDATION : 1
21
+ }
22
+
23
+ const kstr_VERSION= "0.1";
24
+
25
+ // TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
26
+
27
+ // const regex_IOI= new RegExp('\\bquery\\s*\\{\\s*IOI\\s*\\(\\s*pkg\\s*:\\s*"([^"]*)"\\s*\\)\\s*\\{.*heartbeat\\s*\\}\\s*\\}');
28
+
29
+ var JSON_MsgSubverseInfo_discovery = (function() {
30
+ return {
31
+ merge : function(json) {
32
+ let json_msg= JSON_Msg.merge(json);
33
+ json_msg["subverse_info"]= kstr_VERSION;
34
+
35
+ return json_msg;
36
+ },
37
+ validate : function(json, _pkg) {
38
+ if (! JSON_Msg.validate(json))
39
+ return false;
40
+
41
+ if (! schema_SubverseInfo_discovery_(json)) {
42
+ LOGR_.log(l_.VALIDATION, 'schema_SubverseInfo_discovery: validate: ', schema_SubverseInfo_discovery_.errors)
43
+ return false;
44
+ }
45
+
46
+ // const str_graphql = json["discovery"]["graphql"];
47
+
48
+ // const regex_match= str_graphql.match(regex_IOI);
49
+ // if (regex_match === null || regex_match.length !== 2)
50
+ // return false;
51
+
52
+ // if (pkg !== regex_match[1])
53
+ // return false;
54
+
55
+ return true;
56
+ }
57
+ }
58
+ })();
59
+
60
+ var JSON_MsgSubverseInfo_expanse = (function() {
61
+ return {
62
+ create_with_msg_merge : function(_msg, json) {
63
+ let json_msg_msg= JSON_Msg_msg.create_with_msg_merge(_msg, json);
64
+ json_msg_msg["subverse_info"]= kstr_VERSION;
65
+
66
+ return json_msg_msg;
67
+ },
68
+ validate : function(json) {
69
+ if (! JSON_Msg_msg.validate(json))
70
+ return false;
71
+ if (! schema_SubverseInfo_expanse_(json)) {
72
+ LOGR_.log(l_.VALIDATION, 'JSON_SubverseInfo_expanse: validate: ', schema_SubverseInfo_expanse_.errors)
73
+ return false;
74
+ }
75
+ return true;
76
+ }
77
+ }
78
+ })();
79
+
80
+ /*
81
+ var JSON_MsgAnnouncement = (function() {
82
+ return {
83
+ // create_with_msgOk : function(_msg, b_ok= true) {
84
+ // return JSON_Msg_msg.create_with_msg_merge(_msg, {
85
+ // ack : {
86
+ // "ok" : b_ok,
87
+ // },
88
+ // });
89
+ // },
90
+ // create_with_msgExpired : function(_msg) {
91
+ // return JSON_Msg_msg.create_with_msg_merge(_msg, {
92
+ // ack : {
93
+ // "ok" : false,
94
+ // "expired" : true
95
+ // },
96
+ // });
97
+ // },
98
+ create_with_msg_merge : function(_msg, json) {
99
+ let json_msgAnnouncement= JSON_Msg_msg.create_with_msg_merge(_msg, json);
100
+ json_msgAnnouncement["_v"]= kstr_VERSION;
101
+ return json_msgAnnouncement;
102
+ },
103
+ validate : function(json) {
104
+ if (! JSON_Msg.validate(json))
105
+ return false;
106
+ const b_valid= schema_MsgAnnouncement_(json);
107
+ if (!b_valid)
108
+ LOGR_.log(l_.VALIDATION, 'JSON_MsgAnnouncement: validate: ', schema_MsgAnnouncement_.errors)
109
+ return b_valid;
110
+ }
111
+ }
112
+ })();
113
+
114
+ var JSON_instances= (function() {
115
+ return {
116
+ validate : function(json) {
117
+ if (json.expanse === undefined)
118
+ return false;
119
+
120
+ const b_valid= schema_expanse_instances_(json.expanse);
121
+ if (!b_valid)
122
+ LOGR_.log(l_.VALIDATION, 'JSON_instances: validate: ', schema_expanse_instances_.errors)
123
+ return b_valid;
124
+ }
125
+ }
126
+ })();
127
+ */
128
+
129
+ //-------------------------------------------------------------------------------------------------
130
+
131
+ export {
132
+ JSON_MsgSubverseInfo_discovery,
133
+ JSON_MsgSubverseInfo_expanse,
134
+ }
@@ -0,0 +1 @@
1
+ "use strict";export const definitions_SubverseInfo = validate18;const schema21 = {"$id":"https://root-interface.se/schemas/definitions_SubverseInfo","$schema":"https://json-schema.org/draft/2019-09/schema","definitions":{"_v":{"const":"0.1"},"info":{"type":"object"},"unique-id":{"type":"object","required":["name","uri"],"properties":{"name":{"type":"string"},"uri":{"type":"string"},"favicon":{"type":"string"},"info":{"$ref":"definitions_SubverseInfo#/definitions/info"}}},"instances":{"type":"array","items":{"type":"object","allOf":[{"$ref":"definitions_SubverseInfo#/definitions/unique-id"}],"properties":{}}},"platforms":{"type":"array","items":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"archs":{"type":"array","items":{"type":"string"}},"agents":{"type":"array","items":{"type":"string"}}}}},"protocols":{"type":"array","items":{"type":"object","required":["name","attr"],"properties":{"name":{"type":"string"},"attr":{"type":"string"},"url":{"type":"string"}}}}}};function validate18(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){/*# sourceURL="https://root-interface.se/schemas/definitions_SubverseInfo" */;validate18.errors = null;return true;}validate18.evaluated = {"dynamicProps":false,"dynamicItems":false};export const schema_SubverseInfo_discovery = validate19;const schema22 = {"$id":"https://root-interface.se/schemas/schema_SubverseInfo_discovery","$schema":"https://json-schema.org/draft/2019-09/schema","type":"object","required":["discovery","subverse_info"],"properties":{"discovery":{"type":"object","required":["name","graphql","ttl_msec"],"properties":{"name":{"type":"string"},"graphql":{"type":"string"},"ttl_msec":{"type":"integer"}}},"subverse_info":{"$ref":"definitions_SubverseInfo#/definitions/_v"}}};const schema23 = {"const":"0.1"};function validate19(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){/*# sourceURL="https://root-interface.se/schemas/schema_SubverseInfo_discovery" */;let vErrors = null;let errors = 0;const evaluated0 = validate19.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((data.discovery === undefined) && (missing0 = "discovery")) || ((data.subverse_info === undefined) && (missing0 = "subverse_info"))){validate19.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.discovery !== undefined){let data0 = data.discovery;const _errs1 = errors;if(errors === _errs1){if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if((((data0.name === undefined) && (missing1 = "name")) || ((data0.graphql === undefined) && (missing1 = "graphql"))) || ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec"))){validate19.errors = [{instancePath:instancePath+"/discovery",schemaPath:"#/properties/discovery/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.name !== undefined){const _errs3 = errors;if(typeof data0.name !== "string"){validate19.errors = [{instancePath:instancePath+"/discovery/name",schemaPath:"#/properties/discovery/properties/name/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.graphql !== undefined){const _errs5 = errors;if(typeof data0.graphql !== "string"){validate19.errors = [{instancePath:instancePath+"/discovery/graphql",schemaPath:"#/properties/discovery/properties/graphql/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs5 === errors;}else {var valid1 = true;}if(valid1){if(data0.ttl_msec !== undefined){let data3 = data0.ttl_msec;const _errs7 = errors;if(!(((typeof data3 == "number") && (!(data3 % 1) && !isNaN(data3))) && (isFinite(data3)))){validate19.errors = [{instancePath:instancePath+"/discovery/ttl_msec",schemaPath:"#/properties/discovery/properties/ttl_msec/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid1 = _errs7 === errors;}else {var valid1 = true;}}}}}else {validate19.errors = [{instancePath:instancePath+"/discovery",schemaPath:"#/properties/discovery/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.subverse_info !== undefined){const _errs9 = errors;if("0.1" !== data.subverse_info){validate19.errors = [{instancePath:instancePath+"/subverse_info",schemaPath:"definitions_SubverseInfo#/definitions/_v/const",keyword:"const",params:{allowedValue: "0.1"},message:"must be equal to constant"}];return false;}var valid0 = _errs9 === errors;}else {var valid0 = true;}}}}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 = {"props":{"discovery":true,"subverse_info":true},"dynamicProps":false,"dynamicItems":false};export const schema_SubverseInfo_expanse = validate20;const schema24 = {"$id":"https://root-interface.se/schemas/schema_SubverseInfo_expanse","$schema":"https://json-schema.org/draft/2019-09/schema","type":"object","required":["expanse","subverse_info"],"properties":{"expanse":{"type":"object","required":["subverse","protocols"],"properties":{"subverse":{"type":"object","allOf":[{"$ref":"definitions_SubverseInfo#/definitions/unique-id"}],"required":["map_url"],"properties":{"map_url":{"type":"string"}}},"instances":{"$ref":"definitions_SubverseInfo#/definitions/instances"},"platforms":{"$ref":"definitions_SubverseInfo#/definitions/platforms"},"protocols":{"$ref":"definitions_SubverseInfo#/definitions/protocols"}}},"subverse_info":{"$ref":"definitions_SubverseInfo#/definitions/_v"}}};const schema30 = {"type":"array","items":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"archs":{"type":"array","items":{"type":"string"}},"agents":{"type":"array","items":{"type":"string"}}}}};const schema31 = {"type":"array","items":{"type":"object","required":["name","attr"],"properties":{"name":{"type":"string"},"attr":{"type":"string"},"url":{"type":"string"}}}};const schema25 = {"type":"object","required":["name","uri"],"properties":{"name":{"type":"string"},"uri":{"type":"string"},"favicon":{"type":"string"},"info":{"$ref":"definitions_SubverseInfo#/definitions/info"}}};const schema26 = {"type":"object"};function validate21(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate21.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((data.name === undefined) && (missing0 = "name")) || ((data.uri === undefined) && (missing0 = "uri"))){validate21.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.name !== undefined){const _errs1 = errors;if(typeof data.name !== "string"){validate21.errors = [{instancePath:instancePath+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.uri !== undefined){const _errs3 = errors;if(typeof data.uri !== "string"){validate21.errors = [{instancePath:instancePath+"/uri",schemaPath:"#/properties/uri/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}if(valid0){if(data.favicon !== undefined){const _errs5 = errors;if(typeof data.favicon !== "string"){validate21.errors = [{instancePath:instancePath+"/favicon",schemaPath:"#/properties/favicon/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs5 === errors;}else {var valid0 = true;}if(valid0){if(data.info !== undefined){let data3 = data.info;const _errs7 = errors;if(!(data3 && typeof data3 == "object" && !Array.isArray(data3))){validate21.errors = [{instancePath:instancePath+"/info",schemaPath:"definitions_SubverseInfo#/definitions/info/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid0 = _errs7 === errors;}else {var valid0 = true;}}}}}}else {validate21.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate21.errors = vErrors;return errors === 0;}validate21.evaluated = {"props":{"name":true,"uri":true,"favicon":true,"info":true},"dynamicProps":false,"dynamicItems":false};const schema27 = {"type":"array","items":{"type":"object","allOf":[{"$ref":"definitions_SubverseInfo#/definitions/unique-id"}],"properties":{}}};function validate24(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate24.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((data.name === undefined) && (missing0 = "name")) || ((data.uri === undefined) && (missing0 = "uri"))){validate24.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.name !== undefined){const _errs1 = errors;if(typeof data.name !== "string"){validate24.errors = [{instancePath:instancePath+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.uri !== undefined){const _errs3 = errors;if(typeof data.uri !== "string"){validate24.errors = [{instancePath:instancePath+"/uri",schemaPath:"#/properties/uri/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}if(valid0){if(data.favicon !== undefined){const _errs5 = errors;if(typeof data.favicon !== "string"){validate24.errors = [{instancePath:instancePath+"/favicon",schemaPath:"#/properties/favicon/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs5 === errors;}else {var valid0 = true;}if(valid0){if(data.info !== undefined){let data3 = data.info;const _errs7 = errors;if(!(data3 && typeof data3 == "object" && !Array.isArray(data3))){validate24.errors = [{instancePath:instancePath+"/info",schemaPath:"definitions_SubverseInfo#/definitions/info/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid0 = _errs7 === errors;}else {var valid0 = true;}}}}}}else {validate24.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate24.errors = vErrors;return errors === 0;}validate24.evaluated = {"props":{"name":true,"uri":true,"favicon":true,"info":true},"dynamicProps":false,"dynamicItems":false};function validate23(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate23.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}if(errors === 0){if(Array.isArray(data)){var valid0 = true;const len0 = data.length;for(let i0=0; i0<len0; i0++){let data0 = data[i0];const _errs1 = errors;if(!(validate24(data0, {instancePath:instancePath+"/" + i0,parentData:data,parentDataProperty:i0,rootData,dynamicAnchors}))){vErrors = vErrors === null ? validate24.errors : vErrors.concat(validate24.errors);errors = vErrors.length;}if(errors === _errs1){if(!(data0 && typeof data0 == "object" && !Array.isArray(data0))){validate23.errors = [{instancePath:instancePath+"/" + i0,schemaPath:"#/items/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs1 === errors;if(!valid0){break;}}}else {validate23.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}validate23.errors = vErrors;return errors === 0;}validate23.evaluated = {"items":true,"dynamicProps":false,"dynamicItems":false};function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){/*# sourceURL="https://root-interface.se/schemas/schema_SubverseInfo_expanse" */;let vErrors = null;let errors = 0;const evaluated0 = validate20.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((data.expanse === undefined) && (missing0 = "expanse")) || ((data.subverse_info === undefined) && (missing0 = "subverse_info"))){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.expanse !== undefined){let data0 = data.expanse;const _errs1 = errors;if(errors === _errs1){if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((data0.subverse === undefined) && (missing1 = "subverse")) || ((data0.protocols === undefined) && (missing1 = "protocols"))){validate20.errors = [{instancePath:instancePath+"/expanse",schemaPath:"#/properties/expanse/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.subverse !== undefined){let data1 = data0.subverse;const _errs3 = errors;if(!(validate21(data1, {instancePath:instancePath+"/expanse/subverse",parentData:data0,parentDataProperty:"subverse",rootData,dynamicAnchors}))){vErrors = vErrors === null ? validate21.errors : vErrors.concat(validate21.errors);errors = vErrors.length;}if(errors === _errs3){if(data1 && typeof data1 == "object" && !Array.isArray(data1)){let missing2;if((data1.map_url === undefined) && (missing2 = "map_url")){validate20.errors = [{instancePath:instancePath+"/expanse/subverse",schemaPath:"#/properties/expanse/properties/subverse/required",keyword:"required",params:{missingProperty: missing2},message:"must have required property '"+missing2+"'"}];return false;}else {if(data1.map_url !== undefined){if(typeof data1.map_url !== "string"){validate20.errors = [{instancePath:instancePath+"/expanse/subverse/map_url",schemaPath:"#/properties/expanse/properties/subverse/properties/map_url/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/expanse/subverse",schemaPath:"#/properties/expanse/properties/subverse/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.instances !== undefined){const _errs8 = errors;if(!(validate23(data0.instances, {instancePath:instancePath+"/expanse/instances",parentData:data0,parentDataProperty:"instances",rootData,dynamicAnchors}))){vErrors = vErrors === null ? validate23.errors : vErrors.concat(validate23.errors);errors = vErrors.length;}var valid1 = _errs8 === errors;}else {var valid1 = true;}if(valid1){if(data0.platforms !== undefined){let data4 = data0.platforms;const _errs9 = errors;const _errs10 = errors;if(errors === _errs10){if(Array.isArray(data4)){var valid5 = true;const len0 = data4.length;for(let i0=0; i0<len0; i0++){let data5 = data4[i0];const _errs12 = errors;if(errors === _errs12){if(data5 && typeof data5 == "object" && !Array.isArray(data5)){let missing3;if((data5.name === undefined) && (missing3 = "name")){validate20.errors = [{instancePath:instancePath+"/expanse/platforms/" + i0,schemaPath:"definitions_SubverseInfo#/definitions/platforms/items/required",keyword:"required",params:{missingProperty: missing3},message:"must have required property '"+missing3+"'"}];return false;}else {if(data5.name !== undefined){const _errs14 = errors;if(typeof data5.name !== "string"){validate20.errors = [{instancePath:instancePath+"/expanse/platforms/" + i0+"/name",schemaPath:"definitions_SubverseInfo#/definitions/platforms/items/properties/name/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid6 = _errs14 === errors;}else {var valid6 = true;}if(valid6){if(data5.archs !== undefined){let data7 = data5.archs;const _errs16 = errors;if(errors === _errs16){if(Array.isArray(data7)){var valid7 = true;const len1 = data7.length;for(let i1=0; i1<len1; i1++){const _errs18 = errors;if(typeof data7[i1] !== "string"){validate20.errors = [{instancePath:instancePath+"/expanse/platforms/" + i0+"/archs/" + i1,schemaPath:"definitions_SubverseInfo#/definitions/platforms/items/properties/archs/items/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid7 = _errs18 === errors;if(!valid7){break;}}}else {validate20.errors = [{instancePath:instancePath+"/expanse/platforms/" + i0+"/archs",schemaPath:"definitions_SubverseInfo#/definitions/platforms/items/properties/archs/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid6 = _errs16 === errors;}else {var valid6 = true;}if(valid6){if(data5.agents !== undefined){let data9 = data5.agents;const _errs20 = errors;if(errors === _errs20){if(Array.isArray(data9)){var valid8 = true;const len2 = data9.length;for(let i2=0; i2<len2; i2++){const _errs22 = errors;if(typeof data9[i2] !== "string"){validate20.errors = [{instancePath:instancePath+"/expanse/platforms/" + i0+"/agents/" + i2,schemaPath:"definitions_SubverseInfo#/definitions/platforms/items/properties/agents/items/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid8 = _errs22 === errors;if(!valid8){break;}}}else {validate20.errors = [{instancePath:instancePath+"/expanse/platforms/" + i0+"/agents",schemaPath:"definitions_SubverseInfo#/definitions/platforms/items/properties/agents/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid6 = _errs20 === errors;}else {var valid6 = true;}}}}}else {validate20.errors = [{instancePath:instancePath+"/expanse/platforms/" + i0,schemaPath:"definitions_SubverseInfo#/definitions/platforms/items/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid5 = _errs12 === errors;if(!valid5){break;}}}else {validate20.errors = [{instancePath:instancePath+"/expanse/platforms",schemaPath:"definitions_SubverseInfo#/definitions/platforms/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid1 = _errs9 === errors;}else {var valid1 = true;}if(valid1){if(data0.protocols !== undefined){let data11 = data0.protocols;const _errs24 = errors;const _errs25 = errors;if(errors === _errs25){if(Array.isArray(data11)){var valid10 = true;const len3 = data11.length;for(let i3=0; i3<len3; i3++){let data12 = data11[i3];const _errs27 = errors;if(errors === _errs27){if(data12 && typeof data12 == "object" && !Array.isArray(data12)){let missing4;if(((data12.name === undefined) && (missing4 = "name")) || ((data12.attr === undefined) && (missing4 = "attr"))){validate20.errors = [{instancePath:instancePath+"/expanse/protocols/" + i3,schemaPath:"definitions_SubverseInfo#/definitions/protocols/items/required",keyword:"required",params:{missingProperty: missing4},message:"must have required property '"+missing4+"'"}];return false;}else {if(data12.name !== undefined){const _errs29 = errors;if(typeof data12.name !== "string"){validate20.errors = [{instancePath:instancePath+"/expanse/protocols/" + i3+"/name",schemaPath:"definitions_SubverseInfo#/definitions/protocols/items/properties/name/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid11 = _errs29 === errors;}else {var valid11 = true;}if(valid11){if(data12.attr !== undefined){const _errs31 = errors;if(typeof data12.attr !== "string"){validate20.errors = [{instancePath:instancePath+"/expanse/protocols/" + i3+"/attr",schemaPath:"definitions_SubverseInfo#/definitions/protocols/items/properties/attr/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid11 = _errs31 === errors;}else {var valid11 = true;}if(valid11){if(data12.url !== undefined){const _errs33 = errors;if(typeof data12.url !== "string"){validate20.errors = [{instancePath:instancePath+"/expanse/protocols/" + i3+"/url",schemaPath:"definitions_SubverseInfo#/definitions/protocols/items/properties/url/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid11 = _errs33 === errors;}else {var valid11 = true;}}}}}else {validate20.errors = [{instancePath:instancePath+"/expanse/protocols/" + i3,schemaPath:"definitions_SubverseInfo#/definitions/protocols/items/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid10 = _errs27 === errors;if(!valid10){break;}}}else {validate20.errors = [{instancePath:instancePath+"/expanse/protocols",schemaPath:"definitions_SubverseInfo#/definitions/protocols/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid1 = _errs24 === errors;}else {var valid1 = true;}}}}}}else {validate20.errors = [{instancePath:instancePath+"/expanse",schemaPath:"#/properties/expanse/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.subverse_info !== undefined){const _errs35 = errors;if("0.1" !== data.subverse_info){validate20.errors = [{instancePath:instancePath+"/subverse_info",schemaPath:"definitions_SubverseInfo#/definitions/_v/const",keyword:"const",params:{allowedValue: "0.1"},message:"must be equal to constant"}];return false;}var valid0 = _errs35 === errors;}else {var valid0 = true;}}}}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":{"expanse":true,"subverse_info":true},"dynamicProps":false,"dynamicItems":false};
@@ -0,0 +1,377 @@
1
+
2
+ // throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
3
+ // https://stackoverflow.com/questions/69118216/crypto-getrandomvalues-not-supported-in-react-js
4
+ // - https://stackoverflow.com/questions/52612122/how-to-use-jest-to-test-functions-using-crypto-or-window-mscrypto
5
+ import { v4 as uuidv4 } from 'uuid';
6
+ import crypto from 'crypto'
7
+ Object.defineProperty(globalThis, 'crypto', {
8
+ value: {
9
+ getRandomValues: arr => crypto.randomBytes(arr.length)
10
+ }
11
+ });
12
+
13
+ // import { JSON_Msg, JSON_Msg_msg } from '@rootintf/json-msg';
14
+ import {
15
+ JSON_MsgSubverseInfo_discovery,
16
+ JSON_MsgSubverseInfo_expanse,
17
+ } from '../src/subverseinfo.mjs';
18
+
19
+ const kstr_VERSION = "0.1"
20
+
21
+ //-------------------------------------------------------------------------------------------------
22
+
23
+ const json_msgSubverseInfo_discovery_merge = JSON_MsgSubverseInfo_discovery.merge({
24
+ "discovery": {
25
+ "name": "discovery-expanse",
26
+ "graphql": "query { expanse { name map logo(width: 200, height: 200) { link } platforms { name archs agents } protocols { name attr } } }",
27
+ "ttl_msec": 5000
28
+ },
29
+ });
30
+ json_msgSubverseInfo_discovery_merge.referer = [ "karr_referer", "" ];
31
+
32
+ describe("Validation", function () {
33
+ it("JSON_MsgSubverseInfo_discovery.validate(json_msgSubverseInfo_discovery_merge)", function () {
34
+ expect(JSON_MsgSubverseInfo_discovery.validate(json_msgSubverseInfo_discovery_merge)).toBe(true);
35
+ });
36
+ });
37
+
38
+ // const json_msgSubverseInfo_discovery= JSON_MsgSubverseInfo_discovery.create_with_name_graphql(
39
+ // "discovery-expanse",
40
+ // "query { expanse { name map logo(width: 200, height: 200) { link } platforms { name archs agents } protocols { name attr } } }",
41
+ // 5000
42
+ // );
43
+ // json_msgSubverseInfo_discovery.referer = [ "karr_referer", "" ];
44
+
45
+ // describe("Validation", function () {
46
+ // it("JSON_MsgSubverseInfo_discovery.validate(json_msgSubverseInfo_discovery)", function () {
47
+ // expect(JSON_MsgSubverseInfo_discovery.validate(json_msgSubverseInfo_discovery)).toBe(true);
48
+ // });
49
+ // });
50
+
51
+ //-------------------------------------------------------------------------------------------------
52
+
53
+ const json_msgAnnouncement_expanse = {
54
+ "id": "53C2A451-D3E7-4657-932D-22EBF4A823D8",
55
+ "_msg": { "id": "15169a65-94fe-449a-9164-a2e2bdd78c56", "discovery": { "graphql": "query { subverse { name logo(width: 200, height: 200) protocols integrations } }", "ttl_msec": 5000 }, "referer": ["subverse-protocol-map", "4b1ad967-8154-416f-a744-989db452bd76"], "dt": "2023-04-28T10:13:11.642Z" },
56
+ "referer": ["tx-sl", "D41EDF64-6BF9-40D0-B30C-CC6A798B67F2"],
57
+ "dt": "2023-04-28T10:13:11Z",
58
+ "announcement": {
59
+ // "expanse": {
60
+ // "integrations": [
61
+ // { "pkg": "tx-sl", "ppa": "https://root-interface.se/depot", "sha2-384": "c3f3e373de97e8d7f5d9c47096c128fcdcb07fbbb4581d6ab7d32913fe301edec0abb48a0bcf585f167c473b45a24634", "sha3-224": "", "version": "0.2.9" }
62
+ // ],
63
+ // "logo": "http://root-interface.se/depot/tx-sl/img-SL_DLbackground.png",
64
+ // "name": "Second Life",
65
+ // "protocols": ["QuerySubverse", "2PhW", "Discovery"]
66
+ // }
67
+ },
68
+ "_v" : kstr_VERSION
69
+ }
70
+
71
+ let json_SubverseInfo_expanse_OpenSim= JSON_MsgSubverseInfo_expanse.create_with_msg_merge(null, {
72
+ expanse : {
73
+ subverse: {
74
+ name : "OpenSimulator",
75
+ uri : "http://opensimulator.org",
76
+ favicon : "https://upload.wikimedia.org/wikipedia/commons/5/50/Opensimulator_logo200x160.png",
77
+ map_url : "http://opensimulator.org/wiki/Grid_List"
78
+ },
79
+ protocols: [
80
+ { name: "Second Life protocol", attr: "0r" }
81
+ ]
82
+ }
83
+ });
84
+ json_SubverseInfo_expanse_OpenSim.referer = [ "karr_referer", "" ];
85
+ // console.log('json_msgAnnouncement_OpenSim', json_msgAnnouncement_OpenSim)
86
+
87
+ describe("Validation", function () {
88
+ it("JSON_MsgSubverseInfo_expanse.validate(json_SubverseInfo_expanse_OpenSim)", function () {
89
+ expect(JSON_MsgSubverseInfo_expanse.validate(json_SubverseInfo_expanse_OpenSim)).toBe(true);
90
+ });
91
+ });
92
+
93
+ const json_msgSubverseInfo_expanse_DCL = {
94
+ "id": "02f5e7b0-140c-496d-a3b5-4fd4023a5e94",
95
+ "referer": [
96
+ "subverse-protocol-map",
97
+ "c8961cab-1aeb-4d9e-9cf2-ce94e6b3ef7f"
98
+ ],
99
+ "dt": "2025-03-05T07:52:01.212Z",
100
+ "expanse": {
101
+ "subverse": {
102
+ "name": "Decentraland",
103
+ "uri": "https://genesis.city",
104
+ "favicon": "https://cryptologos.cc/logos/decentraland-mana-logo.png",
105
+ "map_url": "https://genesis.city"
106
+ },
107
+ "protocols": [
108
+ {
109
+ "name": "Ethereum",
110
+ "attr": "0rw"
111
+ }
112
+ ]
113
+ },
114
+ "_msg": {
115
+ "id": "611aeb54-9d2c-4dd9-9a39-e5d95627cc82",
116
+ "referer": [
117
+ "subverse-protocol-map",
118
+ "c8961cab-1aeb-4d9e-9cf2-ce94e6b3ef7f"
119
+ ],
120
+ "dt": "2025-03-05T07:52:01.209Z",
121
+ "discovery": {
122
+ "name": "discovery-expanse",
123
+ "graphql": "query { expanse { name map logo(width: 200, height: 200) { link } platforms { name archs agents } protocols { name attr } } }",
124
+ "ttl_msec": 5000
125
+ },
126
+ "_v": "0.8"
127
+ },
128
+ "subverse_info": "0.1"
129
+ }
130
+
131
+ describe("Validation", function () {
132
+ it("JSON_MsgSubverseInfo_expanse.validate(json_msgSubverseInfo_expanse_DCL)", function () {
133
+ expect(JSON_MsgSubverseInfo_expanse.validate(json_msgSubverseInfo_expanse_DCL)).toBe(true);
134
+ });
135
+ });
136
+
137
+ /*
138
+ describe("Validation", function () {
139
+ it("JSON_MsgDiscovery.validate(json_msgDiscovery)", function () {
140
+ expect(JSON_MsgDiscovery.validate(json_msgDiscovery)).toBe(true);
141
+ });
142
+ });
143
+
144
+ describe("Validation", function () {
145
+ it("JSON_MsgAnnouncement.validate(json_msgAnnouncement)", function () {
146
+ expect(JSON_MsgAnnouncement.validate(json_msgAnnouncement)).toBe(true);
147
+ });
148
+ });
149
+
150
+ describe("Validation", function () {
151
+ it("JSON_MsgAnnouncement.validate(json_msgAnnouncement_msg)", function () {
152
+ expect(JSON_MsgAnnouncement.validate(json_msgAnnouncement_msg)).toBe(true);
153
+ });
154
+ });
155
+
156
+ describe("Validation", function () {
157
+ it("JSON_MsgAnnouncement.validate(json_msgAnnouncement_expanse)", function () {
158
+ expect(JSON_MsgAnnouncement.validate(json_msgAnnouncement_expanse)).toBe(true);
159
+ });
160
+ });
161
+ */
162
+
163
+ //-------------------------------------------------------------------------------------------------
164
+
165
+ // protocols are required, except ...
166
+ // instances don't need protocols, if they are linked to a valid subverse
167
+ // - if subverse.spec exists, protocols required
168
+ // - if subverse missing, protocols required
169
+
170
+ //-------------------------------------------------------------------------------------------------
171
+ // subverses
172
+
173
+ // const json_subverse_subverse = {
174
+ // "expanse" : {
175
+ // "platforms": [
176
+ // {
177
+ // "name": "Darwin",
178
+ // "archs": [
179
+ // "arm64",
180
+ // "x86_64"
181
+ // ]
182
+ // },
183
+ // {
184
+ // "name": "Windows",
185
+ // "archs": [
186
+ // "x86",
187
+ // "x64"
188
+ // ]
189
+ // },
190
+ // {
191
+ // "name": "WebBr",
192
+ // "agents": [
193
+ // "Firefox",
194
+ // "Chrome"
195
+ // ]
196
+ // }
197
+ // ],
198
+ // "protocols": [
199
+ // {
200
+ // name: "Discovery@4",
201
+ // attr: "rw"
202
+ // },
203
+ // {
204
+ // name: "Hyperlink",
205
+ // attr: "0w"
206
+ // }
207
+ // ]
208
+ // }
209
+ // }
210
+
211
+ // const json_subverse_instances= {
212
+ // expanse : {
213
+ // instances : [
214
+ // {
215
+ // name : "js-blue",
216
+ // logo : "https://ipsme.dev/js-blue/img/js-blue.png",
217
+ // link : "https://ipsme.dev/js-blue/blue.html"
218
+ // },
219
+ // {
220
+ // name : "js-orange",
221
+ // logo : "http://root-interface.se/js-orange/img/js-orange.png",
222
+ // link : "https://root-interface.se/js-orange/orange.html"
223
+ // }
224
+ // ],
225
+ // locations : {},
226
+ // platforms : [
227
+ // {
228
+ // name: "WebBr",
229
+ // agents : [ "Firefox" ]
230
+ // }
231
+ // ],
232
+ // protocols : [
233
+ // {
234
+ // name: "Hyperlink",
235
+ // attr: "0rw"
236
+ // },
237
+ // {
238
+ // name: "2PhW@0.6",
239
+ // attr: "0rw"
240
+ // }
241
+ // ]
242
+ // }
243
+ // }
244
+
245
+ const json_subverse_minimum = {
246
+ "expanse" : {
247
+ subverse : {
248
+ "name": "Decentraland",
249
+ "uri" : "",
250
+ "map_url": "",
251
+ },
252
+ "protocols": [
253
+ { name: "JanusWeb", attr: "0rw", url: "https://janusvr.com/web.html" },
254
+ ]
255
+ }
256
+ }
257
+
258
+ const json_subverse_minimum_fail = {
259
+ "expanse" : {
260
+ subverse : {
261
+ "name": "Decentraland",
262
+ "uri" : "",
263
+ // "map-url": "",
264
+ },
265
+ "protocols": [
266
+ { name: "JanusWeb", attr: "0rw", url: "https://janusvr.com/web.html" },
267
+ ]
268
+ }
269
+ }
270
+
271
+ const json_subverse_ = {
272
+ "expanse" : {
273
+ subverse : {
274
+ "name": "Decentraland",
275
+ "uri" : "https://decentraland.org",
276
+ map_url : "https://decentraland.org/map",
277
+ "favicon" : "",
278
+ info : {},
279
+ },
280
+ instances : [
281
+ {
282
+ name : "",
283
+ uri : "",
284
+ info : {}
285
+ },
286
+ {
287
+ name : "",
288
+ uri : "",
289
+ info : {}
290
+ },
291
+ ],
292
+ platforms : [],
293
+ "protocols": []
294
+ }
295
+ }
296
+
297
+ /*
298
+ describe("Validation", function () {
299
+ it("JSON_subverse.validate(json_subverse_minimum)", function () {
300
+ expect(JSON_subverse.validate(json_subverse_minimum)).toBe(true);
301
+ });
302
+ });
303
+
304
+ describe("Validation", function () {
305
+ it("JSON_subverse.validate(json_subverse_minimum_fail)", function () {
306
+ expect(JSON_subverse.validate(json_subverse_minimum_fail)).toBe(false);
307
+ });
308
+ });
309
+
310
+ describe("Validation", function () {
311
+ it("JSON_subverse.validate(json_subverse_)", function () {
312
+ expect(JSON_subverse.validate(json_subverse_)).toBe(true);
313
+ });
314
+ });
315
+ */
316
+
317
+ //-------------------------------------------------------------------------------------------------
318
+ // instances
319
+
320
+ const json_instance_minimum = {
321
+ "expanse" : {
322
+ instances : []
323
+ }
324
+ }
325
+
326
+ const json_instance_minimum_fail = {
327
+ "expanse" : {
328
+ // instances : []
329
+ }
330
+ }
331
+
332
+ const json_instance_ = {
333
+ "expanse" : {
334
+ instances : [
335
+ {
336
+ name : "",
337
+ uri : "",
338
+ favicon : "",
339
+ info : {}
340
+ },
341
+ {
342
+ name : "",
343
+ uri : "",
344
+ },
345
+ ],
346
+ subverse : {
347
+ "name": "Decentraland",
348
+ "uri" : "decentraland.org"
349
+ },
350
+ platforms : [],
351
+ "protocols": []
352
+ }
353
+ }
354
+
355
+ /*
356
+ describe("Validation", function () {
357
+ it("JSON_instances.validate(json_instance_minimum)", function () {
358
+ expect(JSON_instances.validate(json_instance_minimum)).toBe(true);
359
+ });
360
+ });
361
+
362
+ describe("Validation", function () {
363
+ it("JSON_instances.validate(json_instance_minimum_fail)", function () {
364
+ expect(JSON_instances.validate(json_instance_minimum_fail)).toBe(false);
365
+ });
366
+ });
367
+
368
+ describe("Validation", function () {
369
+ it("JSON_instances.validate(json_instance_)", function () {
370
+ expect(JSON_instances.validate(json_instance_)).toBe(true);
371
+ });
372
+ });
373
+ */
374
+
375
+ //-------------------------------------------------------------------------------------------------
376
+
377
+