@codama/renderers-js 1.4.3 → 1.5.1
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 +55 -76
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +55 -76
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.cjs +55 -76
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +55 -76
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.react-native.mjs +55 -76
- package/dist/index.react-native.mjs.map +1 -1
- package/dist/types/fragments/accountType.d.ts.map +1 -1
- package/dist/types/fragments/instructionInputDefault.d.ts.map +1 -1
- package/dist/types/visitors/getRenderMapVisitor.d.ts +2 -2
- package/dist/types/visitors/getRenderMapVisitor.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -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
|
|
|
@@ -1115,39 +1119,39 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1115
1119
|
}
|
|
1116
1120
|
return fragment`args.${inputName} = ${renderedValue};`;
|
|
1117
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");
|
|
1118
1127
|
switch (defaultValue.kind) {
|
|
1119
1128
|
case "accountValueNode":
|
|
1120
1129
|
const name = camelCase6(defaultValue.name);
|
|
1121
1130
|
if (input.kind === "instructionAccountNode" && input.resolvedIsSigner && !input.isSigner) {
|
|
1122
|
-
return
|
|
1123
|
-
defaultFragment(`expectTransactionSigner(accounts.${name}.value).address`),
|
|
1124
|
-
(f) => addFragmentImports(f, "shared", ["expectTransactionSigner"])
|
|
1125
|
-
);
|
|
1131
|
+
return defaultFragment(fragment`${expectTransactionSigner}(accounts.${name}.value).address`);
|
|
1126
1132
|
}
|
|
1127
1133
|
if (input.kind === "instructionAccountNode") {
|
|
1128
|
-
return
|
|
1129
|
-
defaultFragment(`expectSome(accounts.${name}.value)`),
|
|
1130
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1131
|
-
);
|
|
1134
|
+
return defaultFragment(fragment`${expectSome}(accounts.${name}.value)`);
|
|
1132
1135
|
}
|
|
1133
|
-
return
|
|
1134
|
-
defaultFragment(`expectAddress(accounts.${name}.value)`),
|
|
1135
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1136
|
-
);
|
|
1136
|
+
return defaultFragment(fragment`${expectAddress}(accounts.${name}.value)`);
|
|
1137
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
|
+
}
|
|
1138
1145
|
if (isNode8(defaultValue.pda, "pdaNode")) {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
)
|
|
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
|
+
}
|
|
1143
1152
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
1144
1153
|
if (isNode8(seed, "constantPdaSeedNode") && isNode8(seed.value, "programIdValueNode")) {
|
|
1145
|
-
return [
|
|
1146
|
-
pipe5(
|
|
1147
|
-
fragment`getAddressEncoder().encode(${pdaProgram})`,
|
|
1148
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["getAddressEncoder"])
|
|
1149
|
-
)
|
|
1150
|
-
];
|
|
1154
|
+
return [fragment`${use("getAddressEncoder", "solanaAddresses")}().encode(${pdaProgram})`];
|
|
1151
1155
|
}
|
|
1152
1156
|
if (isNode8(seed, "constantPdaSeedNode") && !isNode8(seed.value, "programIdValueNode")) {
|
|
1153
1157
|
const typeManifest2 = visit4(seed.type, typeManifestVisitor);
|
|
@@ -1160,18 +1164,12 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1160
1164
|
if (!valueSeed) return [];
|
|
1161
1165
|
if (isNode8(valueSeed, "accountValueNode")) {
|
|
1162
1166
|
return [
|
|
1163
|
-
|
|
1164
|
-
fragment`${typeManifest2.encoder}.encode(expectAddress(accounts.${camelCase6(valueSeed.name)}.value))`,
|
|
1165
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1166
|
-
)
|
|
1167
|
+
fragment`${typeManifest2.encoder}.encode(${expectAddress}(accounts.${camelCase6(valueSeed.name)}.value))`
|
|
1167
1168
|
];
|
|
1168
1169
|
}
|
|
1169
1170
|
if (isNode8(valueSeed, "argumentValueNode")) {
|
|
1170
1171
|
return [
|
|
1171
|
-
|
|
1172
|
-
fragment`${typeManifest2.encoder}.encode(expectSome(args.${camelCase6(valueSeed.name)}))`,
|
|
1173
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1174
|
-
)
|
|
1172
|
+
fragment`${typeManifest2.encoder}.encode(${expectSome}(args.${camelCase6(valueSeed.name)}))`
|
|
1175
1173
|
];
|
|
1176
1174
|
}
|
|
1177
1175
|
const valueManifest2 = visit4(valueSeed, typeManifestVisitor);
|
|
@@ -1179,29 +1177,21 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1179
1177
|
}
|
|
1180
1178
|
return [];
|
|
1181
1179
|
});
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
})
|
|
1187
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["getProgramDerivedAddress"]),
|
|
1188
|
-
(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}] })`
|
|
1189
1185
|
);
|
|
1190
1186
|
}
|
|
1191
|
-
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
1187
|
+
const pdaFunction = use(nameApi.pdaFindFunction(defaultValue.pda.name), getImportFrom(defaultValue.pda));
|
|
1192
1188
|
const pdaArgs = [];
|
|
1193
1189
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
1194
1190
|
if (isNode8(seed.value, "accountValueNode")) {
|
|
1195
|
-
return
|
|
1196
|
-
fragment`${seed.name}: expectAddress(accounts.${camelCase6(seed.value.name)}.value)`,
|
|
1197
|
-
(f) => addFragmentImports(f, "shared", ["expectAddress"])
|
|
1198
|
-
);
|
|
1191
|
+
return fragment`${seed.name}: ${expectAddress}(accounts.${camelCase6(seed.value.name)}.value)`;
|
|
1199
1192
|
}
|
|
1200
1193
|
if (isNode8(seed.value, "argumentValueNode")) {
|
|
1201
|
-
return
|
|
1202
|
-
fragment`${seed.name}: expectSome(args.${camelCase6(seed.value.name)})`,
|
|
1203
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1204
|
-
);
|
|
1194
|
+
return fragment`${seed.name}: ${expectSome}(args.${camelCase6(seed.value.name)})`;
|
|
1205
1195
|
}
|
|
1206
1196
|
return pipe5(
|
|
1207
1197
|
visit4(seed.value, typeManifestVisitor).value,
|
|
@@ -1213,49 +1203,38 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1213
1203
|
(f) => mapFragmentContent4(f, (c) => `{ ${c} }`)
|
|
1214
1204
|
);
|
|
1215
1205
|
if (pdaSeeds.length > 0) {
|
|
1216
|
-
pdaArgs.push(pdaSeedsFragment
|
|
1206
|
+
pdaArgs.push(pdaSeedsFragment);
|
|
1217
1207
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
(f) => addFragmentImports(f, module, [pdaFunction])
|
|
1223
|
-
);
|
|
1208
|
+
if (pdaProgramValue) {
|
|
1209
|
+
pdaArgs.push(fragment`{ programAddress: ${pdaProgramValue} }`);
|
|
1210
|
+
}
|
|
1211
|
+
return defaultFragment(fragment`await ${pdaFunction}(${mergeFragments(pdaArgs, (c) => c.join(", "))})`);
|
|
1224
1212
|
case "publicKeyValueNode":
|
|
1225
|
-
return
|
|
1226
|
-
|
|
1227
|
-
(f) => addFragmentImports(f, "solanaAddresses", ["type Address"])
|
|
1213
|
+
return defaultFragment(
|
|
1214
|
+
fragment`'${defaultValue.publicKey}' as ${addressType}<'${defaultValue.publicKey}'>`
|
|
1228
1215
|
);
|
|
1229
1216
|
case "programLinkNode":
|
|
1230
|
-
const programAddress = nameApi.programAddressConstant(defaultValue.name);
|
|
1231
|
-
return
|
|
1232
|
-
defaultFragment(programAddress, false),
|
|
1233
|
-
(f) => addFragmentImports(f, getImportFrom(defaultValue), [programAddress])
|
|
1234
|
-
);
|
|
1217
|
+
const programAddress = use(nameApi.programAddressConstant(defaultValue.name), getImportFrom(defaultValue));
|
|
1218
|
+
return defaultFragment(programAddress, false);
|
|
1235
1219
|
case "programIdValueNode":
|
|
1236
1220
|
if (optionalAccountStrategy === "programId" && input.kind === "instructionAccountNode" && input.isOptional) {
|
|
1237
1221
|
return fragment``;
|
|
1238
1222
|
}
|
|
1239
|
-
return defaultFragment(
|
|
1223
|
+
return defaultFragment(fragment`programAddress`, false);
|
|
1240
1224
|
case "identityValueNode":
|
|
1241
1225
|
case "payerValueNode":
|
|
1242
1226
|
return fragment``;
|
|
1243
1227
|
case "accountBumpValueNode":
|
|
1244
|
-
return
|
|
1245
|
-
|
|
1246
|
-
(f) => addFragmentImports(f, "shared", ["expectProgramDerivedAddress"])
|
|
1228
|
+
return defaultFragment(
|
|
1229
|
+
fragment`${expectProgramDerivedAddress}(accounts.${camelCase6(defaultValue.name)}.value)[1]`
|
|
1247
1230
|
);
|
|
1248
1231
|
case "argumentValueNode":
|
|
1249
|
-
return
|
|
1250
|
-
defaultFragment(`expectSome(args.${camelCase6(defaultValue.name)})`),
|
|
1251
|
-
(f) => addFragmentImports(f, "shared", ["expectSome"])
|
|
1252
|
-
);
|
|
1232
|
+
return defaultFragment(fragment`${expectSome}(args.${camelCase6(defaultValue.name)})`);
|
|
1253
1233
|
case "resolverValueNode":
|
|
1254
|
-
const resolverFunction = nameApi.resolverFunction(defaultValue.name);
|
|
1234
|
+
const resolverFunction = use(nameApi.resolverFunction(defaultValue.name), getImportFrom(defaultValue));
|
|
1255
1235
|
const resolverAwait = useAsync && asyncResolvers.includes(defaultValue.name) ? "await " : "";
|
|
1256
1236
|
return pipe5(
|
|
1257
|
-
defaultFragment(`${resolverAwait}${resolverFunction}(resolverScope)`),
|
|
1258
|
-
(f) => addFragmentImports(f, getImportFrom(defaultValue), [resolverFunction]),
|
|
1237
|
+
defaultFragment(fragment`${resolverAwait}${resolverFunction}(resolverScope)`),
|
|
1259
1238
|
(f) => addFragmentFeatures(f, ["instruction:resolverScopeVariable"])
|
|
1260
1239
|
);
|
|
1261
1240
|
case "conditionalValueNode":
|
|
@@ -1281,10 +1260,10 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
1281
1260
|
let condition = "true";
|
|
1282
1261
|
if (isNode8(defaultValue.condition, "resolverValueNode")) {
|
|
1283
1262
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
1284
|
-
const
|
|
1263
|
+
const module = getImportFrom(defaultValue.condition);
|
|
1285
1264
|
conditionalFragment = pipe5(
|
|
1286
1265
|
conditionalFragment,
|
|
1287
|
-
(f) => addFragmentImports(f,
|
|
1266
|
+
(f) => addFragmentImports(f, module, [conditionalResolverFunction]),
|
|
1288
1267
|
(f) => addFragmentFeatures(f, ["instruction:resolverScopeVariable"])
|
|
1289
1268
|
);
|
|
1290
1269
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
@@ -1319,7 +1298,7 @@ ${ifTrueRenderer ? ifTrueRenderer.content : ifFalseRenderer?.content}
|
|
|
1319
1298
|
);
|
|
1320
1299
|
default:
|
|
1321
1300
|
const valueManifest = visit4(defaultValue, typeManifestVisitor).value;
|
|
1322
|
-
return
|
|
1301
|
+
return defaultFragment(valueManifest);
|
|
1323
1302
|
}
|
|
1324
1303
|
}
|
|
1325
1304
|
function renderNestedInstructionDefault(scope) {
|