diff --git a/packages/arcgis-rest-request/src/job.ts b/packages/arcgis-rest-request/src/job.ts index 1a39c68a5b..4074dd59b0 100644 --- a/packages/arcgis-rest-request/src/job.ts +++ b/packages/arcgis-rest-request/src/job.ts @@ -4,6 +4,7 @@ import { ArcGISJobError } from "./utils/ArcGISJobError.js"; import { JOB_STATUSES } from "./types/job-statuses.js"; import { IAuthenticationManager } from "./utils/IAuthenticationManager.js"; import mitt from "mitt"; +import { processJobParams } from "./utils/process-job-params.js"; /** * Options for creating a new {@linkcode Job}. @@ -188,10 +189,11 @@ export class Job { ...requestOptions }; + const processedParams = processJobParams(params); const baseUrl = cleanUrl(url.replace(/\/submitJob\/?/, "")); const submitUrl = baseUrl + "/submitJob"; return request(submitUrl, { - params, + params: processedParams, authentication }).then( (response) => @@ -236,6 +238,7 @@ export class Job { */ private setIntervalHandler: any; + constructor(options: IJobOptions) { const { url, id, pollingRate, authentication }: Partial = { ...DefaultJobOptions, diff --git a/packages/arcgis-rest-request/src/utils/process-job-params.ts b/packages/arcgis-rest-request/src/utils/process-job-params.ts new file mode 100644 index 0000000000..e66f640a19 --- /dev/null +++ b/packages/arcgis-rest-request/src/utils/process-job-params.ts @@ -0,0 +1,13 @@ + /** + * Processes arrays to JSON strings for Geoprocessing services. See “GPMultiValue” in {@link https://developers.arcgis.com/rest/services-reference/enterprise/gp-data-types.htm} + */ + export function processJobParams(params: any) { + const processedParams = Object.keys(params).reduce((newParams: any, key) => { + const value = params[key] + const type = value.constructor.name; + newParams[key] = type === "Array" ? JSON.stringify(value) : value; + return newParams; + }, {}); + + return processedParams +} \ No newline at end of file diff --git a/packages/arcgis-rest-request/test/job.test.ts b/packages/arcgis-rest-request/test/job.test.ts index 8361b14499..e5b148a860 100644 --- a/packages/arcgis-rest-request/test/job.test.ts +++ b/packages/arcgis-rest-request/test/job.test.ts @@ -1,5 +1,6 @@ import fetchMock, { done } from "fetch-mock"; import { Job, JOB_STATUSES, ArcGISRequestError } from "../src/index.js"; +import { processJobParams } from "../src/utils/process-job-params.js"; import { GPJobIdResponse, GPEndpointCall, @@ -473,9 +474,7 @@ describe("Job", () => { mockHotspot_Raster ); }); - return job.getResult("Hotspot_Raster"); - }) .then((result) => { expect(result).toEqual(mockHotspot_Raster); @@ -681,6 +680,55 @@ describe("Job", () => { Job.submitJob(GPEndpointCall).then((job) => { expect(job.isMonitoring).toEqual(true); done(); + + }); + }); + + it("parses params if there is multi-value input", () => { + processJobParams({ + url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot/submitJob", + params: { + summarizeType: "['CentralFeature', 'MeanCenter', 'MedianCenter', 'Ellipse']", + weightField: 'NUM_TREES', + ellipseSize: '1 standard deviation', + context: { + extent: { + xmin: -15034729.266472297, + ymin: 5716733.479048933, + xmax: -12070195.56146081, + ymax: 7808050.572930799, + spatialReference: { wkid: 102100, latestWkid: 3857 }, + }, + }, + } + }); + + expect(processJobParams({ + summarizeType: ['CentralFeature', 'MeanCenter', 'MedianCenter', 'Ellipse'], + weightField: 'NUM_TREES', + ellipseSize: '1 standard deviation', + context: { + extent: { + xmin: -15034729.266472297, + ymin: 5716733.479048933, + xmax: -12070195.56146081, + ymax: 7808050.572930799, + spatialReference: { wkid: 102100, latestWkid: 3857 }, + }, + } + })).toEqual({ + summarizeType:'["CentralFeature","MeanCenter","MedianCenter","Ellipse"]', + weightField: 'NUM_TREES', + ellipseSize: '1 standard deviation', + context: { + extent: { + xmin: -15034729.266472297, + ymin: 5716733.479048933, + xmax: -12070195.56146081, + ymax: 7808050.572930799, + spatialReference: { wkid: 102100, latestWkid: 3857 }, + }, + } }); }); diff --git a/packages/arcgis-rest-request/test/mocks/job-mock-fetches.ts b/packages/arcgis-rest-request/test/mocks/job-mock-fetches.ts index 73e7c65c0e..cc0bd380fb 100644 --- a/packages/arcgis-rest-request/test/mocks/job-mock-fetches.ts +++ b/packages/arcgis-rest-request/test/mocks/job-mock-fetches.ts @@ -1,7 +1,7 @@ export const GPEndpointCall = { url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot/submitJob", params: { - Query: `"DATE" > date '1998-01-01 00:00:00' AND "DATE" < date '1998-01-31 00:00:00') AND ("Day" = 'SUN' OR "Day"= 'SAT') + Query: `"DATE" > date '1998-01-01 00:00:00' AND "DATE" < date '1998-01-31 00:00:00') AND ("Day" = 'SUN' OR "Day"= 'SAT'), ` }, startMonitoring: true,