@codama/renderers-js 1.3.1 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.node.cjs +201 -190
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +75 -64
- package/dist/index.node.mjs.map +1 -1
- package/dist/templates/fragments/instructionParseFunction.njk +1 -1
- package/dist/templates/fragments/programErrors.njk +1 -1
- package/dist/templates/fragments/typeDecoder.njk +1 -1
- package/dist/templates/fragments/typeEncoder.njk +1 -1
- package/dist/templates/pages/sharedPage.njk +2 -2
- package/dist/types/fragments/accountType.d.ts.map +1 -1
- package/dist/types/fragments/instructionData.d.ts.map +1 -1
- package/dist/types/fragments/typeCodec.d.ts +2 -0
- package/dist/types/fragments/typeCodec.d.ts.map +1 -1
- package/dist/types/fragments/typeDecoder.d.ts +2 -0
- package/dist/types/fragments/typeDecoder.d.ts.map +1 -1
- package/dist/types/fragments/typeEncoder.d.ts +2 -0
- package/dist/types/fragments/typeEncoder.d.ts.map +1 -1
- package/dist/types/fragments/typeWithCodec.d.ts +2 -0
- package/dist/types/fragments/typeWithCodec.d.ts.map +1 -1
- package/dist/types/getRenderMapVisitor.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.node.mjs
CHANGED
|
@@ -498,6 +498,7 @@ function getAccountSizeHelpersFragment(scope) {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
// src/fragments/accountType.ts
|
|
501
|
+
import { resolveNestedTypeNode } from "@codama/nodes";
|
|
501
502
|
import { getLastNodeFromPath as getLastNodeFromPath4 } from "@codama/visitors-core";
|
|
502
503
|
|
|
503
504
|
// src/fragments/type.ts
|
|
@@ -516,30 +517,36 @@ function getTypeFragment(scope) {
|
|
|
516
517
|
}
|
|
517
518
|
|
|
518
519
|
// src/fragments/typeDecoder.ts
|
|
520
|
+
import { isDataEnum, isNode as isNode3 } from "@codama/nodes";
|
|
519
521
|
function getTypeDecoderFragment(scope) {
|
|
520
|
-
const { name, manifest, nameApi, docs = [] } = scope;
|
|
522
|
+
const { name, node, manifest, nameApi, docs = [] } = scope;
|
|
521
523
|
const decoderType = typeof scope.size === "number" ? "FixedSizeDecoder" : "Decoder";
|
|
524
|
+
const useTypeCast = isNode3(node, "enumTypeNode") && isDataEnum(node) && typeof scope.size === "number";
|
|
522
525
|
return fragmentFromTemplate("typeDecoder.njk", {
|
|
523
526
|
decoderFunction: nameApi.decoderFunction(name),
|
|
524
527
|
decoderType,
|
|
525
528
|
docs,
|
|
526
529
|
looseName: nameApi.dataArgsType(name),
|
|
527
530
|
manifest,
|
|
528
|
-
strictName: nameApi.dataType(name)
|
|
531
|
+
strictName: nameApi.dataType(name),
|
|
532
|
+
useTypeCast
|
|
529
533
|
}).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore", `type ${decoderType}`);
|
|
530
534
|
}
|
|
531
535
|
|
|
532
536
|
// src/fragments/typeEncoder.ts
|
|
537
|
+
import { isDataEnum as isDataEnum2, isNode as isNode4 } from "@codama/nodes";
|
|
533
538
|
function getTypeEncoderFragment(scope) {
|
|
534
|
-
const { name, manifest, nameApi, docs = [] } = scope;
|
|
539
|
+
const { name, node, manifest, nameApi, docs = [] } = scope;
|
|
535
540
|
const encoderType = typeof scope.size === "number" ? "FixedSizeEncoder" : "Encoder";
|
|
541
|
+
const useTypeCast = isNode4(node, "enumTypeNode") && isDataEnum2(node) && typeof scope.size === "number";
|
|
536
542
|
return fragmentFromTemplate("typeEncoder.njk", {
|
|
537
543
|
docs,
|
|
538
544
|
encoderFunction: nameApi.encoderFunction(name),
|
|
539
545
|
encoderType,
|
|
540
546
|
looseName: nameApi.dataArgsType(name),
|
|
541
547
|
manifest,
|
|
542
|
-
strictName: nameApi.dataType(name)
|
|
548
|
+
strictName: nameApi.dataType(name),
|
|
549
|
+
useTypeCast
|
|
543
550
|
}).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore", `type ${encoderType}`);
|
|
544
551
|
}
|
|
545
552
|
|
|
@@ -585,6 +592,7 @@ function getAccountTypeFragment(scope) {
|
|
|
585
592
|
manifest: typeManifest2,
|
|
586
593
|
name: accountNode.name,
|
|
587
594
|
nameApi,
|
|
595
|
+
node: resolveNestedTypeNode(accountNode.data),
|
|
588
596
|
size: scope.size
|
|
589
597
|
});
|
|
590
598
|
}
|
|
@@ -594,7 +602,7 @@ import {
|
|
|
594
602
|
constantDiscriminatorNode,
|
|
595
603
|
constantValueNode,
|
|
596
604
|
constantValueNodeFromBytes,
|
|
597
|
-
isNode as
|
|
605
|
+
isNode as isNode5,
|
|
598
606
|
isNodeFilter as isNodeFilter2
|
|
599
607
|
} from "@codama/nodes";
|
|
600
608
|
import { visit } from "@codama/visitors-core";
|
|
@@ -602,13 +610,13 @@ import { getBase64Decoder } from "@solana/codecs-strings";
|
|
|
602
610
|
function getDiscriminatorConditionFragment(scope) {
|
|
603
611
|
return mergeFragments(
|
|
604
612
|
scope.discriminators.flatMap((discriminator) => {
|
|
605
|
-
if (
|
|
613
|
+
if (isNode5(discriminator, "sizeDiscriminatorNode")) {
|
|
606
614
|
return [getSizeConditionFragment(discriminator, scope)];
|
|
607
615
|
}
|
|
608
|
-
if (
|
|
616
|
+
if (isNode5(discriminator, "constantDiscriminatorNode")) {
|
|
609
617
|
return [getByteConditionFragment(discriminator, scope)];
|
|
610
618
|
}
|
|
611
|
-
if (
|
|
619
|
+
if (isNode5(discriminator, "fieldDiscriminatorNode")) {
|
|
612
620
|
return [getFieldConditionFragment(discriminator, scope)];
|
|
613
621
|
}
|
|
614
622
|
return [];
|
|
@@ -632,7 +640,7 @@ function getFieldConditionFragment(discriminator, scope) {
|
|
|
632
640
|
`Field discriminator "${discriminator.name}" does not have a matching argument with default value.`
|
|
633
641
|
);
|
|
634
642
|
}
|
|
635
|
-
if (
|
|
643
|
+
if (isNode5(field.type, "arrayTypeNode") && isNode5(field.type.item, "numberTypeNode") && field.type.item.format === "u8" && isNode5(field.type.count, "fixedCountNode") && isNode5(field.defaultValue, "arrayValueNode") && field.defaultValue.items.every(isNodeFilter2("numberValueNode"))) {
|
|
636
644
|
const base64Bytes = getBase64Decoder().decode(
|
|
637
645
|
new Uint8Array(field.defaultValue.items.map((node) => node.number))
|
|
638
646
|
);
|
|
@@ -702,7 +710,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
702
710
|
}
|
|
703
711
|
|
|
704
712
|
// src/fragments/instructionByteDelta.ts
|
|
705
|
-
import { assertIsNode, camelCase as camelCase3, isNode as
|
|
713
|
+
import { assertIsNode, camelCase as camelCase3, isNode as isNode6 } from "@codama/nodes";
|
|
706
714
|
import { getLastNodeFromPath as getLastNodeFromPath6 } from "@codama/visitors-core";
|
|
707
715
|
function getInstructionByteDeltaFragment(scope) {
|
|
708
716
|
const { byteDeltas } = getLastNodeFromPath6(scope.instructionPath);
|
|
@@ -716,16 +724,16 @@ const byteDelta: number = [${r.join(",")}].reduce((a, b) => a + b, 0);`
|
|
|
716
724
|
}
|
|
717
725
|
function getByteDeltaFragment(byteDelta, scope) {
|
|
718
726
|
const bytesFragment = (() => {
|
|
719
|
-
if (
|
|
727
|
+
if (isNode6(byteDelta.value, "numberValueNode")) {
|
|
720
728
|
return getNumberValueNodeFragment(byteDelta);
|
|
721
729
|
}
|
|
722
|
-
if (
|
|
730
|
+
if (isNode6(byteDelta.value, "argumentValueNode")) {
|
|
723
731
|
return getArgumentValueNodeFragment(byteDelta);
|
|
724
732
|
}
|
|
725
|
-
if (
|
|
733
|
+
if (isNode6(byteDelta.value, "accountLinkNode")) {
|
|
726
734
|
return getAccountLinkNodeFragment(byteDelta, scope);
|
|
727
735
|
}
|
|
728
|
-
if (
|
|
736
|
+
if (isNode6(byteDelta.value, "resolverValueNode")) {
|
|
729
737
|
return getResolverValueNodeFragment(byteDelta, scope);
|
|
730
738
|
}
|
|
731
739
|
return null;
|
|
@@ -763,6 +771,7 @@ function getResolverValueNodeFragment(byteDelta, scope) {
|
|
|
763
771
|
}
|
|
764
772
|
|
|
765
773
|
// src/fragments/instructionData.ts
|
|
774
|
+
import { structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes2 } from "@codama/nodes";
|
|
766
775
|
import { getLastNodeFromPath as getLastNodeFromPath7 } from "@codama/visitors-core";
|
|
767
776
|
function getInstructionDataFragment(scope) {
|
|
768
777
|
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
@@ -775,6 +784,7 @@ function getInstructionDataFragment(scope) {
|
|
|
775
784
|
manifest: dataArgsManifest,
|
|
776
785
|
name: instructionDataName,
|
|
777
786
|
nameApi,
|
|
787
|
+
node: structTypeNodeFromInstructionArgumentNodes2(instructionNode.arguments),
|
|
778
788
|
size: scope.size
|
|
779
789
|
});
|
|
780
790
|
}
|
|
@@ -782,7 +792,7 @@ function getInstructionDataFragment(scope) {
|
|
|
782
792
|
// src/fragments/discriminatorConstants.ts
|
|
783
793
|
import {
|
|
784
794
|
camelCase as camelCase4,
|
|
785
|
-
isNode as
|
|
795
|
+
isNode as isNode7,
|
|
786
796
|
isNodeFilter as isNodeFilter3,
|
|
787
797
|
VALUE_NODES
|
|
788
798
|
} from "@codama/nodes";
|
|
@@ -813,7 +823,7 @@ function getConstantDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
|
813
823
|
function getFieldDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
814
824
|
const { fields, prefix, typeManifestVisitor } = scope;
|
|
815
825
|
const field = fields.find((f) => f.name === discriminatorNode.name);
|
|
816
|
-
if (!field || !field.defaultValue || !
|
|
826
|
+
if (!field || !field.defaultValue || !isNode7(field.defaultValue, VALUE_NODES)) {
|
|
817
827
|
return null;
|
|
818
828
|
}
|
|
819
829
|
const name = camelCase4(`${prefix}_${discriminatorNode.name}`);
|
|
@@ -851,18 +861,18 @@ function getInstructionExtraArgsFragment(scope) {
|
|
|
851
861
|
}
|
|
852
862
|
|
|
853
863
|
// src/fragments/instructionFunction.ts
|
|
854
|
-
import { camelCase as camelCase9, isNode as
|
|
864
|
+
import { camelCase as camelCase9, isNode as isNode12, isNodeFilter as isNodeFilter4, pascalCase as pascalCase5 } from "@codama/nodes";
|
|
855
865
|
import {
|
|
856
866
|
findProgramNodeFromPath as findProgramNodeFromPath3,
|
|
857
867
|
getLastNodeFromPath as getLastNodeFromPath12
|
|
858
868
|
} from "@codama/visitors-core";
|
|
859
869
|
|
|
860
870
|
// src/fragments/instructionInputResolved.ts
|
|
861
|
-
import { camelCase as camelCase6, isNode as
|
|
871
|
+
import { camelCase as camelCase6, isNode as isNode9, parseOptionalAccountStrategy } from "@codama/nodes";
|
|
862
872
|
import { getLastNodeFromPath as getLastNodeFromPath9 } from "@codama/visitors-core";
|
|
863
873
|
|
|
864
874
|
// src/fragments/instructionInputDefault.ts
|
|
865
|
-
import { camelCase as camelCase5, isNode as
|
|
875
|
+
import { camelCase as camelCase5, isNode as isNode8 } from "@codama/nodes";
|
|
866
876
|
import { visit as visit3 } from "@codama/visitors-core";
|
|
867
877
|
function getInstructionInputDefaultFragment(scope) {
|
|
868
878
|
const { input, optionalAccountStrategy, asyncResolvers, useAsync, nameApi, typeManifestVisitor, getImportFrom } = scope;
|
|
@@ -875,7 +885,7 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
875
885
|
const { defaultValue } = input;
|
|
876
886
|
const defaultFragment = (renderedValue, isWritable) => {
|
|
877
887
|
const inputName = camelCase5(input.name);
|
|
878
|
-
if (input.kind === "instructionAccountNode" &&
|
|
888
|
+
if (input.kind === "instructionAccountNode" && isNode8(defaultValue, "resolverValueNode")) {
|
|
879
889
|
return fragment(`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`);
|
|
880
890
|
}
|
|
881
891
|
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
@@ -903,17 +913,17 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
903
913
|
}
|
|
904
914
|
return defaultFragment(`expectAddress(accounts.${name}.value)`).addImports("shared", "expectAddress");
|
|
905
915
|
case "pdaValueNode":
|
|
906
|
-
if (
|
|
916
|
+
if (isNode8(defaultValue.pda, "pdaNode")) {
|
|
907
917
|
const pdaProgram = defaultValue.pda.programId ? fragment(
|
|
908
918
|
`'${defaultValue.pda.programId}' as Address<'${defaultValue.pda.programId}'>`
|
|
909
919
|
).addImports("solanaAddresses", "type Address") : fragment("programAddress");
|
|
910
920
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
911
|
-
if (
|
|
921
|
+
if (isNode8(seed, "constantPdaSeedNode") && isNode8(seed.value, "programIdValueNode")) {
|
|
912
922
|
return [
|
|
913
923
|
fragment(`getAddressEncoder().encode(${pdaProgram.render})`).mergeImportsWith(pdaProgram).addImports("solanaAddresses", "getAddressEncoder")
|
|
914
924
|
];
|
|
915
925
|
}
|
|
916
|
-
if (
|
|
926
|
+
if (isNode8(seed, "constantPdaSeedNode") && !isNode8(seed.value, "programIdValueNode")) {
|
|
917
927
|
const typeManifest2 = visit3(seed.type, typeManifestVisitor);
|
|
918
928
|
const valueManifest2 = visit3(seed.value, typeManifestVisitor);
|
|
919
929
|
return [
|
|
@@ -922,18 +932,18 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
922
932
|
).mergeImportsWith(typeManifest2.encoder, valueManifest2.value)
|
|
923
933
|
];
|
|
924
934
|
}
|
|
925
|
-
if (
|
|
935
|
+
if (isNode8(seed, "variablePdaSeedNode")) {
|
|
926
936
|
const typeManifest2 = visit3(seed.type, typeManifestVisitor);
|
|
927
937
|
const valueSeed = defaultValue.seeds.find((s) => s.name === seed.name)?.value;
|
|
928
938
|
if (!valueSeed) return [];
|
|
929
|
-
if (
|
|
939
|
+
if (isNode8(valueSeed, "accountValueNode")) {
|
|
930
940
|
return [
|
|
931
941
|
fragment(
|
|
932
942
|
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${camelCase5(valueSeed.name)}.value))`
|
|
933
943
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectAddress")
|
|
934
944
|
];
|
|
935
945
|
}
|
|
936
|
-
if (
|
|
946
|
+
if (isNode8(valueSeed, "argumentValueNode")) {
|
|
937
947
|
return [
|
|
938
948
|
fragment(
|
|
939
949
|
`${typeManifest2.encoder.render}.encode(expectSome(args.${camelCase5(valueSeed.name)}))`
|
|
@@ -958,12 +968,12 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
958
968
|
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
959
969
|
const pdaArgs = [];
|
|
960
970
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
961
|
-
if (
|
|
971
|
+
if (isNode8(seed.value, "accountValueNode")) {
|
|
962
972
|
return fragment(
|
|
963
973
|
`${seed.name}: expectAddress(accounts.${camelCase5(seed.value.name)}.value)`
|
|
964
974
|
).addImports("shared", "expectAddress");
|
|
965
975
|
}
|
|
966
|
-
if (
|
|
976
|
+
if (isNode8(seed.value, "argumentValueNode")) {
|
|
967
977
|
return fragment(`${seed.name}: expectSome(args.${camelCase5(seed.value.name)})`).addImports(
|
|
968
978
|
"shared",
|
|
969
979
|
"expectSome"
|
|
@@ -1026,14 +1036,14 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
1026
1036
|
}
|
|
1027
1037
|
const negatedCondition = !ifTrueRenderer;
|
|
1028
1038
|
let condition = "true";
|
|
1029
|
-
if (
|
|
1039
|
+
if (isNode8(defaultValue.condition, "resolverValueNode")) {
|
|
1030
1040
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
1031
1041
|
conditionalFragment.addImports(getImportFrom(defaultValue.condition), conditionalResolverFunction).addFeatures(["instruction:resolverScopeVariable"]);
|
|
1032
1042
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
1033
1043
|
condition = `${conditionalResolverAwait}${conditionalResolverFunction}(resolverScope)`;
|
|
1034
1044
|
condition = negatedCondition ? `!${condition}` : condition;
|
|
1035
1045
|
} else {
|
|
1036
|
-
const comparedInputName =
|
|
1046
|
+
const comparedInputName = isNode8(defaultValue.condition, "accountValueNode") ? `accounts.${camelCase5(defaultValue.condition.name)}.value` : `args.${camelCase5(defaultValue.condition.name)}`;
|
|
1037
1047
|
if (defaultValue.value) {
|
|
1038
1048
|
const comparedValue = visit3(defaultValue.value, typeManifestVisitor).value;
|
|
1039
1049
|
conditionalFragment.mergeImportsWith(comparedValue).mergeFeaturesWith(comparedValue);
|
|
@@ -1084,7 +1094,7 @@ function getInstructionInputResolvedFragment(scope) {
|
|
|
1084
1094
|
const camelName = camelCase6(input.name);
|
|
1085
1095
|
return [
|
|
1086
1096
|
inputFragment.mapRender(
|
|
1087
|
-
(r) =>
|
|
1097
|
+
(r) => isNode9(input, "instructionArgumentNode") ? `if (!args.${camelName}) {
|
|
1088
1098
|
${r}
|
|
1089
1099
|
}` : `if (!accounts.${camelName}.value) {
|
|
1090
1100
|
${r}
|
|
@@ -1105,7 +1115,7 @@ ${r}
|
|
|
1105
1115
|
import {
|
|
1106
1116
|
camelCase as camelCase7,
|
|
1107
1117
|
getAllInstructionArguments,
|
|
1108
|
-
isNode as
|
|
1118
|
+
isNode as isNode10,
|
|
1109
1119
|
parseDocs,
|
|
1110
1120
|
pascalCase as pascalCase4
|
|
1111
1121
|
} from "@codama/nodes";
|
|
@@ -1143,7 +1153,7 @@ function getAccountsFragment(scope) {
|
|
|
1143
1153
|
const resolvedAccount = resolvedInputs.find(
|
|
1144
1154
|
(input) => input.kind === "instructionAccountNode" && input.name === account.name
|
|
1145
1155
|
);
|
|
1146
|
-
const hasDefaultValue = !!resolvedAccount.defaultValue && !
|
|
1156
|
+
const hasDefaultValue = !!resolvedAccount.defaultValue && !isNode10(resolvedAccount.defaultValue, ["identityValueNode", "payerValueNode"]) && (useAsync || !isAsyncDefaultValue(resolvedAccount.defaultValue, asyncResolvers));
|
|
1147
1157
|
const accountDocs = parseDocs(account.docs);
|
|
1148
1158
|
const docblock = accountDocs.length > 0 ? jsDocblock(accountDocs) : "";
|
|
1149
1159
|
const optionalSign = hasDefaultValue || resolvedAccount.isOptional ? "?" : "";
|
|
@@ -1202,7 +1212,7 @@ function getExtraArgumentsFragment(scope) {
|
|
|
1202
1212
|
}
|
|
1203
1213
|
function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
1204
1214
|
const resolvedArg = resolvedInputs.find(
|
|
1205
|
-
(input) =>
|
|
1215
|
+
(input) => isNode10(input, "instructionArgumentNode") && input.name === arg.name
|
|
1206
1216
|
);
|
|
1207
1217
|
if (arg.defaultValue && arg.defaultValueStrategy === "omitted") return null;
|
|
1208
1218
|
const renamedName = renamedArgs.get(arg.name) ?? arg.name;
|
|
@@ -1211,7 +1221,7 @@ function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
|
1211
1221
|
}
|
|
1212
1222
|
function getRemainingAccountsFragment(instructionNode) {
|
|
1213
1223
|
const fragments = (instructionNode.remainingAccounts ?? []).flatMap((remainingAccountsNode) => {
|
|
1214
|
-
if (
|
|
1224
|
+
if (isNode10(remainingAccountsNode.value, "resolverValueNode")) return [];
|
|
1215
1225
|
const { name } = remainingAccountsNode.value;
|
|
1216
1226
|
const allArguments = getAllInstructionArguments(instructionNode);
|
|
1217
1227
|
const argumentExists = allArguments.some((arg) => arg.name === name);
|
|
@@ -1235,7 +1245,7 @@ import {
|
|
|
1235
1245
|
assertIsNode as assertIsNode2,
|
|
1236
1246
|
camelCase as camelCase8,
|
|
1237
1247
|
getAllInstructionArguments as getAllInstructionArguments2,
|
|
1238
|
-
isNode as
|
|
1248
|
+
isNode as isNode11
|
|
1239
1249
|
} from "@codama/nodes";
|
|
1240
1250
|
import { getLastNodeFromPath as getLastNodeFromPath11 } from "@codama/visitors-core";
|
|
1241
1251
|
function getInstructionRemainingAccountsFragment(scope) {
|
|
@@ -1250,10 +1260,10 @@ const remainingAccounts: AccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.join
|
|
|
1250
1260
|
}
|
|
1251
1261
|
function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
1252
1262
|
const remainingAccountsFragment = (() => {
|
|
1253
|
-
if (
|
|
1263
|
+
if (isNode11(remainingAccounts.value, "argumentValueNode")) {
|
|
1254
1264
|
return getArgumentValueNodeFragment2(remainingAccounts, scope);
|
|
1255
1265
|
}
|
|
1256
|
-
if (
|
|
1266
|
+
if (isNode11(remainingAccounts.value, "resolverValueNode")) {
|
|
1257
1267
|
return getResolverValueNodeFragment2(remainingAccounts, scope);
|
|
1258
1268
|
}
|
|
1259
1269
|
return null;
|
|
@@ -1335,7 +1345,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1335
1345
|
const hasExtraArgs = (instructionNode.extraArguments ?? []).filter(
|
|
1336
1346
|
(field) => argIsNotOmitted(field) && (argIsDependent(field) || argHasDefaultValue(field))
|
|
1337
1347
|
).length > 0;
|
|
1338
|
-
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) =>
|
|
1348
|
+
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => isNode12(value, "argumentValueNode")).length > 0;
|
|
1339
1349
|
const hasAnyArgs = hasDataArgs || hasExtraArgs || hasRemainingAccountArgs;
|
|
1340
1350
|
const hasInput = hasAccounts || hasAnyArgs;
|
|
1341
1351
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
@@ -1534,7 +1544,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1534
1544
|
}
|
|
1535
1545
|
|
|
1536
1546
|
// src/fragments/pdaFunction.ts
|
|
1537
|
-
import { isNode as
|
|
1547
|
+
import { isNode as isNode13, isNodeFilter as isNodeFilter5 } from "@codama/nodes";
|
|
1538
1548
|
import { findProgramNodeFromPath as findProgramNodeFromPath6, getLastNodeFromPath as getLastNodeFromPath15, visit as visit4 } from "@codama/visitors-core";
|
|
1539
1549
|
function getPdaFunctionFragment(scope) {
|
|
1540
1550
|
const { pdaPath, typeManifestVisitor, nameApi } = scope;
|
|
@@ -1542,12 +1552,12 @@ function getPdaFunctionFragment(scope) {
|
|
|
1542
1552
|
const programNode = findProgramNodeFromPath6(pdaPath);
|
|
1543
1553
|
const imports = new ImportMap();
|
|
1544
1554
|
const seeds = pdaNode.seeds.map((seed) => {
|
|
1545
|
-
if (
|
|
1555
|
+
if (isNode13(seed, "variablePdaSeedNode")) {
|
|
1546
1556
|
const seedManifest2 = visit4(seed.type, typeManifestVisitor);
|
|
1547
1557
|
imports.mergeWith(seedManifest2.looseType, seedManifest2.encoder);
|
|
1548
1558
|
return { ...seed, typeManifest: seedManifest2 };
|
|
1549
1559
|
}
|
|
1550
|
-
if (
|
|
1560
|
+
if (isNode13(seed.value, "programIdValueNode")) {
|
|
1551
1561
|
imports.add("solanaAddresses", "getAddressEncoder");
|
|
1552
1562
|
return seed;
|
|
1553
1563
|
}
|
|
@@ -1577,7 +1587,7 @@ function getProgramFragment(scope) {
|
|
|
1577
1587
|
}
|
|
1578
1588
|
|
|
1579
1589
|
// src/fragments/programAccounts.ts
|
|
1580
|
-
import { resolveNestedTypeNode } from "@codama/nodes";
|
|
1590
|
+
import { resolveNestedTypeNode as resolveNestedTypeNode2 } from "@codama/nodes";
|
|
1581
1591
|
function getProgramAccountsFragment(scope) {
|
|
1582
1592
|
if (scope.programNode.accounts.length === 0) return fragment("");
|
|
1583
1593
|
return mergeFragments(
|
|
@@ -1611,7 +1621,7 @@ function getProgramAccountsIdentifierFunctionFragment(scope) {
|
|
|
1611
1621
|
dataName: "data",
|
|
1612
1622
|
discriminators: account.discriminators ?? [],
|
|
1613
1623
|
ifTrue: `return ${programAccountsEnum}.${variant};`,
|
|
1614
|
-
struct:
|
|
1624
|
+
struct: resolveNestedTypeNode2(account.data)
|
|
1615
1625
|
});
|
|
1616
1626
|
}),
|
|
1617
1627
|
(r) => r.join("\n")
|
|
@@ -1644,7 +1654,7 @@ function getProgramErrorsFragment(scope) {
|
|
|
1644
1654
|
// src/fragments/programInstructions.ts
|
|
1645
1655
|
import {
|
|
1646
1656
|
getAllInstructionsWithSubs,
|
|
1647
|
-
structTypeNodeFromInstructionArgumentNodes as
|
|
1657
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes3
|
|
1648
1658
|
} from "@codama/nodes";
|
|
1649
1659
|
function getProgramInstructionsFragment(scope) {
|
|
1650
1660
|
if (scope.programNode.instructions.length === 0) return fragment("");
|
|
@@ -1690,7 +1700,7 @@ function getProgramInstructionsIdentifierFunctionFragment(scope) {
|
|
|
1690
1700
|
dataName: "data",
|
|
1691
1701
|
discriminators: instruction.discriminators ?? [],
|
|
1692
1702
|
ifTrue: `return ${programInstructionsEnum}.${variant};`,
|
|
1693
|
-
struct:
|
|
1703
|
+
struct: structTypeNodeFromInstructionArgumentNodes3(instruction.arguments)
|
|
1694
1704
|
});
|
|
1695
1705
|
}),
|
|
1696
1706
|
(r) => r.join("\n")
|
|
@@ -1725,10 +1735,10 @@ function getProgramInstructionsParsedUnionTypeFragment(scope) {
|
|
|
1725
1735
|
}
|
|
1726
1736
|
|
|
1727
1737
|
// src/fragments/typeDiscriminatedUnionHelpers.ts
|
|
1728
|
-
import { isDataEnum, isNode as
|
|
1738
|
+
import { isDataEnum as isDataEnum3, isNode as isNode14 } from "@codama/nodes";
|
|
1729
1739
|
function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
1730
1740
|
const { name, typeNode, nameApi } = scope;
|
|
1731
|
-
const isDiscriminatedUnion =
|
|
1741
|
+
const isDiscriminatedUnion = isNode14(typeNode, "enumTypeNode") && isDataEnum3(typeNode);
|
|
1732
1742
|
if (!isDiscriminatedUnion) {
|
|
1733
1743
|
return fragment("");
|
|
1734
1744
|
}
|
|
@@ -1781,8 +1791,8 @@ import {
|
|
|
1781
1791
|
getAllInstructionsWithSubs as getAllInstructionsWithSubs2,
|
|
1782
1792
|
getAllPdas,
|
|
1783
1793
|
getAllPrograms,
|
|
1784
|
-
resolveNestedTypeNode as
|
|
1785
|
-
structTypeNodeFromInstructionArgumentNodes as
|
|
1794
|
+
resolveNestedTypeNode as resolveNestedTypeNode4,
|
|
1795
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes5
|
|
1786
1796
|
} from "@codama/nodes";
|
|
1787
1797
|
import { RenderMap } from "@codama/renderers-core";
|
|
1788
1798
|
import {
|
|
@@ -1802,16 +1812,16 @@ import {
|
|
|
1802
1812
|
// src/getTypeManifestVisitor.ts
|
|
1803
1813
|
import {
|
|
1804
1814
|
camelCase as camelCase10,
|
|
1805
|
-
isNode as
|
|
1815
|
+
isNode as isNode15,
|
|
1806
1816
|
isNodeFilter as isNodeFilter6,
|
|
1807
1817
|
isScalarEnum,
|
|
1808
1818
|
parseDocs as parseDocs2,
|
|
1809
1819
|
REGISTERED_TYPE_NODE_KINDS,
|
|
1810
1820
|
REGISTERED_VALUE_NODE_KINDS,
|
|
1811
|
-
resolveNestedTypeNode as
|
|
1821
|
+
resolveNestedTypeNode as resolveNestedTypeNode3,
|
|
1812
1822
|
structFieldTypeNode,
|
|
1813
1823
|
structTypeNode,
|
|
1814
|
-
structTypeNodeFromInstructionArgumentNodes as
|
|
1824
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes4
|
|
1815
1825
|
} from "@codama/nodes";
|
|
1816
1826
|
import {
|
|
1817
1827
|
extendVisitor,
|
|
@@ -1883,7 +1893,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1883
1893
|
const decoderImports = new ImportMap().add("solanaCodecsDataStructures", "getBooleanDecoder");
|
|
1884
1894
|
let sizeEncoder = "";
|
|
1885
1895
|
let sizeDecoder = "";
|
|
1886
|
-
const resolvedSize =
|
|
1896
|
+
const resolvedSize = resolveNestedTypeNode3(booleanType.size);
|
|
1887
1897
|
if (resolvedSize.format !== "u8" || resolvedSize.endian !== "le") {
|
|
1888
1898
|
const size = visit5(booleanType.size, self);
|
|
1889
1899
|
encoderImports.mergeWith(size.encoder);
|
|
@@ -1934,7 +1944,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1934
1944
|
return manifest;
|
|
1935
1945
|
},
|
|
1936
1946
|
visitConstantValue(node, { self }) {
|
|
1937
|
-
if (
|
|
1947
|
+
if (isNode15(node.type, "bytesTypeNode") && isNode15(node.value, "bytesValueNode")) {
|
|
1938
1948
|
return visit5(node.value, self);
|
|
1939
1949
|
}
|
|
1940
1950
|
return {
|
|
@@ -2035,7 +2045,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2035
2045
|
const decoderImports = new ImportMap();
|
|
2036
2046
|
const encoderOptions = [];
|
|
2037
2047
|
const decoderOptions = [];
|
|
2038
|
-
const enumSize =
|
|
2048
|
+
const enumSize = resolveNestedTypeNode3(enumType.size);
|
|
2039
2049
|
if (enumSize.format !== "u8" || enumSize.endian !== "le") {
|
|
2040
2050
|
const sizeManifest = visit5(enumType.size, self);
|
|
2041
2051
|
encoderImports.mergeWith(sizeManifest.encoder);
|
|
@@ -2091,7 +2101,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2091
2101
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
2092
2102
|
const importFrom = getImportFrom(node.enum);
|
|
2093
2103
|
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
2094
|
-
const isScalar = enumNode &&
|
|
2104
|
+
const isScalar = enumNode && isNode15(enumNode, "enumTypeNode") ? isScalarEnum(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
2095
2105
|
if (!node.value && isScalar) {
|
|
2096
2106
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
2097
2107
|
manifest.value.setRender(`${enumName}.${variantName2}`).addImports(importFrom, enumName);
|
|
@@ -2136,7 +2146,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2136
2146
|
strict: nameApi.dataType(instructionDataName)
|
|
2137
2147
|
};
|
|
2138
2148
|
const link = customInstructionData.get(instruction.name)?.linkNode;
|
|
2139
|
-
const struct =
|
|
2149
|
+
const struct = structTypeNodeFromInstructionArgumentNodes4(instruction.arguments);
|
|
2140
2150
|
const manifest = link ? visit5(link, self) : visit5(struct, self);
|
|
2141
2151
|
parentName = null;
|
|
2142
2152
|
return manifest;
|
|
@@ -2203,7 +2213,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2203
2213
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2204
2214
|
const encoderOptions = [];
|
|
2205
2215
|
const decoderOptions = [];
|
|
2206
|
-
const optionPrefix =
|
|
2216
|
+
const optionPrefix = resolveNestedTypeNode3(optionType.prefix);
|
|
2207
2217
|
if (optionPrefix.format !== "u8" || optionPrefix.endian !== "le") {
|
|
2208
2218
|
const prefixManifest = visit5(optionType.prefix, self);
|
|
2209
2219
|
childManifest.encoder.mergeImportsWith(prefixManifest.encoder);
|
|
@@ -2477,19 +2487,19 @@ ${jsDocblock(structFieldDocs)}` : "";
|
|
|
2477
2487
|
);
|
|
2478
2488
|
}
|
|
2479
2489
|
function getArrayLikeSizeOption(count, visitor) {
|
|
2480
|
-
if (
|
|
2490
|
+
if (isNode15(count, "fixedCountNode")) {
|
|
2481
2491
|
return {
|
|
2482
2492
|
decoder: fragment(`size: ${count.value}`),
|
|
2483
2493
|
encoder: fragment(`size: ${count.value}`)
|
|
2484
2494
|
};
|
|
2485
2495
|
}
|
|
2486
|
-
if (
|
|
2496
|
+
if (isNode15(count, "remainderCountNode")) {
|
|
2487
2497
|
return {
|
|
2488
2498
|
decoder: fragment(`size: 'remainder'`),
|
|
2489
2499
|
encoder: fragment(`size: 'remainder'`)
|
|
2490
2500
|
};
|
|
2491
2501
|
}
|
|
2492
|
-
const prefix =
|
|
2502
|
+
const prefix = resolveNestedTypeNode3(count.prefix);
|
|
2493
2503
|
if (prefix.format === "u32" && prefix.endian === "le") {
|
|
2494
2504
|
return { decoder: fragment(""), encoder: fragment("") };
|
|
2495
2505
|
}
|
|
@@ -2622,7 +2632,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2622
2632
|
size: visit6(node, byteSizeVisitor),
|
|
2623
2633
|
typeManifest: visit6(node, typeManifestVisitor)
|
|
2624
2634
|
};
|
|
2625
|
-
const fields =
|
|
2635
|
+
const fields = resolveNestedTypeNode4(node.data).fields;
|
|
2626
2636
|
const accountDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2627
2637
|
...scope,
|
|
2628
2638
|
discriminatorNodes: node.discriminators ?? [],
|
|
@@ -2660,6 +2670,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2660
2670
|
encoderDocs: [],
|
|
2661
2671
|
manifest: visit6(node, typeManifestVisitor),
|
|
2662
2672
|
name: node.name,
|
|
2673
|
+
node: node.type,
|
|
2663
2674
|
size: visit6(node, byteSizeVisitor),
|
|
2664
2675
|
typeDocs: node.docs,
|
|
2665
2676
|
typeNode: node.type
|
|
@@ -2697,7 +2708,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2697
2708
|
extraArgsManifest: visit6(
|
|
2698
2709
|
definedTypeNode2({
|
|
2699
2710
|
name: instructionExtraName,
|
|
2700
|
-
type:
|
|
2711
|
+
type: structTypeNodeFromInstructionArgumentNodes5(node.extraArguments ?? [])
|
|
2701
2712
|
}),
|
|
2702
2713
|
typeManifestVisitor
|
|
2703
2714
|
),
|