@codama/renderers-js 1.3.1 → 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 +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/typeDecoder.njk +1 -1
- package/dist/templates/fragments/typeEncoder.njk +1 -1
- 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.cjs
CHANGED
|
@@ -532,6 +532,7 @@ function getAccountSizeHelpersFragment(scope) {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
// src/fragments/accountType.ts
|
|
535
|
+
var import_nodes7 = require("@codama/nodes");
|
|
535
536
|
var import_visitors_core5 = require("@codama/visitors-core");
|
|
536
537
|
|
|
537
538
|
// src/fragments/type.ts
|
|
@@ -550,30 +551,36 @@ function getTypeFragment(scope) {
|
|
|
550
551
|
}
|
|
551
552
|
|
|
552
553
|
// src/fragments/typeDecoder.ts
|
|
554
|
+
var import_nodes5 = require("@codama/nodes");
|
|
553
555
|
function getTypeDecoderFragment(scope) {
|
|
554
|
-
const { name, manifest, nameApi, docs = [] } = scope;
|
|
556
|
+
const { name, node, manifest, nameApi, docs = [] } = scope;
|
|
555
557
|
const decoderType = typeof scope.size === "number" ? "FixedSizeDecoder" : "Decoder";
|
|
558
|
+
const useTypeCast = (0, import_nodes5.isNode)(node, "enumTypeNode") && (0, import_nodes5.isDataEnum)(node) && typeof scope.size === "number";
|
|
556
559
|
return fragmentFromTemplate("typeDecoder.njk", {
|
|
557
560
|
decoderFunction: nameApi.decoderFunction(name),
|
|
558
561
|
decoderType,
|
|
559
562
|
docs,
|
|
560
563
|
looseName: nameApi.dataArgsType(name),
|
|
561
564
|
manifest,
|
|
562
|
-
strictName: nameApi.dataType(name)
|
|
565
|
+
strictName: nameApi.dataType(name),
|
|
566
|
+
useTypeCast
|
|
563
567
|
}).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore", `type ${decoderType}`);
|
|
564
568
|
}
|
|
565
569
|
|
|
566
570
|
// src/fragments/typeEncoder.ts
|
|
571
|
+
var import_nodes6 = require("@codama/nodes");
|
|
567
572
|
function getTypeEncoderFragment(scope) {
|
|
568
|
-
const { name, manifest, nameApi, docs = [] } = scope;
|
|
573
|
+
const { name, node, manifest, nameApi, docs = [] } = scope;
|
|
569
574
|
const encoderType = typeof scope.size === "number" ? "FixedSizeEncoder" : "Encoder";
|
|
575
|
+
const useTypeCast = (0, import_nodes6.isNode)(node, "enumTypeNode") && (0, import_nodes6.isDataEnum)(node) && typeof scope.size === "number";
|
|
570
576
|
return fragmentFromTemplate("typeEncoder.njk", {
|
|
571
577
|
docs,
|
|
572
578
|
encoderFunction: nameApi.encoderFunction(name),
|
|
573
579
|
encoderType,
|
|
574
580
|
looseName: nameApi.dataArgsType(name),
|
|
575
581
|
manifest,
|
|
576
|
-
strictName: nameApi.dataType(name)
|
|
582
|
+
strictName: nameApi.dataType(name),
|
|
583
|
+
useTypeCast
|
|
577
584
|
}).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore", `type ${encoderType}`);
|
|
578
585
|
}
|
|
579
586
|
|
|
@@ -619,24 +626,25 @@ function getAccountTypeFragment(scope) {
|
|
|
619
626
|
manifest: typeManifest2,
|
|
620
627
|
name: accountNode.name,
|
|
621
628
|
nameApi,
|
|
629
|
+
node: (0, import_nodes7.resolveNestedTypeNode)(accountNode.data),
|
|
622
630
|
size: scope.size
|
|
623
631
|
});
|
|
624
632
|
}
|
|
625
633
|
|
|
626
634
|
// src/fragments/discriminatorCondition.ts
|
|
627
|
-
var
|
|
635
|
+
var import_nodes8 = require("@codama/nodes");
|
|
628
636
|
var import_visitors_core6 = require("@codama/visitors-core");
|
|
629
637
|
var import_codecs_strings2 = require("@solana/codecs-strings");
|
|
630
638
|
function getDiscriminatorConditionFragment(scope) {
|
|
631
639
|
return mergeFragments(
|
|
632
640
|
scope.discriminators.flatMap((discriminator) => {
|
|
633
|
-
if ((0,
|
|
641
|
+
if ((0, import_nodes8.isNode)(discriminator, "sizeDiscriminatorNode")) {
|
|
634
642
|
return [getSizeConditionFragment(discriminator, scope)];
|
|
635
643
|
}
|
|
636
|
-
if ((0,
|
|
644
|
+
if ((0, import_nodes8.isNode)(discriminator, "constantDiscriminatorNode")) {
|
|
637
645
|
return [getByteConditionFragment(discriminator, scope)];
|
|
638
646
|
}
|
|
639
|
-
if ((0,
|
|
647
|
+
if ((0, import_nodes8.isNode)(discriminator, "fieldDiscriminatorNode")) {
|
|
640
648
|
return [getFieldConditionFragment(discriminator, scope)];
|
|
641
649
|
}
|
|
642
650
|
return [];
|
|
@@ -660,25 +668,25 @@ function getFieldConditionFragment(discriminator, scope) {
|
|
|
660
668
|
`Field discriminator "${discriminator.name}" does not have a matching argument with default value.`
|
|
661
669
|
);
|
|
662
670
|
}
|
|
663
|
-
if ((0,
|
|
671
|
+
if ((0, import_nodes8.isNode)(field.type, "arrayTypeNode") && (0, import_nodes8.isNode)(field.type.item, "numberTypeNode") && field.type.item.format === "u8" && (0, import_nodes8.isNode)(field.type.count, "fixedCountNode") && (0, import_nodes8.isNode)(field.defaultValue, "arrayValueNode") && field.defaultValue.items.every((0, import_nodes8.isNodeFilter)("numberValueNode"))) {
|
|
664
672
|
const base64Bytes = (0, import_codecs_strings2.getBase64Decoder)().decode(
|
|
665
673
|
new Uint8Array(field.defaultValue.items.map((node) => node.number))
|
|
666
674
|
);
|
|
667
675
|
return getByteConditionFragment(
|
|
668
|
-
(0,
|
|
676
|
+
(0, import_nodes8.constantDiscriminatorNode)((0, import_nodes8.constantValueNodeFromBytes)("base64", base64Bytes), discriminator.offset),
|
|
669
677
|
scope
|
|
670
678
|
);
|
|
671
679
|
}
|
|
672
680
|
return getByteConditionFragment(
|
|
673
|
-
(0,
|
|
681
|
+
(0, import_nodes8.constantDiscriminatorNode)((0, import_nodes8.constantValueNode)(field.type, field.defaultValue), discriminator.offset),
|
|
674
682
|
scope
|
|
675
683
|
);
|
|
676
684
|
}
|
|
677
685
|
|
|
678
686
|
// src/fragments/instructionAccountMeta.ts
|
|
679
|
-
var
|
|
687
|
+
var import_nodes9 = require("@codama/nodes");
|
|
680
688
|
function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
681
|
-
const typeParam = `TAccount${(0,
|
|
689
|
+
const typeParam = `TAccount${(0, import_nodes9.pascalCase)(instructionAccountNode.name)}`;
|
|
682
690
|
if (instructionAccountNode.isSigner === true && instructionAccountNode.isWritable) {
|
|
683
691
|
return fragment(`WritableSignerAccount<${typeParam}> & AccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type WritableSignerAccount"]).addImports("solanaSigners", ["type AccountSignerMeta"]);
|
|
684
692
|
}
|
|
@@ -692,14 +700,14 @@ function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
|
692
700
|
}
|
|
693
701
|
|
|
694
702
|
// src/fragments/instructionAccountTypeParam.ts
|
|
695
|
-
var
|
|
703
|
+
var import_nodes10 = require("@codama/nodes");
|
|
696
704
|
var import_visitors_core7 = require("@codama/visitors-core");
|
|
697
705
|
function getInstructionAccountTypeParamFragment(scope) {
|
|
698
706
|
const { instructionAccountPath, allowAccountMeta, linkables } = scope;
|
|
699
707
|
const instructionAccountNode = (0, import_visitors_core7.getLastNodeFromPath)(instructionAccountPath);
|
|
700
708
|
const instructionNode = (0, import_visitors_core7.findInstructionNodeFromPath)(instructionAccountPath);
|
|
701
709
|
const programNode = (0, import_visitors_core7.findProgramNodeFromPath)(instructionAccountPath);
|
|
702
|
-
const typeParam = `TAccount${(0,
|
|
710
|
+
const typeParam = `TAccount${(0, import_nodes10.pascalCase)(instructionAccountNode.name)}`;
|
|
703
711
|
const accountMeta = allowAccountMeta ? " | AccountMeta<string>" : "";
|
|
704
712
|
const imports = new ImportMap();
|
|
705
713
|
if (allowAccountMeta) {
|
|
@@ -726,7 +734,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
726
734
|
}
|
|
727
735
|
|
|
728
736
|
// src/fragments/instructionByteDelta.ts
|
|
729
|
-
var
|
|
737
|
+
var import_nodes11 = require("@codama/nodes");
|
|
730
738
|
var import_visitors_core8 = require("@codama/visitors-core");
|
|
731
739
|
function getInstructionByteDeltaFragment(scope) {
|
|
732
740
|
const { byteDeltas } = (0, import_visitors_core8.getLastNodeFromPath)(scope.instructionPath);
|
|
@@ -740,16 +748,16 @@ const byteDelta: number = [${r.join(",")}].reduce((a, b) => a + b, 0);`
|
|
|
740
748
|
}
|
|
741
749
|
function getByteDeltaFragment(byteDelta, scope) {
|
|
742
750
|
const bytesFragment = (() => {
|
|
743
|
-
if ((0,
|
|
751
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "numberValueNode")) {
|
|
744
752
|
return getNumberValueNodeFragment(byteDelta);
|
|
745
753
|
}
|
|
746
|
-
if ((0,
|
|
754
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "argumentValueNode")) {
|
|
747
755
|
return getArgumentValueNodeFragment(byteDelta);
|
|
748
756
|
}
|
|
749
|
-
if ((0,
|
|
757
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "accountLinkNode")) {
|
|
750
758
|
return getAccountLinkNodeFragment(byteDelta, scope);
|
|
751
759
|
}
|
|
752
|
-
if ((0,
|
|
760
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "resolverValueNode")) {
|
|
753
761
|
return getResolverValueNodeFragment(byteDelta, scope);
|
|
754
762
|
}
|
|
755
763
|
return null;
|
|
@@ -764,21 +772,21 @@ function getByteDeltaFragment(byteDelta, scope) {
|
|
|
764
772
|
return [bytesFragment];
|
|
765
773
|
}
|
|
766
774
|
function getNumberValueNodeFragment(byteDelta) {
|
|
767
|
-
(0,
|
|
775
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "numberValueNode");
|
|
768
776
|
return fragment(byteDelta.value.number.toString());
|
|
769
777
|
}
|
|
770
778
|
function getArgumentValueNodeFragment(byteDelta) {
|
|
771
|
-
(0,
|
|
772
|
-
const argumentName = (0,
|
|
779
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "argumentValueNode");
|
|
780
|
+
const argumentName = (0, import_nodes11.camelCase)(byteDelta.value.name);
|
|
773
781
|
return fragment(`Number(args.${argumentName})`);
|
|
774
782
|
}
|
|
775
783
|
function getAccountLinkNodeFragment(byteDelta, scope) {
|
|
776
|
-
(0,
|
|
784
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "accountLinkNode");
|
|
777
785
|
const functionName = scope.nameApi.accountGetSizeFunction(byteDelta.value.name);
|
|
778
786
|
return fragment(`${functionName}()`).addImports(scope.getImportFrom(byteDelta.value), functionName);
|
|
779
787
|
}
|
|
780
788
|
function getResolverValueNodeFragment(byteDelta, scope) {
|
|
781
|
-
(0,
|
|
789
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "resolverValueNode");
|
|
782
790
|
const isAsync = scope.asyncResolvers.includes(byteDelta.value.name);
|
|
783
791
|
if (!scope.useAsync && isAsync) return null;
|
|
784
792
|
const awaitKeyword = scope.useAsync && isAsync ? "await " : "";
|
|
@@ -787,6 +795,7 @@ function getResolverValueNodeFragment(byteDelta, scope) {
|
|
|
787
795
|
}
|
|
788
796
|
|
|
789
797
|
// src/fragments/instructionData.ts
|
|
798
|
+
var import_nodes12 = require("@codama/nodes");
|
|
790
799
|
var import_visitors_core9 = require("@codama/visitors-core");
|
|
791
800
|
function getInstructionDataFragment(scope) {
|
|
792
801
|
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
@@ -799,12 +808,13 @@ function getInstructionDataFragment(scope) {
|
|
|
799
808
|
manifest: dataArgsManifest,
|
|
800
809
|
name: instructionDataName,
|
|
801
810
|
nameApi,
|
|
811
|
+
node: (0, import_nodes12.structTypeNodeFromInstructionArgumentNodes)(instructionNode.arguments),
|
|
802
812
|
size: scope.size
|
|
803
813
|
});
|
|
804
814
|
}
|
|
805
815
|
|
|
806
816
|
// src/fragments/discriminatorConstants.ts
|
|
807
|
-
var
|
|
817
|
+
var import_nodes13 = require("@codama/nodes");
|
|
808
818
|
var import_visitors_core10 = require("@codama/visitors-core");
|
|
809
819
|
function getDiscriminatorConstantsFragment(scope) {
|
|
810
820
|
const fragments = scope.discriminatorNodes.map((node) => getDiscriminatorConstantFragment(node, scope)).filter(Boolean);
|
|
@@ -822,9 +832,9 @@ function getDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
|
822
832
|
}
|
|
823
833
|
function getConstantDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
824
834
|
const { discriminatorNodes, typeManifestVisitor, prefix } = scope;
|
|
825
|
-
const index = discriminatorNodes.filter((0,
|
|
835
|
+
const index = discriminatorNodes.filter((0, import_nodes13.isNodeFilter)("constantDiscriminatorNode")).indexOf(discriminatorNode);
|
|
826
836
|
const suffix = index <= 0 ? "" : `_${index + 1}`;
|
|
827
|
-
const name = (0,
|
|
837
|
+
const name = (0, import_nodes13.camelCase)(`${prefix}_discriminator${suffix}`);
|
|
828
838
|
const encoder = (0, import_visitors_core10.visit)(discriminatorNode.constant.type, typeManifestVisitor).encoder;
|
|
829
839
|
const value = (0, import_visitors_core10.visit)(discriminatorNode.constant.value, typeManifestVisitor).value;
|
|
830
840
|
return getConstantFragment({ ...scope, encoder, name, value });
|
|
@@ -832,10 +842,10 @@ function getConstantDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
|
832
842
|
function getFieldDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
833
843
|
const { fields, prefix, typeManifestVisitor } = scope;
|
|
834
844
|
const field = fields.find((f) => f.name === discriminatorNode.name);
|
|
835
|
-
if (!field || !field.defaultValue || !(0,
|
|
845
|
+
if (!field || !field.defaultValue || !(0, import_nodes13.isNode)(field.defaultValue, import_nodes13.VALUE_NODES)) {
|
|
836
846
|
return null;
|
|
837
847
|
}
|
|
838
|
-
const name = (0,
|
|
848
|
+
const name = (0, import_nodes13.camelCase)(`${prefix}_${discriminatorNode.name}`);
|
|
839
849
|
const encoder = (0, import_visitors_core10.visit)(field.type, typeManifestVisitor).encoder;
|
|
840
850
|
const value = (0, import_visitors_core10.visit)(field.defaultValue, typeManifestVisitor).value;
|
|
841
851
|
return getConstantFragment({ ...scope, encoder, name, value });
|
|
@@ -870,15 +880,15 @@ function getInstructionExtraArgsFragment(scope) {
|
|
|
870
880
|
}
|
|
871
881
|
|
|
872
882
|
// src/fragments/instructionFunction.ts
|
|
873
|
-
var
|
|
883
|
+
var import_nodes18 = require("@codama/nodes");
|
|
874
884
|
var import_visitors_core16 = require("@codama/visitors-core");
|
|
875
885
|
|
|
876
886
|
// src/fragments/instructionInputResolved.ts
|
|
877
|
-
var
|
|
887
|
+
var import_nodes15 = require("@codama/nodes");
|
|
878
888
|
var import_visitors_core13 = require("@codama/visitors-core");
|
|
879
889
|
|
|
880
890
|
// src/fragments/instructionInputDefault.ts
|
|
881
|
-
var
|
|
891
|
+
var import_nodes14 = require("@codama/nodes");
|
|
882
892
|
var import_visitors_core12 = require("@codama/visitors-core");
|
|
883
893
|
function getInstructionInputDefaultFragment(scope) {
|
|
884
894
|
const { input, optionalAccountStrategy, asyncResolvers, useAsync, nameApi, typeManifestVisitor, getImportFrom } = scope;
|
|
@@ -890,8 +900,8 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
890
900
|
}
|
|
891
901
|
const { defaultValue } = input;
|
|
892
902
|
const defaultFragment = (renderedValue, isWritable) => {
|
|
893
|
-
const inputName = (0,
|
|
894
|
-
if (input.kind === "instructionAccountNode" && (0,
|
|
903
|
+
const inputName = (0, import_nodes14.camelCase)(input.name);
|
|
904
|
+
if (input.kind === "instructionAccountNode" && (0, import_nodes14.isNode)(defaultValue, "resolverValueNode")) {
|
|
895
905
|
return fragment(`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`);
|
|
896
906
|
}
|
|
897
907
|
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
@@ -907,7 +917,7 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
907
917
|
};
|
|
908
918
|
switch (defaultValue.kind) {
|
|
909
919
|
case "accountValueNode":
|
|
910
|
-
const name = (0,
|
|
920
|
+
const name = (0, import_nodes14.camelCase)(defaultValue.name);
|
|
911
921
|
if (input.kind === "instructionAccountNode" && input.resolvedIsSigner && !input.isSigner) {
|
|
912
922
|
return defaultFragment(`expectTransactionSigner(accounts.${name}.value).address`).addImports(
|
|
913
923
|
"shared",
|
|
@@ -919,17 +929,17 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
919
929
|
}
|
|
920
930
|
return defaultFragment(`expectAddress(accounts.${name}.value)`).addImports("shared", "expectAddress");
|
|
921
931
|
case "pdaValueNode":
|
|
922
|
-
if ((0,
|
|
932
|
+
if ((0, import_nodes14.isNode)(defaultValue.pda, "pdaNode")) {
|
|
923
933
|
const pdaProgram = defaultValue.pda.programId ? fragment(
|
|
924
934
|
`'${defaultValue.pda.programId}' as Address<'${defaultValue.pda.programId}'>`
|
|
925
935
|
).addImports("solanaAddresses", "type Address") : fragment("programAddress");
|
|
926
936
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
927
|
-
if ((0,
|
|
937
|
+
if ((0, import_nodes14.isNode)(seed, "constantPdaSeedNode") && (0, import_nodes14.isNode)(seed.value, "programIdValueNode")) {
|
|
928
938
|
return [
|
|
929
939
|
fragment(`getAddressEncoder().encode(${pdaProgram.render})`).mergeImportsWith(pdaProgram).addImports("solanaAddresses", "getAddressEncoder")
|
|
930
940
|
];
|
|
931
941
|
}
|
|
932
|
-
if ((0,
|
|
942
|
+
if ((0, import_nodes14.isNode)(seed, "constantPdaSeedNode") && !(0, import_nodes14.isNode)(seed.value, "programIdValueNode")) {
|
|
933
943
|
const typeManifest2 = (0, import_visitors_core12.visit)(seed.type, typeManifestVisitor);
|
|
934
944
|
const valueManifest2 = (0, import_visitors_core12.visit)(seed.value, typeManifestVisitor);
|
|
935
945
|
return [
|
|
@@ -938,21 +948,21 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
938
948
|
).mergeImportsWith(typeManifest2.encoder, valueManifest2.value)
|
|
939
949
|
];
|
|
940
950
|
}
|
|
941
|
-
if ((0,
|
|
951
|
+
if ((0, import_nodes14.isNode)(seed, "variablePdaSeedNode")) {
|
|
942
952
|
const typeManifest2 = (0, import_visitors_core12.visit)(seed.type, typeManifestVisitor);
|
|
943
953
|
const valueSeed = defaultValue.seeds.find((s) => s.name === seed.name)?.value;
|
|
944
954
|
if (!valueSeed) return [];
|
|
945
|
-
if ((0,
|
|
955
|
+
if ((0, import_nodes14.isNode)(valueSeed, "accountValueNode")) {
|
|
946
956
|
return [
|
|
947
957
|
fragment(
|
|
948
|
-
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${(0,
|
|
958
|
+
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${(0, import_nodes14.camelCase)(valueSeed.name)}.value))`
|
|
949
959
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectAddress")
|
|
950
960
|
];
|
|
951
961
|
}
|
|
952
|
-
if ((0,
|
|
962
|
+
if ((0, import_nodes14.isNode)(valueSeed, "argumentValueNode")) {
|
|
953
963
|
return [
|
|
954
964
|
fragment(
|
|
955
|
-
`${typeManifest2.encoder.render}.encode(expectSome(args.${(0,
|
|
965
|
+
`${typeManifest2.encoder.render}.encode(expectSome(args.${(0, import_nodes14.camelCase)(valueSeed.name)}))`
|
|
956
966
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectSome")
|
|
957
967
|
];
|
|
958
968
|
}
|
|
@@ -974,13 +984,13 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
974
984
|
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
975
985
|
const pdaArgs = [];
|
|
976
986
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
977
|
-
if ((0,
|
|
987
|
+
if ((0, import_nodes14.isNode)(seed.value, "accountValueNode")) {
|
|
978
988
|
return fragment(
|
|
979
|
-
`${seed.name}: expectAddress(accounts.${(0,
|
|
989
|
+
`${seed.name}: expectAddress(accounts.${(0, import_nodes14.camelCase)(seed.value.name)}.value)`
|
|
980
990
|
).addImports("shared", "expectAddress");
|
|
981
991
|
}
|
|
982
|
-
if ((0,
|
|
983
|
-
return fragment(`${seed.name}: expectSome(args.${(0,
|
|
992
|
+
if ((0, import_nodes14.isNode)(seed.value, "argumentValueNode")) {
|
|
993
|
+
return fragment(`${seed.name}: expectSome(args.${(0, import_nodes14.camelCase)(seed.value.name)})`).addImports(
|
|
984
994
|
"shared",
|
|
985
995
|
"expectSome"
|
|
986
996
|
);
|
|
@@ -1010,10 +1020,10 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
1010
1020
|
return fragment("");
|
|
1011
1021
|
case "accountBumpValueNode":
|
|
1012
1022
|
return defaultFragment(
|
|
1013
|
-
`expectProgramDerivedAddress(accounts.${(0,
|
|
1023
|
+
`expectProgramDerivedAddress(accounts.${(0, import_nodes14.camelCase)(defaultValue.name)}.value)[1]`
|
|
1014
1024
|
).addImports("shared", "expectProgramDerivedAddress");
|
|
1015
1025
|
case "argumentValueNode":
|
|
1016
|
-
return defaultFragment(`expectSome(args.${(0,
|
|
1026
|
+
return defaultFragment(`expectSome(args.${(0, import_nodes14.camelCase)(defaultValue.name)})`).addImports(
|
|
1017
1027
|
"shared",
|
|
1018
1028
|
"expectSome"
|
|
1019
1029
|
);
|
|
@@ -1042,14 +1052,14 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
1042
1052
|
}
|
|
1043
1053
|
const negatedCondition = !ifTrueRenderer;
|
|
1044
1054
|
let condition = "true";
|
|
1045
|
-
if ((0,
|
|
1055
|
+
if ((0, import_nodes14.isNode)(defaultValue.condition, "resolverValueNode")) {
|
|
1046
1056
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
1047
1057
|
conditionalFragment.addImports(getImportFrom(defaultValue.condition), conditionalResolverFunction).addFeatures(["instruction:resolverScopeVariable"]);
|
|
1048
1058
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
1049
1059
|
condition = `${conditionalResolverAwait}${conditionalResolverFunction}(resolverScope)`;
|
|
1050
1060
|
condition = negatedCondition ? `!${condition}` : condition;
|
|
1051
1061
|
} else {
|
|
1052
|
-
const comparedInputName = (0,
|
|
1062
|
+
const comparedInputName = (0, import_nodes14.isNode)(defaultValue.condition, "accountValueNode") ? `accounts.${(0, import_nodes14.camelCase)(defaultValue.condition.name)}.value` : `args.${(0, import_nodes14.camelCase)(defaultValue.condition.name)}`;
|
|
1053
1063
|
if (defaultValue.value) {
|
|
1054
1064
|
const comparedValue = (0, import_visitors_core12.visit)(defaultValue.value, typeManifestVisitor).value;
|
|
1055
1065
|
conditionalFragment.mergeImportsWith(comparedValue).mergeFeaturesWith(comparedValue);
|
|
@@ -1094,13 +1104,13 @@ function getInstructionInputResolvedFragment(scope) {
|
|
|
1094
1104
|
const inputFragment = getInstructionInputDefaultFragment({
|
|
1095
1105
|
...scope,
|
|
1096
1106
|
input,
|
|
1097
|
-
optionalAccountStrategy: (0,
|
|
1107
|
+
optionalAccountStrategy: (0, import_nodes15.parseOptionalAccountStrategy)(instructionNode.optionalAccountStrategy)
|
|
1098
1108
|
});
|
|
1099
1109
|
if (!inputFragment.render) return [];
|
|
1100
|
-
const camelName = (0,
|
|
1110
|
+
const camelName = (0, import_nodes15.camelCase)(input.name);
|
|
1101
1111
|
return [
|
|
1102
1112
|
inputFragment.mapRender(
|
|
1103
|
-
(r) => (0,
|
|
1113
|
+
(r) => (0, import_nodes15.isNode)(input, "instructionArgumentNode") ? `if (!args.${camelName}) {
|
|
1104
1114
|
${r}
|
|
1105
1115
|
}` : `if (!accounts.${camelName}.value) {
|
|
1106
1116
|
${r}
|
|
@@ -1118,7 +1128,7 @@ ${r}
|
|
|
1118
1128
|
}
|
|
1119
1129
|
|
|
1120
1130
|
// src/fragments/instructionInputType.ts
|
|
1121
|
-
var
|
|
1131
|
+
var import_nodes16 = require("@codama/nodes");
|
|
1122
1132
|
var import_visitors_core14 = require("@codama/visitors-core");
|
|
1123
1133
|
function getInstructionInputTypeFragment(scope) {
|
|
1124
1134
|
const { instructionPath, useAsync, nameApi } = scope;
|
|
@@ -1151,18 +1161,18 @@ function getAccountsFragment(scope) {
|
|
|
1151
1161
|
const resolvedAccount = resolvedInputs.find(
|
|
1152
1162
|
(input) => input.kind === "instructionAccountNode" && input.name === account.name
|
|
1153
1163
|
);
|
|
1154
|
-
const hasDefaultValue = !!resolvedAccount.defaultValue && !(0,
|
|
1155
|
-
const accountDocs = (0,
|
|
1164
|
+
const hasDefaultValue = !!resolvedAccount.defaultValue && !(0, import_nodes16.isNode)(resolvedAccount.defaultValue, ["identityValueNode", "payerValueNode"]) && (useAsync || !isAsyncDefaultValue(resolvedAccount.defaultValue, asyncResolvers));
|
|
1165
|
+
const accountDocs = (0, import_nodes16.parseDocs)(account.docs);
|
|
1156
1166
|
const docblock = accountDocs.length > 0 ? jsDocblock(accountDocs) : "";
|
|
1157
1167
|
const optionalSign = hasDefaultValue || resolvedAccount.isOptional ? "?" : "";
|
|
1158
1168
|
return getAccountTypeFragment2(resolvedAccount).mapRender(
|
|
1159
|
-
(r) => `${docblock}${(0,
|
|
1169
|
+
(r) => `${docblock}${(0, import_nodes16.camelCase)(account.name)}${optionalSign}: ${r};`
|
|
1160
1170
|
);
|
|
1161
1171
|
});
|
|
1162
1172
|
return mergeFragments(fragments, (r) => r.join("\n"));
|
|
1163
1173
|
}
|
|
1164
1174
|
function getAccountTypeFragment2(account) {
|
|
1165
|
-
const typeParam = `TAccount${(0,
|
|
1175
|
+
const typeParam = `TAccount${(0, import_nodes16.pascalCase)(account.name)}`;
|
|
1166
1176
|
if (account.isPda && account.isSigner === false) {
|
|
1167
1177
|
return fragment(`ProgramDerivedAddress<${typeParam}>`).addImports("solanaAddresses", [
|
|
1168
1178
|
"type ProgramDerivedAddress"
|
|
@@ -1210,18 +1220,18 @@ function getExtraArgumentsFragment(scope) {
|
|
|
1210
1220
|
}
|
|
1211
1221
|
function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
1212
1222
|
const resolvedArg = resolvedInputs.find(
|
|
1213
|
-
(input) => (0,
|
|
1223
|
+
(input) => (0, import_nodes16.isNode)(input, "instructionArgumentNode") && input.name === arg.name
|
|
1214
1224
|
);
|
|
1215
1225
|
if (arg.defaultValue && arg.defaultValueStrategy === "omitted") return null;
|
|
1216
1226
|
const renamedName = renamedArgs.get(arg.name) ?? arg.name;
|
|
1217
1227
|
const optionalSign = arg.defaultValue || resolvedArg?.defaultValue ? "?" : "";
|
|
1218
|
-
return argsType.mapRender((r) => `${(0,
|
|
1228
|
+
return argsType.mapRender((r) => `${(0, import_nodes16.camelCase)(renamedName)}${optionalSign}: ${r}["${(0, import_nodes16.camelCase)(arg.name)}"];`);
|
|
1219
1229
|
}
|
|
1220
1230
|
function getRemainingAccountsFragment(instructionNode) {
|
|
1221
1231
|
const fragments = (instructionNode.remainingAccounts ?? []).flatMap((remainingAccountsNode) => {
|
|
1222
|
-
if ((0,
|
|
1232
|
+
if ((0, import_nodes16.isNode)(remainingAccountsNode.value, "resolverValueNode")) return [];
|
|
1223
1233
|
const { name } = remainingAccountsNode.value;
|
|
1224
|
-
const allArguments = (0,
|
|
1234
|
+
const allArguments = (0, import_nodes16.getAllInstructionArguments)(instructionNode);
|
|
1225
1235
|
const argumentExists = allArguments.some((arg) => arg.name === name);
|
|
1226
1236
|
if (argumentExists) return [];
|
|
1227
1237
|
const isSigner = remainingAccountsNode.isSigner ?? false;
|
|
@@ -1233,13 +1243,13 @@ function getRemainingAccountsFragment(instructionNode) {
|
|
|
1233
1243
|
return mergeFragments([signerFragment, addressFragment], (r) => r.join(" | "));
|
|
1234
1244
|
}
|
|
1235
1245
|
return isSigner ? signerFragment : addressFragment;
|
|
1236
|
-
})().mapRender((r) => `${(0,
|
|
1246
|
+
})().mapRender((r) => `${(0, import_nodes16.camelCase)(name)}${optionalSign}: Array<${r}>;`);
|
|
1237
1247
|
});
|
|
1238
1248
|
return mergeFragments(fragments, (r) => r.join("\n"));
|
|
1239
1249
|
}
|
|
1240
1250
|
|
|
1241
1251
|
// src/fragments/instructionRemainingAccounts.ts
|
|
1242
|
-
var
|
|
1252
|
+
var import_nodes17 = require("@codama/nodes");
|
|
1243
1253
|
var import_visitors_core15 = require("@codama/visitors-core");
|
|
1244
1254
|
function getInstructionRemainingAccountsFragment(scope) {
|
|
1245
1255
|
const { remainingAccounts } = (0, import_visitors_core15.getLastNodeFromPath)(scope.instructionPath);
|
|
@@ -1253,10 +1263,10 @@ const remainingAccounts: AccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.join
|
|
|
1253
1263
|
}
|
|
1254
1264
|
function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
1255
1265
|
const remainingAccountsFragment = (() => {
|
|
1256
|
-
if ((0,
|
|
1266
|
+
if ((0, import_nodes17.isNode)(remainingAccounts.value, "argumentValueNode")) {
|
|
1257
1267
|
return getArgumentValueNodeFragment2(remainingAccounts, scope);
|
|
1258
1268
|
}
|
|
1259
|
-
if ((0,
|
|
1269
|
+
if ((0, import_nodes17.isNode)(remainingAccounts.value, "resolverValueNode")) {
|
|
1260
1270
|
return getResolverValueNodeFragment2(remainingAccounts, scope);
|
|
1261
1271
|
}
|
|
1262
1272
|
return null;
|
|
@@ -1266,8 +1276,8 @@ function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
|
1266
1276
|
}
|
|
1267
1277
|
function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
1268
1278
|
const instructionNode = (0, import_visitors_core15.getLastNodeFromPath)(scope.instructionPath);
|
|
1269
|
-
(0,
|
|
1270
|
-
const argumentName = (0,
|
|
1279
|
+
(0, import_nodes17.assertIsNode)(remainingAccounts.value, "argumentValueNode");
|
|
1280
|
+
const argumentName = (0, import_nodes17.camelCase)(remainingAccounts.value.name);
|
|
1271
1281
|
const isOptional = remainingAccounts.isOptional ?? false;
|
|
1272
1282
|
const isSigner = remainingAccounts.isSigner ?? false;
|
|
1273
1283
|
const isWritable = remainingAccounts.isWritable ?? false;
|
|
@@ -1275,7 +1285,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1275
1285
|
const signerRole = isWritable ? "AccountRole.WRITABLE_SIGNER" : "AccountRole.READONLY_SIGNER";
|
|
1276
1286
|
const role = isSigner === true ? signerRole : nonSignerRole;
|
|
1277
1287
|
const argumentArray = isOptional ? `(args.${argumentName} ?? [])` : `args.${argumentName}`;
|
|
1278
|
-
const allArguments = (0,
|
|
1288
|
+
const allArguments = (0, import_nodes17.getAllInstructionArguments)(instructionNode);
|
|
1279
1289
|
const argumentExists = allArguments.some((arg) => arg.name === remainingAccounts.value.name);
|
|
1280
1290
|
if (argumentExists || isSigner === false) {
|
|
1281
1291
|
return fragment(`${argumentArray}.map((address) => ({ address, role: ${role} }))`).addImports(
|
|
@@ -1296,7 +1306,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1296
1306
|
).addImports("solanaInstructions", ["AccountRole"]);
|
|
1297
1307
|
}
|
|
1298
1308
|
function getResolverValueNodeFragment2(remainingAccounts, scope) {
|
|
1299
|
-
(0,
|
|
1309
|
+
(0, import_nodes17.assertIsNode)(remainingAccounts.value, "resolverValueNode");
|
|
1300
1310
|
const isAsync = scope.asyncResolvers.includes(remainingAccounts.value.name);
|
|
1301
1311
|
if (!scope.useAsync && isAsync) return null;
|
|
1302
1312
|
const awaitKeyword = scope.useAsync && isAsync ? "await " : "";
|
|
@@ -1325,7 +1335,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1325
1335
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1326
1336
|
const hasLegacyOptionalAccounts = instructionNode.optionalAccountStrategy === "omitted" && instructionNode.accounts.some((account) => account.isOptional);
|
|
1327
1337
|
const instructionDependencies = getInstructionDependencies(instructionNode, asyncResolvers, useAsync);
|
|
1328
|
-
const argDependencies = instructionDependencies.filter((0,
|
|
1338
|
+
const argDependencies = instructionDependencies.filter((0, import_nodes18.isNodeFilter)("argumentValueNode")).map((node) => node.name);
|
|
1329
1339
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
1330
1340
|
const argIsNotOmitted = (arg) => !(arg.defaultValue && arg.defaultValueStrategy === "omitted");
|
|
1331
1341
|
const argIsDependent = (arg) => argDependencies.includes(arg.name);
|
|
@@ -1338,7 +1348,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1338
1348
|
const hasExtraArgs = (instructionNode.extraArguments ?? []).filter(
|
|
1339
1349
|
(field) => argIsNotOmitted(field) && (argIsDependent(field) || argHasDefaultValue(field))
|
|
1340
1350
|
).length > 0;
|
|
1341
|
-
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => (0,
|
|
1351
|
+
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => (0, import_nodes18.isNode)(value, "argumentValueNode")).length > 0;
|
|
1342
1352
|
const hasAnyArgs = hasDataArgs || hasExtraArgs || hasRemainingAccountArgs;
|
|
1343
1353
|
const hasInput = hasAccounts || hasAnyArgs;
|
|
1344
1354
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
@@ -1414,7 +1424,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1414
1424
|
return functionFragment;
|
|
1415
1425
|
}
|
|
1416
1426
|
function getTypeParams(instructionNode, programAddressConstant) {
|
|
1417
|
-
const typeParams = instructionNode.accounts.map((account) => `TAccount${(0,
|
|
1427
|
+
const typeParams = instructionNode.accounts.map((account) => `TAccount${(0, import_nodes18.pascalCase)(account.name)} extends string`);
|
|
1418
1428
|
typeParams.push(`TProgramAddress extends Address = typeof ${programAddressConstant}`);
|
|
1419
1429
|
return fragment(typeParams.filter((x) => !!x).join(", ")).mapRender((r) => `<${r}>`).addImports("generatedPrograms", [programAddressConstant]);
|
|
1420
1430
|
}
|
|
@@ -1424,8 +1434,8 @@ function getInstructionType(scope) {
|
|
|
1424
1434
|
const instructionTypeName = nameApi.instructionType(instructionNode.name);
|
|
1425
1435
|
const programAddressFragment = fragment("TProgramAddress");
|
|
1426
1436
|
const accountTypeParamsFragments = instructionNode.accounts.map((account) => {
|
|
1427
|
-
const typeParam = `TAccount${(0,
|
|
1428
|
-
const camelName = (0,
|
|
1437
|
+
const typeParam = `TAccount${(0, import_nodes18.pascalCase)(account.name)}`;
|
|
1438
|
+
const camelName = (0, import_nodes18.camelCase)(account.name);
|
|
1429
1439
|
if (account.isSigner === "either") {
|
|
1430
1440
|
const signerRole = account.isWritable ? "WritableSignerAccount" : "ReadonlySignerAccount";
|
|
1431
1441
|
return fragment(
|
|
@@ -1444,7 +1454,7 @@ function getInputTypeCall(scope) {
|
|
|
1444
1454
|
const instructionNode = (0, import_visitors_core16.getLastNodeFromPath)(instructionPath);
|
|
1445
1455
|
const inputTypeName = useAsync ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name);
|
|
1446
1456
|
if (instructionNode.accounts.length === 0) return fragment(inputTypeName);
|
|
1447
|
-
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0,
|
|
1457
|
+
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0, import_nodes18.pascalCase)(account.name)}`).join(", ");
|
|
1448
1458
|
return fragment(`${inputTypeName}<${accountTypeParams}>`);
|
|
1449
1459
|
}
|
|
1450
1460
|
|
|
@@ -1483,7 +1493,7 @@ function getInstructionParseFunctionFragment(scope) {
|
|
|
1483
1493
|
}
|
|
1484
1494
|
|
|
1485
1495
|
// src/fragments/instructionType.ts
|
|
1486
|
-
var
|
|
1496
|
+
var import_nodes19 = require("@codama/nodes");
|
|
1487
1497
|
var import_visitors_core18 = require("@codama/visitors-core");
|
|
1488
1498
|
function getInstructionTypeFragment(scope) {
|
|
1489
1499
|
const { instructionPath, nameApi, customInstructionData } = scope;
|
|
@@ -1494,7 +1504,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1494
1504
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
1495
1505
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
1496
1506
|
const programAddressConstant = nameApi.programAddressConstant(programNode.name);
|
|
1497
|
-
const dataType = customData ? (0,
|
|
1507
|
+
const dataType = customData ? (0, import_nodes19.pascalCase)(customData.importAs) : (0, import_nodes19.pascalCase)(instructionDataName);
|
|
1498
1508
|
const accountTypeParamsFragment = mergeFragments(
|
|
1499
1509
|
instructionNode.accounts.map(
|
|
1500
1510
|
(account) => getInstructionAccountTypeParamFragment({
|
|
@@ -1509,7 +1519,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1509
1519
|
const accountMetasFragment = mergeFragments(
|
|
1510
1520
|
instructionNode.accounts.map(
|
|
1511
1521
|
(account) => getInstructionAccountMetaFragment(account).mapRender((r) => {
|
|
1512
|
-
const typeParam = `TAccount${(0,
|
|
1522
|
+
const typeParam = `TAccount${(0, import_nodes19.pascalCase)(account.name)}`;
|
|
1513
1523
|
const isLegacyOptional = account.isOptional && usesLegacyOptionalAccounts;
|
|
1514
1524
|
const type = `${typeParam} extends string ? ${r} : ${typeParam}`;
|
|
1515
1525
|
if (!isLegacyOptional) return type;
|
|
@@ -1537,7 +1547,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1537
1547
|
}
|
|
1538
1548
|
|
|
1539
1549
|
// src/fragments/pdaFunction.ts
|
|
1540
|
-
var
|
|
1550
|
+
var import_nodes20 = require("@codama/nodes");
|
|
1541
1551
|
var import_visitors_core19 = require("@codama/visitors-core");
|
|
1542
1552
|
function getPdaFunctionFragment(scope) {
|
|
1543
1553
|
const { pdaPath, typeManifestVisitor, nameApi } = scope;
|
|
@@ -1545,12 +1555,12 @@ function getPdaFunctionFragment(scope) {
|
|
|
1545
1555
|
const programNode = (0, import_visitors_core19.findProgramNodeFromPath)(pdaPath);
|
|
1546
1556
|
const imports = new ImportMap();
|
|
1547
1557
|
const seeds = pdaNode.seeds.map((seed) => {
|
|
1548
|
-
if ((0,
|
|
1558
|
+
if ((0, import_nodes20.isNode)(seed, "variablePdaSeedNode")) {
|
|
1549
1559
|
const seedManifest2 = (0, import_visitors_core19.visit)(seed.type, typeManifestVisitor);
|
|
1550
1560
|
imports.mergeWith(seedManifest2.looseType, seedManifest2.encoder);
|
|
1551
1561
|
return { ...seed, typeManifest: seedManifest2 };
|
|
1552
1562
|
}
|
|
1553
|
-
if ((0,
|
|
1563
|
+
if ((0, import_nodes20.isNode)(seed.value, "programIdValueNode")) {
|
|
1554
1564
|
imports.add("solanaAddresses", "getAddressEncoder");
|
|
1555
1565
|
return seed;
|
|
1556
1566
|
}
|
|
@@ -1560,7 +1570,7 @@ function getPdaFunctionFragment(scope) {
|
|
|
1560
1570
|
imports.mergeWith(valueManifest.imports);
|
|
1561
1571
|
return { ...seed, typeManifest: seedManifest, valueManifest };
|
|
1562
1572
|
});
|
|
1563
|
-
const hasVariableSeeds = pdaNode.seeds.filter((0,
|
|
1573
|
+
const hasVariableSeeds = pdaNode.seeds.filter((0, import_nodes20.isNodeFilter)("variablePdaSeedNode")).length > 0;
|
|
1564
1574
|
return fragmentFromTemplate("pdaFunction.njk", {
|
|
1565
1575
|
findPdaFunction: nameApi.pdaFindFunction(pdaNode.name),
|
|
1566
1576
|
hasVariableSeeds,
|
|
@@ -1580,7 +1590,7 @@ function getProgramFragment(scope) {
|
|
|
1580
1590
|
}
|
|
1581
1591
|
|
|
1582
1592
|
// src/fragments/programAccounts.ts
|
|
1583
|
-
var
|
|
1593
|
+
var import_nodes21 = require("@codama/nodes");
|
|
1584
1594
|
function getProgramAccountsFragment(scope) {
|
|
1585
1595
|
if (scope.programNode.accounts.length === 0) return fragment("");
|
|
1586
1596
|
return mergeFragments(
|
|
@@ -1614,7 +1624,7 @@ function getProgramAccountsIdentifierFunctionFragment(scope) {
|
|
|
1614
1624
|
dataName: "data",
|
|
1615
1625
|
discriminators: account.discriminators ?? [],
|
|
1616
1626
|
ifTrue: `return ${programAccountsEnum}.${variant};`,
|
|
1617
|
-
struct: (0,
|
|
1627
|
+
struct: (0, import_nodes21.resolveNestedTypeNode)(account.data)
|
|
1618
1628
|
});
|
|
1619
1629
|
}),
|
|
1620
1630
|
(r) => r.join("\n")
|
|
@@ -1645,10 +1655,10 @@ function getProgramErrorsFragment(scope) {
|
|
|
1645
1655
|
}
|
|
1646
1656
|
|
|
1647
1657
|
// src/fragments/programInstructions.ts
|
|
1648
|
-
var
|
|
1658
|
+
var import_nodes22 = require("@codama/nodes");
|
|
1649
1659
|
function getProgramInstructionsFragment(scope) {
|
|
1650
1660
|
if (scope.programNode.instructions.length === 0) return fragment("");
|
|
1651
|
-
const allInstructions = (0,
|
|
1661
|
+
const allInstructions = (0, import_nodes22.getAllInstructionsWithSubs)(scope.programNode, {
|
|
1652
1662
|
leavesOnly: !scope.renderParentInstructions,
|
|
1653
1663
|
subInstructionsFirst: true
|
|
1654
1664
|
});
|
|
@@ -1690,7 +1700,7 @@ function getProgramInstructionsIdentifierFunctionFragment(scope) {
|
|
|
1690
1700
|
dataName: "data",
|
|
1691
1701
|
discriminators: instruction.discriminators ?? [],
|
|
1692
1702
|
ifTrue: `return ${programInstructionsEnum}.${variant};`,
|
|
1693
|
-
struct: (0,
|
|
1703
|
+
struct: (0, import_nodes22.structTypeNodeFromInstructionArgumentNodes)(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
|
-
var
|
|
1738
|
+
var import_nodes23 = require("@codama/nodes");
|
|
1729
1739
|
function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
1730
1740
|
const { name, typeNode, nameApi } = scope;
|
|
1731
|
-
const isDiscriminatedUnion = (0,
|
|
1741
|
+
const isDiscriminatedUnion = (0, import_nodes23.isNode)(typeNode, "enumTypeNode") && (0, import_nodes23.isDataEnum)(typeNode);
|
|
1732
1742
|
if (!isDiscriminatedUnion) {
|
|
1733
1743
|
return fragment("");
|
|
1734
1744
|
}
|
|
@@ -1773,12 +1783,12 @@ function mergeManifests(manifests, options = {}) {
|
|
|
1773
1783
|
// src/getRenderMapVisitor.ts
|
|
1774
1784
|
var import_node_path3 = require("path");
|
|
1775
1785
|
var import_errors2 = require("@codama/errors");
|
|
1776
|
-
var
|
|
1786
|
+
var import_nodes26 = require("@codama/nodes");
|
|
1777
1787
|
var import_renderers_core = require("@codama/renderers-core");
|
|
1778
1788
|
var import_visitors_core21 = require("@codama/visitors-core");
|
|
1779
1789
|
|
|
1780
1790
|
// src/getTypeManifestVisitor.ts
|
|
1781
|
-
var
|
|
1791
|
+
var import_nodes24 = require("@codama/nodes");
|
|
1782
1792
|
var import_visitors_core20 = require("@codama/visitors-core");
|
|
1783
1793
|
function getTypeManifestVisitor(input) {
|
|
1784
1794
|
const { nameApi, linkables, nonScalarEnums, customAccountData, customInstructionData, getImportFrom } = input;
|
|
@@ -1796,8 +1806,8 @@ function getTypeManifestVisitor(input) {
|
|
|
1796
1806
|
}),
|
|
1797
1807
|
{
|
|
1798
1808
|
keys: [
|
|
1799
|
-
...
|
|
1800
|
-
...
|
|
1809
|
+
...import_nodes24.REGISTERED_TYPE_NODE_KINDS,
|
|
1810
|
+
...import_nodes24.REGISTERED_VALUE_NODE_KINDS,
|
|
1801
1811
|
"definedTypeLinkNode",
|
|
1802
1812
|
"definedTypeNode",
|
|
1803
1813
|
"accountNode",
|
|
@@ -1841,7 +1851,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1841
1851
|
const decoderImports = new ImportMap().add("solanaCodecsDataStructures", "getBooleanDecoder");
|
|
1842
1852
|
let sizeEncoder = "";
|
|
1843
1853
|
let sizeDecoder = "";
|
|
1844
|
-
const resolvedSize = (0,
|
|
1854
|
+
const resolvedSize = (0, import_nodes24.resolveNestedTypeNode)(booleanType.size);
|
|
1845
1855
|
if (resolvedSize.format !== "u8" || resolvedSize.endian !== "le") {
|
|
1846
1856
|
const size = (0, import_visitors_core20.visit)(booleanType.size, self);
|
|
1847
1857
|
encoderImports.mergeWith(size.encoder);
|
|
@@ -1892,7 +1902,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1892
1902
|
return manifest;
|
|
1893
1903
|
},
|
|
1894
1904
|
visitConstantValue(node, { self }) {
|
|
1895
|
-
if ((0,
|
|
1905
|
+
if ((0, import_nodes24.isNode)(node.type, "bytesTypeNode") && (0, import_nodes24.isNode)(node.value, "bytesValueNode")) {
|
|
1896
1906
|
return (0, import_visitors_core20.visit)(node.value, self);
|
|
1897
1907
|
}
|
|
1898
1908
|
return {
|
|
@@ -1931,7 +1941,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1931
1941
|
};
|
|
1932
1942
|
},
|
|
1933
1943
|
visitEnumEmptyVariantType(enumEmptyVariantType) {
|
|
1934
|
-
const discriminator = nameApi.discriminatedUnionDiscriminator((0,
|
|
1944
|
+
const discriminator = nameApi.discriminatedUnionDiscriminator((0, import_nodes24.camelCase)(parentName?.strict ?? ""));
|
|
1935
1945
|
const name = nameApi.discriminatedUnionVariant(enumEmptyVariantType.name);
|
|
1936
1946
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1937
1947
|
return {
|
|
@@ -1952,7 +1962,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1952
1962
|
visitEnumStructVariantType(enumStructVariantType, { self }) {
|
|
1953
1963
|
const currentParentName = parentName;
|
|
1954
1964
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1955
|
-
(0,
|
|
1965
|
+
(0, import_nodes24.camelCase)(currentParentName?.strict ?? "")
|
|
1956
1966
|
);
|
|
1957
1967
|
const name = nameApi.discriminatedUnionVariant(enumStructVariantType.name);
|
|
1958
1968
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
@@ -1968,12 +1978,12 @@ function getTypeManifestVisitor(input) {
|
|
|
1968
1978
|
visitEnumTupleVariantType(enumTupleVariantType, { self }) {
|
|
1969
1979
|
const currentParentName = parentName;
|
|
1970
1980
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1971
|
-
(0,
|
|
1981
|
+
(0, import_nodes24.camelCase)(currentParentName?.strict ?? "")
|
|
1972
1982
|
);
|
|
1973
1983
|
const name = nameApi.discriminatedUnionVariant(enumTupleVariantType.name);
|
|
1974
1984
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1975
|
-
const struct = (0,
|
|
1976
|
-
(0,
|
|
1985
|
+
const struct = (0, import_nodes24.structTypeNode)([
|
|
1986
|
+
(0, import_nodes24.structFieldTypeNode)({
|
|
1977
1987
|
name: "fields",
|
|
1978
1988
|
type: enumTupleVariantType.tuple
|
|
1979
1989
|
})
|
|
@@ -1993,7 +2003,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1993
2003
|
const decoderImports = new ImportMap();
|
|
1994
2004
|
const encoderOptions = [];
|
|
1995
2005
|
const decoderOptions = [];
|
|
1996
|
-
const enumSize = (0,
|
|
2006
|
+
const enumSize = (0, import_nodes24.resolveNestedTypeNode)(enumType.size);
|
|
1997
2007
|
if (enumSize.format !== "u8" || enumSize.endian !== "le") {
|
|
1998
2008
|
const sizeManifest = (0, import_visitors_core20.visit)(enumType.size, self);
|
|
1999
2009
|
encoderImports.mergeWith(sizeManifest.encoder);
|
|
@@ -2002,15 +2012,15 @@ function getTypeManifestVisitor(input) {
|
|
|
2002
2012
|
decoderOptions.push(`size: ${sizeManifest.decoder.render}`);
|
|
2003
2013
|
}
|
|
2004
2014
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2005
|
-
(0,
|
|
2015
|
+
(0, import_nodes24.camelCase)(currentParentName?.strict ?? "")
|
|
2006
2016
|
);
|
|
2007
|
-
if (!(0,
|
|
2017
|
+
if (!(0, import_nodes24.isScalarEnum)(enumType) && discriminator !== "__kind") {
|
|
2008
2018
|
encoderOptions.push(`discriminator: '${discriminator}'`);
|
|
2009
2019
|
decoderOptions.push(`discriminator: '${discriminator}'`);
|
|
2010
2020
|
}
|
|
2011
2021
|
const encoderOptionsAsString = encoderOptions.length > 0 ? `, { ${encoderOptions.join(", ")} }` : "";
|
|
2012
2022
|
const decoderOptionsAsString = decoderOptions.length > 0 ? `, { ${decoderOptions.join(", ")} }` : "";
|
|
2013
|
-
if ((0,
|
|
2023
|
+
if ((0, import_nodes24.isScalarEnum)(enumType)) {
|
|
2014
2024
|
if (currentParentName === null) {
|
|
2015
2025
|
throw new Error(
|
|
2016
2026
|
"Scalar enums cannot be inlined and must be introduced via a defined type. Ensure you are not inlining a defined type that is a scalar enum through a visitor."
|
|
@@ -2049,7 +2059,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2049
2059
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
2050
2060
|
const importFrom = getImportFrom(node.enum);
|
|
2051
2061
|
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
2052
|
-
const isScalar = enumNode && (0,
|
|
2062
|
+
const isScalar = enumNode && (0, import_nodes24.isNode)(enumNode, "enumTypeNode") ? (0, import_nodes24.isScalarEnum)(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
2053
2063
|
if (!node.value && isScalar) {
|
|
2054
2064
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
2055
2065
|
manifest.value.setRender(`${enumName}.${variantName2}`).addImports(importFrom, enumName);
|
|
@@ -2094,7 +2104,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2094
2104
|
strict: nameApi.dataType(instructionDataName)
|
|
2095
2105
|
};
|
|
2096
2106
|
const link = customInstructionData.get(instruction.name)?.linkNode;
|
|
2097
|
-
const struct = (0,
|
|
2107
|
+
const struct = (0, import_nodes24.structTypeNodeFromInstructionArgumentNodes)(instruction.arguments);
|
|
2098
2108
|
const manifest = link ? (0, import_visitors_core20.visit)(link, self) : (0, import_visitors_core20.visit)(struct, self);
|
|
2099
2109
|
parentName = null;
|
|
2100
2110
|
return manifest;
|
|
@@ -2161,7 +2171,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2161
2171
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2162
2172
|
const encoderOptions = [];
|
|
2163
2173
|
const decoderOptions = [];
|
|
2164
|
-
const optionPrefix = (0,
|
|
2174
|
+
const optionPrefix = (0, import_nodes24.resolveNestedTypeNode)(optionType.prefix);
|
|
2165
2175
|
if (optionPrefix.format !== "u8" || optionPrefix.endian !== "le") {
|
|
2166
2176
|
const prefixManifest = (0, import_visitors_core20.visit)(optionType.prefix, self);
|
|
2167
2177
|
childManifest.encoder.mergeImportsWith(prefixManifest.encoder);
|
|
@@ -2327,9 +2337,9 @@ function getTypeManifestVisitor(input) {
|
|
|
2327
2337
|
return manifest;
|
|
2328
2338
|
},
|
|
2329
2339
|
visitStructFieldType(structFieldType, { self }) {
|
|
2330
|
-
const name = (0,
|
|
2340
|
+
const name = (0, import_nodes24.camelCase)(structFieldType.name);
|
|
2331
2341
|
const childManifest = (0, import_visitors_core20.visit)(structFieldType.type, self);
|
|
2332
|
-
const structFieldDocs = (0,
|
|
2342
|
+
const structFieldDocs = (0, import_nodes24.parseDocs)(structFieldType.docs);
|
|
2333
2343
|
const docblock = structFieldDocs.length > 0 ? `
|
|
2334
2344
|
${jsDocblock(structFieldDocs)}` : "";
|
|
2335
2345
|
const originalLooseType = childManifest.looseType.render;
|
|
@@ -2371,11 +2381,11 @@ ${jsDocblock(structFieldDocs)}` : "";
|
|
|
2371
2381
|
const accountNode = (0, import_visitors_core20.findLastNodeFromPath)(parentPath, "accountNode");
|
|
2372
2382
|
const discriminatorPrefix = instructionNode ? instructionNode.name : accountNode?.name;
|
|
2373
2383
|
const discriminators = (instructionNode ? instructionNode.discriminators : accountNode?.discriminators) ?? [];
|
|
2374
|
-
const fieldDiscriminators = discriminators.filter((0,
|
|
2384
|
+
const fieldDiscriminators = discriminators.filter((0, import_nodes24.isNodeFilter)("fieldDiscriminatorNode"));
|
|
2375
2385
|
const defaultValues = optionalFields.map((f) => {
|
|
2376
|
-
const key = (0,
|
|
2386
|
+
const key = (0, import_nodes24.camelCase)(f.name);
|
|
2377
2387
|
if (fieldDiscriminators.some((d) => d.name === f.name)) {
|
|
2378
|
-
const constantName = nameApi.constant((0,
|
|
2388
|
+
const constantName = nameApi.constant((0, import_nodes24.camelCase)(`${discriminatorPrefix}_${f.name}`));
|
|
2379
2389
|
return f.defaultValueStrategy === "omitted" ? `${key}: ${constantName}` : `${key}: value.${key} ?? ${constantName}`;
|
|
2380
2390
|
}
|
|
2381
2391
|
const defaultValue = f.defaultValue;
|
|
@@ -2435,19 +2445,19 @@ ${jsDocblock(structFieldDocs)}` : "";
|
|
|
2435
2445
|
);
|
|
2436
2446
|
}
|
|
2437
2447
|
function getArrayLikeSizeOption(count, visitor) {
|
|
2438
|
-
if ((0,
|
|
2448
|
+
if ((0, import_nodes24.isNode)(count, "fixedCountNode")) {
|
|
2439
2449
|
return {
|
|
2440
2450
|
decoder: fragment(`size: ${count.value}`),
|
|
2441
2451
|
encoder: fragment(`size: ${count.value}`)
|
|
2442
2452
|
};
|
|
2443
2453
|
}
|
|
2444
|
-
if ((0,
|
|
2454
|
+
if ((0, import_nodes24.isNode)(count, "remainderCountNode")) {
|
|
2445
2455
|
return {
|
|
2446
2456
|
decoder: fragment(`size: 'remainder'`),
|
|
2447
2457
|
encoder: fragment(`size: 'remainder'`)
|
|
2448
2458
|
};
|
|
2449
2459
|
}
|
|
2450
|
-
const prefix = (0,
|
|
2460
|
+
const prefix = (0, import_nodes24.resolveNestedTypeNode)(count.prefix);
|
|
2451
2461
|
if (prefix.format === "u32" && prefix.endian === "le") {
|
|
2452
2462
|
return { decoder: fragment(""), encoder: fragment("") };
|
|
2453
2463
|
}
|
|
@@ -2458,67 +2468,67 @@ function getArrayLikeSizeOption(count, visitor) {
|
|
|
2458
2468
|
}
|
|
2459
2469
|
|
|
2460
2470
|
// src/nameTransformers.ts
|
|
2461
|
-
var
|
|
2471
|
+
var import_nodes25 = require("@codama/nodes");
|
|
2462
2472
|
function getNameApi(transformers) {
|
|
2463
2473
|
const helpers = {
|
|
2464
|
-
camelCase:
|
|
2465
|
-
capitalize:
|
|
2466
|
-
kebabCase:
|
|
2467
|
-
pascalCase:
|
|
2468
|
-
snakeCase:
|
|
2469
|
-
titleCase:
|
|
2474
|
+
camelCase: import_nodes25.camelCase,
|
|
2475
|
+
capitalize: import_nodes25.capitalize,
|
|
2476
|
+
kebabCase: import_nodes25.kebabCase,
|
|
2477
|
+
pascalCase: import_nodes25.pascalCase,
|
|
2478
|
+
snakeCase: import_nodes25.snakeCase,
|
|
2479
|
+
titleCase: import_nodes25.titleCase
|
|
2470
2480
|
};
|
|
2471
2481
|
return Object.fromEntries(
|
|
2472
2482
|
Object.entries(transformers).map(([key, transformer]) => [key, (name) => transformer(name, helpers)])
|
|
2473
2483
|
);
|
|
2474
2484
|
}
|
|
2475
2485
|
var DEFAULT_NAME_TRANSFORMERS = {
|
|
2476
|
-
accountDecodeFunction: (name) => `decode${(0,
|
|
2477
|
-
accountFetchAllFunction: (name) => `fetchAll${(0,
|
|
2478
|
-
accountFetchAllMaybeFunction: (name) => `fetchAllMaybe${(0,
|
|
2479
|
-
accountFetchFromSeedsFunction: (name) => `fetch${(0,
|
|
2480
|
-
accountFetchFunction: (name) => `fetch${(0,
|
|
2481
|
-
accountFetchMaybeFromSeedsFunction: (name) => `fetchMaybe${(0,
|
|
2482
|
-
accountFetchMaybeFunction: (name) => `fetchMaybe${(0,
|
|
2483
|
-
accountGetSizeFunction: (name) => `get${(0,
|
|
2484
|
-
codecFunction: (name) => `get${(0,
|
|
2485
|
-
constant: (name) => (0,
|
|
2486
|
-
constantFunction: (name) => `get${(0,
|
|
2487
|
-
dataArgsType: (name) => `${(0,
|
|
2488
|
-
dataType: (name) => `${(0,
|
|
2489
|
-
decoderFunction: (name) => `get${(0,
|
|
2486
|
+
accountDecodeFunction: (name) => `decode${(0, import_nodes25.pascalCase)(name)}`,
|
|
2487
|
+
accountFetchAllFunction: (name) => `fetchAll${(0, import_nodes25.pascalCase)(name)}`,
|
|
2488
|
+
accountFetchAllMaybeFunction: (name) => `fetchAllMaybe${(0, import_nodes25.pascalCase)(name)}`,
|
|
2489
|
+
accountFetchFromSeedsFunction: (name) => `fetch${(0, import_nodes25.pascalCase)(name)}FromSeeds`,
|
|
2490
|
+
accountFetchFunction: (name) => `fetch${(0, import_nodes25.pascalCase)(name)}`,
|
|
2491
|
+
accountFetchMaybeFromSeedsFunction: (name) => `fetchMaybe${(0, import_nodes25.pascalCase)(name)}FromSeeds`,
|
|
2492
|
+
accountFetchMaybeFunction: (name) => `fetchMaybe${(0, import_nodes25.pascalCase)(name)}`,
|
|
2493
|
+
accountGetSizeFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}Size`,
|
|
2494
|
+
codecFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}Codec`,
|
|
2495
|
+
constant: (name) => (0, import_nodes25.snakeCase)(name).toUpperCase(),
|
|
2496
|
+
constantFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}Bytes`,
|
|
2497
|
+
dataArgsType: (name) => `${(0, import_nodes25.pascalCase)(name)}Args`,
|
|
2498
|
+
dataType: (name) => `${(0, import_nodes25.pascalCase)(name)}`,
|
|
2499
|
+
decoderFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}Decoder`,
|
|
2490
2500
|
discriminatedUnionDiscriminator: () => "__kind",
|
|
2491
|
-
discriminatedUnionFunction: (name) => `${(0,
|
|
2492
|
-
discriminatedUnionVariant: (name) => `${(0,
|
|
2493
|
-
encoderFunction: (name) => `get${(0,
|
|
2494
|
-
enumVariant: (name) => `${(0,
|
|
2495
|
-
instructionAsyncFunction: (name) => `get${(0,
|
|
2496
|
-
instructionAsyncInputType: (name) => `${(0,
|
|
2497
|
-
instructionDataType: (name) => `${(0,
|
|
2498
|
-
instructionExtraType: (name) => `${(0,
|
|
2499
|
-
instructionParseFunction: (name) => `parse${(0,
|
|
2500
|
-
instructionParsedType: (name) => `Parsed${(0,
|
|
2501
|
-
instructionSyncFunction: (name) => `get${(0,
|
|
2502
|
-
instructionSyncInputType: (name) => `${(0,
|
|
2503
|
-
instructionType: (name) => `${(0,
|
|
2504
|
-
isDiscriminatedUnionFunction: (name) => `is${(0,
|
|
2505
|
-
pdaFindFunction: (name) => `find${(0,
|
|
2506
|
-
pdaSeedsType: (name) => `${(0,
|
|
2507
|
-
programAccountsEnum: (name) => `${(0,
|
|
2508
|
-
programAccountsEnumVariant: (name) => `${(0,
|
|
2509
|
-
programAccountsIdentifierFunction: (name) => `identify${(0,
|
|
2510
|
-
programAddressConstant: (name) => `${(0,
|
|
2511
|
-
programErrorConstant: (name) => (0,
|
|
2512
|
-
programErrorConstantPrefix: (name) => `${(0,
|
|
2513
|
-
programErrorMessagesMap: (name) => `${(0,
|
|
2514
|
-
programErrorUnion: (name) => `${(0,
|
|
2515
|
-
programGetErrorMessageFunction: (name) => `get${(0,
|
|
2516
|
-
programInstructionsEnum: (name) => `${(0,
|
|
2517
|
-
programInstructionsEnumVariant: (name) => `${(0,
|
|
2518
|
-
programInstructionsIdentifierFunction: (name) => `identify${(0,
|
|
2519
|
-
programInstructionsParsedUnionType: (name) => `Parsed${(0,
|
|
2520
|
-
programIsErrorFunction: (name) => `is${(0,
|
|
2521
|
-
resolverFunction: (name) => `${(0,
|
|
2501
|
+
discriminatedUnionFunction: (name) => `${(0, import_nodes25.camelCase)(name)}`,
|
|
2502
|
+
discriminatedUnionVariant: (name) => `${(0, import_nodes25.pascalCase)(name)}`,
|
|
2503
|
+
encoderFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}Encoder`,
|
|
2504
|
+
enumVariant: (name) => `${(0, import_nodes25.pascalCase)(name)}`,
|
|
2505
|
+
instructionAsyncFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}InstructionAsync`,
|
|
2506
|
+
instructionAsyncInputType: (name) => `${(0, import_nodes25.pascalCase)(name)}AsyncInput`,
|
|
2507
|
+
instructionDataType: (name) => `${(0, import_nodes25.pascalCase)(name)}InstructionData`,
|
|
2508
|
+
instructionExtraType: (name) => `${(0, import_nodes25.pascalCase)(name)}InstructionExtra`,
|
|
2509
|
+
instructionParseFunction: (name) => `parse${(0, import_nodes25.pascalCase)(name)}Instruction`,
|
|
2510
|
+
instructionParsedType: (name) => `Parsed${(0, import_nodes25.pascalCase)(name)}Instruction`,
|
|
2511
|
+
instructionSyncFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}Instruction`,
|
|
2512
|
+
instructionSyncInputType: (name) => `${(0, import_nodes25.pascalCase)(name)}Input`,
|
|
2513
|
+
instructionType: (name) => `${(0, import_nodes25.pascalCase)(name)}Instruction`,
|
|
2514
|
+
isDiscriminatedUnionFunction: (name) => `is${(0, import_nodes25.pascalCase)(name)}`,
|
|
2515
|
+
pdaFindFunction: (name) => `find${(0, import_nodes25.pascalCase)(name)}Pda`,
|
|
2516
|
+
pdaSeedsType: (name) => `${(0, import_nodes25.pascalCase)(name)}Seeds`,
|
|
2517
|
+
programAccountsEnum: (name) => `${(0, import_nodes25.pascalCase)(name)}Account`,
|
|
2518
|
+
programAccountsEnumVariant: (name) => `${(0, import_nodes25.pascalCase)(name)}`,
|
|
2519
|
+
programAccountsIdentifierFunction: (name) => `identify${(0, import_nodes25.pascalCase)(name)}Account`,
|
|
2520
|
+
programAddressConstant: (name) => `${(0, import_nodes25.snakeCase)(name).toUpperCase()}_PROGRAM_ADDRESS`,
|
|
2521
|
+
programErrorConstant: (name) => (0, import_nodes25.snakeCase)(name).toUpperCase(),
|
|
2522
|
+
programErrorConstantPrefix: (name) => `${(0, import_nodes25.snakeCase)(name).toUpperCase()}_ERROR__`,
|
|
2523
|
+
programErrorMessagesMap: (name) => `${(0, import_nodes25.camelCase)(name)}ErrorMessages`,
|
|
2524
|
+
programErrorUnion: (name) => `${(0, import_nodes25.pascalCase)(name)}Error`,
|
|
2525
|
+
programGetErrorMessageFunction: (name) => `get${(0, import_nodes25.pascalCase)(name)}ErrorMessage`,
|
|
2526
|
+
programInstructionsEnum: (name) => `${(0, import_nodes25.pascalCase)(name)}Instruction`,
|
|
2527
|
+
programInstructionsEnumVariant: (name) => `${(0, import_nodes25.pascalCase)(name)}`,
|
|
2528
|
+
programInstructionsIdentifierFunction: (name) => `identify${(0, import_nodes25.pascalCase)(name)}Instruction`,
|
|
2529
|
+
programInstructionsParsedUnionType: (name) => `Parsed${(0, import_nodes25.pascalCase)(name)}Instruction`,
|
|
2530
|
+
programIsErrorFunction: (name) => `is${(0, import_nodes25.pascalCase)(name)}Error`,
|
|
2531
|
+
resolverFunction: (name) => `${(0, import_nodes25.camelCase)(name)}`
|
|
2522
2532
|
};
|
|
2523
2533
|
|
|
2524
2534
|
// src/getRenderMapVisitor.ts
|
|
@@ -2533,9 +2543,9 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2533
2543
|
const renderParentInstructions = options.renderParentInstructions ?? false;
|
|
2534
2544
|
const dependencyMap = options.dependencyMap ?? {};
|
|
2535
2545
|
const useGranularImports = options.useGranularImports ?? false;
|
|
2536
|
-
const asyncResolvers = (options.asyncResolvers ?? []).map(
|
|
2537
|
-
const nonScalarEnums = (options.nonScalarEnums ?? []).map(
|
|
2538
|
-
const internalNodes = (options.internalNodes ?? []).map(
|
|
2546
|
+
const asyncResolvers = (options.asyncResolvers ?? []).map(import_nodes26.camelCase);
|
|
2547
|
+
const nonScalarEnums = (options.nonScalarEnums ?? []).map(import_nodes26.camelCase);
|
|
2548
|
+
const internalNodes = (options.internalNodes ?? []).map(import_nodes26.camelCase);
|
|
2539
2549
|
const customAccountData = parseCustomDataOptions(options.customAccountData ?? [], "AccountData");
|
|
2540
2550
|
const customInstructionData = parseCustomDataOptions(options.customInstructionData ?? [], "InstructionData");
|
|
2541
2551
|
const getImportFrom = getImportFromFactory(options.linkOverrides ?? {}, customAccountData, customInstructionData);
|
|
@@ -2580,7 +2590,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2580
2590
|
size: (0, import_visitors_core21.visit)(node, byteSizeVisitor),
|
|
2581
2591
|
typeManifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor)
|
|
2582
2592
|
};
|
|
2583
|
-
const fields = (0,
|
|
2593
|
+
const fields = (0, import_nodes26.resolveNestedTypeNode)(node.data).fields;
|
|
2584
2594
|
const accountDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2585
2595
|
...scope,
|
|
2586
2596
|
discriminatorNodes: node.discriminators ?? [],
|
|
@@ -2599,7 +2609,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2599
2609
|
accountPdaHelpersFragment
|
|
2600
2610
|
);
|
|
2601
2611
|
return new import_renderers_core.RenderMap().add(
|
|
2602
|
-
`accounts/${(0,
|
|
2612
|
+
`accounts/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2603
2613
|
render2("accountsPage.njk", {
|
|
2604
2614
|
accountDiscriminatorConstantsFragment,
|
|
2605
2615
|
accountFetchHelpersFragment,
|
|
@@ -2618,6 +2628,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2618
2628
|
encoderDocs: [],
|
|
2619
2629
|
manifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor),
|
|
2620
2630
|
name: node.name,
|
|
2631
|
+
node: node.type,
|
|
2621
2632
|
size: (0, import_visitors_core21.visit)(node, byteSizeVisitor),
|
|
2622
2633
|
typeDocs: node.docs,
|
|
2623
2634
|
typeNode: node.type
|
|
@@ -2632,7 +2643,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2632
2643
|
nameApi.codecFunction(node.name)
|
|
2633
2644
|
]);
|
|
2634
2645
|
return new import_renderers_core.RenderMap().add(
|
|
2635
|
-
`types/${(0,
|
|
2646
|
+
`types/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2636
2647
|
render2("definedTypesPage.njk", {
|
|
2637
2648
|
imports: imports.toString({
|
|
2638
2649
|
...dependencyMap,
|
|
@@ -2653,9 +2664,9 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2653
2664
|
...globalScope,
|
|
2654
2665
|
dataArgsManifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor),
|
|
2655
2666
|
extraArgsManifest: (0, import_visitors_core21.visit)(
|
|
2656
|
-
(0,
|
|
2667
|
+
(0, import_nodes26.definedTypeNode)({
|
|
2657
2668
|
name: instructionExtraName,
|
|
2658
|
-
type: (0,
|
|
2669
|
+
type: (0, import_nodes26.structTypeNodeFromInstructionArgumentNodes)(node.extraArguments ?? [])
|
|
2659
2670
|
}),
|
|
2660
2671
|
typeManifestVisitor
|
|
2661
2672
|
),
|
|
@@ -2692,7 +2703,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2692
2703
|
instructionParseFunctionFragment
|
|
2693
2704
|
);
|
|
2694
2705
|
return new import_renderers_core.RenderMap().add(
|
|
2695
|
-
`instructions/${(0,
|
|
2706
|
+
`instructions/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2696
2707
|
render2("instructionsPage.njk", {
|
|
2697
2708
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2698
2709
|
instruction: node,
|
|
@@ -2715,7 +2726,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2715
2726
|
const pdaFunctionFragment = getPdaFunctionFragment(scope);
|
|
2716
2727
|
const imports = new ImportMap().mergeWith(pdaFunctionFragment);
|
|
2717
2728
|
return new import_renderers_core.RenderMap().add(
|
|
2718
|
-
`pdas/${(0,
|
|
2729
|
+
`pdas/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2719
2730
|
render2("pdasPage.njk", {
|
|
2720
2731
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2721
2732
|
pdaFunctionFragment
|
|
@@ -2732,7 +2743,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2732
2743
|
if (node.errors.length > 0) {
|
|
2733
2744
|
const programErrorsFragment = getProgramErrorsFragment(scope);
|
|
2734
2745
|
renderMap.add(
|
|
2735
|
-
`errors/${(0,
|
|
2746
|
+
`errors/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2736
2747
|
render2("errorsPage.njk", {
|
|
2737
2748
|
imports: new ImportMap().mergeWith(programErrorsFragment).toString(dependencyMap, useGranularImports),
|
|
2738
2749
|
programErrorsFragment
|
|
@@ -2743,7 +2754,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2743
2754
|
const programAccountsFragment = getProgramAccountsFragment(scope);
|
|
2744
2755
|
const programInstructionsFragment = getProgramInstructionsFragment(scope);
|
|
2745
2756
|
renderMap.add(
|
|
2746
|
-
`programs/${(0,
|
|
2757
|
+
`programs/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2747
2758
|
render2("programsPage.njk", {
|
|
2748
2759
|
imports: new ImportMap().mergeWith(programFragment, programAccountsFragment, programInstructionsFragment).toString(dependencyMap, useGranularImports),
|
|
2749
2760
|
programAccountsFragment,
|
|
@@ -2752,7 +2763,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2752
2763
|
})
|
|
2753
2764
|
);
|
|
2754
2765
|
renderMap.mergeWith(
|
|
2755
|
-
...(0,
|
|
2766
|
+
...(0, import_nodes26.getAllInstructionsWithSubs)(node, {
|
|
2756
2767
|
leavesOnly: !renderParentInstructions
|
|
2757
2768
|
}).map((ix) => (0, import_visitors_core21.visit)(ix, self))
|
|
2758
2769
|
);
|
|
@@ -2760,14 +2771,14 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2760
2771
|
},
|
|
2761
2772
|
visitRoot(node, { self }) {
|
|
2762
2773
|
const isNotInternal = (n) => !internalNodes.includes(n.name);
|
|
2763
|
-
const programsToExport = (0,
|
|
2774
|
+
const programsToExport = (0, import_nodes26.getAllPrograms)(node).filter(isNotInternal);
|
|
2764
2775
|
const programsWithErrorsToExport = programsToExport.filter((p) => p.errors.length > 0);
|
|
2765
|
-
const pdasToExport = (0,
|
|
2766
|
-
const accountsToExport = (0,
|
|
2767
|
-
const instructionsToExport = (0,
|
|
2776
|
+
const pdasToExport = (0, import_nodes26.getAllPdas)(node);
|
|
2777
|
+
const accountsToExport = (0, import_nodes26.getAllAccounts)(node).filter(isNotInternal);
|
|
2778
|
+
const instructionsToExport = (0, import_nodes26.getAllInstructionsWithSubs)(node, {
|
|
2768
2779
|
leavesOnly: !renderParentInstructions
|
|
2769
2780
|
}).filter(isNotInternal);
|
|
2770
|
-
const definedTypesToExport = (0,
|
|
2781
|
+
const definedTypesToExport = (0, import_nodes26.getAllDefinedTypes)(node).filter(isNotInternal);
|
|
2771
2782
|
const hasAnythingToExport = programsToExport.length > 0 || accountsToExport.length > 0 || instructionsToExport.length > 0 || definedTypesToExport.length > 0;
|
|
2772
2783
|
const ctx = {
|
|
2773
2784
|
accountsToExport,
|
|
@@ -2819,7 +2830,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2819
2830
|
if (definedTypesToExport.length > 0) {
|
|
2820
2831
|
map.add("types/index.ts", render2("definedTypesIndex.njk", ctx));
|
|
2821
2832
|
}
|
|
2822
|
-
return map.add("index.ts", render2("rootIndex.njk", ctx)).mergeWith(...(0,
|
|
2833
|
+
return map.add("index.ts", render2("rootIndex.njk", ctx)).mergeWith(...(0, import_nodes26.getAllPrograms)(node).map((p) => (0, import_visitors_core21.visit)(p, self)));
|
|
2823
2834
|
}
|
|
2824
2835
|
}),
|
|
2825
2836
|
(v) => (0, import_visitors_core21.recordNodeStackVisitor)(v, stack),
|
|
@@ -2841,7 +2852,7 @@ function getRenamedArgsMap(instruction) {
|
|
|
2841
2852
|
(0, import_errors2.logWarn)(
|
|
2842
2853
|
`[JavaScript] Accounts and args of instruction [${instruction.name}] have the following conflicting attributes [${duplicates.join(", ")}]. Thus, the arguments have been renamed to avoid conflicts in the input type.`
|
|
2843
2854
|
);
|
|
2844
|
-
return new Map(duplicates.map((name) => [(0,
|
|
2855
|
+
return new Map(duplicates.map((name) => [(0, import_nodes26.camelCase)(name), (0, import_nodes26.camelCase)(`${name}Arg`)]));
|
|
2845
2856
|
}
|
|
2846
2857
|
|
|
2847
2858
|
// src/renderVisitor.ts
|