@codama/renderers-js 1.0.1 → 1.1.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.node.cjs +89 -72
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +91 -74
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/fragments/accountFetchHelpers.d.ts +2 -1
- package/dist/types/fragments/accountFetchHelpers.d.ts.map +1 -1
- package/dist/types/fragments/accountPdaHelpers.d.ts +3 -3
- package/dist/types/fragments/accountPdaHelpers.d.ts.map +1 -1
- package/dist/types/fragments/accountSizeHelpers.d.ts +2 -1
- package/dist/types/fragments/accountSizeHelpers.d.ts.map +1 -1
- package/dist/types/fragments/accountType.d.ts +2 -1
- package/dist/types/fragments/accountType.d.ts.map +1 -1
- package/dist/types/fragments/instructionAccountTypeParam.d.ts +3 -4
- package/dist/types/fragments/instructionAccountTypeParam.d.ts.map +1 -1
- package/dist/types/fragments/instructionByteDelta.d.ts +2 -1
- package/dist/types/fragments/instructionByteDelta.d.ts.map +1 -1
- package/dist/types/fragments/instructionData.d.ts +2 -1
- package/dist/types/fragments/instructionData.d.ts.map +1 -1
- package/dist/types/fragments/instructionExtraArgs.d.ts +2 -1
- package/dist/types/fragments/instructionExtraArgs.d.ts.map +1 -1
- package/dist/types/fragments/instructionFunction.d.ts +3 -4
- package/dist/types/fragments/instructionFunction.d.ts.map +1 -1
- package/dist/types/fragments/instructionInputResolved.d.ts +2 -2
- package/dist/types/fragments/instructionInputResolved.d.ts.map +1 -1
- package/dist/types/fragments/instructionInputType.d.ts +2 -2
- package/dist/types/fragments/instructionInputType.d.ts.map +1 -1
- package/dist/types/fragments/instructionParseFunction.d.ts +3 -3
- package/dist/types/fragments/instructionParseFunction.d.ts.map +1 -1
- package/dist/types/fragments/instructionRemainingAccounts.d.ts +2 -1
- package/dist/types/fragments/instructionRemainingAccounts.d.ts.map +1 -1
- package/dist/types/fragments/instructionType.d.ts +3 -3
- package/dist/types/fragments/instructionType.d.ts.map +1 -1
- package/dist/types/fragments/pdaFunction.d.ts +3 -3
- package/dist/types/fragments/pdaFunction.d.ts.map +1 -1
- package/dist/types/getRenderMapVisitor.d.ts.map +1 -1
- package/dist/types/getTypeManifestVisitor.d.ts +2 -5
- package/dist/types/getTypeManifestVisitor.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.node.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var visitorsCore = require('@codama/visitors-core');
|
|
3
4
|
var path = require('path');
|
|
4
5
|
var nodes = require('@codama/nodes');
|
|
5
|
-
var visitorsCore = require('@codama/visitors-core');
|
|
6
6
|
var codecsStrings = require('@solana/codecs-strings');
|
|
7
7
|
var errors = require('@codama/errors');
|
|
8
8
|
require('url');
|
|
@@ -424,7 +424,8 @@ var Fragment = class _Fragment {
|
|
|
424
424
|
|
|
425
425
|
// src/fragments/accountFetchHelpers.ts
|
|
426
426
|
function getAccountFetchHelpersFragment(scope) {
|
|
427
|
-
const {
|
|
427
|
+
const { accountPath, typeManifest: typeManifest2, nameApi, customAccountData } = scope;
|
|
428
|
+
const accountNode = visitorsCore.getLastNodeFromPath(accountPath);
|
|
428
429
|
const hasCustomData = customAccountData.has(accountNode.name);
|
|
429
430
|
const accountTypeFragment = hasCustomData ? typeManifest2.strictType.clone() : fragment(nameApi.dataType(accountNode.name));
|
|
430
431
|
const decoderFunctionFragment = hasCustomData ? typeManifest2.decoder.clone() : fragment(`${nameApi.decoderFunction(accountNode.name)}()`);
|
|
@@ -451,8 +452,10 @@ function getAccountFetchHelpersFragment(scope) {
|
|
|
451
452
|
]);
|
|
452
453
|
}
|
|
453
454
|
function getAccountPdaHelpersFragment(scope) {
|
|
454
|
-
const {
|
|
455
|
-
const
|
|
455
|
+
const { accountPath, nameApi, linkables, customAccountData, typeManifest: typeManifest2 } = scope;
|
|
456
|
+
const accountNode = visitorsCore.getLastNodeFromPath(accountPath);
|
|
457
|
+
const programNode = visitorsCore.findProgramNodeFromPath(accountPath);
|
|
458
|
+
const pdaNode = accountNode.pda ? linkables.get([...accountPath, accountNode.pda]) : void 0;
|
|
456
459
|
if (!pdaNode) {
|
|
457
460
|
return fragment("");
|
|
458
461
|
}
|
|
@@ -478,10 +481,9 @@ function getAccountPdaHelpersFragment(scope) {
|
|
|
478
481
|
"type MaybeAccount"
|
|
479
482
|
]);
|
|
480
483
|
}
|
|
481
|
-
|
|
482
|
-
// src/fragments/accountSizeHelpers.ts
|
|
483
484
|
function getAccountSizeHelpersFragment(scope) {
|
|
484
|
-
const {
|
|
485
|
+
const { accountPath, nameApi } = scope;
|
|
486
|
+
const accountNode = visitorsCore.getLastNodeFromPath(accountPath);
|
|
485
487
|
if (accountNode.size == null) {
|
|
486
488
|
return fragment("");
|
|
487
489
|
}
|
|
@@ -561,7 +563,8 @@ function getTypeWithCodecFragment(scope) {
|
|
|
561
563
|
|
|
562
564
|
// src/fragments/accountType.ts
|
|
563
565
|
function getAccountTypeFragment(scope) {
|
|
564
|
-
const {
|
|
566
|
+
const { accountPath, typeManifest: typeManifest2, nameApi, customAccountData } = scope;
|
|
567
|
+
const accountNode = visitorsCore.getLastNodeFromPath(accountPath);
|
|
565
568
|
if (customAccountData.has(accountNode.name)) {
|
|
566
569
|
return fragment("");
|
|
567
570
|
}
|
|
@@ -632,7 +635,10 @@ function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
|
632
635
|
return fragment(`ReadonlyAccount<${typeParam}>`).addImports("solanaInstructions", "type ReadonlyAccount");
|
|
633
636
|
}
|
|
634
637
|
function getInstructionAccountTypeParamFragment(scope) {
|
|
635
|
-
const {
|
|
638
|
+
const { instructionAccountPath, allowAccountMeta, linkables } = scope;
|
|
639
|
+
const instructionAccountNode = visitorsCore.getLastNodeFromPath(instructionAccountPath);
|
|
640
|
+
const instructionNode = visitorsCore.findInstructionNodeFromPath(instructionAccountPath);
|
|
641
|
+
const programNode = visitorsCore.findProgramNodeFromPath(instructionAccountPath);
|
|
636
642
|
const typeParam = `TAccount${nodes.pascalCase(instructionAccountNode.name)}`;
|
|
637
643
|
const accountMeta = allowAccountMeta ? " | IAccountMeta<string>" : "";
|
|
638
644
|
const imports = new ImportMap();
|
|
@@ -650,7 +656,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
650
656
|
case "publicKeyValueNode":
|
|
651
657
|
return `"${defaultValue.publicKey}"`;
|
|
652
658
|
case "programLinkNode":
|
|
653
|
-
const programNode = linkables.get(defaultValue);
|
|
659
|
+
const programNode = linkables.get([defaultValue]);
|
|
654
660
|
return programNode ? `"${programNode.publicKey}"` : "string";
|
|
655
661
|
case "programIdValueNode":
|
|
656
662
|
return `"${programId}"`;
|
|
@@ -659,7 +665,7 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
659
665
|
}
|
|
660
666
|
}
|
|
661
667
|
function getInstructionByteDeltaFragment(scope) {
|
|
662
|
-
const { byteDeltas } = scope.
|
|
668
|
+
const { byteDeltas } = visitorsCore.getLastNodeFromPath(scope.instructionPath);
|
|
663
669
|
const fragments = (byteDeltas ?? []).flatMap((r) => getByteDeltaFragment(r, scope));
|
|
664
670
|
if (fragments.length === 0) return fragment("");
|
|
665
671
|
return mergeFragments(
|
|
@@ -715,10 +721,9 @@ function getResolverValueNodeFragment(byteDelta, scope) {
|
|
|
715
721
|
const functionName = scope.nameApi.resolverFunction(byteDelta.value.name);
|
|
716
722
|
return fragment(`${awaitKeyword}${functionName}(resolverScope)`).addImports(scope.getImportFrom(byteDelta.value), functionName).addFeatures(["instruction:resolverScopeVariable"]);
|
|
717
723
|
}
|
|
718
|
-
|
|
719
|
-
// src/fragments/instructionData.ts
|
|
720
724
|
function getInstructionDataFragment(scope) {
|
|
721
|
-
const {
|
|
725
|
+
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
726
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
722
727
|
if (instructionNode.arguments.length === 0 || customInstructionData.has(instructionNode.name)) {
|
|
723
728
|
return fragment("");
|
|
724
729
|
}
|
|
@@ -775,10 +780,9 @@ function getConstantFragment(scope) {
|
|
|
775
780
|
(r) => r.join("\n\n")
|
|
776
781
|
);
|
|
777
782
|
}
|
|
778
|
-
|
|
779
|
-
// src/fragments/instructionExtraArgs.ts
|
|
780
783
|
function getInstructionExtraArgsFragment(scope) {
|
|
781
|
-
const {
|
|
784
|
+
const { instructionPath, extraArgsManifest, nameApi } = scope;
|
|
785
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
782
786
|
if ((instructionNode.extraArguments ?? []).length === 0) {
|
|
783
787
|
return fragment("");
|
|
784
788
|
}
|
|
@@ -1000,11 +1004,12 @@ function renderNestedInstructionDefault(scope) {
|
|
|
1000
1004
|
|
|
1001
1005
|
// src/fragments/instructionInputResolved.ts
|
|
1002
1006
|
function getInstructionInputResolvedFragment(scope) {
|
|
1007
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(scope.instructionPath);
|
|
1003
1008
|
const resolvedInputFragments = scope.resolvedInputs.flatMap((input) => {
|
|
1004
1009
|
const inputFragment = getInstructionInputDefaultFragment({
|
|
1005
1010
|
...scope,
|
|
1006
1011
|
input,
|
|
1007
|
-
optionalAccountStrategy:
|
|
1012
|
+
optionalAccountStrategy: instructionNode.optionalAccountStrategy
|
|
1008
1013
|
});
|
|
1009
1014
|
if (!inputFragment.render) return [];
|
|
1010
1015
|
const camelName = nodes.camelCase(input.name);
|
|
@@ -1027,7 +1032,8 @@ ${r}
|
|
|
1027
1032
|
);
|
|
1028
1033
|
}
|
|
1029
1034
|
function getInstructionInputTypeFragment(scope) {
|
|
1030
|
-
const {
|
|
1035
|
+
const { instructionPath, useAsync, nameApi } = scope;
|
|
1036
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1031
1037
|
const instructionInputType = useAsync ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name);
|
|
1032
1038
|
const accountsFragment = getAccountsFragment(scope);
|
|
1033
1039
|
const [dataArgumentsFragment, customDataArgumentsFragment] = getDataArgumentsFragments(scope);
|
|
@@ -1050,7 +1056,8 @@ function getInstructionInputTypeFragment(scope) {
|
|
|
1050
1056
|
).addImports("solanaAddresses", ["type Address"]);
|
|
1051
1057
|
}
|
|
1052
1058
|
function getAccountsFragment(scope) {
|
|
1053
|
-
const {
|
|
1059
|
+
const { instructionPath, resolvedInputs, useAsync, asyncResolvers } = scope;
|
|
1060
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1054
1061
|
const fragments = instructionNode.accounts.map((account) => {
|
|
1055
1062
|
const resolvedAccount = resolvedInputs.find(
|
|
1056
1063
|
(input) => input.kind === "instructionAccountNode" && input.name === account.name
|
|
@@ -1083,7 +1090,8 @@ function getAccountTypeFragment2(account) {
|
|
|
1083
1090
|
return fragment(`Address<${typeParam}>`).addImports("solanaAddresses", ["type Address"]);
|
|
1084
1091
|
}
|
|
1085
1092
|
function getDataArgumentsFragments(scope) {
|
|
1086
|
-
const {
|
|
1093
|
+
const { instructionPath, nameApi } = scope;
|
|
1094
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1087
1095
|
const customData = scope.customInstructionData.get(instructionNode.name);
|
|
1088
1096
|
if (customData) {
|
|
1089
1097
|
return [
|
|
@@ -1100,7 +1108,8 @@ function getDataArgumentsFragments(scope) {
|
|
|
1100
1108
|
return [mergeFragments(fragments, (r) => r.join("\n")), fragment("")];
|
|
1101
1109
|
}
|
|
1102
1110
|
function getExtraArgumentsFragment(scope) {
|
|
1103
|
-
const {
|
|
1111
|
+
const { instructionPath, nameApi } = scope;
|
|
1112
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1104
1113
|
const instructionExtraName = nameApi.instructionExtraType(instructionNode.name);
|
|
1105
1114
|
const extraArgsType = nameApi.dataArgsType(instructionExtraName);
|
|
1106
1115
|
const fragments = (instructionNode.extraArguments ?? []).flatMap((arg) => {
|
|
@@ -1139,7 +1148,7 @@ function getRemainingAccountsFragment(instructionNode) {
|
|
|
1139
1148
|
return mergeFragments(fragments, (r) => r.join("\n"));
|
|
1140
1149
|
}
|
|
1141
1150
|
function getInstructionRemainingAccountsFragment(scope) {
|
|
1142
|
-
const { remainingAccounts } = scope.
|
|
1151
|
+
const { remainingAccounts } = visitorsCore.getLastNodeFromPath(scope.instructionPath);
|
|
1143
1152
|
const fragments = (remainingAccounts ?? []).flatMap((r) => getRemainingAccountsFragment2(r, scope));
|
|
1144
1153
|
if (fragments.length === 0) return fragment("");
|
|
1145
1154
|
return mergeFragments(
|
|
@@ -1162,7 +1171,7 @@ function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
|
1162
1171
|
return [remainingAccountsFragment];
|
|
1163
1172
|
}
|
|
1164
1173
|
function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
1165
|
-
const
|
|
1174
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(scope.instructionPath);
|
|
1166
1175
|
nodes.assertIsNode(remainingAccounts.value, "argumentValueNode");
|
|
1167
1176
|
const argumentName = nodes.camelCase(remainingAccounts.value.name);
|
|
1168
1177
|
const isOptional = remainingAccounts.isOptional ?? false;
|
|
@@ -1205,8 +1214,7 @@ function getResolverValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1205
1214
|
function getInstructionFunctionFragment(scope) {
|
|
1206
1215
|
const {
|
|
1207
1216
|
useAsync,
|
|
1208
|
-
|
|
1209
|
-
programNode,
|
|
1217
|
+
instructionPath,
|
|
1210
1218
|
resolvedInputs,
|
|
1211
1219
|
renamedArgs,
|
|
1212
1220
|
dataArgsManifest,
|
|
@@ -1214,6 +1222,8 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1214
1222
|
nameApi,
|
|
1215
1223
|
customInstructionData
|
|
1216
1224
|
} = scope;
|
|
1225
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1226
|
+
const programNode = visitorsCore.findProgramNodeFromPath(instructionPath);
|
|
1217
1227
|
if (useAsync && !hasAsyncFunction(instructionNode, resolvedInputs, asyncResolvers)) {
|
|
1218
1228
|
return fragment("");
|
|
1219
1229
|
}
|
|
@@ -1315,7 +1325,8 @@ function getTypeParams(instructionNode, programAddressConstant) {
|
|
|
1315
1325
|
return fragment(typeParams.filter((x) => !!x).join(", ")).mapRender((r) => `<${r}>`).addImports("generatedPrograms", [programAddressConstant]);
|
|
1316
1326
|
}
|
|
1317
1327
|
function getInstructionType(scope) {
|
|
1318
|
-
const {
|
|
1328
|
+
const { instructionPath, nameApi } = scope;
|
|
1329
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1319
1330
|
const instructionTypeName = nameApi.instructionType(instructionNode.name);
|
|
1320
1331
|
const programAddressFragment = fragment("TProgramAddress");
|
|
1321
1332
|
const accountTypeParamsFragments = instructionNode.accounts.map((account) => {
|
|
@@ -1335,16 +1346,17 @@ function getInstructionType(scope) {
|
|
|
1335
1346
|
).mapRender((r) => `${instructionTypeName}<${r}>`);
|
|
1336
1347
|
}
|
|
1337
1348
|
function getInputTypeCall(scope) {
|
|
1338
|
-
const {
|
|
1349
|
+
const { instructionPath, useAsync, nameApi } = scope;
|
|
1350
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1339
1351
|
const inputTypeName = useAsync ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name);
|
|
1340
1352
|
if (instructionNode.accounts.length === 0) return fragment(inputTypeName);
|
|
1341
1353
|
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${nodes.pascalCase(account.name)}`).join(", ");
|
|
1342
1354
|
return fragment(`${inputTypeName}<${accountTypeParams}>`);
|
|
1343
1355
|
}
|
|
1344
|
-
|
|
1345
|
-
// src/fragments/instructionParseFunction.ts
|
|
1346
1356
|
function getInstructionParseFunctionFragment(scope) {
|
|
1347
|
-
const {
|
|
1357
|
+
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
1358
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1359
|
+
const programNode = visitorsCore.findProgramNodeFromPath(instructionPath);
|
|
1348
1360
|
const customData = customInstructionData.get(instructionNode.name);
|
|
1349
1361
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1350
1362
|
const hasOptionalAccounts = instructionNode.accounts.some((account) => account.isOptional);
|
|
@@ -1373,7 +1385,9 @@ function getInstructionParseFunctionFragment(scope) {
|
|
|
1373
1385
|
}).mergeImportsWith(dataTypeFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaInstructions", ["type IInstruction"]).addImports("solanaInstructions", hasAccounts ? ["type IInstructionWithAccounts", "type IAccountMeta"] : []).addImports("solanaInstructions", hasData ? ["type IInstructionWithData"] : []);
|
|
1374
1386
|
}
|
|
1375
1387
|
function getInstructionTypeFragment(scope) {
|
|
1376
|
-
const {
|
|
1388
|
+
const { instructionPath, nameApi, customInstructionData } = scope;
|
|
1389
|
+
const instructionNode = visitorsCore.getLastNodeFromPath(instructionPath);
|
|
1390
|
+
const programNode = visitorsCore.findProgramNodeFromPath(instructionPath);
|
|
1377
1391
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1378
1392
|
const customData = customInstructionData.get(instructionNode.name);
|
|
1379
1393
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
@@ -1385,7 +1399,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1385
1399
|
(account) => getInstructionAccountTypeParamFragment({
|
|
1386
1400
|
...scope,
|
|
1387
1401
|
allowAccountMeta: true,
|
|
1388
|
-
|
|
1402
|
+
instructionAccountPath: [...instructionPath, account]
|
|
1389
1403
|
})
|
|
1390
1404
|
),
|
|
1391
1405
|
(renders) => renders.join(", ")
|
|
@@ -1421,7 +1435,9 @@ function getInstructionTypeFragment(scope) {
|
|
|
1421
1435
|
return fragment2;
|
|
1422
1436
|
}
|
|
1423
1437
|
function getPdaFunctionFragment(scope) {
|
|
1424
|
-
const {
|
|
1438
|
+
const { pdaPath, typeManifestVisitor, nameApi } = scope;
|
|
1439
|
+
const pdaNode = visitorsCore.getLastNodeFromPath(pdaPath);
|
|
1440
|
+
const programNode = visitorsCore.findProgramNodeFromPath(pdaPath);
|
|
1425
1441
|
const imports = new ImportMap();
|
|
1426
1442
|
const seeds = pdaNode.seeds.map((seed) => {
|
|
1427
1443
|
if (nodes.isNode(seed, "variablePdaSeedNode")) {
|
|
@@ -1640,8 +1656,8 @@ function mergeManifests(manifests, options = {}) {
|
|
|
1640
1656
|
}
|
|
1641
1657
|
function getTypeManifestVisitor(input) {
|
|
1642
1658
|
const { nameApi, linkables, nonScalarEnums, customAccountData, customInstructionData, getImportFrom } = input;
|
|
1643
|
-
const stack = new visitorsCore.NodeStack();
|
|
1644
|
-
let parentName =
|
|
1659
|
+
const stack = input.stack ?? new visitorsCore.NodeStack();
|
|
1660
|
+
let parentName = null;
|
|
1645
1661
|
return visitorsCore.pipe(
|
|
1646
1662
|
visitorsCore.staticVisitor(
|
|
1647
1663
|
() => ({
|
|
@@ -1652,14 +1668,16 @@ function getTypeManifestVisitor(input) {
|
|
|
1652
1668
|
strictType: fragment(""),
|
|
1653
1669
|
value: fragment("")
|
|
1654
1670
|
}),
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1671
|
+
{
|
|
1672
|
+
keys: [
|
|
1673
|
+
...nodes.REGISTERED_TYPE_NODE_KINDS,
|
|
1674
|
+
...nodes.REGISTERED_VALUE_NODE_KINDS,
|
|
1675
|
+
"definedTypeLinkNode",
|
|
1676
|
+
"definedTypeNode",
|
|
1677
|
+
"accountNode",
|
|
1678
|
+
"instructionNode"
|
|
1679
|
+
]
|
|
1680
|
+
}
|
|
1663
1681
|
),
|
|
1664
1682
|
(visitor) => visitorsCore.extendVisitor(visitor, {
|
|
1665
1683
|
visitAccount(account, { self }) {
|
|
@@ -1904,7 +1922,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1904
1922
|
const enumName = nameApi.dataType(node.enum.name);
|
|
1905
1923
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
1906
1924
|
const importFrom = getImportFrom(node.enum);
|
|
1907
|
-
const enumNode = linkables.get(node.enum)?.type;
|
|
1925
|
+
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
1908
1926
|
const isScalar = enumNode && nodes.isNode(enumNode, "enumTypeNode") ? nodes.isScalarEnum(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
1909
1927
|
if (!node.value && isScalar) {
|
|
1910
1928
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
@@ -2224,8 +2242,9 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2224
2242
|
if (optionalFields.length === 0) {
|
|
2225
2243
|
return mergedManifest;
|
|
2226
2244
|
}
|
|
2227
|
-
const
|
|
2228
|
-
const
|
|
2245
|
+
const parentPath = stack.getPath();
|
|
2246
|
+
const instructionNode = visitorsCore.findLastNodeFromPath(parentPath, "instructionNode");
|
|
2247
|
+
const accountNode = visitorsCore.findLastNodeFromPath(parentPath, "accountNode");
|
|
2229
2248
|
const discriminatorPrefix = instructionNode ? instructionNode.name : accountNode?.name;
|
|
2230
2249
|
const discriminators = (instructionNode ? instructionNode.discriminators : accountNode?.discriminators) ?? [];
|
|
2231
2250
|
const fieldDiscriminators = discriminators.filter(nodes.isNodeFilter("fieldDiscriminatorNode"));
|
|
@@ -2378,7 +2397,7 @@ var DEFAULT_NAME_TRANSFORMERS = {
|
|
|
2378
2397
|
// src/getRenderMapVisitor.ts
|
|
2379
2398
|
function getRenderMapVisitor(options = {}) {
|
|
2380
2399
|
const linkables = new visitorsCore.LinkableDictionary();
|
|
2381
|
-
|
|
2400
|
+
const stack = new visitorsCore.NodeStack();
|
|
2382
2401
|
const nameTransformers = {
|
|
2383
2402
|
...DEFAULT_NAME_TRANSFORMERS,
|
|
2384
2403
|
...options.nameTransformers
|
|
@@ -2393,16 +2412,15 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2393
2412
|
const customAccountData = parseCustomDataOptions(options.customAccountData ?? [], "AccountData");
|
|
2394
2413
|
const customInstructionData = parseCustomDataOptions(options.customInstructionData ?? [], "InstructionData");
|
|
2395
2414
|
const getImportFrom = getImportFromFactory(options.linkOverrides ?? {}, customAccountData, customInstructionData);
|
|
2396
|
-
const
|
|
2415
|
+
const typeManifestVisitor = getTypeManifestVisitor({
|
|
2397
2416
|
customAccountData,
|
|
2398
2417
|
customInstructionData,
|
|
2399
2418
|
getImportFrom,
|
|
2400
2419
|
linkables,
|
|
2401
2420
|
nameApi,
|
|
2402
2421
|
nonScalarEnums,
|
|
2403
|
-
|
|
2422
|
+
stack
|
|
2404
2423
|
});
|
|
2405
|
-
const typeManifestVisitor = getTypeManifestVisitor2();
|
|
2406
2424
|
const resolvedInstructionInputVisitor = visitorsCore.getResolvedInstructionInputsVisitor();
|
|
2407
2425
|
const globalScope = {
|
|
2408
2426
|
asyncResolvers,
|
|
@@ -2419,19 +2437,18 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2419
2437
|
return render(path.join("pages", template), context, renderOptions);
|
|
2420
2438
|
};
|
|
2421
2439
|
return visitorsCore.pipe(
|
|
2422
|
-
visitorsCore.staticVisitor(
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
),
|
|
2440
|
+
visitorsCore.staticVisitor(() => new renderersCore.RenderMap(), {
|
|
2441
|
+
keys: ["rootNode", "programNode", "pdaNode", "accountNode", "definedTypeNode", "instructionNode"]
|
|
2442
|
+
}),
|
|
2426
2443
|
(v) => visitorsCore.extendVisitor(v, {
|
|
2427
2444
|
visitAccount(node) {
|
|
2428
|
-
|
|
2445
|
+
const accountPath = stack.getPath("accountNode");
|
|
2446
|
+
if (!visitorsCore.findProgramNodeFromPath(accountPath)) {
|
|
2429
2447
|
throw new Error("Account must be visited inside a program.");
|
|
2430
2448
|
}
|
|
2431
2449
|
const scope = {
|
|
2432
2450
|
...globalScope,
|
|
2433
|
-
|
|
2434
|
-
programNode: program,
|
|
2451
|
+
accountPath,
|
|
2435
2452
|
typeManifest: visitorsCore.visit(node, typeManifestVisitor)
|
|
2436
2453
|
};
|
|
2437
2454
|
const fields = nodes.resolveNestedTypeNode(node.data).fields;
|
|
@@ -2497,7 +2514,8 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2497
2514
|
);
|
|
2498
2515
|
},
|
|
2499
2516
|
visitInstruction(node) {
|
|
2500
|
-
|
|
2517
|
+
const instructionPath = stack.getPath("instructionNode");
|
|
2518
|
+
if (!visitorsCore.findProgramNodeFromPath(instructionPath)) {
|
|
2501
2519
|
throw new Error("Instruction must be visited inside a program.");
|
|
2502
2520
|
}
|
|
2503
2521
|
const instructionExtraName = nameApi.instructionExtraType(node.name);
|
|
@@ -2505,14 +2523,13 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2505
2523
|
...globalScope,
|
|
2506
2524
|
dataArgsManifest: visitorsCore.visit(node, typeManifestVisitor),
|
|
2507
2525
|
extraArgsManifest: visitorsCore.visit(
|
|
2508
|
-
nodes.
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2526
|
+
nodes.definedTypeNode({
|
|
2527
|
+
name: instructionExtraName,
|
|
2528
|
+
type: nodes.structTypeNodeFromInstructionArgumentNodes(node.extraArguments ?? [])
|
|
2529
|
+
}),
|
|
2530
|
+
typeManifestVisitor
|
|
2513
2531
|
),
|
|
2514
|
-
|
|
2515
|
-
programNode: program,
|
|
2532
|
+
instructionPath,
|
|
2516
2533
|
renamedArgs: getRenamedArgsMap(node),
|
|
2517
2534
|
resolvedInputs: visitorsCore.visit(node, resolvedInstructionInputVisitor)
|
|
2518
2535
|
};
|
|
@@ -2559,10 +2576,11 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2559
2576
|
);
|
|
2560
2577
|
},
|
|
2561
2578
|
visitPda(node) {
|
|
2562
|
-
|
|
2579
|
+
const pdaPath = stack.getPath("pdaNode");
|
|
2580
|
+
if (!visitorsCore.findProgramNodeFromPath(pdaPath)) {
|
|
2563
2581
|
throw new Error("Account must be visited inside a program.");
|
|
2564
2582
|
}
|
|
2565
|
-
const scope = { ...globalScope,
|
|
2583
|
+
const scope = { ...globalScope, pdaPath };
|
|
2566
2584
|
const pdaFunctionFragment = getPdaFunctionFragment(scope);
|
|
2567
2585
|
const imports = new ImportMap().mergeWith(pdaFunctionFragment);
|
|
2568
2586
|
return new renderersCore.RenderMap().add(
|
|
@@ -2574,7 +2592,6 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2574
2592
|
);
|
|
2575
2593
|
},
|
|
2576
2594
|
visitProgram(node, { self }) {
|
|
2577
|
-
program = node;
|
|
2578
2595
|
const customDataDefinedType = [
|
|
2579
2596
|
...getDefinedTypeNodesToExtract(node.accounts, customAccountData),
|
|
2580
2597
|
...getDefinedTypeNodesToExtract(node.instructions, customInstructionData)
|
|
@@ -2604,11 +2621,10 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2604
2621
|
})
|
|
2605
2622
|
);
|
|
2606
2623
|
renderMap.mergeWith(
|
|
2607
|
-
...nodes.getAllInstructionsWithSubs(
|
|
2624
|
+
...nodes.getAllInstructionsWithSubs(node, {
|
|
2608
2625
|
leavesOnly: !renderParentInstructions
|
|
2609
2626
|
}).map((ix) => visitorsCore.visit(ix, self))
|
|
2610
2627
|
);
|
|
2611
|
-
program = null;
|
|
2612
2628
|
return renderMap;
|
|
2613
2629
|
},
|
|
2614
2630
|
visitRoot(node, { self }) {
|
|
@@ -2675,7 +2691,8 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2675
2691
|
return map.add("index.ts", render2("rootIndex.njk", ctx)).mergeWith(...nodes.getAllPrograms(node).map((p) => visitorsCore.visit(p, self)));
|
|
2676
2692
|
}
|
|
2677
2693
|
}),
|
|
2678
|
-
(v) => visitorsCore.
|
|
2694
|
+
(v) => visitorsCore.recordNodeStackVisitor(v, stack),
|
|
2695
|
+
(v) => visitorsCore.recordLinkablesOnFirstVisitVisitor(v, linkables)
|
|
2679
2696
|
);
|
|
2680
2697
|
}
|
|
2681
2698
|
function getRenamedArgsMap(instruction) {
|