Skip to content

Commit

Permalink
Merge pull request #365 from Esri/fix/geocoding-params
Browse files Browse the repository at this point in the history
ensure 'first class citizen' geocode request parameters are passed through
  • Loading branch information
jgravois authored Oct 15, 2018
2 parents 8abca8f + 6157ddf commit b426e8f
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 81 deletions.
72 changes: 71 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,87 @@
"release:prepare": "lerna publish --skip-git --skip-npm --yes && node ./support/changelog.js",
"release:review": "git --no-pager diff --word-diff",
"release:publish": "./support/publish.sh",
"c": "npm run precommit && git-cz"
"c": "git-cz"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Esri/arcgis-rest-js.git"
},
"contributors": [
{
"name": "Anthony Lukach"
},
{
"name": "Bill Reynolds",
"email": "wreynolds@esri.com"
},
{
"name": "City of Veronia GIS"
},
{
"name": "Dave Bouwman",
"email": "dbouwman@esri.com"
},
{
"name": "Enguerrand des Vaux"
},
{
"name": "Gavin Rehkemper",
"email": "grehkemper@esri.com"
},
{
"name": "Ian Trewella"
},
{
"name": "Idi Eradiri",
"email": "ieradiri@esri.com"
},
{
"name": "Jeff Jacobson"
},
{
"name": "John Gravois",
"email": "john@esri.com"
},
{
"name": "Junshan Liu",
"email": "jliu@esri.com"
},
{
"name": "Max Payson",
"email": "mpayson@esri.com"
},
{
"name": "Mike 'Jupe' Juniper",
"email": "mjuniper@esri.com"
},
{
"name": "Mike Tschudi",
"email": "mtschudi@esri.com"
},
{
"name": "Noah Mulfinger",
"email": "nmulfinger@esri.com"
},
{
"name": "Patrick Arlt",
"email": "parlt@esri.com",
"url": "http://patrickarlt.com/"
},
{
"name": "Richard Hincamp"
},
{
"name": "Steven Kitterman",
"email": "skitterman@esri.com"
},
{
"name": "Stephen Sylvia",
"email": "ssylvia@esri.com"
},
{
"name": "Tom Wayson",
"email": "twayson@esri.com"
}
],
"license": "Apache-2.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/arcgis-rest-feature-service/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* Apache-2.0 */

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

import {
IEditFeaturesParams,
IEditFeatureResult,
request,
IRequestOptions,
appendCustomParams
} from "./helpers";
} from "@esri/arcgis-rest-request";
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.
Expand Down
1 change: 0 additions & 1 deletion packages/arcgis-rest-feature-service/src/addAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Apache-2.0 */

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

import { IEditFeatureResult } from "./helpers";

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/arcgis-rest-feature-service/src/delete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

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

import {
request,
IRequestOptions,
appendCustomParams
} from "@esri/arcgis-rest-request";
import {
IEditFeaturesParams,
IEditFeatureResult,
ISharedQueryParams,
appendCustomParams
ISharedQueryParams
} from "./helpers";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Apache-2.0 */

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

import { IEditFeatureResult } from "./helpers";

/**
Expand Down
38 changes: 4 additions & 34 deletions packages/arcgis-rest-feature-service/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

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

import {
esriGeometryType,
SpatialRelationship,
IGeometry,
ISpatialReference
} from "@esri/arcgis-rest-common-types";
import { IRequestOptions } from "@esri/arcgis-rest-request";

import { IQueryFeaturesRequestOptions } from "./query";
import { IAddFeaturesRequestOptions } from "./add";
import { IUpdateFeaturesRequestOptions } from "./update";
import { IDeleteFeaturesRequestOptions } from "./delete";
import { IQueryRelatedRequestOptions } from "./queryRelated";

export interface ISharedQueryParams {
where?: string;
Expand Down Expand Up @@ -51,30 +46,5 @@ export interface IEditFeaturesParams {
rollbackOnFailure?: boolean;
}

/**
* Used internally by the package to ensure that first order request options are passed through as request parameters.
*/
export function appendCustomParams(
oldOptions:
| IQueryFeaturesRequestOptions
| IAddFeaturesRequestOptions
| IUpdateFeaturesRequestOptions
| IDeleteFeaturesRequestOptions
| IQueryRelatedRequestOptions,
newOptions: IRequestOptions
) {
// only pass query parameters through in the request, not generic IRequestOptions props
Object.keys(oldOptions).forEach(function(key: string) {
if (
key !== "url" &&
key !== "params" &&
key !== "authentication" &&
key !== "httpMethod" &&
key !== "fetch" &&
key !== "portal" &&
key !== "maxUrlLength"
) {
newOptions.params[key] = (oldOptions as { [key: string]: any })[key];
}
});
}
// this function has been moved into @esri/request. it is re-exported here for backwards compatibility
export { appendCustomParams };
8 changes: 6 additions & 2 deletions packages/arcgis-rest-feature-service/src/query.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
appendCustomParams
} from "@esri/arcgis-rest-request";
import {
ISpatialReference,
IFeatureSet,
IFeature,
esriUnits,
IExtent
} from "@esri/arcgis-rest-common-types";
import { request, IRequestOptions } from "@esri/arcgis-rest-request";
import { ISharedQueryParams } from "./helpers";

