Skip to content

Commit

Permalink
refactor(portal interfaces): renames portal request/response interfac…
Browse files Browse the repository at this point in the history
…es to match their functions

AFFECTS PACKAGES:
@esri/arcgis-rest-portal
@esri/arcgis-rest-service-admin

BREAKING CHANGE:
removes "Request" from portal option interfaces & renames response interfaces
  • Loading branch information
tomwayson committed Apr 19, 2019
1 parent 11fd46d commit faa5b3d
Show file tree
Hide file tree
Showing 29 changed files with 155 additions and 175 deletions.
4 changes: 2 additions & 2 deletions packages/arcgis-rest-portal/src/groups/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IGroupAdd, IGroup } from "@esri/arcgis-rest-types";

import { getPortalUrl } from "../util/get-portal-url";

export interface IGroupAddRequestOptions extends IRequestOptions {
export interface ICreateGroupOptions extends IRequestOptions {
group: IGroupAdd;
}

Expand All @@ -30,7 +30,7 @@ export interface IGroupAddRequestOptions extends IRequestOptions {
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function createGroup(
requestOptions: IGroupAddRequestOptions
requestOptions: ICreateGroupOptions
): Promise<{ success: boolean; group: IGroup }> {
const url = `${getPortalUrl(requestOptions)}/community/createGroup`;

Expand Down
6 changes: 3 additions & 3 deletions packages/arcgis-rest-portal/src/groups/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IPagingParams, IGroup, IItem } from "@esri/arcgis-rest-types";

import { getPortalUrl } from "../util/get-portal-url";

export interface IPagingParamsRequestOptions extends IRequestOptions {
export interface IGetGroupContentOptions extends IRequestOptions {
paging: IPagingParams;
}

Expand Down Expand Up @@ -59,7 +59,7 @@ export function getGroup(
*/
export function getGroupContent(
id: string,
requestOptions?: IPagingParamsRequestOptions
requestOptions?: IGetGroupContentOptions
): Promise<IGroup> {
const url = `${getPortalUrl(requestOptions)}/content/groups/${id}`;

Expand All @@ -68,7 +68,7 @@ export function getGroupContent(
...{ httpMethod: "GET" },
params: { start: 1, num: 100 },
...requestOptions
} as IPagingParamsRequestOptions;
} as IGetGroupContentOptions;

// is this the most concise way to mixin with the defaults above?
if (requestOptions && requestOptions.paging) {
Expand Down
8 changes: 7 additions & 1 deletion packages/arcgis-rest-portal/src/groups/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

import { IUserRequestOptions } from "@esri/arcgis-rest-auth";

export interface IGroupIdRequestOptions extends IUserRequestOptions {
/**
* Base options interface for making authenticated requests for groups.
*/
export interface IUserGroupOptions extends IUserRequestOptions {
/**
* Unique identifier of the group.
*/
id: string;
}
6 changes: 3 additions & 3 deletions packages/arcgis-rest-portal/src/groups/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { request } from "@esri/arcgis-rest-request";

import { getPortalUrl } from "../util/get-portal-url";
import { IGroupIdRequestOptions } from "./helpers";
import { IUserGroupOptions } from "./helpers";

/**
* ```js
Expand All @@ -22,7 +22,7 @@ import { IGroupIdRequestOptions } from "./helpers";
* @returns A Promise that will resolve with the success/failure status of the request and the groupId.
*/
export function joinGroup(
requestOptions: IGroupIdRequestOptions
requestOptions: IUserGroupOptions
): Promise<{ success: boolean; groupId: string }> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
Expand All @@ -47,7 +47,7 @@ export function joinGroup(
* @returns A Promise that will resolve with the success/failure status of the request and the groupId.
*/
export function leaveGroup(
requestOptions: IGroupIdRequestOptions
requestOptions: IUserGroupOptions
): Promise<{ success: boolean; groupId: string }> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
Expand Down
9 changes: 4 additions & 5 deletions packages/arcgis-rest-portal/src/groups/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
* Apache-2.0 */

import { request } from "@esri/arcgis-rest-request";
import { IGroupIdRequestOptions } from "./helpers";
import { IUserGroupOptions } from "./helpers";

import { getPortalUrl } from "../util/get-portal-url";

export type NotificationChannelType = "push" | "email" | "builtin";

export interface IGroupNotificationRequestOptions
extends IGroupIdRequestOptions {
export interface ICreateGroupNotificationOptions extends IUserGroupOptions {
/**
* Subject of the notification. This only applies to email and builtin notifications. For push notifications, subject/title is provided as a part of the message payload.
*/
Expand Down Expand Up @@ -54,13 +53,13 @@ export interface IGroupNotificationRequestOptions
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function createGroupNotification(
requestOptions: IGroupNotificationRequestOptions
requestOptions: ICreateGroupNotificationOptions
): Promise<any> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
}/createNotification`;

const options: IGroupNotificationRequestOptions = {
const options: ICreateGroupNotificationOptions = {
params: {
subject: requestOptions.subject,
message: requestOptions.message,
Expand Down
6 changes: 3 additions & 3 deletions packages/arcgis-rest-portal/src/groups/protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { request } from "@esri/arcgis-rest-request";

import { getPortalUrl } from "../util/get-portal-url";
import { IGroupIdRequestOptions } from "./helpers";
import { IUserGroupOptions } from "./helpers";

/**
* ```js
Expand All @@ -22,7 +22,7 @@ import { IGroupIdRequestOptions } from "./helpers";
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function protectGroup(
requestOptions: IGroupIdRequestOptions
requestOptions: IUserGroupOptions
): Promise<{ success: boolean }> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
Expand All @@ -46,7 +46,7 @@ export function protectGroup(
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function unprotectGroup(
requestOptions: IGroupIdRequestOptions
requestOptions: IUserGroupOptions
): Promise<{ success: boolean }> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
Expand Down
8 changes: 3 additions & 5 deletions packages/arcgis-rest-portal/src/groups/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { request } from "@esri/arcgis-rest-request";

import { getPortalUrl } from "../util/get-portal-url";
import { IGroupIdRequestOptions } from "./helpers";
import { IUserGroupOptions } from "./helpers";

/**
* ```js
Expand All @@ -21,13 +21,11 @@ import { IGroupIdRequestOptions } from "./helpers";
* @param requestOptions - Options for the request
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function removeGroup(
requestOptions: IGroupIdRequestOptions
): Promise<any> {
export function removeGroup(requestOptions: IUserGroupOptions): Promise<any> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
}/delete`;
const options: IGroupIdRequestOptions = {
const options: IUserGroupOptions = {
...requestOptions
};
return request(url, options);
Expand Down
4 changes: 2 additions & 2 deletions packages/arcgis-rest-portal/src/groups/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { IGroup } from "@esri/arcgis-rest-types";
import { SearchQueryBuilder } from "../util/SearchQueryBuilder";
import { ISearchRequestOptions, ISearchResult } from "../util/search";
import { ISearchOptions, ISearchResult } from "../util/search";
import { genericSearch } from "../util/generic-search";

/**
Expand All @@ -19,7 +19,7 @@ import { genericSearch } from "../util/generic-search";
* @returns A Promise that will resolve with the data from the response.
*/
export function searchGroups(
search: string | ISearchRequestOptions | SearchQueryBuilder
search: string | ISearchOptions | SearchQueryBuilder
): Promise<ISearchResult<IGroup>> {
return genericSearch<IGroup>(search, "group");
}
4 changes: 2 additions & 2 deletions packages/arcgis-rest-portal/src/groups/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { request, IRequestOptions } from "@esri/arcgis-rest-request";
import { IItemUpdate } from "@esri/arcgis-rest-types";
import { getPortalUrl } from "../util/get-portal-url";

export interface IGroupUpdateRequestOptions extends IRequestOptions {
export interface IUpdateGroupOptions extends IRequestOptions {
group: IItemUpdate;
}

Expand All @@ -24,7 +24,7 @@ export interface IGroupUpdateRequestOptions extends IRequestOptions {
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function updateGroup(
requestOptions: IGroupUpdateRequestOptions
requestOptions: IUpdateGroupOptions
): Promise<{ success: boolean; groupId: string }> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.group.id
Expand Down
24 changes: 12 additions & 12 deletions packages/arcgis-rest-portal/src/items/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { request, appendCustomParams } from "@esri/arcgis-rest-request";

import { getPortalUrl } from "../util/get-portal-url";
import {
IItemIdRequestOptions,
IItemResourceRequestOptions,
IItemAddResponse,
IUserItemOptions,
IItemResourceOptions,
IUpdateItemResponse,
IItemResourceResponse,
determineOwner,
IManageItemRelationshipRequestOptions
IManageItemRelationshipOptions
} from "./helpers";

export interface IItemDataAddRequestOptions extends IItemIdRequestOptions {
export interface IAddItemDataOptions extends IUserItemOptions {
/**
* Object to store
*/
Expand All @@ -38,8 +38,8 @@ export interface IItemDataAddRequestOptions extends IItemIdRequestOptions {
* success/failure and echoing the item id.
*/
export function addItemJsonData(
requestOptions: IItemDataAddRequestOptions
): Promise<IItemAddResponse> {
requestOptions: IAddItemDataOptions
): Promise<IUpdateItemResponse> {
const owner = determineOwner(requestOptions);
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
Expand Down Expand Up @@ -74,8 +74,8 @@ export function addItemJsonData(
* success/failure and echoing the item id.
*/
export function addItemData(
requestOptions: IItemDataAddRequestOptions
): Promise<IItemAddResponse> {
requestOptions: IAddItemDataOptions
): Promise<IUpdateItemResponse> {
const owner = determineOwner(requestOptions);

const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
Expand Down Expand Up @@ -109,14 +109,14 @@ export function addItemData(
* @returns A Promise to add item resources.
*/
export function addItemRelationship(
requestOptions: IManageItemRelationshipRequestOptions
requestOptions: IManageItemRelationshipOptions
): Promise<{ success: boolean }> {
const owner = determineOwner(requestOptions);
const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/addRelationship`;

const options = appendCustomParams<IManageItemRelationshipRequestOptions>(
const options = appendCustomParams<IManageItemRelationshipOptions>(
requestOptions,
["originItemId", "destinationItemId", "relationshipType"],
{ params: { ...requestOptions.params } }
Expand Down Expand Up @@ -153,7 +153,7 @@ export function addItemRelationship(
* @returns A Promise to add item resources.
*/
export function addItemResource(
requestOptions: IItemResourceRequestOptions
requestOptions: IItemResourceOptions
): Promise<IItemResourceResponse> {
const owner = determineOwner(requestOptions);
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
Expand Down
24 changes: 14 additions & 10 deletions packages/arcgis-rest-portal/src/items/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ import { IItemAdd } from "@esri/arcgis-rest-types";
import { getPortalUrl } from "../util/get-portal-url";
import {
IAddFolderResponse,
IItemAddResponse,
IItemCrudRequestOptions,
IUpdateItemResponse,
ICreateUpdateItemOptions,
serializeItem,
determineOwner
} from "./helpers";

export interface IAddFolderRequestOptions extends IItemCrudRequestOptions {
export interface ICreateFolderOptions extends ICreateUpdateItemOptions {
/**
* Name of the folder to create.
*/
title: string;
}

export interface IItemAddRequestOptions extends IItemCrudRequestOptions {
export interface ICreateItemOptions extends ICreateUpdateItemOptions {
item: IItemAdd;
}

export interface ICreateItemResponse extends IUpdateItemResponse {
folder: string;
}

/**
* ```js
* import { createFolder } from "@esri/arcgis-rest-portal";
Expand All @@ -40,7 +44,7 @@ export interface IItemAddRequestOptions extends IItemCrudRequestOptions {
* @returns A Promise that resolves with folder details once the folder has been created
*/
export function createFolder(
requestOptions: IAddFolderRequestOptions
requestOptions: ICreateFolderOptions
): Promise<IAddFolderResponse> {
const owner = determineOwner(requestOptions);

Expand Down Expand Up @@ -74,8 +78,8 @@ export function createFolder(
* @param requestOptions = Options for the request
*/
export function createItemInFolder(
requestOptions: IItemAddRequestOptions
): Promise<IItemAddResponse> {
requestOptions: ICreateItemOptions
): Promise<ICreateItemResponse> {
const owner = determineOwner(requestOptions);

const baseUrl = `${getPortalUrl(requestOptions)}/content/users/${owner}`;
Expand Down Expand Up @@ -113,12 +117,12 @@ export function createItemInFolder(
* @returns A Promise that creates an item.
*/
export function createItem(
requestOptions: IItemAddRequestOptions
): Promise<IItemAddResponse> {
requestOptions: ICreateItemOptions
): Promise<ICreateItemResponse> {
// delegate to createItemInFolder placing in the root of the filestore
const options = {
folderId: null,
...requestOptions
} as IItemAddRequestOptions;
} as ICreateItemOptions;
return createItemInFolder(options);
}
Loading

0 comments on commit faa5b3d

Please sign in to comment.