New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

featureservice

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

featureservice - npm Package Compare versions

Comparing version

to
0.0.2

dist/featureservice.min.js

12

CHANGELOG.md

@@ -5,7 +5,17 @@ # Change Log

## [0.0.1] - 2015-07-09
## [0.0.2] - 2015-07-27
### Added
* A method for making statistics calls to a service
* Support for using the module in the browser
### Changed
* http requests are all routed through the core http/https libs now
## [0.0.1] - 2015-07-22
### Added
* Code for requesting data from FeatureServices
* Tests on most methods
[0.0.2]: https://github.com/chelm/featureservice/ompare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/chelm/featureservice/releases/tag/v0.0.1

105

index.js
// A module designed to talk to feature services and get every feature
// this code will expose methods for getting the URL to each page
var request = require('request')
var async = require('async')
// var request = require('browser-request')
var queue = require('async').queue
var http = require('http')
var https = require('https')
var zlib = require('zlib')
var url = require('url')
var urlUtils = require('url')
// easy reference to a protocol type
var protocols = {
http: http,
https: https
}
/**

@@ -37,6 +32,12 @@ * A feature service object needs a url and some optional params to make requests

// an async for requesting pages of data
this.pageQueue = async.queue(function (task, callback) {
this.pageQueue = queue(function (task, callback) {
this._requestFeatures(task, callback)
}.bind(this), (this.url.split('//')[1].match(/^service/)) ? 16 : 4)
// easy reference to a protocol type
this.protocols = {
http: http,
https: https
}
return this

@@ -51,3 +52,41 @@ }

FeatureService.prototype.request = function (url, callback) {
request.get(url, callback)
var uri = urlUtils.parse(encodeURI(decodeURI(url)))
var opts = {
method: 'GET',
port: (uri.protocol === 'https:') ? 443 : uri.port || 80,
hostname: uri.hostname,
path: uri.path,
headers: {
'User-Agent': 'featureservices-node'
}
}
// make an http or https request based on the protocol
var req = ((uri.protocol === 'https:') ? this.protocols.https : this.protocols.http).request(opts, function (response) {
var data = []
response.on('data', function (chunk) {
data.push(chunk)
})
response.on('error', function (err) {
callback(err)
})
response.on('end', function () {
var buffer = Buffer.concat(data)
try {
callback(null, JSON.parse(buffer.toString()))
} catch (e) {
callback(e)
}
})
})
req.on('error', function (error) {
callback(error)
})
req.end()
}

@@ -78,2 +117,11 @@

* Gets the feature service info
* @param {string} field - the name of a field to build a stat request for
* @param {array} stats - an array of stats to request: ['min', 'max', 'avg', 'stddev', 'count']
*/
FeatureService.prototype.statistics = function (field, stats, callback) {
this.request(this._statsUrl(field, stats), callback)
}
/**
* Gets the feature service info
* @param {function} callback - called when the service info comes back

@@ -83,5 +131,4 @@ */

var url = this.url + '/' + this.layer + '?f=json'
this.request(url, function (err, res) {
this.request(url, function (err, json) {
try {
var json = JSON.parse(res.body)
json.url = url

@@ -100,4 +147,3 @@ } catch (e) {

FeatureService.prototype.layerIds = function (callback) {
this.request(this.url + '/' + this.layer + '/query?where=1=1&returnIdsOnly=true&f=json', function (err, res) {
var json = JSON.parse(res.body)
this.request(this.url + '/' + this.layer + '/query?where=1=1&returnIdsOnly=true&f=json', function (err, json) {
callback(err, json.objectIds)

@@ -140,5 +186,4 @@ })

if (serviceInfo.supportsStatistics) {
var statsUrl = this._statsUrl(serviceInfo.objectIdField)
this.request(statsUrl, function (err, res) {
this.request(this._statsUrl(serviceInfo.objectIdField), function (err, res) {
if (err) {

@@ -152,5 +197,4 @@ return callback(err)

try {
// DMF: if stats fail, try to grab all the object IDs
var idUrl = this.url + '/' + (this.layer || 0) + '/query?where=1=1&returnIdsOnly=true&f=json'
this.request(idUrl, function (err, res) {
this.request(idUrl, function (err, idJson) {
if (err) {

@@ -160,3 +204,2 @@ return callback(err)

var idJson = JSON.parse(res.body)
var minID, maxID

@@ -216,3 +259,3 @@ if (idJson.error) {

this.request(countUrl, function (err, response) {
this.request(countUrl, function (err, json) {
if (err) {

@@ -222,13 +265,2 @@ return callback(err)

if (!response || !response.body) {
return callback('Unknown layer, make sure the layer you requested exists')
}
var json
try {
json = JSON.parse(response.body)
} catch (e) {
json = { error: e }
}
if (json.error) {

@@ -238,3 +270,3 @@ return callback(json.error.message + ': ' + countUrl, null)

callback(null, json.count)
callback(null, json)
})

@@ -277,3 +309,2 @@ }

url = this.url
var objId = this.options.objectIdField || 'objectId'

@@ -286,3 +317,3 @@ var pages = (ids.length / maxCount)

where = objId + ' in (' + pageIds.join(',') + ')'
pageUrl = url + '/' + (this.options.layer || 0) + '/query?outSR=4326&where=' + where + '&f=json&outFields=*'
pageUrl = this.url + '/' + (this.options.layer || 0) + '/query?outSR=4326&where=' + where + '&f=json&outFields=*'
pageUrl += '&geometry=&returnGeometry=true&geometryPrecision=10'

@@ -354,3 +385,3 @@ reqs.push({req: pageUrl})

try {
var url_parts = url.parse(uri)
var url_parts = urlUtils.parse(uri)

@@ -369,3 +400,3 @@ var opts = {

// make an http or https request based on the protocol
var req = ((url_parts.protocol === 'https:') ? protocols.https : protocols.http).request(opts, function (response) {
var req = ((url_parts.protocol === 'https:') ? this.protocols.https : this.protocols.http).request(opts, function (response) {
var data = []

@@ -372,0 +403,0 @@ response.on('data', function (chunk) {

{
"name": "featureservice",
"description": "a node module meant to extract every feature from an Esri geo-service thing",
"version": "0.0.1",
"version": "0.0.2",
"author": "Chris Helm",

@@ -14,6 +14,11 @@ "bugs": {

"devDependencies": {
"browserify": "^11.0.0",
"http-browserify": "^1.7.0",
"https-browserify": "0.0.0",
"minifyify": "^7.0.3",
"sinon": "^1.15.4",
"standard": "^4.5.4",
"tap-spec": "^4.0.2",
"tape": "^4.0.1"
"tape": "^4.0.1",
"zlib-browserify": "0.0.3"
},

@@ -33,4 +38,5 @@ "homepage": "https://github.com/chelm/featureservice",

"scripts": {
"test": "standard && tape test/*.js | tap-spec"
"test": "standard index.js && tape test/*.js | tap-spec",
"build": "browserify -d index.js -s FeatureService -p [minifyify --map featureservice.map.json --output featureservice.map.json] > dist/featureservice.min.js"
}
}

@@ -24,2 +24,21 @@ # featureservice

### layerIds(callback)
Get all the ids in a feature service layer
### layerInfo(callback)
Get the json metadata for a service layer
### statistics(field, stats, callback)
Get statistics for a field and an array of stats.
```javascript
service.statistics('id', ['min', 'max'], function (err, stats) {
console.log(stats.features)
})
```
### pages(callback)
Returns an array of page urls that would get every feature in the service
## Todo

@@ -26,0 +45,0 @@