import { ISharedQueryParams, appendCustomParams } from "./helpers";
/**
* Request options to fetch a feature by id.
*/
Expand Down
7 changes: 5 additions & 2 deletions packages/arcgis-rest-feature-service/src/queryRelated.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
appendCustomParams
} from "@esri/arcgis-rest-request";
import {
ISpatialReference,
IFeature,
IHasZM,
esriGeometryType,
IField
} from "@esri/arcgis-rest-common-types";
import { request, IRequestOptions } from "@esri/arcgis-rest-request";
import { appendCustomParams } from "./helpers";

/**
* Related record query request options. Additional arguments can be passed via the [params](/arcgis-rest-js/api/feature-service/IQueryRelatedRequestOptions/#params) property. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/query-related-feature-service-.htm) for more information and a full list of parameters.
Expand Down
9 changes: 4 additions & 5 deletions packages/arcgis-rest-feature-service/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* Apache-2.0 */

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

import {
IEditFeaturesParams,
IEditFeatureResult,
request,
IRequestOptions,
appendCustomParams
} from "./helpers";
} from "@esri/arcgis-rest-request";
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Apache-2.0 */

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

import { IEditFeatureResult } from "./helpers";

/**
Expand Down
34 changes: 22 additions & 12 deletions packages/arcgis-rest-geocoder/src/geocode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

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

import {
IExtent,
Expand All @@ -18,15 +22,21 @@ export interface IGeocodeParams extends IParams {
* import { suggest, geocode } from '@esri/arcgis-rest-geocoder';
* suggest("LAX")
* .then((response) => {
* response.suggestions[2].magicKey; // => "dHA9MCNsb2M9Mjk3ODc2MCNsbmc9MzMjcGw9ODkxNDg4I2xicz0xNDoxNDc4MTI1MA=="
* });
* geocode("LAX, 1 World Way, Los Angeles, CA, 90045, USA", {magicKey: "dHA9MCN..."})
* geocode({
* singleLine: response.suggestions[1].text,
* magicKey: response.suggestions[0].magicKey
* })
* })
* ```
*/
magicKey?: string;
}

export interface IGeocodeRequestOptions extends IEndpointRequestOptions {
/**
* use this if all your address info is contained in a single string.
*/
singleLine?: string;
address?: string;
address2?: string;
address3?: string;
Expand All @@ -53,25 +63,23 @@ export interface IGeocodeResponse {
}

/**
* Used to determine the [location](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm) of a single address or point of interest.
* Used to determine the location of a single address or point of interest. See the [REST Documentation](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm) for more information.
*
* ```js
* import { geocode } from '@esri/arcgis-rest-geocoder';
*
* geocode("LAX")
* .then((response) => {
* response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: { wkid: 4326 } }
* response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: ... }
* });
*
* geocode({
* params: {
* address: "1600 Pennsylvania Ave",
* postal: 20500,
* countryCode: "USA"
* }
* address: "1600 Pennsylvania Ave",
* postal: 20500,
* countryCode: "USA"
* })
* .then((response) => {
* response.candidates[0].location; // => { x: -77.036533, y: 38.898719, spatialReference: { wkid: 4326 } }
* response.candidates[1].location; // => { x: -77.036533, y: 38.898719, spatialReference: ... }
* });
* ```
*
Expand All @@ -94,6 +102,8 @@ export function geocode(
...options,
...address
};

appendCustomParams(address, options);
}

// add spatialReference property to individual matches
Expand Down
15 changes: 6 additions & 9 deletions packages/arcgis-rest-geocoder/src/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export interface ISuggestRequestOptions extends IEndpointRequestOptions {
* import { suggest, geocode } from '@esri/arcgis-rest-geocoder';
* suggest("LAX")
* .then((response) => {
* response.suggestions[2].magicKey; // => "dHA9MCNsb2M9Mjk3ODc2MCNsbmc9MzMjcGw9ODkxNDg4I2xicz0xNDoxNDc4MTI1MA=="
* });
* geocode("LAX, 1 World Way, Los Angeles, CA, 90045, USA", {magicKey: "dHA9MCN..."})
* geocode({
* singleLine: response.suggestions[1].text,
* magicKey: response.suggestions[1].magicKey
* })
* })
* ```
*/
magicKey?: string;
Expand Down Expand Up @@ -53,17 +55,12 @@ export function suggest(
...requestOptions
};

// is this the most concise way to mixin these optional parameters?
if (requestOptions && requestOptions.params) {
options.params = requestOptions.params;
}
options.params.text = partialText;

if (requestOptions && requestOptions.magicKey) {
options.params.magicKey = requestOptions.magicKey;
}

options.params.text = partialText;

return request(options.endpoint + "suggest", options);
}

Expand Down
Loading

0 comments on commit b426e8f

Please sign in to comment.