UNPKG

@microsoft/office-js

Version:
26 lines (19 loc) • 330 kB
/* Copyright (c) Microsoft Corporation. All rights reserved. */ /* Your use of this file is governed by the Microsoft Services Agreement http://go.microsoft.com/fwlink/?LinkId=266419. */ /* * @overview es6-promise - a tiny implementation of Promises/A+. * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) * @license Licensed under MIT license * See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE * @version 2.3.0 */ // Sources: // osfweb: none // runtime: 16.0\15303.10000 // core: 16.0\15303.10000 // host: 16.0.15302.34957 var OfficeExtension,__extends=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(e){var t;!function(e){e.OfficeRequire=function(){return null}()}(e._Internal||(e._Internal={})),function(e){!function(t){t.Init=function(){return function(){"use strict";function t(e){return"function"===typeof e}var n,r=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},i=0,o=function(e,t){l[i]=e,l[i+1]=t,2===(i+=2)&&(n?n(f):u())};var s=("undefined"!==typeof window?window:void 0)||{},a=(s.MutationObserver||s.WebKitMutationObserver,"undefined"!==typeof process&&"[object process]"==={}.toString.call(process)),c="undefined"!==typeof Uint8ClampedArray&&"undefined"!==typeof importScripts&&"undefined"!==typeof MessageChannel;var u,l=new Array(1e3);function f(){for(var e=0;e<i;e+=2){(0,l[e])(l[e+1]),l[e]=void 0,l[e+1]=void 0}i=0}function p(){}u=a?function(){var e=process.nextTick,t=process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);return Array.isArray(t)&&"0"===t[1]&&"10"===t[2]&&(e=window.setImmediate),function(){e(f)}}():c?function(){var e=new MessageChannel;return e.port1.onmessage=f,function(){e.port2.postMessage(0)}}():function(){return function(){setTimeout(f,1)}}();var h=new O;function d(e,n){if(n.constructor===e.constructor)!function(e,t){1===t._state?g(e,t._result):2===t._state?_(e,t._result):b(t,void 0,(function(t){m(e,t)}),(function(t){_(e,t)}))}(e,n);else{var r=function(e){try{return e.then}catch(e){return h.error=e,h}}(n);r===h?_(e,h.error):void 0===r?g(e,n):t(r)?function(e,t,n){o((function(e){var r=!1,i=function(e,t,n,r){try{e.call(t,n,r)}catch(e){return e}}(n,t,(function(n){r||(r=!0,t!==n?m(e,n):g(e,n))}),(function(t){r||(r=!0,_(e,t))}),e._label);!r&&i&&(r=!0,_(e,i))}),e)}(e,n,r):g(e,n)}}function m(e,t){e===t?_(e,function(){return new TypeError("You cannot resolve a promise with itself")}()):!function(e){return"function"===typeof e||"object"===typeof e&&null!==e}(t)?g(e,t):d(e,t)}function y(e){e._onerror&&e._onerror(e._result),v(e)}function g(e,t){void 0===e._state&&(e._result=t,e._state=1,0!==e._subscribers.length&&o(v,e))}function _(e,t){void 0===e._state&&(e._state=2,e._result=t,o(y,e))}function b(e,t,n,r){var i=e._subscribers,s=i.length;e._onerror=null,i[s]=t,i[s+1]=n,i[s+2]=r,0===s&&e._state&&o(v,e)}function v(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var r,i,o=e._result,s=0;s<t.length;s+=3)r=t[s],i=t[s+n],r?I(n,r,i,o):i(o);e._subscribers.length=0}}function O(){this.error=null}var P=new O;function I(e,n,r,i){var o,s,a,c,u=t(r);if(u){if((o=function(e,t){try{return e(t)}catch(e){return P.error=e,P}}(r,i))===P?(c=!0,s=o.error,o=null):a=!0,n===o)return void _(n,function(){return new TypeError("A promises callback cannot return that same promise.")}())}else o=i,a=!0;void 0!==n._state||(u&&a?m(n,o):c?_(n,s):1===e?g(n,o):2===e&&_(n,o))}function R(e,t){this._instanceConstructor=e,this.promise=new e(p),this._validateInput(t)?(this._input=t,this.length=t.length,this._remaining=t.length,this._init(),0===this.length?g(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&g(this.promise,this._result))):_(this.promise,this._validationError())}R.prototype._validateInput=function(e){return r(e)},R.prototype._validationError=function(){return new e.Error("Array Methods must be provided an Array")},R.prototype._init=function(){this._result=new Array(this.length)};var j=R;R.prototype._enumerate=function(){for(var e=this.length,t=this.promise,n=this._input,r=0;void 0===t._state&&r<e;r++)this._eachEntry(n[r],r)},R.prototype._eachEntry=function(e,t){var n=this._instanceConstructor;!function(e){return"object"===typeof e&&null!==e}(e)?(this._remaining--,this._result[t]=e):e.constructor===n&&void 0!==e._state?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(n.resolve(e),t)},R.prototype._settledAt=function(e,t,n){var r=this.promise;void 0===r._state&&(this._remaining--,2===e?_(r,n):this._result[t]=n),0===this._remaining&&g(r,this._result)},R.prototype._willSettleAt=function(e,t){var n=this;b(e,void 0,(function(e){n._settledAt(1,t,e)}),(function(e){n._settledAt(2,t,e)}))};var C=function(e){return new j(this,e).promise};var S=function(e){var t=new this(p);if(!r(e))return _(t,new TypeError("You must pass an array to race.")),t;var n=e.length;function i(e){m(t,e)}function o(e){_(t,e)}for(var s=0;void 0===t._state&&s<n;s++)b(this.resolve(e[s]),void 0,i,o);return t};var A=function(e){if(e&&"object"===typeof e&&e.constructor===this)return e;var t=new this(p);return m(t,e),t};var E=function(e){var t=new this(p);return _(t,e),t},x=0;var N=w;function w(e){this._id=x++,this._state=void 0,this._result=void 0,this._subscribers=[],p!==e&&(t(e)||function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof w||function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}(),function(e,t){try{t((function(t){m(e,t)}),(function(t){_(e,t)}))}catch(t){_(e,t)}}(this,e))}return w.all=C,w.race=S,w.resolve=A,w.reject=E,w._setScheduler=function(e){n=e},w._setAsap=function(e){o=e},w._asap=o,w.prototype={constructor:w,then:function(e,t){var n=this,r=n._state;if(1===r&&!e||2===r&&!t)return this;var i=new this.constructor(p),s=n._result;if(r){var a=arguments[r-1];o((function(){I(r,i,a,s)}))}else b(n,i,e,t);return i},catch:function(e){return this.then(null,e)}},N}.call(this)}}(e.PromiseImpl||(e.PromiseImpl={}))}(e._Internal||(e._Internal={})),function(e){e.OfficePromise=function(){return"undefined"===typeof window&&"function"===typeof Promise?Promise:"undefined"!==typeof window&&window.Promise?function(){var e=window.navigator.userAgent,t=e.indexOf("Edge/");return t>=0&&(e=e.substring(t+5,e.length))<"14.14393"}()?e.PromiseImpl.Init():window.Promise:e.PromiseImpl.Init()}()}(t=e._Internal||(e._Internal={}));var n=t.OfficePromise;e.Promise=n}(OfficeExtension||(OfficeExtension={})),function(e){var t=function(){function e(){}return e.prototype._resolveRequestUrlAndHeaderInfo=function(){return u._createPromiseFromResult(null)},e.prototype._createRequestExecutorOrNull=function(){return null},e.prototype.getEventRegistration=function(e){return null},e}();e.SessionBase=t;var n=function(){function e(){}return e.setCustomSendRequestFunc=function(t){e.s_customSendRequestFunc=t},e.xhrSendRequestFunc=function(e){return u.createPromise((function(t,n){var i=new XMLHttpRequest;if(i.open(e.method,e.url),i.onload=function(){var e={statusCode:i.status,headers:u._parseHttpResponseHeaders(i.getAllResponseHeaders()),body:i.responseText};t(e)},i.onerror=function(){n(new r.RuntimeError({code:o.connectionFailure,httpStatusCode:i.status,message:u._getResourceString(s.connectionFailureWithStatus,i.statusText)}))},e.headers)for(var a in e.headers)i.setRequestHeader(a,e.headers[a]);i.send(u._getRequestBodyText(e))}))},e.fetchSendRequestFunc=function(e){var t=u._getRequestBodyText(e);return""===t&&(t=void 0),fetch(e.url,{method:e.method,headers:e.headers,body:t}).then((function(e){return e.text().then((function(t){var n=e.status,r={};return e.headers.forEach((function(e,t){r[t]=e})),{statusCode:n,headers:r,body:t}}))}))},e.sendRequest=function(t){e.validateAndNormalizeRequest(t);var n=e.s_customSendRequestFunc;return n||(n="undefined"!==typeof fetch?e.fetchSendRequestFunc:e.xhrSendRequestFunc),n(t)},e.setCustomSendLocalDocumentRequestFunc=function(t){e.s_customSendLocalDocumentRequestFunc=t},e.sendLocalDocumentRequest=function(t){return e.validateAndNormalizeRequest(t),(e.s_customSendLocalDocumentRequestFunc||e.officeJsSendLocalDocumentRequestFunc)(t)},e.officeJsSendLocalDocumentRequestFunc=function(e){e=u._validateLocalDocumentRequest(e);var t=u._buildRequestMessageSafeArray(e);return u.createPromise((function(e,n){OSF.DDA.RichApi.executeRichApiRequestAsync(t,(function(t){var n;n="succeeded"==t.status?{statusCode:c.getResponseStatusCode(t),headers:c.getResponseHeaders(t),body:c.getResponseBody(t)}:c.buildHttpResponseFromOfficeJsError(t.error.code,t.error.message),u.log("Response:"),u.log(JSON.stringify(n)),e(n)}))}))},e.validateAndNormalizeRequest=function(e){if(u.isNullOrUndefined(e))throw r.RuntimeError._createInvalidArgError({argumentName:"request"});u.isNullOrEmptyString(e.method)&&(e.method="GET"),e.method=e.method.toUpperCase();var t=!1;if("object"===typeof e.headers&&e.headers[a.testRequestNameHeader]&&(t=!0),!t){var n=l._getCurrentTestNameWithSequenceId();n&&(e.headers||(e.headers={}),e.headers[a.testRequestNameHeader]=n)}},e.logRequest=function(t){if(u._logEnabled){if(u.log("---HTTP Request---"),u.log(t.method+" "+t.url),t.headers)for(var n in t.headers)u.log(n+": "+t.headers[n]);e._logBodyEnabled&&u.log(u._getRequestBodyText(t))}},e.logResponse=function(t){if(u._logEnabled){if(u.log("---HTTP Response---"),u.log(""+t.statusCode),t.headers)for(var n in t.headers)u.log(n+": "+t.headers[n]);e._logBodyEnabled&&u.log(t.body)}},e._logBodyEnabled=!1,e}();e.HttpUtility=n;var r,i=function(){function e(e){var t=this;this.m_bridge=e,this.m_promiseResolver={},this.m_handlers=[],this.m_bridge.onMessageFromHost=function(e){var n=JSON.parse(e);if(3==n.type){var r=n.message;if(r&&r.entries)for(var i=0;i<r.entries.length;i++){var o=r.entries[i];if(Array.isArray(o)){var s={messageCategory:o[0],messageType:o[1],targetId:o[2],message:o[3],id:o[4]};r.entries[i]=s}}}t.dispatchMessage(n)}}return e.init=function(t){if("object"===typeof t&&t){var r=new e(t);e.s_instance=r,n.setCustomSendLocalDocumentRequestFunc((function(t){t=u._validateLocalDocumentRequest(t);var n=0;u.isReadonlyRestRequest(t.method)||(n=1);var i=t.url.indexOf("?");if(i>=0){var o=t.url.substr(i+1),s=u._parseRequestFlagsAndCustomDataFromQueryStringIfAny(o);s.flags>=0&&(n=s.flags)}"string"===typeof t.body&&(t.body=JSON.parse(t.body));var a={id:e.nextId(),type:1,flags:n,message:t};return r.sendMessageToHostAndExpectResponse(a).then((function(e){return e.message}))}));for(var i=0;i<e.s_onInitedHandlers.length;i++)e.s_onInitedHandlers[i](r)}},Object.defineProperty(e,"instance",{get:function(){return e.s_instance},enumerable:!0,configurable:!0}),e.prototype.sendMessageToHost=function(e){this.m_bridge.sendMessageToHost(JSON.stringify(e))},e.prototype.sendMessageToHostAndExpectResponse=function(e){var t=this,n=u.createPromise((function(n,r){t.m_promiseResolver[e.id]=n}));return this.m_bridge.sendMessageToHost(JSON.stringify(e)),n},e.prototype.addHostMessageHandler=function(e){this.m_handlers.push(e)},e.prototype.removeHostMessageHandler=function(e){var t=this.m_handlers.indexOf(e);t>=0&&this.m_handlers.splice(t,1)},e.onInited=function(t){e.s_onInitedHandlers.push(t),e.s_instance&&t(e.s_instance)},e.prototype.dispatchMessage=function(e){if("number"===typeof e.id){var t=this.m_promiseResolver[e.id];if(t)return t(e),void delete this.m_promiseResolver[e.id]}for(var n=0;n<this.m_handlers.length;n++)this.m_handlers[n](e)},e.nextId=function(){return e.s_nextId++},e.s_onInitedHandlers=[],e.s_nextId=1,e}();e.HostBridge=i,"object"===typeof _richApiNativeBridge&&_richApiNativeBridge&&i.init(_richApiNativeBridge),function(e){var t=function(t){function n(e){var r=t.call(this,"string"===typeof e?e:e.message)||this;if(Object.setPrototypeOf(r,n.prototype),r.name="RichApi.Error","string"===typeof e?r.message=e:(r.code=e.code,r.message=e.message,r.traceMessages=e.traceMessages||[],r.innerError=e.innerError||null,r.debugInfo=r._createDebugInfo(e.debugInfo||{}),r.httpStatusCode=e.httpStatusCode,r.data=e.data),u.isNullOrUndefined(r.httpStatusCode)||200===r.httpStatusCode){var i={};i[o.accessDenied]=401,i[o.connectionFailure]=500,i[o.generalException]=500,i[o.invalidArgument]=400,i[o.invalidObjectPath]=400,i[o.invalidOrTimedOutSession]=408,i[o.invalidRequestContext]=400,i[o.timeout]=408,i[o.valueNotLoaded]=400,r.httpStatusCode=i[r.code]}return u.isNullOrUndefined(r.httpStatusCode)&&(r.httpStatusCode=500),r}return __extends(n,t),n.prototype.toString=function(){return this.code+": "+this.message},n.prototype._createDebugInfo=function(t){var n={code:this.code,message:this.message,toString:function(){return JSON.stringify(this)}};for(var r in t)n[r]=t[r];return this.innerError&&(this.innerError instanceof e.RuntimeError?n.innerError=this.innerError.debugInfo:n.innerError=this.innerError),n},n._createInvalidArgError=function(t){return new e.RuntimeError({code:o.invalidArgument,httpStatusCode:400,message:u.isNullOrEmptyString(t.argumentName)?u._getResourceString(s.invalidArgumentGeneric):u._getResourceString(s.invalidArgument,t.argumentName),debugInfo:t.errorLocation?{errorLocation:t.errorLocation}:{},innerError:t.innerError})},n}(Error);e.RuntimeError=t}(r=e._Internal||(e._Internal={})),e.Error=r.RuntimeError;var o=function(){function e(){}return e.apiNotFound="ApiNotFound",e.accessDenied="AccessDenied",e.generalException="GeneralException",e.activityLimitReached="ActivityLimitReached",e.invalidArgument="InvalidArgument",e.connectionFailure="ConnectionFailure",e.timeout="Timeout",e.invalidOrTimedOutSession="InvalidOrTimedOutSession",e.invalidObjectPath="InvalidObjectPath",e.invalidRequestContext="InvalidRequestContext",e.valueNotLoaded="ValueNotLoaded",e.requestPayloadSizeLimitExceeded="RequestPayloadSizeLimitExceeded",e.responsePayloadSizeLimitExceeded="ResponsePayloadSizeLimitExceeded",e.writeNotSupportedWhenModalDialogOpen="WriteNotSupportedWhenModalDialogOpen",e}();e.CoreErrorCodes=o;var s=function(){function e(){}return e.apiNotFoundDetails="ApiNotFoundDetails",e.connectionFailureWithStatus="ConnectionFailureWithStatus",e.connectionFailureWithDetails="ConnectionFailureWithDetails",e.invalidArgument="InvalidArgument",e.invalidArgumentGeneric="InvalidArgumentGeneric",e.timeout="Timeout",e.invalidOrTimedOutSessionMessage="InvalidOrTimedOutSessionMessage",e.invalidSheetName="InvalidSheetName",e.invalidObjectPath="InvalidObjectPath",e.invalidRequestContext="InvalidRequestContext",e.valueNotLoaded="ValueNotLoaded",e}();e.CoreResourceStrings=s;var a=function(){function e(){}return e.flags="flags",e.sourceLibHeader="SdkVersion",e.processQuery="ProcessQuery",e.localDocument="http://document.localhost/",e.localDocumentApiPrefix="http://document.localhost/_api/",e.customData="customdata",e.testRequestNameHeader="x-test-request-name",e}();e.CoreConstants=a;var c=function(){function e(){}return e.buildMessageArrayForIRequestExecutor=function(t,n,r,i){var o=JSON.stringify(r.Body);u.log("Request:"),u.log(o);var s={};return u._copyHeaders(r.Headers,s),s[a.sourceLibHeader]=i,e.buildRequestMessageSafeArray(t,n,"POST",a.processQuery,s,o)},e.buildResponseOnSuccess=function(e,t){var n={HttpStatusCode:200,ErrorCode:"",ErrorMessage:"",Headers:null,Body:null};return n.Body=JSON.parse(e),n.Headers=t,n},e.buildResponseOnError=function(t,n){var r={HttpStatusCode:500,ErrorCode:"",ErrorMessage:"",Headers:null,Body:null};return r.ErrorCode=o.generalException,r.ErrorMessage=n,t==e.OfficeJsErrorCode_ooeNoCapability?(r.ErrorCode=o.accessDenied,r.HttpStatusCode=401):t==e.OfficeJsErrorCode_ooeActivityLimitReached?(r.ErrorCode=o.activityLimitReached,r.HttpStatusCode=429):t==e.OfficeJsErrorCode_ooeInvalidOrTimedOutSession?(r.ErrorCode=o.invalidOrTimedOutSession,r.HttpStatusCode=408,r.ErrorMessage=u._getResourceString(s.invalidOrTimedOutSessionMessage)):t==e.OfficeJsErrorCode_ooeRequestPayloadSizeLimitExceeded?(r.ErrorCode=o.requestPayloadSizeLimitExceeded,r.HttpStatusCode=400):t==e.OfficeJsErrorCode_ooeResponsePayloadSizeLimitExceeded?(r.ErrorCode=o.responsePayloadSizeLimitExceeded,r.HttpStatusCode=400):t==e.OfficeJsErrorCode_ooeWriteNotSupportedWhenModalDialogOpen?(r.ErrorCode=o.writeNotSupportedWhenModalDialogOpen,r.HttpStatusCode=400):t==e.OfficeJsErrorCode_ooeInvalidSheetName&&(r.ErrorCode=o.invalidRequestContext,r.HttpStatusCode=400,r.ErrorMessage=u._getResourceString(s.invalidSheetName)),r},e.buildHttpResponseFromOfficeJsError=function(t,n){var r=500,i={error:{}};return i.error.code=o.generalException,i.error.message=n,t===e.OfficeJsErrorCode_ooeNoCapability?(r=403,i.error.code=o.accessDenied):t===e.OfficeJsErrorCode_ooeActivityLimitReached&&(r=429,i.error.code=o.activityLimitReached),{statusCode:r,headers:{},body:JSON.stringify(i)}},e.buildRequestMessageSafeArray=function(e,t,n,r,i,o){var s=[];if(i)for(var a in i)s.push(a),s.push(i[a]);return[e,n,r,s,o,0,t,"","","","","",""]},e.getResponseBody=function(t){return e.getResponseBodyFromSafeArray(t.value.data)},e.getResponseHeaders=function(t){return e.getResponseHeadersFromSafeArray(t.value.data)},e.getResponseBodyFromSafeArray=function(e){var t=e[2];return"string"===typeof t?t:t.join("")},e.getResponseHeadersFromSafeArray=function(e){var t=e[1];if(!t)return null;for(var n={},r=0;r<t.length-1;r+=2)n[t[r]]=t[r+1];return n},e.getResponseStatusCode=function(t){return e.getResponseStatusCodeFromSafeArray(t.value.data)},e.getResponseStatusCodeFromSafeArray=function(e){return e[0]},e.OfficeJsErrorCode_ooeInvalidOrTimedOutSession=5012,e.OfficeJsErrorCode_ooeActivityLimitReached=5102,e.OfficeJsErrorCode_ooeNoCapability=7e3,e.OfficeJsErrorCode_ooeRequestPayloadSizeLimitExceeded=5103,e.OfficeJsErrorCode_ooeResponsePayloadSizeLimitExceeded=5104,e.OfficeJsErrorCode_ooeWriteNotSupportedWhenModalDialogOpen=5016,e.OfficeJsErrorCode_ooeInvalidSheetName=1014,e}();e.RichApiMessageUtility=c,function(e){e.getPromiseType=function(){if("undefined"!==typeof Promise)return Promise;if("undefined"!==typeof Office&&Office.Promise)return Office.Promise;if("undefined"!==typeof OfficeExtension&&OfficeExtension.Promise)return OfficeExtension.Promise;throw new e.Error("No Promise implementation found")}}(r=e._Internal||(e._Internal={}));var u=function(){function e(){}return e.log=function(t){e._logEnabled&&"undefined"!==typeof console&&console.log&&console.log(t)},e.checkArgumentNull=function(t,n){if(e.isNullOrUndefined(t))throw r.RuntimeError._createInvalidArgError({argumentName:n})},e.isNullOrUndefined=function(e){return null===e||"undefined"===typeof e},e.isUndefined=function(e){return"undefined"===typeof e},e.isNullOrEmptyString=function(e){return null===e||("undefined"===typeof e||0==e.length)},e.isPlainJsonObject=function(t){if(e.isNullOrUndefined(t))return!1;if("object"!==typeof t)return!1;if("[object Object]"!==Object.prototype.toString.apply(t))return!1;if(t.constructor&&!Object.prototype.hasOwnProperty.call(t,"constructor")&&!Object.prototype.hasOwnProperty.call(t.constructor.prototype,"hasOwnProperty"))return!1;for(var n in t)if(!Object.prototype.hasOwnProperty.call(t,n))return!1;return!0},e.trim=function(e){return e.replace(new RegExp("^\\s+|\\s+$","g"),"")},e.caseInsensitiveCompareString=function(t,n){return e.isNullOrUndefined(t)?e.isNullOrUndefined(n):!e.isNullOrUndefined(n)&&t.toUpperCase()==n.toUpperCase()},e.isReadonlyRestRequest=function(t){return e.caseInsensitiveCompareString(t,"GET")},e._getResourceString=function(t,n){var r;if("undefined"!==typeof window&&window.Strings&&window.Strings.OfficeOM){var i="L_"+t,o=window.Strings.OfficeOM[i];o&&(r=o)}if(r||(r=e.s_resourceStringValues[t]),r||(r=t),!e.isNullOrUndefined(n))if(Array.isArray(n)){var s=n;r=e._formatString(r,s)}else r=r.replace("{0}",n);return r},e._formatString=function(e,t){return e.replace(/\{\d\}/g,(function(e){var n=parseInt(e.substr(1,e.length-2));if(n<t.length)return t[n];throw r.RuntimeError._createInvalidArgError({argumentName:"format"})}))},Object.defineProperty(e,"Promise",{get:function(){return r.getPromiseType()},enumerable:!0,configurable:!0}),e.createPromise=function(t){return new e.Promise(t)},e._createPromiseFromResult=function(t){return e.createPromise((function(e,n){e(t)}))},e._createPromiseFromException=function(t){return e.createPromise((function(e,n){n(t)}))},e._createTimeoutPromise=function(t){return e.createPromise((function(e,n){setTimeout((function(){e(null)}),t)}))},e._createInvalidArgError=function(e){return r.RuntimeError._createInvalidArgError(e)},e._isLocalDocumentUrl=function(t){return e._getLocalDocumentUrlPrefixLength(t)>0},e._getLocalDocumentUrlPrefixLength=function(e){for(var t=["http://document.localhost","https://document.localhost","//document.localhost"],n=e.toLowerCase().trim(),r=0;r<t.length;r++){if(n===t[r])return t[r].length;if(n.substr(0,t[r].length+1)===t[r]+"/")return t[r].length+1}return 0},e._validateLocalDocumentRequest=function(t){var n=e._getLocalDocumentUrlPrefixLength(t.url);if(n<=0)throw r.RuntimeError._createInvalidArgError({argumentName:"request"});var i=t.url.substr(n),o=i.toLowerCase();return"_api"===o?i="":"_api/"===o.substr(0,"_api/".length)&&(i=i.substr("_api/".length)),{method:t.method,url:i,headers:t.headers,body:t.body}},e._parseRequestFlagsAndCustomDataFromQueryStringIfAny=function(e){for(var t={flags:-1,customData:""},n=e.split("&"),r=0;r<n.length;r++){var i=n[r].split("=");if(i[0].toLowerCase()===a.flags){var o=parseInt(i[1]);o&=8191,t.flags=o}else i[0].toLowerCase()===a.customData&&(t.customData=decodeURIComponent(i[1]))}return t},e._getRequestBodyText=function(e){var t="";return"string"===typeof e.body?t=e.body:e.body&&"object"===typeof e.body&&(t=JSON.stringify(e.body)),t},e._parseResponseBody=function(t){if("string"===typeof t.body){var n=e.trim(t.body);return JSON.parse(n)}return t.body},e._buildRequestMessageSafeArray=function(t){var n=0;e.isReadonlyRestRequest(t.method)||(n=1);var r="";if(t.url.substr(0,a.processQuery.length).toLowerCase()===a.processQuery.toLowerCase()){var i=t.url.indexOf("?");if(i>0){var o=t.url.substr(i+1),s=e._parseRequestFlagsAndCustomDataFromQueryStringIfAny(o);s.flags>=0&&(n=s.flags),r=s.customData}}return c.buildRequestMessageSafeArray(r,n,t.method,t.url,t.headers,e._getRequestBodyText(t))},e._parseHttpResponseHeaders=function(t){var n={};if(!e.isNullOrEmptyString(t))for(var r=new RegExp("\r?\n"),i=t.split(r),o=0;o<i.length;o++){var s=i[o];if(null!=s){var a=s.indexOf(":");if(a>0){var c=s.substr(0,a),u=s.substr(a+1);c=e.trim(c),u=e.trim(u),n[c.toUpperCase()]=u}}}return n},e._parseErrorResponse=function(t){var n=e._parseErrorResponseBody(t),r=t.statusCode.toString();if(e.isNullOrUndefined(n)||"object"!==typeof n||!n.error)return e._createDefaultErrorResponse(r);var i=n.error,o=i.innerError;return o&&o.code?e._createErrorResponse(o.code,r,o.message):i.code?e._createErrorResponse(i.code,r,i.message):e._createDefaultErrorResponse(r)},e._parseErrorResponseBody=function(t){if(e.isPlainJsonObject(t.body))return t.body;if(!e.isNullOrEmptyString(t.body)){var n=e.trim(t.body);try{return JSON.parse(n)}catch(t){e.log("Error when parse "+n)}}},e._createDefaultErrorResponse=function(t){return{errorCode:o.connectionFailure,errorMessage:e._getResourceString(s.connectionFailureWithStatus,t)}},e._createErrorResponse=function(t,n,r){return{errorCode:t,errorMessage:e._getResourceString(s.connectionFailureWithDetails,[n,t,r])}},e._copyHeaders=function(e,t){if(e&&t)for(var n in e)t[n]=e[n]},e.addResourceStringValues=function(t){for(var n in t)e.s_resourceStringValues[n]=t[n]},e._logEnabled=!1,e.s_resourceStringValues={ApiNotFoundDetails:"The method or property {0} is part of the {1} requirement set, which is not available in your version of {2}.",ConnectionFailureWithStatus:"The request failed with status code of {0}.",ConnectionFailureWithDetails:"The request failed with status code of {0}, error code {1} and the following error message: {2}",InvalidArgument:"The argument '{0}' doesn't work for this situation, is missing, or isn't in the right format.",InvalidObjectPath:'The object path \'{0}\' isn\'t working for what you\'re trying to do. If you\'re using the object across multiple "context.sync" calls and outside the sequential execution of a ".run" batch, please use the "context.trackedObjects.add()" and "context.trackedObjects.remove()" methods to manage the object\'s lifetime.',InvalidRequestContext:"Cannot use the object across different request contexts.",Timeout:"The operation has timed out.",ValueNotLoaded:'The value of the result object has not been loaded yet. Before reading the value property, call "context.sync()" on the associated request context.'},e}();e.CoreUtility=u;var l=function(){function e(){}return e.setMock=function(t){e.s_isMock=t},e.isMock=function(){return e.s_isMock},e._setCurrentTestName=function(t){e.s_currentTestName=t,e.s_currentTestSequenceId=0},e._getCurrentTestNameWithSequenceId=function(){return e.s_currentTestName?(e.s_currentTestSequenceId++,e.s_currentTestName+"."+e.s_currentTestSequenceId):null},e}();e.TestUtility=l,e._internalConfig={showDisposeInfoInDebugInfo:!1,showInternalApiInDebugInfo:!1,enableEarlyDispose:!0,alwaysPolyfillClientObjectUpdateMethod:!1,alwaysPolyfillClientObjectRetrieveMethod:!1,enableConcurrentFlag:!0,enableUndoableFlag:!0,appendTypeNameToObjectPathInfo:!1,enablePreviewExecution:!1},e.config={extendedErrorLogging:!1};var f=function(){function t(){}return t.createSetPropertyAction=function(t,n,r,i,o){P.validateObjectPath(n);var s={Id:t._nextId(),ActionType:4,Name:r,ObjectPathId:n._objectPath.objectPathInfo.Id,ArgumentInfo:{}},a=[i],c=P.setMethodArguments(t,s.ArgumentInfo,a);P.validateReferencedObjectPaths(c);var u=new h(s,0,o);if(u.referencedObjectPath=n._objectPath,u.referencedArgumentObjectPaths=c,e._internalConfig.enablePreviewExecution&&0!==(16&o)){var l={Id:t._nextId(),ActionType:4,Name:r,ObjectId:"",ObjectType:"",Arguments:[i]};n._addPreviewExecutionAction(l)}return n._addAction(u)},t.createQueryAction=function(e,t,n,r){P.validateObjectPath(t);var i={Id:e._nextId(),ActionType:2,Name:"",ObjectPathId:t._objectPath.objectPathInfo.Id,QueryInfo:n},o=new h(i,1,4);return o.referencedObjectPath=t._objectPath,t._addAction(o,r)},t.createQueryAsJsonAction=function(e,t,n,r){P.validateObjectPath(t);var i={Id:e._nextId(),ActionType:7,Name:"",ObjectPathId:t._objectPath.objectPathInfo.Id,QueryInfo:n},o=new h(i,1,4);return o.referencedObjectPath=t._objectPath,t._addAction(o,r)},t.createUpdateAction=function(e,t,n){P.validateObjectPath(t);var r={Id:e._nextId(),ActionType:9,Name:"",ObjectPathId:t._objectPath.objectPathInfo.Id,ObjectState:n},i=new h(r,0,0);return i.referencedObjectPath=t._objectPath,t._addAction(i)},t}();e.CommonActionFactory=f;var p=function(){function t(e,t){this.m_contextBase=e,this.m_objectPath=t}return Object.defineProperty(t.prototype,"_objectPath",{get:function(){return this.m_objectPath},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_context",{get:function(){return this.m_contextBase},enumerable:!0,configurable:!0}),t.prototype._addAction=function(e,t){var n=this;return void 0===t&&(t=null),u.createPromise((function(r,i){n._context._addServiceApiAction(e,t,r,i)}))},t.prototype._addPreviewExecutionAction=function(e){},t.prototype._retrieve=function(t,n){var r=e._internalConfig.alwaysPolyfillClientObjectRetrieveMethod;r||(r=!P.isSetSupported("RichApiRuntime","1.1"));var i=m._parseQueryOption(t);return r?f.createQueryAction(this._context,this,i,n):f.createQueryAsJsonAction(this._context,this,i,n)},t.prototype._recursivelyUpdate=function(t){var n=e._internalConfig.alwaysPolyfillClientObjectUpdateMethod;n||(n=!P.isSetSupported("RichApiRuntime","1.2"));try{var i=this[O.scalarPropertyNames];i||(i=[]);var a=this[O.scalarPropertyUpdateable];if(!a){a=[];for(var c=0;c<i.length;c++)a.push(!1)}var l=this[O.navigationPropertyNames];l||(l=[]);var p={},h={},d=0;for(var m in t){var y=i.indexOf(m);if(y>=0){if(!a[y])throw new r.RuntimeError({code:o.invalidArgument,httpStatusCode:400,message:u._getResourceString(I.attemptingToSetReadOnlyProperty,m),debugInfo:{errorLocation:m}});p[m]=t[m],++d}else{if(!(l.indexOf(m)>=0))throw new r.RuntimeError({code:o.invalidArgument,httpStatusCode:400,message:u._getResourceString(I.propertyDoesNotExist,m),debugInfo:{errorLocation:m}});h[m]=t[m]}}if(d>0)if(n)for(c=0;c<i.length;c++){var g=p[m=i[c]];P.isUndefined(g)||f.createSetPropertyAction(this._context,this,m,g)}else f.createUpdateAction(this._context,this,p);for(var m in h){var _=this[m],b=h[m];_._recursivelyUpdate(b)}}catch(e){throw new r.RuntimeError({code:o.invalidArgument,httpStatusCode:400,message:u._getResourceString(s.invalidArgument,"properties"),debugInfo:{errorLocation:this._className+".update"},innerError:e})}},t}();e.ClientObjectBase=p;var h=function(){function e(e,t,n){this.m_actionInfo=e,this.m_operationType=t,this.m_flags=n}return Object.defineProperty(e.prototype,"actionInfo",{get:function(){return this.m_actionInfo},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"operationType",{get:function(){return this.m_operationType},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"flags",{get:function(){return this.m_flags},enumerable:!0,configurable:!0}),e}();e.Action=h;var d=function(){function t(e,t,n,r,i,o){this.m_objectPathInfo=e,this.m_parentObjectPath=t,this.m_isCollection=n,this.m_isInvalidAfterRequest=r,this.m_isValid=!0,this.m_operationType=i,this.m_flags=o}return Object.defineProperty(t.prototype,"id",{get:function(){var e=this.m_objectPathInfo.ArgumentInfo;if(e){var t=e.Arguments;if(t)return t[0]}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){var e=this.m_parentObjectPath;if(e)return e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parentId",{get:function(){return this.parent?this.parent.id:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"objectPathInfo",{get:function(){return this.m_objectPathInfo},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"operationType",{get:function(){return this.m_operationType},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"flags",{get:function(){return this.m_flags},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isCollection",{get:function(){return this.m_isCollection},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isInvalidAfterRequest",{get:function(){return this.m_isInvalidAfterRequest},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parentObjectPath",{get:function(){return this.m_parentObjectPath},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"argumentObjectPaths",{get:function(){return this.m_argumentObjectPaths},set:function(e){this.m_argumentObjectPaths=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isValid",{get:function(){return this.m_isValid},set:function(e){this.m_isValid=e,!e&&6===this.m_objectPathInfo.ObjectPathType&&this.m_savedObjectPathInfo&&(t.copyObjectPathInfo(this.m_savedObjectPathInfo.pathInfo,this.m_objectPathInfo),this.m_parentObjectPath=this.m_savedObjectPathInfo.parent,this.m_isValid=!0,this.m_savedObjectPathInfo=null)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"originalObjectPathInfo",{get:function(){return this.m_originalObjectPathInfo},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"getByIdMethodName",{get:function(){return this.m_getByIdMethodName},set:function(e){this.m_getByIdMethodName=e},enumerable:!0,configurable:!0}),t.prototype._updateAsNullObject=function(){this.resetForUpdateUsingObjectData(),this.m_objectPathInfo.ObjectPathType=7,this.m_objectPathInfo.Name="",this.m_parentObjectPath=null},t.prototype.saveOriginalObjectPathInfo=function(){e.config.extendedErrorLogging&&!this.m_originalObjectPathInfo&&(this.m_originalObjectPathInfo={},t.copyObjectPathInfo(this.m_objectPathInfo,this.m_originalObjectPathInfo))},t.prototype.updateUsingObjectData=function(e,n){var r=e[O.referenceId];if(!u.isNullOrEmptyString(r)){if(!this.m_savedObjectPathInfo&&!this.isInvalidAfterRequest&&t.isRestorableObjectPath(this.m_objectPathInfo.ObjectPathType)){var i={};t.copyObjectPathInfo(this.m_objectPathInfo,i),this.m_savedObjectPathInfo={pathInfo:i,parent:this.m_parentObjectPath}}return this.saveOriginalObjectPathInfo(),this.resetForUpdateUsingObjectData(),this.m_objectPathInfo.ObjectPathType=6,this.m_objectPathInfo.Name=r,delete this.m_objectPathInfo.ParentObjectPathId,void(this.m_parentObjectPath=null)}if(n){var o=n[O.collectionPropertyPath];if(!u.isNullOrEmptyString(o)&&n.context){var s=P.tryGetObjectIdFromLoadOrRetrieveResult(e);if(!u.isNullOrUndefined(s)){for(var a=o.split("."),c=n.context[a[0]],l=1;l<a.length;l++)c=c[a[l]];return this.saveOriginalObjectPathInfo(),this.resetForUpdateUsingObjectData(),this.m_parentObjectPath=c._objectPath,this.m_objectPathInfo.ParentObjectPathId=this.m_parentObjectPath.objectPathInfo.Id,this.m_objectPathInfo.ObjectPathType=5,this.m_objectPathInfo.Name="",void(this.m_objectPathInfo.ArgumentInfo.Arguments=[s])}}}var f=this.parentObjectPath&&this.parentObjectPath.isCollection,p=this.getByIdMethodName;if(f||!u.isNullOrEmptyString(p)){s=P.tryGetObjectIdFromLoadOrRetrieveResult(e);if(!u.isNullOrUndefined(s))return this.saveOriginalObjectPathInfo(),this.resetForUpdateUsingObjectData(),u.isNullOrEmptyString(p)?(this.m_objectPathInfo.ObjectPathType=5,this.m_objectPathInfo.Name=""):(this.m_objectPathInfo.ObjectPathType=3,this.m_objectPathInfo.Name=p),void(this.m_objectPathInfo.ArgumentInfo.Arguments=[s])}},t.prototype.resetForUpdateUsingObjectData=function(){this.m_isInvalidAfterRequest=!1,this.m_isValid=!0,this.m_operationType=1,this.m_flags=4,this.m_objectPathInfo.ArgumentInfo={},this.m_argumentObjectPaths=null,this.m_getByIdMethodName=null},t.isRestorableObjectPath=function(e){return 1===e||5===e||3===e||4===e},t.copyObjectPathInfo=function(e,t){t.Id=e.Id,t.ArgumentInfo=e.ArgumentInfo,t.Name=e.Name,t.ObjectPathType=e.ObjectPathType,t.ParentObjectPathId=e.ParentObjectPathId},t}();e.ObjectPath=d;var m=function(){function e(){this.m_nextId=0}return e.prototype._nextId=function(){return++this.m_nextId},e.prototype._addServiceApiAction=function(e,t,n,r){this.m_serviceApiQueue||(this.m_serviceApiQueue=new b(this)),this.m_serviceApiQueue.add(e,t,n,r)},e._parseQueryOption=function(t){var n={};if("string"===typeof t){var i=t;n.Select=P._parseSelectExpand(i)}else if(Array.isArray(t))n.Select=t;else if("object"===typeof t){var o=t;if(e.isLoadOption(o)){if("string"===typeof o.select)n.Select=P._parseSelectExpand(o.select);else if(Array.isArray(o.select))n.Select=o.select;else if(!P.isNullOrUndefined(o.select))throw r.RuntimeError._createInvalidArgError({argumentName:"option.select"});if("string"===typeof o.expand)n.Expand=P._parseSelectExpand(o.expand);else if(Array.isArray(o.expand))n.Expand=o.expand;else if(!P.isNullOrUndefined(o.expand))throw r.RuntimeError._createInvalidArgError({argumentName:"option.expand"});if("number"===typeof o.top)n.Top=o.top;else if(!P.isNullOrUndefined(o.top))throw r.RuntimeError._createInvalidArgError({argumentName:"option.top"});if("number"===typeof o.skip)n.Skip=o.skip;else if(!P.isNullOrUndefined(o.skip))throw r.RuntimeError._createInvalidArgError({argumentName:"option.skip"})}else n=e.parseStrictLoadOption(t)}else if(!P.isNullOrUndefined(t))throw r.RuntimeError._createInvalidArgError({argumentName:"option"});return n},e.isLoadOption=function(e){if(!P.isUndefined(e.select)&&("string"===typeof e.select||Array.isArray(e.select)))return!0;if(!P.isUndefined(e.expand)&&("string"===typeof e.expand||Array.isArray(e.expand)))return!0;if(!P.isUndefined(e.top)&&"number"===typeof e.top)return!0;if(!P.isUndefined(e.skip)&&"number"===typeof e.skip)return!0;for(var t in e)return!1;return!0},e.parseStrictLoadOption=function(t){var n={Select:[]};return e.parseStrictLoadOptionHelper(n,"","option",t),n},e.combineQueryPath=function(e,t,n){return 0===e.length?t:e+n+t},e.parseStrictLoadOptionHelper=function(t,n,i,o){for(var s in o){var a=o[s];if("$all"===s){if("boolean"!==typeof a)throw r.RuntimeError._createInvalidArgError({argumentName:e.combineQueryPath(i,s,".")});a&&t.Select.push(e.combineQueryPath(n,"*","/"))}else if("$top"===s){if("number"!==typeof a||n.length>0)throw r.RuntimeError._createInvalidArgError({argumentName:e.combineQueryPath(i,s,".")});t.Top=a}else if("$skip"===s){if("number"!==typeof a||n.length>0)throw r.RuntimeError._createInvalidArgError({argumentName:e.combineQueryPath(i,s,".")});t.Skip=a}else if("boolean"===typeof a)a&&t.Select.push(e.combineQueryPath(n,s,"/"));else{if("object"!==typeof a)throw r.RuntimeError._createInvalidArgError({argumentName:e.combineQueryPath(i,s,".")});e.parseStrictLoadOptionHelper(t,e.combineQueryPath(n,s,"/"),e.combineQueryPath(i,s,"."),a)}}},e}();e.ClientRequestContextBase=m;var y=function(){function e(e){this.m_objectPath=e}return e.prototype._handleResult=function(e){u.isNullOrUndefined(e)?this.m_objectPath._updateAsNullObject():this.m_objectPath.updateUsingObjectData(e,null)},e}(),g=function(){function t(e){this.m_contextBase=e,this.m_actions=[],this.m_actionResultHandler={},this.m_referencedObjectPaths={},this.m_instantiatedObjectPaths={},this.m_preSyncPromises=[],this.m_previewExecutionActions=[]}return t.prototype.addAction=function(e){this.m_actions.push(e),1==e.actionInfo.ActionType&&(this.m_instantiatedObjectPaths[e.actionInfo.ObjectPathId]=e)},t.prototype.addPreviewExecutionAction=function(e){this.m_previewExecutionActions.push(e)},Object.defineProperty(t.prototype,"hasActions",{get:function(){return this.m_actions.length>0},enumerable:!0,configurable:!0}),t.prototype._getLastAction=function(){return this.m_actions[this.m_actions.length-1]},t.prototype.ensureInstantiateObjectPath=function(e){if(e){if(this.m_instantiatedObjectPaths[e.objectPathInfo.Id])return;if(this.ensureInstantiateObjectPath(e.parentObjectPath),this.ensureInstantiateObjectPaths(e.argumentObjectPaths),!this.m_instantiatedObjectPaths[e.objectPathInfo.Id]){var t={Id:this.m_contextBase._nextId(),ActionType:1,Name:"",ObjectPathId:e.objectPathInfo.Id},n=new h(t,1,4);n.referencedObjectPath=e,this.addReferencedObjectPath(e),this.addAction(n);var r=new y(e);this.addActionResultHandler(n,r)}}},t.prototype.ensureInstantiateObjectPaths=function(e){if(e)for(var t=0;t<e.length;t++)this.ensureInstantiateObjectPath(e[t])},t.prototype.addReferencedObjectPath=function(e){if(e&&!this.m_referencedObjectPaths[e.objectPathInfo.Id]){if(!e.isValid)throw new r.RuntimeError({code:o.invalidObjectPath,httpStatusCode:400,message:u._getResourceString(s.invalidObjectPath,P.getObjectPathExpression(e)),debugInfo:{errorLocation:P.getObjectPathExpression(e)}});for(;e;)this.m_referencedObjectPaths[e.objectPathInfo.Id]=e,3==e.objectPathInfo.ObjectPathType&&this.addReferencedObjectPaths(e.argumentObjectPaths),e=e.parentObjectPath}},t.prototype.addReferencedObjectPaths=function(e){if(e)for(var t=0;t<e.length;t++)this.addReferencedObjectPath(e[t])},t.prototype.addActionResultHandler=function(e,t){this.m_actionResultHandler[e.actionInfo.Id]=t},t.prototype.aggregrateRequestFlags=function(e,t,n){return 0===t&&(e|=1,0===(2&n)&&(e&=-17),0===(8&n)&&(e&=-257),e&=-5),1&n&&(e|=2),0===(4&n)&&(e&=-5),e},t.prototype.finallyNormalizeFlags=function(t){return 0===(1&t)&&(t&=-17,t&=-257),e._internalConfig.enableConcurrentFlag||(t&=-5),e._internalConfig.enableUndoableFlag||(t&=-17),P.isSetSupported("RichApiRuntimeFlag","1.1")||(t&=-5,t&=-17),P.isSetSupported("RichApiRuntimeFlag","1.2")||(t&=-257),"number"===typeof this.m_flagsForTesting&&(t=this.m_flagsForTesting),t},t.prototype.buildRequestMessageBodyAndRequestFlags=function(){e._internalConfig.enableEarlyDispose&&t._calculateLastUsedObjectPathIds(this.m_actions);var n=276,r={};for(var i in this.m_referencedObjectPaths)n=this.aggregrateRequestFlags(n,this.m_referencedObjectPaths[i].operationType,this.m_referencedObjectPaths[i].flags),r[i]=this.m_referencedObjectPaths[i].objectPathInfo;for(var o=[],s=!1,a=0;a<this.m_actions.length;a++){var c=this.m_actions[a];3===c.actionInfo.ActionType&&c.actionInfo.Name===O.keepReference&&(s=!0),n=this.aggregrateRequestFlags(n,c.operationType,c.flags),o.push(c.actionInfo)}n=this.finallyNormalizeFlags(n);var u={AutoKeepReference:this.m_contextBase._autoCleanup&&s,Actions:o,ObjectPaths:r};return this.m_previewExecutionActions.length>0&&(u.PreviewExecutionActions=this.m_previewExecutionActions,n|=4096),{body:u,flags:n}},t.prototype.processResponse=function(e){if(e)for(var t=0;t<e.length;t++){var n=e[t],r=this.m_actionResultHandler[n.ActionId];r&&r._handleResult(n.Value)}},t.prototype.invalidatePendingInvalidObjectPaths=function(){for(var e in this.m_referencedObjectPaths)this.m_referencedObjectPaths[e].isInvalidAfterRequest&&(this.m_referencedObjectPaths[e].isValid=!1)},t.prototype._addPreSyncPromise=function(e){this.m_preSyncPromises.push(e)},Object.defineProperty(t.prototype,"_preSyncPromises",{get:function(){return this.m_preSyncPromises},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_actions",{get:function(){return this.m_actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"_objectPaths",{get:function(){return this.m_referencedObjectPaths},enumerable:!0,configurable:!0}),t.prototype._removeKeepReferenceAction=function(e){for(var t=this.m_actions.length-1;t>=0;t--){var n=this.m_actions[t].actionInfo;if(n.ObjectPathId===e&&3===n.ActionType&&n.Name===O.keepReference){this.m_actions.splice(t,1);break}}},t._updateLastUsedActionIdOfObjectPathId=function(e,n,r){for(;n;){if(e[n.objectPathInfo.Id])return;e[n.objectPathInfo.Id]=r;var i=n.argumentObjectPaths;if(i)for(var o=i.length,s=0;s<o;s++)t._updateLastUsedActionIdOfObjectPathId(e,i[s],r);n=n.parentObjectPath}},t._calculateLastUsedObjectPathIds=function(e){for(var n={},r=e.length,i=r-1;i>=0;--i){var o=(p=e[i]).actionInfo.Id;p.referencedObjectPath&&t._updateLastUsedActionIdOfObjectPathId(n,p.referencedObjectPath,o);var s=p.referencedArgumentObjectPaths;if(s)for(var a=s.length,c=0;c<a;c++)t._updateLastUsedActionIdOfObjectPathId(n,s[c],o)}var u={};for(var l in n){var f=u[o=n[l]];f||(f=[],u[o]=f),f.push(parseInt(l))}for(i=0;i<r;i++){var p,h=u[(p=e[i]).actionInfo.Id];h&&h.length>0?p.actionInfo.L=h:p.actionInfo.L&&delete p.actionInfo.L}},t}();e.ClientRequestBase=g;var _=function(){function e(e){this.m_type=e}return Object.defineProperty(e.prototype,"value",{get:function(){if(!this.m_isLoaded)throw new r.RuntimeError({code:o.valueNotLoaded,httpStatusCode:400,message:u._getResourceString(s.valueNotLoaded),debugInfo:{errorLocation:"clientResult.value"}});return this.m_value},enumerable:!0,configurable:!0}),e.prototype._handleResult=function(e){this.m_isLoaded=!0,"object"===typeof e&&e&&e._IsNull||(1===this.m_type?this.m_value=P.adjustToDateTime(e):this.m_value=e)},e}();e.ClientResult=_;var b=function(){function e(e){this.m_context=e,this.m_actions=[]}return e.prototype.add=function(e,t,n,r){var i=this;this.m_actions.push({action:e,resultHandler:t,resolve:n,reject:r}),1===this.m_actions.length&&setTimeout((function(){return i.processActions()}),0)},e.prototype.processActions=function(){var e=this;if(0!==this.m_actions.length){var t=this.m_actions;this.m_actions=[];for(var n=new g(this.m_context),r=0;r<t.length;r++){var i=t[r];n.ensureInstantiateObjectPath(i.action.referencedObjectPath),n.ensureInstantiateObjectPaths(i.action.referencedArgumentObjectPaths),n.addAction(i.action),n.addReferencedObjectPath(i.action.referencedObjectPath),n.addReferencedObjectPaths(i.action.referencedArgumentObjectPaths)}var o=n.buildRequestMessageBodyAndRequestFlags(),s=o.body,c=o.flags,l={Url:a.localDocumentApiPrefix,Headers:null,Body:s};u.log("Request:"),u.log(JSON.stringify(s)),(new v).executeAsync(this.m_context._customData,c,l).then((function(r){e.processResponse(n,t,r)})).catch((function(e){for(var n=0;n<t.length;n++){t[n].reject(e)}}))}},e.prototype.processResponse=function(e,t,n){var r=this.getErrorFromResponse(n),i=null;n.Body.Results?i=n.Body.Results:n.Body.ProcessedResults&&n.Body.ProcessedResults.Results&&(i=n.Body.ProcessedResults.Results),i||(i=[]),this.processActionResults(e,t,i,r)},e.prototype.getErrorFromResponse=function(e){return u.isNullOrEmptyString(e.ErrorCode)?e.Body&&e.Body.Error?new r.RuntimeError({code:e.Body.Error.Code,httpStatusCode:e.Body.Error.HttpStatusCode,message:e.Body.Error.Message}):null:new r.RuntimeError({code:e.ErrorCode,httpStatusCode:e.HttpStatusCode,message:e.ErrorMessage})},e.prototype.processActionResults=function(e,t,n,r){e.processResponse(n);for(var i=0;i<t.length;i++){for(var o=t[i],s=o.action.actionInfo.Id,a=!1,c=0;c<n.length;c++)if(s==n[c].ActionId){var u=n[c].Value;o.resultHandler&&(o.resultHandler._handleResult(u),u=o.resultHandler.value),o.resolve&&o.resolve(u),a=!0;break}!a&&o.reject&&(r?o.reject(r):o.reject("No response for the action."))}},e}(),v=function(){function e(){}return e.prototype.getRequestUrl=function(e,t){return"/"!=e.charAt(e.length-1)&&(e+="/"),e=(e+=a.processQuery)+"?"+a.flags+"="+t.toString()},e.prototype.executeAsync=function(t,r,i){var o={method:"POST",url:this.getRequestUrl(i.Url,r),headers:{},body:i.Body};if(o.headers[a.sourceLibHeader]=e.SourceLibHeaderValue,o.headers["CONTENT-TYPE"]="application/json",i.Headers)for(var s in i.Headers)o.headers[s]=i.Headers[s];return(u._isLocalDocumentUrl(o.url)?n.sendLocalDocumentRequest:n.sendRequest)(o).then((function(e){var t;if(200===e.statusCode)t={HttpStatusCode:e.statusCode,ErrorCode:null,ErrorMessage:null,Headers:e.headers,Body:u._parseResponseBody(e)};else{u.log("Error Response:"+e.body);var n=u._parseErrorResponse(e);t={HttpStatusCode:e.statusCode,ErrorCode:n.errorCode,ErrorMessage:n.errorMessage,Headers:e.headers,Body:null,RawErrorResponseBody:u._parseErrorResponseBody(e)}}return t}))},e.SourceLibHeaderValue="officejs-rest",e}();e.HttpRequestExecutor=v;var O=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.collectionPropertyPath="_collectionPropertyPath",t.id="Id",t.idLowerCase="id",t.idPrivate="_Id",t.keepReference="_KeepReference",t.objectPathIdPrivate="_ObjectPathId",t.referenceId="_ReferenceId",t.items="_Items",t.itemsLowerCase="items",t.scalarPropertyNames="_scalarPropertyNames",t.scalarPropertyOriginalNames="_scalarPropertyOriginalNames",t.navigationPropertyNames="_navigationPropertyNames",t.scalarPropertyUpdateable="_scalarPropertyUpdateable",t.previewExecutionObjectId="_previewExecutionObjectId",t}(a);e.CommonConstants=O;var P=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.validateObjectPath=function(e){for(var n=e._objectPath;n;){if(!n.isValid)throw new r.RuntimeError({code:o.invalidObjectPath,httpStatusCode:400,message:u._getResourceString(s.invalidObjectPath,t.getObjectPathExpression(n)),debugInfo:{errorLocation:t.getObjectPathExpression(n)}});n=n.parentObjectPath}},t.validateReferencedObjectPaths=function(e){if(e)for(var n=0;n<e.length;n++)for(var i=e[n];i;){if(!i.isValid)throw new r.RuntimeError({code:o.invalidObjectPath,httpStatusCode:400,message:u._getResourceString(s.invalidObjectPath,t.getObjectPathExpression(i))});i=i.parentObjectPath}},t._toCamelLowerCase=function(e){if(u.isNullOrEmptyString(e))return e;for(var t=0;t<e.length&&e.charCodeAt(t)>=65&&e.charCodeAt(t)<=90;)t++;return t<e.length?e.substr(0,t).toLowerCase()+e.substr(t):e.toLowerCase()},t.adjustToDateTime=function(e){if(u.isNullOrUndefined(e))return null;if("string"===typeof e)return new Date(e);if(Array.isArray(e)){for(var n=e,r=0;r<n.length;r++)n[r]=t.adjustToDateTime(n[r]);return n}throw u._createInvalidArgError({argumentName:"date"})},t.tryGetObjectIdFromLoadOrRetrieveResult=function(e){var t=e[O.id];return u.isNullOrUndefined(t)&&(t=e[O.idLowerCase]),u.isNullOrUndefined(t)&&(t=e[O.idPrivate]),t},t.getObjectPathExpression=function(e){for(var n="";e;){switch(e.objectPathInfo.ObjectPathType){case 1:n=n;break;case 2:n="new()"+(n.length>0?".":"")+n;break;case 3:n=t.normalizeName(e.objectPathInfo.Name)+"()"+(n.length>0?".":"")+n;break;case 4:n=t.normalizeName(e.objectPathInfo.Name)+(n.length>0?".":"")+n;break;case 5:n="getItem()"+(n.length>0?".":"")+n;break;case 6:n="_reference()"+(n.length>0?".":"")+n}e=e.parentObjectPath}return n},t.setMethodArguments=function(e,n,r){if(u.isNullOrUndefined(r))return null;var i=new Array,o=new Array,s=t.collectObjectPathInfos(e,r,i,o);return n.Arguments=r,s&&(n.ReferencedObjectPathIds=o),i},t.validateContext=function(e,t){if(e&&t&&t._context!==e)throw new r.RuntimeError({code:o.invalidRequestContext,httpStatusCode:400,message:u._getResourceString(s.invalidRequestContext)})},t.isSetSupported=function(e,t){return!("undefined"!==typeof window&&window.Office&&window.Office.context&&window.Office.context.requirements)||window.Office.context.requirements.isSetSupported(e,t)},t.throwIfApiNotSupported=function(e,n,i,a){if(t._doApiNotSupportedCheck&&!t.isSetSupported(n,i)){var c=u._getResourceString(s.apiNotFoundDetails,[e,n+" "+i,a]);throw new r.RuntimeError({code:o.apiNotFound,httpStatusCode:404,message:c,debugInfo:{errorLocation:e}})}},t.calculateApiFlags=function(e,n,r){return t.isSetSupported(n,r)||(e&=-3),e},t._parseSelectExpand=function(e){var t=[];if(!u.isNullOrEmptyString(e))for(var n=e.split(","),r=0;r<n.length;r++){var i=n[r];(i=o(i.trim())).length>0&&t.push(i)}return t;function o(e){var t=e.toLowerCase();if("items"===t||"items/"===t)return"*";return("items/"===t.substr(0,6)||"items."===