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(feature-service): update signatures #214

Merged
merged 2 commits into from
Jun 8, 2018

Conversation

jgravois
Copy link
Contributor

@jgravois jgravois commented Jun 6, 2018

to stop leaning on params directly

AFFECTS PACKAGES:
@esri/arcgis-rest-common-types
@esri/arcgis-rest-feature-service

addresses @patrickarlt's #137 (comment)

this is one rare instance in which it will 'just work' if developers don't update their code.

@coveralls
Copy link

coveralls commented Jun 6, 2018

Coverage Status

Coverage increased (+0.02%) to 99.311% when pulling b2e27de on chore/feature-service-params into 415508c on master.

@@ -83,22 +89,11 @@ export interface IQueryFeaturesParams extends ISharedQueryParams {
quantizationParameters?: any;
returnCentroid?: boolean;
resultType?: "none" | "standard" | "tile";
// TODO: is Date the right type for epoch time in milliseconds?
historicMoment?: Date;
historicMoment?: number;
Copy link
Member

Choose a reason for hiding this comment

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

I think my idea was our API would take in dates, but convert them to epoch time (numbers) before sending the requests. That said, I didn't implement it. 😄

So I agree w/ this change. We can take in numbers for now and then later add the option to take dates (historicMoment?: number | Date).

/**
* Layer service url.
*/
url: string;
objectIds?: number[];
relationParam?: string;
// NOTE: either time=1199145600000 or time=1199145600000, 1230768000000
time?: Date | Date[];
Copy link
Member

Choose a reason for hiding this comment

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

I think we should change this to number | number[] as well to be consistent w/ historicMoment.

// mixin, don't overwrite
options.params.objectIds = requestOptions.deletes;

return request(url, options);
}

function appendCustomParams(
oldOptions: IQueryFeaturesRequestOptions,
Copy link
Member

@tomwayson tomwayson Jun 7, 2018

Choose a reason for hiding this comment

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

Should both of these be union types? IQueryFeaturesRequestOptions | IAddFeaturesRequestOptions | IUpdateFeaturesRequestOptions | IDeleteFeaturesRequestOptions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They should, but this would require adding [key: string]: any; to all four interfaces to avoid TypeScript complaints.

Element implicitly has an 'any' type because type 'IQueryFeaturesRequestOptions | IAddFeaturesRequestOptions | IUpdateFeaturesRequestOptions | IDele...' has no index signature. (7017)

Copy link
Member

Choose a reason for hiding this comment

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

actually, I guess just oldOptions should be that union type, is that what you tried?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly. my current approach is definitely incorrect, but for some reason it doesn't bother TypeScript (or me).

we could also:

  • append the generic key to each of the interfaces we'd like to union (not DRY, but that's not a big deal)
  • create and export a generic ICrudRequestOptions interface and have each of the ones we'd like to union extend that (this would require it to appear in the doc, which feels like overkill)
  • create and not export a generic ICrudRequestOptions interface and use it to declare the type to the utility method without extending the existing interfaces to inherit from it (which isn't really any better than what i'm doing now).
  • just do this:
export function appendCustomParams(
  oldOptions: { [key: string]: any; },
  newOptions:
    | IQueryFeaturesRequestOptions
    | IAddFeaturesRequestOptions
    | IUpdateFeaturesRequestOptions
    | IDeleteFeaturesRequestOptions
) { /**/ }

Copy link
Member

Choose a reason for hiding this comment

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

for some reason it doesn't bother TypeScript (or me).

sorry, it bothers the shit out of me. It's not you, it's TS.

I suspect the problem is the [key: string]: any in IQueryFeaturesRequestOptions is what causes the Element implicitly has any error when you use a union type for oldOptions. Can we remove that?

Also, if you don't want to deal w/ this, just LMK and I'll pull and try to reason through it myself.

Copy link
Member

@tomwayson tomwayson left a comment

Choose a reason for hiding this comment

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

Nice work @jgravois.

I made a couple of minor suggestions.

I think this achieves what @patrickarlt suggested in #137 (comment), but I think he should review and weigh in as well.

@tomwayson tomwayson requested a review from patrickarlt June 7, 2018 16:16
@tomwayson
Copy link
Member

One other thing, should we add links to the REST API docs for each of the CUD request options interfaces the same way I did for the query request options.

@tomwayson
Copy link
Member

Hm... I'm confused that link doesn't make its way to the docs: https://esri.github.io/arcgis-rest-js/api/feature-service/IQueryFeaturesRequestOptions/

Copy link
Contributor Author

@jgravois jgravois left a comment

Choose a reason for hiding this comment

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

When i was addressing @tomwayson's excellent feedback, i also went ahead and split out the source code into distinct files to make it more legible going forward.

I'm confused that link doesn't make its way to the docs: http://esri.github.io/arcgis-rest-js/api/feature-service/IQueryFeaturesRequestOptions

this was just because of the newline (and fixed now)

@jgravois jgravois force-pushed the chore/feature-service-params branch from 55b000c to e84da39 Compare June 7, 2018 21:46
jgravois added 2 commits June 7, 2018 15:12
…p leaning on params directly

AFFECTS PACKAGES:
@esri/arcgis-rest-common-types
@esri/arcgis-rest-feature-service
@jgravois jgravois force-pushed the chore/feature-service-params branch from e84da39 to dd1e4c7 Compare June 7, 2018 22:12
Copy link
Member

@tomwayson tomwayson left a comment

Choose a reason for hiding this comment

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

Merge at will

@jgravois jgravois merged commit c0a881b into master Jun 8, 2018
@jgravois jgravois deleted the chore/feature-service-params branch June 8, 2018 00:06
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.

3 participants