featureservice
Advanced tools
Comparing version 1.4.2 to 1.4.3
@@ -5,2 +5,8 @@ # Change Log | ||
## [1.4.3] - 2015-01-04 | ||
### Changed | ||
* Concurrency is throttled when encountering errors in the paging queue | ||
### Fixed | ||
* Urls and Layers are parsed correctly on service init | ||
## [1.4.2] - 2015-10-13 | ||
@@ -16,3 +22,3 @@ ### Changed | ||
### Added | ||
* Backoff time for failed requests can now be set as an option | ||
* Backoff time for failed requests can now be set as an option | ||
* `service.info` returns information about the feature or map service | ||
@@ -33,3 +39,3 @@ | ||
### Added | ||
* Allow a logger to be passed in through options.logger when initializing a new service | ||
* Allow a logger to be passed in through options.logger when initializing a new service | ||
@@ -46,3 +52,3 @@ ### Fixed | ||
## [1.2.6] - 2015-09-02 | ||
## [1.2.6] - 2015-09-02 | ||
### Fixed | ||
@@ -158,2 +164,3 @@ * Don't set a layer id with a query string | ||
[1.4.2]: https://github.com/koopjs/featureservice/compare/v1.4.2...v1.4.3 | ||
[1.4.2]: https://github.com/koopjs/featureservice/compare/v1.4.1...v1.4.2 | ||
@@ -181,2 +188,1 @@ [1.4.1]: https://github.com/koopjs/featureservice/compare/v1.4.0...v1.4.1 | ||
[0.0.1]: https://github.com/koopjs/featureservice/releases/tag/v0.0.1 | ||
38
index.js
@@ -21,18 +21,4 @@ var queue = require('async').queue | ||
} | ||
// check the last char on the url | ||
// protects us from urls registered with layers already in the url | ||
var end = url.split('/').pop().split('?')[0] | ||
var layer | ||
if (parseInt(end, 10) >= 0) { | ||
// protect against layers coming in with query strings | ||
layer = end | ||
var len = ('' + layer).length | ||
// protect against urls with query strings | ||
// TODO clean up this confusing logic | ||
url = url.split('?')[0] | ||
url = url.substring(0, url.length - ((len || 2) + 1)) | ||
} | ||
this.url = url.split('?')[0] | ||
var service = parseUrl(url) | ||
this.url = service.url | ||
this.options = options || {} | ||
@@ -44,3 +30,3 @@ this.options.size = this.options.size || 5000 | ||
this.layer = layer || this.options.layer || 0 | ||
this.layer = service.layer || this.options.layer || 0 | ||
this.logger = this.options.logger | ||
@@ -54,2 +40,10 @@ | ||
function parseUrl (url) { | ||
var layer = url.match(/(?:.+\/(?:feature|map)server\/)(\d+)/i) | ||
return { | ||
layer: layer && layer[1] ? layer[1] : undefined, | ||
url: url.match(/.+\/(feature|map)server/i)[0] | ||
} | ||
} | ||
/** | ||
@@ -590,3 +584,3 @@ * Wraps logging functionality so a logger can be passed in | ||
response = buffer.toString() | ||
parsed = JSON.parse(response.replace(/NaN/g, null)) | ||
parsed = JSON.parse(response.replace(/NaN/g, '')) | ||
} catch (e) { | ||
@@ -623,2 +617,5 @@ // sometimes we get html or plain strings back | ||
// dial back concurrency if we start hitting errors | ||
throttleQueue() | ||
this.log('info', 'Re-requesting page ' + task.req + ' attempt ' + task.retry) | ||
@@ -629,2 +626,7 @@ | ||
}.bind(this), task.retry * this.options.backoff) | ||
function throttleQueue () { | ||
var concurrency = this.pageQueue.concurrency / 2 | ||
this.pageQueue.concurrency = concurrency > 1 ? Math.ceil(concurrency) : 1 | ||
} | ||
} | ||
@@ -631,0 +633,0 @@ |
{ | ||
"name": "featureservice", | ||
"description": "Get all features from an Esri Feature Service", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"author": "Chris Helm", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -24,2 +24,9 @@ var sinon = require('sinon') | ||
test('create a service when the url has a trailing slash', function (t) { | ||
var serv = new FeatureService('http://koop.whatava.com/FeatureServer/0/', {layer: 0}) | ||
t.equal(serv.layer.toString(), '0') | ||
t.equal(serv.url, 'http://koop.whatava.com/FeatureServer') | ||
t.end() | ||
}) | ||
test('get the objectId', function (t) { | ||
@@ -441,4 +448,4 @@ var oid = service.getObjectIdField(layerInfo) | ||
test('service times out on third try for features', function (t) { | ||
var service = new FeatureService('http://www.foobar.com', {timeOut: 5}) | ||
nock('http://www.foobar.com').get('/').socketDelay(100).reply({}.toString()) | ||
var service = new FeatureService('http://www.foobar.com/FeatureServer', {timeOut: 5, layer: 0}) | ||
nock('http://www.foobar.com').get('/FeatureServer/0/query?where=1=1').socketDelay(100).reply({}.toString()) | ||
sinon.stub(service, '_abortPaging', function (err, callback) { | ||
@@ -450,7 +457,7 @@ callback(err) | ||
retry: 3, | ||
req: 'http://www.foobar.com/' | ||
req: 'http://www.foobar.com/FeatureServer/0/query?where=1=1' | ||
} | ||
service._requestFeatures(task, function (err) { | ||
t.equal(err.code, 504) | ||
t.equal(err.url, 'http://www.foobar.com/') | ||
t.equal(err.url, 'http://www.foobar.com/FeatureServer/0/query?where=1=1') | ||
t.end() | ||
@@ -506,2 +513,1 @@ }) | ||
}) | ||
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
1267329
30
1765