Skip to content

Commit

Permalink
refactor(getLayer()): brings getLayer() signature inline w/ the rest …
Browse files Browse the repository at this point in the history
…of esri-arcgis-feature-service

adds new IFeatureRequestOptions base type for all fns in this package that includes url: string

AFFECTS PACKAGES:
@esri/arcgis-rest-feature-service

BREAKING CHANGE:
changed signature of getLayer() fn to always expect an options hash
  • Loading branch information
tomwayson committed Apr 17, 2019
1 parent 5e33dbe commit f59fa90
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/arcgis-rest-feature-service/src/decodeValues.ts
Expand Up @@ -66,7 +66,7 @@ export function decodeValues(
): Promise<IQueryFeaturesResponse> {
return new Promise(resolve => {
if (!requestOptions.fields) {
return getLayer(requestOptions.url, requestOptions).then(
return getLayer({ url: requestOptions.url }).then(
(metadata: ILayerDefinition) => {
resolve((requestOptions.fields = metadata.fields));
}
Expand Down
20 changes: 8 additions & 12 deletions packages/arcgis-rest-feature-service/src/getLayer.ts
@@ -1,28 +1,24 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
cleanUrl,
ILayerDefinition
} from "@esri/arcgis-rest-request";

import { request, cleanUrl, ILayerDefinition } from "@esri/arcgis-rest-request";
import { ILayerRequestOptions } from "./helpers";
/**
* ```js
* import { getLayer } from '@esri/arcgis-rest-feature-service';
* //
* getLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0")
* getLayer({
* url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0"
* })
* .then(response) // { name: "311", id: 0, ... }
* ```
* Layer (Feature Service) request. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/layer-feature-service-.htm) for more information.
*
* @param requestOptions - Options for the request.
* @param options - Options for the request.
* @returns A Promise that will resolve with the addFeatures response.
*/
export function getLayer(
url: string,
requestOptions?: IRequestOptions
options: ILayerRequestOptions
): Promise<ILayerDefinition> {
return request(cleanUrl(url), requestOptions);
return request(cleanUrl(options.url), options);
}
2 changes: 1 addition & 1 deletion packages/arcgis-rest-feature-service/test/getLayer.test.ts
Expand Up @@ -15,7 +15,7 @@ describe("feature", () => {

it("should fetch service metadata", done => {
fetchMock.once("*", getFeatureServiceResponse);
getLayer(layerUrl)
getLayer({ url: layerUrl })
.then(response => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
Expand Down

0 comments on commit f59fa90

Please sign in to comment.