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

Use TS Morph to generate type predicates #1278

Closed
wants to merge 0 commits into from

Conversation

Roaders
Copy link
Contributor

@Roaders Roaders commented Jul 19, 2024

adresses #1268

This is a very rough cut and really just proves that what I was planning does work.

We could generate the predicates in a different file if we wanted to. We could also generate union types of the request and response messages if we wanted to.

I had some issues getting ts-node working initially hence the extra tsconfig file. We can move the generate-type-predicates file into the root of the project if desired.


THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE FINOS CORPORATE CONTRIBUTOR LICENSE AGREEMENT.

THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.

@Roaders
Copy link
Contributor Author

Roaders commented Jul 19, 2024

We should probably run tsc on the generated ts code after generation is complete to make sure it's all good. Does that currently happen?

@Roaders
Copy link
Contributor Author

Roaders commented Jul 19, 2024

we should probably also generate type predicates for the context objects as well.

@kriswest
Copy link
Contributor

We should probably run tsc on the generated ts code after generation is complete to make sure it's all good. Does that currently happen?

We currently just run the type generation and then the linter vai teh prebuild npm script, which I think would error out if there was a problem with the generated code:

"lint": "eslint src/ test/ --ext .ts --fix",

In the fdc3-for-web branch this is now set to happen on a pre-commit hook.

I haven't had time to take a proper look at this PR yet, but I wanted to get you an answer on the above.

@kriswest
Copy link
Contributor

we should probably also generate type predicates for the context objects as well.

Yes we should! This is the PR that touched those last and introduced some util functions based on them: https://github.com/finos/FDC3/pull/1139/files

If you have a minute do please take a look and compare notes.

@kriswest kriswest requested a review from a team as a code owner August 29, 2024 11:06
@Roaders Roaders closed this Oct 15, 2024
@kriswest
Copy link
Contributor

@Roaders do you still want to do this? I had review this (finally) on my todo list for this week and next.

@Roaders
Copy link
Contributor Author

Roaders commented Oct 15, 2024

yes I do. I actually meant to extend it a bit. A union type for all the request messages would be very useful for Discriminated unions and Exhaustiveness checking when handling request messages in the root agent for example.

@Roaders
Copy link
Contributor Author

Roaders commented Oct 15, 2024

oh dammit. I've accidentally closed this. Sorry, I'll raise a new PR.

@Roaders
Copy link
Contributor Author

Roaders commented Oct 15, 2024

New PR: #1387

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.

2 participants