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

Adding toText to Value and Type #6

Merged
merged 4 commits into from
Mar 10, 2023
Merged

Adding toText to Value and Type #6

merged 4 commits into from
Mar 10, 2023

Conversation

Gekctek
Copy link
Collaborator

@Gekctek Gekctek commented Feb 5, 2023

No description provided.

@Gekctek
Copy link
Collaborator Author

Gekctek commented Feb 5, 2023

@fermartz This is the start of the work for #5
Right now I just have the Value.toText(...) implemented. I want to do the Types as well
Im basing my text off of the candid reference: https://internetcomputer.org/docs/current/references/candid-ref
If you look at the ValueTests.mo you can see the expected outputs for each value and at the end there is the advanced options
A mapper that gives you an unknown tag hash value and returns a Text if there is a mapping, otherwise return null
A function to override toText for specific values. if null is returned, will use default

tagHashMapper = ?(
    func(h : Hash.Hash) : ?Text {
        switch (h) {
            case (3) ?"\"hello\"";
            case (_) null;
        };
    },
);
toTextOverride = ?(
    func(v : Value.Value) : ?Text {
        switch (v) {
            // Maps booleans to have a question mark
            case (#bool(b)) ?(Bool.toText(b) # "?");
            case (_) null;
        };
    },
);

Any thoughts/concerns are welcome, still a work in progress.
Also adding this has made me realize a few design mistakes I made in the current version, so Im going to be making some breaking changes:

  • #null, #func, etc.. will change to #null, #func, etc... because apparently that is the correct way to escape reserved words in motoko
  • TransparencyState = { #opaque; #transparent(t) } is not only confusing but annoying to deal with. Its really just something that should live at the encoding level. And plus there isnt really much support or usage of #opaque right now, so im going to be removing or changing that
  • #opt(?Value) is changing to #opt(Value) because #opt(#null_) is the same as #opt(null).

I have other priorities this week so Im not sure when ill get time to work on it more. But this seems to be in a good state to try

@fermartz
Copy link

fermartz commented Feb 7, 2023

@Gekctek thank you so much.

I will try it and send you feedback.

🙌

@Gekctek
Copy link
Collaborator Author

Gekctek commented Mar 10, 2023

I have added the toText to Values and Types.

Apparently the build is failing but thats a MOPS regression it seems

@Gekctek Gekctek marked this pull request as ready for review March 10, 2023 19:16
@Gekctek Gekctek merged commit 75d34ee into main Mar 10, 2023
@Gekctek Gekctek deleted the toText branch March 10, 2023 19:16
@Gekctek
Copy link
Collaborator Author

Gekctek commented Mar 10, 2023

now under MOPS package [email protected]

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