Hi @lastmjs, I’m trying out Azle for the first time and have successfully migrated a simple Rust canister. Everything was really straight forward, great stuff!
I have run into one small thing though. It seems Azle generates new did files and overwrites any manually created ones? I have this did from my Rust canister:
type Name = text;
type AvatarUrl = text;
type UserProfile = record {
address : text;
name : text;
avatar_url : text;
};
type GetMyProfileResponse = variant {
Ok : UserProfile;
Err : text;
};
type SaveMyProfileResponse = variant {
Ok : UserProfile;
Err : text;
};
type ListProfilesResponse = variant {
Ok : vec record { text; UserProfile };
Err : text;
};
service : (principal) -> {
"get_my_profile" : () -> (GetMyProfileResponse) query;
"list_profiles" : () -> (ListProfilesResponse) query;
"save_my_profile" : (Name, AvatarUrl) -> (SaveMyProfileResponse);
};
So, those are essentially the same, except for the named response types. But I like having named response types in the did, it increases readability and makes the frontend code happier. Is there an option perhaps, not to compact the did? Or am I doing something weird elsewhere that causes this?
There is currently no option to turn off automatic Candid generation in Azle. We could of course add the feature but this is the first time anyone has really asked (we’ve discussed it before).
Especially with a simple app like this that looks like it wants to be consumed by a more traditional client like a web application, have a look at the new REST-based Azle paradigm.
Nice! One alternative to turning generation off would be to generate the types if properly specified in the code. This approach takes more work of course.
const GetMyProfileResponse = Variant({
Ok: UserProfile,
Err: text,
});
export type GetMyProfileResponse = typeof GetMyProfileResponse.tsType;
export const get_my_profile = query(
[],
GetMyProfileResponse,
(): GetMyProfileResponse => {
const profile = profileStore.profiles[ic.caller().toString()];
if (!profile) return { Err: "No profile found for the given address" };
return { Ok: profile };
}
);
Like, if a return type is specified and the type is exported, then include it in the did.
Yes, I like that approach, it is good for folks familiar with Express and Node.
I believe the Candid approach has its merits as well though. Especially for a simple app like the demo I’m working on. With a properly typed DID, the DX for setting up a small app is great!
Implement backend Canister with Azle. Fully typed DID is generated on build.
dfx generate is included as part of the frontend build script = frontend gets access to the DID types.
Add ic-use-actor to the frontend (React) and connect the hook with your did and idlFactory
Use the created hook in your components and enjoy fully typed responses. Changes made to the backend are always available to the frontend without having to manage any separate type files.
Adding Express on top of the RPC functionality that IC already provides is I’m sure a good idea in some circumstances. Ideally, the developer have the option to choose. Not overwriting manually created DIDs (or generating fully typed) leaves the choice with the dev.
I was about to upgrade to new Azle version but ran into an issue. podman has not been required prior to this version, right? Unfortunately, it reliably crashes my computer during the build. No errors or warnings, just freeze and reboot. Mac M1, OS 12.2.1
Can you follow the linked steps? You may be running into the exact problem linked to in those steps. I am also very interested to know the output you get after deploying with AZLE_VERBOSE=true, especially knowing what the last output is before the hang/crash.
I followed the steps you outline but podman crashes at the “Waiting fo WM…” step. I also tried some of the tricks in the referenced issue, such as installing podman desktop. But, no luck so far, podman desktop also crashes, no Azle reference.
Is it possible you’re running out of disk space? Another dev with a Mac had some initial problems with Podman and it ended up being that Podman was taking a lot of disk space…he was able to limit the disk space somehow, if that seems to be the issue i can find out exactly how he fixed it.