From d91dd0e127f70804beec8a4ce373c17755746c2e Mon Sep 17 00:00:00 2001 From: john gravois Date: Thu, 22 Feb 2018 17:29:37 -0800 Subject: [PATCH] feat(common-types): add more common types, keep the 'I' in front of interfaces AFFECTS PACKAGES: @esri/arcgis-rest-common-types @esri/arcgis-rest-geocoder @esri/arcgis-rest-groups @esri/arcgis-rest-items --- .../arcgis-rest-common-types/src/index.ts | 115 ++++++++---------- packages/arcgis-rest-geocoder/src/geocoder.ts | 38 +++--- packages/arcgis-rest-groups/src/groups.ts | 8 +- packages/arcgis-rest-items/src/items.ts | 14 +-- packages/arcgis-rest-items/test/mocks/item.ts | 4 +- .../arcgis-rest-items/test/mocks/search.ts | 2 +- 6 files changed, 85 insertions(+), 96 deletions(-) diff --git a/packages/arcgis-rest-common-types/src/index.ts b/packages/arcgis-rest-common-types/src/index.ts index e32968c015..c137e39d3c 100644 --- a/packages/arcgis-rest-common-types/src/index.ts +++ b/packages/arcgis-rest-common-types/src/index.ts @@ -4,7 +4,7 @@ /** * an arc can be represented as a JSON curve object */ -export interface Arc { +export interface IArc { a: [ Position, // End point: x, y, , Position2D, // Center point: center_x, center_y @@ -19,14 +19,14 @@ export interface Arc { /** * a bezier curve can be represented as a JSON curve object */ -export interface BezierCurve { +export interface IBezierCurve { b: [Position, Position2D, Position2D]; } /** * a circular arc can be represented as a JSON curve object */ -export interface CircularArc { +export interface ICircularArc { c: [Position, Position2D]; } @@ -38,20 +38,20 @@ export type Color = [number, number, number, number]; /** * */ -export type ElipticArc = Arc; +export type ElipticArc = IArc; /** * a spatial entity and its corresponding properties */ -export interface Feature { - geometry?: Geometry; +export interface IFeature { + geometry?: IGeometry; attributes?: any; } /** * */ -export interface Field { +export interface IField { name: string; type: string; alias?: string; @@ -61,14 +61,14 @@ export interface Field { /** * a building block for discrete geometries */ -export interface Geometry { - spatialReference?: SpatialReference; +export interface IGeometry { + spatialReference?: ISpatialReference; } /** * An envelope is a rectangle defined by a range of values for each coordinate and attribute. */ -export interface Envelope extends Geometry { +export interface IEnvelope extends IGeometry { xmin: number; xmax: number; ymin: number; @@ -91,23 +91,34 @@ export type esriGeometryType = | "esriGeometryPolygon" | "esriGeometryEnvelope"; +/** + * Extents are used to define rectangles and bounding boxes. + */ +export interface IExtent { + xmin: number; + ymin: number; + xmax: number; + ymax: number; + spatialReference?: ISpatialReference; +} + /** * */ -export interface FeatureSet extends HasZM { +export interface IFeatureSet extends IHasZM { objectIdFieldName?: string; // optional globalIdFieldName?: string; // optional displayFieldName?: string; // optional geometryType?: esriGeometryType; // for feature layers only - spatialReference?: SpatialReference; // for feature layers only. - fields?: Field[]; - features: Feature[]; + spatialReference?: ISpatialReference; // for feature layers only. + fields?: IField[]; + features: IFeature[]; } /** * */ -export interface Font { +export interface IFont { family?: string; // ""; size?: number; // ; style?: "italic" | "normal" | "oblique"; @@ -115,21 +126,10 @@ export interface Font { decoration?: "line-through" | "underline" | "none"; } -/** - * Extents are used to define rectangles and bounding boxes. - */ -export interface Extent { - xmin: number; - ymin: number; - xmax: number; - ymax: number; - spatialReference?: SpatialReference; -} - /** * */ -export interface HasZM { +export interface IHasZM { hasZ?: boolean; hasM?: boolean; } @@ -137,7 +137,7 @@ export interface HasZM { /** * Portal Item */ -export interface Item { +export interface IItem { id?: string; owner: string; title: string; @@ -159,12 +159,12 @@ export interface Item { /** * */ -export type JsonCurve = CircularArc | Arc | OldCircularArc | BezierCurve; +export type JsonCurve = ICircularArc | IArc | IOldCircularArc | IBezierCurve; /** * */ -export interface OldCircularArc { +export interface IOldCircularArc { a: [ Position, // End point: x, y, , Position2D, // Center point: center_x, center_y @@ -176,7 +176,7 @@ export interface OldCircularArc { /** * */ -export interface MarkerSymbol extends Symbol { +export interface IMarkerSymbol extends ISymbol { angle?: number; xoffset?: number; yoffset?: number; @@ -185,14 +185,14 @@ export interface MarkerSymbol extends Symbol { /** * A multipoint contains an array of points. */ -export interface Multipoint extends HasZM, Geometry { +export interface IMultipoint extends IHasZM, IGeometry { points: Position[]; } /** * Params for paging operations */ -export interface PagingParams { +export interface IPagingParams { start?: number; num?: number; } @@ -200,9 +200,9 @@ export interface PagingParams { /** * */ -export interface PictureFillSymbol extends Symbol, PictureSourced { +export interface IPictureFillSymbol extends ISymbol, IPictureSourced { type: "esriPFS"; - outline?: SimpleLineSymbol; // if outline has been specified + outline?: ISimpleLineSymbol; // if outline has been specified xscale?: number; yscale?: number; } @@ -210,14 +210,14 @@ export interface PictureFillSymbol extends Symbol, PictureSourced { /** * */ -export interface PictureMarkerSymbol extends MarkerSymbol, PictureSourced { +export interface IPictureMarkerSymbol extends IMarkerSymbol, IPictureSourced { type: "esriPMS"; } /** * */ -export interface PictureSourced { +export interface IPictureSourced { url?: string; // Relative URL for static layers and full URL for dynamic layers. Access relative URL using http:////images/ imageData?: string; // ""; contentType?: string; @@ -231,7 +231,7 @@ export interface PictureSourced { /** * A simple point geometry, with spatial reference defined. */ -export interface Point extends HasZM, Geometry { +export interface IPoint extends IHasZM, IGeometry { x: number; y: number; } @@ -239,28 +239,28 @@ export interface Point extends HasZM, Geometry { /** * */ -export interface Polyline extends HasZM, Geometry { +export interface IPolyline extends IHasZM, IGeometry { paths: Position[][]; } /** * */ -export interface PolylineWithCurves extends HasZM, Geometry { +export interface IPolylineWithCurves extends IHasZM, IGeometry { curvePaths: Array>; } /** * */ -export interface Polygon extends HasZM, Geometry { +export interface IPolygon extends IHasZM, IGeometry { rings: Position[][]; } /** * */ -export interface PolygonWithCurves extends HasZM, Geometry { +export interface IPolygonWithCurves extends IHasZM, IGeometry { curveRings: Array>; } @@ -326,17 +326,17 @@ export type SymbolType = /** * */ -export interface SimpleFillSymbol extends Symbol { +export interface ISimpleFillSymbol extends ISymbol { type: "esriSFS"; style?: SimpleFillSymbolStyle; color?: Color; - outline?: SimpleLineSymbol; // if outline has been specified + outline?: ISimpleLineSymbol; // if outline has been specified } /** * */ -export interface SimpleLineSymbol extends Symbol { +export interface ISimpleLineSymbol extends ISymbol { type: "esriSLS"; style?: SimpleLineSymbolStyle; color?: Color; @@ -346,28 +346,22 @@ export interface SimpleLineSymbol extends Symbol { /** * */ -export interface SimpleMarkerSymbol extends MarkerSymbol { +export interface ISimpleMarkerSymbol extends IMarkerSymbol { type: "esriSMS"; style?: SimpleMarkerSymbolStyle; color?: Color; size?: number; - outline?: SimpleLineSymbol; + outline?: ISimpleLineSymbol; } /** * Spatial reference systems define mathematical transformations and coordinate systems for displaying spatial information in 2D and 3D. */ -export interface SpatialReferenceWkid { - wkid: number; +export interface ISpatialReference { + wkid?: number; latestWkid?: number; vcsWkid?: number; latestVcsWkid?: number; -} - -/** - * - */ -export interface SpatialReferenceWkt { wkt?: string; latestWkt?: string; } @@ -375,12 +369,7 @@ export interface SpatialReferenceWkt { /** * */ -export type SpatialReference = SpatialReferenceWkt | SpatialReferenceWkid; - -/** - * - */ -export interface Symbol { +export interface ISymbol { type: SymbolType; style?: string; } @@ -388,7 +377,7 @@ export interface Symbol { /** * */ -export interface TextSymbol extends MarkerSymbol { +export interface ITextSymbol extends IMarkerSymbol { type: "esriTS"; color?: Color; backgroundColor?: Color; @@ -400,6 +389,6 @@ export interface TextSymbol extends MarkerSymbol { horizontalAlignment?: "left" | "right" | "center" | "justify"; rightToLeft?: boolean; kerning?: boolean; - font?: Font; + font?: IFont; text?: string; // only applicable when specified as a client-side graphic. } diff --git a/packages/arcgis-rest-geocoder/src/geocoder.ts b/packages/arcgis-rest-geocoder/src/geocoder.ts index 84abbd747b..bff780b61d 100644 --- a/packages/arcgis-rest-geocoder/src/geocoder.ts +++ b/packages/arcgis-rest-geocoder/src/geocoder.ts @@ -5,9 +5,9 @@ import { request, IRequestOptions, IParams } from "@esri/arcgis-rest-request"; import { IAuthenticatedRequestOptions } from "@esri/arcgis-rest-auth"; import { - Extent, - SpatialReferenceWkid, - Point + IExtent, + ISpatialReference, + IPoint } from "@esri/arcgis-rest-common-types"; // https always @@ -35,7 +35,7 @@ export interface IAddressBulk { countryCode?: string; } -export interface Location { +export interface ILocation { latitude?: number; longitude?: number; lat?: number; @@ -43,17 +43,17 @@ export interface Location { } function isLocationArray( - coords: Location | Point | [number, number] + coords: ILocation | IPoint | [number, number] ): coords is [number, number] { return (coords as [number, number]).length === 2; } function isLocation( - coords: Location | Point | [number, number] -): coords is Location { + coords: ILocation | IPoint | [number, number] +): coords is ILocation { return ( - (coords as Location).latitude !== undefined || - (coords as Location).lat !== undefined + (coords as ILocation).latitude !== undefined || + (coords as ILocation).lat !== undefined ); } @@ -116,11 +116,11 @@ export interface IBulkGeocodeRequestOptions extends IEndpointRequestOptions { } export interface IGeocodeResponse { - spatialReference: SpatialReferenceWkid; + spatialReference: ISpatialReference; candidates: Array<{ address: string; - location: Point; - extent: Extent; + location: IPoint; + extent: IExtent; attributes: object; }>; } @@ -129,7 +129,7 @@ export interface IReverseGeocodeResponse { address: { [key: string]: any; }; - location: Point; + location: IPoint; } export interface ISuggestResponse { @@ -141,10 +141,10 @@ export interface ISuggestResponse { } export interface IBulkGeocodeResponse { - spatialReference: SpatialReferenceWkid; + spatialReference: ISpatialReference; locations: Array<{ address: string; - location: Point; + location: IPoint; score: number; attributes: object; }>; @@ -205,8 +205,8 @@ export function geocode( response => { const sr = response.spatialReference; response.candidates.forEach(function(candidate: { - location: Point; - extent: Extent; + location: IPoint; + extent: IExtent; }) { candidate.location.spatialReference = sr; candidate.extent.spatialReference = sr; @@ -279,7 +279,7 @@ export function suggest( * @returns A Promise that will resolve with the data from the response. */ export function reverseGeocode( - coords: Point | Location | [number, number], + coords: IPoint | ILocation | [number, number], requestOptions?: IEndpointRequestOptions ): Promise { const options: IGeocodeRequestOptions = { @@ -356,7 +356,7 @@ export function bulkGeocode( return request(options.endpoint + "geocodeAddresses", requestOptions).then( response => { const sr = response.spatialReference; - response.locations.forEach(function(address: { location: Point }) { + response.locations.forEach(function(address: { location: IPoint }) { address.location.spatialReference = sr; }); return response; diff --git a/packages/arcgis-rest-groups/src/groups.ts b/packages/arcgis-rest-groups/src/groups.ts index 91743ad1ba..8e50040fc7 100644 --- a/packages/arcgis-rest-groups/src/groups.ts +++ b/packages/arcgis-rest-groups/src/groups.ts @@ -7,10 +7,10 @@ import { getPortalUrl } from "@esri/arcgis-rest-request"; -import { PagingParams, Item } from "@esri/arcgis-rest-common-types"; +import { IPagingParams, IItem } from "@esri/arcgis-rest-common-types"; export interface IPagingParamsRequestOptions extends IRequestOptions { - paging: PagingParams; + paging: IPagingParams; } export interface IGroupIdRequestOptions extends IRequestOptions { @@ -32,7 +32,7 @@ export interface IGroupRequestOptions extends IRequestOptions { group: IGroup; } -export interface IGroupSearchRequest extends PagingParams { +export interface IGroupSearchRequest extends IPagingParams { q: string; sortField?: string; sortOrder?: string; @@ -56,7 +56,7 @@ export interface IGroupContentResult { start: number; num: number; nextStart: number; - items: Item[]; + items: IItem[]; } export interface IGroupUsersResult { diff --git a/packages/arcgis-rest-items/src/items.ts b/packages/arcgis-rest-items/src/items.ts index c52a1f6d7c..fd95f7fa7a 100644 --- a/packages/arcgis-rest-items/src/items.ts +++ b/packages/arcgis-rest-items/src/items.ts @@ -7,12 +7,12 @@ import { getPortalUrl } from "@esri/arcgis-rest-request"; -import { Extent, Item, PagingParams } from "@esri/arcgis-rest-common-types"; +import { IExtent, IItem, IPagingParams } from "@esri/arcgis-rest-common-types"; import { IUserRequestOptions } from "@esri/arcgis-rest-auth"; export interface IItemRequestOptions extends IUserRequestOptions { - item: Item; + item: IItem; } // * @param id - Item Id @@ -54,7 +54,7 @@ export interface IItemResourceRequestOptions extends IItemIdRequestOptions { } export interface IItemCrudRequestOptions extends IUserRequestOptions { - item: Item; + item: IItem; /** * Item owner username (by default authentication session will be used). */ @@ -66,7 +66,7 @@ export interface IItemCrudRequestOptions extends IUserRequestOptions { } // this interface still needs to be docced -export interface ISearchRequest extends PagingParams { +export interface ISearchRequest extends IPagingParams { q: string; [key: string]: any; // start: number; @@ -86,7 +86,7 @@ export interface ISearchResult { start: number; num: number; nextStart: number; - results: Item[]; + results: IItem[]; } /** @@ -199,7 +199,7 @@ export function addItemJsonData( export function getItem( id: string, requestOptions?: IRequestOptions -): Promise { +): Promise { const url = `${getPortalUrl(requestOptions)}/content/items/${id}`; // default to a GET request @@ -363,7 +363,7 @@ export function removeItemResource( * @param item IItem to be serialized * @returns a formatted json object to be sent to Portal */ -function serializeItem(item: Item): any { +function serializeItem(item: IItem): any { // create a clone so we're not messing with the original const clone = JSON.parse(JSON.stringify(item)); // join keywords and tags... diff --git a/packages/arcgis-rest-items/test/mocks/item.ts b/packages/arcgis-rest-items/test/mocks/item.ts index ac7e2c01dd..11377a2196 100644 --- a/packages/arcgis-rest-items/test/mocks/item.ts +++ b/packages/arcgis-rest-items/test/mocks/item.ts @@ -1,11 +1,11 @@ -import { Item } from "@esri/arcgis-rest-common-types"; +import { IItem } from "@esri/arcgis-rest-common-types"; export const ItemSuccessResponse: any = { success: true, id: "3efakeitemid0000" }; -export const ItemResponse: Item = { +export const ItemResponse: IItem = { id: "4bc", owner: "jeffvader", title: "DS Plans", diff --git a/packages/arcgis-rest-items/test/mocks/search.ts b/packages/arcgis-rest-items/test/mocks/search.ts index 687a48181b..6d91d33fd8 100644 --- a/packages/arcgis-rest-items/test/mocks/search.ts +++ b/packages/arcgis-rest-items/test/mocks/search.ts @@ -1,5 +1,5 @@ import { ISearchResult } from "../../src/items"; -import { Item } from "@esri/arcgis-rest-common-types"; +import { IItem } from "@esri/arcgis-rest-common-types"; export const SearchResponse: ISearchResult = { query: "",