diff --git a/packages/arcgis-rest-feature-service/src/add.ts b/packages/arcgis-rest-feature-service/src/add.ts index 3b276373a8..def3c9633e 100644 --- a/packages/arcgis-rest-feature-service/src/add.ts +++ b/packages/arcgis-rest-feature-service/src/add.ts @@ -5,7 +5,8 @@ import { IFeature } from "@esri/arcgis-rest-common-types"; import { request, IRequestOptions, - appendCustomParams + appendCustomParams, + warn } from "@esri/arcgis-rest-request"; import { IEditFeaturesParams, IEditFeatureResult } from "./helpers"; @@ -13,7 +14,7 @@ import { IEditFeaturesParams, IEditFeatureResult } from "./helpers"; * Add features request options. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/add-features.htm) for more information. * * @param url - Feature service url. - * @param adds - Array of JSON features to add. + * @param features - Array of JSON features to add. * @param params - Query parameters to be sent to the feature service via the request. */ export interface IAddFeaturesRequestOptions @@ -26,7 +27,11 @@ export interface IAddFeaturesRequestOptions /** * Array of JSON features to add. */ - adds: IFeature[]; + features: IFeature[]; + /** + * Deprecated. Please use `features` instead. + */ + adds?: IFeature[]; } /** @@ -49,7 +54,7 @@ export interface IAddFeaturesResult { * * addFeatures({ * url, - * adds: [{ + * features: [{ * geometry: { x: -120, y: 45, spatialReference: { wkid: 4326 } }, * attributes: { status: "alive" } * }] @@ -72,9 +77,14 @@ export function addFeatures( appendCustomParams(requestOptions, options); - // mixin, don't overwrite - options.params.features = requestOptions.adds; - delete options.params.adds; + if (options.params.adds && options.params.adds.length) { + // mixin, don't overwrite + options.params.features = requestOptions.adds; + delete options.params.adds; + warn( + "The `adds` parameter is deprecated and will be removed in a future release. Please use `features` instead." + ); + } return request(url, options); } diff --git a/packages/arcgis-rest-feature-service/src/delete.ts b/packages/arcgis-rest-feature-service/src/delete.ts index ad22b2e465..9466771f18 100644 --- a/packages/arcgis-rest-feature-service/src/delete.ts +++ b/packages/arcgis-rest-feature-service/src/delete.ts @@ -4,7 +4,8 @@ import { request, IRequestOptions, - appendCustomParams + appendCustomParams, + warn } from "@esri/arcgis-rest-request"; import { IEditFeaturesParams, @@ -23,7 +24,7 @@ export interface IDeleteFeaturesParams * Delete features request options. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/delete-features.htm) for more information. * * @param url - Feature service url. - * @param deletes - Array of objectIds to delete. + * @param objectIds - Array of objectIds to delete. * @param params - Query parameters to be sent to the feature service via the request. */ export interface IDeleteFeaturesRequestOptions @@ -36,7 +37,11 @@ export interface IDeleteFeaturesRequestOptions /** * Array of objectIds to delete. */ - deletes: number[]; + objectIds: number[]; + /** + * Deprecated. Please use `objectIds` instead. + */ + deletes?: number[]; } /** @@ -59,7 +64,7 @@ export interface IDeleteFeaturesResult { * * deleteFeatures({ * url, - * deletes: [1,2,3] + * objectIds: [1,2,3] * }); * ``` * @@ -79,9 +84,14 @@ export function deleteFeatures( appendCustomParams(requestOptions, options); - // mixin, don't overwrite - options.params.objectIds = requestOptions.deletes; - delete options.params.deletes; + if (options.params.deletes && options.params.deletes.length) { + // mixin, don't overwrite + options.params.objectIds = requestOptions.deletes; + delete options.params.deletes; + warn( + "The `deletes` parameter is deprecated and will be removed in a future release. Please use `objectIds` instead." + ); + } return request(url, options); } diff --git a/packages/arcgis-rest-feature-service/src/update.ts b/packages/arcgis-rest-feature-service/src/update.ts index 750a9fa15c..86f10e1f96 100644 --- a/packages/arcgis-rest-feature-service/src/update.ts +++ b/packages/arcgis-rest-feature-service/src/update.ts @@ -5,7 +5,8 @@ import { IFeature } from "@esri/arcgis-rest-common-types"; import { request, IRequestOptions, - appendCustomParams + appendCustomParams, + warn } from "@esri/arcgis-rest-request"; import { IEditFeaturesParams, IEditFeatureResult } from "./helpers"; @@ -13,7 +14,7 @@ import { IEditFeaturesParams, IEditFeatureResult } from "./helpers"; * Update features request options. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/update-features.htm) for more information. * * @param url - Feature service url. - * @param updates - Array of JSON features to update. + * @param features - Array of JSON features to update. * @param params - Query parameters to be sent to the feature service via the request. */ export interface IUpdateFeaturesRequestOptions @@ -26,7 +27,11 @@ export interface IUpdateFeaturesRequestOptions /** * Array of JSON features to update. */ - updates: IFeature[]; + features: IFeature[]; + /** + * Deprecated. Please use `features` instead. + */ + updates?: IFeature[]; } /** @@ -49,7 +54,7 @@ export interface IUpdateFeaturesResult { * * updateFeatures({ * url, - * updates: [{ + * features: [{ * geometry: { x: -120, y: 45, spatialReference: { wkid: 4326 } }, * attributes: { status: "alive" } * }] @@ -72,9 +77,14 @@ export function updateFeatures( appendCustomParams(requestOptions, options); - // mixin, don't overwrite - options.params.features = requestOptions.updates; - delete options.params.updates; + if (options.params.updates && options.params.updates.length) { + // mixin, don't overwrite + options.params.features = requestOptions.updates; + delete options.params.updates; + warn( + "The `updates` parameter is deprecated and will be removed in a future release. Please use `features` instead." + ); + } return request(url, options); } diff --git a/packages/arcgis-rest-feature-service/test/crud.test.ts b/packages/arcgis-rest-feature-service/test/crud.test.ts index 8f75294315..9f7a1eb7e7 100644 --- a/packages/arcgis-rest-feature-service/test/crud.test.ts +++ b/packages/arcgis-rest-feature-service/test/crud.test.ts @@ -26,6 +26,130 @@ describe("feature", () => { it("should return objectId of the added feature and a truthy success", done => { const requestOptions = { url: serviceUrl, + features: [ + { + geometry: { + x: -9177311.62541634, + y: 4247151.205222242, + spatialReference: { + wkid: 102100, + latestWkid: 3857 + } + }, + attributes: { + Tree_ID: 102, + Collected: 1349395200000, + Crew: "Linden+ Forrest+ Johnny" + } + } + ] + }; + fetchMock.once("*", addFeaturesResponse); + addFeatures(requestOptions) + .then(response => { + expect(fetchMock.called()).toBeTruthy(); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual(`${requestOptions.url}/addFeatures`); + expect(options.body).toContain( + "features=" + + encodeURIComponent( + '[{"geometry":{"x":-9177311.62541634,"y":4247151.205222242,"spatialReference":{"wkid":102100,"latestWkid":3857}},"attributes":{"Tree_ID":102,"Collected":1349395200000,"Crew":"Linden+ Forrest+ Johnny"}}]' + ) + ); + expect(options.method).toBe("POST"); + expect(response.addResults[0].objectId).toEqual(1001); + expect(response.addResults[0].success).toEqual(true); + done(); + }) + .catch(e => { + fail(e); + }); + }); + + it("should return objectId of the updated feature and a truthy success", done => { + const requestOptions = { + url: serviceUrl, + features: [ + { + attributes: { + OBJECTID: 1001, + Street: "NO", + Native: "YES" + } + } + ], + rollbackOnFailure: false + } as IUpdateFeaturesRequestOptions; + fetchMock.once("*", updateFeaturesResponse); + updateFeatures(requestOptions) + .then(response => { + expect(fetchMock.called()).toBeTruthy(); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual(`${requestOptions.url}/updateFeatures`); + expect(options.method).toBe("POST"); + expect(options.body).toContain( + "features=" + + encodeURIComponent( + '[{"attributes":{"OBJECTID":1001,"Street":"NO","Native":"YES"}}]' + ) + ); + expect(options.body).toContain("rollbackOnFailure=false"); + expect(response.updateResults[0].success).toEqual(true); + done(); + }) + .catch(e => { + fail(e); + }); + }); + + it("should return objectId of the deleted feature and a truthy success", done => { + const requestOptions = { + url: serviceUrl, + objectIds: [1001], + where: "1=1" + } as IDeleteFeaturesRequestOptions; + fetchMock.once("*", deleteFeaturesResponse); + deleteFeatures(requestOptions) + .then(response => { + expect(fetchMock.called()).toBeTruthy(); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual(`${requestOptions.url}/deleteFeatures`); + expect(options.body).toContain("objectIds=1001"); + expect(options.body).toContain("where=1%3D1"); + expect(options.method).toBe("POST"); + expect(response.deleteResults[0].objectId).toEqual( + requestOptions.objectIds[0] + ); + expect(response.deleteResults[0].success).toEqual(true); + done(); + }) + .catch(e => { + fail(e); + }); + }); + + // tests for depreciated params + // remove when `adds`, `updates` and `deletes` params removed + it("should return objectId of the added feature and a truthy success", done => { + const requestOptions = { + url: serviceUrl, + features: [ + { + geometry: { + x: -9177311.62541634, + y: 4247151.205222242, + spatialReference: { + wkid: 102100, + latestWkid: 3857 + } + }, + attributes: { + Tree_ID: 102, + Collected: 1349395200000, + Crew: "Linden+ Forrest+ Johnny" + } + } + ], // for linting adds: [ { geometry: { @@ -69,6 +193,15 @@ describe("feature", () => { it("should return objectId of the updated feature and a truthy success", done => { const requestOptions = { url: serviceUrl, + features: [ + { + attributes: { + OBJECTID: 1001, + Street: "NO", + Native: "YES" + } + } + ], // for linting updates: [ { attributes: {