-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update enums codecs from latest Web3.js version
This PR updates the JS experimental renderer to use the latest version of the new Web3.js and adjusts the Data Enum and Scalar Enum codecs, now known as Discriminated Union and Enum codecs respectively.
- Loading branch information
1 parent
bc6e82c
commit 0434144
Showing
31 changed files
with
249 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@metaplex-foundation/kinobi": minor | ||
--- | ||
|
||
Update enums codecs from latest Web3.js version on the JS experimental renderer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/renderers/js-experimental/fragments/typeDataEnumHelpers.njk
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/renderers/js-experimental/fragments/typeDiscriminatedUnionHelpers.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Data Enum Helpers. | ||
{% for variant in typeNode.variants %} | ||
{% if variant.kind === 'enumStructVariantTypeNode' %} | ||
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}', data: GetDiscriminatedUnionVariantContent<{{ looseName }}, '__kind', '{{ getVariant(variant.name) }}'>): GetDiscriminatedUnionVariant<{{ looseName }}, '__kind', '{{ getVariant(variant.name) }}'>; | ||
{% elif variant.kind === 'enumTupleVariantTypeNode' %} | ||
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}', data: GetDiscriminatedUnionVariantContent<{{ looseName }}, '__kind', '{{ getVariant(variant.name) }}'>['fields']): GetDiscriminatedUnionVariant<{{ looseName }}, '__kind', '{{ getVariant(variant.name) }}'>; | ||
{% else %} | ||
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}'): GetDiscriminatedUnionVariant<{{ looseName }}, '__kind', '{{ getVariant(variant.name) }}'>; | ||
{% endif %} | ||
{% endfor %} | ||
export function {{ discriminatedUnionFunction }}<K extends {{ looseName }}['{{ discriminatedUnionDiscriminator }}'], Data>( | ||
kind: K, | ||
data?: Data, | ||
) { | ||
return Array.isArray(data) ? { {{ discriminatedUnionDiscriminator }}: kind, fields: data } : { {{ discriminatedUnionDiscriminator }}: kind, ...(data ?? {}) }; | ||
} | ||
|
||
export function {{ isDiscriminatedUnionFunction }}<K extends {{ strictName }}['{{ discriminatedUnionDiscriminator }}']>( | ||
kind: K, | ||
value: {{ strictName }}, | ||
): value is {{ strictName }} & { {{ discriminatedUnionDiscriminator }}: K } { | ||
return value.{{ discriminatedUnionDiscriminator }} === kind; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.