Comparing version 0.0.12 to 0.0.13
@@ -161,3 +161,5 @@ 'use strict'; | ||
set: function set(val) { | ||
if (this.config.debug) this.logger.warn('debug mode must explicitly be turned on via the constructor in config.debug'); | ||
if (this.config.debug) { | ||
this.logger.warn('debug mode must explicitly be turned on via the constructor in config.debug'); | ||
} | ||
} | ||
@@ -164,0 +166,0 @@ }, { |
@@ -60,9 +60,14 @@ 'use strict'; | ||
var urlParams = []; | ||
var id = arguments.length <= 1 ? undefined : arguments[1]; | ||
var data = arguments.length <= 2 ? undefined : arguments[2]; | ||
for (var _len = arguments.length, params = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
params[_key - 1] = arguments[_key]; | ||
} | ||
var id = params[0]; | ||
var data = params[1]; | ||
if (Number.isInteger(id)) { | ||
this.id(id); | ||
} else { | ||
data = arguments.length <= 1 ? undefined : arguments[1]; | ||
data = params[0]; | ||
} | ||
@@ -74,3 +79,3 @@ | ||
if (method == 'update') { | ||
if (method === 'update') { | ||
this.withParams(data); | ||
@@ -89,4 +94,4 @@ } | ||
value: function update() { | ||
for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) { | ||
params[_key] = arguments[_key]; | ||
for (var _len2 = arguments.length, params = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
params[_key2] = arguments[_key2]; | ||
} | ||
@@ -115,4 +120,4 @@ | ||
value: function destroy() { | ||
for (var _len2 = arguments.length, params = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
params[_key2] = arguments[_key2]; | ||
for (var _len3 = arguments.length, params = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
params[_key3] = arguments[_key3]; | ||
} | ||
@@ -119,0 +124,0 @@ |
@@ -18,4 +18,4 @@ 'use strict'; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /*! | ||
* Rapid.js v0.0.1 | ||
* (c) 2017 Drew J Bartlett (http://drewjbartlett.com) | ||
* Rapid.js v0.0.13 | ||
* (c) 2017 Drew J Bartlett (https://drewjbartlett.com) | ||
* Released under the MIT License. | ||
@@ -22,0 +22,0 @@ */ |
@@ -9,2 +9,4 @@ 'use strict'; | ||
var _lodash = require('lodash'); | ||
var _Routes2 = require('./Routes'); | ||
@@ -14,4 +16,2 @@ | ||
var _lodash = require('lodash'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -53,2 +53,3 @@ | ||
// axios handles the options differently for the request type | ||
if (['put', 'post', 'patch'].includes(type)) { | ||
@@ -306,3 +307,3 @@ params = (0, _lodash.defaultsDeep)(params, this.config.globalParameters); | ||
this.requestData.params = params; | ||
(0, _lodash.set)(this.requestData, 'params', params); | ||
@@ -322,3 +323,3 @@ return this; | ||
value: function withParam(key, value) { | ||
this.requestData.params[key] = value; | ||
(0, _lodash.set)(this.requestData, 'params.' + key, value); | ||
@@ -339,3 +340,3 @@ return this; | ||
this.requestData.options = options; | ||
(0, _lodash.set)(this.requestData, 'options', options); | ||
@@ -355,3 +356,3 @@ return this; | ||
value: function withOption(key, value) { | ||
this.requestData.options[key] = value; | ||
(0, _lodash.set)(this.requestData, 'options.' + key, value); | ||
@@ -358,0 +359,0 @@ return this; |
@@ -9,6 +9,4 @@ 'use strict'; | ||
var _Url2 = require('./Url'); | ||
var _lodash = require('lodash'); | ||
var _Url3 = _interopRequireDefault(_Url2); | ||
var _pluralize = require('pluralize'); | ||
@@ -18,4 +16,6 @@ | ||
var _lodash = require('lodash'); | ||
var _Url2 = require('./Url'); | ||
var _Url3 = _interopRequireDefault(_Url2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -42,3 +42,4 @@ | ||
* Set the current route. | ||
* This will set the current route to either model, collection, or any to make appropriate requests | ||
* This will set the current route to either model, collection, | ||
* or any to make appropriate requests | ||
* Can also be changed by calling rapid.model.func() or rapid.collection.func() | ||
@@ -72,3 +73,3 @@ * | ||
if (this.config.routes[route] != '') { | ||
if (this.config.routes[route] !== '') { | ||
newRoute = this.config.routes[route]; | ||
@@ -75,0 +76,0 @@ } else { |
@@ -9,2 +9,4 @@ 'use strict'; | ||
var _lodash = require('lodash'); | ||
var _Core2 = require('./Core'); | ||
@@ -14,4 +16,2 @@ | ||
var _lodash = require('lodash'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -18,0 +18,0 @@ |
{ | ||
"name": "rapid.js", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "", | ||
@@ -10,3 +10,4 @@ "main": "dist/rapid.js", | ||
"copy-dev": "npm run compile && rm -rf ./demo/rapid && cp -R ./dist ./demo/rapid", | ||
"prepublish": "npm run compile" | ||
"prepublish": "npm run compile", | ||
"lint": "eslint src/**/*.js" | ||
}, | ||
@@ -39,2 +40,4 @@ "babel": { | ||
"babel-preset-es2015": "^6.24.0", | ||
"eslint": "^4.9.0", | ||
"eslint-config-airbnb-standard": "^1.5.0", | ||
"nyc": "^10.2.0", | ||
@@ -41,0 +44,0 @@ "sinon": "^2.1.0" |
@@ -88,5 +88,5 @@ /** | ||
this.routes = { | ||
model : '', | ||
collection : '', | ||
any : '' | ||
model: '', | ||
collection: '', | ||
any: '' | ||
}; | ||
@@ -110,3 +110,5 @@ } | ||
set debug (val) { | ||
if(this.config.debug) this.logger.warn('debug mode must explicitly be turned on via the constructor in config.debug'); | ||
if (this.config.debug) { | ||
this.logger.warn('debug mode must explicitly be turned on via the constructor in config.debug'); | ||
} | ||
} | ||
@@ -113,0 +115,0 @@ |
@@ -28,18 +28,18 @@ /** | ||
*/ | ||
updateOrDestroy(method, ...params) { | ||
updateOrDestroy (method, ...params) { | ||
const urlParams = []; | ||
const id = params[0]; | ||
let data = params[1]; | ||
const id = params[0]; | ||
let data = params[1]; | ||
if(Number.isInteger(id)) { | ||
if (Number.isInteger(id)) { | ||
this.id(id); | ||
} else { | ||
data = params[0]; | ||
[data] = params; | ||
} | ||
if(this.config.suffixes[method]) { | ||
if (this.config.suffixes[method]) { | ||
urlParams.push(this.config.suffixes[method]); | ||
} | ||
if(method == 'update') { | ||
if (method === 'update') { | ||
this.withParams(data); | ||
@@ -79,3 +79,4 @@ } | ||
create (data) { | ||
return this.withParams(data).buildRequest(this.config.methods.create, this.config.suffixes.create); | ||
return this.withParams(data) | ||
.buildRequest(this.config.methods.create, this.config.suffixes.create); | ||
} | ||
@@ -93,3 +94,3 @@ | ||
if(this.config.primaryKey) { | ||
if (this.config.primaryKey) { | ||
params = [this.config.primaryKey, id]; | ||
@@ -106,3 +107,2 @@ } else { | ||
/** | ||
@@ -132,3 +132,3 @@ * Collection Only Functions | ||
if(value) { | ||
if (value) { | ||
urlParams.push(value); | ||
@@ -135,0 +135,0 @@ } |
@@ -21,17 +21,17 @@ export default { | ||
suffixes: { | ||
create : 'create', | ||
update : 'update', | ||
destroy : 'destroy', | ||
create: 'create', | ||
update: 'update', | ||
destroy: 'destroy' | ||
}, | ||
methods: { | ||
create : 'post', | ||
update : 'post', | ||
destroy : 'post' | ||
create: 'post', | ||
update: 'post', | ||
destroy: 'post' | ||
}, | ||
routes: { | ||
model : '', | ||
collection : '', | ||
any : '' | ||
model: '', | ||
collection: '', | ||
any: '' | ||
}, | ||
@@ -38,0 +38,0 @@ |
/*! | ||
* Rapid.js v0.0.1 | ||
* (c) 2017 Drew J Bartlett (http://drewjbartlett.com) | ||
* Rapid.js v0.0.13 | ||
* (c) 2017 Drew J Bartlett (https://drewjbartlett.com) | ||
* Released under the MIT License. | ||
*/ | ||
/** | ||
@@ -9,0 +8,0 @@ * The inheritance of the classes |
@@ -5,4 +5,4 @@ /** | ||
import { isArray, defaultsDeep, set } from 'lodash'; | ||
import Routes from './Routes'; | ||
import { isArray, defaultsDeep } from 'lodash'; | ||
@@ -21,7 +21,7 @@ class Request extends Routes { | ||
const requestData = []; | ||
const options = this.requestData.options; | ||
let params = this.requestData.params; | ||
const { options } = this.requestData; | ||
let { params } = this.requestData; | ||
// axios handles the options differently for the request type | ||
if(['put', 'post', 'patch'].includes(type)) { | ||
if (['put', 'post', 'patch'].includes(type)) { | ||
params = defaultsDeep(params, this.config.globalParameters); | ||
@@ -47,3 +47,3 @@ requestData.push(params); | ||
if(!this.isAllowedRequestType(type)) { | ||
if (!this.isAllowedRequestType(type)) { | ||
return; | ||
@@ -54,3 +54,3 @@ } | ||
if(this.config.debug) { | ||
if (this.config.debug) { | ||
return this.debugger.fakeRequest(type, url); | ||
@@ -61,12 +61,12 @@ } | ||
this.api[type].call(this, this.sanitizeUrl(url), ...this.parseRequestData(type)) | ||
.then(response => { | ||
.then((response) => { | ||
this.afterRequest(response); | ||
resolve(response); | ||
}) | ||
.catch(error => { | ||
}) | ||
.catch((error) => { | ||
this.onError(error); | ||
reject(error); | ||
}); | ||
}); | ||
}); | ||
@@ -81,4 +81,4 @@ } | ||
isAllowedRequestType (type) { | ||
if(!this.config.allowedRequestTypes.includes(type)) { | ||
if(this.config.debug) { | ||
if (!this.config.allowedRequestTypes.includes(type)) { | ||
if (this.config.debug) { | ||
this.logger.warn(`'${type}' is not included in allowedRequestTypes: [${this.config.allowedRequestTypes.join(', ')}]`); | ||
@@ -98,3 +98,3 @@ } | ||
if(this.urlParams) { | ||
if (this.urlParams) { | ||
urlParams = this.urlParams.concat(urlParams); | ||
@@ -190,3 +190,2 @@ this.resetURLParams(); | ||
/** | ||
@@ -213,3 +212,3 @@ * Params and Options | ||
withParams (params = {}) { | ||
this.requestData.params = params; | ||
set(this.requestData, 'params', params); | ||
@@ -226,3 +225,3 @@ return this; | ||
withParam (key, value) { | ||
this.requestData.params[key] = value; | ||
set(this.requestData, `params.${key}`, value); | ||
@@ -238,3 +237,3 @@ return this; | ||
withOptions (options = {}) { | ||
this.requestData.options = options; | ||
set(this.requestData, 'options', options); | ||
@@ -251,3 +250,3 @@ return this; | ||
withOption (key, value) { | ||
this.requestData.options[key] = value; | ||
set(this.requestData, `options.${key}`, value); | ||
@@ -254,0 +253,0 @@ return this; |
@@ -5,5 +5,5 @@ /** | ||
import { kebabCase } from 'lodash'; | ||
import pluralize from 'pluralize'; | ||
import Url from './Url'; | ||
import pluralize from 'pluralize'; | ||
import { kebabCase } from 'lodash'; | ||
@@ -18,3 +18,4 @@ class Routes extends Url { | ||
* Set the current route. | ||
* This will set the current route to either model, collection, or any to make appropriate requests | ||
* This will set the current route to either model, collection, | ||
* or any to make appropriate requests | ||
* Can also be changed by calling rapid.model.func() or rapid.collection.func() | ||
@@ -36,8 +37,8 @@ * | ||
const formattedRoute = { | ||
model : this.config.modelName, | ||
collection : pluralize(this.config.modelName), | ||
any : '' | ||
model: this.config.modelName, | ||
collection: pluralize(this.config.modelName), | ||
any: '' | ||
}; | ||
if(this.config.routes[route] != '') { | ||
if (this.config.routes[route] !== '') { | ||
newRoute = this.config.routes[route]; | ||
@@ -47,3 +48,3 @@ } else { | ||
if(this.config.caseSensitive) { | ||
if (this.config.caseSensitive) { | ||
newRoute = formattedRoute[route]; | ||
@@ -50,0 +51,0 @@ } |
@@ -5,4 +5,4 @@ /** | ||
import { isArray } from 'lodash'; | ||
import Core from './Core'; | ||
import { isArray } from 'lodash'; | ||
@@ -23,3 +23,3 @@ class Url extends Core { | ||
if(this.config.trailingSlash) { | ||
if (this.config.trailingSlash) { | ||
params.push(''); | ||
@@ -32,3 +32,3 @@ } | ||
// make sure routes don't need to regenerate | ||
if(this.config.extension) { | ||
if (this.config.extension) { | ||
url += `.${this.config.extension}`; | ||
@@ -52,3 +52,3 @@ } | ||
if(!this.config.trailingSlash) { | ||
if (!this.config.trailingSlash) { | ||
url = url.replace(/\/$/, ''); | ||
@@ -73,7 +73,7 @@ } | ||
if(!isArray(urlParams)) { | ||
if (!isArray(urlParams)) { | ||
urlParams = [urlParams]; | ||
} | ||
if(overwrite) { | ||
if (overwrite) { | ||
this.urlParams = urlParams; | ||
@@ -84,3 +84,3 @@ | ||
if(prepend) { | ||
if (prepend) { | ||
this.urlParams = urlParams.concat(this.urlParams); | ||
@@ -87,0 +87,0 @@ } else { |
@@ -5,14 +5,14 @@ import qs from 'qs'; | ||
constructor (caller) { | ||
this.caller = caller; | ||
this.data = {}; | ||
this.logEnabled = true; | ||
this.caller = caller; | ||
this.data = {}; | ||
this.logEnabled = true; | ||
} | ||
fakeRequest (type, url) { | ||
const params = this.caller.parseRequestData(type); | ||
const lastUrl = this.setLastUrl(type, url, ...params); | ||
const params = this.caller.parseRequestData(type); | ||
const lastUrl = this.setLastUrl(type, url, ...params); | ||
this.setLastRequest(...arguments); | ||
if(this.logEnabled) { | ||
if (this.logEnabled) { | ||
this.caller.logger.debug(`${this.caller.config.modelName} made a ${type.toUpperCase()} request (${lastUrl})`); | ||
@@ -27,10 +27,10 @@ this.caller.logger.log(params); | ||
setLastUrl(type, url, params = {}) { | ||
setLastUrl (type, url, params = {}) { | ||
let lastUrl = ''; | ||
if(['put', 'post', 'patch'].includes(type)) { | ||
if (['put', 'post', 'patch'].includes(type)) { | ||
lastUrl = this.caller.sanitizeUrl([this.caller.config.baseURL, url].join('/')); | ||
} else { | ||
const urlParams = params.params; | ||
const stringified = urlParams ? '?' + qs.stringify(urlParams) : ''; | ||
const stringified = urlParams ? `?${qs.stringify(urlParams)}` : ''; | ||
@@ -37,0 +37,0 @@ lastUrl = this.caller.sanitizeUrl([this.caller.config.baseURL, url].join('/')) + stringified; |
class Logger { | ||
constructor (prefix) { | ||
this.prefix = prefix; | ||
this.prefix = prefix; | ||
this.firedDebugNotice = false; | ||
@@ -9,3 +9,3 @@ this.fireDebugNotice(); | ||
fireDebugNotice () { | ||
if(!this.firedDebugNotice) { | ||
if (!this.firedDebugNotice) { | ||
// this.debug('You are running Rapid in debug mode. All requests will be mimicked.'); | ||
@@ -12,0 +12,0 @@ |
1008516
42
2143
7