-
Notifications
You must be signed in to change notification settings - Fork 9
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
#179 Consistently use URI object in APIs #121
Conversation
- Remove simple-import-sort eslint plugin as it interferes with the built-in import sort - Ignore zipped rolling log files - Fix launch configs Contributed on behalf of STMicroelectronics
- Use `urijs` as typed URI library - Use URI objects in APIs and internally for proper URI handling - Adapt interfaces, tests - Customize JsonRpcProxyFactory to ensure URI object is correctly typed onRequest/onNotifciation - Configure on backend and frontend for the JsonRpc WebSocketConnection - Rename modeluri to lowercase where applicable for better alignment - Differentiate URI and TheiaURI object - Update README examples Part of eclipse-emfcloud/emfcloud#179 Contributed on behalf of STMicroelectronics
- Update custom DevModelServerClient - Update api-test-menu - User URIs to trigger commands - Refine notification printing - Add test commands that edit via JSON patch commands - Remove xmi test commands as they are not relevant anymore Contributed on behalf of STMicroelectronics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good overall. I have some questions and remarks, though.
private intervalId: NodeJS.Timeout; | ||
|
||
subscribe(modeluri: string, options: SubscriptionOptions = {}): void { | ||
subscribe(modeluri: URI, listener?: SubscriptionListener, options: SubscriptionOptionsV2 = {}): SubscriptionListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had multiple examples where the options were set but the listener was undefined. Why use subscription options if no listener is set anyway? This happened in examples/dev-example/src/browser/api-test-menu.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously with v1
, the listener only was a member of the SubscriptionOptions
. With v2
it should be a separate argument (for compatibility reasons, the options member will be used as the listener internally then).
Why use subscription options if no listener is set anyway?
Yes I agree that it might look a bit off, but in the case of the api-test-menu
example we make use of a ModelServerSubscriptionClient
that is initalized once and shows notifications received by opened subscriptions.
Perhaps we could re-work the example application a bit (in a separate ticket) and align the listener usage and also show the request (data like command or patch).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please open a follow up here as suggested by you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up ticket: #124
packages/modelserver-client/src/model-server-client-v2-integration.spec.ts
Show resolved
Hide resolved
- Use URI.equals() for uri comparison checks in tests - Revert unwanted changes in keepAliveInterval in CustomDevModelServerClient - Revert unwanted changes in api-test-menu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks. I have just a few nits to remark on, but possibly not significant enough to need changes.
@@ -28,7 +30,7 @@ export interface ModelServerClientApiV1 { | |||
* @param defaultFormat Optional fallback format that should used when a request method is invoked and no explicit format argument | |||
* has been passed. | |||
*/ | |||
initialize(baseUrl: string, defaultFormat?: string): void | Promise<void>; | |||
initialize(baseUrl: URI, defaultFormat?: string): void | Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about using the URI
type for the HTTP resource/request URL. It's not really exactly an URI. Perhaps instead this should be the Node built-in URL
type. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, the baseUrl is actually an URL (identifying the endpoint location as our jsdoc states) and not an URI, so using the URL type makes sense here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to stick to one type, that makes things a little more unified. Also the documentation of the URI library speaks of URLs being a "subset" of the URIs according to definition: https://medialize.github.io/URI.js/about-uris.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes URLs are a subset. In the end in doesn't matter. I agree that for code simplification it make sense to stick to one type.
@@ -234,7 +240,7 @@ describe('Integration tests for ModelServerClientV2', () => { | |||
const notification = await patchNotification; | |||
const patch = notification.patch; | |||
|
|||
expect(notification.modelUri).to.be.equal(modeluri); | |||
expect(notification.modeluri.equals(modeluri)).to.be.true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only quibble with this is that it loses the presentation of the string comparison when the test fails, which is highly informative in the test report.
Is there a good reason not to test equality of the toString() conversions of the URIs? I wouldn't go so far as to implement a Chai assertion just for equality testing of URIs ... 😀
(there are many more occurrences of this throughout the tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the docs, the equals method does things like normalization and also ignores the order of query parameters. This is probably not needed here in the tests, but still cleaner imho.
The expect
accepts a second parameter, which we should use to provide an error message which is helpful.
@cdamus, @ndoschek what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree, thanks for that hint, I didn't think of that earlier, I will revert the changes from the first review cycle and go back to string comparisons for better test output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the second parameter for a better failure error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I didn't see your comment earlier. As discussed we will stick to the string comparisons for now and will create dedicated URI tests in a follow up (see #123 ) where we should test all varieties (e.g. relative hierarchies, random order of query parameters).
packages/modelserver-client/src/model-server-client-v2-integration.spec.ts
Outdated
Show resolved
Hide resolved
- Revert URI.equals() checks and use sring comparison checks in tests for better test result output - Rename variable to `patch` in model-server-client-v2-integration.spec.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks good.
Consistently use URI object in APIs
urijs
as typed URI libraryUpdate dev-example to ModelServerClient V2
General
Part of eclipse-emfcloud/emfcloud#179
Contributed on behalf of STMicroelectronics