@codama/renderers-js 1.4.2 → 1.5.0
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.browser.cjs +182 -202
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +100 -120
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.cjs +182 -202
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +100 -120
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.react-native.mjs +100 -120
- package/dist/index.react-native.mjs.map +1 -1
- package/dist/types/fragments/accountType.d.ts.map +1 -1
- package/dist/types/fragments/indexPage.d.ts +1 -2
- package/dist/types/fragments/indexPage.d.ts.map +1 -1
- package/dist/types/fragments/instructionInputDefault.d.ts.map +1 -1
- package/package.json +10 -10
package/dist/index.browser.cjs
CHANGED
|
@@ -314,7 +314,7 @@ function mergeTypeManifests(manifests, options = {}) {
|
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
// src/visitors/getRenderMapVisitor.ts
|
|
317
|
-
var
|
|
317
|
+
var import_nodes29 = require("@codama/nodes");
|
|
318
318
|
var import_renderers_core13 = require("@codama/renderers-core");
|
|
319
319
|
var import_visitors_core29 = require("@codama/visitors-core");
|
|
320
320
|
|
|
@@ -718,11 +718,15 @@ function getAccountTypeFragment(scope) {
|
|
|
718
718
|
const accountNode = (0, import_visitors_core5.getLastNodeFromPath)(accountPath);
|
|
719
719
|
if (customAccountData.has(accountNode.name)) return;
|
|
720
720
|
return getTypeWithCodecFragment({
|
|
721
|
+
codecDocs: [`Gets the codec for {@link ${nameApi.dataType(accountNode.name)}} account data.`],
|
|
722
|
+
decoderDocs: [`Gets the decoder for {@link ${nameApi.dataType(accountNode.name)}} account data.`],
|
|
723
|
+
encoderDocs: [`Gets the encoder for {@link ${nameApi.dataArgsType(accountNode.name)}} account data.`],
|
|
721
724
|
manifest: typeManifest2,
|
|
722
725
|
name: accountNode.name,
|
|
723
726
|
nameApi,
|
|
724
727
|
node: (0, import_nodes7.resolveNestedTypeNode)(accountNode.data),
|
|
725
|
-
size: scope.size
|
|
728
|
+
size: scope.size,
|
|
729
|
+
typeDocs: accountNode.docs
|
|
726
730
|
});
|
|
727
731
|
}
|
|
728
732
|
|
|
@@ -928,16 +932,17 @@ function getIsErrorFunctionFragment(scope) {
|
|
|
928
932
|
}
|
|
929
933
|
|
|
930
934
|
// src/fragments/indexPage.ts
|
|
935
|
+
var import_nodes11 = require("@codama/nodes");
|
|
931
936
|
function getIndexPageFragment(items) {
|
|
932
937
|
if (items.length === 0) return;
|
|
933
|
-
const names = items.map((item) => item.name).sort((a, b) => a.localeCompare(b)).map((name) => getExportAllFragment(`./${name}`));
|
|
938
|
+
const names = items.map((item) => (0, import_nodes11.camelCase)(item.name)).sort((a, b) => a.localeCompare(b)).map((name) => getExportAllFragment(`./${name}`));
|
|
934
939
|
return mergeFragments(names, (cs) => cs.join("\n"));
|
|
935
940
|
}
|
|
936
941
|
|
|
937
942
|
// src/fragments/instructionAccountMeta.ts
|
|
938
|
-
var
|
|
943
|
+
var import_nodes12 = require("@codama/nodes");
|
|
939
944
|
function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
940
|
-
const typeParam = `TAccount${(0,
|
|
945
|
+
const typeParam = `TAccount${(0, import_nodes12.pascalCase)(instructionAccountNode.name)}`;
|
|
941
946
|
if (instructionAccountNode.isSigner === true && instructionAccountNode.isWritable) {
|
|
942
947
|
return fragment`${use("type WritableSignerAccount", "solanaInstructions")}<${typeParam}> & ${use("type AccountSignerMeta", "solanaSigners")}<${typeParam}>`;
|
|
943
948
|
}
|
|
@@ -951,14 +956,14 @@ function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
|
951
956
|
}
|
|
952
957
|
|
|
953
958
|
// src/fragments/instructionAccountTypeParam.ts
|
|
954
|
-
var
|
|
959
|
+
var import_nodes13 = require("@codama/nodes");
|
|
955
960
|
var import_visitors_core9 = require("@codama/visitors-core");
|
|
956
961
|
function getInstructionAccountTypeParamFragment(scope) {
|
|
957
962
|
const { instructionAccountPath, allowAccountMeta, linkables } = scope;
|
|
958
963
|
const instructionAccountNode = (0, import_visitors_core9.getLastNodeFromPath)(instructionAccountPath);
|
|
959
964
|
const instructionNode = (0, import_visitors_core9.findInstructionNodeFromPath)(instructionAccountPath);
|
|
960
965
|
const programNode = (0, import_visitors_core9.findProgramNodeFromPath)(instructionAccountPath);
|
|
961
|
-
const typeParam = `TAccount${(0,
|
|
966
|
+
const typeParam = `TAccount${(0, import_nodes13.pascalCase)(instructionAccountNode.name)}`;
|
|
962
967
|
const accountMeta = allowAccountMeta ? fragment` | ${use("type AccountMeta", "solanaInstructions")}<string>` : void 0;
|
|
963
968
|
if (instructionNode.optionalAccountStrategy === "omitted" && instructionAccountNode.isOptional) {
|
|
964
969
|
return fragment`${typeParam} extends string${accountMeta} | undefined = undefined`;
|
|
@@ -981,7 +986,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
981
986
|
}
|
|
982
987
|
|
|
983
988
|
// src/fragments/instructionByteDelta.ts
|
|
984
|
-
var
|
|
989
|
+
var import_nodes14 = require("@codama/nodes");
|
|
985
990
|
var import_renderers_core3 = require("@codama/renderers-core");
|
|
986
991
|
var import_visitors_core10 = require("@codama/visitors-core");
|
|
987
992
|
function getInstructionByteDeltaFragment(scope) {
|
|
@@ -996,16 +1001,16 @@ const byteDelta: number = [${c.join(",")}].reduce((a, b) => a + b, 0);`
|
|
|
996
1001
|
}
|
|
997
1002
|
function getByteDeltaFragment(byteDelta, scope) {
|
|
998
1003
|
let bytesFragment = (() => {
|
|
999
|
-
if ((0,
|
|
1004
|
+
if ((0, import_nodes14.isNode)(byteDelta.value, "numberValueNode")) {
|
|
1000
1005
|
return getNumberValueNodeFragment(byteDelta);
|
|
1001
1006
|
}
|
|
1002
|
-
if ((0,
|
|
1007
|
+
if ((0, import_nodes14.isNode)(byteDelta.value, "argumentValueNode")) {
|
|
1003
1008
|
return getArgumentValueNodeFragment(byteDelta);
|
|
1004
1009
|
}
|
|
1005
|
-
if ((0,
|
|
1010
|
+
if ((0, import_nodes14.isNode)(byteDelta.value, "accountLinkNode")) {
|
|
1006
1011
|
return getAccountLinkNodeFragment(byteDelta, scope);
|
|
1007
1012
|
}
|
|
1008
|
-
if ((0,
|
|
1013
|
+
if ((0, import_nodes14.isNode)(byteDelta.value, "resolverValueNode")) {
|
|
1009
1014
|
return getResolverValueNodeFragment(byteDelta, scope);
|
|
1010
1015
|
}
|
|
1011
1016
|
return null;
|
|
@@ -1020,16 +1025,16 @@ function getByteDeltaFragment(byteDelta, scope) {
|
|
|
1020
1025
|
return [bytesFragment];
|
|
1021
1026
|
}
|
|
1022
1027
|
function getNumberValueNodeFragment(byteDelta) {
|
|
1023
|
-
(0,
|
|
1028
|
+
(0, import_nodes14.assertIsNode)(byteDelta.value, "numberValueNode");
|
|
1024
1029
|
return fragment`${byteDelta.value.number}`;
|
|
1025
1030
|
}
|
|
1026
1031
|
function getArgumentValueNodeFragment(byteDelta) {
|
|
1027
|
-
(0,
|
|
1028
|
-
const argumentName = (0,
|
|
1032
|
+
(0, import_nodes14.assertIsNode)(byteDelta.value, "argumentValueNode");
|
|
1033
|
+
const argumentName = (0, import_nodes14.camelCase)(byteDelta.value.name);
|
|
1029
1034
|
return fragment`Number(args.${argumentName})`;
|
|
1030
1035
|
}
|
|
1031
1036
|
function getAccountLinkNodeFragment(byteDelta, scope) {
|
|
1032
|
-
(0,
|
|
1037
|
+
(0, import_nodes14.assertIsNode)(byteDelta.value, "accountLinkNode");
|
|
1033
1038
|
const functionName = use(
|
|
1034
1039
|
scope.nameApi.accountGetSizeFunction(byteDelta.value.name),
|
|
1035
1040
|
scope.getImportFrom(byteDelta.value)
|
|
@@ -1037,7 +1042,7 @@ function getAccountLinkNodeFragment(byteDelta, scope) {
|
|
|
1037
1042
|
return fragment`${functionName}()`;
|
|
1038
1043
|
}
|
|
1039
1044
|
function getResolverValueNodeFragment(byteDelta, scope) {
|
|
1040
|
-
(0,
|
|
1045
|
+
(0, import_nodes14.assertIsNode)(byteDelta.value, "resolverValueNode");
|
|
1041
1046
|
const isAsync = scope.asyncResolvers.includes(byteDelta.value.name);
|
|
1042
1047
|
if (!scope.useAsync && isAsync) return null;
|
|
1043
1048
|
const awaitKeyword = scope.useAsync && isAsync ? "await " : "";
|
|
@@ -1052,7 +1057,7 @@ function getResolverValueNodeFragment(byteDelta, scope) {
|
|
|
1052
1057
|
}
|
|
1053
1058
|
|
|
1054
1059
|
// src/fragments/instructionData.ts
|
|
1055
|
-
var
|
|
1060
|
+
var import_nodes15 = require("@codama/nodes");
|
|
1056
1061
|
var import_visitors_core11 = require("@codama/visitors-core");
|
|
1057
1062
|
function getInstructionDataFragment(scope) {
|
|
1058
1063
|
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
@@ -1063,7 +1068,7 @@ function getInstructionDataFragment(scope) {
|
|
|
1063
1068
|
manifest: dataArgsManifest,
|
|
1064
1069
|
name: instructionDataName,
|
|
1065
1070
|
nameApi,
|
|
1066
|
-
node: (0,
|
|
1071
|
+
node: (0, import_nodes15.structTypeNodeFromInstructionArgumentNodes)(instructionNode.arguments),
|
|
1067
1072
|
size: scope.size
|
|
1068
1073
|
});
|
|
1069
1074
|
}
|
|
@@ -1081,17 +1086,17 @@ function getInstructionExtraArgsFragment(scope) {
|
|
|
1081
1086
|
}
|
|
1082
1087
|
|
|
1083
1088
|
// src/fragments/instructionFunction.ts
|
|
1084
|
-
var
|
|
1089
|
+
var import_nodes20 = require("@codama/nodes");
|
|
1085
1090
|
var import_renderers_core8 = require("@codama/renderers-core");
|
|
1086
1091
|
var import_visitors_core17 = require("@codama/visitors-core");
|
|
1087
1092
|
|
|
1088
1093
|
// src/fragments/instructionInputResolved.ts
|
|
1089
|
-
var
|
|
1094
|
+
var import_nodes17 = require("@codama/nodes");
|
|
1090
1095
|
var import_renderers_core6 = require("@codama/renderers-core");
|
|
1091
1096
|
var import_visitors_core14 = require("@codama/visitors-core");
|
|
1092
1097
|
|
|
1093
1098
|
// src/fragments/instructionInputDefault.ts
|
|
1094
|
-
var
|
|
1099
|
+
var import_nodes16 = require("@codama/nodes");
|
|
1095
1100
|
var import_renderers_core5 = require("@codama/renderers-core");
|
|
1096
1101
|
var import_visitors_core13 = require("@codama/visitors-core");
|
|
1097
1102
|
function getInstructionInputDefaultFragment(scope) {
|
|
@@ -1104,8 +1109,8 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1104
1109
|
}
|
|
1105
1110
|
const { defaultValue } = input;
|
|
1106
1111
|
const defaultFragment = (renderedValue, isWritable) => {
|
|
1107
|
-
const inputName = (0,
|
|
1108
|
-
if (input.kind === "instructionAccountNode" && (0,
|
|
1112
|
+
const inputName = (0, import_nodes16.camelCase)(input.name);
|
|
1113
|
+
if (input.kind === "instructionAccountNode" && (0, import_nodes16.isNode)(defaultValue, "resolverValueNode")) {
|
|
1109
1114
|
return fragment`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`;
|
|
1110
1115
|
}
|
|
1111
1116
|
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
@@ -1116,63 +1121,57 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1116
1121
|
}
|
|
1117
1122
|
return fragment`args.${inputName} = ${renderedValue};`;
|
|
1118
1123
|
};
|
|
1124
|
+
const expectTransactionSigner = use("expectTransactionSigner", "shared");
|
|
1125
|
+
const expectSome = use("expectSome", "shared");
|
|
1126
|
+
const expectAddress = use("expectAddress", "shared");
|
|
1127
|
+
const expectProgramDerivedAddress = use("expectProgramDerivedAddress", "shared");
|
|
1128
|
+
const addressType = use("type Address", "solanaAddresses");
|
|
1119
1129
|
switch (defaultValue.kind) {
|
|
1120
1130
|
case "accountValueNode":
|
|
1121
|
-
const name = (0,
|
|
1131
|
+
const name = (0, import_nodes16.camelCase)(defaultValue.name);
|
|
1122
1132
|
if (input.kind === "instructionAccountNode" && input.resolvedIsSigner && !input.isSigner) {
|
|
1123
|
-
return (
|
|
1124
|
-
defaultFragment(`expectTransactionSigner(accounts.${name}.value).address`),
|
|
1125
|
-
(f) => addFragmentImports(f, "shared", ["expectTransactionSigner"])
|
|
1126
|
-
);
|
|
1133
|
+
return defaultFragment(fragment`${expectTransactionSigner}(accounts.${name}.value).address`);
|
|
1127
1134
|
}
|
|
1128
1135
|
if (input.kind === "instructionAccountNode") {
|
|
1129
|
-
return (
|
|
1130
|
-
defaultFragment(`expectSome(accounts.${name}.value)`),
|
|
1131
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1132
|
-
);
|
|
1136
|
+
return defaultFragment(fragment`${expectSome}(accounts.${name}.value)`);
|
|
1133
1137
|
}
|
|
1134
|
-
return (
|
|
1135
|
-
defaultFragment(`expectAddress(accounts.${name}.value)`),
|
|
1136
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1137
|
-
);
|
|
1138
|
+
return defaultFragment(fragment`${expectAddress}(accounts.${name}.value)`);
|
|
1138
1139
|
case "pdaValueNode":
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1140
|
+
let pdaProgramValue;
|
|
1141
|
+
if ((0, import_nodes16.isNode)(defaultValue.programId, "accountValueNode")) {
|
|
1142
|
+
pdaProgramValue = fragment`${expectAddress}(accounts.${(0, import_nodes16.camelCase)(defaultValue.programId.name)}.value)`;
|
|
1143
|
+
}
|
|
1144
|
+
if ((0, import_nodes16.isNode)(defaultValue.programId, "argumentValueNode")) {
|
|
1145
|
+
pdaProgramValue = fragment`${expectAddress}(args.${(0, import_nodes16.camelCase)(defaultValue.programId.name)})`;
|
|
1146
|
+
}
|
|
1147
|
+
if ((0, import_nodes16.isNode)(defaultValue.pda, "pdaNode")) {
|
|
1148
|
+
let pdaProgram = fragment`programAddress`;
|
|
1149
|
+
if (pdaProgramValue) {
|
|
1150
|
+
pdaProgram = pdaProgramValue;
|
|
1151
|
+
} else if (defaultValue.pda.programId) {
|
|
1152
|
+
pdaProgram = fragment`'${defaultValue.pda.programId}' as ${addressType}<'${defaultValue.pda.programId}'>`;
|
|
1153
|
+
}
|
|
1144
1154
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
1145
|
-
if ((0,
|
|
1146
|
-
return [
|
|
1147
|
-
(0, import_visitors_core13.pipe)(
|
|
1148
|
-
fragment`getAddressEncoder().encode(${pdaProgram})`,
|
|
1149
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["getAddressEncoder"])
|
|
1150
|
-
)
|
|
1151
|
-
];
|
|
1155
|
+
if ((0, import_nodes16.isNode)(seed, "constantPdaSeedNode") && (0, import_nodes16.isNode)(seed.value, "programIdValueNode")) {
|
|
1156
|
+
return [fragment`${use("getAddressEncoder", "solanaAddresses")}().encode(${pdaProgram})`];
|
|
1152
1157
|
}
|
|
1153
|
-
if ((0,
|
|
1158
|
+
if ((0, import_nodes16.isNode)(seed, "constantPdaSeedNode") && !(0, import_nodes16.isNode)(seed.value, "programIdValueNode")) {
|
|
1154
1159
|
const typeManifest2 = (0, import_visitors_core13.visit)(seed.type, typeManifestVisitor);
|
|
1155
1160
|
const valueManifest2 = (0, import_visitors_core13.visit)(seed.value, typeManifestVisitor);
|
|
1156
1161
|
return [fragment`${typeManifest2.encoder}.encode(${valueManifest2.value})`];
|
|
1157
1162
|
}
|
|
1158
|
-
if ((0,
|
|
1163
|
+
if ((0, import_nodes16.isNode)(seed, "variablePdaSeedNode")) {
|
|
1159
1164
|
const typeManifest2 = (0, import_visitors_core13.visit)(seed.type, typeManifestVisitor);
|
|
1160
1165
|
const valueSeed = defaultValue.seeds.find((s) => s.name === seed.name)?.value;
|
|
1161
1166
|
if (!valueSeed) return [];
|
|
1162
|
-
if ((0,
|
|
1167
|
+
if ((0, import_nodes16.isNode)(valueSeed, "accountValueNode")) {
|
|
1163
1168
|
return [
|
|
1164
|
-
(0,
|
|
1165
|
-
fragment`${typeManifest2.encoder}.encode(expectAddress(accounts.${(0, import_nodes15.camelCase)(valueSeed.name)}.value))`,
|
|
1166
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1167
|
-
)
|
|
1169
|
+
fragment`${typeManifest2.encoder}.encode(${expectAddress}(accounts.${(0, import_nodes16.camelCase)(valueSeed.name)}.value))`
|
|
1168
1170
|
];
|
|
1169
1171
|
}
|
|
1170
|
-
if ((0,
|
|
1172
|
+
if ((0, import_nodes16.isNode)(valueSeed, "argumentValueNode")) {
|
|
1171
1173
|
return [
|
|
1172
|
-
(0,
|
|
1173
|
-
fragment`${typeManifest2.encoder}.encode(expectSome(args.${(0, import_nodes15.camelCase)(valueSeed.name)}))`,
|
|
1174
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1175
|
-
)
|
|
1174
|
+
fragment`${typeManifest2.encoder}.encode(${expectSome}(args.${(0, import_nodes16.camelCase)(valueSeed.name)}))`
|
|
1176
1175
|
];
|
|
1177
1176
|
}
|
|
1178
1177
|
const valueManifest2 = (0, import_visitors_core13.visit)(valueSeed, typeManifestVisitor);
|
|
@@ -1180,29 +1179,21 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1180
1179
|
}
|
|
1181
1180
|
return [];
|
|
1182
1181
|
});
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
})
|
|
1188
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["getProgramDerivedAddress"]),
|
|
1189
|
-
(f) => (0, import_renderers_core5.mapFragmentContent)(f, (c) => defaultFragment(c).content)
|
|
1182
|
+
const getProgramDerivedAddress = use("getProgramDerivedAddress", "solanaAddresses");
|
|
1183
|
+
const programAddress2 = pdaProgram.content === "programAddress" ? pdaProgram : fragment`programAddress: ${pdaProgram}`;
|
|
1184
|
+
const seeds = mergeFragments(pdaSeeds2, (s) => s.join(", "));
|
|
1185
|
+
return defaultFragment(
|
|
1186
|
+
fragment`await ${getProgramDerivedAddress}({ ${programAddress2}, seeds: [${seeds}] })`
|
|
1190
1187
|
);
|
|
1191
1188
|
}
|
|
1192
|
-
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
1189
|
+
const pdaFunction = use(nameApi.pdaFindFunction(defaultValue.pda.name), getImportFrom(defaultValue.pda));
|
|
1193
1190
|
const pdaArgs = [];
|
|
1194
1191
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
1195
|
-
if ((0,
|
|
1196
|
-
return (0,
|
|
1197
|
-
fragment`${seed.name}: expectAddress(accounts.${(0, import_nodes15.camelCase)(seed.value.name)}.value)`,
|
|
1198
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1199
|
-
);
|
|
1192
|
+
if ((0, import_nodes16.isNode)(seed.value, "accountValueNode")) {
|
|
1193
|
+
return fragment`${seed.name}: ${expectAddress}(accounts.${(0, import_nodes16.camelCase)(seed.value.name)}.value)`;
|
|
1200
1194
|
}
|
|
1201
|
-
if ((0,
|
|
1202
|
-
return (0,
|
|
1203
|
-
fragment`${seed.name}: expectSome(args.${(0, import_nodes15.camelCase)(seed.value.name)})`,
|
|
1204
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1205
|
-
);
|
|
1195
|
+
if ((0, import_nodes16.isNode)(seed.value, "argumentValueNode")) {
|
|
1196
|
+
return fragment`${seed.name}: ${expectSome}(args.${(0, import_nodes16.camelCase)(seed.value.name)})`;
|
|
1206
1197
|
}
|
|
1207
1198
|
return (0, import_visitors_core13.pipe)(
|
|
1208
1199
|
(0, import_visitors_core13.visit)(seed.value, typeManifestVisitor).value,
|
|
@@ -1214,49 +1205,38 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1214
1205
|
(f) => (0, import_renderers_core5.mapFragmentContent)(f, (c) => `{ ${c} }`)
|
|
1215
1206
|
);
|
|
1216
1207
|
if (pdaSeeds.length > 0) {
|
|
1217
|
-
pdaArgs.push(pdaSeedsFragment
|
|
1208
|
+
pdaArgs.push(pdaSeedsFragment);
|
|
1218
1209
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
(f) => addFragmentImports(f, module2, [pdaFunction])
|
|
1224
|
-
);
|
|
1210
|
+
if (pdaProgramValue) {
|
|
1211
|
+
pdaArgs.push(fragment`{ programAddress: ${pdaProgramValue} }`);
|
|
1212
|
+
}
|
|
1213
|
+
return defaultFragment(fragment`await ${pdaFunction}(${mergeFragments(pdaArgs, (c) => c.join(", "))})`);
|
|
1225
1214
|
case "publicKeyValueNode":
|
|
1226
|
-
return (
|
|
1227
|
-
|
|
1228
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["type Address"])
|
|
1215
|
+
return defaultFragment(
|
|
1216
|
+
fragment`'${defaultValue.publicKey}' as ${addressType}<'${defaultValue.publicKey}'>`
|
|
1229
1217
|
);
|
|
1230
1218
|
case "programLinkNode":
|
|
1231
|
-
const programAddress = nameApi.programAddressConstant(defaultValue.name);
|
|
1232
|
-
return (
|
|
1233
|
-
defaultFragment(programAddress, false),
|
|
1234
|
-
(f) => addFragmentImports(f, getImportFrom(defaultValue), [programAddress])
|
|
1235
|
-
);
|
|
1219
|
+
const programAddress = use(nameApi.programAddressConstant(defaultValue.name), getImportFrom(defaultValue));
|
|
1220
|
+
return defaultFragment(programAddress, false);
|
|
1236
1221
|
case "programIdValueNode":
|
|
1237
1222
|
if (optionalAccountStrategy === "programId" && input.kind === "instructionAccountNode" && input.isOptional) {
|
|
1238
1223
|
return fragment``;
|
|
1239
1224
|
}
|
|
1240
|
-
return defaultFragment(
|
|
1225
|
+
return defaultFragment(fragment`programAddress`, false);
|
|
1241
1226
|
case "identityValueNode":
|
|
1242
1227
|
case "payerValueNode":
|
|
1243
1228
|
return fragment``;
|
|
1244
1229
|
case "accountBumpValueNode":
|
|
1245
|
-
return (
|
|
1246
|
-
|
|
1247
|
-
(f) => addFragmentImports(f, "shared", ["expectProgramDerivedAddress"])
|
|
1230
|
+
return defaultFragment(
|
|
1231
|
+
fragment`${expectProgramDerivedAddress}(accounts.${(0, import_nodes16.camelCase)(defaultValue.name)}.value)[1]`
|
|
1248
1232
|
);
|
|
1249
1233
|
case "argumentValueNode":
|
|
1250
|
-
return (0,
|
|
1251
|
-
defaultFragment(`expectSome(args.${(0, import_nodes15.camelCase)(defaultValue.name)})`),
|
|
1252
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1253
|
-
);
|
|
1234
|
+
return defaultFragment(fragment`${expectSome}(args.${(0, import_nodes16.camelCase)(defaultValue.name)})`);
|
|
1254
1235
|
case "resolverValueNode":
|
|
1255
|
-
const resolverFunction = nameApi.resolverFunction(defaultValue.name);
|
|
1236
|
+
const resolverFunction = use(nameApi.resolverFunction(defaultValue.name), getImportFrom(defaultValue));
|
|
1256
1237
|
const resolverAwait = useAsync && asyncResolvers.includes(defaultValue.name) ? "await " : "";
|
|
1257
1238
|
return (0, import_visitors_core13.pipe)(
|
|
1258
|
-
defaultFragment(`${resolverAwait}${resolverFunction}(resolverScope)`),
|
|
1259
|
-
(f) => addFragmentImports(f, getImportFrom(defaultValue), [resolverFunction]),
|
|
1239
|
+
defaultFragment(fragment`${resolverAwait}${resolverFunction}(resolverScope)`),
|
|
1260
1240
|
(f) => addFragmentFeatures(f, ["instruction:resolverScopeVariable"])
|
|
1261
1241
|
);
|
|
1262
1242
|
case "conditionalValueNode":
|
|
@@ -1280,19 +1260,19 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1280
1260
|
}
|
|
1281
1261
|
const negatedCondition = !ifTrueRenderer;
|
|
1282
1262
|
let condition = "true";
|
|
1283
|
-
if ((0,
|
|
1263
|
+
if ((0, import_nodes16.isNode)(defaultValue.condition, "resolverValueNode")) {
|
|
1284
1264
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
1285
|
-
const
|
|
1265
|
+
const module2 = getImportFrom(defaultValue.condition);
|
|
1286
1266
|
conditionalFragment = (0, import_visitors_core13.pipe)(
|
|
1287
1267
|
conditionalFragment,
|
|
1288
|
-
(f) => addFragmentImports(f,
|
|
1268
|
+
(f) => addFragmentImports(f, module2, [conditionalResolverFunction]),
|
|
1289
1269
|
(f) => addFragmentFeatures(f, ["instruction:resolverScopeVariable"])
|
|
1290
1270
|
);
|
|
1291
1271
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
1292
1272
|
condition = `${conditionalResolverAwait}${conditionalResolverFunction}(resolverScope)`;
|
|
1293
1273
|
condition = negatedCondition ? `!${condition}` : condition;
|
|
1294
1274
|
} else {
|
|
1295
|
-
const comparedInputName = (0,
|
|
1275
|
+
const comparedInputName = (0, import_nodes16.isNode)(defaultValue.condition, "accountValueNode") ? `accounts.${(0, import_nodes16.camelCase)(defaultValue.condition.name)}.value` : `args.${(0, import_nodes16.camelCase)(defaultValue.condition.name)}`;
|
|
1296
1276
|
if (defaultValue.value) {
|
|
1297
1277
|
const comparedValue = (0, import_visitors_core13.visit)(defaultValue.value, typeManifestVisitor).value;
|
|
1298
1278
|
conditionalFragment = mergeFragments([conditionalFragment, comparedValue], (c) => c[0]);
|
|
@@ -1320,7 +1300,7 @@ ${ifTrueRenderer ? ifTrueRenderer.content : ifFalseRenderer?.content}
|
|
|
1320
1300
|
);
|
|
1321
1301
|
default:
|
|
1322
1302
|
const valueManifest = (0, import_visitors_core13.visit)(defaultValue, typeManifestVisitor).value;
|
|
1323
|
-
return (
|
|
1303
|
+
return defaultFragment(valueManifest);
|
|
1324
1304
|
}
|
|
1325
1305
|
}
|
|
1326
1306
|
function renderNestedInstructionDefault(scope) {
|
|
@@ -1339,14 +1319,14 @@ function getInstructionInputResolvedFragment(scope) {
|
|
|
1339
1319
|
const inputFragment = getInstructionInputDefaultFragment({
|
|
1340
1320
|
...scope,
|
|
1341
1321
|
input,
|
|
1342
|
-
optionalAccountStrategy: (0,
|
|
1322
|
+
optionalAccountStrategy: (0, import_nodes17.parseOptionalAccountStrategy)(instructionNode.optionalAccountStrategy)
|
|
1343
1323
|
});
|
|
1344
1324
|
if (!inputFragment.content) return [];
|
|
1345
|
-
const camelName = (0,
|
|
1325
|
+
const camelName = (0, import_nodes17.camelCase)(input.name);
|
|
1346
1326
|
return [
|
|
1347
1327
|
(0, import_renderers_core6.mapFragmentContent)(
|
|
1348
1328
|
inputFragment,
|
|
1349
|
-
(c) => (0,
|
|
1329
|
+
(c) => (0, import_nodes17.isNode)(input, "instructionArgumentNode") ? `if (!args.${camelName}) {
|
|
1350
1330
|
${c}
|
|
1351
1331
|
}` : `if (!accounts.${camelName}.value) {
|
|
1352
1332
|
${c}
|
|
@@ -1361,7 +1341,7 @@ ${c}
|
|
|
1361
1341
|
}
|
|
1362
1342
|
|
|
1363
1343
|
// src/fragments/instructionInputType.ts
|
|
1364
|
-
var
|
|
1344
|
+
var import_nodes18 = require("@codama/nodes");
|
|
1365
1345
|
var import_renderers_core7 = require("@codama/renderers-core");
|
|
1366
1346
|
var import_visitors_core15 = require("@codama/visitors-core");
|
|
1367
1347
|
function getInstructionInputTypeFragment(scope) {
|
|
@@ -1371,7 +1351,7 @@ function getInstructionInputTypeFragment(scope) {
|
|
|
1371
1351
|
const [dataArgumentsFragment, customDataArgumentsFragment] = getDataArgumentsFragments(scope);
|
|
1372
1352
|
let accountTypeParams = "";
|
|
1373
1353
|
if (instructionNode.accounts.length > 0) {
|
|
1374
|
-
accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0,
|
|
1354
|
+
accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0, import_nodes18.pascalCase)(account.name)} extends string = string`).join(", ");
|
|
1375
1355
|
accountTypeParams = `<${accountTypeParams}>`;
|
|
1376
1356
|
}
|
|
1377
1357
|
const typeBodyFragment = mergeFragments(
|
|
@@ -1394,15 +1374,15 @@ function getAccountsFragment(scope) {
|
|
|
1394
1374
|
const resolvedAccount = resolvedInputs.find(
|
|
1395
1375
|
(input) => input.kind === "instructionAccountNode" && input.name === account.name
|
|
1396
1376
|
);
|
|
1397
|
-
const hasDefaultValue = !!resolvedAccount.defaultValue && !(0,
|
|
1377
|
+
const hasDefaultValue = !!resolvedAccount.defaultValue && !(0, import_nodes18.isNode)(resolvedAccount.defaultValue, ["identityValueNode", "payerValueNode"]) && (useAsync || !isAsyncDefaultValue(resolvedAccount.defaultValue, asyncResolvers));
|
|
1398
1378
|
const docs = getDocblockFragment(account.docs ?? [], true);
|
|
1399
1379
|
const optionalSign = hasDefaultValue || resolvedAccount.isOptional ? "?" : "";
|
|
1400
|
-
return fragment`${docs}${(0,
|
|
1380
|
+
return fragment`${docs}${(0, import_nodes18.camelCase)(account.name)}${optionalSign}: ${getAccountTypeFragment2(resolvedAccount)};`;
|
|
1401
1381
|
});
|
|
1402
1382
|
return mergeFragments(fragments, (c) => c.join("\n"));
|
|
1403
1383
|
}
|
|
1404
1384
|
function getAccountTypeFragment2(account) {
|
|
1405
|
-
const typeParam = `TAccount${(0,
|
|
1385
|
+
const typeParam = `TAccount${(0, import_nodes18.pascalCase)(account.name)}`;
|
|
1406
1386
|
const address = use("type Address", "solanaAddresses");
|
|
1407
1387
|
const signer = use("type TransactionSigner", "solanaSigners");
|
|
1408
1388
|
const pda = use("type ProgramDerivedAddress", "solanaAddresses");
|
|
@@ -1448,18 +1428,18 @@ function getExtraArgumentsFragment(scope) {
|
|
|
1448
1428
|
}
|
|
1449
1429
|
function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
1450
1430
|
const resolvedArg = resolvedInputs.find(
|
|
1451
|
-
(input) => (0,
|
|
1431
|
+
(input) => (0, import_nodes18.isNode)(input, "instructionArgumentNode") && input.name === arg.name
|
|
1452
1432
|
);
|
|
1453
1433
|
if (arg.defaultValue && arg.defaultValueStrategy === "omitted") return null;
|
|
1454
1434
|
const renamedName = renamedArgs.get(arg.name) ?? arg.name;
|
|
1455
1435
|
const optionalSign = arg.defaultValue || resolvedArg?.defaultValue ? "?" : "";
|
|
1456
|
-
return fragment`${(0,
|
|
1436
|
+
return fragment`${(0, import_nodes18.camelCase)(renamedName)}${optionalSign}: ${argsType}["${(0, import_nodes18.camelCase)(arg.name)}"];`;
|
|
1457
1437
|
}
|
|
1458
1438
|
function getRemainingAccountsFragment(instructionNode) {
|
|
1459
1439
|
const fragments = (instructionNode.remainingAccounts ?? []).flatMap((remainingAccountsNode) => {
|
|
1460
|
-
if ((0,
|
|
1440
|
+
if ((0, import_nodes18.isNode)(remainingAccountsNode.value, "resolverValueNode")) return [];
|
|
1461
1441
|
const { name } = remainingAccountsNode.value;
|
|
1462
|
-
const allArguments = (0,
|
|
1442
|
+
const allArguments = (0, import_nodes18.getAllInstructionArguments)(instructionNode);
|
|
1463
1443
|
const argumentExists = allArguments.some((arg) => arg.name === name);
|
|
1464
1444
|
if (argumentExists) return [];
|
|
1465
1445
|
const isSigner = remainingAccountsNode.isSigner ?? false;
|
|
@@ -1470,14 +1450,14 @@ function getRemainingAccountsFragment(instructionNode) {
|
|
|
1470
1450
|
if (isSigner === "either") return fragment`${signerFragment} | ${addressFragment}`;
|
|
1471
1451
|
return isSigner ? signerFragment : addressFragment;
|
|
1472
1452
|
})();
|
|
1473
|
-
return fragment`${(0,
|
|
1453
|
+
return fragment`${(0, import_nodes18.camelCase)(name)}${optionalSign}: Array<${typeFragment}>;`;
|
|
1474
1454
|
});
|
|
1475
1455
|
if (fragments.length === 0) return;
|
|
1476
1456
|
return mergeFragments(fragments, (c) => c.join("\n"));
|
|
1477
1457
|
}
|
|
1478
1458
|
|
|
1479
1459
|
// src/fragments/instructionRemainingAccounts.ts
|
|
1480
|
-
var
|
|
1460
|
+
var import_nodes19 = require("@codama/nodes");
|
|
1481
1461
|
var import_visitors_core16 = require("@codama/visitors-core");
|
|
1482
1462
|
function getInstructionRemainingAccountsFragment(scope) {
|
|
1483
1463
|
const { remainingAccounts } = (0, import_visitors_core16.getLastNodeFromPath)(scope.instructionPath);
|
|
@@ -1494,10 +1474,10 @@ const remainingAccounts: AccountMeta[] = ${c.length === 1 ? c[0] : `[...${c.join
|
|
|
1494
1474
|
}
|
|
1495
1475
|
function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
1496
1476
|
const remainingAccountsFragment = (() => {
|
|
1497
|
-
if ((0,
|
|
1477
|
+
if ((0, import_nodes19.isNode)(remainingAccounts.value, "argumentValueNode")) {
|
|
1498
1478
|
return getArgumentValueNodeFragment2(remainingAccounts, scope);
|
|
1499
1479
|
}
|
|
1500
|
-
if ((0,
|
|
1480
|
+
if ((0, import_nodes19.isNode)(remainingAccounts.value, "resolverValueNode")) {
|
|
1501
1481
|
return getResolverValueNodeFragment2(remainingAccounts, scope);
|
|
1502
1482
|
}
|
|
1503
1483
|
return null;
|
|
@@ -1507,8 +1487,8 @@ function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
|
1507
1487
|
}
|
|
1508
1488
|
function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
1509
1489
|
const instructionNode = (0, import_visitors_core16.getLastNodeFromPath)(scope.instructionPath);
|
|
1510
|
-
(0,
|
|
1511
|
-
const argumentName = (0,
|
|
1490
|
+
(0, import_nodes19.assertIsNode)(remainingAccounts.value, "argumentValueNode");
|
|
1491
|
+
const argumentName = (0, import_nodes19.camelCase)(remainingAccounts.value.name);
|
|
1512
1492
|
const isOptional = remainingAccounts.isOptional ?? false;
|
|
1513
1493
|
const isSigner = remainingAccounts.isSigner ?? false;
|
|
1514
1494
|
const isWritable = remainingAccounts.isWritable ?? false;
|
|
@@ -1517,7 +1497,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1517
1497
|
const signerRole = isWritable ? fragment`${accountRole}.WRITABLE_SIGNER` : fragment`${accountRole}.READONLY_SIGNER`;
|
|
1518
1498
|
const role = isSigner === true ? signerRole : nonSignerRole;
|
|
1519
1499
|
const argumentArray = isOptional ? `(args.${argumentName} ?? [])` : `args.${argumentName}`;
|
|
1520
|
-
const allArguments = (0,
|
|
1500
|
+
const allArguments = (0, import_nodes19.getAllInstructionArguments)(instructionNode);
|
|
1521
1501
|
const argumentExists = allArguments.some((arg) => arg.name === remainingAccounts.value.name);
|
|
1522
1502
|
if (argumentExists || isSigner === false) {
|
|
1523
1503
|
return fragment`${argumentArray}.map((address) => ({ address, role: ${role} }))`;
|
|
@@ -1528,7 +1508,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1528
1508
|
return fragment`${argumentArray}.map((signer) => ({ address: signer.address, role: ${signerRole}, signer }))`;
|
|
1529
1509
|
}
|
|
1530
1510
|
function getResolverValueNodeFragment2(remainingAccounts, scope) {
|
|
1531
|
-
(0,
|
|
1511
|
+
(0, import_nodes19.assertIsNode)(remainingAccounts.value, "resolverValueNode");
|
|
1532
1512
|
const isAsync = scope.asyncResolvers.includes(remainingAccounts.value.name);
|
|
1533
1513
|
if (!scope.useAsync && isAsync) return null;
|
|
1534
1514
|
const awaitKeyword = scope.useAsync && isAsync ? "await " : "";
|
|
@@ -1551,7 +1531,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1551
1531
|
const customData = customInstructionData.get(instructionNode.name);
|
|
1552
1532
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1553
1533
|
const instructionDependencies = getInstructionDependencies(instructionNode, asyncResolvers, useAsync);
|
|
1554
|
-
const argDependencies = instructionDependencies.filter((0,
|
|
1534
|
+
const argDependencies = instructionDependencies.filter((0, import_nodes20.isNodeFilter)("argumentValueNode")).map((node) => node.name);
|
|
1555
1535
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
1556
1536
|
const argIsNotOmitted = (arg) => !(arg.defaultValue && arg.defaultValueStrategy === "omitted");
|
|
1557
1537
|
const argIsDependent = (arg) => argDependencies.includes(arg.name);
|
|
@@ -1564,7 +1544,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1564
1544
|
const hasExtraArgs = (instructionNode.extraArguments ?? []).filter(
|
|
1565
1545
|
(field) => argIsNotOmitted(field) && (argIsDependent(field) || argHasDefaultValue(field))
|
|
1566
1546
|
).length > 0;
|
|
1567
|
-
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => (0,
|
|
1547
|
+
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => (0, import_nodes20.isNode)(value, "argumentValueNode")).length > 0;
|
|
1568
1548
|
const hasAnyArgs = hasDataArgs || hasExtraArgs || hasRemainingAccountArgs;
|
|
1569
1549
|
const hasInput = hasAccounts || hasAnyArgs;
|
|
1570
1550
|
const programAddressConstant = use(nameApi.programAddressConstant(programNode.name), "generatedPrograms");
|
|
@@ -1615,7 +1595,7 @@ function getAccountsInitializationFragment(instructionNode) {
|
|
|
1615
1595
|
if (instructionNode.accounts.length === 0) return;
|
|
1616
1596
|
const accounts = mergeFragments(
|
|
1617
1597
|
instructionNode.accounts.map((account) => {
|
|
1618
|
-
const name = (0,
|
|
1598
|
+
const name = (0, import_nodes20.camelCase)(account.name);
|
|
1619
1599
|
const isWritable = account.isWritable ? "true" : "false";
|
|
1620
1600
|
return fragment`${name}: { value: input.${name} ?? null, isWritable: ${isWritable} }`;
|
|
1621
1601
|
}),
|
|
@@ -1650,7 +1630,7 @@ function getReturnStatementFragment(scope) {
|
|
|
1650
1630
|
const hasLegacyOptionalAccounts = instructionNode.optionalAccountStrategy === "omitted" && instructionNode.accounts.some((account) => account.isOptional);
|
|
1651
1631
|
const getAccountMeta = hasAccounts ? fragment`const getAccountMeta = ${use("getAccountMetaFactory", "shared")}(programAddress, '${optionalAccountStrategy}');` : "";
|
|
1652
1632
|
const accountItems = [
|
|
1653
|
-
...instructionNode.accounts.map((account) => `getAccountMeta(accounts.${(0,
|
|
1633
|
+
...instructionNode.accounts.map((account) => `getAccountMeta(accounts.${(0, import_nodes20.camelCase)(account.name)})`),
|
|
1654
1634
|
...hasRemainingAccounts ? ["...remainingAccounts"] : []
|
|
1655
1635
|
].join(", ");
|
|
1656
1636
|
let accounts;
|
|
@@ -1687,7 +1667,7 @@ function getReturnTypeFragment(instructionTypeFragment, hasByteDeltas, useAsync)
|
|
|
1687
1667
|
function getTypeParamsFragment(instructionNode, programAddressConstant) {
|
|
1688
1668
|
return mergeFragments(
|
|
1689
1669
|
[
|
|
1690
|
-
...instructionNode.accounts.map((account) => fragment`TAccount${(0,
|
|
1670
|
+
...instructionNode.accounts.map((account) => fragment`TAccount${(0, import_nodes20.pascalCase)(account.name)} extends string`),
|
|
1691
1671
|
fragment`TProgramAddress extends ${use("type Address", "solanaAddresses")} = typeof ${programAddressConstant}`
|
|
1692
1672
|
],
|
|
1693
1673
|
(cs) => `<${cs.join(", ")}>`
|
|
@@ -1698,8 +1678,8 @@ function getInstructionTypeFragment(scope) {
|
|
|
1698
1678
|
const instructionNode = (0, import_visitors_core17.getLastNodeFromPath)(instructionPath);
|
|
1699
1679
|
const instructionTypeName = nameApi.instructionType(instructionNode.name);
|
|
1700
1680
|
const accountTypeParamsFragments = instructionNode.accounts.map((account) => {
|
|
1701
|
-
const typeParam = fragment`TAccount${(0,
|
|
1702
|
-
const camelName = (0,
|
|
1681
|
+
const typeParam = fragment`TAccount${(0, import_nodes20.pascalCase)(account.name)}`;
|
|
1682
|
+
const camelName = (0, import_nodes20.camelCase)(account.name);
|
|
1703
1683
|
if (account.isSigner === "either") {
|
|
1704
1684
|
const signerRole = use(
|
|
1705
1685
|
account.isWritable ? "type WritableSignerAccount" : "type ReadonlySignerAccount",
|
|
@@ -1722,17 +1702,17 @@ function getInputTypeCallFragment(scope) {
|
|
|
1722
1702
|
const instructionNode = (0, import_visitors_core17.getLastNodeFromPath)(instructionPath);
|
|
1723
1703
|
const inputTypeName = useAsync ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name);
|
|
1724
1704
|
if (instructionNode.accounts.length === 0) return fragment`${inputTypeName}`;
|
|
1725
|
-
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0,
|
|
1705
|
+
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${(0, import_nodes20.pascalCase)(account.name)}`).join(", ");
|
|
1726
1706
|
return fragment`${inputTypeName}<${accountTypeParams}>`;
|
|
1727
1707
|
}
|
|
1728
1708
|
|
|
1729
1709
|
// src/fragments/instructionPage.ts
|
|
1730
1710
|
var import_errors2 = require("@codama/errors");
|
|
1731
|
-
var
|
|
1711
|
+
var import_nodes23 = require("@codama/nodes");
|
|
1732
1712
|
var import_visitors_core20 = require("@codama/visitors-core");
|
|
1733
1713
|
|
|
1734
1714
|
// src/fragments/instructionParseFunction.ts
|
|
1735
|
-
var
|
|
1715
|
+
var import_nodes21 = require("@codama/nodes");
|
|
1736
1716
|
var import_visitors_core18 = require("@codama/visitors-core");
|
|
1737
1717
|
function getInstructionParseFunctionFragment(scope) {
|
|
1738
1718
|
const instructionNode = (0, import_visitors_core18.getLastNodeFromPath)(scope.instructionPath);
|
|
@@ -1757,7 +1737,7 @@ function getTypeFragment2(scope) {
|
|
|
1757
1737
|
const accounts = mergeFragments(
|
|
1758
1738
|
scope.instructionNode.accounts.map((account, i) => {
|
|
1759
1739
|
const docs = getDocblockFragment(account.docs ?? [], true);
|
|
1760
|
-
const name = (0,
|
|
1740
|
+
const name = (0, import_nodes21.camelCase)(account.name);
|
|
1761
1741
|
return fragment`${docs}${name}${account.isOptional ? "?" : ""}: TAccountMetas[${i}]${account.isOptional ? " | undefined" : ""};`;
|
|
1762
1742
|
}),
|
|
1763
1743
|
(cs) => hasAccounts ? `
|
|
@@ -1829,7 +1809,7 @@ const getNextOptionalAccount = () => {
|
|
|
1829
1809
|
}
|
|
1830
1810
|
const accounts = mergeFragments(
|
|
1831
1811
|
scope.instructionNode.accounts.map(
|
|
1832
|
-
(account) => account.isOptional ? fragment`${(0,
|
|
1812
|
+
(account) => account.isOptional ? fragment`${(0, import_nodes21.camelCase)(account.name)}: getNextOptionalAccount()` : fragment`${(0, import_nodes21.camelCase)(account.name)}: getNextAccount()`
|
|
1833
1813
|
),
|
|
1834
1814
|
(cs) => hasAccounts ? `, accounts: { ${cs.join(", ")} }` : ""
|
|
1835
1815
|
);
|
|
@@ -1841,7 +1821,7 @@ const getNextOptionalAccount = () => {
|
|
|
1841
1821
|
}
|
|
1842
1822
|
|
|
1843
1823
|
// src/fragments/instructionType.ts
|
|
1844
|
-
var
|
|
1824
|
+
var import_nodes22 = require("@codama/nodes");
|
|
1845
1825
|
var import_renderers_core9 = require("@codama/renderers-core");
|
|
1846
1826
|
var import_visitors_core19 = require("@codama/visitors-core");
|
|
1847
1827
|
function getInstructionTypeFragment2(scope) {
|
|
@@ -1868,7 +1848,7 @@ function getInstructionTypeFragment2(scope) {
|
|
|
1868
1848
|
const accountMetasFragment = mergeFragments(
|
|
1869
1849
|
instructionNode.accounts.map(
|
|
1870
1850
|
(account) => (0, import_renderers_core9.mapFragmentContent)(getInstructionAccountMetaFragment(account), (c) => {
|
|
1871
|
-
const typeParam = `TAccount${(0,
|
|
1851
|
+
const typeParam = `TAccount${(0, import_nodes22.pascalCase)(account.name)}`;
|
|
1872
1852
|
const isLegacyOptional = account.isOptional && usesLegacyOptionalAccounts;
|
|
1873
1853
|
const type = `${typeParam} extends string ? ${c} : ${typeParam}`;
|
|
1874
1854
|
if (!isLegacyOptional) return type;
|
|
@@ -1893,9 +1873,9 @@ function getInstructionPageFragment(scope) {
|
|
|
1893
1873
|
...scope,
|
|
1894
1874
|
dataArgsManifest: (0, import_visitors_core20.visit)(node, scope.typeManifestVisitor),
|
|
1895
1875
|
extraArgsManifest: (0, import_visitors_core20.visit)(
|
|
1896
|
-
(0,
|
|
1876
|
+
(0, import_nodes23.definedTypeNode)({
|
|
1897
1877
|
name: scope.nameApi.instructionExtraType(node.name),
|
|
1898
|
-
type: (0,
|
|
1878
|
+
type: (0, import_nodes23.structTypeNodeFromInstructionArgumentNodes)(node.extraArguments ?? [])
|
|
1899
1879
|
}),
|
|
1900
1880
|
scope.typeManifestVisitor
|
|
1901
1881
|
),
|
|
@@ -1934,11 +1914,11 @@ function getRenamedArgsMap(instruction) {
|
|
|
1934
1914
|
(0, import_errors2.logWarn)(
|
|
1935
1915
|
`[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.`
|
|
1936
1916
|
);
|
|
1937
|
-
return new Map(duplicates.map((name) => [(0,
|
|
1917
|
+
return new Map(duplicates.map((name) => [(0, import_nodes23.camelCase)(name), (0, import_nodes23.camelCase)(`${name}Arg`)]));
|
|
1938
1918
|
}
|
|
1939
1919
|
|
|
1940
1920
|
// src/fragments/pdaFunction.ts
|
|
1941
|
-
var
|
|
1921
|
+
var import_nodes24 = require("@codama/nodes");
|
|
1942
1922
|
var import_visitors_core21 = require("@codama/visitors-core");
|
|
1943
1923
|
function getPdaFunctionFragment(scope) {
|
|
1944
1924
|
const pdaNode = (0, import_visitors_core21.getLastNodeFromPath)(scope.pdaPath);
|
|
@@ -1949,7 +1929,7 @@ function getPdaFunctionFragment(scope) {
|
|
|
1949
1929
|
);
|
|
1950
1930
|
}
|
|
1951
1931
|
function getSeedInputTypeFragment(seeds, scope) {
|
|
1952
|
-
const variableSeeds = seeds.filter((0,
|
|
1932
|
+
const variableSeeds = seeds.filter((0, import_nodes24.isNodeFilter)("variablePdaSeedNode"));
|
|
1953
1933
|
if (variableSeeds.length === 0) return;
|
|
1954
1934
|
const pdaNode = (0, import_visitors_core21.getLastNodeFromPath)(scope.pdaPath);
|
|
1955
1935
|
const seedTypeName = scope.nameApi.pdaSeedsType(pdaNode.name);
|
|
@@ -1968,7 +1948,7 @@ function getFunctionFragment2(seeds, scope) {
|
|
|
1968
1948
|
const seedTypeName = scope.nameApi.pdaSeedsType(pdaNode.name);
|
|
1969
1949
|
const findPdaFunction = scope.nameApi.pdaFindFunction(pdaNode.name);
|
|
1970
1950
|
const docs = getDocblockFragment(pdaNode.docs ?? [], true);
|
|
1971
|
-
const hasVariableSeeds = seeds.filter((0,
|
|
1951
|
+
const hasVariableSeeds = seeds.filter((0, import_nodes24.isNodeFilter)("variablePdaSeedNode")).length > 0;
|
|
1972
1952
|
const seedArgument = hasVariableSeeds ? `seeds: ${seedTypeName}, ` : "";
|
|
1973
1953
|
const programAddress = pdaNode.programId ?? programNode.publicKey;
|
|
1974
1954
|
const encodedSeeds = mergeFragments(
|
|
@@ -1982,8 +1962,8 @@ function getFunctionFragment2(seeds, scope) {
|
|
|
1982
1962
|
}
|
|
1983
1963
|
function parsePdaSeedNodes(seeds, scope) {
|
|
1984
1964
|
return seeds.map((seed) => {
|
|
1985
|
-
if ((0,
|
|
1986
|
-
const name = (0,
|
|
1965
|
+
if ((0, import_nodes24.isNode)(seed, "variablePdaSeedNode")) {
|
|
1966
|
+
const name = (0, import_nodes24.camelCase)(seed.name);
|
|
1987
1967
|
const docs = getDocblockFragment(seed.docs ?? [], true);
|
|
1988
1968
|
const { encoder: encoder2, looseType } = (0, import_visitors_core21.visit)(seed.type, scope.typeManifestVisitor);
|
|
1989
1969
|
return {
|
|
@@ -1992,7 +1972,7 @@ function parsePdaSeedNodes(seeds, scope) {
|
|
|
1992
1972
|
inputAttribute: fragment`${docs}${name}: ${looseType};`
|
|
1993
1973
|
};
|
|
1994
1974
|
}
|
|
1995
|
-
if ((0,
|
|
1975
|
+
if ((0, import_nodes24.isNode)(seed.value, "programIdValueNode")) {
|
|
1996
1976
|
const addressEncoder = use("getAddressEncoder", "solanaAddresses");
|
|
1997
1977
|
return { ...seed, encodedValue: fragment`${addressEncoder}().encode(programAddress)` };
|
|
1998
1978
|
}
|
|
@@ -2012,7 +1992,7 @@ function getPdaPageFragment(scope) {
|
|
|
2012
1992
|
}
|
|
2013
1993
|
|
|
2014
1994
|
// src/fragments/programAccounts.ts
|
|
2015
|
-
var
|
|
1995
|
+
var import_nodes25 = require("@codama/nodes");
|
|
2016
1996
|
var import_renderers_core10 = require("@codama/renderers-core");
|
|
2017
1997
|
var import_visitors_core23 = require("@codama/visitors-core");
|
|
2018
1998
|
function getProgramAccountsFragment(scope) {
|
|
@@ -2048,7 +2028,7 @@ function getProgramAccountsIdentifierFunctionFragment(scope) {
|
|
|
2048
2028
|
dataName: "data",
|
|
2049
2029
|
discriminators: account.discriminators ?? [],
|
|
2050
2030
|
ifTrue: `return ${programAccountsEnum}.${variant};`,
|
|
2051
|
-
struct: (0,
|
|
2031
|
+
struct: (0, import_nodes25.resolveNestedTypeNode)(account.data)
|
|
2052
2032
|
});
|
|
2053
2033
|
}),
|
|
2054
2034
|
(c) => c.join("\n")
|
|
@@ -2077,12 +2057,12 @@ function getProgramConstantFragment(scope) {
|
|
|
2077
2057
|
}
|
|
2078
2058
|
|
|
2079
2059
|
// src/fragments/programInstructions.ts
|
|
2080
|
-
var
|
|
2060
|
+
var import_nodes26 = require("@codama/nodes");
|
|
2081
2061
|
var import_renderers_core11 = require("@codama/renderers-core");
|
|
2082
2062
|
var import_visitors_core25 = require("@codama/visitors-core");
|
|
2083
2063
|
function getProgramInstructionsFragment(scope) {
|
|
2084
2064
|
if (scope.programNode.instructions.length === 0) return;
|
|
2085
|
-
const allInstructions = (0,
|
|
2065
|
+
const allInstructions = (0, import_nodes26.getAllInstructionsWithSubs)(scope.programNode, {
|
|
2086
2066
|
leavesOnly: !scope.renderParentInstructions,
|
|
2087
2067
|
subInstructionsFirst: true
|
|
2088
2068
|
});
|
|
@@ -2121,7 +2101,7 @@ function getProgramInstructionsIdentifierFunctionFragment(scope) {
|
|
|
2121
2101
|
dataName: "data",
|
|
2122
2102
|
discriminators: instruction.discriminators ?? [],
|
|
2123
2103
|
ifTrue: `return ${programInstructionsEnum}.${variant};`,
|
|
2124
|
-
struct: (0,
|
|
2104
|
+
struct: (0, import_nodes26.structTypeNodeFromInstructionArgumentNodes)(instruction.arguments)
|
|
2125
2105
|
});
|
|
2126
2106
|
}),
|
|
2127
2107
|
(c) => c.join("\n")
|
|
@@ -2308,10 +2288,10 @@ export function isTransactionSigner<TAddress extends string = string>(value: Add
|
|
|
2308
2288
|
}
|
|
2309
2289
|
|
|
2310
2290
|
// src/fragments/typeDiscriminatedUnionHelpers.ts
|
|
2311
|
-
var
|
|
2291
|
+
var import_nodes27 = require("@codama/nodes");
|
|
2312
2292
|
function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
2313
2293
|
const { name, typeNode, nameApi } = scope;
|
|
2314
|
-
const isDiscriminatedUnion = (0,
|
|
2294
|
+
const isDiscriminatedUnion = (0, import_nodes27.isNode)(typeNode, "enumTypeNode") && (0, import_nodes27.isDataEnum)(typeNode);
|
|
2315
2295
|
if (!isDiscriminatedUnion) return;
|
|
2316
2296
|
const functionName = nameApi.discriminatedUnionFunction(name);
|
|
2317
2297
|
const isDiscriminatedUnionFunctionName = nameApi.isDiscriminatedUnionFunction(name);
|
|
@@ -2323,10 +2303,10 @@ function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
|
2323
2303
|
const variantSignatures = mergeFragments(
|
|
2324
2304
|
typeNode.variants.map((variant) => {
|
|
2325
2305
|
const variantName = nameApi.discriminatedUnionVariant(variant.name);
|
|
2326
|
-
if ((0,
|
|
2306
|
+
if ((0, import_nodes27.isNode)(variant, "enumStructVariantTypeNode")) {
|
|
2327
2307
|
return fragment`export function ${functionName}(kind: '${variantName}', data: ${getVariantContentType}<${looseName}, '${discriminatorName}', '${variantName}'>): ${getVariantType}<${looseName}, '${discriminatorName}', '${variantName}'>;`;
|
|
2328
2308
|
}
|
|
2329
|
-
if ((0,
|
|
2309
|
+
if ((0, import_nodes27.isNode)(variant, "enumTupleVariantTypeNode")) {
|
|
2330
2310
|
return fragment`export function ${functionName}(kind: '${variantName}', data: ${getVariantContentType}<${looseName}, '${discriminatorName}', '${variantName}'>['fields']): ${getVariantType}<${looseName}, '${discriminatorName}', '${variantName}'>;`;
|
|
2331
2311
|
}
|
|
2332
2312
|
return fragment`export function ${functionName}(kind: '${variantName}'): ${getVariantType}<${looseName}, '${discriminatorName}', '${variantName}'>;`;
|
|
@@ -2369,7 +2349,7 @@ function getTypePageFragment(scope) {
|
|
|
2369
2349
|
}
|
|
2370
2350
|
|
|
2371
2351
|
// src/visitors/getTypeManifestVisitor.ts
|
|
2372
|
-
var
|
|
2352
|
+
var import_nodes28 = require("@codama/nodes");
|
|
2373
2353
|
var import_renderers_core12 = require("@codama/renderers-core");
|
|
2374
2354
|
var import_visitors_core28 = require("@codama/visitors-core");
|
|
2375
2355
|
function getTypeManifestVisitor(input) {
|
|
@@ -2379,8 +2359,8 @@ function getTypeManifestVisitor(input) {
|
|
|
2379
2359
|
return (0, import_visitors_core28.pipe)(
|
|
2380
2360
|
(0, import_visitors_core28.staticVisitor)(() => typeManifest(), {
|
|
2381
2361
|
keys: [
|
|
2382
|
-
...
|
|
2383
|
-
...
|
|
2362
|
+
...import_nodes28.REGISTERED_TYPE_NODE_KINDS,
|
|
2363
|
+
...import_nodes28.REGISTERED_VALUE_NODE_KINDS,
|
|
2384
2364
|
"definedTypeLinkNode",
|
|
2385
2365
|
"definedTypeNode",
|
|
2386
2366
|
"accountNode",
|
|
@@ -2423,7 +2403,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2423
2403
|
visitBooleanType(booleanType, { self }) {
|
|
2424
2404
|
let sizeEncoder = fragment``;
|
|
2425
2405
|
let sizeDecoder = fragment``;
|
|
2426
|
-
const resolvedSize = (0,
|
|
2406
|
+
const resolvedSize = (0, import_nodes28.resolveNestedTypeNode)(booleanType.size);
|
|
2427
2407
|
if (resolvedSize.format !== "u8" || resolvedSize.endian !== "le") {
|
|
2428
2408
|
const size = (0, import_visitors_core28.visit)(booleanType.size, self);
|
|
2429
2409
|
sizeEncoder = fragment`{ size: ${size.encoder} }`;
|
|
@@ -2453,7 +2433,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2453
2433
|
return typeManifest({ value: fragment`new Uint8Array([${Array.from(bytes).join(", ")}])` });
|
|
2454
2434
|
},
|
|
2455
2435
|
visitConstantValue(node, { self }) {
|
|
2456
|
-
if ((0,
|
|
2436
|
+
if ((0, import_nodes28.isNode)(node.type, "bytesTypeNode") && (0, import_nodes28.isNode)(node.value, "bytesValueNode")) {
|
|
2457
2437
|
return (0, import_visitors_core28.visit)(node.value, self);
|
|
2458
2438
|
}
|
|
2459
2439
|
return typeManifest({
|
|
@@ -2486,7 +2466,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2486
2466
|
});
|
|
2487
2467
|
},
|
|
2488
2468
|
visitEnumEmptyVariantType(enumEmptyVariantType) {
|
|
2489
|
-
const discriminator = nameApi.discriminatedUnionDiscriminator((0,
|
|
2469
|
+
const discriminator = nameApi.discriminatedUnionDiscriminator((0, import_nodes28.camelCase)(parentName?.strict ?? ""));
|
|
2490
2470
|
const name = nameApi.discriminatedUnionVariant(enumEmptyVariantType.name);
|
|
2491
2471
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
2492
2472
|
return typeManifest({
|
|
@@ -2499,7 +2479,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2499
2479
|
visitEnumStructVariantType(enumStructVariantType, { self }) {
|
|
2500
2480
|
const currentParentName = parentName;
|
|
2501
2481
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2502
|
-
(0,
|
|
2482
|
+
(0, import_nodes28.camelCase)(currentParentName?.strict ?? "")
|
|
2503
2483
|
);
|
|
2504
2484
|
const name = nameApi.discriminatedUnionVariant(enumStructVariantType.name);
|
|
2505
2485
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
@@ -2523,12 +2503,12 @@ function getTypeManifestVisitor(input) {
|
|
|
2523
2503
|
visitEnumTupleVariantType(enumTupleVariantType, { self }) {
|
|
2524
2504
|
const currentParentName = parentName;
|
|
2525
2505
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2526
|
-
(0,
|
|
2506
|
+
(0, import_nodes28.camelCase)(currentParentName?.strict ?? "")
|
|
2527
2507
|
);
|
|
2528
2508
|
const name = nameApi.discriminatedUnionVariant(enumTupleVariantType.name);
|
|
2529
2509
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
2530
|
-
const struct = (0,
|
|
2531
|
-
(0,
|
|
2510
|
+
const struct = (0, import_nodes28.structTypeNode)([
|
|
2511
|
+
(0, import_nodes28.structFieldTypeNode)({
|
|
2532
2512
|
name: "fields",
|
|
2533
2513
|
type: enumTupleVariantType.tuple
|
|
2534
2514
|
})
|
|
@@ -2554,16 +2534,16 @@ function getTypeManifestVisitor(input) {
|
|
|
2554
2534
|
const currentParentName = parentName;
|
|
2555
2535
|
const encoderOptions = [];
|
|
2556
2536
|
const decoderOptions = [];
|
|
2557
|
-
const enumSize = (0,
|
|
2537
|
+
const enumSize = (0, import_nodes28.resolveNestedTypeNode)(enumType.size);
|
|
2558
2538
|
if (enumSize.format !== "u8" || enumSize.endian !== "le") {
|
|
2559
2539
|
const sizeManifest = (0, import_visitors_core28.visit)(enumType.size, self);
|
|
2560
2540
|
encoderOptions.push(fragment`size: ${sizeManifest.encoder}`);
|
|
2561
2541
|
decoderOptions.push(fragment`size: ${sizeManifest.decoder}`);
|
|
2562
2542
|
}
|
|
2563
2543
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2564
|
-
(0,
|
|
2544
|
+
(0, import_nodes28.camelCase)(currentParentName?.strict ?? "")
|
|
2565
2545
|
);
|
|
2566
|
-
if (!(0,
|
|
2546
|
+
if (!(0, import_nodes28.isScalarEnum)(enumType) && discriminator !== "__kind") {
|
|
2567
2547
|
encoderOptions.push(fragment`discriminator: '${discriminator}'`);
|
|
2568
2548
|
decoderOptions.push(fragment`discriminator: '${discriminator}'`);
|
|
2569
2549
|
}
|
|
@@ -2575,7 +2555,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2575
2555
|
decoderOptions,
|
|
2576
2556
|
(cs) => cs.length > 0 ? `, { ${cs.join(", ")} }` : ""
|
|
2577
2557
|
);
|
|
2578
|
-
if ((0,
|
|
2558
|
+
if ((0, import_nodes28.isScalarEnum)(enumType)) {
|
|
2579
2559
|
if (currentParentName === null) {
|
|
2580
2560
|
throw new Error(
|
|
2581
2561
|
"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."
|
|
@@ -2609,7 +2589,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2609
2589
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
2610
2590
|
const importFrom = getImportFrom(node.enum);
|
|
2611
2591
|
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
2612
|
-
const isScalar = enumNode && (0,
|
|
2592
|
+
const isScalar = enumNode && (0, import_nodes28.isNode)(enumNode, "enumTypeNode") ? (0, import_nodes28.isScalarEnum)(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
2613
2593
|
if (!node.value && isScalar) {
|
|
2614
2594
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
2615
2595
|
return typeManifest({
|
|
@@ -2690,7 +2670,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2690
2670
|
strict: nameApi.dataType(instructionDataName)
|
|
2691
2671
|
};
|
|
2692
2672
|
const link = customInstructionData.get(instruction.name)?.linkNode;
|
|
2693
|
-
const struct = (0,
|
|
2673
|
+
const struct = (0, import_nodes28.structTypeNodeFromInstructionArgumentNodes)(instruction.arguments);
|
|
2694
2674
|
const manifest = link ? (0, import_visitors_core28.visit)(link, self) : (0, import_visitors_core28.visit)(struct, self);
|
|
2695
2675
|
parentName = null;
|
|
2696
2676
|
return manifest;
|
|
@@ -2746,7 +2726,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2746
2726
|
const childManifest = (0, import_visitors_core28.visit)(optionType.item, self);
|
|
2747
2727
|
const encoderOptions = [];
|
|
2748
2728
|
const decoderOptions = [];
|
|
2749
|
-
const optionPrefix = (0,
|
|
2729
|
+
const optionPrefix = (0, import_nodes28.resolveNestedTypeNode)(optionType.prefix);
|
|
2750
2730
|
if (optionPrefix.format !== "u8" || optionPrefix.endian !== "le") {
|
|
2751
2731
|
const prefixManifest = (0, import_visitors_core28.visit)(optionType.prefix, self);
|
|
2752
2732
|
encoderOptions.push(fragment`prefix: ${prefixManifest.encoder}`);
|
|
@@ -2930,7 +2910,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2930
2910
|
});
|
|
2931
2911
|
},
|
|
2932
2912
|
visitStructFieldType(structFieldType, { self }) {
|
|
2933
|
-
const name = (0,
|
|
2913
|
+
const name = (0, import_nodes28.camelCase)(structFieldType.name);
|
|
2934
2914
|
const originalChildManifest = (0, import_visitors_core28.visit)(structFieldType.type, self);
|
|
2935
2915
|
let docs = getDocblockFragment(structFieldType.docs ?? [], true);
|
|
2936
2916
|
docs = docs ? fragment`\n${docs}` : docs;
|
|
@@ -2982,12 +2962,12 @@ function getTypeManifestVisitor(input) {
|
|
|
2982
2962
|
const accountNode = (0, import_visitors_core28.findLastNodeFromPath)(parentPath, "accountNode");
|
|
2983
2963
|
const discriminatorPrefix = instructionNode ? instructionNode.name : accountNode?.name;
|
|
2984
2964
|
const discriminators = (instructionNode ? instructionNode.discriminators : accountNode?.discriminators) ?? [];
|
|
2985
|
-
const fieldDiscriminators = discriminators.filter((0,
|
|
2965
|
+
const fieldDiscriminators = discriminators.filter((0, import_nodes28.isNodeFilter)("fieldDiscriminatorNode"));
|
|
2986
2966
|
const defaultValues = mergeFragments(
|
|
2987
2967
|
optionalFields.map((f) => {
|
|
2988
|
-
const key = (0,
|
|
2968
|
+
const key = (0, import_nodes28.camelCase)(f.name);
|
|
2989
2969
|
if (fieldDiscriminators.some((d) => d.name === f.name)) {
|
|
2990
|
-
const constantName = nameApi.constant((0,
|
|
2970
|
+
const constantName = nameApi.constant((0, import_nodes28.camelCase)(`${discriminatorPrefix}_${f.name}`));
|
|
2991
2971
|
return f.defaultValueStrategy === "omitted" ? fragment`${key}: ${constantName}` : fragment`${key}: value.${key} ?? ${constantName}`;
|
|
2992
2972
|
}
|
|
2993
2973
|
const defaultValue = f.defaultValue;
|
|
@@ -3058,19 +3038,19 @@ function getTypeManifestVisitor(input) {
|
|
|
3058
3038
|
);
|
|
3059
3039
|
}
|
|
3060
3040
|
function getArrayLikeSizeOption(count, visitor) {
|
|
3061
|
-
if ((0,
|
|
3041
|
+
if ((0, import_nodes28.isNode)(count, "fixedCountNode")) {
|
|
3062
3042
|
return {
|
|
3063
3043
|
decoder: fragment`size: ${count.value}`,
|
|
3064
3044
|
encoder: fragment`size: ${count.value}`
|
|
3065
3045
|
};
|
|
3066
3046
|
}
|
|
3067
|
-
if ((0,
|
|
3047
|
+
if ((0, import_nodes28.isNode)(count, "remainderCountNode")) {
|
|
3068
3048
|
return {
|
|
3069
3049
|
decoder: fragment`size: 'remainder'`,
|
|
3070
3050
|
encoder: fragment`size: 'remainder'`
|
|
3071
3051
|
};
|
|
3072
3052
|
}
|
|
3073
|
-
const prefix = (0,
|
|
3053
|
+
const prefix = (0, import_nodes28.resolveNestedTypeNode)(count.prefix);
|
|
3074
3054
|
if (prefix.format === "u32" && prefix.endian === "le") {
|
|
3075
3055
|
return { decoder: void 0, encoder: void 0 };
|
|
3076
3056
|
}
|
|
@@ -3088,20 +3068,20 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3088
3068
|
const customAccountData = parseCustomDataOptions(options.customAccountData ?? [], "AccountData");
|
|
3089
3069
|
const customInstructionData = parseCustomDataOptions(options.customInstructionData ?? [], "InstructionData");
|
|
3090
3070
|
const renderScopeWithTypeManifestVisitor = {
|
|
3091
|
-
asyncResolvers: (options.asyncResolvers ?? []).map(
|
|
3071
|
+
asyncResolvers: (options.asyncResolvers ?? []).map(import_nodes29.camelCase),
|
|
3092
3072
|
customAccountData,
|
|
3093
3073
|
customInstructionData,
|
|
3094
3074
|
dependencyMap: options.dependencyMap ?? {},
|
|
3095
3075
|
getImportFrom: getImportFromFactory(options.linkOverrides ?? {}, customAccountData, customInstructionData),
|
|
3096
3076
|
linkables,
|
|
3097
3077
|
nameApi: getNameApi({ ...DEFAULT_NAME_TRANSFORMERS, ...options.nameTransformers }),
|
|
3098
|
-
nonScalarEnums: (options.nonScalarEnums ?? []).map(
|
|
3078
|
+
nonScalarEnums: (options.nonScalarEnums ?? []).map(import_nodes29.camelCase),
|
|
3099
3079
|
renderParentInstructions: options.renderParentInstructions ?? false,
|
|
3100
3080
|
useGranularImports: options.useGranularImports ?? false
|
|
3101
3081
|
};
|
|
3102
3082
|
const typeManifestVisitor = getTypeManifestVisitor({ ...renderScopeWithTypeManifestVisitor, stack });
|
|
3103
3083
|
const renderScope = { ...renderScopeWithTypeManifestVisitor, typeManifestVisitor };
|
|
3104
|
-
const internalNodes = (options.internalNodes ?? []).map(
|
|
3084
|
+
const internalNodes = (options.internalNodes ?? []).map(import_nodes29.camelCase);
|
|
3105
3085
|
const resolvedInstructionInputVisitor = (0, import_visitors_core29.getResolvedInstructionInputsVisitor)();
|
|
3106
3086
|
const byteSizeVisitor = (0, import_visitors_core29.getByteSizeVisitor)(linkables, { stack });
|
|
3107
3087
|
const asPage = (fragment2, dependencyMap = {}) => {
|
|
@@ -3118,7 +3098,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3118
3098
|
(v) => (0, import_visitors_core29.extendVisitor)(v, {
|
|
3119
3099
|
visitAccount(node) {
|
|
3120
3100
|
return (0, import_renderers_core13.createRenderMap)(
|
|
3121
|
-
`accounts/${(0,
|
|
3101
|
+
`accounts/${(0, import_nodes29.camelCase)(node.name)}.ts`,
|
|
3122
3102
|
asPage(
|
|
3123
3103
|
getAccountPageFragment({
|
|
3124
3104
|
...renderScope,
|
|
@@ -3130,7 +3110,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3130
3110
|
},
|
|
3131
3111
|
visitDefinedType(node) {
|
|
3132
3112
|
return (0, import_renderers_core13.createRenderMap)(
|
|
3133
|
-
`types/${(0,
|
|
3113
|
+
`types/${(0, import_nodes29.camelCase)(node.name)}.ts`,
|
|
3134
3114
|
asPage(getTypePageFragment({ ...renderScope, node, size: (0, import_visitors_core29.visit)(node, byteSizeVisitor) }), {
|
|
3135
3115
|
generatedTypes: "."
|
|
3136
3116
|
})
|
|
@@ -3138,7 +3118,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3138
3118
|
},
|
|
3139
3119
|
visitInstruction(node) {
|
|
3140
3120
|
return (0, import_renderers_core13.createRenderMap)(
|
|
3141
|
-
`instructions/${(0,
|
|
3121
|
+
`instructions/${(0, import_nodes29.camelCase)(node.name)}.ts`,
|
|
3142
3122
|
asPage(
|
|
3143
3123
|
getInstructionPageFragment({
|
|
3144
3124
|
...renderScope,
|
|
@@ -3151,7 +3131,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3151
3131
|
},
|
|
3152
3132
|
visitPda(node) {
|
|
3153
3133
|
return (0, import_renderers_core13.createRenderMap)(
|
|
3154
|
-
`pdas/${(0,
|
|
3134
|
+
`pdas/${(0, import_nodes29.camelCase)(node.name)}.ts`,
|
|
3155
3135
|
asPage(getPdaPageFragment({ ...renderScope, pdaPath: stack.getPath("pdaNode") }))
|
|
3156
3136
|
);
|
|
3157
3137
|
},
|
|
@@ -3163,28 +3143,28 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3163
3143
|
const scope = { ...renderScope, programNode: node };
|
|
3164
3144
|
return (0, import_renderers_core13.mergeRenderMaps)([
|
|
3165
3145
|
(0, import_renderers_core13.createRenderMap)({
|
|
3166
|
-
[`programs/${(0,
|
|
3167
|
-
[`errors/${(0,
|
|
3146
|
+
[`programs/${(0, import_nodes29.camelCase)(node.name)}.ts`]: asPage(getProgramPageFragment(scope)),
|
|
3147
|
+
[`errors/${(0, import_nodes29.camelCase)(node.name)}.ts`]: node.errors.length > 0 ? asPage(getErrorPageFragment(scope)) : void 0
|
|
3168
3148
|
}),
|
|
3169
3149
|
...node.pdas.map((p) => (0, import_visitors_core29.visit)(p, self)),
|
|
3170
3150
|
...node.accounts.map((a) => (0, import_visitors_core29.visit)(a, self)),
|
|
3171
3151
|
...node.definedTypes.map((t) => (0, import_visitors_core29.visit)(t, self)),
|
|
3172
3152
|
...customDataDefinedType.map((t) => (0, import_visitors_core29.visit)(t, self)),
|
|
3173
|
-
...(0,
|
|
3153
|
+
...(0, import_nodes29.getAllInstructionsWithSubs)(node, { leavesOnly: !renderScope.renderParentInstructions }).map(
|
|
3174
3154
|
(i) => (0, import_visitors_core29.visit)(i, self)
|
|
3175
3155
|
)
|
|
3176
3156
|
]);
|
|
3177
3157
|
},
|
|
3178
3158
|
visitRoot(node, { self }) {
|
|
3179
3159
|
const isNotInternal = (n) => !internalNodes.includes(n.name);
|
|
3180
|
-
const programsToExport = (0,
|
|
3160
|
+
const programsToExport = (0, import_nodes29.getAllPrograms)(node).filter(isNotInternal);
|
|
3181
3161
|
const programsWithErrorsToExport = programsToExport.filter((p) => p.errors.length > 0);
|
|
3182
|
-
const pdasToExport = (0,
|
|
3183
|
-
const accountsToExport = (0,
|
|
3184
|
-
const instructionsToExport = (0,
|
|
3162
|
+
const pdasToExport = (0, import_nodes29.getAllPdas)(node);
|
|
3163
|
+
const accountsToExport = (0, import_nodes29.getAllAccounts)(node).filter(isNotInternal);
|
|
3164
|
+
const instructionsToExport = (0, import_nodes29.getAllInstructionsWithSubs)(node, {
|
|
3185
3165
|
leavesOnly: !renderScope.renderParentInstructions
|
|
3186
3166
|
}).filter(isNotInternal);
|
|
3187
|
-
const definedTypesToExport = (0,
|
|
3167
|
+
const definedTypesToExport = (0, import_nodes29.getAllDefinedTypes)(node).filter(isNotInternal);
|
|
3188
3168
|
const hasAnythingToExport = programsToExport.length > 0 || accountsToExport.length > 0 || instructionsToExport.length > 0 || definedTypesToExport.length > 0;
|
|
3189
3169
|
const scope = {
|
|
3190
3170
|
...renderScope,
|
|
@@ -3205,7 +3185,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3205
3185
|
["shared/index.ts"]: hasAnythingToExport ? asPage(getSharedPageFragment()) : void 0,
|
|
3206
3186
|
["types/index.ts"]: asPage(getIndexPageFragment(definedTypesToExport))
|
|
3207
3187
|
}),
|
|
3208
|
-
...(0,
|
|
3188
|
+
...(0, import_nodes29.getAllPrograms)(node).map((p) => (0, import_visitors_core29.visit)(p, self))
|
|
3209
3189
|
]);
|
|
3210
3190
|
}
|
|
3211
3191
|
}),
|