UNPKG

azure-devops-extension-sdk

Version:
2 lines (1 loc) 7.55 kB
define(["exports"],(function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}"function"==typeof SuppressedError&&SuppressedError;var r=parseInt("10000000000",36),o=Number.MAX_SAFE_INTEGER||9007199254740991;var i=function(){function e(){this.objects={}}return e.prototype.register=function(e,t){this.objects[e]=t},e.prototype.unregister=function(e){delete this.objects[e]},e.prototype.getInstance=function(e,t){var n=this.objects[e];if(n)return"function"==typeof n?n(t):n},e}(),s=1,a=function(){function e(e,t){this.promises={},this.nextMessageId=1,this.nextProxyId=1,this.proxyFunctions={},this.postToWindow=e,this.targetOrigin=t,this.registry=new i,this.channelId=s++,this.targetOrigin||(this.handshakeToken=Math.floor(Math.random()*(o-r)+r).toString(36)+Math.floor(Math.random()*(o-r)+r).toString(36))}return e.prototype.getObjectRegistry=function(){return this.registry},e.prototype.invokeRemoteMethod=function(e,r,o,i,s){return t(this,void 0,void 0,(function(){var t,a,c=this;return n(this,(function(n){return t={id:this.nextMessageId++,methodName:e,instanceId:r,instanceContext:i,params:this._customSerializeObject(o,s),serializationSettings:s},this.targetOrigin||(t.handshakeToken=this.handshakeToken),a=new Promise((function(e,n){c.promises[t.id]={resolve:e,reject:n}})),this._sendRpcMessage(t),[2,a]}))}))},e.prototype.getRemoteObjectProxy=function(e,t){return this.invokeRemoteMethod("",e,void 0,t)},e.prototype.invokeMethod=function(e,t){var n=this;if(t.methodName){var r=e[t.methodName];if("function"==typeof r)try{var o=[];t.params&&(o=this._customDeserializeObject(t.params,{}));var i=r.apply(e,o);i&&i.then&&"function"==typeof i.then?i.then((function(e){n._success(t,e,t.handshakeToken)}),(function(e){n.error(t,e)})):this._success(t,i,t.handshakeToken)}catch(e){this.error(t,e)}else this.error(t,new Error("RPC method not found: "+t.methodName))}else this._success(t,e,t.handshakeToken)},e.prototype.getRegisteredObject=function(e,t){if("__proxyFunctions"===e)return this.proxyFunctions;var n=this.registry.getInstance(e,t);return n||(n=u.getInstance(e,t)),n},e.prototype.onMessage=function(e){var t=this;if(e.instanceId){var n=this.getRegisteredObject(e.instanceId,e.instanceContext);if(!n)return!1;"function"==typeof n.then?n.then((function(n){t.invokeMethod(n,e)}),(function(n){t.error(e,n)})):this.invokeMethod(n,e)}else{var r=this.promises[e.id];if(!r)return!1;e.error?r.reject(this._customDeserializeObject([e.error],{})[0]):r.resolve(this._customDeserializeObject([e.result],{})[0]),delete this.promises[e.id]}return!0},e.prototype.owns=function(e,t,n){if(this.postToWindow===e){if(this.targetOrigin)return!!t&&("null"===t.toLowerCase()||0===this.targetOrigin.toLowerCase().indexOf(t.toLowerCase()));if(n.handshakeToken&&n.handshakeToken===this.handshakeToken)return this.targetOrigin=t,!0}return!1},e.prototype.error=function(e,t){this._sendRpcMessage({id:e.id,error:this._customSerializeObject([t],e.serializationSettings)[0],handshakeToken:e.handshakeToken})},e.prototype._success=function(e,t,n){this._sendRpcMessage({id:e.id,result:this._customSerializeObject([t],e.serializationSettings)[0],handshakeToken:n})},e.prototype._sendRpcMessage=function(e){this.postToWindow.postMessage(JSON.stringify(e),"*")},e.prototype._customSerializeObject=function(e,t,n,r,o){var i=this;if(void 0===r&&(r=1),void 0===o&&(o=1),e&&!(o>100)&&!(e instanceof Node||e instanceof Window||e instanceof Event)){var s,a;(a=n||{newObjects:[],originalObjects:[]}).originalObjects.push(e);var c=function(n,s,c){var u;try{u=n[c]}catch(e){}var h=typeof u;if("undefined"!==h){var f=-1;if("object"===h&&(f=a.originalObjects.indexOf(u)),f>=0){var p=a.newObjects[f];p.__circularReferenceId||(p.__circularReferenceId=r++),s[c]={__circularReference:p.__circularReferenceId}}else"function"===h?(i.nextProxyId++,s[c]={__proxyFunctionId:i._registerProxyFunction(u,e),_channelId:i.channelId}):"object"===h?u&&u instanceof Date?s[c]={__proxyDate:u.getTime()}:s[c]=i._customSerializeObject(u,t,a,r,o+1):"__proxyFunctionId"!==c&&(s[c]=u)}};if(e instanceof Array){s=[],a.newObjects.push(s);for(var u=0,h=e.length;u<h;u++)c(e,s,u)}else{s={},a.newObjects.push(s);var f={};try{f=function(e){for(var t={};e&&e!==Object.prototype;){for(var n=0,r=Object.getOwnPropertyNames(e);n<r.length;n++){var o=r[n];"constructor"!==o&&(t[o]=!0)}e=Object.getPrototypeOf(e)}return t}(e)}catch(e){}for(var p in f)(p&&"_"!==p[0]||t&&t.includeUnderscoreProperties)&&c(e,s,p)}return a.originalObjects.pop(),a.newObjects.pop(),s}},e.prototype._registerProxyFunction=function(e,t){var n=this.nextProxyId++;return this.proxyFunctions["proxy"+n]=function(){return e.apply(t,Array.prototype.slice.call(arguments,0))},n},e.prototype._customDeserializeObject=function(e,t){var n=this,r=this;if(!e)return null;var o=function(e,o){var i=e[o],s=typeof i;"__circularReferenceId"===o&&"number"===s?(t[i]=e,delete e[o]):"object"===s&&i&&(i.__proxyFunctionId?e[o]=function(){return r.invokeRemoteMethod("proxy"+i.__proxyFunctionId,"__proxyFunctions",Array.prototype.slice.call(arguments,0),{},{includeUnderscoreProperties:!0})}:i.__proxyDate?e[o]=new Date(i.__proxyDate):i.__circularReference?e[o]=t[i.__circularReference]:n._customDeserializeObject(i,t))};if(e instanceof Array)for(var i=0,s=e.length;i<s;i++)o(e,i);else if("object"==typeof e)for(var a in e)o(e,a);return e},e}(),c=function(){function e(){var e=this;this._channels=[],this._handleMessageReceived=function(t){var n;if("string"==typeof t.data)try{n=JSON.parse(t.data)}catch(e){}if(n){for(var r=!1,o=void 0,i=0,s=e._channels;i<s.length;i++){var a=s[i];a.owns(t.source,t.origin,n)&&(o=a,r=a.onMessage(n)||r)}o&&!r&&(window.console&&console.error("No handler found on any channel for message: ".concat(JSON.stringify(n))),n.instanceId&&o.error(n,new Error("The registered object ".concat(n.instanceId," could not be found."))))}},window.addEventListener("message",this._handleMessageReceived)}return e.prototype.addChannel=function(e,t){var n=new a(e,t);return this._channels.push(n),n},e.prototype.removeChannel=function(e){this._channels=this._channels.filter((function(t){return t!==e}))},e}(),u=new i,h=new c;e.XDMChannel=a,e.XDMObjectRegistry=i,e.channelManager=h,e.globalObjectRegistry=u}));