@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.mjs
CHANGED
|
@@ -266,7 +266,7 @@ function mergeTypeManifests(manifests, options = {}) {
|
|
|
266
266
|
|
|
267
267
|
// src/visitors/getRenderMapVisitor.ts
|
|
268
268
|
import {
|
|
269
|
-
camelCase as
|
|
269
|
+
camelCase as camelCase15,
|
|
270
270
|
getAllAccounts,
|
|
271
271
|
getAllDefinedTypes,
|
|
272
272
|
getAllInstructionsWithSubs as getAllInstructionsWithSubs2,
|
|
@@ -697,11 +697,15 @@ function getAccountTypeFragment(scope) {
|
|
|
697
697
|
const accountNode = getLastNodeFromPath4(accountPath);
|
|
698
698
|
if (customAccountData.has(accountNode.name)) return;
|
|
699
699
|
return getTypeWithCodecFragment({
|
|
700
|
+
codecDocs: [`Gets the codec for {@link ${nameApi.dataType(accountNode.name)}} account data.`],
|
|
701
|
+
decoderDocs: [`Gets the decoder for {@link ${nameApi.dataType(accountNode.name)}} account data.`],
|
|
702
|
+
encoderDocs: [`Gets the encoder for {@link ${nameApi.dataArgsType(accountNode.name)}} account data.`],
|
|
700
703
|
manifest: typeManifest2,
|
|
701
704
|
name: accountNode.name,
|
|
702
705
|
nameApi,
|
|
703
706
|
node: resolveNestedTypeNode(accountNode.data),
|
|
704
|
-
size: scope.size
|
|
707
|
+
size: scope.size,
|
|
708
|
+
typeDocs: accountNode.docs
|
|
705
709
|
});
|
|
706
710
|
}
|
|
707
711
|
|
|
@@ -918,9 +922,10 @@ function getIsErrorFunctionFragment(scope) {
|
|
|
918
922
|
}
|
|
919
923
|
|
|
920
924
|
// src/fragments/indexPage.ts
|
|
925
|
+
import { camelCase as camelCase4 } from "@codama/nodes";
|
|
921
926
|
function getIndexPageFragment(items) {
|
|
922
927
|
if (items.length === 0) return;
|
|
923
|
-
const names = items.map((item) => item.name).sort((a, b) => a.localeCompare(b)).map((name) => getExportAllFragment(`./${name}`));
|
|
928
|
+
const names = items.map((item) => camelCase4(item.name)).sort((a, b) => a.localeCompare(b)).map((name) => getExportAllFragment(`./${name}`));
|
|
924
929
|
return mergeFragments(names, (cs) => cs.join("\n"));
|
|
925
930
|
}
|
|
926
931
|
|
|
@@ -975,7 +980,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
975
980
|
}
|
|
976
981
|
|
|
977
982
|
// src/fragments/instructionByteDelta.ts
|
|
978
|
-
import { assertIsNode, camelCase as
|
|
983
|
+
import { assertIsNode, camelCase as camelCase5, isNode as isNode7 } from "@codama/nodes";
|
|
979
984
|
import { mapFragmentContent as mapFragmentContent2 } from "@codama/renderers-core";
|
|
980
985
|
import { getLastNodeFromPath as getLastNodeFromPath7, pipe as pipe4 } from "@codama/visitors-core";
|
|
981
986
|
function getInstructionByteDeltaFragment(scope) {
|
|
@@ -1019,7 +1024,7 @@ function getNumberValueNodeFragment(byteDelta) {
|
|
|
1019
1024
|
}
|
|
1020
1025
|
function getArgumentValueNodeFragment(byteDelta) {
|
|
1021
1026
|
assertIsNode(byteDelta.value, "argumentValueNode");
|
|
1022
|
-
const argumentName =
|
|
1027
|
+
const argumentName = camelCase5(byteDelta.value.name);
|
|
1023
1028
|
return fragment`Number(args.${argumentName})`;
|
|
1024
1029
|
}
|
|
1025
1030
|
function getAccountLinkNodeFragment(byteDelta, scope) {
|
|
@@ -1075,7 +1080,7 @@ function getInstructionExtraArgsFragment(scope) {
|
|
|
1075
1080
|
}
|
|
1076
1081
|
|
|
1077
1082
|
// src/fragments/instructionFunction.ts
|
|
1078
|
-
import { camelCase as
|
|
1083
|
+
import { camelCase as camelCase10, isNode as isNode12, isNodeFilter as isNodeFilter4, pascalCase as pascalCase5 } from "@codama/nodes";
|
|
1079
1084
|
import { mapFragmentContent as mapFragmentContent7 } from "@codama/renderers-core";
|
|
1080
1085
|
import {
|
|
1081
1086
|
findProgramNodeFromPath as findProgramNodeFromPath3,
|
|
@@ -1084,12 +1089,12 @@ import {
|
|
|
1084
1089
|
} from "@codama/visitors-core";
|
|
1085
1090
|
|
|
1086
1091
|
// src/fragments/instructionInputResolved.ts
|
|
1087
|
-
import { camelCase as
|
|
1092
|
+
import { camelCase as camelCase7, isNode as isNode9, parseOptionalAccountStrategy } from "@codama/nodes";
|
|
1088
1093
|
import { mapFragmentContent as mapFragmentContent5 } from "@codama/renderers-core";
|
|
1089
1094
|
import { getLastNodeFromPath as getLastNodeFromPath10 } from "@codama/visitors-core";
|
|
1090
1095
|
|
|
1091
1096
|
// src/fragments/instructionInputDefault.ts
|
|
1092
|
-
import { camelCase as
|
|
1097
|
+
import { camelCase as camelCase6, isNode as isNode8 } from "@codama/nodes";
|
|
1093
1098
|
import { mapFragmentContent as mapFragmentContent4, setFragmentContent } from "@codama/renderers-core";
|
|
1094
1099
|
import { pipe as pipe5, visit as visit4 } from "@codama/visitors-core";
|
|
1095
1100
|
function getInstructionInputDefaultFragment(scope) {
|
|
@@ -1102,7 +1107,7 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1102
1107
|
}
|
|
1103
1108
|
const { defaultValue } = input;
|
|
1104
1109
|
const defaultFragment = (renderedValue, isWritable) => {
|
|
1105
|
-
const inputName =
|
|
1110
|
+
const inputName = camelCase6(input.name);
|
|
1106
1111
|
if (input.kind === "instructionAccountNode" && isNode8(defaultValue, "resolverValueNode")) {
|
|
1107
1112
|
return fragment`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`;
|
|
1108
1113
|
}
|
|
@@ -1114,39 +1119,39 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1114
1119
|
}
|
|
1115
1120
|
return fragment`args.${inputName} = ${renderedValue};`;
|
|
1116
1121
|
};
|
|
1122
|
+
const expectTransactionSigner = use("expectTransactionSigner", "shared");
|
|
1123
|
+
const expectSome = use("expectSome", "shared");
|
|
1124
|
+
const expectAddress = use("expectAddress", "shared");
|
|
1125
|
+
const expectProgramDerivedAddress = use("expectProgramDerivedAddress", "shared");
|
|
1126
|
+
const addressType = use("type Address", "solanaAddresses");
|
|
1117
1127
|
switch (defaultValue.kind) {
|
|
1118
1128
|
case "accountValueNode":
|
|
1119
|
-
const name =
|
|
1129
|
+
const name = camelCase6(defaultValue.name);
|
|
1120
1130
|
if (input.kind === "instructionAccountNode" && input.resolvedIsSigner && !input.isSigner) {
|
|
1121
|
-
return
|
|
1122
|
-
defaultFragment(`expectTransactionSigner(accounts.${name}.value).address`),
|
|
1123
|
-
(f) => addFragmentImports(f, "shared", ["expectTransactionSigner"])
|
|
1124
|
-
);
|
|
1131
|
+
return defaultFragment(fragment`${expectTransactionSigner}(accounts.${name}.value).address`);
|
|
1125
1132
|
}
|
|
1126
1133
|
if (input.kind === "instructionAccountNode") {
|
|
1127
|
-
return
|
|
1128
|
-
defaultFragment(`expectSome(accounts.${name}.value)`),
|
|
1129
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1130
|
-
);
|
|
1134
|
+
return defaultFragment(fragment`${expectSome}(accounts.${name}.value)`);
|
|
1131
1135
|
}
|
|
1132
|
-
return
|
|
1133
|
-
defaultFragment(`expectAddress(accounts.${name}.value)`),
|
|
1134
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1135
|
-
);
|
|
1136
|
+
return defaultFragment(fragment`${expectAddress}(accounts.${name}.value)`);
|
|
1136
1137
|
case "pdaValueNode":
|
|
1138
|
+
let pdaProgramValue;
|
|
1139
|
+
if (isNode8(defaultValue.programId, "accountValueNode")) {
|
|
1140
|
+
pdaProgramValue = fragment`${expectAddress}(accounts.${camelCase6(defaultValue.programId.name)}.value)`;
|
|
1141
|
+
}
|
|
1142
|
+
if (isNode8(defaultValue.programId, "argumentValueNode")) {
|
|
1143
|
+
pdaProgramValue = fragment`${expectAddress}(args.${camelCase6(defaultValue.programId.name)})`;
|
|
1144
|
+
}
|
|
1137
1145
|
if (isNode8(defaultValue.pda, "pdaNode")) {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
)
|
|
1146
|
+
let pdaProgram = fragment`programAddress`;
|
|
1147
|
+
if (pdaProgramValue) {
|
|
1148
|
+
pdaProgram = pdaProgramValue;
|
|
1149
|
+
} else if (defaultValue.pda.programId) {
|
|
1150
|
+
pdaProgram = fragment`'${defaultValue.pda.programId}' as ${addressType}<'${defaultValue.pda.programId}'>`;
|
|
1151
|
+
}
|
|
1142
1152
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
1143
1153
|
if (isNode8(seed, "constantPdaSeedNode") && isNode8(seed.value, "programIdValueNode")) {
|
|
1144
|
-
return [
|
|
1145
|
-
pipe5(
|
|
1146
|
-
fragment`getAddressEncoder().encode(${pdaProgram})`,
|
|
1147
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["getAddressEncoder"])
|
|
1148
|
-
)
|
|
1149
|
-
];
|
|
1154
|
+
return [fragment`${use("getAddressEncoder", "solanaAddresses")}().encode(${pdaProgram})`];
|
|
1150
1155
|
}
|
|
1151
1156
|
if (isNode8(seed, "constantPdaSeedNode") && !isNode8(seed.value, "programIdValueNode")) {
|
|
1152
1157
|
const typeManifest2 = visit4(seed.type, typeManifestVisitor);
|
|
@@ -1159,18 +1164,12 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1159
1164
|
if (!valueSeed) return [];
|
|
1160
1165
|
if (isNode8(valueSeed, "accountValueNode")) {
|
|
1161
1166
|
return [
|
|
1162
|
-
|
|
1163
|
-
fragment`${typeManifest2.encoder}.encode(expectAddress(accounts.${camelCase5(valueSeed.name)}.value))`,
|
|
1164
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1165
|
-
)
|
|
1167
|
+
fragment`${typeManifest2.encoder}.encode(${expectAddress}(accounts.${camelCase6(valueSeed.name)}.value))`
|
|
1166
1168
|
];
|
|
1167
1169
|
}
|
|
1168
1170
|
if (isNode8(valueSeed, "argumentValueNode")) {
|
|
1169
1171
|
return [
|
|
1170
|
-
|
|
1171
|
-
fragment`${typeManifest2.encoder}.encode(expectSome(args.${camelCase5(valueSeed.name)}))`,
|
|
1172
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1173
|
-
)
|
|
1172
|
+
fragment`${typeManifest2.encoder}.encode(${expectSome}(args.${camelCase6(valueSeed.name)}))`
|
|
1174
1173
|
];
|
|
1175
1174
|
}
|
|
1176
1175
|
const valueManifest2 = visit4(valueSeed, typeManifestVisitor);
|
|
@@ -1178,29 +1177,21 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1178
1177
|
}
|
|
1179
1178
|
return [];
|
|
1180
1179
|
});
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
})
|
|
1186
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["getProgramDerivedAddress"]),
|
|
1187
|
-
(f) => mapFragmentContent4(f, (c) => defaultFragment(c).content)
|
|
1180
|
+
const getProgramDerivedAddress = use("getProgramDerivedAddress", "solanaAddresses");
|
|
1181
|
+
const programAddress2 = pdaProgram.content === "programAddress" ? pdaProgram : fragment`programAddress: ${pdaProgram}`;
|
|
1182
|
+
const seeds = mergeFragments(pdaSeeds2, (s) => s.join(", "));
|
|
1183
|
+
return defaultFragment(
|
|
1184
|
+
fragment`await ${getProgramDerivedAddress}({ ${programAddress2}, seeds: [${seeds}] })`
|
|
1188
1185
|
);
|
|
1189
1186
|
}
|
|
1190
|
-
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
1187
|
+
const pdaFunction = use(nameApi.pdaFindFunction(defaultValue.pda.name), getImportFrom(defaultValue.pda));
|
|
1191
1188
|
const pdaArgs = [];
|
|
1192
1189
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
1193
1190
|
if (isNode8(seed.value, "accountValueNode")) {
|
|
1194
|
-
return
|
|
1195
|
-
fragment`${seed.name}: expectAddress(accounts.${camelCase5(seed.value.name)}.value)`,
|
|
1196
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1197
|
-
);
|
|
1191
|
+
return fragment`${seed.name}: ${expectAddress}(accounts.${camelCase6(seed.value.name)}.value)`;
|
|
1198
1192
|
}
|
|
1199
1193
|
if (isNode8(seed.value, "argumentValueNode")) {
|
|
1200
|
-
return
|
|
1201
|
-
fragment`${seed.name}: expectSome(args.${camelCase5(seed.value.name)})`,
|
|
1202
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1203
|
-
);
|
|
1194
|
+
return fragment`${seed.name}: ${expectSome}(args.${camelCase6(seed.value.name)})`;
|
|
1204
1195
|
}
|
|
1205
1196
|
return pipe5(
|
|
1206
1197
|
visit4(seed.value, typeManifestVisitor).value,
|
|
@@ -1212,49 +1203,38 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1212
1203
|
(f) => mapFragmentContent4(f, (c) => `{ ${c} }`)
|
|
1213
1204
|
);
|
|
1214
1205
|
if (pdaSeeds.length > 0) {
|
|
1215
|
-
pdaArgs.push(pdaSeedsFragment
|
|
1206
|
+
pdaArgs.push(pdaSeedsFragment);
|
|
1216
1207
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
(f) => addFragmentImports(f, module, [pdaFunction])
|
|
1222
|
-
);
|
|
1208
|
+
if (pdaProgramValue) {
|
|
1209
|
+
pdaArgs.push(fragment`{ programAddress: ${pdaProgramValue} }`);
|
|
1210
|
+
}
|
|
1211
|
+
return defaultFragment(fragment`await ${pdaFunction}(${mergeFragments(pdaArgs, (c) => c.join(", "))})`);
|
|
1223
1212
|
case "publicKeyValueNode":
|
|
1224
|
-
return
|
|
1225
|
-
|
|
1226
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["type Address"])
|
|
1213
|
+
return defaultFragment(
|
|
1214
|
+
fragment`'${defaultValue.publicKey}' as ${addressType}<'${defaultValue.publicKey}'>`
|
|
1227
1215
|
);
|
|
1228
1216
|
case "programLinkNode":
|
|
1229
|
-
const programAddress = nameApi.programAddressConstant(defaultValue.name);
|
|
1230
|
-
return
|
|
1231
|
-
defaultFragment(programAddress, false),
|
|
1232
|
-
(f) => addFragmentImports(f, getImportFrom(defaultValue), [programAddress])
|
|
1233
|
-
);
|
|
1217
|
+
const programAddress = use(nameApi.programAddressConstant(defaultValue.name), getImportFrom(defaultValue));
|
|
1218
|
+
return defaultFragment(programAddress, false);
|
|
1234
1219
|
case "programIdValueNode":
|
|
1235
1220
|
if (optionalAccountStrategy === "programId" && input.kind === "instructionAccountNode" && input.isOptional) {
|
|
1236
1221
|
return fragment``;
|
|
1237
1222
|
}
|
|
1238
|
-
return defaultFragment(
|
|
1223
|
+
return defaultFragment(fragment`programAddress`, false);
|
|
1239
1224
|
case "identityValueNode":
|
|
1240
1225
|
case "payerValueNode":
|
|
1241
1226
|
return fragment``;
|
|
1242
1227
|
case "accountBumpValueNode":
|
|
1243
|
-
return
|
|
1244
|
-
|
|
1245
|
-
(f) => addFragmentImports(f, "shared", ["expectProgramDerivedAddress"])
|
|
1228
|
+
return defaultFragment(
|
|
1229
|
+
fragment`${expectProgramDerivedAddress}(accounts.${camelCase6(defaultValue.name)}.value)[1]`
|
|
1246
1230
|
);
|
|
1247
1231
|
case "argumentValueNode":
|
|
1248
|
-
return
|
|
1249
|
-
defaultFragment(`expectSome(args.${camelCase5(defaultValue.name)})`),
|
|
1250
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1251
|
-
);
|
|
1232
|
+
return defaultFragment(fragment`${expectSome}(args.${camelCase6(defaultValue.name)})`);
|
|
1252
1233
|
case "resolverValueNode":
|
|
1253
|
-
const resolverFunction = nameApi.resolverFunction(defaultValue.name);
|
|
1234
|
+
const resolverFunction = use(nameApi.resolverFunction(defaultValue.name), getImportFrom(defaultValue));
|
|
1254
1235
|
const resolverAwait = useAsync && asyncResolvers.includes(defaultValue.name) ? "await " : "";
|
|
1255
1236
|
return pipe5(
|
|
1256
|
-
defaultFragment(`${resolverAwait}${resolverFunction}(resolverScope)`),
|
|
1257
|
-
(f) => addFragmentImports(f, getImportFrom(defaultValue), [resolverFunction]),
|
|
1237
|
+
defaultFragment(fragment`${resolverAwait}${resolverFunction}(resolverScope)`),
|
|
1258
1238
|
(f) => addFragmentFeatures(f, ["instruction:resolverScopeVariable"])
|
|
1259
1239
|
);
|
|
1260
1240
|
case "conditionalValueNode":
|
|
@@ -1280,17 +1260,17 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1280
1260
|
let condition = "true";
|
|
1281
1261
|
if (isNode8(defaultValue.condition, "resolverValueNode")) {
|
|
1282
1262
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
1283
|
-
const
|
|
1263
|
+
const module = getImportFrom(defaultValue.condition);
|
|
1284
1264
|
conditionalFragment = pipe5(
|
|
1285
1265
|
conditionalFragment,
|
|
1286
|
-
(f) => addFragmentImports(f,
|
|
1266
|
+
(f) => addFragmentImports(f, module, [conditionalResolverFunction]),
|
|
1287
1267
|
(f) => addFragmentFeatures(f, ["instruction:resolverScopeVariable"])
|
|
1288
1268
|
);
|
|
1289
1269
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
1290
1270
|
condition = `${conditionalResolverAwait}${conditionalResolverFunction}(resolverScope)`;
|
|
1291
1271
|
condition = negatedCondition ? `!${condition}` : condition;
|
|
1292
1272
|
} else {
|
|
1293
|
-
const comparedInputName = isNode8(defaultValue.condition, "accountValueNode") ? `accounts.${
|
|
1273
|
+
const comparedInputName = isNode8(defaultValue.condition, "accountValueNode") ? `accounts.${camelCase6(defaultValue.condition.name)}.value` : `args.${camelCase6(defaultValue.condition.name)}`;
|
|
1294
1274
|
if (defaultValue.value) {
|
|
1295
1275
|
const comparedValue = visit4(defaultValue.value, typeManifestVisitor).value;
|
|
1296
1276
|
conditionalFragment = mergeFragments([conditionalFragment, comparedValue], (c) => c[0]);
|
|
@@ -1318,7 +1298,7 @@ ${ifTrueRenderer ? ifTrueRenderer.content : ifFalseRenderer?.content}
|
|
|
1318
1298
|
);
|
|
1319
1299
|
default:
|
|
1320
1300
|
const valueManifest = visit4(defaultValue, typeManifestVisitor).value;
|
|
1321
|
-
return
|
|
1301
|
+
return defaultFragment(valueManifest);
|
|
1322
1302
|
}
|
|
1323
1303
|
}
|
|
1324
1304
|
function renderNestedInstructionDefault(scope) {
|
|
@@ -1340,7 +1320,7 @@ function getInstructionInputResolvedFragment(scope) {
|
|
|
1340
1320
|
optionalAccountStrategy: parseOptionalAccountStrategy(instructionNode.optionalAccountStrategy)
|
|
1341
1321
|
});
|
|
1342
1322
|
if (!inputFragment.content) return [];
|
|
1343
|
-
const camelName =
|
|
1323
|
+
const camelName = camelCase7(input.name);
|
|
1344
1324
|
return [
|
|
1345
1325
|
mapFragmentContent5(
|
|
1346
1326
|
inputFragment,
|
|
@@ -1360,7 +1340,7 @@ ${c}
|
|
|
1360
1340
|
|
|
1361
1341
|
// src/fragments/instructionInputType.ts
|
|
1362
1342
|
import {
|
|
1363
|
-
camelCase as
|
|
1343
|
+
camelCase as camelCase8,
|
|
1364
1344
|
getAllInstructionArguments,
|
|
1365
1345
|
isNode as isNode10,
|
|
1366
1346
|
pascalCase as pascalCase4
|
|
@@ -1403,7 +1383,7 @@ function getAccountsFragment(scope) {
|
|
|
1403
1383
|
const hasDefaultValue = !!resolvedAccount.defaultValue && !isNode10(resolvedAccount.defaultValue, ["identityValueNode", "payerValueNode"]) && (useAsync || !isAsyncDefaultValue(resolvedAccount.defaultValue, asyncResolvers));
|
|
1404
1384
|
const docs = getDocblockFragment(account.docs ?? [], true);
|
|
1405
1385
|
const optionalSign = hasDefaultValue || resolvedAccount.isOptional ? "?" : "";
|
|
1406
|
-
return fragment`${docs}${
|
|
1386
|
+
return fragment`${docs}${camelCase8(account.name)}${optionalSign}: ${getAccountTypeFragment2(resolvedAccount)};`;
|
|
1407
1387
|
});
|
|
1408
1388
|
return mergeFragments(fragments, (c) => c.join("\n"));
|
|
1409
1389
|
}
|
|
@@ -1459,7 +1439,7 @@ function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
|
1459
1439
|
if (arg.defaultValue && arg.defaultValueStrategy === "omitted") return null;
|
|
1460
1440
|
const renamedName = renamedArgs.get(arg.name) ?? arg.name;
|
|
1461
1441
|
const optionalSign = arg.defaultValue || resolvedArg?.defaultValue ? "?" : "";
|
|
1462
|
-
return fragment`${
|
|
1442
|
+
return fragment`${camelCase8(renamedName)}${optionalSign}: ${argsType}["${camelCase8(arg.name)}"];`;
|
|
1463
1443
|
}
|
|
1464
1444
|
function getRemainingAccountsFragment(instructionNode) {
|
|
1465
1445
|
const fragments = (instructionNode.remainingAccounts ?? []).flatMap((remainingAccountsNode) => {
|
|
@@ -1476,7 +1456,7 @@ function getRemainingAccountsFragment(instructionNode) {
|
|
|
1476
1456
|
if (isSigner === "either") return fragment`${signerFragment} | ${addressFragment}`;
|
|
1477
1457
|
return isSigner ? signerFragment : addressFragment;
|
|
1478
1458
|
})();
|
|
1479
|
-
return fragment`${
|
|
1459
|
+
return fragment`${camelCase8(name)}${optionalSign}: Array<${typeFragment}>;`;
|
|
1480
1460
|
});
|
|
1481
1461
|
if (fragments.length === 0) return;
|
|
1482
1462
|
return mergeFragments(fragments, (c) => c.join("\n"));
|
|
@@ -1485,7 +1465,7 @@ function getRemainingAccountsFragment(instructionNode) {
|
|
|
1485
1465
|
// src/fragments/instructionRemainingAccounts.ts
|
|
1486
1466
|
import {
|
|
1487
1467
|
assertIsNode as assertIsNode2,
|
|
1488
|
-
camelCase as
|
|
1468
|
+
camelCase as camelCase9,
|
|
1489
1469
|
getAllInstructionArguments as getAllInstructionArguments2,
|
|
1490
1470
|
isNode as isNode11
|
|
1491
1471
|
} from "@codama/nodes";
|
|
@@ -1519,7 +1499,7 @@ function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
|
1519
1499
|
function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
1520
1500
|
const instructionNode = getLastNodeFromPath12(scope.instructionPath);
|
|
1521
1501
|
assertIsNode2(remainingAccounts.value, "argumentValueNode");
|
|
1522
|
-
const argumentName =
|
|
1502
|
+
const argumentName = camelCase9(remainingAccounts.value.name);
|
|
1523
1503
|
const isOptional = remainingAccounts.isOptional ?? false;
|
|
1524
1504
|
const isSigner = remainingAccounts.isSigner ?? false;
|
|
1525
1505
|
const isWritable = remainingAccounts.isWritable ?? false;
|
|
@@ -1626,7 +1606,7 @@ function getAccountsInitializationFragment(instructionNode) {
|
|
|
1626
1606
|
if (instructionNode.accounts.length === 0) return;
|
|
1627
1607
|
const accounts = mergeFragments(
|
|
1628
1608
|
instructionNode.accounts.map((account) => {
|
|
1629
|
-
const name =
|
|
1609
|
+
const name = camelCase10(account.name);
|
|
1630
1610
|
const isWritable = account.isWritable ? "true" : "false";
|
|
1631
1611
|
return fragment`${name}: { value: input.${name} ?? null, isWritable: ${isWritable} }`;
|
|
1632
1612
|
}),
|
|
@@ -1661,7 +1641,7 @@ function getReturnStatementFragment(scope) {
|
|
|
1661
1641
|
const hasLegacyOptionalAccounts = instructionNode.optionalAccountStrategy === "omitted" && instructionNode.accounts.some((account) => account.isOptional);
|
|
1662
1642
|
const getAccountMeta = hasAccounts ? fragment`const getAccountMeta = ${use("getAccountMetaFactory", "shared")}(programAddress, '${optionalAccountStrategy}');` : "";
|
|
1663
1643
|
const accountItems = [
|
|
1664
|
-
...instructionNode.accounts.map((account) => `getAccountMeta(accounts.${
|
|
1644
|
+
...instructionNode.accounts.map((account) => `getAccountMeta(accounts.${camelCase10(account.name)})`),
|
|
1665
1645
|
...hasRemainingAccounts ? ["...remainingAccounts"] : []
|
|
1666
1646
|
].join(", ");
|
|
1667
1647
|
let accounts;
|
|
@@ -1710,7 +1690,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1710
1690
|
const instructionTypeName = nameApi.instructionType(instructionNode.name);
|
|
1711
1691
|
const accountTypeParamsFragments = instructionNode.accounts.map((account) => {
|
|
1712
1692
|
const typeParam = fragment`TAccount${pascalCase5(account.name)}`;
|
|
1713
|
-
const camelName =
|
|
1693
|
+
const camelName = camelCase10(account.name);
|
|
1714
1694
|
if (account.isSigner === "either") {
|
|
1715
1695
|
const signerRole = use(
|
|
1716
1696
|
account.isWritable ? "type WritableSignerAccount" : "type ReadonlySignerAccount",
|
|
@@ -1739,7 +1719,7 @@ function getInputTypeCallFragment(scope) {
|
|
|
1739
1719
|
|
|
1740
1720
|
// src/fragments/instructionPage.ts
|
|
1741
1721
|
import { logWarn } from "@codama/errors";
|
|
1742
|
-
import { camelCase as
|
|
1722
|
+
import { camelCase as camelCase12, definedTypeNode as definedTypeNode2, structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes3 } from "@codama/nodes";
|
|
1743
1723
|
import {
|
|
1744
1724
|
findProgramNodeFromPath as findProgramNodeFromPath6,
|
|
1745
1725
|
getLastNodeFromPath as getLastNodeFromPath16,
|
|
@@ -1747,7 +1727,7 @@ import {
|
|
|
1747
1727
|
} from "@codama/visitors-core";
|
|
1748
1728
|
|
|
1749
1729
|
// src/fragments/instructionParseFunction.ts
|
|
1750
|
-
import { camelCase as
|
|
1730
|
+
import { camelCase as camelCase11 } from "@codama/nodes";
|
|
1751
1731
|
import { findProgramNodeFromPath as findProgramNodeFromPath4, getLastNodeFromPath as getLastNodeFromPath14, pipe as pipe9 } from "@codama/visitors-core";
|
|
1752
1732
|
function getInstructionParseFunctionFragment(scope) {
|
|
1753
1733
|
const instructionNode = getLastNodeFromPath14(scope.instructionPath);
|
|
@@ -1772,7 +1752,7 @@ function getTypeFragment2(scope) {
|
|
|
1772
1752
|
const accounts = mergeFragments(
|
|
1773
1753
|
scope.instructionNode.accounts.map((account, i) => {
|
|
1774
1754
|
const docs = getDocblockFragment(account.docs ?? [], true);
|
|
1775
|
-
const name =
|
|
1755
|
+
const name = camelCase11(account.name);
|
|
1776
1756
|
return fragment`${docs}${name}${account.isOptional ? "?" : ""}: TAccountMetas[${i}]${account.isOptional ? " | undefined" : ""};`;
|
|
1777
1757
|
}),
|
|
1778
1758
|
(cs) => hasAccounts ? `
|
|
@@ -1844,7 +1824,7 @@ const getNextOptionalAccount = () => {
|
|
|
1844
1824
|
}
|
|
1845
1825
|
const accounts = mergeFragments(
|
|
1846
1826
|
scope.instructionNode.accounts.map(
|
|
1847
|
-
(account) => account.isOptional ? fragment`${
|
|
1827
|
+
(account) => account.isOptional ? fragment`${camelCase11(account.name)}: getNextOptionalAccount()` : fragment`${camelCase11(account.name)}: getNextAccount()`
|
|
1848
1828
|
),
|
|
1849
1829
|
(cs) => hasAccounts ? `, accounts: { ${cs.join(", ")} }` : ""
|
|
1850
1830
|
);
|
|
@@ -1949,11 +1929,11 @@ function getRenamedArgsMap(instruction) {
|
|
|
1949
1929
|
logWarn(
|
|
1950
1930
|
`[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.`
|
|
1951
1931
|
);
|
|
1952
|
-
return new Map(duplicates.map((name) => [
|
|
1932
|
+
return new Map(duplicates.map((name) => [camelCase12(name), camelCase12(`${name}Arg`)]));
|
|
1953
1933
|
}
|
|
1954
1934
|
|
|
1955
1935
|
// src/fragments/pdaFunction.ts
|
|
1956
|
-
import { camelCase as
|
|
1936
|
+
import { camelCase as camelCase13, isNode as isNode13, isNodeFilter as isNodeFilter5 } from "@codama/nodes";
|
|
1957
1937
|
import { findProgramNodeFromPath as findProgramNodeFromPath7, getLastNodeFromPath as getLastNodeFromPath17, visit as visit6 } from "@codama/visitors-core";
|
|
1958
1938
|
function getPdaFunctionFragment(scope) {
|
|
1959
1939
|
const pdaNode = getLastNodeFromPath17(scope.pdaPath);
|
|
@@ -1998,7 +1978,7 @@ function getFunctionFragment2(seeds, scope) {
|
|
|
1998
1978
|
function parsePdaSeedNodes(seeds, scope) {
|
|
1999
1979
|
return seeds.map((seed) => {
|
|
2000
1980
|
if (isNode13(seed, "variablePdaSeedNode")) {
|
|
2001
|
-
const name =
|
|
1981
|
+
const name = camelCase13(seed.name);
|
|
2002
1982
|
const docs = getDocblockFragment(seed.docs ?? [], true);
|
|
2003
1983
|
const { encoder: encoder2, looseType } = visit6(seed.type, scope.typeManifestVisitor);
|
|
2004
1984
|
return {
|
|
@@ -2388,7 +2368,7 @@ function getTypePageFragment(scope) {
|
|
|
2388
2368
|
|
|
2389
2369
|
// src/visitors/getTypeManifestVisitor.ts
|
|
2390
2370
|
import {
|
|
2391
|
-
camelCase as
|
|
2371
|
+
camelCase as camelCase14,
|
|
2392
2372
|
isNode as isNode15,
|
|
2393
2373
|
isNodeFilter as isNodeFilter6,
|
|
2394
2374
|
isScalarEnum,
|
|
@@ -2523,7 +2503,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2523
2503
|
});
|
|
2524
2504
|
},
|
|
2525
2505
|
visitEnumEmptyVariantType(enumEmptyVariantType) {
|
|
2526
|
-
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2506
|
+
const discriminator = nameApi.discriminatedUnionDiscriminator(camelCase14(parentName?.strict ?? ""));
|
|
2527
2507
|
const name = nameApi.discriminatedUnionVariant(enumEmptyVariantType.name);
|
|
2528
2508
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
2529
2509
|
return typeManifest({
|
|
@@ -2536,7 +2516,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2536
2516
|
visitEnumStructVariantType(enumStructVariantType, { self }) {
|
|
2537
2517
|
const currentParentName = parentName;
|
|
2538
2518
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2539
|
-
|
|
2519
|
+
camelCase14(currentParentName?.strict ?? "")
|
|
2540
2520
|
);
|
|
2541
2521
|
const name = nameApi.discriminatedUnionVariant(enumStructVariantType.name);
|
|
2542
2522
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
@@ -2560,7 +2540,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2560
2540
|
visitEnumTupleVariantType(enumTupleVariantType, { self }) {
|
|
2561
2541
|
const currentParentName = parentName;
|
|
2562
2542
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2563
|
-
|
|
2543
|
+
camelCase14(currentParentName?.strict ?? "")
|
|
2564
2544
|
);
|
|
2565
2545
|
const name = nameApi.discriminatedUnionVariant(enumTupleVariantType.name);
|
|
2566
2546
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
@@ -2598,7 +2578,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2598
2578
|
decoderOptions.push(fragment`size: ${sizeManifest.decoder}`);
|
|
2599
2579
|
}
|
|
2600
2580
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
2601
|
-
|
|
2581
|
+
camelCase14(currentParentName?.strict ?? "")
|
|
2602
2582
|
);
|
|
2603
2583
|
if (!isScalarEnum(enumType) && discriminator !== "__kind") {
|
|
2604
2584
|
encoderOptions.push(fragment`discriminator: '${discriminator}'`);
|
|
@@ -2967,7 +2947,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2967
2947
|
});
|
|
2968
2948
|
},
|
|
2969
2949
|
visitStructFieldType(structFieldType, { self }) {
|
|
2970
|
-
const name =
|
|
2950
|
+
const name = camelCase14(structFieldType.name);
|
|
2971
2951
|
const originalChildManifest = visit8(structFieldType.type, self);
|
|
2972
2952
|
let docs = getDocblockFragment(structFieldType.docs ?? [], true);
|
|
2973
2953
|
docs = docs ? fragment`\n${docs}` : docs;
|
|
@@ -3022,9 +3002,9 @@ function getTypeManifestVisitor(input) {
|
|
|
3022
3002
|
const fieldDiscriminators = discriminators.filter(isNodeFilter6("fieldDiscriminatorNode"));
|
|
3023
3003
|
const defaultValues = mergeFragments(
|
|
3024
3004
|
optionalFields.map((f) => {
|
|
3025
|
-
const key =
|
|
3005
|
+
const key = camelCase14(f.name);
|
|
3026
3006
|
if (fieldDiscriminators.some((d) => d.name === f.name)) {
|
|
3027
|
-
const constantName = nameApi.constant(
|
|
3007
|
+
const constantName = nameApi.constant(camelCase14(`${discriminatorPrefix}_${f.name}`));
|
|
3028
3008
|
return f.defaultValueStrategy === "omitted" ? fragment`${key}: ${constantName}` : fragment`${key}: value.${key} ?? ${constantName}`;
|
|
3029
3009
|
}
|
|
3030
3010
|
const defaultValue = f.defaultValue;
|
|
@@ -3125,20 +3105,20 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3125
3105
|
const customAccountData = parseCustomDataOptions(options.customAccountData ?? [], "AccountData");
|
|
3126
3106
|
const customInstructionData = parseCustomDataOptions(options.customInstructionData ?? [], "InstructionData");
|
|
3127
3107
|
const renderScopeWithTypeManifestVisitor = {
|
|
3128
|
-
asyncResolvers: (options.asyncResolvers ?? []).map(
|
|
3108
|
+
asyncResolvers: (options.asyncResolvers ?? []).map(camelCase15),
|
|
3129
3109
|
customAccountData,
|
|
3130
3110
|
customInstructionData,
|
|
3131
3111
|
dependencyMap: options.dependencyMap ?? {},
|
|
3132
3112
|
getImportFrom: getImportFromFactory(options.linkOverrides ?? {}, customAccountData, customInstructionData),
|
|
3133
3113
|
linkables,
|
|
3134
3114
|
nameApi: getNameApi({ ...DEFAULT_NAME_TRANSFORMERS, ...options.nameTransformers }),
|
|
3135
|
-
nonScalarEnums: (options.nonScalarEnums ?? []).map(
|
|
3115
|
+
nonScalarEnums: (options.nonScalarEnums ?? []).map(camelCase15),
|
|
3136
3116
|
renderParentInstructions: options.renderParentInstructions ?? false,
|
|
3137
3117
|
useGranularImports: options.useGranularImports ?? false
|
|
3138
3118
|
};
|
|
3139
3119
|
const typeManifestVisitor = getTypeManifestVisitor({ ...renderScopeWithTypeManifestVisitor, stack });
|
|
3140
3120
|
const renderScope = { ...renderScopeWithTypeManifestVisitor, typeManifestVisitor };
|
|
3141
|
-
const internalNodes = (options.internalNodes ?? []).map(
|
|
3121
|
+
const internalNodes = (options.internalNodes ?? []).map(camelCase15);
|
|
3142
3122
|
const resolvedInstructionInputVisitor = getResolvedInstructionInputsVisitor();
|
|
3143
3123
|
const byteSizeVisitor = getByteSizeVisitor(linkables, { stack });
|
|
3144
3124
|
const asPage = (fragment2, dependencyMap = {}) => {
|
|
@@ -3155,7 +3135,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3155
3135
|
(v) => extendVisitor2(v, {
|
|
3156
3136
|
visitAccount(node) {
|
|
3157
3137
|
return createRenderMap(
|
|
3158
|
-
`accounts/${
|
|
3138
|
+
`accounts/${camelCase15(node.name)}.ts`,
|
|
3159
3139
|
asPage(
|
|
3160
3140
|
getAccountPageFragment({
|
|
3161
3141
|
...renderScope,
|
|
@@ -3167,7 +3147,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3167
3147
|
},
|
|
3168
3148
|
visitDefinedType(node) {
|
|
3169
3149
|
return createRenderMap(
|
|
3170
|
-
`types/${
|
|
3150
|
+
`types/${camelCase15(node.name)}.ts`,
|
|
3171
3151
|
asPage(getTypePageFragment({ ...renderScope, node, size: visit9(node, byteSizeVisitor) }), {
|
|
3172
3152
|
generatedTypes: "."
|
|
3173
3153
|
})
|
|
@@ -3175,7 +3155,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3175
3155
|
},
|
|
3176
3156
|
visitInstruction(node) {
|
|
3177
3157
|
return createRenderMap(
|
|
3178
|
-
`instructions/${
|
|
3158
|
+
`instructions/${camelCase15(node.name)}.ts`,
|
|
3179
3159
|
asPage(
|
|
3180
3160
|
getInstructionPageFragment({
|
|
3181
3161
|
...renderScope,
|
|
@@ -3188,7 +3168,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3188
3168
|
},
|
|
3189
3169
|
visitPda(node) {
|
|
3190
3170
|
return createRenderMap(
|
|
3191
|
-
`pdas/${
|
|
3171
|
+
`pdas/${camelCase15(node.name)}.ts`,
|
|
3192
3172
|
asPage(getPdaPageFragment({ ...renderScope, pdaPath: stack.getPath("pdaNode") }))
|
|
3193
3173
|
);
|
|
3194
3174
|
},
|
|
@@ -3200,8 +3180,8 @@ function getRenderMapVisitor(options = {}) {
|
|
|
3200
3180
|
const scope = { ...renderScope, programNode: node };
|
|
3201
3181
|
return mergeRenderMaps([
|
|
3202
3182
|
createRenderMap({
|
|
3203
|
-
[`programs/${
|
|
3204
|
-
[`errors/${
|
|
3183
|
+
[`programs/${camelCase15(node.name)}.ts`]: asPage(getProgramPageFragment(scope)),
|
|
3184
|
+
[`errors/${camelCase15(node.name)}.ts`]: node.errors.length > 0 ? asPage(getErrorPageFragment(scope)) : void 0
|
|
3205
3185
|
}),
|
|
3206
3186
|
...node.pdas.map((p) => visit9(p, self)),
|
|
3207
3187
|
...node.accounts.map((a) => visit9(a, self)),
|