Comparing version 2.0.2 to 2.0.3
70
index.js
@@ -1,9 +0,11 @@ | ||
const request = require('request') | ||
const parallel = require('run-parallel-limit') | ||
const flatten = require('flatten') | ||
var request = require('request') | ||
var parallel = require('run-parallel-limit') | ||
var flatten = require('flatten') | ||
module.exports = agsWalk | ||
/** | ||
* A module to walk the folders of an ArcGIS Server Rest API | ||
* and return all the services | ||
* @name ags-walk | ||
* Walk the folders of an ArcGIS Server Rest API | ||
* and return all the services as an array | ||
* @name agsWalk | ||
* @param {string} url the base url of an ArcGIS Server Rest API | ||
@@ -23,3 +25,3 @@ * @param {Object} [opts] options for the module | ||
*/ | ||
module.exports = function (url, opts, cb) { | ||
function agsWalk (url, opts, cb) { | ||
if (typeof opts === 'function') { | ||
@@ -29,27 +31,31 @@ cb = opts | ||
} | ||
const limit = opts.limit || 5 | ||
const services = this.services = [] | ||
var limit = opts.limit || 5 | ||
var services = (this.services = []) | ||
try { | ||
request.get({ | ||
url: url + '?f=json', | ||
json: true | ||
}, function (err, res, data) { | ||
if (err) return cb(err) | ||
if (res.statusCode === 404) { | ||
return cb(res.statusMessage || 'Not Found') | ||
request.get( | ||
{ | ||
url: url + '?f=json', | ||
json: true | ||
}, | ||
function (err, res, data) { | ||
if (err) return cb(err) | ||
if (res.statusCode === 404) { | ||
return cb(res.statusMessage || 'Not Found') | ||
} | ||
if (!_isAgs(data)) { | ||
return cb('Is not a valid ArcGIS Server URL') | ||
} | ||
services.push(data.services) | ||
var harvester = _harvestFolders(url, data.folders) | ||
parallel(harvester, limit, function (err, res) { | ||
if (err) throw err | ||
services.push( | ||
res.map(function (folder) { | ||
return folder.services | ||
}) | ||
) | ||
cb(null, flatten(services)) | ||
}) | ||
} | ||
if (!_isAgs(data)) { | ||
return cb('Is not a valid ArcGIS Server URL') | ||
} | ||
services.push(data.services) | ||
const harvester = _harvestFolders(url, data.folders) | ||
parallel(harvester, limit, function (err, res) { | ||
if (err) throw err | ||
services.push(res.map(function (folder) { | ||
return folder.services | ||
})) | ||
cb(null, flatten(services)) | ||
}) | ||
}) | ||
) | ||
} catch (err) { | ||
@@ -78,5 +84,5 @@ return cb(err) | ||
if (folders) { | ||
const tasks = folders.map(function (folder) { | ||
var tasks = folders.map(function (folder) { | ||
return function (cb) { | ||
const opts = { | ||
var opts = { | ||
url: baseUrl + '/' + folder + '?f=json', | ||
@@ -83,0 +89,0 @@ json: true |
{ | ||
"name": "ags-walk", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Walks an ArcGIS Server Rest API and returns all services", | ||
"main": "index.js", | ||
"browser": { | ||
"request": "xhr" | ||
}, | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "tape test.js", | ||
"build-docs": "documentation readme index.js --section=api", | ||
"build-min": "browserify --standalone agsWalk | uglifyjs -cm > agsWalk.min.js", | ||
"preversion": "npm test", | ||
"version": "npm run build-docs && npm run build-min", | ||
"postversion": "git push && git push --tags" | ||
}, | ||
@@ -20,7 +28,11 @@ "keywords": [ | ||
"request": "^2.79.0", | ||
"run-parallel-limit": "^1.0.3" | ||
"run-parallel-limit": "^1.0.3", | ||
"xhr": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.6.3" | ||
"browserify": "^14.5.0", | ||
"documentation": "^5.3.3", | ||
"tape": "^4.6.3", | ||
"uglify-js": "^3.1.5" | ||
} | ||
} |
@@ -0,7 +1,31 @@ | ||
# ags-walk | ||
Walk the folders of an ArcGIS Server Rest API and return all the services as an | ||
array | ||
## about | ||
[ArcGIS Server](http://server.arcgis.com) is GIS software used by many federal, state, and municipal governments and organizations to publish web-enabled GIS data. ArcGIS Server uses the [GeoServices API](https://geoservices.github.io/). This module walks the services and folders of the root GeoServices API for a given URL and returns all services and service types in an array. This could be used to create a repository of dataset names from one or more ArcGIS Server REST URLs. | ||
Links to each dataset URL can be made by concatenating the root GeoServices URL with the dataset item and dataset type. For example, if the root URL is `http://sampleserver6.arcgisonline.com/arcgis/rest/services` and one of the datasets in the array is `{ name: '911CallsHotspot', type: 'MapServer' }` the full URL to the service is `http://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/MapServer`. | ||
## install | ||
For Node.js: | ||
`npm i ags-walk` | ||
and | ||
`var agsWalk = require('ags-walk')` | ||
For the browser include the tag: | ||
`<script src="https://unpkg.com/ags-walk/ags-walk.min.js"></script>` | ||
and `agsWalk()` is added as a global function. | ||
## api | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
# ags-walk | ||
### agsWalk | ||
A module to walk the folders of an ArcGIS Server Rest API | ||
and return all the services | ||
Walk the folders of an ArcGIS Server Rest API | ||
and return all the services as an array | ||
@@ -11,4 +35,4 @@ **Parameters** | ||
- `url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the base url of an ArcGIS Server Rest API | ||
- `opts` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** options for the module | ||
- `opts.limit` **\[[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** the maximum number of folders to | ||
- `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** options for the module | ||
- `opts.limit` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the maximum number of folders to | ||
index at the same time (optional, default `5`) | ||
@@ -29,1 +53,11 @@ - `cb` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** the callback function to run after | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** | ||
## license | ||
Copyright 2017 Nick Peihl | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
<http://www.apache.org/licenses/LICENSE-2.0> | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
@@ -0,0 +0,0 @@ const test = require('tape') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
73755
16
633
62
4
4
2
+ Addedxhr@^2.4.0
+ Addeddom-walk@0.1.2(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedis-function@1.0.2(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addedparse-headers@2.0.5(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedxhr@2.6.0(transitive)
+ Addedxtend@4.0.2(transitive)