Skip to content

JavaScript target IDL type object exports and factory function deprecations#665

Merged
ilbertt merged 7 commits into
dfinity:nextfrom
demergent-labs:javascript_exports
Aug 18, 2025
Merged

JavaScript target IDL type object exports and factory function deprecations#665
ilbertt merged 7 commits into
dfinity:nextfrom
demergent-labs:javascript_exports

Conversation

@lastmjs

@lastmjs lastmjs commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

Overview

The JavaScript target would be more useful (especially to Azle developers) if it exported the IDL type objects that it generates. We also no longer need the factory functions as of 3.0.0, thus we will mark them deprecated and provide direct exports for that previous functionality.

Requirements

The JavaScript target should export all of the IDL type objects, including the generated IDL.Service and init args, without the need to use a factory function.

Considerations

There are no breaking changes besides some formatting of the generated JavaScript files. The idflFactory and init functions have been marked as deprecated but not removed. Developers can choose to import the IDL type objects now, but they are not forced to. This is mainly an ergonomic change with deprecations to prepare for a future with the best developer experience by default.

@lastmjs lastmjs requested a review from a team as a code owner July 30, 2025 20:41
@lastmjs lastmjs changed the title improving the JavaScript target with exporting of the IDL type object… improvements to the JavaScript target Jul 30, 2025
@lastmjs lastmjs changed the title improvements to the JavaScript target JavaScript target IDL type object exports and factory function deprecations Jul 30, 2025

@ilbertt ilbertt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm: the use case you are trying to solve is not about being able to programmatically access the args and return types inside functions, right? Otherwise, we may need to export a serviceMethods object, similar to what @nathanosdev was doing in https://github.com/dfinity/candid/pull/610/files#diff-c0a840e21a25105098350b8bb524fa19d48e84949aed98ccbf945da739a1ed79R263-R274.

Btw, we can now make use of the doc comments (similar to what we added in the ts target in #638). I can add them in a separate PR though, so that we keep this one small.

Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/tests/assets/ok/actor.js
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
@lastmjs lastmjs changed the base branch from master to next August 1, 2025 21:55
@lastmjs lastmjs force-pushed the javascript_exports branch 4 times, most recently from f25c3b7 to e52a537 Compare August 7, 2025 21:15

@lastmjs lastmjs left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have addressed all comments and added one more about the naming of idlInitArgs.

Comment thread rust/candid_parser/src/bindings/javascript.rs
@lastmjs lastmjs requested review from ilbertt and nathanosdev August 7, 2025 21:29

@ilbertt ilbertt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've updated the next branch now. Can you merge it into your branch (again)?

For the rest, I just left a few minor comments. I think we are really close to complete it!

Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/tests/assets/ok/actor.js
Comment thread rust/candid_parser/src/bindings/javascript.rs
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
@lastmjs lastmjs force-pushed the javascript_exports branch from fc0f2a8 to 3ef2028 Compare August 11, 2025 17:31
@lastmjs lastmjs requested a review from ilbertt August 11, 2025 17:46

@ilbertt ilbertt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Already pre-approving, with just a couple of improvements that are not strictly necessary.

Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
@lastmjs lastmjs requested a review from ilbertt August 11, 2025 20:29

@ilbertt ilbertt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I plan to test these changes in a fresh project that uses both agent-js v2 and v3, to check that we don't have regressions. Once done, I'll merge the PR.

@ilbertt ilbertt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If there are no type definitions, the generated file has one more empty line between import statements and export const idlService. Not a big deal, can be left as it is.

Comment thread rust/candid_parser/src/bindings/javascript.rs
Comment thread rust/candid_parser/src/bindings/javascript.rs Outdated
@ilbertt

ilbertt commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

I plan to test these changes in a fresh project that uses both agent-js v2 and v3, to check that we don't have regressions. Once done, I'll merge the PR.

Update: I've tested the generated bindings with both agent-js v2 and v3, locally and on mainnet, and I couldn't find any regression.

@lastmjs lastmjs requested a review from ilbertt August 18, 2025 17:58
@ilbertt ilbertt merged commit 5f419c5 into dfinity:next Aug 18, 2025
5 of 6 checks passed
@ilbertt ilbertt mentioned this pull request Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants