Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/get layer signature #520

Merged
merged 2 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
348 changes: 174 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions packages/arcgis-rest-feature-service/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

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

import { IEditFeaturesParams, IEditFeatureResult } from "./helpers";
import {
ILayerRequestOptions,
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 All @@ -20,11 +23,7 @@ import { IEditFeaturesParams, IEditFeatureResult } from "./helpers";
*/
export interface IAddFeaturesRequestOptions
extends IEditFeaturesParams,
IRequestOptions {
/**
* Feature service url.
*/
url: string;
ILayerRequestOptions {
/**
* Array of JSON features to add.
*/
Expand Down
10 changes: 3 additions & 7 deletions packages/arcgis-rest-feature-service/src/addAttachment.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { request, IRequestOptions, cleanUrl } from "@esri/arcgis-rest-request";
import { IEditFeatureResult } from "./helpers";
import { request, cleanUrl } from "@esri/arcgis-rest-request";
import { ILayerRequestOptions, IEditFeatureResult } from "./helpers";

/**
* Request options for adding a related attachment to a feature by id. See [Add Attachment](https://developers.arcgis.com/rest/services-reference/add-attachment.htm) for more information.
*
*/
export interface IAddAttachmentOptions extends IRequestOptions {
/**
* Feature service url.
*/
url: string;
export interface IAddAttachmentOptions extends ILayerRequestOptions {
/**
* Unique identifier of feature to add related attachment.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-feature-service/src/decodeValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function decodeValues(
): Promise<IQueryFeaturesResponse> {
return new Promise(resolve => {
if (!requestOptions.fields) {
return getLayer(requestOptions.url, requestOptions).then(
return getLayer({ url: requestOptions.url }).then(
(metadata: ILayerDefinition) => {
resolve((requestOptions.fields = metadata.fields));
}
Expand Down
8 changes: 2 additions & 6 deletions packages/arcgis-rest-feature-service/src/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import {
request,
IRequestOptions,
cleanUrl,
appendCustomParams
} from "@esri/arcgis-rest-request";
import {
ILayerRequestOptions,
IEditFeaturesParams,
IEditFeatureResult,
ISharedQueryParams
Expand All @@ -29,11 +29,7 @@ export interface IDeleteFeaturesParams
*/
export interface IDeleteFeaturesRequestOptions
extends IDeleteFeaturesParams,
IRequestOptions {
/**
* Feature service url.
*/
url: string;
ILayerRequestOptions {
/**
* Array of objectIds to delete.
*/
Expand Down
10 changes: 3 additions & 7 deletions packages/arcgis-rest-feature-service/src/deleteAttachments.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { request, IRequestOptions, cleanUrl } from "@esri/arcgis-rest-request";
import { IEditFeatureResult } from "./helpers";
import { request, cleanUrl } from "@esri/arcgis-rest-request";
import { ILayerRequestOptions, IEditFeatureResult } from "./helpers";

/**
* Request options to for deleting related attachments of a feature by id. See [Delete Attachments](https://developers.arcgis.com/rest/services-reference/delete-attachments.htm) for more information.
*
*/
export interface IDeleteAttachmentsOptions extends IRequestOptions {
/**
* Feature service url.
*/
url: string;
export interface IDeleteAttachmentsOptions extends ILayerRequestOptions {
/**
* Unique identifier of feature to delete related attachment(s).
*/
Expand Down
9 changes: 3 additions & 6 deletions packages/arcgis-rest-feature-service/src/getAttachments.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { request, IRequestOptions, cleanUrl } from "@esri/arcgis-rest-request";
import { request, cleanUrl } from "@esri/arcgis-rest-request";
import { ILayerRequestOptions } from "./helpers";

/**
* Request options to fetch `attachmentInfos` of a feature by id. See [Attachment Infos](https://developers.arcgis.com/rest/services-reference/attachment-infos-feature-service-.htm) for more information.
*
*/
export interface IGetAttachmentsOptions extends IRequestOptions {
/**
* Feature service url.
*/
url: string;
export interface IGetAttachmentsOptions extends ILayerRequestOptions {
/**
* Unique identifier of feature to request related `attachmentInfos`.
*/
Expand Down
20 changes: 8 additions & 12 deletions packages/arcgis-rest-feature-service/src/getLayer.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

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

import { request, cleanUrl, ILayerDefinition } from "@esri/arcgis-rest-request";
import { ILayerRequestOptions } from "./helpers";
/**
* ```js
* import { getLayer } from '@esri/arcgis-rest-feature-service';
* //
* getLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0")
* getLayer({
* url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0"
* })
* .then(response) // { name: "311", id: 0, ... }
* ```
* Layer (Feature Service) request. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/layer-feature-service-.htm) for more information.
*
* @param requestOptions - Options for the request.
* @param options - Options for the request.
* @returns A Promise that will resolve with the addFeatures response.
*/
export function getLayer(
url: string,
requestOptions?: IRequestOptions
options: ILayerRequestOptions
): Promise<ILayerDefinition> {
return request(cleanUrl(url), requestOptions);
return request(cleanUrl(options.url), options);
}
13 changes: 12 additions & 1 deletion packages/arcgis-rest-feature-service/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ import {
GeometryType,
SpatialRelationship,
IGeometry,
ISpatialReference
ISpatialReference,
IRequestOptions
} from "@esri/arcgis-rest-request";

/**
* Base options for making requests against feature layers
*/
export interface ILayerRequestOptions extends IRequestOptions {
/**
* Layer service url.
*/
url: string;
}

export interface ISharedQueryParams {
where?: string;
geometry?: IGeometry;
Expand Down
15 changes: 3 additions & 12 deletions packages/arcgis-rest-feature-service/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import {
request,
IRequestOptions,
cleanUrl,
appendCustomParams,
ISpatialReference,
Expand All @@ -13,16 +12,12 @@ import {
IExtent
} from "@esri/arcgis-rest-request";

import { ISharedQueryParams } from "./helpers";
import { ILayerRequestOptions, ISharedQueryParams } from "./helpers";

/**
* Request options to fetch a feature by id.
*/
export interface IFeatureRequestOptions extends IRequestOptions {
/**
* Layer service url.
*/
url: string;
export interface IFeatureRequestOptions extends ILayerRequestOptions {
/**
* Unique identifier of the feature.
*/
Expand All @@ -49,11 +44,7 @@ export interface IStatisticDefinition {
*/
export interface IQueryFeaturesRequestOptions
extends ISharedQueryParams,
IRequestOptions {
/**
* Layer service url.
*/
url: string;
ILayerRequestOptions {
objectIds?: number[];
relationParam?: string;
// NOTE: either time=1199145600000 or time=1199145600000, 1230768000000
Expand Down
5 changes: 2 additions & 3 deletions packages/arcgis-rest-feature-service/src/queryRelated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import {
request,
IRequestOptions,
cleanUrl,
appendCustomParams,
ISpatialReference,
Expand All @@ -12,12 +11,12 @@ import {
GeometryType,
IField
} from "@esri/arcgis-rest-request";
import { ILayerRequestOptions } 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.
*/
export interface IQueryRelatedRequestOptions extends IRequestOptions {
url: string;
export interface IQueryRelatedRequestOptions extends ILayerRequestOptions {
relationshipId?: number;
objectIds?: number[];
outFields?: "*" | string[];
Expand Down
13 changes: 6 additions & 7 deletions packages/arcgis-rest-feature-service/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

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

import { IEditFeaturesParams, IEditFeatureResult } from "./helpers";
import {
ILayerRequestOptions,
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 All @@ -20,11 +23,7 @@ import { IEditFeaturesParams, IEditFeatureResult } from "./helpers";
*/
export interface IUpdateFeaturesRequestOptions
extends IEditFeaturesParams,
IRequestOptions {
/**
* Feature service url.
*/
url: string;
ILayerRequestOptions {
/**
* Array of JSON features to update.
*/
Expand Down
10 changes: 3 additions & 7 deletions packages/arcgis-rest-feature-service/src/updateAttachment.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { request, IRequestOptions, cleanUrl } from "@esri/arcgis-rest-request";
import { IEditFeatureResult } from "./helpers";
import { request, cleanUrl } from "@esri/arcgis-rest-request";
import { ILayerRequestOptions, IEditFeatureResult } from "./helpers";

/**
* Request options to for updating a related attachment to a feature by id. See [Update Attachment](https://developers.arcgis.com/rest/services-reference/update-attachment.htm) for more information.
*
*/
export interface IUpdateAttachmentOptions extends IRequestOptions {
/**
* Feature service url.
*/
url: string;
export interface IUpdateAttachmentOptions extends ILayerRequestOptions {
/**
* Unique identifier of feature to update related attachment.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-feature-service/test/getLayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("feature", () => {

it("should fetch service metadata", done => {
fetchMock.once("*", getFeatureServiceResponse);
getLayer(layerUrl)
getLayer({ url: layerUrl })
.then(response => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
Expand Down