Skip to content

Commit

Permalink
use new appendCustomParams consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
jgravois committed Apr 16, 2019
1 parent eb297cb commit 99300a8
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 241 deletions.
8 changes: 8 additions & 0 deletions packages/arcgis-rest-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
"dist/**"
],
"dependencies": {
"tslib": "^1.9.3"
},

"devDependencies": {
"tslib": "^1.9.3",
"@esri/arcgis-rest-request": "^1.19.2"
},
"peerDependencies": {
"tslib": "^1.9.3",
"@esri/arcgis-rest-request": "^1.19.2"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/arcgis-rest-common/src/util/append-custom-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export function appendCustomParams<T extends IRequestOptions>(

// merge all keys in customOptions into options.params
options.params = keys.reduce((value, key) => {
value[key as any] = customOptions[key];
if (customOptions[key] || typeof customOptions[key] === "boolean") {
value[key as any] = customOptions[key];
}
return value;
}, options.params);

Expand Down
6 changes: 4 additions & 2 deletions packages/arcgis-rest-feature-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
},
"devDependencies": {
"@esri/arcgis-rest-common-types": "^1.19.2",
"@esri/arcgis-rest-request": "^1.19.2"
"@esri/arcgis-rest-request": "^1.19.2",
"@esri/arcgis-rest-common": "^1.19.2"
},
"peerDependencies": {
"@esri/arcgis-rest-common-types": "^1.19.2",
"@esri/arcgis-rest-request": "^1.19.2"
"@esri/arcgis-rest-request": "^1.19.2",
"@esri/arcgis-rest-common": "^1.19.2"
},
"scripts": {
"prepare": "npm run build",
Expand Down
23 changes: 7 additions & 16 deletions packages/arcgis-rest-feature-service/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { IFeature } from "@esri/arcgis-rest-common-types";
import {
request,
IRequestOptions,
appendCustomParams,
cleanUrl,
warn
} from "@esri/arcgis-rest-request";
import { appendCustomParams } from "@esri/arcgis-rest-common";

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

/**
Expand Down Expand Up @@ -69,21 +70,11 @@ export function addFeatures(
const url = `${cleanUrl(requestOptions.url)}/addFeatures`;

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

appendCustomParams(requestOptions, options);

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."
);
}
const options = appendCustomParams<IAddFeaturesRequestOptions>(
requestOptions,
["features", "gdbVersion", "returnEditMoment", "rollbackOnFailure"],
{ params: { ...requestOptions.params } }
);

return request(url, options);
}
28 changes: 12 additions & 16 deletions packages/arcgis-rest-feature-service/src/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import {
request,
IRequestOptions,
appendCustomParams,
cleanUrl,
warn
} from "@esri/arcgis-rest-request";
import { appendCustomParams } from "@esri/arcgis-rest-common";
import {
IEditFeaturesParams,
IEditFeatureResult,
Expand Down Expand Up @@ -75,21 +75,17 @@ export function deleteFeatures(
const url = `${cleanUrl(requestOptions.url)}/deleteFeatures`;

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

appendCustomParams(requestOptions, options);

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."
);
}
const options = appendCustomParams<IDeleteFeaturesRequestOptions>(
requestOptions,
[
"where",
"objectIds",
"gdbVersion",
"returnEditMoment",
"rollbackOnFailure"
],
{ params: { ...requestOptions.params } }
);

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

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

import {
esriGeometryType,
SpatialRelationship,
Expand Down Expand Up @@ -45,6 +43,3 @@ export interface IEditFeaturesParams {
*/
rollbackOnFailure?: boolean;
}

// this function has been moved into @esri/request. it is re-exported here for backwards compatibility
export { appendCustomParams };
71 changes: 48 additions & 23 deletions packages/arcgis-rest-feature-service/src/query.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
appendCustomParams,
cleanUrl
} from "@esri/arcgis-rest-request";
import { request, IRequestOptions, cleanUrl } from "@esri/arcgis-rest-request";
import { appendCustomParams } from "@esri/arcgis-rest-common";
import {
ISpatialReference,
IFeatureSet,
Expand Down Expand Up @@ -163,22 +159,51 @@ export function getFeature(
export function queryFeatures(
requestOptions: IQueryFeaturesRequestOptions
): Promise<IQueryFeaturesResponse | IQueryResponse> {
const queryOptions: IQueryFeaturesRequestOptions = {
params: {},
httpMethod: "GET",
url: requestOptions.url,
...requestOptions
};

appendCustomParams(requestOptions, queryOptions);

// set default query parameters
if (!queryOptions.params.where) {
queryOptions.params.where = "1=1";
}
if (!queryOptions.params.outFields) {
queryOptions.params.outFields = "*";
}
const queryOptions = appendCustomParams<IQueryFeaturesRequestOptions>(
requestOptions,
[
"where",
"objectIds",
"relationParam",
"time",
"distance",
"units",
"outFields",
"returnGeometry",
"maxAllowableOffset",
"geometryPrecision",
"outSR",
"gdbVersion",
"returnDistinctValues",
"returnIdsOnly",
"returnCountOnly",
"returnExtentOnly",
"orderByFields",
"groupByFieldsForStatistics",
"outStatistics",
"returnZ",
"returnM",
"multipatchOption",
"resultOffset",
"resultRecordCount",
"quantizationParameters",
"returnCentroid",
"resultType",
"historicMoment",
"returnTrueCurves",
"sqlFormat",
"returnExceededLimitFeatures"
],
{
httpMethod: "GET",
params: {
// set default query parameters
where: "1=1",
outFields: "*",
...requestOptions.params
}
}
);

return request(`${cleanUrl(queryOptions.url)}/query`, queryOptions);
return request(`${cleanUrl(requestOptions.url)}/query`, queryOptions);
}
47 changes: 20 additions & 27 deletions packages/arcgis-rest-feature-service/src/queryRelated.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
appendCustomParams,
cleanUrl
} from "@esri/arcgis-rest-request";
import { request, IRequestOptions, cleanUrl } from "@esri/arcgis-rest-request";
import { appendCustomParams } from "@esri/arcgis-rest-common";
import {
ISpatialReference,
IFeature,
Expand Down Expand Up @@ -66,26 +62,23 @@ export interface IQueryRelatedResponse extends IHasZM {
export function queryRelated(
requestOptions: IQueryRelatedRequestOptions
): Promise<IQueryRelatedResponse> {
const options: IQueryRelatedRequestOptions = {
params: {},
httpMethod: "GET",
url: requestOptions.url,
...requestOptions
};

appendCustomParams(requestOptions, options);

if (!options.params.definitionExpression) {
options.params.definitionExpression = "1=1";
}

if (!options.params.outFields) {
options.params.outFields = "*";
}

if (!options.params.relationshipId) {
options.params.relationshipId = 0;
}
const options = appendCustomParams<IQueryRelatedRequestOptions>(
requestOptions,
["objectIds", "relationshipId", "definitionExpression", "outFields"],
{
httpMethod: "GET",
params: {
// set default query parameters
definitionExpression: "1=1",
outFields: "*",
relationshipId: 0,
...requestOptions.params
}
}
);

return request(`${cleanUrl(options.url)}/queryRelatedRecords`, options);
return request(
`${cleanUrl(requestOptions.url)}/queryRelatedRecords`,
options
);
}
22 changes: 6 additions & 16 deletions packages/arcgis-rest-feature-service/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { IFeature } from "@esri/arcgis-rest-common-types";
import {
request,
IRequestOptions,
appendCustomParams,
cleanUrl,
warn
} from "@esri/arcgis-rest-request";
import { appendCustomParams } from "@esri/arcgis-rest-common";
import { IEditFeaturesParams, IEditFeatureResult } from "./helpers";

/**
Expand Down Expand Up @@ -69,21 +69,11 @@ export function updateFeatures(
const url = `${cleanUrl(requestOptions.url)}/updateFeatures`;

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

appendCustomParams(requestOptions, options);

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."
);
}
const options = appendCustomParams<IUpdateFeaturesRequestOptions>(
requestOptions,
["features", "gdbVersion", "returnEditMoment", "rollbackOnFailure"],
{ params: { ...requestOptions.params } }
);

return request(url, options);
}
13 changes: 2 additions & 11 deletions packages/arcgis-rest-feature-service/test/crud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,6 @@ describe("feature", () => {
Native: "YES"
}
}
], // for linting
updates: [
{
attributes: {
OBJECTID: 1001,
Street: "NO",
Native: "YES"
}
}
],
rollbackOnFailure: false
} as IUpdateFeaturesRequestOptions;
Expand Down Expand Up @@ -238,7 +229,7 @@ describe("feature", () => {
it("should return objectId of the deleted feature and a truthy success", done => {
const requestOptions = {
url: serviceUrl,
deletes: [1001],
objectIds: [1001],
where: "1=1"
} as IDeleteFeaturesRequestOptions;
fetchMock.once("*", deleteFeaturesResponse);
Expand All @@ -251,7 +242,7 @@ describe("feature", () => {
expect(options.body).toContain("where=1%3D1");
expect(options.method).toBe("POST");
expect(response.deleteResults[0].objectId).toEqual(
requestOptions.deletes[0]
requestOptions.objectIds[0]
);
expect(response.deleteResults[0].success).toEqual(true);
done();
Expand Down
2 changes: 2 additions & 0 deletions packages/arcgis-rest-geocoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
"devDependencies": {
"@esri/arcgis-rest-auth": "^1.19.2",
"@esri/arcgis-rest-common-types": "^1.19.2",
"@esri/arcgis-rest-common": "^1.19.2",
"@esri/arcgis-rest-request": "^1.19.2"
},
"peerDependencies": {
"@esri/arcgis-rest-auth": "^1.19.2",
"@esri/arcgis-rest-common-types": "^1.19.2",
"@esri/arcgis-rest-common": "^1.19.2",
"@esri/arcgis-rest-request": "^1.19.2"
},
"scripts": {
Expand Down
Loading

0 comments on commit 99300a8

Please sign in to comment.