jsforce
Version:
Salesforce API Library for JavaScript
3 lines • 4.63 kB
JavaScript
/*! jsforce - v1.3.0 - 2014-09-15 */
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self);var c=b;c=c.jsforce||(c.jsforce={}),c=c.modules||(c.modules={}),c=c.api||(c.api={}),c.Tooling=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){var c=(jsforce.require("util"),jsforce.require("underscore")._),d=a("../cache"),e=function(a){this._conn=a,this._logger=a._logger;var b=["query","queryMore","create","insert","retrieve","update","upsert","del","delete","destroy","describe","describeGlobal","sobject"];b.forEach(function(b){this[b]=a.constructor.prototype[b]},this),this.cache=new d;var c={key:function(a){return a?"describe."+a:"describe"}};this.describe$=this.cache.makeCacheable(this.describe,this,c),this.describe=this.cache.makeResponseCacheable(this.describe,this,c),this.describeSObject$=this.describe$,this.describeSObject=this.describe,c={key:"describeGlobal"},this.describeGlobal$=this.cache.makeCacheable(this.describeGlobal,this,c),this.describeGlobal=this.cache.makeResponseCacheable(this.describeGlobal,this,c),this.initialize()};e.prototype.initialize=function(){this.sobjects={},this.cache.clear(),this.cache.get("describeGlobal").on("value",c.bind(function(a){if(a.result){var b=c.map(a.result.sobjects,function(a){return a.name});c.each(b,this.sobject,this)}},this))},e.prototype._baseUrl=function(){return this._conn.urls.rest.base+"/tooling"},e.prototype._request=function(){return this._conn._request.apply(this._conn,arguments)},e.prototype.executeAnonymous=function(a,b){var c=this._baseUrl()+"/executeAnonymous?anonymousBody="+encodeURIComponent(a);return this._request(c).thenCall(b)},e.prototype.completions=function(a,b){c.isString(a)||(b=a,a="apex");var d=this._baseUrl()+"/completions?type="+encodeURIComponent(a);return this._request(d).thenCall(b)},b.exports=e},{"../cache":2}],2:[function(a,b){function c(a,b){return b=Array.prototype.slice.apply(b),a+"("+f.map(b,function(a){return JSON.stringify(a)}).join(",")+")"}var d=jsforce.require("events"),e=jsforce.require("util"),f=jsforce.require("underscore")._,g=function(){this.fetching=!1};e.inherits(g,d.EventEmitter),g.prototype.get=function(a){return a?(this.once("value",a),void(f.isUndefined(this._value)||this.emit("value",this._value))):this._value},g.prototype.set=function(a){this._value=a,this.emit("value",this._value)},g.prototype.clear=function(){this.fetching=!1,delete this._value};var h=function(){this._entries={}};h.prototype.get=function(a){if(a&&this._entries[a])return this._entries[a];var b=new g;return this._entries[a]=b,b},h.prototype.clear=function(a){for(var b in this._entries)a&&0!==b.indexOf(a)||this._entries[b].clear()},h.prototype.makeResponseCacheable=function(a,b,d){var e=this;return d=d||{},function(){var g=Array.prototype.slice.apply(arguments),h=g.pop();f.isFunction(h)||(g.push(h),h=null);var i=f.isString(d.key)?d.key:f.isFunction(d.key)?d.key.apply(b,g):c(d.namespace,g),j=e.get(i);j.fetching=!0,h&&g.push(function(a,b){j.set({error:a,result:b}),h(a,b)});var k,l;try{k=a.apply(b||this,g)}catch(m){l=m}if(k&&f.isFunction(k.then))return h?k:k.then(function(a){return j.set({error:void 0,result:a}),a},function(a){throw j.set({error:a,result:void 0}),a});if(j.set({error:l,result:k}),l)throw l;return k}},h.prototype.makeCacheable=function(a,b,d){var e=this;d=d||{};var g=function(){var g=Array.prototype.slice.apply(arguments),h=g.pop();f.isFunction(h)||g.push(h);var i=f.isString(d.key)?d.key:f.isFunction(d.key)?d.key.apply(b,g):c(d.namespace,g),j=e.get(i);if(!f.isFunction(h)){var k=j.get();if(!k)throw new Error("Function call result is not cached yet.");if(k.error)throw k.error;return k.result}j.get(function(a){h(a.error,a.result)}),j.fetching||(j.fetching=!0,g.push(function(a,b){j.set({error:a,result:b})}),a.apply(b||this,g))};return g.clear=function(){var a=f.isString(d.key)?d.key:f.isFunction(d.key)?d.key.apply(b,arguments):c(d.namespace,arguments);e.clear(a)},g},b.exports=h},{}]},{},[1])(1)});
//# sourceMappingURL=jsforce-api-tooling.min.js.map