@jolokia.js/simple
Version:
Jolokia JavaScript ES Simple module
2 lines (1 loc) • 3.09 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("jolokia.js")):"function"==typeof define&&define.amd?define(["jolokia.js"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).JolokiaSimple=e(t.Jolokia)}(this,(function(t){"use strict";function e(e,r){r&&(Array.isArray(r)?e.path=r.map(t.escapePost).join("/"):e.path=r)}function r(t){if(t.success&&"function"==typeof t.success){const e=t.success;t.success=(t,r)=>{e(t.value)}}}return t.prototype.getAttribute=async function(n,...o){const s={type:"read",mbean:n};let i={};return 3!==o.length||Array.isArray(o[2])||"object"!=typeof o[2]?2===o.length?(s.attribute=o[0],Array.isArray(o[1])||"object"!=typeof o[1]?e(s,o[1]):i=o[1]):1==o.length&&(Array.isArray(o[0])||"object"!=typeof o[0]?s.attribute=o[0]:i=o[0]):(s.attribute=o[0],e(s,o[1]),i=o[2]),i.method="post",r(i),"success"in i||"error"in i?(await this.request(s,i),null):await this.request(s,i).then((e=>{const r=e;if(r){if(t.isError(r))throw r.error;return r.value}return null}))},t.prototype.setAttribute=async function(n,o,s,...i){const u={type:"write",mbean:n,attribute:o,value:s};let a={};return 2!==i.length||Array.isArray(i[1])||"object"!=typeof i[1]?1===i.length&&(Array.isArray(i[0])||"object"!=typeof i[0]?e(u,i[0]):a=i[0]):(e(u,i[0]),a=i[1]),a.method="post",r(a),"success"in a||"error"in a?(await this.request(u,a),null):await this.request(u,a).then((e=>{const r=e;if(r){if(t.isError(r))throw r.error;return r.value}return null}))},t.prototype.execute=async function(e,n,...o){const s={type:"exec",mbean:e,operation:n,arguments:o.length>0&&o[o.length-1]&&!Array.isArray(o[o.length-1])&&"object"==typeof o[o.length-1]?o.slice(0,-1):o},i=o.length>0&&o[o.length-1]&&!Array.isArray(o[o.length-1])&&"object"==typeof o[o.length-1]?o[o.length-1]:{};return i.method="post",r(i),"success"in i||"error"in i?(await this.request(s,i),null):await this.request(s,i).then((e=>{const r=e;if(r){if(t.isError(r))throw r.error;return r.value}return null}))},t.prototype.search=async function(e,n){const o={type:"search",mbean:e},s=n||{};return s.method="post",r(s),"success"in s||"error"in s?(await this.request(o,s),[]):await this.request(o,s).then((e=>{const r=e;if(r){if(t.isError(r))throw r.error;return r.value?r.value:[]}return[]}))},t.prototype.version=async function(e){const n={type:"version"},o=e||{};return o.method="post",r(o),"success"in o||"error"in o?(await this.request(n,o),null):await this.request(n,o).then((e=>{const r=e;if(r){if(t.isError(r))throw r.error;return r.value}return null}))},t.prototype.list=async function(...n){const o={type:"list"};let s={};return 2!==n.length||Array.isArray(n[1])||"object"!=typeof n[1]?1===n.length&&(Array.isArray(n[0])||Array.isArray(n[0])||"object"!=typeof n[0]?e(o,n[0]):s=n[0]):(e(o,n[0]),s=n[1]),s.method="post",r(s),"success"in s||"error"in s?(await this.request(o,s),null):await this.request(o,s).then((e=>{const r=e;if(r){if(t.isError(r))throw r.error;return r.value}return{}}))},t.isVersionResponse=function(t){return!(!t||"object"!=typeof t)&&("protocol"in t&&"agent"in t)},t}));