diff --git a/package.json b/package.json index cc8ce8f51b7043ac8700049f932efa79520236cc..93c510267f52aebd868c480f40a6594fbd98e572 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "dev": "tsc --watch", "docs": "npx typedoc", "prepublishOnly": "npm run build && npm run docs", - "test": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} mocha -r ts-node/register 'tests/**/*.test.ts'" + "test": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} mocha -r ts-node/register 'tests/**/*.test.ts'", + "qjs": "tsc && " }, "keywords": [], "author": "Marin Karamihalev <marin.karamihalev@iopsys.eu> (http://iopsys.eu)", diff --git a/src/configurations/genexis/async-mqtt.js b/src/configurations/genexis/async-mqtt.js new file mode 100644 index 0000000000000000000000000000000000000000..636c4ebaaca9f1c2258b8ea444831a5c312eefe3 --- /dev/null +++ b/src/configurations/genexis/async-mqtt.js @@ -0,0 +1,104 @@ +import * as os from "os"; +import * as std from "std"; +import { WebSocket } from "/usr/lib/quickjs/websocket.js"; + +class AsyncClient { + constructor() { + globalThis.WebSocket = WebSocket; + // paho-mqtt requires setTimeout and clearTimeout in global scope + globalThis.setTimeout = os.setTimeout; + globalThis.clearTimeout = function (timeout) { + if (timeout) { + os.clearTimeout(timeout); + } + }; + globalThis.global = globalThis; + std.loadScript("/usr/lib/usp-js/lib/protobuf.min.js"); + std.loadScript("/usr/lib/usp-js/lib/paho-mqtt.min.js"); + protobuf.Root.prototype.fetch = function (filename, callback) { + os.setTimeout(function () { + const data = std.loadFile(filename); + if (data === null) { + console.log("failed to load file: " + filename); + callback(new Error("failed to load file: " + filename)); + } else { + //console.log(`data loaded for ${filename}`) + callback(null, data); + } + }, 0); + }; + } + + async connectAsync( + host = "localhost", + port = 9001, + user = "admin", + password = "admin" + ) { + this.client = new Paho.Client( + host, + port, + "/mqtt", + "proto::interop-usp-controller" + ); + const opts = { + userName: user, + password: password, + }; + + const client = this.client; + const connectPromise = new Promise(function (resolve, reject) { + opts.onFailure = function (err) { + reject(new Error(err.errorMessage)); + }; + + opts.onSuccess = function () { + resolve(client); + }; + client.connect(opts); + }); + + this.client = await connectPromise; + // this.client.subscribe('/usp/controller/#') + + return this; + } + + async subscribe(id) { + this.client.subscribe(id); + } + + async unsubscribe(id) { + this.client.unsubscribe(id); + } + + async on(msg, callback) { + if (msg === "message") { + this.client.onMessageArrived = function (msg) { + callback(msg.payloadBytes); + }; + } else if (msg === "error") { + // there is no erro handling in paho mqtt + this.client.onConnectionLost = function (responseObject) { + callback(responseObject); + console.log("USP Disconnected: ", responseObject.errorMessage); + }; + } + } + + async publish(topic, msg) { + this.client.send(topic, msg); + } + + async end() { + this.client.disconnect(); + } +} + +async function main() { + const client = new AsyncClient(); + await client.connect(); +} + +const mqttAsync = new AsyncClient(); +export default mqttAsync; diff --git a/src/configurations/genexis/index.ts b/src/configurations/genexis/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..83baaf47de3614e97135141f9dc4e693992e1393 --- /dev/null +++ b/src/configurations/genexis/index.ts @@ -0,0 +1,78 @@ +// import mqttAsync from "async-mqtt"; +import { + ConnectionClient, + Proto, + HostConnectionOptions, + ConnectionOptions, +} from "../../types"; + +import buildConnect from "../build"; +import protobuf from "protobufjs"; +import rootRecordJson from "../../specs/usp-record-1-1.json"; +import rootMsgJson from "../../specs/usp-msg-1-1.json"; +import mqttAsync from "./async-mqtt.js"; + +const connectClient = async ( + options: ConnectionOptions +): Promise<ConnectionClient> => + //forcing compliance for testing + await mqttAsync.connectAsync( + (options as HostConnectionOptions).host, + (options as HostConnectionOptions).port, + options.username, + options.password + ); + +const loadProtobuf = async (): Promise<Proto> => { + const rootRecord = protobuf.Root.fromJSON(rootRecordJson); + const rootMsg = protobuf.Root.fromJSON(rootMsgJson); + const header: any = rootMsg.lookupType("usp.Header"); + return { rootRecord, rootMsg, header }; +}; + +function decodeId(array) { + var out, i, len, c; + var char2, char3; + + out = ""; + len = array.length; + i = 0; + while (i < len) { + c = array[i++]; + switch (c >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + // 0xxxxxxx + out += String.fromCharCode(c); + break; + case 12: + case 13: + // 110x xxxx 10xx xxxx + char2 = array[i++]; + out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f)); + break; + case 14: + // 1110 xxxx 10xx xxxx 10xx xxxx + char2 = array[i++]; + char3 = array[i++]; + out += String.fromCharCode( + ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0) + ); + break; + } + } + + return out; +} + +export default buildConnect({ + connectClient: connectClient as any, + decodeID: decodeId, + loadProtobuf, +}); diff --git a/src/index.ts b/src/index.ts index 0c979d265b7c2c7376f3a0cebd6897c48380c4f4..f0a72468310f73b91f6020e71226425c1539195a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,6 @@ -import iopsysConnect from "./configurations/iopsys" +import iopsysConnect from "./configurations/iopsys"; import build from "./configurations/build"; +import genexisConnect from "./configurations/genexis/index"; -export { - build -} -export default iopsysConnect; \ No newline at end of file +export { build, genexisConnect }; +export default iopsysConnect; diff --git a/src/specs/usp-msg-1-1.json b/src/specs/usp-msg-1-1.json index c47dbbb3d5d7f855a71a93a09c18c3abc4ecb398..ec2da376f4eb693c3e3d55195de90efd71f62a13 100644 --- a/src/specs/usp-msg-1-1.json +++ b/src/specs/usp-msg-1-1.json @@ -1,1175 +1 @@ -{ - "nested": { - "usp": { - "nested": { - "Msg": { - "fields": { - "header": { - "type": "Header", - "id": 1 - }, - "body": { - "type": "Body", - "id": 2 - } - } - }, - "Header": { - "fields": { - "msgId": { - "type": "string", - "id": 1 - }, - "msgType": { - "type": "MsgType", - "id": 2 - } - }, - "nested": { - "MsgType": { - "values": { - "ERROR": 0, - "GET": 1, - "GET_RESP": 2, - "NOTIFY": 3, - "SET": 4, - "SET_RESP": 5, - "OPERATE": 6, - "OPERATE_RESP": 7, - "ADD": 8, - "ADD_RESP": 9, - "DELETE": 10, - "DELETE_RESP": 11, - "GET_SUPPORTED_DM": 12, - "GET_SUPPORTED_DM_RESP": 13, - "GET_INSTANCES": 14, - "GET_INSTANCES_RESP": 15, - "NOTIFY_RESP": 16, - "GET_SUPPORTED_PROTO": 17, - "GET_SUPPORTED_PROTO_RESP": 18 - } - } - } - }, - "Body": { - "oneofs": { - "msgBody": { - "oneof": [ - "request", - "response", - "error" - ] - } - }, - "fields": { - "request": { - "type": "Request", - "id": 1 - }, - "response": { - "type": "Response", - "id": 2 - }, - "error": { - "type": "Error", - "id": 3 - } - } - }, - "Request": { - "oneofs": { - "reqType": { - "oneof": [ - "get", - "getSupportedDm", - "getInstances", - "set", - "add", - "delete", - "operate", - "notify", - "getSupportedProtocol" - ] - } - }, - "fields": { - "get": { - "type": "Get", - "id": 1 - }, - "getSupportedDm": { - "type": "GetSupportedDM", - "id": 2 - }, - "getInstances": { - "type": "GetInstances", - "id": 3 - }, - "set": { - "type": "Set", - "id": 4 - }, - "add": { - "type": "Add", - "id": 5 - }, - "delete": { - "type": "Delete", - "id": 6 - }, - "operate": { - "type": "Operate", - "id": 7 - }, - "notify": { - "type": "Notify", - "id": 8 - }, - "getSupportedProtocol": { - "type": "GetSupportedProtocol", - "id": 9 - } - } - }, - "Response": { - "oneofs": { - "respType": { - "oneof": [ - "getResp", - "getSupportedDmResp", - "getInstancesResp", - "setResp", - "addResp", - "deleteResp", - "operateResp", - "notifyResp", - "getSupportedProtocolResp" - ] - } - }, - "fields": { - "getResp": { - "type": "GetResp", - "id": 1 - }, - "getSupportedDmResp": { - "type": "GetSupportedDMResp", - "id": 2 - }, - "getInstancesResp": { - "type": "GetInstancesResp", - "id": 3 - }, - "setResp": { - "type": "SetResp", - "id": 4 - }, - "addResp": { - "type": "AddResp", - "id": 5 - }, - "deleteResp": { - "type": "DeleteResp", - "id": 6 - }, - "operateResp": { - "type": "OperateResp", - "id": 7 - }, - "notifyResp": { - "type": "NotifyResp", - "id": 8 - }, - "getSupportedProtocolResp": { - "type": "GetSupportedProtocolResp", - "id": 9 - } - } - }, - "Error": { - "fields": { - "errCode": { - "type": "fixed32", - "id": 1 - }, - "errMsg": { - "type": "string", - "id": 2 - }, - "paramErrs": { - "rule": "repeated", - "type": "ParamError", - "id": 3 - } - }, - "nested": { - "ParamError": { - "fields": { - "paramPath": { - "type": "string", - "id": 1 - }, - "errCode": { - "type": "fixed32", - "id": 2 - }, - "errMsg": { - "type": "string", - "id": 3 - } - } - } - } - }, - "Get": { - "fields": { - "paramPaths": { - "rule": "repeated", - "type": "string", - "id": 1 - } - } - }, - "GetResp": { - "fields": { - "reqPathResults": { - "rule": "repeated", - "type": "RequestedPathResult", - "id": 1 - } - }, - "nested": { - "RequestedPathResult": { - "fields": { - "requestedPath": { - "type": "string", - "id": 1 - }, - "errCode": { - "type": "fixed32", - "id": 2 - }, - "errMsg": { - "type": "string", - "id": 3 - }, - "resolvedPathResults": { - "rule": "repeated", - "type": "ResolvedPathResult", - "id": 4 - } - } - }, - "ResolvedPathResult": { - "fields": { - "resolvedPath": { - "type": "string", - "id": 1 - }, - "resultParams": { - "keyType": "string", - "type": "string", - "id": 2 - } - } - } - } - }, - "GetSupportedDM": { - "fields": { - "objPaths": { - "rule": "repeated", - "type": "string", - "id": 1 - }, - "firstLevelOnly": { - "type": "bool", - "id": 2 - }, - "returnCommands": { - "type": "bool", - "id": 3 - }, - "returnEvents": { - "type": "bool", - "id": 4 - }, - "returnParams": { - "type": "bool", - "id": 5 - } - } - }, - "GetSupportedDMResp": { - "fields": { - "reqObjResults": { - "rule": "repeated", - "type": "RequestedObjectResult", - "id": 1 - } - }, - "nested": { - "RequestedObjectResult": { - "fields": { - "reqObjPath": { - "type": "string", - "id": 1 - }, - "errCode": { - "type": "fixed32", - "id": 2 - }, - "errMsg": { - "type": "string", - "id": 3 - }, - "dataModelInstUri": { - "type": "string", - "id": 4 - }, - "supportedObjs": { - "rule": "repeated", - "type": "SupportedObjectResult", - "id": 5 - } - } - }, - "SupportedObjectResult": { - "fields": { - "supportedObjPath": { - "type": "string", - "id": 1 - }, - "access": { - "type": "ObjAccessType", - "id": 2 - }, - "isMultiInstance": { - "type": "bool", - "id": 3 - }, - "supportedCommands": { - "rule": "repeated", - "type": "SupportedCommandResult", - "id": 4 - }, - "supportedEvents": { - "rule": "repeated", - "type": "SupportedEventResult", - "id": 5 - }, - "supportedParams": { - "rule": "repeated", - "type": "SupportedParamResult", - "id": 6 - } - } - }, - "SupportedParamResult": { - "fields": { - "paramName": { - "type": "string", - "id": 1 - }, - "access": { - "type": "ParamAccessType", - "id": 2 - } - } - }, - "SupportedCommandResult": { - "fields": { - "commandName": { - "type": "string", - "id": 1 - }, - "inputArgNames": { - "rule": "repeated", - "type": "string", - "id": 2 - }, - "outputArgNames": { - "rule": "repeated", - "type": "string", - "id": 3 - } - } - }, - "SupportedEventResult": { - "fields": { - "eventName": { - "type": "string", - "id": 1 - }, - "argNames": { - "rule": "repeated", - "type": "string", - "id": 2 - } - } - }, - "ParamAccessType": { - "values": { - "PARAM_READ_ONLY": 0, - "PARAM_READ_WRITE": 1, - "PARAM_WRITE_ONLY": 2 - } - }, - "ObjAccessType": { - "values": { - "OBJ_READ_ONLY": 0, - "OBJ_ADD_DELETE": 1, - "OBJ_ADD_ONLY": 2, - "OBJ_DELETE_ONLY": 3 - } - } - } - }, - "GetInstances": { - "fields": { - "objPaths": { - "rule": "repeated", - "type": "string", - "id": 1 - }, - "firstLevelOnly": { - "type": "bool", - "id": 2 - } - } - }, - "GetInstancesResp": { - "fields": { - "reqPathResults": { - "rule": "repeated", - "type": "RequestedPathResult", - "id": 1 - } - }, - "nested": { - "RequestedPathResult": { - "fields": { - "requestedPath": { - "type": "string", - "id": 1 - }, - "errCode": { - "type": "fixed32", - "id": 2 - }, - "errMsg": { - "type": "string", - "id": 3 - }, - "currInsts": { - "rule": "repeated", - "type": "CurrInstance", - "id": 4 - } - } - }, - "CurrInstance": { - "fields": { - "instantiatedObjPath": { - "type": "string", - "id": 1 - }, - "uniqueKeys": { - "keyType": "string", - "type": "string", - "id": 2 - } - } - } - } - }, - "GetSupportedProtocol": { - "fields": { - "controllerSupportedProtocolVersions": { - "type": "string", - "id": 1 - } - } - }, - "GetSupportedProtocolResp": { - "fields": { - "agentSupportedProtocolVersions": { - "type": "string", - "id": 1 - } - } - }, - "Add": { - "fields": { - "allowPartial": { - "type": "bool", - "id": 1 - }, - "createObjs": { - "rule": "repeated", - "type": "CreateObject", - "id": 2 - } - }, - "nested": { - "CreateObject": { - "fields": { - "objPath": { - "type": "string", - "id": 1 - }, - "paramSettings": { - "rule": "repeated", - "type": "CreateParamSetting", - "id": 2 - } - } - }, - "CreateParamSetting": { - "fields": { - "param": { - "type": "string", - "id": 1 - }, - "value": { - "type": "string", - "id": 2 - }, - "required": { - "type": "bool", - "id": 3 - } - } - } - } - }, - "AddResp": { - "fields": { - "createdObjResults": { - "rule": "repeated", - "type": "CreatedObjectResult", - "id": 1 - } - }, - "nested": { - "CreatedObjectResult": { - "fields": { - "requestedPath": { - "type": "string", - "id": 1 - }, - "operStatus": { - "type": "OperationStatus", - "id": 2 - } - }, - "nested": { - "OperationStatus": { - "oneofs": { - "operStatus": { - "oneof": [ - "operFailure", - "operSuccess" - ] - } - }, - "fields": { - "operFailure": { - "type": "OperationFailure", - "id": 1 - }, - "operSuccess": { - "type": "OperationSuccess", - "id": 2 - } - }, - "nested": { - "OperationFailure": { - "fields": { - "errCode": { - "type": "fixed32", - "id": 1 - }, - "errMsg": { - "type": "string", - "id": 2 - } - } - }, - "OperationSuccess": { - "fields": { - "instantiatedPath": { - "type": "string", - "id": 1 - }, - "paramErrs": { - "rule": "repeated", - "type": "ParameterError", - "id": 2 - }, - "uniqueKeys": { - "keyType": "string", - "type": "string", - "id": 3 - } - } - } - } - } - } - }, - "ParameterError": { - "fields": { - "param": { - "type": "string", - "id": 1 - }, - "errCode": { - "type": "fixed32", - "id": 2 - }, - "errMsg": { - "type": "string", - "id": 3 - } - } - } - } - }, - "Delete": { - "fields": { - "allowPartial": { - "type": "bool", - "id": 1 - }, - "objPaths": { - "rule": "repeated", - "type": "string", - "id": 2 - } - } - }, - "DeleteResp": { - "fields": { - "deletedObjResults": { - "rule": "repeated", - "type": "DeletedObjectResult", - "id": 1 - } - }, - "nested": { - "DeletedObjectResult": { - "fields": { - "requestedPath": { - "type": "string", - "id": 1 - }, - "operStatus": { - "type": "OperationStatus", - "id": 2 - } - }, - "nested": { - "OperationStatus": { - "oneofs": { - "operStatus": { - "oneof": [ - "operFailure", - "operSuccess" - ] - } - }, - "fields": { - "operFailure": { - "type": "OperationFailure", - "id": 1 - }, - "operSuccess": { - "type": "OperationSuccess", - "id": 2 - } - }, - "nested": { - "OperationFailure": { - "fields": { - "errCode": { - "type": "fixed32", - "id": 1 - }, - "errMsg": { - "type": "string", - "id": 2 - } - } - }, - "OperationSuccess": { - "fields": { - "affectedPaths": { - "rule": "repeated", - "type": "string", - "id": 1 - }, - "unaffectedPathErrs": { - "rule": "repeated", - "type": "UnaffectedPathError", - "id": 2 - } - } - } - } - } - } - }, - "UnaffectedPathError": { - "fields": { - "unaffectedPath": { - "type": "string", - "id": 1 - }, - "errCode": { - "type": "fixed32", - "id": 2 - }, - "errMsg": { - "type": "string", - "id": 3 - } - } - } - } - }, - "Set": { - "fields": { - "allowPartial": { - "type": "bool", - "id": 1 - }, - "updateObjs": { - "rule": "repeated", - "type": "UpdateObject", - "id": 2 - } - }, - "nested": { - "UpdateObject": { - "fields": { - "objPath": { - "type": "string", - "id": 1 - }, - "paramSettings": { - "rule": "repeated", - "type": "UpdateParamSetting", - "id": 2 - } - } - }, - "UpdateParamSetting": { - "fields": { - "param": { - "type": "string", - "id": 1 - }, - "value": { - "type": "string", - "id": 2 - }, - "required": { - "type": "bool", - "id": 3 - } - } - } - } - }, - "SetResp": { - "fields": { - "updatedObjResults": { - "rule": "repeated", - "type": "UpdatedObjectResult", - "id": 1 - } - }, - "nested": { - "UpdatedObjectResult": { - "fields": { - "requestedPath": { - "type": "string", - "id": 1 - }, - "operStatus": { - "type": "OperationStatus", - "id": 2 - } - }, - "nested": { - "OperationStatus": { - "oneofs": { - "operStatus": { - "oneof": [ - "operFailure", - "operSuccess" - ] - } - }, - "fields": { - "operFailure": { - "type": "OperationFailure", - "id": 1 - }, - "operSuccess": { - "type": "OperationSuccess", - "id": 2 - } - }, - "nested": { - "OperationFailure": { - "fields": { - "errCode": { - "type": "fixed32", - "id": 1 - }, - "errMsg": { - "type": "string", - "id": 2 - }, - "updatedInstFailures": { - "rule": "repeated", - "type": "UpdatedInstanceFailure", - "id": 3 - } - } - }, - "OperationSuccess": { - "fields": { - "updatedInstResults": { - "rule": "repeated", - "type": "UpdatedInstanceResult", - "id": 1 - } - } - } - } - } - } - }, - "UpdatedInstanceFailure": { - "fields": { - "affectedPath": { - "type": "string", - "id": 1 - }, - "paramErrs": { - "rule": "repeated", - "type": "ParameterError", - "id": 2 - } - } - }, - "UpdatedInstanceResult": { - "fields": { - "affectedPath": { - "type": "string", - "id": 1 - }, - "paramErrs": { - "rule": "repeated", - "type": "ParameterError", - "id": 2 - }, - "updatedParams": { - "keyType": "string", - "type": "string", - "id": 3 - } - } - }, - "ParameterError": { - "fields": { - "param": { - "type": "string", - "id": 1 - }, - "errCode": { - "type": "fixed32", - "id": 2 - }, - "errMsg": { - "type": "string", - "id": 3 - } - } - } - } - }, - "Operate": { - "fields": { - "command": { - "type": "string", - "id": 1 - }, - "commandKey": { - "type": "string", - "id": 2 - }, - "sendResp": { - "type": "bool", - "id": 3 - }, - "inputArgs": { - "keyType": "string", - "type": "string", - "id": 4 - } - } - }, - "OperateResp": { - "fields": { - "operationResults": { - "rule": "repeated", - "type": "OperationResult", - "id": 1 - } - }, - "nested": { - "OperationResult": { - "oneofs": { - "operationResp": { - "oneof": [ - "reqObjPath", - "reqOutputArgs", - "cmdFailure" - ] - } - }, - "fields": { - "executedCommand": { - "type": "string", - "id": 1 - }, - "reqObjPath": { - "type": "string", - "id": 2 - }, - "reqOutputArgs": { - "type": "OutputArgs", - "id": 3 - }, - "cmdFailure": { - "type": "CommandFailure", - "id": 4 - } - }, - "nested": { - "OutputArgs": { - "fields": { - "outputArgs": { - "keyType": "string", - "type": "string", - "id": 1 - } - } - }, - "CommandFailure": { - "fields": { - "errCode": { - "type": "fixed32", - "id": 1 - }, - "errMsg": { - "type": "string", - "id": 2 - } - } - } - } - } - } - }, - "Notify": { - "oneofs": { - "notification": { - "oneof": [ - "event", - "valueChange", - "objCreation", - "objDeletion", - "operComplete", - "onBoardReq" - ] - } - }, - "fields": { - "subscriptionId": { - "type": "string", - "id": 1 - }, - "sendResp": { - "type": "bool", - "id": 2 - }, - "event": { - "type": "Event", - "id": 3 - }, - "valueChange": { - "type": "ValueChange", - "id": 4 - }, - "objCreation": { - "type": "ObjectCreation", - "id": 5 - }, - "objDeletion": { - "type": "ObjectDeletion", - "id": 6 - }, - "operComplete": { - "type": "OperationComplete", - "id": 7 - }, - "onBoardReq": { - "type": "OnBoardRequest", - "id": 8 - } - }, - "nested": { - "Event": { - "fields": { - "objPath": { - "type": "string", - "id": 1 - }, - "eventName": { - "type": "string", - "id": 2 - }, - "params": { - "keyType": "string", - "type": "string", - "id": 3 - } - } - }, - "ValueChange": { - "fields": { - "paramPath": { - "type": "string", - "id": 1 - }, - "paramValue": { - "type": "string", - "id": 2 - } - } - }, - "ObjectCreation": { - "fields": { - "objPath": { - "type": "string", - "id": 1 - }, - "uniqueKeys": { - "keyType": "string", - "type": "string", - "id": 2 - } - } - }, - "ObjectDeletion": { - "fields": { - "objPath": { - "type": "string", - "id": 1 - } - } - }, - "OperationComplete": { - "oneofs": { - "operationResp": { - "oneof": [ - "reqOutputArgs", - "cmdFailure" - ] - } - }, - "fields": { - "objPath": { - "type": "string", - "id": 1 - }, - "commandName": { - "type": "string", - "id": 2 - }, - "commandKey": { - "type": "string", - "id": 3 - }, - "reqOutputArgs": { - "type": "OutputArgs", - "id": 4 - }, - "cmdFailure": { - "type": "CommandFailure", - "id": 5 - } - }, - "nested": { - "OutputArgs": { - "fields": { - "outputArgs": { - "keyType": "string", - "type": "string", - "id": 1 - } - } - }, - "CommandFailure": { - "fields": { - "errCode": { - "type": "fixed32", - "id": 1 - }, - "errMsg": { - "type": "string", - "id": 2 - } - } - } - } - }, - "OnBoardRequest": { - "fields": { - "oui": { - "type": "string", - "id": 1 - }, - "productClass": { - "type": "string", - "id": 2 - }, - "serialNumber": { - "type": "string", - "id": 3 - }, - "agentSupportedProtocolVersions": { - "type": "string", - "id": 4 - } - } - } - } - }, - "NotifyResp": { - "fields": { - "subscriptionId": { - "type": "string", - "id": 1 - } - } - } - } - } - } -} \ No newline at end of file +{"nested":{"usp":{"nested":{"Msg":{"fields":{"header":{"type":"Header","id":1},"body":{"type":"Body","id":2}}},"Header":{"fields":{"msgId":{"type":"string","id":1},"msgType":{"type":"MsgType","id":2}},"nested":{"MsgType":{"values":{"ERROR":0,"GET":1,"GET_RESP":2,"NOTIFY":3,"SET":4,"SET_RESP":5,"OPERATE":6,"OPERATE_RESP":7,"ADD":8,"ADD_RESP":9,"DELETE":10,"DELETE_RESP":11,"GET_SUPPORTED_DM":12,"GET_SUPPORTED_DM_RESP":13,"GET_INSTANCES":14,"GET_INSTANCES_RESP":15,"NOTIFY_RESP":16,"GET_SUPPORTED_PROTO":17,"GET_SUPPORTED_PROTO_RESP":18}}}},"Body":{"oneofs":{"msgBody":{"oneof":["request","response","error"]}},"fields":{"request":{"type":"Request","id":1},"response":{"type":"Response","id":2},"error":{"type":"Error","id":3}}},"Request":{"oneofs":{"reqType":{"oneof":["get","getSupportedDm","getInstances","set","add","delete","operate","notify","getSupportedProtocol"]}},"fields":{"get":{"type":"Get","id":1},"getSupportedDm":{"type":"GetSupportedDM","id":2},"getInstances":{"type":"GetInstances","id":3},"set":{"type":"Set","id":4},"add":{"type":"Add","id":5},"delete":{"type":"Delete","id":6},"operate":{"type":"Operate","id":7},"notify":{"type":"Notify","id":8},"getSupportedProtocol":{"type":"GetSupportedProtocol","id":9}}},"Response":{"oneofs":{"respType":{"oneof":["getResp","getSupportedDmResp","getInstancesResp","setResp","addResp","deleteResp","operateResp","notifyResp","getSupportedProtocolResp"]}},"fields":{"getResp":{"type":"GetResp","id":1},"getSupportedDmResp":{"type":"GetSupportedDMResp","id":2},"getInstancesResp":{"type":"GetInstancesResp","id":3},"setResp":{"type":"SetResp","id":4},"addResp":{"type":"AddResp","id":5},"deleteResp":{"type":"DeleteResp","id":6},"operateResp":{"type":"OperateResp","id":7},"notifyResp":{"type":"NotifyResp","id":8},"getSupportedProtocolResp":{"type":"GetSupportedProtocolResp","id":9}}},"Error":{"fields":{"errCode":{"type":"fixed32","id":1},"errMsg":{"type":"string","id":2},"paramErrs":{"rule":"repeated","type":"ParamError","id":3}},"nested":{"ParamError":{"fields":{"paramPath":{"type":"string","id":1},"errCode":{"type":"fixed32","id":2},"errMsg":{"type":"string","id":3}}}}},"Get":{"fields":{"paramPaths":{"rule":"repeated","type":"string","id":1}}},"GetResp":{"fields":{"reqPathResults":{"rule":"repeated","type":"RequestedPathResult","id":1}},"nested":{"RequestedPathResult":{"fields":{"requestedPath":{"type":"string","id":1},"errCode":{"type":"fixed32","id":2},"errMsg":{"type":"string","id":3},"resolvedPathResults":{"rule":"repeated","type":"ResolvedPathResult","id":4}}},"ResolvedPathResult":{"fields":{"resolvedPath":{"type":"string","id":1},"resultParams":{"keyType":"string","type":"string","id":2}}}}},"GetSupportedDM":{"fields":{"objPaths":{"rule":"repeated","type":"string","id":1},"firstLevelOnly":{"type":"bool","id":2},"returnCommands":{"type":"bool","id":3},"returnEvents":{"type":"bool","id":4},"returnParams":{"type":"bool","id":5}}},"GetSupportedDMResp":{"fields":{"reqObjResults":{"rule":"repeated","type":"RequestedObjectResult","id":1}},"nested":{"RequestedObjectResult":{"fields":{"reqObjPath":{"type":"string","id":1},"errCode":{"type":"fixed32","id":2},"errMsg":{"type":"string","id":3},"dataModelInstUri":{"type":"string","id":4},"supportedObjs":{"rule":"repeated","type":"SupportedObjectResult","id":5}}},"SupportedObjectResult":{"fields":{"supportedObjPath":{"type":"string","id":1},"access":{"type":"ObjAccessType","id":2},"isMultiInstance":{"type":"bool","id":3},"supportedCommands":{"rule":"repeated","type":"SupportedCommandResult","id":4},"supportedEvents":{"rule":"repeated","type":"SupportedEventResult","id":5},"supportedParams":{"rule":"repeated","type":"SupportedParamResult","id":6}}},"SupportedParamResult":{"fields":{"paramName":{"type":"string","id":1},"access":{"type":"ParamAccessType","id":2}}},"SupportedCommandResult":{"fields":{"commandName":{"type":"string","id":1},"inputArgNames":{"rule":"repeated","type":"string","id":2},"outputArgNames":{"rule":"repeated","type":"string","id":3}}},"SupportedEventResult":{"fields":{"eventName":{"type":"string","id":1},"argNames":{"rule":"repeated","type":"string","id":2}}},"ParamAccessType":{"values":{"PARAM_READ_ONLY":0,"PARAM_READ_WRITE":1,"PARAM_WRITE_ONLY":2}},"ObjAccessType":{"values":{"OBJ_READ_ONLY":0,"OBJ_ADD_DELETE":1,"OBJ_ADD_ONLY":2,"OBJ_DELETE_ONLY":3}}}},"GetInstances":{"fields":{"objPaths":{"rule":"repeated","type":"string","id":1},"firstLevelOnly":{"type":"bool","id":2}}},"GetInstancesResp":{"fields":{"reqPathResults":{"rule":"repeated","type":"RequestedPathResult","id":1}},"nested":{"RequestedPathResult":{"fields":{"requestedPath":{"type":"string","id":1},"errCode":{"type":"fixed32","id":2},"errMsg":{"type":"string","id":3},"currInsts":{"rule":"repeated","type":"CurrInstance","id":4}}},"CurrInstance":{"fields":{"instantiatedObjPath":{"type":"string","id":1},"uniqueKeys":{"keyType":"string","type":"string","id":2}}}}},"GetSupportedProtocol":{"fields":{"controllerSupportedProtocolVersions":{"type":"string","id":1}}},"GetSupportedProtocolResp":{"fields":{"agentSupportedProtocolVersions":{"type":"string","id":1}}},"Add":{"fields":{"allowPartial":{"type":"bool","id":1},"createObjs":{"rule":"repeated","type":"CreateObject","id":2}},"nested":{"CreateObject":{"fields":{"objPath":{"type":"string","id":1},"paramSettings":{"rule":"repeated","type":"CreateParamSetting","id":2}}},"CreateParamSetting":{"fields":{"param":{"type":"string","id":1},"value":{"type":"string","id":2},"required":{"type":"bool","id":3}}}}},"AddResp":{"fields":{"createdObjResults":{"rule":"repeated","type":"CreatedObjectResult","id":1}},"nested":{"CreatedObjectResult":{"fields":{"requestedPath":{"type":"string","id":1},"operStatus":{"type":"OperationStatus","id":2}},"nested":{"OperationStatus":{"oneofs":{"operStatus":{"oneof":["operFailure","operSuccess"]}},"fields":{"operFailure":{"type":"OperationFailure","id":1},"operSuccess":{"type":"OperationSuccess","id":2}},"nested":{"OperationFailure":{"fields":{"errCode":{"type":"fixed32","id":1},"errMsg":{"type":"string","id":2}}},"OperationSuccess":{"fields":{"instantiatedPath":{"type":"string","id":1},"paramErrs":{"rule":"repeated","type":"ParameterError","id":2},"uniqueKeys":{"keyType":"string","type":"string","id":3}}}}}}},"ParameterError":{"fields":{"param":{"type":"string","id":1},"errCode":{"type":"fixed32","id":2},"errMsg":{"type":"string","id":3}}}}},"Delete":{"fields":{"allowPartial":{"type":"bool","id":1},"objPaths":{"rule":"repeated","type":"string","id":2}}},"DeleteResp":{"fields":{"deletedObjResults":{"rule":"repeated","type":"DeletedObjectResult","id":1}},"nested":{"DeletedObjectResult":{"fields":{"requestedPath":{"type":"string","id":1},"operStatus":{"type":"OperationStatus","id":2}},"nested":{"OperationStatus":{"oneofs":{"operStatus":{"oneof":["operFailure","operSuccess"]}},"fields":{"operFailure":{"type":"OperationFailure","id":1},"operSuccess":{"type":"OperationSuccess","id":2}},"nested":{"OperationFailure":{"fields":{"errCode":{"type":"fixed32","id":1},"errMsg":{"type":"string","id":2}}},"OperationSuccess":{"fields":{"affectedPaths":{"rule":"repeated","type":"string","id":1},"unaffectedPathErrs":{"rule":"repeated","type":"UnaffectedPathError","id":2}}}}}}},"UnaffectedPathError":{"fields":{"unaffectedPath":{"type":"string","id":1},"errCode":{"type":"fixed32","id":2},"errMsg":{"type":"string","id":3}}}}},"Set":{"fields":{"allowPartial":{"type":"bool","id":1},"updateObjs":{"rule":"repeated","type":"UpdateObject","id":2}},"nested":{"UpdateObject":{"fields":{"objPath":{"type":"string","id":1},"paramSettings":{"rule":"repeated","type":"UpdateParamSetting","id":2}}},"UpdateParamSetting":{"fields":{"param":{"type":"string","id":1},"value":{"type":"string","id":2},"required":{"type":"bool","id":3}}}}},"SetResp":{"fields":{"updatedObjResults":{"rule":"repeated","type":"UpdatedObjectResult","id":1}},"nested":{"UpdatedObjectResult":{"fields":{"requestedPath":{"type":"string","id":1},"operStatus":{"type":"OperationStatus","id":2}},"nested":{"OperationStatus":{"oneofs":{"operStatus":{"oneof":["operFailure","operSuccess"]}},"fields":{"operFailure":{"type":"OperationFailure","id":1},"operSuccess":{"type":"OperationSuccess","id":2}},"nested":{"OperationFailure":{"fields":{"errCode":{"type":"fixed32","id":1},"errMsg":{"type":"string","id":2},"updatedInstFailures":{"rule":"repeated","type":"UpdatedInstanceFailure","id":3}}},"OperationSuccess":{"fields":{"updatedInstResults":{"rule":"repeated","type":"UpdatedInstanceResult","id":1}}}}}}},"UpdatedInstanceFailure":{"fields":{"affectedPath":{"type":"string","id":1},"paramErrs":{"rule":"repeated","type":"ParameterError","id":2}}},"UpdatedInstanceResult":{"fields":{"affectedPath":{"type":"string","id":1},"paramErrs":{"rule":"repeated","type":"ParameterError","id":2},"updatedParams":{"keyType":"string","type":"string","id":3}}},"ParameterError":{"fields":{"param":{"type":"string","id":1},"errCode":{"type":"fixed32","id":2},"errMsg":{"type":"string","id":3}}}}},"Operate":{"fields":{"command":{"type":"string","id":1},"commandKey":{"type":"string","id":2},"sendResp":{"type":"bool","id":3},"inputArgs":{"keyType":"string","type":"string","id":4}}},"OperateResp":{"fields":{"operationResults":{"rule":"repeated","type":"OperationResult","id":1}},"nested":{"OperationResult":{"oneofs":{"operationResp":{"oneof":["reqObjPath","reqOutputArgs","cmdFailure"]}},"fields":{"executedCommand":{"type":"string","id":1},"reqObjPath":{"type":"string","id":2},"reqOutputArgs":{"type":"OutputArgs","id":3},"cmdFailure":{"type":"CommandFailure","id":4}},"nested":{"OutputArgs":{"fields":{"outputArgs":{"keyType":"string","type":"string","id":1}}},"CommandFailure":{"fields":{"errCode":{"type":"fixed32","id":1},"errMsg":{"type":"string","id":2}}}}}}},"Notify":{"oneofs":{"notification":{"oneof":["event","valueChange","objCreation","objDeletion","operComplete","onBoardReq"]}},"fields":{"subscriptionId":{"type":"string","id":1},"sendResp":{"type":"bool","id":2},"event":{"type":"Event","id":3},"valueChange":{"type":"ValueChange","id":4},"objCreation":{"type":"ObjectCreation","id":5},"objDeletion":{"type":"ObjectDeletion","id":6},"operComplete":{"type":"OperationComplete","id":7},"onBoardReq":{"type":"OnBoardRequest","id":8}},"nested":{"Event":{"fields":{"objPath":{"type":"string","id":1},"eventName":{"type":"string","id":2},"params":{"keyType":"string","type":"string","id":3}}},"ValueChange":{"fields":{"paramPath":{"type":"string","id":1},"paramValue":{"type":"string","id":2}}},"ObjectCreation":{"fields":{"objPath":{"type":"string","id":1},"uniqueKeys":{"keyType":"string","type":"string","id":2}}},"ObjectDeletion":{"fields":{"objPath":{"type":"string","id":1}}},"OperationComplete":{"oneofs":{"operationResp":{"oneof":["reqOutputArgs","cmdFailure"]}},"fields":{"objPath":{"type":"string","id":1},"commandName":{"type":"string","id":2},"commandKey":{"type":"string","id":3},"reqOutputArgs":{"type":"OutputArgs","id":4},"cmdFailure":{"type":"CommandFailure","id":5}},"nested":{"OutputArgs":{"fields":{"outputArgs":{"keyType":"string","type":"string","id":1}}},"CommandFailure":{"fields":{"errCode":{"type":"fixed32","id":1},"errMsg":{"type":"string","id":2}}}}},"OnBoardRequest":{"fields":{"oui":{"type":"string","id":1},"productClass":{"type":"string","id":2},"serialNumber":{"type":"string","id":3},"agentSupportedProtocolVersions":{"type":"string","id":4}}}}},"NotifyResp":{"fields":{"subscriptionId":{"type":"string","id":1}}}}}}} \ No newline at end of file diff --git a/src/specs/usp-record-1-1.json b/src/specs/usp-record-1-1.json index db2a4716a515fa2bb495a5a3d83622dce3c24afa..7a1f7c7a251ee99016505778c6cd5952b4d4b04a 100644 --- a/src/specs/usp-record-1-1.json +++ b/src/specs/usp-record-1-1.json @@ -1,111 +1 @@ -{ - "nested": { - "usp_record": { - "nested": { - "Record": { - "oneofs": { - "recordType": { - "oneof": [ - "noSessionContext", - "sessionContext" - ] - } - }, - "fields": { - "version": { - "type": "string", - "id": 1 - }, - "toId": { - "type": "string", - "id": 2 - }, - "fromId": { - "type": "string", - "id": 3 - }, - "payloadSecurity": { - "type": "PayloadSecurity", - "id": 4 - }, - "macSignature": { - "type": "bytes", - "id": 5 - }, - "senderCert": { - "type": "bytes", - "id": 6 - }, - "noSessionContext": { - "type": "NoSessionContextRecord", - "id": 7 - }, - "sessionContext": { - "type": "SessionContextRecord", - "id": 8 - } - }, - "nested": { - "PayloadSecurity": { - "values": { - "PLAINTEXT": 0, - "TLS12": 1 - } - } - } - }, - "NoSessionContextRecord": { - "fields": { - "payload": { - "type": "bytes", - "id": 2 - } - } - }, - "SessionContextRecord": { - "fields": { - "sessionId": { - "type": "uint64", - "id": 1 - }, - "sequenceId": { - "type": "uint64", - "id": 2 - }, - "expectedId": { - "type": "uint64", - "id": 3 - }, - "retransmitId": { - "type": "uint64", - "id": 4 - }, - "payloadSarState": { - "type": "PayloadSARState", - "id": 5 - }, - "payloadrecSarState": { - "type": "PayloadSARState", - "id": 6 - }, - "payload": { - "rule": "repeated", - "type": "bytes", - "id": 7 - } - }, - "nested": { - "PayloadSARState": { - "values": { - "NONE": 0, - "BEGIN": 1, - "INPROCESS": 2, - "COMPLETE": 3 - } - } - } - } - } - } - } -} \ No newline at end of file +{"nested":{"usp_record":{"nested":{"Record":{"oneofs":{"recordType":{"oneof":["noSessionContext","sessionContext"]}},"fields":{"version":{"type":"string","id":1},"toId":{"type":"string","id":2},"fromId":{"type":"string","id":3},"payloadSecurity":{"type":"PayloadSecurity","id":4},"macSignature":{"type":"bytes","id":5},"senderCert":{"type":"bytes","id":6},"noSessionContext":{"type":"NoSessionContextRecord","id":7},"sessionContext":{"type":"SessionContextRecord","id":8}},"nested":{"PayloadSecurity":{"values":{"PLAINTEXT":0,"TLS12":1}}}},"NoSessionContextRecord":{"fields":{"payload":{"type":"bytes","id":2}}},"SessionContextRecord":{"fields":{"sessionId":{"type":"uint64","id":1},"sequenceId":{"type":"uint64","id":2},"expectedId":{"type":"uint64","id":3},"retransmitId":{"type":"uint64","id":4},"payloadSarState":{"type":"PayloadSARState","id":5},"payloadrecSarState":{"type":"PayloadSARState","id":6},"payload":{"rule":"repeated","type":"bytes","id":7}},"nested":{"PayloadSARState":{"values":{"NONE":0,"BEGIN":1,"INPROCESS":2,"COMPLETE":3}}}}}}}} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 62a3b98e847d52aed6101e0b02bf9bdd086820c2..137be14398074c7bd49479ec6a71123659248512 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,8 +8,8 @@ "web" ], "compilerOptions": { - "target": "ES5", - "module": "CommonJS", + "target": "ESNext", + "module": "ES6", "lib": ["ESNext","DOM"], "allowJs": true, "outDir": "node", diff --git a/webpack.config.js b/webpack.config.js index 7ac1adb03537f50483f84081480fa8092ec99421..6ebcb7351d0567e35447c932d3bbf3ff586ade96 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,10 @@ const path = require("path"); module.exports = { + externals: { + std: 'std', + '/usr/lib/quickjs/websocket.js': '/usr/lib/quickjs/websocket.js' + }, mode: "production", entry: { index: "./src/index.ts", @@ -22,11 +26,19 @@ module.exports = { { test: /\.tsx?$/, loader: "awesome-typescript-loader", - exclude: /node_modules/, + exclude: [ + /node_modules/, + ], query: { declaration: true, }, }, + { + test: /\.js$/, + exclude: [ + /node_modules/, + ], + } ], - } + }, };