Comparing version 1.1.4 to 1.1.6
@@ -0,1 +1,36 @@ | ||
<a name="1.1.6"></a> | ||
## 1.1.6 (2017-02-03) | ||
### fix | ||
* fix(resource): Entries not being properly returned when parameters are present. | ||
([3630d14](https://github.com/rymizuki/node-hariko/commit/3630d14)) | ||
### refactor | ||
* refactor(entry): format code style | ||
([95c07c8](https://github.com/rymizuki/node-hariko/commit/95c07c8)) | ||
* refactor(test): format code style | ||
([956f1fd](https://github.com/rymizuki/node-hariko/commit/956f1fd)) | ||
* refactor(test): format quotes | ||
([4aed282](https://github.com/rymizuki/node-hariko/commit/4aed282)) | ||
* refactor(test): include semicolon | ||
([074bfe4](https://github.com/rymizuki/node-hariko/commit/074bfe4)) | ||
* refactor(test): invoking a constructor | ||
([641a339](https://github.com/rymizuki/node-hariko/commit/641a339)) | ||
* 1.1.5 | ||
([be0df42](https://github.com/rymizuki/node-hariko/commit/be0df42)) | ||
* Merge pull request #9 from rymizuki/fix_extra_query_entry | ||
([de2f5c4](https://github.com/rymizuki/node-hariko/commit/de2f5c4)) | ||
<a name="1.1.5"></a> | ||
## 1.1.5 (2017-02-03) | ||
<a name="1.1.4"></a> | ||
@@ -2,0 +37,0 @@ ## 1.1.4 (2017-02-01) |
var fs = require('fs'), | ||
_ = require('lodash'), | ||
gaze = require('gaze'), | ||
pathToRegexp = require('path-to-regexp'); | ||
gaze = require('gaze'); | ||
var parser = require('./resource/parser'), | ||
external = require('./resource/external'), | ||
logger = require('../logger'); | ||
var Entries = require('./entries'); | ||
@@ -14,4 +14,4 @@ var DEFAULT_OUTPUT_DESTINATION = '.hariko-cache'; | ||
this.options = options || {}; | ||
this._data = {}; | ||
this.warnings = []; | ||
this.entries = new Entries(); | ||
this.watcher = null; | ||
@@ -30,5 +30,5 @@ if (this.options.output !== undefined && this.options.output !== null) { | ||
var data = this._parse(this._loadFile()); | ||
this._data = data.entries; | ||
this.entries.ensure(data.entries); | ||
this._warnings = data.warnings; | ||
if (this.options.output) external.save(this.options.output, this._data); | ||
if (this.options.output) external.save(this.options.output, this.entries.raw()); | ||
}, | ||
@@ -60,3 +60,3 @@ watch: function (cb) { | ||
getEntry: function (req) { | ||
var entry = this._getEntry(req); | ||
var entry = this.entries.get(req); | ||
if (entry && this.options.output) { | ||
@@ -70,48 +70,2 @@ entry.response.data = external.read(this.options.output, entry); | ||
}, | ||
_getEntry: function (req) { | ||
var resources = []; | ||
for (var i = 0; i < this._data.length; i++) { | ||
var entry = this._data[i]; | ||
var regex = pathToRegexp(entry.request.uri.path); | ||
if (req.method === entry.request.method && regex.exec(req.path)) | ||
resources.push(entry); | ||
} | ||
if (!resources || resources.length <= 0) return; | ||
var params = Object.keys(req.query); | ||
if (params.length === 0) { | ||
resources = _.chain(resources).sortBy(function (resource) { | ||
return resource.request.uri.queries.length; | ||
}).value(); | ||
} else { | ||
logger.debug('request', req.path, req.query); | ||
logger.debug('entries', _.map(resources, function (entry) { return entry.request.uri.queries; })); | ||
var perfectMatchResources = _.select(resources, function (resource) { | ||
var queries = resource.request.uri.queries; | ||
if ('object' !== typeof queries[0]) return false; | ||
for (var i = 0; i < queries.length; i++) { | ||
var query = queries[i]; | ||
if (!req.query[query.name]) return false; | ||
if (req.query[query.name] != query.value) return false; | ||
} | ||
return true; | ||
}); | ||
if (perfectMatchResources.length > 0) { | ||
resources = perfectMatchResources; | ||
} | ||
resources = _.chain(resources) | ||
.reverse() | ||
.sortBy(resources, function (resource) { | ||
return _.chain(resource.request.uri.queries) | ||
.select(function (query) { | ||
return params.indexOf(query) > -1; | ||
}) | ||
.size(); | ||
}) | ||
.value(); | ||
} | ||
return resources.shift(); | ||
} | ||
}; | ||
@@ -118,0 +72,0 @@ |
{ | ||
"name": "hariko", | ||
"version": "1.1.4", | ||
"version": "1.1.6", | ||
"description": "Mock Server that implements the API Blueprint specification.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -58,5 +58,5 @@ var expect = require('expect.js'), | ||
describe('when parse successful', function () { | ||
it('should be return data', function () { | ||
it('should be has entries', function () { | ||
resource.read(); | ||
expect(resource._data).to.be.eql([ | ||
expect(resource.entries.raw()).to.be.eql([ | ||
{ | ||
@@ -63,0 +63,0 @@ "file": "api/app-GET.json", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84746
48
2252