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

feat(types): add custom types for authorities, plugins and asset #9

Merged
merged 3 commits into from
Mar 9, 2024

Conversation

shotgunofdeath
Copy link
Contributor

Description

  1. Custom test types for plugins, asset with plugins, authorities are added
  2. New test fetchAsssetWithPlugins() is added
  3. New addAuthorityWithTestFetch test is added, to demonstrate new asset fetching handling
  4. Authority and plugin helpers are moved to this PR.

Copy link
Contributor

@blockiosaurus blockiosaurus left a comment

Choose a reason for hiding this comment

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

This looks great! I'll leave it to @nhanphan to approve since he works more with the devex side of things.

Copy link
Contributor

@nhanphan nhanphan left a comment

Choose a reason for hiding this comment

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

Overall Asset structure looks good, only had minor questions/comments

export type UpdateDelegatePlugin = BasePlugin & UpdateDelegate;

export type PluginsList = {
reserved?: ReservedPlugin;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should hide this (i.e. skip it, it should not appear on the asset)

Copy link
Contributor Author

@shotgunofdeath shotgunofdeath Mar 7, 2024

Choose a reason for hiding this comment

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

Done. 3e741c6

Though, I'm not sure what a more convenient way to handle this with mapping functions would be. I have 2 options:

  1. For now, I restrict that on the type level. It means that when using map helpers and working with Kinobi-generated Plugin type we will have to check if a plugin is not of a Reserved kind. (e.g. registryRecordsToPluginsList())
  2. We might allow accept the Plugin type as is, but then we will have to return null/undefined, when mapping a plugin. And if it's used in loops, we'll have to filter those null/undefined.

Do you have any thoughts on that?

permanent?: Array<PublicKey>;
};

export type BasePlugin = {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add offset as well. IIRC it's in the registry per plugin just in case anyone wants to do binary stuff with the underlying uint8 array

Copy link
Contributor Author

@shotgunofdeath shotgunofdeath Mar 7, 2024

Choose a reason for hiding this comment

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

Done. 3e741c6

};
}

export function formPluginRegistry({
Copy link
Contributor

Choose a reason for hiding this comment

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

when would you imagine we use formPluginRegistry and formPluginWithAuthorities since I think the original thought was to use them for the t.like(asset,... things. Were you thinking that we'd also use them to submit instructions via say create or something?

Copy link
Contributor Author

@shotgunofdeath shotgunofdeath Mar 7, 2024

Choose a reason for hiding this comment

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

I've written the explanations on this topic in Slack. Let me copy it here:

So, if we go with custom types we can probably drop a couple of plugin helpers, namely formPluginRegistry() and formPluginWithAuthorities() since we won't have the registry field and the AssetWithPlugins type will have a different structure. formPluginHeader() might still be useful, because we decided to leave the pluginHeader field.

I don't see use cases for that couple of helpers yet. Removed those for now. 3e741c6

import { AssetWithPluginsTest, PluginsList } from './types';
import { registryRecordsToPluginsList } from './pluginHelpers';

export async function fetchAssetWithPluginsTest(
Copy link
Contributor

Choose a reason for hiding this comment

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

@blockiosaurus thoughts on just straight overriding fetchAsset with this? i.e. the client lib exposes this as fetchAsset and don't expose the generated fetchAsset?

is there any reason not to deserialize the whole thing always since it's in a single account?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm conflicted. I do like having an explicit fetch with plugins but maybe that'll just be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible, that someone would like to fetch an asset without plugins?

Copy link
Contributor

@nhanphan nhanphan left a comment

Choose a reason for hiding this comment

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

besides feedback from @blockiosaurus on that one comment, this looks good to me. we should replicate the same thing (in another PR/change) to collection as well.

@shotgunofdeath
Copy link
Contributor Author

@nhanphan @blockiosaurus

143e99b

The old fetchAssetWithPlugins() is replaced with the new one and used in tests.
The new fetchCollectionWithPlugins() is added and also used in tests
Types/naming/mapping funcs are updated according to recent changes.

P.S. Couldn't use fetchAsset() for new fetch funcs, since we need maybeAccount there and it's not returned by fetchAsset()

@shotgunofdeath shotgunofdeath marked this pull request as ready for review March 9, 2024 13:41
@nhanphan nhanphan merged commit 39233b6 into main Mar 9, 2024
8 of 9 checks passed
@nhanphan nhanphan deleted the feat/custom-types branch March 9, 2024 18:57
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.

3 participants