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

#179 Consistently use URI object in APIs #121

Merged
merged 5 commits into from
Nov 11, 2022
Merged

#179 Consistently use URI object in APIs #121

merged 5 commits into from
Nov 11, 2022

Conversation

ndoschek
Copy link
Contributor

@ndoschek ndoschek commented Nov 9, 2022

Consistently use URI object in APIs

  • 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

Update dev-example to ModelServerClient V2

  • 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

General

  • Remove simple-import-sort eslint plugin as it interferes with the built-in import sort
  • Ignore zipped rolling log files
  • Fix launch configs

Part of eclipse-emfcloud/emfcloud#179

Contributed on behalf of STMicroelectronics

- 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
@ndoschek ndoschek requested a review from cdamus November 9, 2022 16:30
Copy link
Contributor

@eneufeld eneufeld left a 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.

examples/dev-example/src/browser/api-test-menu.ts Outdated Show resolved Hide resolved
examples/dev-example/src/browser/api-test-menu.ts Outdated Show resolved Hide resolved
private intervalId: NodeJS.Timeout;

subscribe(modeluri: string, options: SubscriptionOptions = {}): void {
subscribe(modeluri: URI, listener?: SubscriptionListener, options: SubscriptionOptionsV2 = {}): SubscriptionListener {
Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up ticket: #124

examples/dev-example/src/node/model-server-client.ts Outdated 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
@ndoschek ndoschek requested a review from eneufeld November 10, 2022 12:53
Copy link
Contributor

@cdamus cdamus left a 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>;
Copy link
Contributor

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?

Copy link
Contributor

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.

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 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

Copy link
Contributor

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;
Copy link
Contributor

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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).

- 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
Copy link
Contributor

@eneufeld eneufeld left a 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.

@ndoschek ndoschek merged commit 6238c88 into master Nov 11, 2022
@ndoschek ndoschek deleted the issues/179 branch November 11, 2022 10:40
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