Socket
Socket
Sign inDemoInstall

mappersmith

Package Overview
Dependencies
Maintainers
3
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mappersmith - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

4

build/mappersmith.js

@@ -9,5 +9,5 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Mappersmith=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

forge: function(manifest, gateway) {
return new Mappersmith.Mapper(
return new this.Mapper(
manifest,
gateway || Mappersmith.VanillaGateway
gateway || this.VanillaGateway
).build();

@@ -14,0 +14,0 @@ }

@@ -1,1 +0,1 @@

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Mappersmith=e()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module){module.exports={Utils:require("./src/utils"),Gateway:require("./src/gateway"),Mapper:require("./src/mapper.js"),VanillaGateway:require("./src/gateway/vanilla-gateway"),JQueryGateway:require("./src/gateway/jquery-gateway"),forge:function(manifest,gateway){return new Mappersmith.Mapper(manifest,gateway||Mappersmith.VanillaGateway).build()}}},{"./src/gateway":2,"./src/gateway/jquery-gateway":3,"./src/gateway/vanilla-gateway":4,"./src/mapper.js":5,"./src/utils":6}],2:[function(require,module){var Utils=require("./utils"),Gateway=function(url,method,opts){this.url=url,this.method=method,this.opts=opts||{},this.successCallback=Utils.noop,this.failCallback=Utils.noop,this.completeCallback=Utils.noop};Gateway.prototype={call:function(){return this[this.method](),this},success:function(callback){return this.successCallback=callback,this},fail:function(callback){return this.failCallback=callback,this},complete:function(callback){return this.completeCallback=callback,this},get:function(){throw new Utils.Exception("Gateway#get not implemented")},post:function(){throw new Utils.Exception("Gateway#post not implemented")},put:function(){throw new Utils.Exception("Gateway#put not implemented")},"delete":function(){throw new Utils.Exception("Gateway#delete not implemented")},patch:function(){throw new Utils.Exception("Gateway#patch not implemented")}},module.exports=Gateway},{"./utils":6}],3:[function(require,module){var Utils=require("../utils"),Gateway=require("../gateway"),JQueryGateway=function(){if(void 0===window.jQuery)throw new Utils.Exception("JQueryGateway requires jQuery but it was not found! Change the gateway implementation or add jQuery on the page");return Gateway.apply(this,arguments)};JQueryGateway.prototype=Utils.extend({},Gateway.prototype,{get:function(){var defaults={dataType:"json",url:this.url},config=Utils.extend(defaults,this.opts);return jQuery.ajax(config).done(function(){this.successCallback.apply(this,arguments)}.bind(this)).fail(function(){this.failCallback.apply(this,arguments)}.bind(this)).always(function(){this.completeCallback.apply(this,arguments)}.bind(this)),this}}),module.exports=JQueryGateway},{"../gateway":2,"../utils":6}],4:[function(require,module){var Utils=require("../utils"),Gateway=require("../gateway"),VanillaGateway=function(){return Gateway.apply(this,arguments)};VanillaGateway.prototype=Utils.extend({},Gateway.prototype,{get:function(){var request=new XMLHttpRequest;request.onload=function(){var data=null;try{request.status>=200&&request.status<400?(data=JSON.parse(request.responseText),this.successCallback(data)):this.failCallback(request)}catch(e){this.failCallback(request)}finally{this.completeCallback(data)}}.bind(this),request.onerror=function(){this.failCallback.apply(this,arguments),this.completeCallback.apply(this,arguments)}.bind(this),this.opts.configure&&this.opts.configure(request),request.open("GET",this.url,!0),request.send()}}),module.exports=VanillaGateway},{"../gateway":2,"../utils":6}],5:[function(require,module){var Mapper=function(manifest,Gateway){this.manifest=manifest,this.Gateway=Gateway,this.host=this.manifest.host};Mapper.prototype={build:function(){return Object.keys(this.manifest.resources||{}).map(function(name){return this.buildResource(name)}.bind(this)).reduce(function(context,resource){return context[resource.name]=resource.methods,context},{})},buildResource:function(resourceName){var methods=this.manifest.resources[resourceName];return Object.keys(methods).reduce(function(context,methodName){var descriptor=methods[methodName],httpMethod=(descriptor.method||"get").toLowerCase();return context.methods[methodName]=this.newGatewayRequest(httpMethod,descriptor.path),context}.bind(this),{name:resourceName,methods:{}})},urlFor:function(path,urlParams){var host=this.host.replace(/\/$/,""),params=urlParams||{},normalizedPath=/^\//.test(path)?path:"/"+path;Object.keys(params).forEach(function(key){var value=params[key],pattern="{"+key+"}";new RegExp(pattern).test(normalizedPath)&&(normalizedPath=normalizedPath.replace("{"+key+"}",value),delete params[key])});var paramsString=Object.keys(params).filter(function(key){return void 0!==key&&null!==key}).map(function(key){return key+"="+params[key]}).join("&");return 0!==paramsString.length&&(paramsString="?"+paramsString),host+normalizedPath+paramsString},newGatewayRequest:function(method,path){return function(params,callback,opts){"function"==typeof params&&(opts=callback,callback=params,params=void 0);var url=this.urlFor(path,params);return new this.Gateway(url,method,opts).success(callback).call()}.bind(this)}},module.exports=Mapper},{}],6:[function(require,module){module.exports={noop:function(){},extend:function(out){out=out||{};for(var i=1;i<arguments.length;i++)if(arguments[i])for(var key in arguments[i])arguments[i].hasOwnProperty(key)&&(out[key]=arguments[i][key]);return out},Exception:function(message){this.message=message,this.toString=function(){return"[Mappersmith] "+this.message}}}},{}]},{},[1])(1)});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Mappersmith=e()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module){module.exports={Utils:require("./src/utils"),Gateway:require("./src/gateway"),Mapper:require("./src/mapper.js"),VanillaGateway:require("./src/gateway/vanilla-gateway"),JQueryGateway:require("./src/gateway/jquery-gateway"),forge:function(manifest,gateway){return new this.Mapper(manifest,gateway||this.VanillaGateway).build()}}},{"./src/gateway":2,"./src/gateway/jquery-gateway":3,"./src/gateway/vanilla-gateway":4,"./src/mapper.js":5,"./src/utils":6}],2:[function(require,module){var Utils=require("./utils"),Gateway=function(url,method,opts){this.url=url,this.method=method,this.opts=opts||{},this.successCallback=Utils.noop,this.failCallback=Utils.noop,this.completeCallback=Utils.noop};Gateway.prototype={call:function(){return this[this.method](),this},success:function(callback){return this.successCallback=callback,this},fail:function(callback){return this.failCallback=callback,this},complete:function(callback){return this.completeCallback=callback,this},get:function(){throw new Utils.Exception("Gateway#get not implemented")},post:function(){throw new Utils.Exception("Gateway#post not implemented")},put:function(){throw new Utils.Exception("Gateway#put not implemented")},"delete":function(){throw new Utils.Exception("Gateway#delete not implemented")},patch:function(){throw new Utils.Exception("Gateway#patch not implemented")}},module.exports=Gateway},{"./utils":6}],3:[function(require,module){var Utils=require("../utils"),Gateway=require("../gateway"),JQueryGateway=function(){if(void 0===window.jQuery)throw new Utils.Exception("JQueryGateway requires jQuery but it was not found! Change the gateway implementation or add jQuery on the page");return Gateway.apply(this,arguments)};JQueryGateway.prototype=Utils.extend({},Gateway.prototype,{get:function(){var defaults={dataType:"json",url:this.url},config=Utils.extend(defaults,this.opts);return jQuery.ajax(config).done(function(){this.successCallback.apply(this,arguments)}.bind(this)).fail(function(){this.failCallback.apply(this,arguments)}.bind(this)).always(function(){this.completeCallback.apply(this,arguments)}.bind(this)),this}}),module.exports=JQueryGateway},{"../gateway":2,"../utils":6}],4:[function(require,module){var Utils=require("../utils"),Gateway=require("../gateway"),VanillaGateway=function(){return Gateway.apply(this,arguments)};VanillaGateway.prototype=Utils.extend({},Gateway.prototype,{get:function(){var request=new XMLHttpRequest;request.onload=function(){var data=null;try{request.status>=200&&request.status<400?(data=JSON.parse(request.responseText),this.successCallback(data)):this.failCallback(request)}catch(e){this.failCallback(request)}finally{this.completeCallback(data)}}.bind(this),request.onerror=function(){this.failCallback.apply(this,arguments),this.completeCallback.apply(this,arguments)}.bind(this),this.opts.configure&&this.opts.configure(request),request.open("GET",this.url,!0),request.send()}}),module.exports=VanillaGateway},{"../gateway":2,"../utils":6}],5:[function(require,module){var Mapper=function(manifest,Gateway){this.manifest=manifest,this.Gateway=Gateway,this.host=this.manifest.host};Mapper.prototype={build:function(){return Object.keys(this.manifest.resources||{}).map(function(name){return this.buildResource(name)}.bind(this)).reduce(function(context,resource){return context[resource.name]=resource.methods,context},{})},buildResource:function(resourceName){var methods=this.manifest.resources[resourceName];return Object.keys(methods).reduce(function(context,methodName){var descriptor=methods[methodName],httpMethod=(descriptor.method||"get").toLowerCase();return context.methods[methodName]=this.newGatewayRequest(httpMethod,descriptor.path),context}.bind(this),{name:resourceName,methods:{}})},urlFor:function(path,urlParams){var host=this.host.replace(/\/$/,""),params=urlParams||{},normalizedPath=/^\//.test(path)?path:"/"+path;Object.keys(params).forEach(function(key){var value=params[key],pattern="{"+key+"}";new RegExp(pattern).test(normalizedPath)&&(normalizedPath=normalizedPath.replace("{"+key+"}",value),delete params[key])});var paramsString=Object.keys(params).filter(function(key){return void 0!==key&&null!==key}).map(function(key){return key+"="+params[key]}).join("&");return 0!==paramsString.length&&(paramsString="?"+paramsString),host+normalizedPath+paramsString},newGatewayRequest:function(method,path){return function(params,callback,opts){"function"==typeof params&&(opts=callback,callback=params,params=void 0);var url=this.urlFor(path,params);return new this.Gateway(url,method,opts).success(callback).call()}.bind(this)}},module.exports=Mapper},{}],6:[function(require,module){module.exports={noop:function(){},extend:function(out){out=out||{};for(var i=1;i<arguments.length;i++)if(arguments[i])for(var key in arguments[i])arguments[i].hasOwnProperty(key)&&(out[key]=arguments[i][key]);return out},Exception:function(message){this.message=message,this.toString=function(){return"[Mappersmith] "+this.message}}}},{}]},{},[1])(1)});

@@ -8,7 +8,7 @@ module.exports = {

forge: function(manifest, gateway) {
return new Mappersmith.Mapper(
return new this.Mapper(
manifest,
gateway || Mappersmith.VanillaGateway
gateway || this.VanillaGateway
).build();
}
}
{
"name": "mappersmith",
"version": "0.1.0",
"version": "0.1.1",
"description": "It is a lightweight rest client mapper for javascript",

@@ -5,0 +5,0 @@ "author": "Tulio Ornelas <ornelas.tulio@gmail.com>",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc