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

lang, ts: decamelize idl #912

Closed
wants to merge 33 commits into from

Conversation

kevinheavey
Copy link
Contributor

@kevinheavey kevinheavey commented Oct 22, 2021

Summary of changes:

  • Takes IDL camel-casing out of the Rust code
  • Adds camelization logic to the Program constructor in the TS code so that this._idl still looks like it did before, even though the IDL file no longer has camelization everywhere. Also adds some stuff to make the type checking happy with this new arrangement.

The idl.ts changes look like a lot more than they are. It's just going through each property in the IDL and adding 🐫 where needed.

Closes #896

@sungoki
Copy link

sungoki commented Oct 24, 2021

Please do this! I don't think there should be any transformations done when generating the IDL.

@kevinheavey kevinheavey changed the title Decamelize idl lang, ts: decamelize idl Nov 4, 2021
@paul-schaaf
Copy link
Contributor

@kevinheavey apart from the merge conflicts, is this ready for review?

@kevinheavey
Copy link
Contributor Author

@kevinheavey apart from the merge conflicts, is this ready for review?

Yes!

@paul-schaaf
Copy link
Contributor

paul-schaaf commented Apr 19, 2022

I updated this PR so it no longer has any conflicts but while doing so I realised that there's more work to be done.

It's been a while so let me begin by asking if youre still interested in working/have the time to work on this PR?

The problem is as follows. The idl generation no longer generates camelCase code. This means that the types.ts is also not camelcased. A program in the ts client is created like thisProgram<IDL> where IDL comes from the types.ts file.
Thanks to the new camelCasing code in the ts client, you can still call functions using camel case but their type is snake_case. This is because of this signature function camelCaseIdl<IDL extends Idl = Idl>(rawIdl: RawIdl): IDL. camelCase returns a type of IDL which is snake_case type from the types.ts file.

  • one quick fix is to adjust the idl generation code so it generates the idl with no changes but the types.ts file with camelCase. If we do this, do we even need any camelcasing code in the ts client? I guess so because the functions and other variables still have to be attached to the dynamic client. Does that sound right?
  • another fix is to use some advanced typescript wrapper types that turn their inner type into a camelcased one

I lean towards just having types.ts be camelCased so the ts types code doesn't get more complicated than it already is and because it makes sense to me that a ts field has the expected casing for a ts file

@kevinheavey
Copy link
Contributor Author

Yeah I don't have time to work on this for the next while 😅 but I agree that this option seems better:

one quick fix is to adjust the idl generation code so it generates the idl with no changes but the types.ts file with camelCase

@paul-schaaf
Copy link
Contributor

ok thanks for letting me know Ill finish it then!

@Juici
Copy link
Contributor

Juici commented Apr 27, 2022

I updated this PR so it no longer has any conflicts but while doing so I realised that there's more work to be done.

It's been a while so let me begin by asking if youre still interested in working/have the time to work on this PR?

The problem is as follows. The idl generation no longer generates camelCase code. This means that the types.ts is also not camelcased. A program in the ts client is created like thisProgram<IDL> where IDL comes from the types.ts file. Thanks to the new camelCasing code in the ts client, you can still call functions using camel case but their type is snake_case. This is because of this signature function camelCaseIdl<IDL extends Idl = Idl>(rawIdl: RawIdl): IDL. camelCase returns a type of IDL which is snake_case type from the types.ts file.

* one quick fix is to adjust the idl generation code so it generates the idl with no changes but the types.ts file with camelCase. If we do this, do we even need any camelcasing code in the ts client? I guess so because the functions and other variables still have to be attached to the dynamic client. Does that sound right?

* another fix is to use some advanced typescript wrapper types that turn their inner type into a camelcased one

I lean towards just having types.ts be camelCased so the ts types code doesn't get more complicated than it already is and because it makes sense to me that a ts field has the expected casing for a ts file

I've written a demo of type level camel casing, but whilst it works perfectly it's horrifically slow; it takes a few seconds to convert one type to camel case. The biggest problem is TypeScripts lack of type level range comparisons, so I have to generate large unicode table types for checks.

https://github.com/Juici/camelcase-ts

@Juici
Copy link
Contributor

Juici commented Apr 30, 2022

I've improved upon my demo and the performance is much better now. It can now reasonably convert type strings to camel case in real-time.

@Henry-E
Copy link
Contributor

Henry-E commented Nov 30, 2022

Seems like maybe something worth revisiting at some stage. Not sure what the current casing behaviour is like

@acheroncrypto acheroncrypto mentioned this pull request Feb 25, 2024
@acheroncrypto acheroncrypto added ts cli idl related to the IDL, either program or client side labels Mar 10, 2024
@acheroncrypto
Copy link
Collaborator

Superseded by #2824.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli idl related to the IDL, either program or client side ts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Defer all camel-casing to the Typescript client
6 participants