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