@codama/renderers-js 1.3.0 → 1.3.2
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 +219 -196
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +94 -70
- package/dist/index.node.mjs.map +1 -1
- package/dist/templates/fragments/instructionParseFunction.njk +6 -6
- package/dist/templates/fragments/typeCodec.njk +1 -1
- package/dist/templates/fragments/typeDecoder.njk +2 -2
- package/dist/templates/fragments/typeEncoder.njk +2 -2
- package/dist/types/fragments/accountType.d.ts +1 -0
- package/dist/types/fragments/accountType.d.ts.map +1 -1
- package/dist/types/fragments/instructionData.d.ts +1 -0
- package/dist/types/fragments/instructionData.d.ts.map +1 -1
- package/dist/types/fragments/typeCodec.d.ts +3 -0
- package/dist/types/fragments/typeCodec.d.ts.map +1 -1
- package/dist/types/fragments/typeDecoder.d.ts +3 -0
- package/dist/types/fragments/typeDecoder.d.ts.map +1 -1
- package/dist/types/fragments/typeEncoder.d.ts +3 -0
- package/dist/types/fragments/typeEncoder.d.ts.map +1 -1
- package/dist/types/fragments/typeWithCodec.d.ts +3 -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,45 +517,57 @@ 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;
|
|
523
|
+
const decoderType = typeof scope.size === "number" ? "FixedSizeDecoder" : "Decoder";
|
|
524
|
+
const useTypeCast = isNode3(node, "enumTypeNode") && isDataEnum(node) && typeof scope.size === "number";
|
|
521
525
|
return fragmentFromTemplate("typeDecoder.njk", {
|
|
522
526
|
decoderFunction: nameApi.decoderFunction(name),
|
|
527
|
+
decoderType,
|
|
523
528
|
docs,
|
|
524
529
|
looseName: nameApi.dataArgsType(name),
|
|
525
530
|
manifest,
|
|
526
|
-
strictName: nameApi.dataType(name)
|
|
527
|
-
|
|
531
|
+
strictName: nameApi.dataType(name),
|
|
532
|
+
useTypeCast
|
|
533
|
+
}).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore", `type ${decoderType}`);
|
|
528
534
|
}
|
|
529
535
|
|
|
530
536
|
// src/fragments/typeEncoder.ts
|
|
537
|
+
import { isDataEnum as isDataEnum2, isNode as isNode4 } from "@codama/nodes";
|
|
531
538
|
function getTypeEncoderFragment(scope) {
|
|
532
|
-
const { name, manifest, nameApi, docs = [] } = scope;
|
|
539
|
+
const { name, node, manifest, nameApi, docs = [] } = scope;
|
|
540
|
+
const encoderType = typeof scope.size === "number" ? "FixedSizeEncoder" : "Encoder";
|
|
541
|
+
const useTypeCast = isNode4(node, "enumTypeNode") && isDataEnum2(node) && typeof scope.size === "number";
|
|
533
542
|
return fragmentFromTemplate("typeEncoder.njk", {
|
|
534
543
|
docs,
|
|
535
544
|
encoderFunction: nameApi.encoderFunction(name),
|
|
545
|
+
encoderType,
|
|
536
546
|
looseName: nameApi.dataArgsType(name),
|
|
537
547
|
manifest,
|
|
538
|
-
strictName: nameApi.dataType(name)
|
|
539
|
-
|
|
548
|
+
strictName: nameApi.dataType(name),
|
|
549
|
+
useTypeCast
|
|
550
|
+
}).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore", `type ${encoderType}`);
|
|
540
551
|
}
|
|
541
552
|
|
|
542
553
|
// src/fragments/typeCodec.ts
|
|
543
554
|
function getTypeCodecFragment(scope) {
|
|
544
555
|
const { name, manifest, nameApi } = scope;
|
|
556
|
+
const codecType = typeof scope.size === "number" ? "FixedSizeCodec" : "Codec";
|
|
545
557
|
return mergeFragments(
|
|
546
558
|
[
|
|
547
559
|
getTypeEncoderFragment({ ...scope, docs: scope.encoderDocs }),
|
|
548
560
|
getTypeDecoderFragment({ ...scope, docs: scope.decoderDocs }),
|
|
549
561
|
fragmentFromTemplate("typeCodec.njk", {
|
|
550
562
|
codecFunction: nameApi.codecFunction(name),
|
|
563
|
+
codecType,
|
|
551
564
|
decoderFunction: nameApi.decoderFunction(name),
|
|
552
565
|
docs: scope.codecDocs,
|
|
553
566
|
encoderFunction: nameApi.encoderFunction(name),
|
|
554
567
|
looseName: nameApi.dataArgsType(name),
|
|
555
568
|
manifest,
|
|
556
569
|
strictName: nameApi.dataType(name)
|
|
557
|
-
}).addImports("solanaCodecsCore", [
|
|
570
|
+
}).addImports("solanaCodecsCore", [`type ${codecType}`, "combineCodec"])
|
|
558
571
|
],
|
|
559
572
|
(renders) => renders.join("\n\n")
|
|
560
573
|
);
|
|
@@ -578,7 +591,9 @@ function getAccountTypeFragment(scope) {
|
|
|
578
591
|
return getTypeWithCodecFragment({
|
|
579
592
|
manifest: typeManifest2,
|
|
580
593
|
name: accountNode.name,
|
|
581
|
-
nameApi
|
|
594
|
+
nameApi,
|
|
595
|
+
node: resolveNestedTypeNode(accountNode.data),
|
|
596
|
+
size: scope.size
|
|
582
597
|
});
|
|
583
598
|
}
|
|
584
599
|
|
|
@@ -587,7 +602,7 @@ import {
|
|
|
587
602
|
constantDiscriminatorNode,
|
|
588
603
|
constantValueNode,
|
|
589
604
|
constantValueNodeFromBytes,
|
|
590
|
-
isNode as
|
|
605
|
+
isNode as isNode5,
|
|
591
606
|
isNodeFilter as isNodeFilter2
|
|
592
607
|
} from "@codama/nodes";
|
|
593
608
|
import { visit } from "@codama/visitors-core";
|
|
@@ -595,13 +610,13 @@ import { getBase64Decoder } from "@solana/codecs-strings";
|
|
|
595
610
|
function getDiscriminatorConditionFragment(scope) {
|
|
596
611
|
return mergeFragments(
|
|
597
612
|
scope.discriminators.flatMap((discriminator) => {
|
|
598
|
-
if (
|
|
613
|
+
if (isNode5(discriminator, "sizeDiscriminatorNode")) {
|
|
599
614
|
return [getSizeConditionFragment(discriminator, scope)];
|
|
600
615
|
}
|
|
601
|
-
if (
|
|
616
|
+
if (isNode5(discriminator, "constantDiscriminatorNode")) {
|
|
602
617
|
return [getByteConditionFragment(discriminator, scope)];
|
|
603
618
|
}
|
|
604
|
-
if (
|
|
619
|
+
if (isNode5(discriminator, "fieldDiscriminatorNode")) {
|
|
605
620
|
return [getFieldConditionFragment(discriminator, scope)];
|
|
606
621
|
}
|
|
607
622
|
return [];
|
|
@@ -625,7 +640,7 @@ function getFieldConditionFragment(discriminator, scope) {
|
|
|
625
640
|
`Field discriminator "${discriminator.name}" does not have a matching argument with default value.`
|
|
626
641
|
);
|
|
627
642
|
}
|
|
628
|
-
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"))) {
|
|
629
644
|
const base64Bytes = getBase64Decoder().decode(
|
|
630
645
|
new Uint8Array(field.defaultValue.items.map((node) => node.number))
|
|
631
646
|
);
|
|
@@ -695,7 +710,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
695
710
|
}
|
|
696
711
|
|
|
697
712
|
// src/fragments/instructionByteDelta.ts
|
|
698
|
-
import { assertIsNode, camelCase as camelCase3, isNode as
|
|
713
|
+
import { assertIsNode, camelCase as camelCase3, isNode as isNode6 } from "@codama/nodes";
|
|
699
714
|
import { getLastNodeFromPath as getLastNodeFromPath6 } from "@codama/visitors-core";
|
|
700
715
|
function getInstructionByteDeltaFragment(scope) {
|
|
701
716
|
const { byteDeltas } = getLastNodeFromPath6(scope.instructionPath);
|
|
@@ -709,16 +724,16 @@ const byteDelta: number = [${r.join(",")}].reduce((a, b) => a + b, 0);`
|
|
|
709
724
|
}
|
|
710
725
|
function getByteDeltaFragment(byteDelta, scope) {
|
|
711
726
|
const bytesFragment = (() => {
|
|
712
|
-
if (
|
|
727
|
+
if (isNode6(byteDelta.value, "numberValueNode")) {
|
|
713
728
|
return getNumberValueNodeFragment(byteDelta);
|
|
714
729
|
}
|
|
715
|
-
if (
|
|
730
|
+
if (isNode6(byteDelta.value, "argumentValueNode")) {
|
|
716
731
|
return getArgumentValueNodeFragment(byteDelta);
|
|
717
732
|
}
|
|
718
|
-
if (
|
|
733
|
+
if (isNode6(byteDelta.value, "accountLinkNode")) {
|
|
719
734
|
return getAccountLinkNodeFragment(byteDelta, scope);
|
|
720
735
|
}
|
|
721
|
-
if (
|
|
736
|
+
if (isNode6(byteDelta.value, "resolverValueNode")) {
|
|
722
737
|
return getResolverValueNodeFragment(byteDelta, scope);
|
|
723
738
|
}
|
|
724
739
|
return null;
|
|
@@ -756,6 +771,7 @@ function getResolverValueNodeFragment(byteDelta, scope) {
|
|
|
756
771
|
}
|
|
757
772
|
|
|
758
773
|
// src/fragments/instructionData.ts
|
|
774
|
+
import { structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes2 } from "@codama/nodes";
|
|
759
775
|
import { getLastNodeFromPath as getLastNodeFromPath7 } from "@codama/visitors-core";
|
|
760
776
|
function getInstructionDataFragment(scope) {
|
|
761
777
|
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
@@ -767,14 +783,16 @@ function getInstructionDataFragment(scope) {
|
|
|
767
783
|
return getTypeWithCodecFragment({
|
|
768
784
|
manifest: dataArgsManifest,
|
|
769
785
|
name: instructionDataName,
|
|
770
|
-
nameApi
|
|
786
|
+
nameApi,
|
|
787
|
+
node: structTypeNodeFromInstructionArgumentNodes2(instructionNode.arguments),
|
|
788
|
+
size: scope.size
|
|
771
789
|
});
|
|
772
790
|
}
|
|
773
791
|
|
|
774
792
|
// src/fragments/discriminatorConstants.ts
|
|
775
793
|
import {
|
|
776
794
|
camelCase as camelCase4,
|
|
777
|
-
isNode as
|
|
795
|
+
isNode as isNode7,
|
|
778
796
|
isNodeFilter as isNodeFilter3,
|
|
779
797
|
VALUE_NODES
|
|
780
798
|
} from "@codama/nodes";
|
|
@@ -805,7 +823,7 @@ function getConstantDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
|
805
823
|
function getFieldDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
806
824
|
const { fields, prefix, typeManifestVisitor } = scope;
|
|
807
825
|
const field = fields.find((f) => f.name === discriminatorNode.name);
|
|
808
|
-
if (!field || !field.defaultValue || !
|
|
826
|
+
if (!field || !field.defaultValue || !isNode7(field.defaultValue, VALUE_NODES)) {
|
|
809
827
|
return null;
|
|
810
828
|
}
|
|
811
829
|
const name = camelCase4(`${prefix}_${discriminatorNode.name}`);
|
|
@@ -843,18 +861,18 @@ function getInstructionExtraArgsFragment(scope) {
|
|
|
843
861
|
}
|
|
844
862
|
|
|
845
863
|
// src/fragments/instructionFunction.ts
|
|
846
|
-
import { camelCase as camelCase9, isNode as
|
|
864
|
+
import { camelCase as camelCase9, isNode as isNode12, isNodeFilter as isNodeFilter4, pascalCase as pascalCase5 } from "@codama/nodes";
|
|
847
865
|
import {
|
|
848
866
|
findProgramNodeFromPath as findProgramNodeFromPath3,
|
|
849
867
|
getLastNodeFromPath as getLastNodeFromPath12
|
|
850
868
|
} from "@codama/visitors-core";
|
|
851
869
|
|
|
852
870
|
// src/fragments/instructionInputResolved.ts
|
|
853
|
-
import { camelCase as camelCase6, isNode as
|
|
871
|
+
import { camelCase as camelCase6, isNode as isNode9, parseOptionalAccountStrategy } from "@codama/nodes";
|
|
854
872
|
import { getLastNodeFromPath as getLastNodeFromPath9 } from "@codama/visitors-core";
|
|
855
873
|
|
|
856
874
|
// src/fragments/instructionInputDefault.ts
|
|
857
|
-
import { camelCase as camelCase5, isNode as
|
|
875
|
+
import { camelCase as camelCase5, isNode as isNode8 } from "@codama/nodes";
|
|
858
876
|
import { visit as visit3 } from "@codama/visitors-core";
|
|
859
877
|
function getInstructionInputDefaultFragment(scope) {
|
|
860
878
|
const { input, optionalAccountStrategy, asyncResolvers, useAsync, nameApi, typeManifestVisitor, getImportFrom } = scope;
|
|
@@ -867,7 +885,7 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
867
885
|
const { defaultValue } = input;
|
|
868
886
|
const defaultFragment = (renderedValue, isWritable) => {
|
|
869
887
|
const inputName = camelCase5(input.name);
|
|
870
|
-
if (input.kind === "instructionAccountNode" &&
|
|
888
|
+
if (input.kind === "instructionAccountNode" && isNode8(defaultValue, "resolverValueNode")) {
|
|
871
889
|
return fragment(`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`);
|
|
872
890
|
}
|
|
873
891
|
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
@@ -895,17 +913,17 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
895
913
|
}
|
|
896
914
|
return defaultFragment(`expectAddress(accounts.${name}.value)`).addImports("shared", "expectAddress");
|
|
897
915
|
case "pdaValueNode":
|
|
898
|
-
if (
|
|
916
|
+
if (isNode8(defaultValue.pda, "pdaNode")) {
|
|
899
917
|
const pdaProgram = defaultValue.pda.programId ? fragment(
|
|
900
918
|
`'${defaultValue.pda.programId}' as Address<'${defaultValue.pda.programId}'>`
|
|
901
919
|
).addImports("solanaAddresses", "type Address") : fragment("programAddress");
|
|
902
920
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
903
|
-
if (
|
|
921
|
+
if (isNode8(seed, "constantPdaSeedNode") && isNode8(seed.value, "programIdValueNode")) {
|
|
904
922
|
return [
|
|
905
923
|
fragment(`getAddressEncoder().encode(${pdaProgram.render})`).mergeImportsWith(pdaProgram).addImports("solanaAddresses", "getAddressEncoder")
|
|
906
924
|
];
|
|
907
925
|
}
|
|
908
|
-
if (
|
|
926
|
+
if (isNode8(seed, "constantPdaSeedNode") && !isNode8(seed.value, "programIdValueNode")) {
|
|
909
927
|
const typeManifest2 = visit3(seed.type, typeManifestVisitor);
|
|
910
928
|
const valueManifest2 = visit3(seed.value, typeManifestVisitor);
|
|
911
929
|
return [
|
|
@@ -914,18 +932,18 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
914
932
|
).mergeImportsWith(typeManifest2.encoder, valueManifest2.value)
|
|
915
933
|
];
|
|
916
934
|
}
|
|
917
|
-
if (
|
|
935
|
+
if (isNode8(seed, "variablePdaSeedNode")) {
|
|
918
936
|
const typeManifest2 = visit3(seed.type, typeManifestVisitor);
|
|
919
937
|
const valueSeed = defaultValue.seeds.find((s) => s.name === seed.name)?.value;
|
|
920
938
|
if (!valueSeed) return [];
|
|
921
|
-
if (
|
|
939
|
+
if (isNode8(valueSeed, "accountValueNode")) {
|
|
922
940
|
return [
|
|
923
941
|
fragment(
|
|
924
942
|
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${camelCase5(valueSeed.name)}.value))`
|
|
925
943
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectAddress")
|
|
926
944
|
];
|
|
927
945
|
}
|
|
928
|
-
if (
|
|
946
|
+
if (isNode8(valueSeed, "argumentValueNode")) {
|
|
929
947
|
return [
|
|
930
948
|
fragment(
|
|
931
949
|
`${typeManifest2.encoder.render}.encode(expectSome(args.${camelCase5(valueSeed.name)}))`
|
|
@@ -950,12 +968,12 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
950
968
|
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
951
969
|
const pdaArgs = [];
|
|
952
970
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
953
|
-
if (
|
|
971
|
+
if (isNode8(seed.value, "accountValueNode")) {
|
|
954
972
|
return fragment(
|
|
955
973
|
`${seed.name}: expectAddress(accounts.${camelCase5(seed.value.name)}.value)`
|
|
956
974
|
).addImports("shared", "expectAddress");
|
|
957
975
|
}
|
|
958
|
-
if (
|
|
976
|
+
if (isNode8(seed.value, "argumentValueNode")) {
|
|
959
977
|
return fragment(`${seed.name}: expectSome(args.${camelCase5(seed.value.name)})`).addImports(
|
|
960
978
|
"shared",
|
|
961
979
|
"expectSome"
|
|
@@ -1018,14 +1036,14 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
1018
1036
|
}
|
|
1019
1037
|
const negatedCondition = !ifTrueRenderer;
|
|
1020
1038
|
let condition = "true";
|
|
1021
|
-
if (
|
|
1039
|
+
if (isNode8(defaultValue.condition, "resolverValueNode")) {
|
|
1022
1040
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
1023
1041
|
conditionalFragment.addImports(getImportFrom(defaultValue.condition), conditionalResolverFunction).addFeatures(["instruction:resolverScopeVariable"]);
|
|
1024
1042
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
1025
1043
|
condition = `${conditionalResolverAwait}${conditionalResolverFunction}(resolverScope)`;
|
|
1026
1044
|
condition = negatedCondition ? `!${condition}` : condition;
|
|
1027
1045
|
} else {
|
|
1028
|
-
const comparedInputName =
|
|
1046
|
+
const comparedInputName = isNode8(defaultValue.condition, "accountValueNode") ? `accounts.${camelCase5(defaultValue.condition.name)}.value` : `args.${camelCase5(defaultValue.condition.name)}`;
|
|
1029
1047
|
if (defaultValue.value) {
|
|
1030
1048
|
const comparedValue = visit3(defaultValue.value, typeManifestVisitor).value;
|
|
1031
1049
|
conditionalFragment.mergeImportsWith(comparedValue).mergeFeaturesWith(comparedValue);
|
|
@@ -1076,7 +1094,7 @@ function getInstructionInputResolvedFragment(scope) {
|
|
|
1076
1094
|
const camelName = camelCase6(input.name);
|
|
1077
1095
|
return [
|
|
1078
1096
|
inputFragment.mapRender(
|
|
1079
|
-
(r) =>
|
|
1097
|
+
(r) => isNode9(input, "instructionArgumentNode") ? `if (!args.${camelName}) {
|
|
1080
1098
|
${r}
|
|
1081
1099
|
}` : `if (!accounts.${camelName}.value) {
|
|
1082
1100
|
${r}
|
|
@@ -1097,7 +1115,7 @@ ${r}
|
|
|
1097
1115
|
import {
|
|
1098
1116
|
camelCase as camelCase7,
|
|
1099
1117
|
getAllInstructionArguments,
|
|
1100
|
-
isNode as
|
|
1118
|
+
isNode as isNode10,
|
|
1101
1119
|
parseDocs,
|
|
1102
1120
|
pascalCase as pascalCase4
|
|
1103
1121
|
} from "@codama/nodes";
|
|
@@ -1135,7 +1153,7 @@ function getAccountsFragment(scope) {
|
|
|
1135
1153
|
const resolvedAccount = resolvedInputs.find(
|
|
1136
1154
|
(input) => input.kind === "instructionAccountNode" && input.name === account.name
|
|
1137
1155
|
);
|
|
1138
|
-
const hasDefaultValue = !!resolvedAccount.defaultValue && !
|
|
1156
|
+
const hasDefaultValue = !!resolvedAccount.defaultValue && !isNode10(resolvedAccount.defaultValue, ["identityValueNode", "payerValueNode"]) && (useAsync || !isAsyncDefaultValue(resolvedAccount.defaultValue, asyncResolvers));
|
|
1139
1157
|
const accountDocs = parseDocs(account.docs);
|
|
1140
1158
|
const docblock = accountDocs.length > 0 ? jsDocblock(accountDocs) : "";
|
|
1141
1159
|
const optionalSign = hasDefaultValue || resolvedAccount.isOptional ? "?" : "";
|
|
@@ -1194,7 +1212,7 @@ function getExtraArgumentsFragment(scope) {
|
|
|
1194
1212
|
}
|
|
1195
1213
|
function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
1196
1214
|
const resolvedArg = resolvedInputs.find(
|
|
1197
|
-
(input) =>
|
|
1215
|
+
(input) => isNode10(input, "instructionArgumentNode") && input.name === arg.name
|
|
1198
1216
|
);
|
|
1199
1217
|
if (arg.defaultValue && arg.defaultValueStrategy === "omitted") return null;
|
|
1200
1218
|
const renamedName = renamedArgs.get(arg.name) ?? arg.name;
|
|
@@ -1203,7 +1221,7 @@ function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
|
1203
1221
|
}
|
|
1204
1222
|
function getRemainingAccountsFragment(instructionNode) {
|
|
1205
1223
|
const fragments = (instructionNode.remainingAccounts ?? []).flatMap((remainingAccountsNode) => {
|
|
1206
|
-
if (
|
|
1224
|
+
if (isNode10(remainingAccountsNode.value, "resolverValueNode")) return [];
|
|
1207
1225
|
const { name } = remainingAccountsNode.value;
|
|
1208
1226
|
const allArguments = getAllInstructionArguments(instructionNode);
|
|
1209
1227
|
const argumentExists = allArguments.some((arg) => arg.name === name);
|
|
@@ -1227,7 +1245,7 @@ import {
|
|
|
1227
1245
|
assertIsNode as assertIsNode2,
|
|
1228
1246
|
camelCase as camelCase8,
|
|
1229
1247
|
getAllInstructionArguments as getAllInstructionArguments2,
|
|
1230
|
-
isNode as
|
|
1248
|
+
isNode as isNode11
|
|
1231
1249
|
} from "@codama/nodes";
|
|
1232
1250
|
import { getLastNodeFromPath as getLastNodeFromPath11 } from "@codama/visitors-core";
|
|
1233
1251
|
function getInstructionRemainingAccountsFragment(scope) {
|
|
@@ -1242,10 +1260,10 @@ const remainingAccounts: AccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.join
|
|
|
1242
1260
|
}
|
|
1243
1261
|
function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
1244
1262
|
const remainingAccountsFragment = (() => {
|
|
1245
|
-
if (
|
|
1263
|
+
if (isNode11(remainingAccounts.value, "argumentValueNode")) {
|
|
1246
1264
|
return getArgumentValueNodeFragment2(remainingAccounts, scope);
|
|
1247
1265
|
}
|
|
1248
|
-
if (
|
|
1266
|
+
if (isNode11(remainingAccounts.value, "resolverValueNode")) {
|
|
1249
1267
|
return getResolverValueNodeFragment2(remainingAccounts, scope);
|
|
1250
1268
|
}
|
|
1251
1269
|
return null;
|
|
@@ -1327,7 +1345,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1327
1345
|
const hasExtraArgs = (instructionNode.extraArguments ?? []).filter(
|
|
1328
1346
|
(field) => argIsNotOmitted(field) && (argIsDependent(field) || argHasDefaultValue(field))
|
|
1329
1347
|
).length > 0;
|
|
1330
|
-
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) =>
|
|
1348
|
+
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => isNode12(value, "argumentValueNode")).length > 0;
|
|
1331
1349
|
const hasAnyArgs = hasDataArgs || hasExtraArgs || hasRemainingAccountArgs;
|
|
1332
1350
|
const hasInput = hasAccounts || hasAnyArgs;
|
|
1333
1351
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
@@ -1526,7 +1544,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1526
1544
|
}
|
|
1527
1545
|
|
|
1528
1546
|
// src/fragments/pdaFunction.ts
|
|
1529
|
-
import { isNode as
|
|
1547
|
+
import { isNode as isNode13, isNodeFilter as isNodeFilter5 } from "@codama/nodes";
|
|
1530
1548
|
import { findProgramNodeFromPath as findProgramNodeFromPath6, getLastNodeFromPath as getLastNodeFromPath15, visit as visit4 } from "@codama/visitors-core";
|
|
1531
1549
|
function getPdaFunctionFragment(scope) {
|
|
1532
1550
|
const { pdaPath, typeManifestVisitor, nameApi } = scope;
|
|
@@ -1534,12 +1552,12 @@ function getPdaFunctionFragment(scope) {
|
|
|
1534
1552
|
const programNode = findProgramNodeFromPath6(pdaPath);
|
|
1535
1553
|
const imports = new ImportMap();
|
|
1536
1554
|
const seeds = pdaNode.seeds.map((seed) => {
|
|
1537
|
-
if (
|
|
1555
|
+
if (isNode13(seed, "variablePdaSeedNode")) {
|
|
1538
1556
|
const seedManifest2 = visit4(seed.type, typeManifestVisitor);
|
|
1539
1557
|
imports.mergeWith(seedManifest2.looseType, seedManifest2.encoder);
|
|
1540
1558
|
return { ...seed, typeManifest: seedManifest2 };
|
|
1541
1559
|
}
|
|
1542
|
-
if (
|
|
1560
|
+
if (isNode13(seed.value, "programIdValueNode")) {
|
|
1543
1561
|
imports.add("solanaAddresses", "getAddressEncoder");
|
|
1544
1562
|
return seed;
|
|
1545
1563
|
}
|
|
@@ -1569,7 +1587,7 @@ function getProgramFragment(scope) {
|
|
|
1569
1587
|
}
|
|
1570
1588
|
|
|
1571
1589
|
// src/fragments/programAccounts.ts
|
|
1572
|
-
import { resolveNestedTypeNode } from "@codama/nodes";
|
|
1590
|
+
import { resolveNestedTypeNode as resolveNestedTypeNode2 } from "@codama/nodes";
|
|
1573
1591
|
function getProgramAccountsFragment(scope) {
|
|
1574
1592
|
if (scope.programNode.accounts.length === 0) return fragment("");
|
|
1575
1593
|
return mergeFragments(
|
|
@@ -1603,7 +1621,7 @@ function getProgramAccountsIdentifierFunctionFragment(scope) {
|
|
|
1603
1621
|
dataName: "data",
|
|
1604
1622
|
discriminators: account.discriminators ?? [],
|
|
1605
1623
|
ifTrue: `return ${programAccountsEnum}.${variant};`,
|
|
1606
|
-
struct:
|
|
1624
|
+
struct: resolveNestedTypeNode2(account.data)
|
|
1607
1625
|
});
|
|
1608
1626
|
}),
|
|
1609
1627
|
(r) => r.join("\n")
|
|
@@ -1636,7 +1654,7 @@ function getProgramErrorsFragment(scope) {
|
|
|
1636
1654
|
// src/fragments/programInstructions.ts
|
|
1637
1655
|
import {
|
|
1638
1656
|
getAllInstructionsWithSubs,
|
|
1639
|
-
structTypeNodeFromInstructionArgumentNodes as
|
|
1657
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes3
|
|
1640
1658
|
} from "@codama/nodes";
|
|
1641
1659
|
function getProgramInstructionsFragment(scope) {
|
|
1642
1660
|
if (scope.programNode.instructions.length === 0) return fragment("");
|
|
@@ -1682,7 +1700,7 @@ function getProgramInstructionsIdentifierFunctionFragment(scope) {
|
|
|
1682
1700
|
dataName: "data",
|
|
1683
1701
|
discriminators: instruction.discriminators ?? [],
|
|
1684
1702
|
ifTrue: `return ${programInstructionsEnum}.${variant};`,
|
|
1685
|
-
struct:
|
|
1703
|
+
struct: structTypeNodeFromInstructionArgumentNodes3(instruction.arguments)
|
|
1686
1704
|
});
|
|
1687
1705
|
}),
|
|
1688
1706
|
(r) => r.join("\n")
|
|
@@ -1717,10 +1735,10 @@ function getProgramInstructionsParsedUnionTypeFragment(scope) {
|
|
|
1717
1735
|
}
|
|
1718
1736
|
|
|
1719
1737
|
// src/fragments/typeDiscriminatedUnionHelpers.ts
|
|
1720
|
-
import { isDataEnum, isNode as
|
|
1738
|
+
import { isDataEnum as isDataEnum3, isNode as isNode14 } from "@codama/nodes";
|
|
1721
1739
|
function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
1722
1740
|
const { name, typeNode, nameApi } = scope;
|
|
1723
|
-
const isDiscriminatedUnion =
|
|
1741
|
+
const isDiscriminatedUnion = isNode14(typeNode, "enumTypeNode") && isDataEnum3(typeNode);
|
|
1724
1742
|
if (!isDiscriminatedUnion) {
|
|
1725
1743
|
return fragment("");
|
|
1726
1744
|
}
|
|
@@ -1773,13 +1791,14 @@ import {
|
|
|
1773
1791
|
getAllInstructionsWithSubs as getAllInstructionsWithSubs2,
|
|
1774
1792
|
getAllPdas,
|
|
1775
1793
|
getAllPrograms,
|
|
1776
|
-
resolveNestedTypeNode as
|
|
1777
|
-
structTypeNodeFromInstructionArgumentNodes as
|
|
1794
|
+
resolveNestedTypeNode as resolveNestedTypeNode4,
|
|
1795
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes5
|
|
1778
1796
|
} from "@codama/nodes";
|
|
1779
1797
|
import { RenderMap } from "@codama/renderers-core";
|
|
1780
1798
|
import {
|
|
1781
1799
|
extendVisitor as extendVisitor2,
|
|
1782
1800
|
findProgramNodeFromPath as findProgramNodeFromPath7,
|
|
1801
|
+
getByteSizeVisitor,
|
|
1783
1802
|
getResolvedInstructionInputsVisitor,
|
|
1784
1803
|
LinkableDictionary as LinkableDictionary3,
|
|
1785
1804
|
NodeStack as NodeStack2,
|
|
@@ -1793,16 +1812,16 @@ import {
|
|
|
1793
1812
|
// src/getTypeManifestVisitor.ts
|
|
1794
1813
|
import {
|
|
1795
1814
|
camelCase as camelCase10,
|
|
1796
|
-
isNode as
|
|
1815
|
+
isNode as isNode15,
|
|
1797
1816
|
isNodeFilter as isNodeFilter6,
|
|
1798
1817
|
isScalarEnum,
|
|
1799
1818
|
parseDocs as parseDocs2,
|
|
1800
1819
|
REGISTERED_TYPE_NODE_KINDS,
|
|
1801
1820
|
REGISTERED_VALUE_NODE_KINDS,
|
|
1802
|
-
resolveNestedTypeNode as
|
|
1821
|
+
resolveNestedTypeNode as resolveNestedTypeNode3,
|
|
1803
1822
|
structFieldTypeNode,
|
|
1804
1823
|
structTypeNode,
|
|
1805
|
-
structTypeNodeFromInstructionArgumentNodes as
|
|
1824
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes4
|
|
1806
1825
|
} from "@codama/nodes";
|
|
1807
1826
|
import {
|
|
1808
1827
|
extendVisitor,
|
|
@@ -1874,7 +1893,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1874
1893
|
const decoderImports = new ImportMap().add("solanaCodecsDataStructures", "getBooleanDecoder");
|
|
1875
1894
|
let sizeEncoder = "";
|
|
1876
1895
|
let sizeDecoder = "";
|
|
1877
|
-
const resolvedSize =
|
|
1896
|
+
const resolvedSize = resolveNestedTypeNode3(booleanType.size);
|
|
1878
1897
|
if (resolvedSize.format !== "u8" || resolvedSize.endian !== "le") {
|
|
1879
1898
|
const size = visit5(booleanType.size, self);
|
|
1880
1899
|
encoderImports.mergeWith(size.encoder);
|
|
@@ -1925,7 +1944,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1925
1944
|
return manifest;
|
|
1926
1945
|
},
|
|
1927
1946
|
visitConstantValue(node, { self }) {
|
|
1928
|
-
if (
|
|
1947
|
+
if (isNode15(node.type, "bytesTypeNode") && isNode15(node.value, "bytesValueNode")) {
|
|
1929
1948
|
return visit5(node.value, self);
|
|
1930
1949
|
}
|
|
1931
1950
|
return {
|
|
@@ -2026,7 +2045,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2026
2045
|
const decoderImports = new ImportMap();
|
|
2027
2046
|
const encoderOptions = [];
|
|
2028
2047
|
const decoderOptions = [];
|
|
2029
|
-
const enumSize =
|
|
2048
|
+
const enumSize = resolveNestedTypeNode3(enumType.size);
|
|
2030
2049
|
if (enumSize.format !== "u8" || enumSize.endian !== "le") {
|
|
2031
2050
|
const sizeManifest = visit5(enumType.size, self);
|
|
2032
2051
|
encoderImports.mergeWith(sizeManifest.encoder);
|
|
@@ -2082,7 +2101,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2082
2101
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
2083
2102
|
const importFrom = getImportFrom(node.enum);
|
|
2084
2103
|
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
2085
|
-
const isScalar = enumNode &&
|
|
2104
|
+
const isScalar = enumNode && isNode15(enumNode, "enumTypeNode") ? isScalarEnum(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
2086
2105
|
if (!node.value && isScalar) {
|
|
2087
2106
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
2088
2107
|
manifest.value.setRender(`${enumName}.${variantName2}`).addImports(importFrom, enumName);
|
|
@@ -2127,7 +2146,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2127
2146
|
strict: nameApi.dataType(instructionDataName)
|
|
2128
2147
|
};
|
|
2129
2148
|
const link = customInstructionData.get(instruction.name)?.linkNode;
|
|
2130
|
-
const struct =
|
|
2149
|
+
const struct = structTypeNodeFromInstructionArgumentNodes4(instruction.arguments);
|
|
2131
2150
|
const manifest = link ? visit5(link, self) : visit5(struct, self);
|
|
2132
2151
|
parentName = null;
|
|
2133
2152
|
return manifest;
|
|
@@ -2194,7 +2213,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2194
2213
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2195
2214
|
const encoderOptions = [];
|
|
2196
2215
|
const decoderOptions = [];
|
|
2197
|
-
const optionPrefix =
|
|
2216
|
+
const optionPrefix = resolveNestedTypeNode3(optionType.prefix);
|
|
2198
2217
|
if (optionPrefix.format !== "u8" || optionPrefix.endian !== "le") {
|
|
2199
2218
|
const prefixManifest = visit5(optionType.prefix, self);
|
|
2200
2219
|
childManifest.encoder.mergeImportsWith(prefixManifest.encoder);
|
|
@@ -2468,19 +2487,19 @@ ${jsDocblock(structFieldDocs)}` : "";
|
|
|
2468
2487
|
);
|
|
2469
2488
|
}
|
|
2470
2489
|
function getArrayLikeSizeOption(count, visitor) {
|
|
2471
|
-
if (
|
|
2490
|
+
if (isNode15(count, "fixedCountNode")) {
|
|
2472
2491
|
return {
|
|
2473
2492
|
decoder: fragment(`size: ${count.value}`),
|
|
2474
2493
|
encoder: fragment(`size: ${count.value}`)
|
|
2475
2494
|
};
|
|
2476
2495
|
}
|
|
2477
|
-
if (
|
|
2496
|
+
if (isNode15(count, "remainderCountNode")) {
|
|
2478
2497
|
return {
|
|
2479
2498
|
decoder: fragment(`size: 'remainder'`),
|
|
2480
2499
|
encoder: fragment(`size: 'remainder'`)
|
|
2481
2500
|
};
|
|
2482
2501
|
}
|
|
2483
|
-
const prefix =
|
|
2502
|
+
const prefix = resolveNestedTypeNode3(count.prefix);
|
|
2484
2503
|
if (prefix.format === "u32" && prefix.endian === "le") {
|
|
2485
2504
|
return { decoder: fragment(""), encoder: fragment("") };
|
|
2486
2505
|
}
|
|
@@ -2582,6 +2601,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2582
2601
|
stack
|
|
2583
2602
|
});
|
|
2584
2603
|
const resolvedInstructionInputVisitor = getResolvedInstructionInputsVisitor();
|
|
2604
|
+
const byteSizeVisitor = getByteSizeVisitor(linkables, { stack });
|
|
2585
2605
|
const globalScope = {
|
|
2586
2606
|
asyncResolvers,
|
|
2587
2607
|
customAccountData,
|
|
@@ -2609,9 +2629,10 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2609
2629
|
const scope = {
|
|
2610
2630
|
...globalScope,
|
|
2611
2631
|
accountPath,
|
|
2632
|
+
size: visit6(node, byteSizeVisitor),
|
|
2612
2633
|
typeManifest: visit6(node, typeManifestVisitor)
|
|
2613
2634
|
};
|
|
2614
|
-
const fields =
|
|
2635
|
+
const fields = resolveNestedTypeNode4(node.data).fields;
|
|
2615
2636
|
const accountDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2616
2637
|
...scope,
|
|
2617
2638
|
discriminatorNodes: node.discriminators ?? [],
|
|
@@ -2649,6 +2670,8 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2649
2670
|
encoderDocs: [],
|
|
2650
2671
|
manifest: visit6(node, typeManifestVisitor),
|
|
2651
2672
|
name: node.name,
|
|
2673
|
+
node: node.type,
|
|
2674
|
+
size: visit6(node, byteSizeVisitor),
|
|
2652
2675
|
typeDocs: node.docs,
|
|
2653
2676
|
typeNode: node.type
|
|
2654
2677
|
};
|
|
@@ -2685,13 +2708,14 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2685
2708
|
extraArgsManifest: visit6(
|
|
2686
2709
|
definedTypeNode2({
|
|
2687
2710
|
name: instructionExtraName,
|
|
2688
|
-
type:
|
|
2711
|
+
type: structTypeNodeFromInstructionArgumentNodes5(node.extraArguments ?? [])
|
|
2689
2712
|
}),
|
|
2690
2713
|
typeManifestVisitor
|
|
2691
2714
|
),
|
|
2692
2715
|
instructionPath,
|
|
2693
2716
|
renamedArgs: getRenamedArgsMap(node),
|
|
2694
|
-
resolvedInputs: visit6(node, resolvedInstructionInputVisitor)
|
|
2717
|
+
resolvedInputs: visit6(node, resolvedInstructionInputVisitor),
|
|
2718
|
+
size: visit6(node, byteSizeVisitor)
|
|
2695
2719
|
};
|
|
2696
2720
|
const instructionDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2697
2721
|
...scope,
|