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

constrain what constitutes a valid Item for crud operations, and require auth #248

Merged
merged 3 commits into from
Jul 23, 2018

Conversation

jgravois
Copy link
Contributor

@jgravois jgravois commented Jul 17, 2018

resolves #246:

  • adds a couple code snippets
  • stops using the (unnecessary) interface IUserRequestOptions
  • createItem() now requires an Item with 'title' and 'type'
  • updateItem() now requires an Item with an 'id'
  • the methods above, and removeItem(), now all require authentication

no one loves interface soup more than @dbouwman. hopefully he can find time to review soon as @tomwayson is out until late next week.

@jgravois jgravois requested a review from dbouwman July 17, 2018 18:53
@noahmulfinger
Copy link
Contributor

@jgravois Nice! This also mostly addresses the issue I just put up #247. What about making determineOwner more generic so that if there is a requestOptions.item.owner, that will be chosen before session.username? That way it could be used for createItemInFolder and updateItem as well.

@coveralls
Copy link

coveralls commented Jul 17, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 03bd9d0 on bug/246 into b2c5cdc on master.

@jgravois
Copy link
Contributor Author

jgravois commented Jul 17, 2018

This also mostly addresses #247

i love it when a plan comes together. i've pushed up another commit that incorporates your suggestion.

@jgravois jgravois requested a review from noahmulfinger July 17, 2018 19:24
/**
* requestOptions.owner is given priority, requestOptions.item.owner will be checked next. If neither are present, authentication.username will be assumed.
*/
function determineOwner(requestOptions: any): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm sure it'd be better to use a union type here instead of casting to any, but i was worried that i'd already reached my daily limit of new interfaces for this package today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think using any is fine in this case for a simple utility function.

@@ -48,8 +57,7 @@ export interface IItemResourceRequestOptions extends IItemIdRequestOptions {
resource?: string;
}

export interface IItemCrudRequestOptions extends IUserRequestOptions {
item: IItem;
export interface IItemCrudRequestOptions extends IRequestOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgravois Why remove IUserRequestOptions? That already has a mandatory authentication property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be honest, i got so excited about the lighter-weight technique i discovered for getting TypeScript to allow me to introspect authentication which may or may not be included in a request (in Esri/hub.js#35 (comment)) that i basically forgot what IUserRequestOptions was doing for us and went ahead and reinvented the 🎡.

@jgravois
Copy link
Contributor Author

it ended up being easier to address #241 and this issue holistically.

its a more involved refactor, but the approach i was suggesting before just feels like a 🤕.

@jgravois
Copy link
Contributor Author

@noahmulfinger if you can find time to review these changes in the next couple days, i'd love to include them in the looming release.

@noahmulfinger
Copy link
Contributor

@jgravois Taking a look now.

Copy link
Contributor

@noahmulfinger noahmulfinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgravois This looks good to me! I had two comments/questions, but they're really minor and don't need to be addressed for merging.

isViewOnly: boolean;
isOpenData: boolean;
isFav: boolean;
snippet?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snippet could probably be moved to IGroupAdd since it fits in with properties that can be passed in to create a group.

created: number;
modified: number;
protected: boolean;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for requiring these specific properties for IItem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've written the interface this way to acknowledge that these props are all guaranteed to exist (after an item has been created).

jgravois added 3 commits July 23, 2018 10:28
AFFECTS PACKAGES:
@esri/arcgis-rest-items

ISSUES CLOSED: #246
extending interfaces between categories proved to be more complicated than helpful
there is
already way too much complexity between what items and groups need to look like when they are
created, updated and retrieved.

AFFECTS PACKAGES:
@esri/arcgis-rest-common-types
@esri/arcgis-rest-groups
@esri/arcgis-rest-items
@esri/arcgis-rest-users
@jgravois
Copy link
Contributor Author

final feedback addressed (and followed by a rebase). thank you @noahmulfinger!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doc: IItem shows "type" & "title" as optional, but AGOL requires them for createItem calls
3 participants