@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.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,45 +551,57 @@ 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;
|
|
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";
|
|
555
559
|
return fragmentFromTemplate("typeDecoder.njk", {
|
|
556
560
|
decoderFunction: nameApi.decoderFunction(name),
|
|
561
|
+
decoderType,
|
|
557
562
|
docs,
|
|
558
563
|
looseName: nameApi.dataArgsType(name),
|
|
559
564
|
manifest,
|
|
560
|
-
strictName: nameApi.dataType(name)
|
|
561
|
-
|
|
565
|
+
strictName: nameApi.dataType(name),
|
|
566
|
+
useTypeCast
|
|
567
|
+
}).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore", `type ${decoderType}`);
|
|
562
568
|
}
|
|
563
569
|
|
|
564
570
|
// src/fragments/typeEncoder.ts
|
|
571
|
+
var import_nodes6 = require("@codama/nodes");
|
|
565
572
|
function getTypeEncoderFragment(scope) {
|
|
566
|
-
const { name, manifest, nameApi, docs = [] } = scope;
|
|
573
|
+
const { name, node, manifest, nameApi, docs = [] } = scope;
|
|
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";
|
|
567
576
|
return fragmentFromTemplate("typeEncoder.njk", {
|
|
568
577
|
docs,
|
|
569
578
|
encoderFunction: nameApi.encoderFunction(name),
|
|
579
|
+
encoderType,
|
|
570
580
|
looseName: nameApi.dataArgsType(name),
|
|
571
581
|
manifest,
|
|
572
|
-
strictName: nameApi.dataType(name)
|
|
573
|
-
|
|
582
|
+
strictName: nameApi.dataType(name),
|
|
583
|
+
useTypeCast
|
|
584
|
+
}).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore", `type ${encoderType}`);
|
|
574
585
|
}
|
|
575
586
|
|
|
576
587
|
// src/fragments/typeCodec.ts
|
|
577
588
|
function getTypeCodecFragment(scope) {
|
|
578
589
|
const { name, manifest, nameApi } = scope;
|
|
590
|
+
const codecType = typeof scope.size === "number" ? "FixedSizeCodec" : "Codec";
|
|
579
591
|
return mergeFragments(
|
|
580
592
|
[
|
|
581
593
|
getTypeEncoderFragment({ ...scope, docs: scope.encoderDocs }),
|
|
582
594
|
getTypeDecoderFragment({ ...scope, docs: scope.decoderDocs }),
|
|
583
595
|
fragmentFromTemplate("typeCodec.njk", {
|
|
584
596
|
codecFunction: nameApi.codecFunction(name),
|
|
597
|
+
codecType,
|
|
585
598
|
decoderFunction: nameApi.decoderFunction(name),
|
|
586
599
|
docs: scope.codecDocs,
|
|
587
600
|
encoderFunction: nameApi.encoderFunction(name),
|
|
588
601
|
looseName: nameApi.dataArgsType(name),
|
|
589
602
|
manifest,
|
|
590
603
|
strictName: nameApi.dataType(name)
|
|
591
|
-
}).addImports("solanaCodecsCore", [
|
|
604
|
+
}).addImports("solanaCodecsCore", [`type ${codecType}`, "combineCodec"])
|
|
592
605
|
],
|
|
593
606
|
(renders) => renders.join("\n\n")
|
|
594
607
|
);
|
|
@@ -612,24 +625,26 @@ function getAccountTypeFragment(scope) {
|
|
|
612
625
|
return getTypeWithCodecFragment({
|
|
613
626
|
manifest: typeManifest2,
|
|
614
627
|
name: accountNode.name,
|
|
615
|
-
nameApi
|
|
628
|
+
nameApi,
|
|
629
|
+
node: (0, import_nodes7.resolveNestedTypeNode)(accountNode.data),
|
|
630
|
+
size: scope.size
|
|
616
631
|
});
|
|
617
632
|
}
|
|
618
633
|
|
|
619
634
|
// src/fragments/discriminatorCondition.ts
|
|
620
|
-
var
|
|
635
|
+
var import_nodes8 = require("@codama/nodes");
|
|
621
636
|
var import_visitors_core6 = require("@codama/visitors-core");
|
|
622
637
|
var import_codecs_strings2 = require("@solana/codecs-strings");
|
|
623
638
|
function getDiscriminatorConditionFragment(scope) {
|
|
624
639
|
return mergeFragments(
|
|
625
640
|
scope.discriminators.flatMap((discriminator) => {
|
|
626
|
-
if ((0,
|
|
641
|
+
if ((0, import_nodes8.isNode)(discriminator, "sizeDiscriminatorNode")) {
|
|
627
642
|
return [getSizeConditionFragment(discriminator, scope)];
|
|
628
643
|
}
|
|
629
|
-
if ((0,
|
|
644
|
+
if ((0, import_nodes8.isNode)(discriminator, "constantDiscriminatorNode")) {
|
|
630
645
|
return [getByteConditionFragment(discriminator, scope)];
|
|
631
646
|
}
|
|
632
|
-
if ((0,
|
|
647
|
+
if ((0, import_nodes8.isNode)(discriminator, "fieldDiscriminatorNode")) {
|
|
633
648
|
return [getFieldConditionFragment(discriminator, scope)];
|
|
634
649
|
}
|
|
635
650
|
return [];
|
|
@@ -653,25 +668,25 @@ function getFieldConditionFragment(discriminator, scope) {
|
|
|
653
668
|
`Field discriminator "${discriminator.name}" does not have a matching argument with default value.`
|
|
654
669
|
);
|
|
655
670
|
}
|
|
656
|
-
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"))) {
|
|
657
672
|
const base64Bytes = (0, import_codecs_strings2.getBase64Decoder)().decode(
|
|
658
673
|
new Uint8Array(field.defaultValue.items.map((node) => node.number))
|
|
659
674
|
);
|
|
660
675
|
return getByteConditionFragment(
|
|
661
|
-
(0,
|
|
676
|
+
(0, import_nodes8.constantDiscriminatorNode)((0, import_nodes8.constantValueNodeFromBytes)("base64", base64Bytes), discriminator.offset),
|
|
662
677
|
scope
|
|
663
678
|
);
|
|
664
679
|
}
|
|
665
680
|
return getByteConditionFragment(
|
|
666
|
-
(0,
|
|
681
|
+
(0, import_nodes8.constantDiscriminatorNode)((0, import_nodes8.constantValueNode)(field.type, field.defaultValue), discriminator.offset),
|
|
667
682
|
scope
|
|
668
683
|
);
|
|
669
684
|
}
|
|
670
685
|
|
|
671
686
|
// src/fragments/instructionAccountMeta.ts
|
|
672
|
-
var
|
|
687
|
+
var import_nodes9 = require("@codama/nodes");
|
|
673
688
|
function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
674
|
-
const typeParam = `TAccount${(0,
|
|
689
|
+
const typeParam = `TAccount${(0, import_nodes9.pascalCase)(instructionAccountNode.name)}`;
|
|
675
690
|
if (instructionAccountNode.isSigner === true && instructionAccountNode.isWritable) {
|
|
676
691
|
return fragment(`WritableSignerAccount<${typeParam}> & AccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type WritableSignerAccount"]).addImports("solanaSigners", ["type AccountSignerMeta"]);
|
|
677
692
|
}
|
|
@@ -685,14 +700,14 @@ function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
|
685
700
|
}
|
|
686
701
|
|
|
687
702
|
// src/fragments/instructionAccountTypeParam.ts
|
|
688
|
-
var
|
|
703
|
+
var import_nodes10 = require("@codama/nodes");
|
|
689
704
|
var import_visitors_core7 = require("@codama/visitors-core");
|
|
690
705
|
function getInstructionAccountTypeParamFragment(scope) {
|
|
691
706
|
const { instructionAccountPath, allowAccountMeta, linkables } = scope;
|
|
692
707
|
const instructionAccountNode = (0, import_visitors_core7.getLastNodeFromPath)(instructionAccountPath);
|
|
693
708
|
const instructionNode = (0, import_visitors_core7.findInstructionNodeFromPath)(instructionAccountPath);
|
|
694
709
|
const programNode = (0, import_visitors_core7.findProgramNodeFromPath)(instructionAccountPath);
|
|
695
|
-
const typeParam = `TAccount${(0,
|
|
710
|
+
const typeParam = `TAccount${(0, import_nodes10.pascalCase)(instructionAccountNode.name)}`;
|
|
696
711
|
const accountMeta = allowAccountMeta ? " | AccountMeta<string>" : "";
|
|
697
712
|
const imports = new ImportMap();
|
|
698
713
|
if (allowAccountMeta) {
|
|
@@ -719,7 +734,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
719
734
|
}
|
|
720
735
|
|
|
721
736
|
// src/fragments/instructionByteDelta.ts
|
|
722
|
-
var
|
|
737
|
+
var import_nodes11 = require("@codama/nodes");
|
|
723
738
|
var import_visitors_core8 = require("@codama/visitors-core");
|
|
724
739
|
function getInstructionByteDeltaFragment(scope) {
|
|
725
740
|
const { byteDeltas } = (0, import_visitors_core8.getLastNodeFromPath)(scope.instructionPath);
|
|
@@ -733,16 +748,16 @@ const byteDelta: number = [${r.join(",")}].reduce((a, b) => a + b, 0);`
|
|
|
733
748
|
}
|
|
734
749
|
function getByteDeltaFragment(byteDelta, scope) {
|
|
735
750
|
const bytesFragment = (() => {
|
|
736
|
-
if ((0,
|
|
751
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "numberValueNode")) {
|
|
737
752
|
return getNumberValueNodeFragment(byteDelta);
|
|
738
753
|
}
|
|
739
|
-
if ((0,
|
|
754
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "argumentValueNode")) {
|
|
740
755
|
return getArgumentValueNodeFragment(byteDelta);
|
|
741
756
|
}
|
|
742
|
-
if ((0,
|
|
757
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "accountLinkNode")) {
|
|
743
758
|
return getAccountLinkNodeFragment(byteDelta, scope);
|
|
744
759
|
}
|
|
745
|
-
if ((0,
|
|
760
|
+
if ((0, import_nodes11.isNode)(byteDelta.value, "resolverValueNode")) {
|
|
746
761
|
return getResolverValueNodeFragment(byteDelta, scope);
|
|
747
762
|
}
|
|
748
763
|
return null;
|
|
@@ -757,21 +772,21 @@ function getByteDeltaFragment(byteDelta, scope) {
|
|
|
757
772
|
return [bytesFragment];
|
|
758
773
|
}
|
|
759
774
|
function getNumberValueNodeFragment(byteDelta) {
|
|
760
|
-
(0,
|
|
775
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "numberValueNode");
|
|
761
776
|
return fragment(byteDelta.value.number.toString());
|
|
762
777
|
}
|
|
763
778
|
function getArgumentValueNodeFragment(byteDelta) {
|
|
764
|
-
(0,
|
|
765
|
-
const argumentName = (0,
|
|
779
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "argumentValueNode");
|
|
780
|
+
const argumentName = (0, import_nodes11.camelCase)(byteDelta.value.name);
|
|
766
781
|
return fragment(`Number(args.${argumentName})`);
|
|
767
782
|
}
|
|
768
783
|
function getAccountLinkNodeFragment(byteDelta, scope) {
|
|
769
|
-
(0,
|
|
784
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "accountLinkNode");
|
|
770
785
|
const functionName = scope.nameApi.accountGetSizeFunction(byteDelta.value.name);
|
|
771
786
|
return fragment(`${functionName}()`).addImports(scope.getImportFrom(byteDelta.value), functionName);
|
|
772
787
|
}
|
|
773
788
|
function getResolverValueNodeFragment(byteDelta, scope) {
|
|
774
|
-
(0,
|
|
789
|
+
(0, import_nodes11.assertIsNode)(byteDelta.value, "resolverValueNode");
|
|
775
790
|
const isAsync = scope.asyncResolvers.includes(byteDelta.value.name);
|
|
776
791
|
if (!scope.useAsync && isAsync) return null;
|
|
777
792
|
const awaitKeyword = scope.useAsync && isAsync ? "await " : "";
|
|
@@ -780,6 +795,7 @@ function getResolverValueNodeFragment(byteDelta, scope) {
|
|
|
780
795
|
}
|
|
781
796
|
|
|
782
797
|
// src/fragments/instructionData.ts
|
|
798
|
+
var import_nodes12 = require("@codama/nodes");
|
|
783
799
|
var import_visitors_core9 = require("@codama/visitors-core");
|
|
784
800
|
function getInstructionDataFragment(scope) {
|
|
785
801
|
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
@@ -791,12 +807,14 @@ function getInstructionDataFragment(scope) {
|
|
|
791
807
|
return getTypeWithCodecFragment({
|
|
792
808
|
manifest: dataArgsManifest,
|
|
793
809
|
name: instructionDataName,
|
|
794
|
-
nameApi
|
|
810
|
+
nameApi,
|
|
811
|
+
node: (0, import_nodes12.structTypeNodeFromInstructionArgumentNodes)(instructionNode.arguments),
|
|
812
|
+
size: scope.size
|
|
795
813
|
});
|
|
796
814
|
}
|
|
797
815
|
|
|
798
816
|
// src/fragments/discriminatorConstants.ts
|
|
799
|
-
var
|
|
817
|
+
var import_nodes13 = require("@codama/nodes");
|
|
800
818
|
var import_visitors_core10 = require("@codama/visitors-core");
|
|
801
819
|
function getDiscriminatorConstantsFragment(scope) {
|
|
802
820
|
const fragments = scope.discriminatorNodes.map((node) => getDiscriminatorConstantFragment(node, scope)).filter(Boolean);
|
|
@@ -814,9 +832,9 @@ function getDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
|
814
832
|
}
|
|
815
833
|
function getConstantDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
816
834
|
const { discriminatorNodes, typeManifestVisitor, prefix } = scope;
|
|
817
|
-
const index = discriminatorNodes.filter((0,
|
|
835
|
+
const index = discriminatorNodes.filter((0, import_nodes13.isNodeFilter)("constantDiscriminatorNode")).indexOf(discriminatorNode);
|
|
818
836
|
const suffix = index <= 0 ? "" : `_${index + 1}`;
|
|
819
|
-
const name = (0,
|
|
837
|
+
const name = (0, import_nodes13.camelCase)(`${prefix}_discriminator${suffix}`);
|
|
820
838
|
const encoder = (0, import_visitors_core10.visit)(discriminatorNode.constant.type, typeManifestVisitor).encoder;
|
|
821
839
|
const value = (0, import_visitors_core10.visit)(discriminatorNode.constant.value, typeManifestVisitor).value;
|
|
822
840
|
return getConstantFragment({ ...scope, encoder, name, value });
|
|
@@ -824,10 +842,10 @@ function getConstantDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
|
824
842
|
function getFieldDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
825
843
|
const { fields, prefix, typeManifestVisitor } = scope;
|
|
826
844
|
const field = fields.find((f) => f.name === discriminatorNode.name);
|
|
827
|
-
if (!field || !field.defaultValue || !(0,
|
|
845
|
+
if (!field || !field.defaultValue || !(0, import_nodes13.isNode)(field.defaultValue, import_nodes13.VALUE_NODES)) {
|
|
828
846
|
return null;
|
|
829
847
|
}
|
|
830
|
-
const name = (0,
|
|
848
|
+
const name = (0, import_nodes13.camelCase)(`${prefix}_${discriminatorNode.name}`);
|
|
831
849
|
const encoder = (0, import_visitors_core10.visit)(field.type, typeManifestVisitor).encoder;
|
|
832
850
|
const value = (0, import_visitors_core10.visit)(field.defaultValue, typeManifestVisitor).value;
|
|
833
851
|
return getConstantFragment({ ...scope, encoder, name, value });
|
|
@@ -862,15 +880,15 @@ function getInstructionExtraArgsFragment(scope) {
|
|
|
862
880
|
}
|
|
863
881
|
|
|
864
882
|
// src/fragments/instructionFunction.ts
|
|
865
|
-
var
|
|
883
|
+
var import_nodes18 = require("@codama/nodes");
|
|
866
884
|
var import_visitors_core16 = require("@codama/visitors-core");
|
|
867
885
|
|
|
868
886
|
// src/fragments/instructionInputResolved.ts
|
|
869
|
-
var
|
|
887
|
+
var import_nodes15 = require("@codama/nodes");
|
|
870
888
|
var import_visitors_core13 = require("@codama/visitors-core");
|
|
871
889
|
|
|
872
890
|
// src/fragments/instructionInputDefault.ts
|
|
873
|
-
var
|
|
891
|
+
var import_nodes14 = require("@codama/nodes");
|
|
874
892
|
var import_visitors_core12 = require("@codama/visitors-core");
|
|
875
893
|
function getInstructionInputDefaultFragment(scope) {
|
|
876
894
|
const { input, optionalAccountStrategy, asyncResolvers, useAsync, nameApi, typeManifestVisitor, getImportFrom } = scope;
|
|
@@ -882,8 +900,8 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
882
900
|
}
|
|
883
901
|
const { defaultValue } = input;
|
|
884
902
|
const defaultFragment = (renderedValue, isWritable) => {
|
|
885
|
-
const inputName = (0,
|
|
886
|
-
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")) {
|
|
887
905
|
return fragment(`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`);
|
|
888
906
|
}
|
|
889
907
|
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
@@ -899,7 +917,7 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
899
917
|
};
|
|
900
918
|
switch (defaultValue.kind) {
|
|
901
919
|
case "accountValueNode":
|
|
902
|
-
const name = (0,
|
|
920
|
+
const name = (0, import_nodes14.camelCase)(defaultValue.name);
|
|
903
921
|
if (input.kind === "instructionAccountNode" && input.resolvedIsSigner && !input.isSigner) {
|
|
904
922
|
return defaultFragment(`expectTransactionSigner(accounts.${name}.value).address`).addImports(
|
|
905
923
|
"shared",
|
|
@@ -911,17 +929,17 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
911
929
|
}
|
|
912
930
|
return defaultFragment(`expectAddress(accounts.${name}.value)`).addImports("shared", "expectAddress");
|
|
913
931
|
case "pdaValueNode":
|
|
914
|
-
if ((0,
|
|
932
|
+
if ((0, import_nodes14.isNode)(defaultValue.pda, "pdaNode")) {
|
|
915
933
|
const pdaProgram = defaultValue.pda.programId ? fragment(
|
|
916
934
|
`'${defaultValue.pda.programId}' as Address<'${defaultValue.pda.programId}'>`
|
|
917
935
|
).addImports("solanaAddresses", "type Address") : fragment("programAddress");
|
|
918
936
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
919
|
-
if ((0,
|
|
937
|
+
if ((0, import_nodes14.isNode)(seed, "constantPdaSeedNode") && (0, import_nodes14.isNode)(seed.value, "programIdValueNode")) {
|
|
920
938
|
return [
|
|
921
939
|
fragment(`getAddressEncoder().encode(${pdaProgram.render})`).mergeImportsWith(pdaProgram).addImports("solanaAddresses", "getAddressEncoder")
|
|
922
940
|
];
|
|
923
941
|
}
|
|
924
|
-
if ((0,
|
|
942
|
+
if ((0, import_nodes14.isNode)(seed, "constantPdaSeedNode") && !(0, import_nodes14.isNode)(seed.value, "programIdValueNode")) {
|
|
925
943
|
const typeManifest2 = (0, import_visitors_core12.visit)(seed.type, typeManifestVisitor);
|
|
926
944
|
const valueManifest2 = (0, import_visitors_core12.visit)(seed.value, typeManifestVisitor);
|
|
927
945
|
return [
|
|
@@ -930,21 +948,21 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
930
948
|
).mergeImportsWith(typeManifest2.encoder, valueManifest2.value)
|
|
931
949
|
];
|
|
932
950
|
}
|
|
933
|
-
if ((0,
|
|
951
|
+
if ((0, import_nodes14.isNode)(seed, "variablePdaSeedNode")) {
|
|
934
952
|
const typeManifest2 = (0, import_visitors_core12.visit)(seed.type, typeManifestVisitor);
|
|
935
953
|
const valueSeed = defaultValue.seeds.find((s) => s.name === seed.name)?.value;
|
|
936
954
|
if (!valueSeed) return [];
|
|
937
|
-
if ((0,
|
|
955
|
+
if ((0, import_nodes14.isNode)(valueSeed, "accountValueNode")) {
|
|
938
956
|
return [
|
|
939
957
|
fragment(
|
|
940
|
-
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${(0,
|
|
958
|
+
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${(0, import_nodes14.camelCase)(valueSeed.name)}.value))`
|
|
941
959
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectAddress")
|
|
942
960
|
];
|
|
943
961
|
}
|
|
944
|
-
if ((0,
|
|
962
|
+
if ((0, import_nodes14.isNode)(valueSeed, "argumentValueNode")) {
|
|
945
963
|
return [
|
|
946
964
|
fragment(
|
|
947
|
-
`${typeManifest2.encoder.render}.encode(expectSome(args.${(0,
|
|
965
|
+
`${typeManifest2.encoder.render}.encode(expectSome(args.${(0, import_nodes14.camelCase)(valueSeed.name)}))`
|
|
948
966
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectSome")
|
|
949
967
|
];
|
|
950
968
|
}
|
|
@@ -966,13 +984,13 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
966
984
|
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
967
985
|
const pdaArgs = [];
|
|
968
986
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
969
|
-
if ((0,
|
|
987
|
+
if ((0, import_nodes14.isNode)(seed.value, "accountValueNode")) {
|
|
970
988
|
return fragment(
|
|
971
|
-
`${seed.name}: expectAddress(accounts.${(0,
|
|
989
|
+
`${seed.name}: expectAddress(accounts.${(0, import_nodes14.camelCase)(seed.value.name)}.value)`
|
|
972
990
|
).addImports("shared", "expectAddress");
|
|
973
991
|
}
|
|
974
|
-
if ((0,
|
|
975
|
-
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(
|
|
976
994
|
"shared",
|
|
977
995
|
"expectSome"
|
|
978
996
|
);
|
|
@@ -1002,10 +1020,10 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
1002
1020
|
return fragment("");
|
|
1003
1021
|
case "accountBumpValueNode":
|
|
1004
1022
|
return defaultFragment(
|
|
1005
|
-
`expectProgramDerivedAddress(accounts.${(0,
|
|
1023
|
+
`expectProgramDerivedAddress(accounts.${(0, import_nodes14.camelCase)(defaultValue.name)}.value)[1]`
|
|
1006
1024
|
).addImports("shared", "expectProgramDerivedAddress");
|
|
1007
1025
|
case "argumentValueNode":
|
|
1008
|
-
return defaultFragment(`expectSome(args.${(0,
|
|
1026
|
+
return defaultFragment(`expectSome(args.${(0, import_nodes14.camelCase)(defaultValue.name)})`).addImports(
|
|
1009
1027
|
"shared",
|
|
1010
1028
|
"expectSome"
|
|
1011
1029
|
);
|
|
@@ -1034,14 +1052,14 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
1034
1052
|
}
|
|
1035
1053
|
const negatedCondition = !ifTrueRenderer;
|
|
1036
1054
|
let condition = "true";
|
|
1037
|
-
if ((0,
|
|
1055
|
+
if ((0, import_nodes14.isNode)(defaultValue.condition, "resolverValueNode")) {
|
|
1038
1056
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
1039
1057
|
conditionalFragment.addImports(getImportFrom(defaultValue.condition), conditionalResolverFunction).addFeatures(["instruction:resolverScopeVariable"]);
|
|
1040
1058
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
1041
1059
|
condition = `${conditionalResolverAwait}${conditionalResolverFunction}(resolverScope)`;
|
|
1042
1060
|
condition = negatedCondition ? `!${condition}` : condition;
|
|
1043
1061
|
} else {
|
|
1044
|
-
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)}`;
|
|
1045
1063
|
if (defaultValue.value) {
|
|
1046
1064
|
const comparedValue = (0, import_visitors_core12.visit)(defaultValue.value, typeManifestVisitor).value;
|
|
1047
1065
|
conditionalFragment.mergeImportsWith(comparedValue).mergeFeaturesWith(comparedValue);
|
|
@@ -1086,13 +1104,13 @@ function getInstructionInputResolvedFragment(scope) {
|
|
|
1086
1104
|
const inputFragment = getInstructionInputDefaultFragment({
|
|
1087
1105
|
...scope,
|
|
1088
1106
|
input,
|
|
1089
|
-
optionalAccountStrategy: (0,
|
|
1107
|
+
optionalAccountStrategy: (0, import_nodes15.parseOptionalAccountStrategy)(instructionNode.optionalAccountStrategy)
|
|
1090
1108
|
});
|
|
1091
1109
|
if (!inputFragment.render) return [];
|
|
1092
|
-
const camelName = (0,
|
|
1110
|
+
const camelName = (0, import_nodes15.camelCase)(input.name);
|
|
1093
1111
|
return [
|
|
1094
1112
|
inputFragment.mapRender(
|
|
1095
|
-
(r) => (0,
|
|
1113
|
+
(r) => (0, import_nodes15.isNode)(input, "instructionArgumentNode") ? `if (!args.${camelName}) {
|
|
1096
1114
|
${r}
|
|
1097
1115
|
}` : `if (!accounts.${camelName}.value) {
|
|
1098
1116
|
${r}
|
|
@@ -1110,7 +1128,7 @@ ${r}
|
|
|
1110
1128
|
}
|
|
1111
1129
|
|
|
1112
1130
|
// src/fragments/instructionInputType.ts
|
|
1113
|
-
var
|
|
1131
|
+
var import_nodes16 = require("@codama/nodes");
|
|
1114
1132
|
var import_visitors_core14 = require("@codama/visitors-core");
|
|
1115
1133
|
function getInstructionInputTypeFragment(scope) {
|
|
1116
1134
|
const { instructionPath, useAsync, nameApi } = scope;
|
|
@@ -1143,18 +1161,18 @@ function getAccountsFragment(scope) {
|
|
|
1143
1161
|
const resolvedAccount = resolvedInputs.find(
|
|
1144
1162
|
(input) => input.kind === "instructionAccountNode" && input.name === account.name
|
|
1145
1163
|
);
|
|
1146
|
-
const hasDefaultValue = !!resolvedAccount.defaultValue && !(0,
|
|
1147
|
-
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);
|
|
1148
1166
|
const docblock = accountDocs.length > 0 ? jsDocblock(accountDocs) : "";
|
|
1149
1167
|
const optionalSign = hasDefaultValue || resolvedAccount.isOptional ? "?" : "";
|
|
1150
1168
|
return getAccountTypeFragment2(resolvedAccount).mapRender(
|
|
1151
|
-
(r) => `${docblock}${(0,
|
|
1169
|
+
(r) => `${docblock}${(0, import_nodes16.camelCase)(account.name)}${optionalSign}: ${r};`
|
|
1152
1170
|
);
|
|
1153
1171
|
});
|
|
1154
1172
|
return mergeFragments(fragments, (r) => r.join("\n"));
|
|
1155
1173
|
}
|
|
1156
1174
|
function getAccountTypeFragment2(account) {
|
|
1157
|
-
const typeParam = `TAccount${(0,
|
|
1175
|
+
const typeParam = `TAccount${(0, import_nodes16.pascalCase)(account.name)}`;
|
|
1158
1176
|
if (account.isPda && account.isSigner === false) {
|
|
1159
1177
|
return fragment(`ProgramDerivedAddress<${typeParam}>`).addImports("solanaAddresses", [
|
|
1160
1178
|
"type ProgramDerivedAddress"
|
|
@@ -1202,18 +1220,18 @@ function getExtraArgumentsFragment(scope) {
|
|
|
1202
1220
|
}
|
|
1203
1221
|
function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
1204
1222
|
const resolvedArg = resolvedInputs.find(
|
|
1205
|
-
(input) => (0,
|
|
1223
|
+
(input) => (0, import_nodes16.isNode)(input, "instructionArgumentNode") && input.name === arg.name
|
|
1206
1224
|
);
|
|
1207
1225
|
if (arg.defaultValue && arg.defaultValueStrategy === "omitted") return null;
|
|
1208
1226
|
const renamedName = renamedArgs.get(arg.name) ?? arg.name;
|
|
1209
1227
|
const optionalSign = arg.defaultValue || resolvedArg?.defaultValue ? "?" : "";
|
|
1210
|
-
return argsType.mapRender((r) => `${(0,
|
|
1228
|
+
return argsType.mapRender((r) => `${(0, import_nodes16.camelCase)(renamedName)}${optionalSign}: ${r}["${(0, import_nodes16.camelCase)(arg.name)}"];`);
|
|
1211
1229
|
}
|
|
1212
1230
|
function getRemainingAccountsFragment(instructionNode) {
|
|
1213
1231
|
const fragments = (instructionNode.remainingAccounts ?? []).flatMap((remainingAccountsNode) => {
|
|
1214
|
-
if ((0,
|
|
1232
|
+
if ((0, import_nodes16.isNode)(remainingAccountsNode.value, "resolverValueNode")) return [];
|
|
1215
1233
|
const { name } = remainingAccountsNode.value;
|
|
1216
|
-
const allArguments = (0,
|
|
1234
|
+
const allArguments = (0, import_nodes16.getAllInstructionArguments)(instructionNode);
|
|
1217
1235
|
const argumentExists = allArguments.some((arg) => arg.name === name);
|
|
1218
1236
|
if (argumentExists) return [];
|
|
1219
1237
|
const isSigner = remainingAccountsNode.isSigner ?? false;
|
|
@@ -1225,13 +1243,13 @@ function getRemainingAccountsFragment(instructionNode) {
|
|
|
1225
1243
|
return mergeFragments([signerFragment, addressFragment], (r) => r.join(" | "));
|
|
1226
1244
|
}
|
|
1227
1245
|
return isSigner ? signerFragment : addressFragment;
|
|
1228
|
-
})().mapRender((r) => `${(0,
|
|
1246
|
+
})().mapRender((r) => `${(0, import_nodes16.camelCase)(name)}${optionalSign}: Array<${r}>;`);
|
|
1229
1247
|
});
|
|
1230
1248
|
return mergeFragments(fragments, (r) => r.join("\n"));
|
|
1231
1249
|
}
|
|
1232
1250
|
|
|
1233
1251
|
// src/fragments/instructionRemainingAccounts.ts
|
|
1234
|
-
var
|
|
1252
|
+
var import_nodes17 = require("@codama/nodes");
|
|
1235
1253
|
var import_visitors_core15 = require("@codama/visitors-core");
|
|
1236
1254
|
function getInstructionRemainingAccountsFragment(scope) {
|
|
1237
1255
|
const { remainingAccounts } = (0, import_visitors_core15.getLastNodeFromPath)(scope.instructionPath);
|
|
@@ -1245,10 +1263,10 @@ const remainingAccounts: AccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.join
|
|
|
1245
1263
|
}
|
|
1246
1264
|
function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
1247
1265
|
const remainingAccountsFragment = (() => {
|
|
1248
|
-
if ((0,
|
|
1266
|
+
if ((0, import_nodes17.isNode)(remainingAccounts.value, "argumentValueNode")) {
|
|
1249
1267
|
return getArgumentValueNodeFragment2(remainingAccounts, scope);
|
|
1250
1268
|
}
|
|
1251
|
-
if ((0,
|
|
1269
|
+
if ((0, import_nodes17.isNode)(remainingAccounts.value, "resolverValueNode")) {
|
|
1252
1270
|
return getResolverValueNodeFragment2(remainingAccounts, scope);
|
|
1253
1271
|
}
|
|
1254
1272
|
return null;
|
|
@@ -1258,8 +1276,8 @@ function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
|
1258
1276
|
}
|
|
1259
1277
|
function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
1260
1278
|
const instructionNode = (0, import_visitors_core15.getLastNodeFromPath)(scope.instructionPath);
|
|
1261
|
-
(0,
|
|
1262
|
-
const argumentName = (0,
|
|
1279
|
+
(0, import_nodes17.assertIsNode)(remainingAccounts.value, "argumentValueNode");
|
|
1280
|
+
const argumentName = (0, import_nodes17.camelCase)(remainingAccounts.value.name);
|
|
1263
1281
|
const isOptional = remainingAccounts.isOptional ?? false;
|
|
1264
1282
|
const isSigner = remainingAccounts.isSigner ?? false;
|
|
1265
1283
|
const isWritable = remainingAccounts.isWritable ?? false;
|
|
@@ -1267,7 +1285,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1267
1285
|
const signerRole = isWritable ? "AccountRole.WRITABLE_SIGNER" : "AccountRole.READONLY_SIGNER";
|
|
1268
1286
|
const role = isSigner === true ? signerRole : nonSignerRole;
|
|
1269
1287
|
const argumentArray = isOptional ? `(args.${argumentName} ?? [])` : `args.${argumentName}`;
|
|
1270
|
-
const allArguments = (0,
|
|
1288
|
+
const allArguments = (0, import_nodes17.getAllInstructionArguments)(instructionNode);
|
|
1271
1289
|
const argumentExists = allArguments.some((arg) => arg.name === remainingAccounts.value.name);
|
|
1272
1290
|
if (argumentExists || isSigner === false) {
|
|
1273
1291
|
return fragment(`${argumentArray}.map((address) => ({ address, role: ${role} }))`).addImports(
|
|
@@ -1288,7 +1306,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1288
1306
|
).addImports("solanaInstructions", ["AccountRole"]);
|
|
1289
1307
|
}
|
|
1290
1308
|
function getResolverValueNodeFragment2(remainingAccounts, scope) {
|
|
1291
|
-
(0,
|
|
1309
|
+
(0, import_nodes17.assertIsNode)(remainingAccounts.value, "resolverValueNode");
|
|
1292
1310
|
const isAsync = scope.asyncResolvers.includes(remainingAccounts.value.name);
|
|
1293
1311
|
if (!scope.useAsync && isAsync) return null;
|
|
1294
1312
|
const awaitKeyword = scope.useAsync && isAsync ? "await " : "";
|
|
@@ -1317,7 +1335,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1317
1335
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1318
1336
|
const hasLegacyOptionalAccounts = instructionNode.optionalAccountStrategy === "omitted" && instructionNode.accounts.some((account) => account.isOptional);
|
|
1319
1337
|
const instructionDependencies = getInstructionDependencies(instructionNode, asyncResolvers, useAsync);
|
|
1320
|
-
const argDependencies = instructionDependencies.filter((0,
|
|
1338
|
+
const argDependencies = instructionDependencies.filter((0, import_nodes18.isNodeFilter)("argumentValueNode")).map((node) => node.name);
|
|
1321
1339
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
1322
1340
|
const argIsNotOmitted = (arg) => !(arg.defaultValue && arg.defaultValueStrategy === "omitted");
|
|
1323
1341
|
const argIsDependent = (arg) => argDependencies.includes(arg.name);
|
|
@@ -1330,7 +1348,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1330
1348
|
const hasExtraArgs = (instructionNode.extraArguments ?? []).filter(
|
|
1331
1349
|
(field) => argIsNotOmitted(field) && (argIsDependent(field) || argHasDefaultValue(field))
|
|
1332
1350
|
).length > 0;
|
|
1333
|
-
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => (0,
|
|
1351
|
+
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => (0, import_nodes18.isNode)(value, "argumentValueNode")).length > 0;
|
|
1334
1352
|
const hasAnyArgs = hasDataArgs || hasExtraArgs || hasRemainingAccountArgs;
|
|
1335
1353
|
const hasInput = hasAccounts || hasAnyArgs;
|
|
1336
1354
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
@@ -1406,7 +1424,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1406
1424
|
return functionFragment;
|
|
1407
1425
|
}
|
|
1408
1426
|
function getTypeParams(instructionNode, programAddressConstant) {
|
|
1409
|
-
const typeParams = instructionNode.accounts.map((account) => `TAccount${(0,
|
|
1427
|
+
const typeParams = instructionNode.accounts.map((account) => `TAccount${(0, import_nodes18.pascalCase)(account.name)} extends string`);
|
|
1410
1428
|
typeParams.push(`TProgramAddress extends Address = typeof ${programAddressConstant}`);
|
|
1411
1429
|
return fragment(typeParams.filter((x) => !!x).join(", ")).mapRender((r) => `<${r}>`).addImports("generatedPrograms", [programAddressConstant]);
|
|
1412
1430
|
}
|
|
@@ -1416,8 +1434,8 @@ function getInstructionType(scope) {
|
|
|
1416
1434
|
const instructionTypeName = nameApi.instructionType(instructionNode.name);
|
|
1417
1435
|
const programAddressFragment = fragment("TProgramAddress");
|
|
1418
1436
|
const accountTypeParamsFragments = instructionNode.accounts.map((account) => {
|
|
1419
|
-
const typeParam = `TAccount${(0,
|
|
1420
|
-
const camelName = (0,
|
|
1437
|
+
const typeParam = `TAccount${(0, import_nodes18.pascalCase)(account.name)}`;
|
|
1438
|
+
const camelName = (0, import_nodes18.camelCase)(account.name);
|
|
1421
1439
|
if (account.isSigner === "either") {
|
|
1422
1440
|
const signerRole = account.isWritable ? "WritableSignerAccount" : "ReadonlySignerAccount";
|
|
1423
1441
|
return fragment(
|
|
@@ -1436,7 +1454,7 @@ function getInputTypeCall(scope) {
|
|
|
1436
1454
|
const instructionNode = (0, import_visitors_core16.getLastNodeFromPath)(instructionPath);
|
|
1437
1455
|
const inputTypeName = useAsync ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name);
|
|
1438
1456
|
if (instructionNode.accounts.length === 0) return fragment(inputTypeName);
|
|
1439
|
-
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0,
|
|
1457
|
+
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0, import_nodes18.pascalCase)(account.name)}`).join(", ");
|
|
1440
1458
|
return fragment(`${inputTypeName}<${accountTypeParams}>`);
|
|
1441
1459
|
}
|
|
1442
1460
|
|
|
@@ -1475,7 +1493,7 @@ function getInstructionParseFunctionFragment(scope) {
|
|
|
1475
1493
|
}
|
|
1476
1494
|
|
|
1477
1495
|
// src/fragments/instructionType.ts
|
|
1478
|
-
var
|
|
1496
|
+
var import_nodes19 = require("@codama/nodes");
|
|
1479
1497
|
var import_visitors_core18 = require("@codama/visitors-core");
|
|
1480
1498
|
function getInstructionTypeFragment(scope) {
|
|
1481
1499
|
const { instructionPath, nameApi, customInstructionData } = scope;
|
|
@@ -1486,7 +1504,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1486
1504
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
1487
1505
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
1488
1506
|
const programAddressConstant = nameApi.programAddressConstant(programNode.name);
|
|
1489
|
-
const dataType = customData ? (0,
|
|
1507
|
+
const dataType = customData ? (0, import_nodes19.pascalCase)(customData.importAs) : (0, import_nodes19.pascalCase)(instructionDataName);
|
|
1490
1508
|
const accountTypeParamsFragment = mergeFragments(
|
|
1491
1509
|
instructionNode.accounts.map(
|
|
1492
1510
|
(account) => getInstructionAccountTypeParamFragment({
|
|
@@ -1501,7 +1519,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1501
1519
|
const accountMetasFragment = mergeFragments(
|
|
1502
1520
|
instructionNode.accounts.map(
|
|
1503
1521
|
(account) => getInstructionAccountMetaFragment(account).mapRender((r) => {
|
|
1504
|
-
const typeParam = `TAccount${(0,
|
|
1522
|
+
const typeParam = `TAccount${(0, import_nodes19.pascalCase)(account.name)}`;
|
|
1505
1523
|
const isLegacyOptional = account.isOptional && usesLegacyOptionalAccounts;
|
|
1506
1524
|
const type = `${typeParam} extends string ? ${r} : ${typeParam}`;
|
|
1507
1525
|
if (!isLegacyOptional) return type;
|
|
@@ -1529,7 +1547,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1529
1547
|
}
|
|
1530
1548
|
|
|
1531
1549
|
// src/fragments/pdaFunction.ts
|
|
1532
|
-
var
|
|
1550
|
+
var import_nodes20 = require("@codama/nodes");
|
|
1533
1551
|
var import_visitors_core19 = require("@codama/visitors-core");
|
|
1534
1552
|
function getPdaFunctionFragment(scope) {
|
|
1535
1553
|
const { pdaPath, typeManifestVisitor, nameApi } = scope;
|
|
@@ -1537,12 +1555,12 @@ function getPdaFunctionFragment(scope) {
|
|
|
1537
1555
|
const programNode = (0, import_visitors_core19.findProgramNodeFromPath)(pdaPath);
|
|
1538
1556
|
const imports = new ImportMap();
|
|
1539
1557
|
const seeds = pdaNode.seeds.map((seed) => {
|
|
1540
|
-
if ((0,
|
|
1558
|
+
if ((0, import_nodes20.isNode)(seed, "variablePdaSeedNode")) {
|
|
1541
1559
|
const seedManifest2 = (0, import_visitors_core19.visit)(seed.type, typeManifestVisitor);
|
|
1542
1560
|
imports.mergeWith(seedManifest2.looseType, seedManifest2.encoder);
|
|
1543
1561
|
return { ...seed, typeManifest: seedManifest2 };
|
|
1544
1562
|
}
|
|
1545
|
-
if ((0,
|
|
1563
|
+
if ((0, import_nodes20.isNode)(seed.value, "programIdValueNode")) {
|
|
1546
1564
|
imports.add("solanaAddresses", "getAddressEncoder");
|
|
1547
1565
|
return seed;
|
|
1548
1566
|
}
|
|
@@ -1552,7 +1570,7 @@ function getPdaFunctionFragment(scope) {
|
|
|
1552
1570
|
imports.mergeWith(valueManifest.imports);
|
|
1553
1571
|
return { ...seed, typeManifest: seedManifest, valueManifest };
|
|
1554
1572
|
});
|
|
1555
|
-
const hasVariableSeeds = pdaNode.seeds.filter((0,
|
|
1573
|
+
const hasVariableSeeds = pdaNode.seeds.filter((0, import_nodes20.isNodeFilter)("variablePdaSeedNode")).length > 0;
|
|
1556
1574
|
return fragmentFromTemplate("pdaFunction.njk", {
|
|
1557
1575
|
findPdaFunction: nameApi.pdaFindFunction(pdaNode.name),
|
|
1558
1576
|
hasVariableSeeds,
|
|
@@ -1572,7 +1590,7 @@ function getProgramFragment(scope) {
|
|
|
1572
1590
|
}
|
|
1573
1591
|
|
|
1574
1592
|
// src/fragments/programAccounts.ts
|
|
1575
|
-
var
|
|
1593
|
+
var import_nodes21 = require("@codama/nodes");
|
|
1576
1594
|
function getProgramAccountsFragment(scope) {
|
|
1577
1595
|
if (scope.programNode.accounts.length === 0) return fragment("");
|
|
1578
1596
|
return mergeFragments(
|
|
@@ -1606,7 +1624,7 @@ function getProgramAccountsIdentifierFunctionFragment(scope) {
|
|
|
1606
1624
|
dataName: "data",
|
|
1607
1625
|
discriminators: account.discriminators ?? [],
|
|
1608
1626
|
ifTrue: `return ${programAccountsEnum}.${variant};`,
|
|
1609
|
-
struct: (0,
|
|
1627
|
+
struct: (0, import_nodes21.resolveNestedTypeNode)(account.data)
|
|
1610
1628
|
});
|
|
1611
1629
|
}),
|
|
1612
1630
|
(r) => r.join("\n")
|
|
@@ -1637,10 +1655,10 @@ function getProgramErrorsFragment(scope) {
|
|
|
1637
1655
|
}
|
|
1638
1656
|
|
|
1639
1657
|
// src/fragments/programInstructions.ts
|
|
1640
|
-
var
|
|
1658
|
+
var import_nodes22 = require("@codama/nodes");
|
|
1641
1659
|
function getProgramInstructionsFragment(scope) {
|
|
1642
1660
|
if (scope.programNode.instructions.length === 0) return fragment("");
|
|
1643
|
-
const allInstructions = (0,
|
|
1661
|
+
const allInstructions = (0, import_nodes22.getAllInstructionsWithSubs)(scope.programNode, {
|
|
1644
1662
|
leavesOnly: !scope.renderParentInstructions,
|
|
1645
1663
|
subInstructionsFirst: true
|
|
1646
1664
|
});
|
|
@@ -1682,7 +1700,7 @@ function getProgramInstructionsIdentifierFunctionFragment(scope) {
|
|
|
1682
1700
|
dataName: "data",
|
|
1683
1701
|
discriminators: instruction.discriminators ?? [],
|
|
1684
1702
|
ifTrue: `return ${programInstructionsEnum}.${variant};`,
|
|
1685
|
-
struct: (0,
|
|
1703
|
+
struct: (0, import_nodes22.structTypeNodeFromInstructionArgumentNodes)(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
|
-
var
|
|
1738
|
+
var import_nodes23 = require("@codama/nodes");
|
|
1721
1739
|
function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
1722
1740
|
const { name, typeNode, nameApi } = scope;
|
|
1723
|
-
const isDiscriminatedUnion = (0,
|
|
1741
|
+
const isDiscriminatedUnion = (0, import_nodes23.isNode)(typeNode, "enumTypeNode") && (0, import_nodes23.isDataEnum)(typeNode);
|
|
1724
1742
|
if (!isDiscriminatedUnion) {
|
|
1725
1743
|
return fragment("");
|
|
1726
1744
|
}
|
|
@@ -1765,12 +1783,12 @@ function mergeManifests(manifests, options = {}) {
|
|
|
1765
1783
|
// src/getRenderMapVisitor.ts
|
|
1766
1784
|
var import_node_path3 = require("path");
|
|
1767
1785
|
var import_errors2 = require("@codama/errors");
|
|
1768
|
-
var
|
|
1786
|
+
var import_nodes26 = require("@codama/nodes");
|
|
1769
1787
|
var import_renderers_core = require("@codama/renderers-core");
|
|
1770
1788
|
var import_visitors_core21 = require("@codama/visitors-core");
|
|
1771
1789
|
|
|
1772
1790
|
// src/getTypeManifestVisitor.ts
|
|
1773
|
-
var
|
|
1791
|
+
var import_nodes24 = require("@codama/nodes");
|
|
1774
1792
|
var import_visitors_core20 = require("@codama/visitors-core");
|
|
1775
1793
|
function getTypeManifestVisitor(input) {
|
|
1776
1794
|
const { nameApi, linkables, nonScalarEnums, customAccountData, customInstructionData, getImportFrom } = input;
|
|
@@ -1788,8 +1806,8 @@ function getTypeManifestVisitor(input) {
|
|
|
1788
1806
|
}),
|
|
1789
1807
|
{
|
|
1790
1808
|
keys: [
|
|
1791
|
-
...
|
|
1792
|
-
...
|
|
1809
|
+
...import_nodes24.REGISTERED_TYPE_NODE_KINDS,
|
|
1810
|
+
...import_nodes24.REGISTERED_VALUE_NODE_KINDS,
|
|
1793
1811
|
"definedTypeLinkNode",
|
|
1794
1812
|
"definedTypeNode",
|
|
1795
1813
|
"accountNode",
|
|
@@ -1833,7 +1851,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1833
1851
|
const decoderImports = new ImportMap().add("solanaCodecsDataStructures", "getBooleanDecoder");
|
|
1834
1852
|
let sizeEncoder = "";
|
|
1835
1853
|
let sizeDecoder = "";
|
|
1836
|
-
const resolvedSize = (0,
|
|
1854
|
+
const resolvedSize = (0, import_nodes24.resolveNestedTypeNode)(booleanType.size);
|
|
1837
1855
|
if (resolvedSize.format !== "u8" || resolvedSize.endian !== "le") {
|
|
1838
1856
|
const size = (0, import_visitors_core20.visit)(booleanType.size, self);
|
|
1839
1857
|
encoderImports.mergeWith(size.encoder);
|
|
@@ -1884,7 +1902,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1884
1902
|
return manifest;
|
|
1885
1903
|
},
|
|
1886
1904
|
visitConstantValue(node, { self }) {
|
|
1887
|
-
if ((0,
|
|
1905
|
+
if ((0, import_nodes24.isNode)(node.type, "bytesTypeNode") && (0, import_nodes24.isNode)(node.value, "bytesValueNode")) {
|
|
1888
1906
|
return (0, import_visitors_core20.visit)(node.value, self);
|
|
1889
1907
|
}
|
|
1890
1908
|
return {
|
|
@@ -1923,7 +1941,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1923
1941
|
};
|
|
1924
1942
|
},
|
|
1925
1943
|
visitEnumEmptyVariantType(enumEmptyVariantType) {
|
|
1926
|
-
const discriminator = nameApi.discriminatedUnionDiscriminator((0,
|
|
1944
|
+
const discriminator = nameApi.discriminatedUnionDiscriminator((0, import_nodes24.camelCase)(parentName?.strict ?? ""));
|
|
1927
1945
|
const name = nameApi.discriminatedUnionVariant(enumEmptyVariantType.name);
|
|
1928
1946
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1929
1947
|
return {
|
|
@@ -1944,7 +1962,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1944
1962
|
visitEnumStructVariantType(enumStructVariantType, { self }) {
|
|
1945
1963
|
const currentParentName = parentName;
|
|
1946
1964
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1947
|
-
(0,
|
|
1965
|
+
(0, import_nodes24.camelCase)(currentParentName?.strict ?? "")
|
|
1948
1966
|
);
|
|
1949
1967
|
const name = nameApi.discriminatedUnionVariant(enumStructVariantType.name);
|
|
1950
1968
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
@@ -1960,12 +1978,12 @@ function getTypeManifestVisitor(input) {
|
|
|
1960
1978
|
visitEnumTupleVariantType(enumTupleVariantType, { self }) {
|
|
1961
1979
|
const currentParentName = parentName;
|
|
1962
1980
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1963
|
-
(0,
|
|
1981
|
+
(0, import_nodes24.camelCase)(currentParentName?.strict ?? "")
|
|
1964
1982
|
);
|
|
1965
1983
|
const name = nameApi.discriminatedUnionVariant(enumTupleVariantType.name);
|
|
1966
1984
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1967
|
-
const struct = (0,
|
|
1968
|
-
(0,
|
|
1985
|
+
const struct = (0, import_nodes24.structTypeNode)([
|
|
1986
|
+
(0, import_nodes24.structFieldTypeNode)({
|
|
1969
1987
|
name: "fields",
|
|
1970
1988
|
type: enumTupleVariantType.tuple
|
|
1971
1989
|
})
|
|
@@ -1985,7 +2003,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1985
2003
|
const decoderImports = new ImportMap();
|
|
1986
2004
|
const encoderOptions = [];
|
|
1987
2005
|
const decoderOptions = [];
|
|
1988
|
-
const enumSize = (0,
|
|
2006
|
+
const enumSize = (0, import_nodes24.resolveNestedTypeNode)(enumType.size);
|
|
1989
2007
|
if (enumSize.format !== "u8" || enumSize.endian !== "le") {
|
|
1990
2008
|
const sizeManifest = (0, import_visitors_core20.visit)(enumType.size, self);
|
|
1991
2009
|
encoderImports.mergeWith(sizeManifest.encoder);
|
|
@@ -1994,15 +2012,15 @@ function getTypeManifestVisitor(input) {
|
|
|
1994
2012
|
decoderOptions.push(`size: ${sizeManifest.decoder.render}`);
|
|
1995
2013
|
}
|
|
1996
2014
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1997
|
-
(0,
|
|
2015
|
+
(0, import_nodes24.camelCase)(currentParentName?.strict ?? "")
|
|
1998
2016
|
);
|
|
1999
|
-
if (!(0,
|
|
2017
|
+
if (!(0, import_nodes24.isScalarEnum)(enumType) && discriminator !== "__kind") {
|
|
2000
2018
|
encoderOptions.push(`discriminator: '${discriminator}'`);
|
|
2001
2019
|
decoderOptions.push(`discriminator: '${discriminator}'`);
|
|
2002
2020
|
}
|
|
2003
2021
|
const encoderOptionsAsString = encoderOptions.length > 0 ? `, { ${encoderOptions.join(", ")} }` : "";
|
|
2004
2022
|
const decoderOptionsAsString = decoderOptions.length > 0 ? `, { ${decoderOptions.join(", ")} }` : "";
|
|
2005
|
-
if ((0,
|
|
2023
|
+
if ((0, import_nodes24.isScalarEnum)(enumType)) {
|
|
2006
2024
|
if (currentParentName === null) {
|
|
2007
2025
|
throw new Error(
|
|
2008
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."
|
|
@@ -2041,7 +2059,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2041
2059
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
2042
2060
|
const importFrom = getImportFrom(node.enum);
|
|
2043
2061
|
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
2044
|
-
const isScalar = enumNode && (0,
|
|
2062
|
+
const isScalar = enumNode && (0, import_nodes24.isNode)(enumNode, "enumTypeNode") ? (0, import_nodes24.isScalarEnum)(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
2045
2063
|
if (!node.value && isScalar) {
|
|
2046
2064
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
2047
2065
|
manifest.value.setRender(`${enumName}.${variantName2}`).addImports(importFrom, enumName);
|
|
@@ -2086,7 +2104,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2086
2104
|
strict: nameApi.dataType(instructionDataName)
|
|
2087
2105
|
};
|
|
2088
2106
|
const link = customInstructionData.get(instruction.name)?.linkNode;
|
|
2089
|
-
const struct = (0,
|
|
2107
|
+
const struct = (0, import_nodes24.structTypeNodeFromInstructionArgumentNodes)(instruction.arguments);
|
|
2090
2108
|
const manifest = link ? (0, import_visitors_core20.visit)(link, self) : (0, import_visitors_core20.visit)(struct, self);
|
|
2091
2109
|
parentName = null;
|
|
2092
2110
|
return manifest;
|
|
@@ -2153,7 +2171,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2153
2171
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2154
2172
|
const encoderOptions = [];
|
|
2155
2173
|
const decoderOptions = [];
|
|
2156
|
-
const optionPrefix = (0,
|
|
2174
|
+
const optionPrefix = (0, import_nodes24.resolveNestedTypeNode)(optionType.prefix);
|
|
2157
2175
|
if (optionPrefix.format !== "u8" || optionPrefix.endian !== "le") {
|
|
2158
2176
|
const prefixManifest = (0, import_visitors_core20.visit)(optionType.prefix, self);
|
|
2159
2177
|
childManifest.encoder.mergeImportsWith(prefixManifest.encoder);
|
|
@@ -2319,9 +2337,9 @@ function getTypeManifestVisitor(input) {
|
|
|
2319
2337
|
return manifest;
|
|
2320
2338
|
},
|
|
2321
2339
|
visitStructFieldType(structFieldType, { self }) {
|
|
2322
|
-
const name = (0,
|
|
2340
|
+
const name = (0, import_nodes24.camelCase)(structFieldType.name);
|
|
2323
2341
|
const childManifest = (0, import_visitors_core20.visit)(structFieldType.type, self);
|
|
2324
|
-
const structFieldDocs = (0,
|
|
2342
|
+
const structFieldDocs = (0, import_nodes24.parseDocs)(structFieldType.docs);
|
|
2325
2343
|
const docblock = structFieldDocs.length > 0 ? `
|
|
2326
2344
|
${jsDocblock(structFieldDocs)}` : "";
|
|
2327
2345
|
const originalLooseType = childManifest.looseType.render;
|
|
@@ -2363,11 +2381,11 @@ ${jsDocblock(structFieldDocs)}` : "";
|
|
|
2363
2381
|
const accountNode = (0, import_visitors_core20.findLastNodeFromPath)(parentPath, "accountNode");
|
|
2364
2382
|
const discriminatorPrefix = instructionNode ? instructionNode.name : accountNode?.name;
|
|
2365
2383
|
const discriminators = (instructionNode ? instructionNode.discriminators : accountNode?.discriminators) ?? [];
|
|
2366
|
-
const fieldDiscriminators = discriminators.filter((0,
|
|
2384
|
+
const fieldDiscriminators = discriminators.filter((0, import_nodes24.isNodeFilter)("fieldDiscriminatorNode"));
|
|
2367
2385
|
const defaultValues = optionalFields.map((f) => {
|
|
2368
|
-
const key = (0,
|
|
2386
|
+
const key = (0, import_nodes24.camelCase)(f.name);
|
|
2369
2387
|
if (fieldDiscriminators.some((d) => d.name === f.name)) {
|
|
2370
|
-
const constantName = nameApi.constant((0,
|
|
2388
|
+
const constantName = nameApi.constant((0, import_nodes24.camelCase)(`${discriminatorPrefix}_${f.name}`));
|
|
2371
2389
|
return f.defaultValueStrategy === "omitted" ? `${key}: ${constantName}` : `${key}: value.${key} ?? ${constantName}`;
|
|
2372
2390
|
}
|
|
2373
2391
|
const defaultValue = f.defaultValue;
|
|
@@ -2427,19 +2445,19 @@ ${jsDocblock(structFieldDocs)}` : "";
|
|
|
2427
2445
|
);
|
|
2428
2446
|
}
|
|
2429
2447
|
function getArrayLikeSizeOption(count, visitor) {
|
|
2430
|
-
if ((0,
|
|
2448
|
+
if ((0, import_nodes24.isNode)(count, "fixedCountNode")) {
|
|
2431
2449
|
return {
|
|
2432
2450
|
decoder: fragment(`size: ${count.value}`),
|
|
2433
2451
|
encoder: fragment(`size: ${count.value}`)
|
|
2434
2452
|
};
|
|
2435
2453
|
}
|
|
2436
|
-
if ((0,
|
|
2454
|
+
if ((0, import_nodes24.isNode)(count, "remainderCountNode")) {
|
|
2437
2455
|
return {
|
|
2438
2456
|
decoder: fragment(`size: 'remainder'`),
|
|
2439
2457
|
encoder: fragment(`size: 'remainder'`)
|
|
2440
2458
|
};
|
|
2441
2459
|
}
|
|
2442
|
-
const prefix = (0,
|
|
2460
|
+
const prefix = (0, import_nodes24.resolveNestedTypeNode)(count.prefix);
|
|
2443
2461
|
if (prefix.format === "u32" && prefix.endian === "le") {
|
|
2444
2462
|
return { decoder: fragment(""), encoder: fragment("") };
|
|
2445
2463
|
}
|
|
@@ -2450,67 +2468,67 @@ function getArrayLikeSizeOption(count, visitor) {
|
|
|
2450
2468
|
}
|
|
2451
2469
|
|
|
2452
2470
|
// src/nameTransformers.ts
|
|
2453
|
-
var
|
|
2471
|
+
var import_nodes25 = require("@codama/nodes");
|
|
2454
2472
|
function getNameApi(transformers) {
|
|
2455
2473
|
const helpers = {
|
|
2456
|
-
camelCase:
|
|
2457
|
-
capitalize:
|
|
2458
|
-
kebabCase:
|
|
2459
|
-
pascalCase:
|
|
2460
|
-
snakeCase:
|
|
2461
|
-
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
|
|
2462
2480
|
};
|
|
2463
2481
|
return Object.fromEntries(
|
|
2464
2482
|
Object.entries(transformers).map(([key, transformer]) => [key, (name) => transformer(name, helpers)])
|
|
2465
2483
|
);
|
|
2466
2484
|
}
|
|
2467
2485
|
var DEFAULT_NAME_TRANSFORMERS = {
|
|
2468
|
-
accountDecodeFunction: (name) => `decode${(0,
|
|
2469
|
-
accountFetchAllFunction: (name) => `fetchAll${(0,
|
|
2470
|
-
accountFetchAllMaybeFunction: (name) => `fetchAllMaybe${(0,
|
|
2471
|
-
accountFetchFromSeedsFunction: (name) => `fetch${(0,
|
|
2472
|
-
accountFetchFunction: (name) => `fetch${(0,
|
|
2473
|
-
accountFetchMaybeFromSeedsFunction: (name) => `fetchMaybe${(0,
|
|
2474
|
-
accountFetchMaybeFunction: (name) => `fetchMaybe${(0,
|
|
2475
|
-
accountGetSizeFunction: (name) => `get${(0,
|
|
2476
|
-
codecFunction: (name) => `get${(0,
|
|
2477
|
-
constant: (name) => (0,
|
|
2478
|
-
constantFunction: (name) => `get${(0,
|
|
2479
|
-
dataArgsType: (name) => `${(0,
|
|
2480
|
-
dataType: (name) => `${(0,
|
|
2481
|
-
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`,
|
|
2482
2500
|
discriminatedUnionDiscriminator: () => "__kind",
|
|
2483
|
-
discriminatedUnionFunction: (name) => `${(0,
|
|
2484
|
-
discriminatedUnionVariant: (name) => `${(0,
|
|
2485
|
-
encoderFunction: (name) => `get${(0,
|
|
2486
|
-
enumVariant: (name) => `${(0,
|
|
2487
|
-
instructionAsyncFunction: (name) => `get${(0,
|
|
2488
|
-
instructionAsyncInputType: (name) => `${(0,
|
|
2489
|
-
instructionDataType: (name) => `${(0,
|
|
2490
|
-
instructionExtraType: (name) => `${(0,
|
|
2491
|
-
instructionParseFunction: (name) => `parse${(0,
|
|
2492
|
-
instructionParsedType: (name) => `Parsed${(0,
|
|
2493
|
-
instructionSyncFunction: (name) => `get${(0,
|
|
2494
|
-
instructionSyncInputType: (name) => `${(0,
|
|
2495
|
-
instructionType: (name) => `${(0,
|
|
2496
|
-
isDiscriminatedUnionFunction: (name) => `is${(0,
|
|
2497
|
-
pdaFindFunction: (name) => `find${(0,
|
|
2498
|
-
pdaSeedsType: (name) => `${(0,
|
|
2499
|
-
programAccountsEnum: (name) => `${(0,
|
|
2500
|
-
programAccountsEnumVariant: (name) => `${(0,
|
|
2501
|
-
programAccountsIdentifierFunction: (name) => `identify${(0,
|
|
2502
|
-
programAddressConstant: (name) => `${(0,
|
|
2503
|
-
programErrorConstant: (name) => (0,
|
|
2504
|
-
programErrorConstantPrefix: (name) => `${(0,
|
|
2505
|
-
programErrorMessagesMap: (name) => `${(0,
|
|
2506
|
-
programErrorUnion: (name) => `${(0,
|
|
2507
|
-
programGetErrorMessageFunction: (name) => `get${(0,
|
|
2508
|
-
programInstructionsEnum: (name) => `${(0,
|
|
2509
|
-
programInstructionsEnumVariant: (name) => `${(0,
|
|
2510
|
-
programInstructionsIdentifierFunction: (name) => `identify${(0,
|
|
2511
|
-
programInstructionsParsedUnionType: (name) => `Parsed${(0,
|
|
2512
|
-
programIsErrorFunction: (name) => `is${(0,
|
|
2513
|
-
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)}`
|
|
2514
2532
|
};
|
|
2515
2533
|
|
|
2516
2534
|
// src/getRenderMapVisitor.ts
|
|
@@ -2525,9 +2543,9 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2525
2543
|
const renderParentInstructions = options.renderParentInstructions ?? false;
|
|
2526
2544
|
const dependencyMap = options.dependencyMap ?? {};
|
|
2527
2545
|
const useGranularImports = options.useGranularImports ?? false;
|
|
2528
|
-
const asyncResolvers = (options.asyncResolvers ?? []).map(
|
|
2529
|
-
const nonScalarEnums = (options.nonScalarEnums ?? []).map(
|
|
2530
|
-
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);
|
|
2531
2549
|
const customAccountData = parseCustomDataOptions(options.customAccountData ?? [], "AccountData");
|
|
2532
2550
|
const customInstructionData = parseCustomDataOptions(options.customInstructionData ?? [], "InstructionData");
|
|
2533
2551
|
const getImportFrom = getImportFromFactory(options.linkOverrides ?? {}, customAccountData, customInstructionData);
|
|
@@ -2541,6 +2559,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2541
2559
|
stack
|
|
2542
2560
|
});
|
|
2543
2561
|
const resolvedInstructionInputVisitor = (0, import_visitors_core21.getResolvedInstructionInputsVisitor)();
|
|
2562
|
+
const byteSizeVisitor = (0, import_visitors_core21.getByteSizeVisitor)(linkables, { stack });
|
|
2544
2563
|
const globalScope = {
|
|
2545
2564
|
asyncResolvers,
|
|
2546
2565
|
customAccountData,
|
|
@@ -2568,9 +2587,10 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2568
2587
|
const scope = {
|
|
2569
2588
|
...globalScope,
|
|
2570
2589
|
accountPath,
|
|
2590
|
+
size: (0, import_visitors_core21.visit)(node, byteSizeVisitor),
|
|
2571
2591
|
typeManifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor)
|
|
2572
2592
|
};
|
|
2573
|
-
const fields = (0,
|
|
2593
|
+
const fields = (0, import_nodes26.resolveNestedTypeNode)(node.data).fields;
|
|
2574
2594
|
const accountDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2575
2595
|
...scope,
|
|
2576
2596
|
discriminatorNodes: node.discriminators ?? [],
|
|
@@ -2589,7 +2609,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2589
2609
|
accountPdaHelpersFragment
|
|
2590
2610
|
);
|
|
2591
2611
|
return new import_renderers_core.RenderMap().add(
|
|
2592
|
-
`accounts/${(0,
|
|
2612
|
+
`accounts/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2593
2613
|
render2("accountsPage.njk", {
|
|
2594
2614
|
accountDiscriminatorConstantsFragment,
|
|
2595
2615
|
accountFetchHelpersFragment,
|
|
@@ -2608,6 +2628,8 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2608
2628
|
encoderDocs: [],
|
|
2609
2629
|
manifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor),
|
|
2610
2630
|
name: node.name,
|
|
2631
|
+
node: node.type,
|
|
2632
|
+
size: (0, import_visitors_core21.visit)(node, byteSizeVisitor),
|
|
2611
2633
|
typeDocs: node.docs,
|
|
2612
2634
|
typeNode: node.type
|
|
2613
2635
|
};
|
|
@@ -2621,7 +2643,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2621
2643
|
nameApi.codecFunction(node.name)
|
|
2622
2644
|
]);
|
|
2623
2645
|
return new import_renderers_core.RenderMap().add(
|
|
2624
|
-
`types/${(0,
|
|
2646
|
+
`types/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2625
2647
|
render2("definedTypesPage.njk", {
|
|
2626
2648
|
imports: imports.toString({
|
|
2627
2649
|
...dependencyMap,
|
|
@@ -2642,15 +2664,16 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2642
2664
|
...globalScope,
|
|
2643
2665
|
dataArgsManifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor),
|
|
2644
2666
|
extraArgsManifest: (0, import_visitors_core21.visit)(
|
|
2645
|
-
(0,
|
|
2667
|
+
(0, import_nodes26.definedTypeNode)({
|
|
2646
2668
|
name: instructionExtraName,
|
|
2647
|
-
type: (0,
|
|
2669
|
+
type: (0, import_nodes26.structTypeNodeFromInstructionArgumentNodes)(node.extraArguments ?? [])
|
|
2648
2670
|
}),
|
|
2649
2671
|
typeManifestVisitor
|
|
2650
2672
|
),
|
|
2651
2673
|
instructionPath,
|
|
2652
2674
|
renamedArgs: getRenamedArgsMap(node),
|
|
2653
|
-
resolvedInputs: (0, import_visitors_core21.visit)(node, resolvedInstructionInputVisitor)
|
|
2675
|
+
resolvedInputs: (0, import_visitors_core21.visit)(node, resolvedInstructionInputVisitor),
|
|
2676
|
+
size: (0, import_visitors_core21.visit)(node, byteSizeVisitor)
|
|
2654
2677
|
};
|
|
2655
2678
|
const instructionDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2656
2679
|
...scope,
|
|
@@ -2680,7 +2703,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2680
2703
|
instructionParseFunctionFragment
|
|
2681
2704
|
);
|
|
2682
2705
|
return new import_renderers_core.RenderMap().add(
|
|
2683
|
-
`instructions/${(0,
|
|
2706
|
+
`instructions/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2684
2707
|
render2("instructionsPage.njk", {
|
|
2685
2708
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2686
2709
|
instruction: node,
|
|
@@ -2703,7 +2726,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2703
2726
|
const pdaFunctionFragment = getPdaFunctionFragment(scope);
|
|
2704
2727
|
const imports = new ImportMap().mergeWith(pdaFunctionFragment);
|
|
2705
2728
|
return new import_renderers_core.RenderMap().add(
|
|
2706
|
-
`pdas/${(0,
|
|
2729
|
+
`pdas/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2707
2730
|
render2("pdasPage.njk", {
|
|
2708
2731
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2709
2732
|
pdaFunctionFragment
|
|
@@ -2720,7 +2743,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2720
2743
|
if (node.errors.length > 0) {
|
|
2721
2744
|
const programErrorsFragment = getProgramErrorsFragment(scope);
|
|
2722
2745
|
renderMap.add(
|
|
2723
|
-
`errors/${(0,
|
|
2746
|
+
`errors/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2724
2747
|
render2("errorsPage.njk", {
|
|
2725
2748
|
imports: new ImportMap().mergeWith(programErrorsFragment).toString(dependencyMap, useGranularImports),
|
|
2726
2749
|
programErrorsFragment
|
|
@@ -2731,7 +2754,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2731
2754
|
const programAccountsFragment = getProgramAccountsFragment(scope);
|
|
2732
2755
|
const programInstructionsFragment = getProgramInstructionsFragment(scope);
|
|
2733
2756
|
renderMap.add(
|
|
2734
|
-
`programs/${(0,
|
|
2757
|
+
`programs/${(0, import_nodes26.camelCase)(node.name)}.ts`,
|
|
2735
2758
|
render2("programsPage.njk", {
|
|
2736
2759
|
imports: new ImportMap().mergeWith(programFragment, programAccountsFragment, programInstructionsFragment).toString(dependencyMap, useGranularImports),
|
|
2737
2760
|
programAccountsFragment,
|
|
@@ -2740,7 +2763,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2740
2763
|
})
|
|
2741
2764
|
);
|
|
2742
2765
|
renderMap.mergeWith(
|
|
2743
|
-
...(0,
|
|
2766
|
+
...(0, import_nodes26.getAllInstructionsWithSubs)(node, {
|
|
2744
2767
|
leavesOnly: !renderParentInstructions
|
|
2745
2768
|
}).map((ix) => (0, import_visitors_core21.visit)(ix, self))
|
|
2746
2769
|
);
|
|
@@ -2748,14 +2771,14 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2748
2771
|
},
|
|
2749
2772
|
visitRoot(node, { self }) {
|
|
2750
2773
|
const isNotInternal = (n) => !internalNodes.includes(n.name);
|
|
2751
|
-
const programsToExport = (0,
|
|
2774
|
+
const programsToExport = (0, import_nodes26.getAllPrograms)(node).filter(isNotInternal);
|
|
2752
2775
|
const programsWithErrorsToExport = programsToExport.filter((p) => p.errors.length > 0);
|
|
2753
|
-
const pdasToExport = (0,
|
|
2754
|
-
const accountsToExport = (0,
|
|
2755
|
-
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, {
|
|
2756
2779
|
leavesOnly: !renderParentInstructions
|
|
2757
2780
|
}).filter(isNotInternal);
|
|
2758
|
-
const definedTypesToExport = (0,
|
|
2781
|
+
const definedTypesToExport = (0, import_nodes26.getAllDefinedTypes)(node).filter(isNotInternal);
|
|
2759
2782
|
const hasAnythingToExport = programsToExport.length > 0 || accountsToExport.length > 0 || instructionsToExport.length > 0 || definedTypesToExport.length > 0;
|
|
2760
2783
|
const ctx = {
|
|
2761
2784
|
accountsToExport,
|
|
@@ -2807,7 +2830,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2807
2830
|
if (definedTypesToExport.length > 0) {
|
|
2808
2831
|
map.add("types/index.ts", render2("definedTypesIndex.njk", ctx));
|
|
2809
2832
|
}
|
|
2810
|
-
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)));
|
|
2811
2834
|
}
|
|
2812
2835
|
}),
|
|
2813
2836
|
(v) => (0, import_visitors_core21.recordNodeStackVisitor)(v, stack),
|
|
@@ -2829,7 +2852,7 @@ function getRenamedArgsMap(instruction) {
|
|
|
2829
2852
|
(0, import_errors2.logWarn)(
|
|
2830
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.`
|
|
2831
2854
|
);
|
|
2832
|
-
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`)]));
|
|
2833
2856
|
}
|
|
2834
2857
|
|
|
2835
2858
|
// src/renderVisitor.ts
|