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

feat: new command asyncapi start preview implemented. #1753

Merged
merged 21 commits into from
Apr 5, 2025

Conversation

neoandmatrix
Copy link
Contributor

@neoandmatrix neoandmatrix commented Apr 3, 2025

Description

This PR introduces the changes to implement the new command asyncapi start preview to open the studio in a minimal readOnly mode along with bundling the ref files internally. An argument to file needs to be passed that is to be opened.

Approach :-

  • First after the path to file is passed it is first validated that the file exist. After the validation is complete then using the function findPathsToWatchFromSchemaRef the path to ref files are extracted.
  • This function uses a stack data structure based approach instead of recursion based as in the later one in case of very large schemas memory consumption will be too much and may cause overflow issues. This makes it not optimal to be implemented hence using stack based approach to get all the path to ref files from schema and then adding them to be watched for changes
  • After the files are added to be watched then the server starts and websocket connection starts which before anything sends a verification message preview:connected to the frontend so that frontend of studio can confirm and set the readOnly mode in studio.
  • Then rest of the bundled contents of the file are sent and upon changes to any of the file the modified file is again bundled and message is sent to update the frontend.
  • Also the websocket connection is also validated that the request to establish a websocket connection is coming from localhost and specified port only to further establish that the readOnly is being set through this command only.

Related issue(s)
Resolves #1627

Copy link

changeset-bot bot commented Apr 3, 2025

🦋 Changeset detected

Latest commit: 1e879a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@neoandmatrix neoandmatrix changed the title Preview command feat: new command asyncapi start preview implemented. Apr 3, 2025
@neoandmatrix neoandmatrix force-pushed the preview-command branch 2 times, most recently from ac34adb to d85b480 Compare April 3, 2025 06:45
@neoandmatrix
Copy link
Contributor Author

Below is a attached demo of the same using the latest studio package and a file having ref. As seen from below the when file is updated or changed the changes sync correctly through the websocket.

Screen.Recording.2025-04-03.075657.mp4

If no file is passed studio doesn't start.

image

Also if there is an error while bundling the file like incorrect ref then also studio doesn't start.

image

@neoandmatrix
Copy link
Contributor Author

Hey @Shurtu-gal done with all the changes for the preview command with the approach mentioned as above :-

Approach :- #1753 (comment)

Demo of working with the latest studio :- #1753 (comment).

Just before marking this PR ready for review wanted to confirm one thing that as we are bundling the files should we also allow to use the flags of the bundle command like --base=<value> , --baseDir=<value> .

Please take a look at the approach and the implemented checks form cli side. After confirmation will mark this ready for review and also will add corresponding docs and changeset.

@Shurtu-gal
Copy link
Collaborator

Let me play around with it a bit will let you know.

@neoandmatrix
Copy link
Contributor Author

Let me play around with it a bit will let you know.

Yeah , sure.

Copy link
Collaborator

@Shurtu-gal Shurtu-gal left a comment

Choose a reason for hiding this comment

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

There still some problems.

  1. Reloading the site makes it go away from readOnly and opens a full studio.
  2. The tour guide modal still appears, need to disable that.
  3. Maybe just me but logos not working 🤔

@github-project-automation github-project-automation bot moved this from To Triage to Backlog in CLI - Kanban Apr 3, 2025
@Shurtu-gal
Copy link
Collaborator

Just before marking this PR ready for review wanted to confirm one thing that as we are bundling the files should we also allow to use the flags of the bundle command like --base=<value> , --baseDir=<value>

Yes, we should. The description should be verbose though to explain this.

@neoandmatrix
Copy link
Contributor Author

There still some problems.

  1. Reloading the site makes it go away from readOnly and opens a full studio.
  2. The tour guide modal still appears, need to disable that.
  3. Maybe just me but logos not working 🤔
  1. Yes, it happens but the connection to server is then not there and even the file is not sent but the old one just stored in local storage of browser is used.

I didn't modify this behaviour as the command is preview so i thought refreshing studio is not expected as the changes will already be synchronised through websockets and any way editing a file with ref is not supported either in studio.

  1. In my testing i never faced tour guide even once.

  2. The logos of 🌐 , GitHub as and slack are working for me.

@neoandmatrix
Copy link
Contributor Author

neoandmatrix commented Apr 3, 2025

Just before marking this PR ready for review wanted to confirm one thing that as we are bundling the files should we also allow to use the flags of the bundle command like --base=<value> , --baseDir=<value>

Yes, we should. The description should be verbose though to explain this.

Okay will do. So should i add all the flags of bundle or just these mentioned two?

@Shurtu-gal
Copy link
Collaborator

Okay will do. So, should I add all the flags of bundle or just these mentioned two?

help and output not needed only thing left is xOrigin you can add that as well.

@neoandmatrix
Copy link
Contributor Author

Okay will do. So, should I add all the flags of bundle or just these mentioned two?

help and output not needed only thing left is xOrigin you can add that as well.

Okay. Will do.

…iew function with additional parameters for base, baseDir, and xOrigin
@neoandmatrix
Copy link
Contributor Author

neoandmatrix commented Apr 3, 2025

There still some problems.

  1. Reloading the site makes it go away from readOnly and opens a full studio.
  2. The tour guide modal still appears, need to disable that.
  3. Maybe just me but logos not working 🤔
  1. Yes, it happens but the connection to server is then not there and even the file is not sent but the old one just stored in local storage of browser is used.

I didn't modify this behaviour as the command is preview so i thought refreshing studio is not expected as the changes will already be synchronised through websockets and any way editing a file with ref is not supported either in studio.

  1. In my testing i never faced tour guide even once.
  2. The logos of 🌐 , GitHub as and slack are working for me.

Also anything on these, are modifications required or will work?

For first maybe we can add that refresh is not allowed in this mode.

@Shurtu-gal
Copy link
Collaborator

Yep, its fine then. Will try once more.

@neoandmatrix
Copy link
Contributor Author

Yep, its fine then. Will try once more.

Sure, let me know if anything else is also expected but i missed. When all good will mark this ready for review and will add docs.

Copy link
Collaborator

@Shurtu-gal Shurtu-gal left a comment

Choose a reason for hiding this comment

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

Just some final things:

@Shurtu-gal
Copy link
Collaborator

After resolving the above just add docs and mark it ready for review 🚀

@neoandmatrix
Copy link
Contributor Author

Usage documentation added.

image

@neoandmatrix neoandmatrix marked this pull request as ready for review April 3, 2025 18:50
@neoandmatrix
Copy link
Contributor Author

Everything done @Shurtu-gal . Please review. The failing test as known will only be solved after the merge of #1748.

Copy link
Collaborator

@Shurtu-gal Shurtu-gal left a comment

Choose a reason for hiding this comment

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

Awesome job! LGTM 🚀

Copy link

sonarqubecloud bot commented Apr 5, 2025

@Shurtu-gal Shurtu-gal merged commit d17aa54 into asyncapi:master Apr 5, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in CLI - Kanban Apr 5, 2025
@asyncapi-bot asyncapi-bot added the bounty AsyncAPI Bounty program related label label Apr 7, 2025
@aeworxet
Copy link
Contributor

aeworxet commented Apr 7, 2025

@asyncapi/bounty_team

@aeworxet aeworxet moved this to Completed in Bounty Program Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty AsyncAPI Bounty program related label
Projects
Status: Completed
Status: Done
Development

Successfully merging this pull request may close these issues.

[FEATURE] introduce new command asyncapi start preview
4 participants