From f59fa90d784542b6092857bc706333915778c3e6 Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Wed, 17 Apr 2019 12:01:41 -0700 Subject: [PATCH] refactor(getLayer()): brings getLayer() signature inline w/ the rest 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 --- .../src/decodeValues.ts | 2 +- .../src/getLayer.ts | 20 ++++++++----------- .../test/getLayer.test.ts | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/arcgis-rest-feature-service/src/decodeValues.ts b/packages/arcgis-rest-feature-service/src/decodeValues.ts index ae551b2b13..b84d6f23c4 100644 --- a/packages/arcgis-rest-feature-service/src/decodeValues.ts +++ b/packages/arcgis-rest-feature-service/src/decodeValues.ts @@ -66,7 +66,7 @@ export function decodeValues( ): Promise { 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)); } diff --git a/packages/arcgis-rest-feature-service/src/getLayer.ts b/packages/arcgis-rest-feature-service/src/getLayer.ts index 5852c1967b..5ebc8c32ce 100644 --- a/packages/arcgis-rest-feature-service/src/getLayer.ts +++ b/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 { - return request(cleanUrl(url), requestOptions); + return request(cleanUrl(options.url), options); } diff --git a/packages/arcgis-rest-feature-service/test/getLayer.test.ts b/packages/arcgis-rest-feature-service/test/getLayer.test.ts index 4c35cfcb11..308efbce0d 100644 --- a/packages/arcgis-rest-feature-service/test/getLayer.test.ts +++ b/packages/arcgis-rest-feature-service/test/getLayer.test.ts @@ -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("*");