Skip to content

Commit

Permalink
Merge 488a3d3 into 75dace0
Browse files Browse the repository at this point in the history
  • Loading branch information
jgravois committed Oct 13, 2018
2 parents 75dace0 + 488a3d3 commit 39de1a9
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 77 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
35 changes: 0 additions & 35 deletions packages/arcgis-rest-feature-service/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import {
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 @@ -50,31 +43,3 @@ 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];
}
});
}
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
26 changes: 17 additions & 9 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 @@ -27,6 +31,10 @@ export interface IGeocodeParams extends IParams {
}

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 +61,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[0].location; // => { x: -77.036533, y: 38.898719, spatialReference: ... }
* });
* ```
*
Expand All @@ -94,6 +100,8 @@ export function geocode(
...options,
...address
};

appendCustomParams(address, options);
}

// add spatialReference property to individual matches
Expand Down
9 changes: 2 additions & 7 deletions packages/arcgis-rest-geocoder/src/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,16 @@ export function suggest(
): Promise<ISuggestResponse> {
const options: ISuggestRequestOptions = {
endpoint: worldGeocoder,
params: {},
params: { text: partialText },
...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
27 changes: 27 additions & 0 deletions packages/arcgis-rest-geocoder/test/geocode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ describe("geocode", () => {
});
});

it("should a geocoding request with custom parameters", done => {
fetchMock.once("*", FindAddressCandidates);

geocode({ address: "1600 Pennsylvania Avenue", city: "Washington D.C." })
.then(response => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"
);
expect(options.method).toBe("POST");
expect(options.body).toContain("f=json");
expect(options.body).toContain(
`address=${encodeURIComponent("1600 Pennsylvania Avenue")}`
);
expect(options.body).toContain(
`city=${encodeURIComponent("Washington D.C.")}`
);
// the only property this lib tacks on
expect(response.spatialReference.wkid).toEqual(4326);
done();
})
.catch(e => {
fail(e);
});
});

it("should make a simple, single geocoding request with a custom parameter", done => {
fetchMock.once("*", FindAddressCandidates);

Expand Down
2 changes: 0 additions & 2 deletions packages/arcgis-rest-geocoder/test/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* Apache-2.0 */

import { serviceInfo, getGeocodeService } from "../src/helpers";

import * as fetchMock from "fetch-mock";

import { SharingInfo } from "./mocks/responses";

const customGeocoderUrl =
Expand Down
Loading

0 comments on commit 39de1a9

Please sign in to comment.