Skip to content

Commit

Permalink
Merge pull request #214 from Esri/chore/feature-service-params
Browse files Browse the repository at this point in the history
refactor(feature-service): update signatures
  • Loading branch information
jgravois authored Jun 8, 2018
2 parents d05ff91 + dd1e4c7 commit c0a881b
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 408 deletions.
8 changes: 8 additions & 0 deletions packages/arcgis-rest-common-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,11 @@ export interface IGroup {
};
[key: string]: any;
}

export type esriUnits =
| "esriSRUnit_Meter"
| "esriSRUnit_StatuteMile"
| "esriSRUnit_Foot"
| "esriSRUnit_Kilometer"
| "esriSRUnit_NauticalMile"
| "esriSRUnit_USNauticalMile";
4 changes: 2 additions & 2 deletions packages/arcgis-rest-feature-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ npm install @esri/arcgis-rest-feature-service
```js
import { getFeature } from '@esri/arcgis-rest-feature-service';

const params = {
const options = {
url:
"https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
id: 42
};

getFeature(params)
getFeature(options)
.then(feature => {
console.log(feature.attributes.FID); // 42
});
Expand Down
81 changes: 81 additions & 0 deletions packages/arcgis-rest-feature-service/src/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* 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";

import {
IEditFeaturesParams,
IEditFeatureResult,
appendCustomParams
} 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 params - Query parameters to be sent to the feature service via the request.
*/
export interface IAddFeaturesRequestOptions
extends IEditFeaturesParams,
IRequestOptions {
/**
* Feature service url.
*/
url: string;
/**
* Array of JSON features to add.
*/
adds: IFeature[];
}

/**
* Add features results.
*/
export interface IAddFeaturesResult {
/**
* Array of JSON response Object(s) for each feature added.
*/
addResults?: IEditFeatureResult[];
}

/**
* Add features request. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/add-features.htm) for more information.
*
* @param requestOptions - Options for the request.
* ```js
* import { addFeatures } from '@esri/arcgis-rest-feature-service';
*
* const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0";
*
* addFeatures({
* url,
* adds: [{
* geometry: { x: -120, y: 45, spatialReference: { wkid: 4326 } },
* attributes: { status: "alive" }
* }]
* });
* ```
*
* @param requestOptions - Options for the request.
* @returns A Promise that will resolve with the addFeatures response.
*/
export function addFeatures(
requestOptions: IAddFeaturesRequestOptions
): Promise<IAddFeaturesResult> {
const url = `${requestOptions.url}/addFeatures`;

// edit operations are POST only
const options: IAddFeaturesRequestOptions = {
params: {},
...requestOptions
};

appendCustomParams(requestOptions, options);

// mixin, don't overwrite
options.params.features = requestOptions.adds;

return request(url, options);
}
84 changes: 84 additions & 0 deletions packages/arcgis-rest-feature-service/src/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

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

import {
IEditFeaturesParams,
IEditFeatureResult,
ISharedQueryParams,
appendCustomParams
} from "./helpers";

/**
* Delete features parameters.
*/
export interface IDeleteFeaturesParams
extends IEditFeaturesParams,
ISharedQueryParams {}

/**
* 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 params - Query parameters to be sent to the feature service via the request.
*/
export interface IDeleteFeaturesRequestOptions
extends IDeleteFeaturesParams,
IRequestOptions {
/**
* Feature service url.
*/
url: string;
/**
* Array of objectIds to delete.
*/
deletes: number[];
}

/**
* Delete features results.
*/
export interface IDeleteFeaturesResult {
/**
* Array of JSON response Object(s) for each feature deleted.
*/
deleteResults?: IEditFeatureResult[];
}

/**
* Delete features request. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/delete-features.htm) for more information.
*
* ```js
* import { deleteFeatures } from '@esri/arcgis-rest-feature-service';
*
* const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0";
*
* deleteFeatures({
* url,
* deletes: [1,2,3]
* });
* ```
*
* @param deleteFeaturesRequestOptions - Options for the request.
* @returns A Promise that will resolve with the deleteFeatures response.
*/
export function deleteFeatures(
requestOptions: IDeleteFeaturesRequestOptions
): Promise<IDeleteFeaturesResult> {
const url = `${requestOptions.url}/deleteFeatures`;

// edit operations POST only
const options: IDeleteFeaturesRequestOptions = {
params: {},
...requestOptions
};

appendCustomParams(requestOptions, options);

// mixin, don't overwrite
options.params.objectIds = requestOptions.deletes;

return request(url, options);
}
Loading

0 comments on commit c0a881b

Please sign in to comment.