From 3edde1b22ed98c6cc8d5f7a1de92f3f57662898f Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Sat, 17 Feb 2018 23:26:09 -0800 Subject: [PATCH 1/9] New arcgis-rest-features package w/ `getFeature()` to get a feature by id --- CHANGELOG.md | 6 ++ .../arcgis-rest-feature-service/README.md | 63 +++++++++++++++++++ .../arcgis-rest-feature-service/package.json | 47 ++++++++++++++ .../src/features.ts | 34 ++++++++++ .../arcgis-rest-feature-service/src/index.ts | 1 + .../test/features.test.ts | 23 +++++++ .../test/mocks/feature.ts | 13 ++++ .../arcgis-rest-feature-service/tsconfig.json | 6 ++ 8 files changed, 193 insertions(+) create mode 100644 packages/arcgis-rest-feature-service/README.md create mode 100644 packages/arcgis-rest-feature-service/package.json create mode 100644 packages/arcgis-rest-feature-service/src/features.ts create mode 100644 packages/arcgis-rest-feature-service/src/index.ts create mode 100644 packages/arcgis-rest-feature-service/test/features.test.ts create mode 100644 packages/arcgis-rest-feature-service/test/mocks/feature.ts create mode 100644 packages/arcgis-rest-feature-service/tsconfig.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 385c3abf82..8e5f6d4506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Unreleased Changes + +### Added + +* New arcgis-rest-feature-service package w/ `getFeature()` to get a feature by id + ## [1.0.2] - December 21st 2017 ### Other Changes diff --git a/packages/arcgis-rest-feature-service/README.md b/packages/arcgis-rest-feature-service/README.md new file mode 100644 index 0000000000..0f35b2f106 --- /dev/null +++ b/packages/arcgis-rest-feature-service/README.md @@ -0,0 +1,63 @@ +[![npm version][npm-img]][npm-url] +[![build status][travis-img]][travis-url] +[![apache licensed](https://img.shields.io/badge/license-Apache-green.svg?style=flat-square)](https://raw.githubusercontent.com/Esri/arcgis-rest-js/master/LICENSE) + +[npm-img]: https://img.shields.io/npm/v/@esri/arcgis-rest-feature-service.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-feature-service +[travis-img]: https://img.shields.io/travis/Esri/arcgis-rest-js/master.svg?style=flat-square +[travis-url]: https://travis-ci.org/Esri/arcgis-rest-js + +# @esri/arcgis-rest-feature-service + +> A module for working with ArcGIS feature services that runs in Node.js and modern browsers. + +### Example + +```bash +npm install @esri/arcgis-rest-feature-service +``` + +```js +import { getFeature } from '@esri/arcgis-rest-feature-service'; + +const serviceUrl = "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"; + +getFeature(serviceUrl, 42) + .then(feature => { + console.log(feature.attributes.FID); // 42 + }); +``` + +### Issues + +If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first. Have you found a new bug? Want to request a new feature? We'd [**love**](https://github.com/Esri/arcgis-rest-js/issues/new) to hear from you. + +If you're looking for help you can also post issues on [GIS Stackexchange](http://gis.stackexchange.com/questions/ask?tags=esri-oss). + +### Versioning + +For transparency into the release cycle and in striving to maintain backward compatibility, @esri/arcgis-rest-js is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible. + +For more information on SemVer, please visit . + +### Contributing + +Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](CONTRIBUTING.md). + +### License + +Copyright 2017 Esri + +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. + +A copy of the license is available in the repository's [LICENSE](./LICENSE) file. diff --git a/packages/arcgis-rest-feature-service/package.json b/packages/arcgis-rest-feature-service/package.json new file mode 100644 index 0000000000..39cdb231f3 --- /dev/null +++ b/packages/arcgis-rest-feature-service/package.json @@ -0,0 +1,47 @@ +{ + "name": "@esri/arcgis-rest-feature-service", + "version": "1.0.2", + "description": "Feature service helpers for @esri/arcgis-rest-request", + "main": "dist/node/index.js", + "browser": "dist/umd/arcgis-rest-feature-service.umd.js", + "module": "dist/esm/index.js", + "js:next": "dist/esm/index.js", + "types": "dist/esm/index.d.ts", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^1.7.1" + }, + "peerDependencies": { + "@esri/arcgis-rest-common-types": "^1.0.2", + "@esri/arcgis-rest-request": "^1.0.2" + }, + "devDependencies": { + "@esri/arcgis-rest-common-types": "^1.0.2", + "@esri/arcgis-rest-request": "^1.0.2" + }, + "scripts": { + "prepare": "npm run build", + "build": "npm run build:node && npm run build:umd && npm run build:esm", + "build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration", + "build:umd": "rollup -c ../../rollup.config.umd.js", + "build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node" + }, + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Esri/arcgis-rest-js.git" + }, + "contributors": [ + { + "name": "Tom Wayson", + "email": "twayson@esri.com", + "url": "http://tomwayson.com/" + } + ], + "bugs": { + "url": "https://github.com/Esri/arcgis-rest-js/issues" + }, + "homepage": "https://github.com/Esri/arcgis-rest-js#readme" +} diff --git a/packages/arcgis-rest-feature-service/src/features.ts b/packages/arcgis-rest-feature-service/src/features.ts new file mode 100644 index 0000000000..62cd1d5ca5 --- /dev/null +++ b/packages/arcgis-rest-feature-service/src/features.ts @@ -0,0 +1,34 @@ +/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. + * Apache-2.0 */ +import { request, IRequestOptions } from "@esri/arcgis-rest-request"; + +/** + * Feature - TODO: move this to common types? + */ +export interface IFeature { + attributes: { [key: string]: any }; + geometry: any; +} + +/** + * Get an feature by id + * + * @param serviceUrl - service url + * @param id - feature id + * @param requestOptions - Options for the request + * @returns A Promise that will resolve with the feature. + */ +export function getFeature( + serviceUrl: string, + id: number, + requestOptions?: IRequestOptions +): Promise { + const url = `${serviceUrl}/${id}`; + + // default to a GET request + const options: IRequestOptions = { + ...{ httpMethod: "GET" }, + ...requestOptions + }; + return request(url, options).then(response => response.feature); +} diff --git a/packages/arcgis-rest-feature-service/src/index.ts b/packages/arcgis-rest-feature-service/src/index.ts new file mode 100644 index 0000000000..0e849261ac --- /dev/null +++ b/packages/arcgis-rest-feature-service/src/index.ts @@ -0,0 +1 @@ +export * from "./features"; diff --git a/packages/arcgis-rest-feature-service/test/features.test.ts b/packages/arcgis-rest-feature-service/test/features.test.ts new file mode 100644 index 0000000000..e6f199eca3 --- /dev/null +++ b/packages/arcgis-rest-feature-service/test/features.test.ts @@ -0,0 +1,23 @@ +import { getFeature } from "../src/index"; + +import * as fetchMock from "fetch-mock"; + +import { featureResponse } from "./mocks/feature"; + +describe("feature", () => { + afterEach(fetchMock.restore); + + it("should return a feature by id", done => { + const layerUrl = + "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"; + fetchMock.once("*", featureResponse); + getFeature(layerUrl, 42).then(response => { + expect(fetchMock.called()).toBeTruthy(); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual(`${layerUrl}/42?f=json`); + expect(options.method).toBe("GET"); + expect(response.attributes.FID).toEqual(42); + done(); + }); + }); +}); diff --git a/packages/arcgis-rest-feature-service/test/mocks/feature.ts b/packages/arcgis-rest-feature-service/test/mocks/feature.ts new file mode 100644 index 0000000000..50c5f18643 --- /dev/null +++ b/packages/arcgis-rest-feature-service/test/mocks/feature.ts @@ -0,0 +1,13 @@ +import { IFeature } from "../../src/features"; + +export const featureResponse = { + feature: { + attributes: { + FID: 42 + }, + geometry: { + x: -9177311.62541634, + y: 4247151.205222242 + } + } +}; diff --git a/packages/arcgis-rest-feature-service/tsconfig.json b/packages/arcgis-rest-feature-service/tsconfig.json new file mode 100644 index 0000000000..400168ea91 --- /dev/null +++ b/packages/arcgis-rest-feature-service/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "src/**/*.ts" + ] +} \ No newline at end of file From 429f982f68b3405211b09da2ebf74fb3c4d3894f Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Sun, 18 Feb 2018 08:49:50 -0800 Subject: [PATCH 2/9] revert manual update of changelog --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e5f6d4506..385c3abf82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## Unreleased Changes - -### Added - -* New arcgis-rest-feature-service package w/ `getFeature()` to get a feature by id - ## [1.0.2] - December 21st 2017 ### Other Changes From 0747a8f8cc0bcaf025f2751656ca92d46cf6f1bf Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Sun, 18 Feb 2018 08:56:50 -0800 Subject: [PATCH 3/9] add link from root README to arcgis-rest-feature-service README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 15049061b7..eac92c690e 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Some useful commands include: * [`@esri/arcgis-rest-geocoder`](./packages/arcgis-rest-geocoder) - Geocoding wrapper for `@esri/arcgis-rest-js` * [`@esri/arcgis-rest-items`](./packages/arcgis-rest-items) - Methods for working with ArcGIS Online/Enterprise content. * [`@esri/arcgis-rest-groups`](./packages/arcgis-rest-groups) - Methods for working with ArcGIS Online/Enterprise groups. +* [`@esri/arcgis-rest-feature-service`](./packages/arcgis-rest-feature-service) - Functions for working with feature services * [`@esri/arcgis-rest-common-types`](./packages/arcgis-rest-common-types) - Stores objects common across the ArcGIS API. ### Frequently Asked Questions From 30d0d24d7caa3181622355d707e03f19da9d0280 Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Sun, 18 Feb 2018 20:36:25 -0800 Subject: [PATCH 4/9] getFeature takes only IFeatureRequestOptions, which extends IRequestOptions --- .../arcgis-rest-feature-service/README.md | 8 +++++-- .../src/features.ts | 23 ++++++++++++------- .../test/features.test.ts | 11 +++++---- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/arcgis-rest-feature-service/README.md b/packages/arcgis-rest-feature-service/README.md index 0f35b2f106..a985d86fc5 100644 --- a/packages/arcgis-rest-feature-service/README.md +++ b/packages/arcgis-rest-feature-service/README.md @@ -20,9 +20,13 @@ npm install @esri/arcgis-rest-feature-service ```js import { getFeature } from '@esri/arcgis-rest-feature-service'; -const serviceUrl = "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"; +const params = { + url: + "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0", + id: 42 +}; -getFeature(serviceUrl, 42) +getFeature(params) .then(feature => { console.log(feature.attributes.FID); // 42 }); diff --git a/packages/arcgis-rest-feature-service/src/features.ts b/packages/arcgis-rest-feature-service/src/features.ts index 62cd1d5ca5..1f3f034be9 100644 --- a/packages/arcgis-rest-feature-service/src/features.ts +++ b/packages/arcgis-rest-feature-service/src/features.ts @@ -11,24 +11,31 @@ export interface IFeature { } /** - * Get an feature by id + * parameters required to get a feature by id * - * @param serviceUrl - service url + * @param url - layer service url * @param id - feature id + */ +export interface IFeatureRequestOptions extends IRequestOptions { + url: string; + id: number; +} + +/** + * Get an feature by id + * * @param requestOptions - Options for the request * @returns A Promise that will resolve with the feature. */ export function getFeature( - serviceUrl: string, - id: number, - requestOptions?: IRequestOptions + requestOptions: IFeatureRequestOptions ): Promise { - const url = `${serviceUrl}/${id}`; + const url = `${requestOptions.url}/${requestOptions.id}`; // default to a GET request - const options: IRequestOptions = { + const options: IFeatureRequestOptions = { ...{ httpMethod: "GET" }, ...requestOptions }; - return request(url, options).then(response => response.feature); + return request(url, options).then((response: any) => response.feature); } diff --git a/packages/arcgis-rest-feature-service/test/features.test.ts b/packages/arcgis-rest-feature-service/test/features.test.ts index e6f199eca3..1a231e5de5 100644 --- a/packages/arcgis-rest-feature-service/test/features.test.ts +++ b/packages/arcgis-rest-feature-service/test/features.test.ts @@ -8,13 +8,16 @@ describe("feature", () => { afterEach(fetchMock.restore); it("should return a feature by id", done => { - const layerUrl = - "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"; + const params = { + url: + "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0", + id: 42 + }; fetchMock.once("*", featureResponse); - getFeature(layerUrl, 42).then(response => { + getFeature(params).then(response => { expect(fetchMock.called()).toBeTruthy(); const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); - expect(url).toEqual(`${layerUrl}/42?f=json`); + expect(url).toEqual(`${params.url}/42?f=json`); expect(options.method).toBe("GET"); expect(response.attributes.FID).toEqual(42); done(); From 868816e6329a6b2b4ec2a88f4659278234ab4c84 Mon Sep 17 00:00:00 2001 From: Noah Mulfinger Date: Thu, 22 Feb 2018 10:57:33 -0800 Subject: [PATCH 5/9] Add package-lock.json --- .../arcgis-rest-feature-service/package-lock.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 packages/arcgis-rest-feature-service/package-lock.json diff --git a/packages/arcgis-rest-feature-service/package-lock.json b/packages/arcgis-rest-feature-service/package-lock.json new file mode 100644 index 0000000000..ee751b102c --- /dev/null +++ b/packages/arcgis-rest-feature-service/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "tslib": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.8.0.tgz", + "integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==" + } + } +} From 780f6d18d54e72968c040df1fc3a269572b82415 Mon Sep 17 00:00:00 2001 From: Noah Mulfinger Date: Thu, 22 Feb 2018 11:04:19 -0800 Subject: [PATCH 6/9] Fix wrong package-lock sha --- packages/arcgis-rest-feature-service/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/arcgis-rest-feature-service/package-lock.json b/packages/arcgis-rest-feature-service/package-lock.json index ee751b102c..ffb34e1f41 100644 --- a/packages/arcgis-rest-feature-service/package-lock.json +++ b/packages/arcgis-rest-feature-service/package-lock.json @@ -5,7 +5,7 @@ "tslib": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.8.0.tgz", - "integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==" + "integrity": "sha512-ymKWWZJST0/CkgduC2qkzjMOWr4bouhuURNXCn/inEX0L57BnRG6FhX76o7FOnsjHazCjfU2LKeSrlS2sIKQJg==" } } } From b868b7b22a1d3f445e1af806648d31176f442c99 Mon Sep 17 00:00:00 2001 From: john gravois Date: Thu, 22 Feb 2018 14:45:45 -0800 Subject: [PATCH 7/9] 2018 --- packages/arcgis-rest-feature-service/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/arcgis-rest-feature-service/README.md b/packages/arcgis-rest-feature-service/README.md index a985d86fc5..68d46516a9 100644 --- a/packages/arcgis-rest-feature-service/README.md +++ b/packages/arcgis-rest-feature-service/README.md @@ -50,7 +50,7 @@ Esri welcomes contributions from anyone and everyone. Please see our [guidelines ### License -Copyright 2017 Esri +Copyright 2018 Esri Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From b1ad7989a53b086c9d0050ee4762b2cccf04696a Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Fri, 23 Feb 2018 22:47:31 -0800 Subject: [PATCH 8/9] use newly added IFeature from arcgis-rest-common-types --- packages/arcgis-rest-common-types/src/index.ts | 2 +- packages/arcgis-rest-feature-service/src/features.ts | 9 +-------- .../arcgis-rest-feature-service/test/mocks/feature.ts | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/arcgis-rest-common-types/src/index.ts b/packages/arcgis-rest-common-types/src/index.ts index 08950cec95..38195451d8 100644 --- a/packages/arcgis-rest-common-types/src/index.ts +++ b/packages/arcgis-rest-common-types/src/index.ts @@ -45,7 +45,7 @@ export type ElipticArc = IArc; */ export interface IFeature { geometry?: IGeometry; - attributes?: any; + attributes: { [key: string]: any }; } /** diff --git a/packages/arcgis-rest-feature-service/src/features.ts b/packages/arcgis-rest-feature-service/src/features.ts index 1f3f034be9..b3c170cb65 100644 --- a/packages/arcgis-rest-feature-service/src/features.ts +++ b/packages/arcgis-rest-feature-service/src/features.ts @@ -1,15 +1,8 @@ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc. * Apache-2.0 */ +import { IFeature } from "@esri/arcgis-rest-common-types"; import { request, IRequestOptions } from "@esri/arcgis-rest-request"; -/** - * Feature - TODO: move this to common types? - */ -export interface IFeature { - attributes: { [key: string]: any }; - geometry: any; -} - /** * parameters required to get a feature by id * diff --git a/packages/arcgis-rest-feature-service/test/mocks/feature.ts b/packages/arcgis-rest-feature-service/test/mocks/feature.ts index 50c5f18643..3bdfb43266 100644 --- a/packages/arcgis-rest-feature-service/test/mocks/feature.ts +++ b/packages/arcgis-rest-feature-service/test/mocks/feature.ts @@ -1,4 +1,4 @@ -import { IFeature } from "../../src/features"; +import { IFeature } from "@esri/arcgis-rest-common-types"; export const featureResponse = { feature: { From 1d0e57eadf283ec37887f097201029196f2ba348 Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Fri, 23 Feb 2018 22:57:28 -0800 Subject: [PATCH 9/9] arcgis-rest-feature-service now needs arcgis-rest-commont-types 1.0.3 --- packages/arcgis-rest-feature-service/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/arcgis-rest-feature-service/package.json b/packages/arcgis-rest-feature-service/package.json index 39cdb231f3..9d81027e0f 100644 --- a/packages/arcgis-rest-feature-service/package.json +++ b/packages/arcgis-rest-feature-service/package.json @@ -12,12 +12,12 @@ "tslib": "^1.7.1" }, "peerDependencies": { - "@esri/arcgis-rest-common-types": "^1.0.2", - "@esri/arcgis-rest-request": "^1.0.2" + "@esri/arcgis-rest-common-types": "^1.0.3", + "@esri/arcgis-rest-request": "^1.0.3" }, "devDependencies": { - "@esri/arcgis-rest-common-types": "^1.0.2", - "@esri/arcgis-rest-request": "^1.0.2" + "@esri/arcgis-rest-common-types": "^1.0.3", + "@esri/arcgis-rest-request": "^1.0.3" }, "scripts": { "prepare": "npm run build",