@codama/renderers-js 1.2.5 → 1.2.7
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/README.md +16 -16
- package/dist/index.node.cjs +547 -421
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +486 -285
- package/dist/index.node.mjs.map +1 -1
- package/dist/templates/pages/sharedPage.njk +1 -1
- package/package.json +8 -9
package/dist/index.node.mjs
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
import { NodeStack, pipe, staticVisitor, extendVisitor, visit, findLastNodeFromPath, recordNodeStackVisitor, LinkableDictionary, getResolvedInstructionInputsVisitor, findProgramNodeFromPath, recordLinkablesOnFirstVisitVisitor, rootNodeVisitor, getLastNodeFromPath, deduplicateInstructionDependencies, findInstructionNodeFromPath } from '@codama/visitors-core';
|
|
2
|
-
import { join, dirname } from 'node:path';
|
|
3
|
-
import { REGISTERED_TYPE_NODE_KINDS, REGISTERED_VALUE_NODE_KINDS, resolveNestedTypeNode, isNode, camelCase, structTypeNode, structFieldTypeNode, isScalarEnum, structTypeNodeFromInstructionArgumentNodes, isNodeFilter, pascalCase, snakeCase, definedTypeNode, getAllInstructionsWithSubs, getAllPrograms, getAllPdas, getAllAccounts, getAllDefinedTypes, definedTypeLinkNode, VALUE_NODES, isDataEnum, capitalize, kebabCase, titleCase, accountValueNode, argumentValueNode, constantDiscriminatorNode, constantValueNodeFromBytes, constantValueNode, assertIsNode, getAllInstructionArguments } from '@codama/nodes';
|
|
4
|
-
import { getBase64Encoder, getBase58Encoder, getBase16Encoder, getUtf8Encoder, getBase64Decoder } from '@solana/codecs-strings';
|
|
5
|
-
import { logWarn, CodamaError, CODAMA_ERROR__UNEXPECTED_NODE_KIND } from '@codama/errors';
|
|
6
|
-
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import nunjucks from 'nunjucks';
|
|
8
|
-
import { RenderMap, deleteDirectory } from '@codama/renderers-core';
|
|
9
|
-
import * as estreePlugin from 'prettier/plugins/estree';
|
|
10
|
-
import * as typeScriptPlugin from 'prettier/plugins/typescript';
|
|
11
|
-
import { format } from 'prettier/standalone';
|
|
12
|
-
|
|
13
1
|
// src/ImportMap.ts
|
|
14
2
|
var DEFAULT_EXTERNAL_MODULE_MAP = {
|
|
15
|
-
solanaAccounts: "@solana/
|
|
16
|
-
solanaAddresses: "@solana/
|
|
17
|
-
solanaCodecsCore: "@solana/
|
|
18
|
-
solanaCodecsDataStructures: "@solana/
|
|
19
|
-
solanaCodecsNumbers: "@solana/
|
|
20
|
-
solanaCodecsStrings: "@solana/
|
|
21
|
-
solanaErrors: "@solana/
|
|
22
|
-
solanaInstructions: "@solana/
|
|
23
|
-
solanaOptions: "@solana/
|
|
24
|
-
solanaPrograms: "@solana/
|
|
25
|
-
solanaRpcTypes: "@solana/
|
|
26
|
-
solanaSigners: "@solana/
|
|
3
|
+
solanaAccounts: "@solana/kit",
|
|
4
|
+
solanaAddresses: "@solana/kit",
|
|
5
|
+
solanaCodecsCore: "@solana/kit",
|
|
6
|
+
solanaCodecsDataStructures: "@solana/kit",
|
|
7
|
+
solanaCodecsNumbers: "@solana/kit",
|
|
8
|
+
solanaCodecsStrings: "@solana/kit",
|
|
9
|
+
solanaErrors: "@solana/kit",
|
|
10
|
+
solanaInstructions: "@solana/kit",
|
|
11
|
+
solanaOptions: "@solana/kit",
|
|
12
|
+
solanaPrograms: "@solana/kit",
|
|
13
|
+
solanaRpcTypes: "@solana/kit",
|
|
14
|
+
solanaSigners: "@solana/kit"
|
|
27
15
|
};
|
|
28
16
|
var DEFAULT_GRANULAR_EXTERNAL_MODULE_MAP = {
|
|
29
17
|
solanaAccounts: "@solana/accounts",
|
|
@@ -142,6 +130,20 @@ var ImportMap = class {
|
|
|
142
130
|
}).join("\n");
|
|
143
131
|
}
|
|
144
132
|
};
|
|
133
|
+
|
|
134
|
+
// src/fragments/accountFetchHelpers.ts
|
|
135
|
+
import { getLastNodeFromPath } from "@codama/visitors-core";
|
|
136
|
+
|
|
137
|
+
// src/fragments/common.ts
|
|
138
|
+
import { join as join2 } from "node:path";
|
|
139
|
+
|
|
140
|
+
// src/utils/async.ts
|
|
141
|
+
import {
|
|
142
|
+
accountValueNode,
|
|
143
|
+
argumentValueNode,
|
|
144
|
+
isNode
|
|
145
|
+
} from "@codama/nodes";
|
|
146
|
+
import { deduplicateInstructionDependencies } from "@codama/visitors-core";
|
|
145
147
|
function hasAsyncFunction(instructionNode, resolvedInputs, asyncResolvers) {
|
|
146
148
|
const hasByteDeltasAsync = (instructionNode.byteDeltas ?? []).some(
|
|
147
149
|
({ value }) => isNode(value, "resolverValueNode") && asyncResolvers.includes(value.name)
|
|
@@ -211,6 +213,9 @@ function getInstructionDependencies(input, asyncResolvers, useAsync) {
|
|
|
211
213
|
}
|
|
212
214
|
return [];
|
|
213
215
|
}
|
|
216
|
+
|
|
217
|
+
// src/utils/codecs.ts
|
|
218
|
+
import { getBase16Encoder, getBase58Encoder, getBase64Encoder, getUtf8Encoder } from "@solana/codecs-strings";
|
|
214
219
|
function getBytesFromBytesValueNode(node) {
|
|
215
220
|
switch (node.encoding) {
|
|
216
221
|
case "utf8":
|
|
@@ -224,6 +229,15 @@ function getBytesFromBytesValueNode(node) {
|
|
|
224
229
|
return getBase64Encoder().encode(node.data);
|
|
225
230
|
}
|
|
226
231
|
}
|
|
232
|
+
|
|
233
|
+
// src/utils/customData.ts
|
|
234
|
+
import {
|
|
235
|
+
camelCase,
|
|
236
|
+
definedTypeLinkNode,
|
|
237
|
+
definedTypeNode,
|
|
238
|
+
isNode as isNode2,
|
|
239
|
+
structTypeNodeFromInstructionArgumentNodes
|
|
240
|
+
} from "@codama/nodes";
|
|
227
241
|
var parseCustomDataOptions = (customDataOptions, defaultSuffix) => new Map(
|
|
228
242
|
customDataOptions.map((o) => {
|
|
229
243
|
const options = typeof o === "string" ? { name: o } : o;
|
|
@@ -244,7 +258,7 @@ var parseCustomDataOptions = (customDataOptions, defaultSuffix) => new Map(
|
|
|
244
258
|
var getDefinedTypeNodesToExtract = (nodes, parsedCustomDataOptions) => nodes.flatMap((node) => {
|
|
245
259
|
const options = parsedCustomDataOptions.get(node.name);
|
|
246
260
|
if (!options || !options.extract) return [];
|
|
247
|
-
if (
|
|
261
|
+
if (isNode2(node, "accountNode")) {
|
|
248
262
|
return [definedTypeNode({ name: options.extractAs, type: { ...node.data } })];
|
|
249
263
|
}
|
|
250
264
|
return [
|
|
@@ -254,6 +268,9 @@ var getDefinedTypeNodesToExtract = (nodes, parsedCustomDataOptions) => nodes.fla
|
|
|
254
268
|
})
|
|
255
269
|
];
|
|
256
270
|
});
|
|
271
|
+
|
|
272
|
+
// src/utils/linkOverrides.ts
|
|
273
|
+
import { CODAMA_ERROR__UNEXPECTED_NODE_KIND, CodamaError } from "@codama/errors";
|
|
257
274
|
function getImportFromFactory(overrides, customAccountData, customInstructionData) {
|
|
258
275
|
const customDataOverrides = Object.fromEntries(
|
|
259
276
|
[...customAccountData.values(), ...customInstructionData.values()].map(({ importFrom, importAs }) => [
|
|
@@ -300,6 +317,12 @@ function getImportFromFactory(overrides, customAccountData, customInstructionDat
|
|
|
300
317
|
}
|
|
301
318
|
};
|
|
302
319
|
}
|
|
320
|
+
|
|
321
|
+
// src/utils/render.ts
|
|
322
|
+
import { dirname as pathDirname, join } from "node:path";
|
|
323
|
+
import { fileURLToPath } from "node:url";
|
|
324
|
+
import { camelCase as camelCase2, kebabCase, pascalCase, snakeCase, titleCase } from "@codama/nodes";
|
|
325
|
+
import nunjucks from "nunjucks";
|
|
303
326
|
function jsDocblock(docs) {
|
|
304
327
|
if (docs.length <= 0) return "";
|
|
305
328
|
if (docs.length === 1) return `/** ${docs[0]} */
|
|
@@ -311,11 +334,11 @@ ${lines.join("\n")}
|
|
|
311
334
|
`;
|
|
312
335
|
}
|
|
313
336
|
var render = (template, context, options) => {
|
|
314
|
-
const dirname
|
|
315
|
-
const templates = join(dirname
|
|
337
|
+
const dirname = true ? pathDirname(fileURLToPath(import.meta.url)) : __dirname;
|
|
338
|
+
const templates = false ? join(dirname, "..", "..", "public", "templates") : join(dirname, "templates");
|
|
316
339
|
const env = nunjucks.configure(templates, { autoescape: false, trimBlocks: true, ...options });
|
|
317
340
|
env.addFilter("pascalCase", pascalCase);
|
|
318
|
-
env.addFilter("camelCase",
|
|
341
|
+
env.addFilter("camelCase", camelCase2);
|
|
319
342
|
env.addFilter("snakeCase", snakeCase);
|
|
320
343
|
env.addFilter("kebabCase", kebabCase);
|
|
321
344
|
env.addFilter("titleCase", titleCase);
|
|
@@ -328,7 +351,7 @@ function fragment(render2, imports) {
|
|
|
328
351
|
return new Fragment(render2, imports);
|
|
329
352
|
}
|
|
330
353
|
function fragmentFromTemplate(fragmentFile, context, options) {
|
|
331
|
-
return fragment(render(
|
|
354
|
+
return fragment(render(join2("fragments", fragmentFile), context, options));
|
|
332
355
|
}
|
|
333
356
|
function mergeFragments(fragments, mergeRenders) {
|
|
334
357
|
return new Fragment(
|
|
@@ -425,11 +448,15 @@ function getAccountFetchHelpersFragment(scope) {
|
|
|
425
448
|
"type MaybeEncodedAccount"
|
|
426
449
|
]);
|
|
427
450
|
}
|
|
451
|
+
|
|
452
|
+
// src/fragments/accountPdaHelpers.ts
|
|
453
|
+
import { isNodeFilter } from "@codama/nodes";
|
|
454
|
+
import { findProgramNodeFromPath, getLastNodeFromPath as getLastNodeFromPath2 } from "@codama/visitors-core";
|
|
428
455
|
function getAccountPdaHelpersFragment(scope) {
|
|
429
456
|
const { accountPath, nameApi, linkables, customAccountData, typeManifest: typeManifest2 } = scope;
|
|
430
|
-
const accountNode =
|
|
457
|
+
const accountNode = getLastNodeFromPath2(accountPath);
|
|
431
458
|
const programNode = findProgramNodeFromPath(accountPath);
|
|
432
|
-
const pdaNode = accountNode.pda ? linkables.get([...accountPath, accountNode.pda]) :
|
|
459
|
+
const pdaNode = accountNode.pda ? linkables.get([...accountPath, accountNode.pda]) : void 0;
|
|
433
460
|
if (!pdaNode) {
|
|
434
461
|
return fragment("");
|
|
435
462
|
}
|
|
@@ -455,9 +482,12 @@ function getAccountPdaHelpersFragment(scope) {
|
|
|
455
482
|
"type MaybeAccount"
|
|
456
483
|
]);
|
|
457
484
|
}
|
|
485
|
+
|
|
486
|
+
// src/fragments/accountSizeHelpers.ts
|
|
487
|
+
import { getLastNodeFromPath as getLastNodeFromPath3 } from "@codama/visitors-core";
|
|
458
488
|
function getAccountSizeHelpersFragment(scope) {
|
|
459
489
|
const { accountPath, nameApi } = scope;
|
|
460
|
-
const accountNode =
|
|
490
|
+
const accountNode = getLastNodeFromPath3(accountPath);
|
|
461
491
|
if (accountNode.size == null) {
|
|
462
492
|
return fragment("");
|
|
463
493
|
}
|
|
@@ -467,6 +497,9 @@ function getAccountSizeHelpersFragment(scope) {
|
|
|
467
497
|
});
|
|
468
498
|
}
|
|
469
499
|
|
|
500
|
+
// src/fragments/accountType.ts
|
|
501
|
+
import { getLastNodeFromPath as getLastNodeFromPath4 } from "@codama/visitors-core";
|
|
502
|
+
|
|
470
503
|
// src/fragments/type.ts
|
|
471
504
|
function getTypeFragment(scope) {
|
|
472
505
|
const { name, manifest, nameApi, docs = [] } = scope;
|
|
@@ -538,7 +571,7 @@ function getTypeWithCodecFragment(scope) {
|
|
|
538
571
|
// src/fragments/accountType.ts
|
|
539
572
|
function getAccountTypeFragment(scope) {
|
|
540
573
|
const { accountPath, typeManifest: typeManifest2, nameApi, customAccountData } = scope;
|
|
541
|
-
const accountNode =
|
|
574
|
+
const accountNode = getLastNodeFromPath4(accountPath);
|
|
542
575
|
if (customAccountData.has(accountNode.name)) {
|
|
543
576
|
return fragment("");
|
|
544
577
|
}
|
|
@@ -548,16 +581,27 @@ function getAccountTypeFragment(scope) {
|
|
|
548
581
|
nameApi
|
|
549
582
|
});
|
|
550
583
|
}
|
|
584
|
+
|
|
585
|
+
// src/fragments/discriminatorCondition.ts
|
|
586
|
+
import {
|
|
587
|
+
constantDiscriminatorNode,
|
|
588
|
+
constantValueNode,
|
|
589
|
+
constantValueNodeFromBytes,
|
|
590
|
+
isNode as isNode3,
|
|
591
|
+
isNodeFilter as isNodeFilter2
|
|
592
|
+
} from "@codama/nodes";
|
|
593
|
+
import { visit } from "@codama/visitors-core";
|
|
594
|
+
import { getBase64Decoder } from "@solana/codecs-strings";
|
|
551
595
|
function getDiscriminatorConditionFragment(scope) {
|
|
552
596
|
return mergeFragments(
|
|
553
597
|
scope.discriminators.flatMap((discriminator) => {
|
|
554
|
-
if (
|
|
598
|
+
if (isNode3(discriminator, "sizeDiscriminatorNode")) {
|
|
555
599
|
return [getSizeConditionFragment(discriminator, scope)];
|
|
556
600
|
}
|
|
557
|
-
if (
|
|
601
|
+
if (isNode3(discriminator, "constantDiscriminatorNode")) {
|
|
558
602
|
return [getByteConditionFragment(discriminator, scope)];
|
|
559
603
|
}
|
|
560
|
-
if (
|
|
604
|
+
if (isNode3(discriminator, "fieldDiscriminatorNode")) {
|
|
561
605
|
return [getFieldConditionFragment(discriminator, scope)];
|
|
562
606
|
}
|
|
563
607
|
return [];
|
|
@@ -581,7 +625,7 @@ function getFieldConditionFragment(discriminator, scope) {
|
|
|
581
625
|
`Field discriminator "${discriminator.name}" does not have a matching argument with default value.`
|
|
582
626
|
);
|
|
583
627
|
}
|
|
584
|
-
if (
|
|
628
|
+
if (isNode3(field.type, "arrayTypeNode") && isNode3(field.type.item, "numberTypeNode") && field.type.item.format === "u8" && isNode3(field.type.count, "fixedCountNode") && isNode3(field.defaultValue, "arrayValueNode") && field.defaultValue.items.every(isNodeFilter2("numberValueNode"))) {
|
|
585
629
|
const base64Bytes = getBase64Decoder().decode(
|
|
586
630
|
new Uint8Array(field.defaultValue.items.map((node) => node.number))
|
|
587
631
|
);
|
|
@@ -595,8 +639,11 @@ function getFieldConditionFragment(discriminator, scope) {
|
|
|
595
639
|
scope
|
|
596
640
|
);
|
|
597
641
|
}
|
|
642
|
+
|
|
643
|
+
// src/fragments/instructionAccountMeta.ts
|
|
644
|
+
import { pascalCase as pascalCase2 } from "@codama/nodes";
|
|
598
645
|
function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
599
|
-
const typeParam = `TAccount${
|
|
646
|
+
const typeParam = `TAccount${pascalCase2(instructionAccountNode.name)}`;
|
|
600
647
|
if (instructionAccountNode.isSigner === true && instructionAccountNode.isWritable) {
|
|
601
648
|
return fragment(`WritableSignerAccount<${typeParam}> & IAccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type WritableSignerAccount"]).addImports("solanaSigners", ["type IAccountSignerMeta"]);
|
|
602
649
|
}
|
|
@@ -608,12 +655,20 @@ function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
|
608
655
|
}
|
|
609
656
|
return fragment(`ReadonlyAccount<${typeParam}>`).addImports("solanaInstructions", "type ReadonlyAccount");
|
|
610
657
|
}
|
|
658
|
+
|
|
659
|
+
// src/fragments/instructionAccountTypeParam.ts
|
|
660
|
+
import { pascalCase as pascalCase3 } from "@codama/nodes";
|
|
661
|
+
import {
|
|
662
|
+
findInstructionNodeFromPath,
|
|
663
|
+
findProgramNodeFromPath as findProgramNodeFromPath2,
|
|
664
|
+
getLastNodeFromPath as getLastNodeFromPath5
|
|
665
|
+
} from "@codama/visitors-core";
|
|
611
666
|
function getInstructionAccountTypeParamFragment(scope) {
|
|
612
667
|
const { instructionAccountPath, allowAccountMeta, linkables } = scope;
|
|
613
|
-
const instructionAccountNode =
|
|
668
|
+
const instructionAccountNode = getLastNodeFromPath5(instructionAccountPath);
|
|
614
669
|
const instructionNode = findInstructionNodeFromPath(instructionAccountPath);
|
|
615
|
-
const programNode =
|
|
616
|
-
const typeParam = `TAccount${
|
|
670
|
+
const programNode = findProgramNodeFromPath2(instructionAccountPath);
|
|
671
|
+
const typeParam = `TAccount${pascalCase3(instructionAccountNode.name)}`;
|
|
617
672
|
const accountMeta = allowAccountMeta ? " | IAccountMeta<string>" : "";
|
|
618
673
|
const imports = new ImportMap();
|
|
619
674
|
if (allowAccountMeta) {
|
|
@@ -638,8 +693,12 @@ function getDefaultAddress(defaultValue, programId, linkables) {
|
|
|
638
693
|
return "string";
|
|
639
694
|
}
|
|
640
695
|
}
|
|
696
|
+
|
|
697
|
+
// src/fragments/instructionByteDelta.ts
|
|
698
|
+
import { assertIsNode, camelCase as camelCase3, isNode as isNode4 } from "@codama/nodes";
|
|
699
|
+
import { getLastNodeFromPath as getLastNodeFromPath6 } from "@codama/visitors-core";
|
|
641
700
|
function getInstructionByteDeltaFragment(scope) {
|
|
642
|
-
const { byteDeltas } =
|
|
701
|
+
const { byteDeltas } = getLastNodeFromPath6(scope.instructionPath);
|
|
643
702
|
const fragments = (byteDeltas ?? []).flatMap((r) => getByteDeltaFragment(r, scope));
|
|
644
703
|
if (fragments.length === 0) return fragment("");
|
|
645
704
|
return mergeFragments(
|
|
@@ -650,16 +709,16 @@ const byteDelta: number = [${r.join(",")}].reduce((a, b) => a + b, 0);`
|
|
|
650
709
|
}
|
|
651
710
|
function getByteDeltaFragment(byteDelta, scope) {
|
|
652
711
|
const bytesFragment = (() => {
|
|
653
|
-
if (
|
|
712
|
+
if (isNode4(byteDelta.value, "numberValueNode")) {
|
|
654
713
|
return getNumberValueNodeFragment(byteDelta);
|
|
655
714
|
}
|
|
656
|
-
if (
|
|
715
|
+
if (isNode4(byteDelta.value, "argumentValueNode")) {
|
|
657
716
|
return getArgumentValueNodeFragment(byteDelta);
|
|
658
717
|
}
|
|
659
|
-
if (
|
|
718
|
+
if (isNode4(byteDelta.value, "accountLinkNode")) {
|
|
660
719
|
return getAccountLinkNodeFragment(byteDelta, scope);
|
|
661
720
|
}
|
|
662
|
-
if (
|
|
721
|
+
if (isNode4(byteDelta.value, "resolverValueNode")) {
|
|
663
722
|
return getResolverValueNodeFragment(byteDelta, scope);
|
|
664
723
|
}
|
|
665
724
|
return null;
|
|
@@ -679,7 +738,7 @@ function getNumberValueNodeFragment(byteDelta) {
|
|
|
679
738
|
}
|
|
680
739
|
function getArgumentValueNodeFragment(byteDelta) {
|
|
681
740
|
assertIsNode(byteDelta.value, "argumentValueNode");
|
|
682
|
-
const argumentName =
|
|
741
|
+
const argumentName = camelCase3(byteDelta.value.name);
|
|
683
742
|
return fragment(`Number(args.${argumentName})`);
|
|
684
743
|
}
|
|
685
744
|
function getAccountLinkNodeFragment(byteDelta, scope) {
|
|
@@ -695,9 +754,12 @@ function getResolverValueNodeFragment(byteDelta, scope) {
|
|
|
695
754
|
const functionName = scope.nameApi.resolverFunction(byteDelta.value.name);
|
|
696
755
|
return fragment(`${awaitKeyword}${functionName}(resolverScope)`).addImports(scope.getImportFrom(byteDelta.value), functionName).addFeatures(["instruction:resolverScopeVariable"]);
|
|
697
756
|
}
|
|
757
|
+
|
|
758
|
+
// src/fragments/instructionData.ts
|
|
759
|
+
import { getLastNodeFromPath as getLastNodeFromPath7 } from "@codama/visitors-core";
|
|
698
760
|
function getInstructionDataFragment(scope) {
|
|
699
761
|
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
700
|
-
const instructionNode =
|
|
762
|
+
const instructionNode = getLastNodeFromPath7(instructionPath);
|
|
701
763
|
if (instructionNode.arguments.length === 0 || customInstructionData.has(instructionNode.name)) {
|
|
702
764
|
return fragment("");
|
|
703
765
|
}
|
|
@@ -708,6 +770,15 @@ function getInstructionDataFragment(scope) {
|
|
|
708
770
|
nameApi
|
|
709
771
|
});
|
|
710
772
|
}
|
|
773
|
+
|
|
774
|
+
// src/fragments/discriminatorConstants.ts
|
|
775
|
+
import {
|
|
776
|
+
camelCase as camelCase4,
|
|
777
|
+
isNode as isNode5,
|
|
778
|
+
isNodeFilter as isNodeFilter3,
|
|
779
|
+
VALUE_NODES
|
|
780
|
+
} from "@codama/nodes";
|
|
781
|
+
import { visit as visit2 } from "@codama/visitors-core";
|
|
711
782
|
function getDiscriminatorConstantsFragment(scope) {
|
|
712
783
|
const fragments = scope.discriminatorNodes.map((node) => getDiscriminatorConstantFragment(node, scope)).filter(Boolean);
|
|
713
784
|
return mergeFragments(fragments, (r) => r.join("\n\n"));
|
|
@@ -724,22 +795,22 @@ function getDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
|
724
795
|
}
|
|
725
796
|
function getConstantDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
726
797
|
const { discriminatorNodes, typeManifestVisitor, prefix } = scope;
|
|
727
|
-
const index = discriminatorNodes.filter(
|
|
798
|
+
const index = discriminatorNodes.filter(isNodeFilter3("constantDiscriminatorNode")).indexOf(discriminatorNode);
|
|
728
799
|
const suffix = index <= 0 ? "" : `_${index + 1}`;
|
|
729
|
-
const name =
|
|
730
|
-
const encoder =
|
|
731
|
-
const value =
|
|
800
|
+
const name = camelCase4(`${prefix}_discriminator${suffix}`);
|
|
801
|
+
const encoder = visit2(discriminatorNode.constant.type, typeManifestVisitor).encoder;
|
|
802
|
+
const value = visit2(discriminatorNode.constant.value, typeManifestVisitor).value;
|
|
732
803
|
return getConstantFragment({ ...scope, encoder, name, value });
|
|
733
804
|
}
|
|
734
805
|
function getFieldDiscriminatorConstantFragment(discriminatorNode, scope) {
|
|
735
806
|
const { fields, prefix, typeManifestVisitor } = scope;
|
|
736
807
|
const field = fields.find((f) => f.name === discriminatorNode.name);
|
|
737
|
-
if (!field || !field.defaultValue || !
|
|
808
|
+
if (!field || !field.defaultValue || !isNode5(field.defaultValue, VALUE_NODES)) {
|
|
738
809
|
return null;
|
|
739
810
|
}
|
|
740
|
-
const name =
|
|
741
|
-
const encoder =
|
|
742
|
-
const value =
|
|
811
|
+
const name = camelCase4(`${prefix}_${discriminatorNode.name}`);
|
|
812
|
+
const encoder = visit2(field.type, typeManifestVisitor).encoder;
|
|
813
|
+
const value = visit2(field.defaultValue, typeManifestVisitor).value;
|
|
743
814
|
return getConstantFragment({ ...scope, encoder, name, value });
|
|
744
815
|
}
|
|
745
816
|
function getConstantFragment(scope) {
|
|
@@ -754,9 +825,12 @@ function getConstantFragment(scope) {
|
|
|
754
825
|
(r) => r.join("\n\n")
|
|
755
826
|
);
|
|
756
827
|
}
|
|
828
|
+
|
|
829
|
+
// src/fragments/instructionExtraArgs.ts
|
|
830
|
+
import { getLastNodeFromPath as getLastNodeFromPath8 } from "@codama/visitors-core";
|
|
757
831
|
function getInstructionExtraArgsFragment(scope) {
|
|
758
832
|
const { instructionPath, extraArgsManifest, nameApi } = scope;
|
|
759
|
-
const instructionNode =
|
|
833
|
+
const instructionNode = getLastNodeFromPath8(instructionPath);
|
|
760
834
|
if ((instructionNode.extraArguments ?? []).length === 0) {
|
|
761
835
|
return fragment("");
|
|
762
836
|
}
|
|
@@ -767,6 +841,21 @@ function getInstructionExtraArgsFragment(scope) {
|
|
|
767
841
|
strictName: nameApi.dataType(instructionExtraName)
|
|
768
842
|
}).mergeImportsWith(extraArgsManifest.looseType);
|
|
769
843
|
}
|
|
844
|
+
|
|
845
|
+
// src/fragments/instructionFunction.ts
|
|
846
|
+
import { camelCase as camelCase9, isNode as isNode10, isNodeFilter as isNodeFilter4, pascalCase as pascalCase5 } from "@codama/nodes";
|
|
847
|
+
import {
|
|
848
|
+
findProgramNodeFromPath as findProgramNodeFromPath3,
|
|
849
|
+
getLastNodeFromPath as getLastNodeFromPath12
|
|
850
|
+
} from "@codama/visitors-core";
|
|
851
|
+
|
|
852
|
+
// src/fragments/instructionInputResolved.ts
|
|
853
|
+
import { camelCase as camelCase6, isNode as isNode7 } from "@codama/nodes";
|
|
854
|
+
import { getLastNodeFromPath as getLastNodeFromPath9 } from "@codama/visitors-core";
|
|
855
|
+
|
|
856
|
+
// src/fragments/instructionInputDefault.ts
|
|
857
|
+
import { camelCase as camelCase5, isNode as isNode6 } from "@codama/nodes";
|
|
858
|
+
import { visit as visit3 } from "@codama/visitors-core";
|
|
770
859
|
function getInstructionInputDefaultFragment(scope) {
|
|
771
860
|
const { input, optionalAccountStrategy, asyncResolvers, useAsync, nameApi, typeManifestVisitor, getImportFrom } = scope;
|
|
772
861
|
if (!input.defaultValue) {
|
|
@@ -777,11 +866,11 @@ function getInstructionInputDefaultFragment(scope) {
|
|
|
777
866
|
}
|
|
778
867
|
const { defaultValue } = input;
|
|
779
868
|
const defaultFragment = (renderedValue, isWritable) => {
|
|
780
|
-
const inputName =
|
|
781
|
-
if (input.kind === "instructionAccountNode" &&
|
|
869
|
+
const inputName = camelCase5(input.name);
|
|
870
|
+
if (input.kind === "instructionAccountNode" && isNode6(defaultValue, "resolverValueNode")) {
|
|
782
871
|
return fragment(`accounts.${inputName} = { ...accounts.${inputName}, ...${renderedValue} };`);
|
|
783
872
|
}
|
|
784
|
-
if (input.kind === "instructionAccountNode" && isWritable ===
|
|
873
|
+
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
785
874
|
return fragment(`accounts.${inputName}.value = ${renderedValue};`);
|
|
786
875
|
}
|
|
787
876
|
if (input.kind === "instructionAccountNode") {
|
|
@@ -794,7 +883,7 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
794
883
|
};
|
|
795
884
|
switch (defaultValue.kind) {
|
|
796
885
|
case "accountValueNode":
|
|
797
|
-
const name =
|
|
886
|
+
const name = camelCase5(defaultValue.name);
|
|
798
887
|
if (input.kind === "instructionAccountNode" && input.resolvedIsSigner && !input.isSigner) {
|
|
799
888
|
return defaultFragment(`expectTransactionSigner(accounts.${name}.value).address`).addImports(
|
|
800
889
|
"shared",
|
|
@@ -806,44 +895,44 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
806
895
|
}
|
|
807
896
|
return defaultFragment(`expectAddress(accounts.${name}.value)`).addImports("shared", "expectAddress");
|
|
808
897
|
case "pdaValueNode":
|
|
809
|
-
if (
|
|
898
|
+
if (isNode6(defaultValue.pda, "pdaNode")) {
|
|
810
899
|
const pdaProgram = defaultValue.pda.programId ? fragment(
|
|
811
900
|
`'${defaultValue.pda.programId}' as Address<'${defaultValue.pda.programId}'>`
|
|
812
901
|
).addImports("solanaAddresses", "type Address") : fragment("programAddress");
|
|
813
902
|
const pdaSeeds2 = defaultValue.pda.seeds.flatMap((seed) => {
|
|
814
|
-
if (
|
|
903
|
+
if (isNode6(seed, "constantPdaSeedNode") && isNode6(seed.value, "programIdValueNode")) {
|
|
815
904
|
return [
|
|
816
905
|
fragment(`getAddressEncoder().encode(${pdaProgram.render})`).mergeImportsWith(pdaProgram).addImports("solanaAddresses", "getAddressEncoder")
|
|
817
906
|
];
|
|
818
907
|
}
|
|
819
|
-
if (
|
|
820
|
-
const typeManifest2 =
|
|
821
|
-
const valueManifest2 =
|
|
908
|
+
if (isNode6(seed, "constantPdaSeedNode") && !isNode6(seed.value, "programIdValueNode")) {
|
|
909
|
+
const typeManifest2 = visit3(seed.type, typeManifestVisitor);
|
|
910
|
+
const valueManifest2 = visit3(seed.value, typeManifestVisitor);
|
|
822
911
|
return [
|
|
823
912
|
fragment(
|
|
824
913
|
`${typeManifest2.encoder.render}.encode(${valueManifest2.value.render})`
|
|
825
914
|
).mergeImportsWith(typeManifest2.encoder, valueManifest2.value)
|
|
826
915
|
];
|
|
827
916
|
}
|
|
828
|
-
if (
|
|
829
|
-
const typeManifest2 =
|
|
917
|
+
if (isNode6(seed, "variablePdaSeedNode")) {
|
|
918
|
+
const typeManifest2 = visit3(seed.type, typeManifestVisitor);
|
|
830
919
|
const valueSeed = defaultValue.seeds.find((s) => s.name === seed.name)?.value;
|
|
831
920
|
if (!valueSeed) return [];
|
|
832
|
-
if (
|
|
921
|
+
if (isNode6(valueSeed, "accountValueNode")) {
|
|
833
922
|
return [
|
|
834
923
|
fragment(
|
|
835
|
-
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${
|
|
924
|
+
`${typeManifest2.encoder.render}.encode(expectAddress(accounts.${camelCase5(valueSeed.name)}.value))`
|
|
836
925
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectAddress")
|
|
837
926
|
];
|
|
838
927
|
}
|
|
839
|
-
if (
|
|
928
|
+
if (isNode6(valueSeed, "argumentValueNode")) {
|
|
840
929
|
return [
|
|
841
930
|
fragment(
|
|
842
|
-
`${typeManifest2.encoder.render}.encode(expectSome(args.${
|
|
931
|
+
`${typeManifest2.encoder.render}.encode(expectSome(args.${camelCase5(valueSeed.name)}))`
|
|
843
932
|
).mergeImportsWith(typeManifest2.encoder).addImports("shared", "expectSome")
|
|
844
933
|
];
|
|
845
934
|
}
|
|
846
|
-
const valueManifest2 =
|
|
935
|
+
const valueManifest2 = visit3(valueSeed, typeManifestVisitor);
|
|
847
936
|
return [
|
|
848
937
|
fragment(
|
|
849
938
|
`${typeManifest2.encoder.render}.encode(${valueManifest2.value.render})`
|
|
@@ -861,18 +950,18 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
861
950
|
const pdaFunction = nameApi.pdaFindFunction(defaultValue.pda.name);
|
|
862
951
|
const pdaArgs = [];
|
|
863
952
|
const pdaSeeds = defaultValue.seeds.map((seed) => {
|
|
864
|
-
if (
|
|
953
|
+
if (isNode6(seed.value, "accountValueNode")) {
|
|
865
954
|
return fragment(
|
|
866
|
-
`${seed.name}: expectAddress(accounts.${
|
|
955
|
+
`${seed.name}: expectAddress(accounts.${camelCase5(seed.value.name)}.value)`
|
|
867
956
|
).addImports("shared", "expectAddress");
|
|
868
957
|
}
|
|
869
|
-
if (
|
|
870
|
-
return fragment(`${seed.name}: expectSome(args.${
|
|
958
|
+
if (isNode6(seed.value, "argumentValueNode")) {
|
|
959
|
+
return fragment(`${seed.name}: expectSome(args.${camelCase5(seed.value.name)})`).addImports(
|
|
871
960
|
"shared",
|
|
872
961
|
"expectSome"
|
|
873
962
|
);
|
|
874
963
|
}
|
|
875
|
-
return
|
|
964
|
+
return visit3(seed.value, typeManifestVisitor).value.mapRender((r) => `${seed.name}: ${r}`);
|
|
876
965
|
});
|
|
877
966
|
const pdaSeedsFragment = mergeFragments(pdaSeeds, (renders) => renders.join(", ")).mapRender((r) => `{ ${r} }`);
|
|
878
967
|
if (pdaSeeds.length > 0) {
|
|
@@ -897,10 +986,10 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
897
986
|
return fragment("");
|
|
898
987
|
case "accountBumpValueNode":
|
|
899
988
|
return defaultFragment(
|
|
900
|
-
`expectProgramDerivedAddress(accounts.${
|
|
989
|
+
`expectProgramDerivedAddress(accounts.${camelCase5(defaultValue.name)}.value)[1]`
|
|
901
990
|
).addImports("shared", "expectProgramDerivedAddress");
|
|
902
991
|
case "argumentValueNode":
|
|
903
|
-
return defaultFragment(`expectSome(args.${
|
|
992
|
+
return defaultFragment(`expectSome(args.${camelCase5(defaultValue.name)})`).addImports(
|
|
904
993
|
"shared",
|
|
905
994
|
"expectSome"
|
|
906
995
|
);
|
|
@@ -929,16 +1018,16 @@ accounts.${inputName}.isWritable = ${isWritable ? "true" : "false"}`
|
|
|
929
1018
|
}
|
|
930
1019
|
const negatedCondition = !ifTrueRenderer;
|
|
931
1020
|
let condition = "true";
|
|
932
|
-
if (
|
|
1021
|
+
if (isNode6(defaultValue.condition, "resolverValueNode")) {
|
|
933
1022
|
const conditionalResolverFunction = nameApi.resolverFunction(defaultValue.condition.name);
|
|
934
1023
|
conditionalFragment.addImports(getImportFrom(defaultValue.condition), conditionalResolverFunction).addFeatures(["instruction:resolverScopeVariable"]);
|
|
935
1024
|
const conditionalResolverAwait = useAsync && asyncResolvers.includes(defaultValue.condition.name) ? "await " : "";
|
|
936
1025
|
condition = `${conditionalResolverAwait}${conditionalResolverFunction}(resolverScope)`;
|
|
937
1026
|
condition = negatedCondition ? `!${condition}` : condition;
|
|
938
1027
|
} else {
|
|
939
|
-
const comparedInputName =
|
|
1028
|
+
const comparedInputName = isNode6(defaultValue.condition, "accountValueNode") ? `accounts.${camelCase5(defaultValue.condition.name)}.value` : `args.${camelCase5(defaultValue.condition.name)}`;
|
|
940
1029
|
if (defaultValue.value) {
|
|
941
|
-
const comparedValue =
|
|
1030
|
+
const comparedValue = visit3(defaultValue.value, typeManifestVisitor).value;
|
|
942
1031
|
conditionalFragment.mergeImportsWith(comparedValue).mergeFeaturesWith(comparedValue);
|
|
943
1032
|
const operator = negatedCondition ? "!==" : "===";
|
|
944
1033
|
condition = `${comparedInputName} ${operator} ${comparedValue.render}`;
|
|
@@ -961,13 +1050,13 @@ ${ifTrueRenderer ? ifTrueRenderer.render : ifFalseRenderer?.render}
|
|
|
961
1050
|
}`
|
|
962
1051
|
);
|
|
963
1052
|
default:
|
|
964
|
-
const valueManifest =
|
|
1053
|
+
const valueManifest = visit3(defaultValue, typeManifestVisitor).value;
|
|
965
1054
|
return defaultFragment(valueManifest.render).mergeImportsWith(valueManifest);
|
|
966
1055
|
}
|
|
967
1056
|
}
|
|
968
1057
|
function renderNestedInstructionDefault(scope) {
|
|
969
1058
|
const { input, defaultValue } = scope;
|
|
970
|
-
if (!defaultValue) return
|
|
1059
|
+
if (!defaultValue) return void 0;
|
|
971
1060
|
return getInstructionInputDefaultFragment({
|
|
972
1061
|
...scope,
|
|
973
1062
|
input: { ...input, defaultValue }
|
|
@@ -976,7 +1065,7 @@ function renderNestedInstructionDefault(scope) {
|
|
|
976
1065
|
|
|
977
1066
|
// src/fragments/instructionInputResolved.ts
|
|
978
1067
|
function getInstructionInputResolvedFragment(scope) {
|
|
979
|
-
const instructionNode =
|
|
1068
|
+
const instructionNode = getLastNodeFromPath9(scope.instructionPath);
|
|
980
1069
|
const resolvedInputFragments = scope.resolvedInputs.flatMap((input) => {
|
|
981
1070
|
const inputFragment = getInstructionInputDefaultFragment({
|
|
982
1071
|
...scope,
|
|
@@ -984,10 +1073,10 @@ function getInstructionInputResolvedFragment(scope) {
|
|
|
984
1073
|
optionalAccountStrategy: instructionNode.optionalAccountStrategy
|
|
985
1074
|
});
|
|
986
1075
|
if (!inputFragment.render) return [];
|
|
987
|
-
const camelName =
|
|
1076
|
+
const camelName = camelCase6(input.name);
|
|
988
1077
|
return [
|
|
989
1078
|
inputFragment.mapRender(
|
|
990
|
-
(r) =>
|
|
1079
|
+
(r) => isNode7(input, "instructionArgumentNode") ? `if (!args.${camelName}) {
|
|
991
1080
|
${r}
|
|
992
1081
|
}` : `if (!accounts.${camelName}.value) {
|
|
993
1082
|
${r}
|
|
@@ -1003,9 +1092,20 @@ ${r}
|
|
|
1003
1092
|
(renders) => renders.join("\n")
|
|
1004
1093
|
);
|
|
1005
1094
|
}
|
|
1095
|
+
|
|
1096
|
+
// src/fragments/instructionInputType.ts
|
|
1097
|
+
import {
|
|
1098
|
+
camelCase as camelCase7,
|
|
1099
|
+
getAllInstructionArguments,
|
|
1100
|
+
isNode as isNode8,
|
|
1101
|
+
pascalCase as pascalCase4
|
|
1102
|
+
} from "@codama/nodes";
|
|
1103
|
+
import {
|
|
1104
|
+
getLastNodeFromPath as getLastNodeFromPath10
|
|
1105
|
+
} from "@codama/visitors-core";
|
|
1006
1106
|
function getInstructionInputTypeFragment(scope) {
|
|
1007
1107
|
const { instructionPath, useAsync, nameApi } = scope;
|
|
1008
|
-
const instructionNode =
|
|
1108
|
+
const instructionNode = getLastNodeFromPath10(instructionPath);
|
|
1009
1109
|
const instructionInputType = useAsync ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name);
|
|
1010
1110
|
const accountsFragment = getAccountsFragment(scope);
|
|
1011
1111
|
const [dataArgumentsFragment, customDataArgumentsFragment] = getDataArgumentsFragments(scope);
|
|
@@ -1029,22 +1129,22 @@ function getInstructionInputTypeFragment(scope) {
|
|
|
1029
1129
|
}
|
|
1030
1130
|
function getAccountsFragment(scope) {
|
|
1031
1131
|
const { instructionPath, resolvedInputs, useAsync, asyncResolvers } = scope;
|
|
1032
|
-
const instructionNode =
|
|
1132
|
+
const instructionNode = getLastNodeFromPath10(instructionPath);
|
|
1033
1133
|
const fragments = instructionNode.accounts.map((account) => {
|
|
1034
1134
|
const resolvedAccount = resolvedInputs.find(
|
|
1035
1135
|
(input) => input.kind === "instructionAccountNode" && input.name === account.name
|
|
1036
1136
|
);
|
|
1037
|
-
const hasDefaultValue = !!resolvedAccount.defaultValue && !
|
|
1137
|
+
const hasDefaultValue = !!resolvedAccount.defaultValue && !isNode8(resolvedAccount.defaultValue, ["identityValueNode", "payerValueNode"]) && (useAsync || !isAsyncDefaultValue(resolvedAccount.defaultValue, asyncResolvers));
|
|
1038
1138
|
const docblock = account.docs.length > 0 ? jsDocblock(account.docs) : "";
|
|
1039
1139
|
const optionalSign = hasDefaultValue || resolvedAccount.isOptional ? "?" : "";
|
|
1040
1140
|
return getAccountTypeFragment2(resolvedAccount).mapRender(
|
|
1041
|
-
(r) => `${docblock}${
|
|
1141
|
+
(r) => `${docblock}${camelCase7(account.name)}${optionalSign}: ${r};`
|
|
1042
1142
|
);
|
|
1043
1143
|
});
|
|
1044
1144
|
return mergeFragments(fragments, (r) => r.join("\n"));
|
|
1045
1145
|
}
|
|
1046
1146
|
function getAccountTypeFragment2(account) {
|
|
1047
|
-
const typeParam = `TAccount${
|
|
1147
|
+
const typeParam = `TAccount${pascalCase4(account.name)}`;
|
|
1048
1148
|
if (account.isPda && account.isSigner === false) {
|
|
1049
1149
|
return fragment(`ProgramDerivedAddress<${typeParam}>`).addImports("solanaAddresses", [
|
|
1050
1150
|
"type ProgramDerivedAddress"
|
|
@@ -1063,7 +1163,7 @@ function getAccountTypeFragment2(account) {
|
|
|
1063
1163
|
}
|
|
1064
1164
|
function getDataArgumentsFragments(scope) {
|
|
1065
1165
|
const { instructionPath, nameApi } = scope;
|
|
1066
|
-
const instructionNode =
|
|
1166
|
+
const instructionNode = getLastNodeFromPath10(instructionPath);
|
|
1067
1167
|
const customData = scope.customInstructionData.get(instructionNode.name);
|
|
1068
1168
|
if (customData) {
|
|
1069
1169
|
return [
|
|
@@ -1081,7 +1181,7 @@ function getDataArgumentsFragments(scope) {
|
|
|
1081
1181
|
}
|
|
1082
1182
|
function getExtraArgumentsFragment(scope) {
|
|
1083
1183
|
const { instructionPath, nameApi } = scope;
|
|
1084
|
-
const instructionNode =
|
|
1184
|
+
const instructionNode = getLastNodeFromPath10(instructionPath);
|
|
1085
1185
|
const instructionExtraName = nameApi.instructionExtraType(instructionNode.name);
|
|
1086
1186
|
const extraArgsType = nameApi.dataArgsType(instructionExtraName);
|
|
1087
1187
|
const fragments = (instructionNode.extraArguments ?? []).flatMap((arg) => {
|
|
@@ -1092,16 +1192,16 @@ function getExtraArgumentsFragment(scope) {
|
|
|
1092
1192
|
}
|
|
1093
1193
|
function getArgumentFragment(arg, argsType, resolvedInputs, renamedArgs) {
|
|
1094
1194
|
const resolvedArg = resolvedInputs.find(
|
|
1095
|
-
(input) =>
|
|
1195
|
+
(input) => isNode8(input, "instructionArgumentNode") && input.name === arg.name
|
|
1096
1196
|
);
|
|
1097
1197
|
if (arg.defaultValue && arg.defaultValueStrategy === "omitted") return null;
|
|
1098
1198
|
const renamedName = renamedArgs.get(arg.name) ?? arg.name;
|
|
1099
1199
|
const optionalSign = arg.defaultValue || resolvedArg?.defaultValue ? "?" : "";
|
|
1100
|
-
return argsType.mapRender((r) => `${
|
|
1200
|
+
return argsType.mapRender((r) => `${camelCase7(renamedName)}${optionalSign}: ${r}["${camelCase7(arg.name)}"];`);
|
|
1101
1201
|
}
|
|
1102
1202
|
function getRemainingAccountsFragment(instructionNode) {
|
|
1103
1203
|
const fragments = (instructionNode.remainingAccounts ?? []).flatMap((remainingAccountsNode) => {
|
|
1104
|
-
if (
|
|
1204
|
+
if (isNode8(remainingAccountsNode.value, "resolverValueNode")) return [];
|
|
1105
1205
|
const { name } = remainingAccountsNode.value;
|
|
1106
1206
|
const allArguments = getAllInstructionArguments(instructionNode);
|
|
1107
1207
|
const argumentExists = allArguments.some((arg) => arg.name === name);
|
|
@@ -1115,12 +1215,21 @@ function getRemainingAccountsFragment(instructionNode) {
|
|
|
1115
1215
|
return mergeFragments([signerFragment, addressFragment], (r) => r.join(" | "));
|
|
1116
1216
|
}
|
|
1117
1217
|
return isSigner ? signerFragment : addressFragment;
|
|
1118
|
-
})().mapRender((r) => `${
|
|
1218
|
+
})().mapRender((r) => `${camelCase7(name)}${optionalSign}: Array<${r}>;`);
|
|
1119
1219
|
});
|
|
1120
1220
|
return mergeFragments(fragments, (r) => r.join("\n"));
|
|
1121
1221
|
}
|
|
1222
|
+
|
|
1223
|
+
// src/fragments/instructionRemainingAccounts.ts
|
|
1224
|
+
import {
|
|
1225
|
+
assertIsNode as assertIsNode2,
|
|
1226
|
+
camelCase as camelCase8,
|
|
1227
|
+
getAllInstructionArguments as getAllInstructionArguments2,
|
|
1228
|
+
isNode as isNode9
|
|
1229
|
+
} from "@codama/nodes";
|
|
1230
|
+
import { getLastNodeFromPath as getLastNodeFromPath11 } from "@codama/visitors-core";
|
|
1122
1231
|
function getInstructionRemainingAccountsFragment(scope) {
|
|
1123
|
-
const { remainingAccounts } =
|
|
1232
|
+
const { remainingAccounts } = getLastNodeFromPath11(scope.instructionPath);
|
|
1124
1233
|
const fragments = (remainingAccounts ?? []).flatMap((r) => getRemainingAccountsFragment2(r, scope));
|
|
1125
1234
|
if (fragments.length === 0) return fragment("");
|
|
1126
1235
|
return mergeFragments(
|
|
@@ -1131,10 +1240,10 @@ const remainingAccounts: IAccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.joi
|
|
|
1131
1240
|
}
|
|
1132
1241
|
function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
1133
1242
|
const remainingAccountsFragment = (() => {
|
|
1134
|
-
if (
|
|
1243
|
+
if (isNode9(remainingAccounts.value, "argumentValueNode")) {
|
|
1135
1244
|
return getArgumentValueNodeFragment2(remainingAccounts, scope);
|
|
1136
1245
|
}
|
|
1137
|
-
if (
|
|
1246
|
+
if (isNode9(remainingAccounts.value, "resolverValueNode")) {
|
|
1138
1247
|
return getResolverValueNodeFragment2(remainingAccounts, scope);
|
|
1139
1248
|
}
|
|
1140
1249
|
return null;
|
|
@@ -1143,9 +1252,9 @@ function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
|
1143
1252
|
return [remainingAccountsFragment];
|
|
1144
1253
|
}
|
|
1145
1254
|
function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
1146
|
-
const instructionNode =
|
|
1147
|
-
|
|
1148
|
-
const argumentName =
|
|
1255
|
+
const instructionNode = getLastNodeFromPath11(scope.instructionPath);
|
|
1256
|
+
assertIsNode2(remainingAccounts.value, "argumentValueNode");
|
|
1257
|
+
const argumentName = camelCase8(remainingAccounts.value.name);
|
|
1149
1258
|
const isOptional = remainingAccounts.isOptional ?? false;
|
|
1150
1259
|
const isSigner = remainingAccounts.isSigner ?? false;
|
|
1151
1260
|
const isWritable = remainingAccounts.isWritable ?? false;
|
|
@@ -1153,7 +1262,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1153
1262
|
const signerRole = isWritable ? "AccountRole.WRITABLE_SIGNER" : "AccountRole.READONLY_SIGNER";
|
|
1154
1263
|
const role = isSigner === true ? signerRole : nonSignerRole;
|
|
1155
1264
|
const argumentArray = isOptional ? `(args.${argumentName} ?? [])` : `args.${argumentName}`;
|
|
1156
|
-
const allArguments =
|
|
1265
|
+
const allArguments = getAllInstructionArguments2(instructionNode);
|
|
1157
1266
|
const argumentExists = allArguments.some((arg) => arg.name === remainingAccounts.value.name);
|
|
1158
1267
|
if (argumentExists || isSigner === false) {
|
|
1159
1268
|
return fragment(`${argumentArray}.map((address) => ({ address, role: ${role} }))`).addImports(
|
|
@@ -1174,7 +1283,7 @@ function getArgumentValueNodeFragment2(remainingAccounts, scope) {
|
|
|
1174
1283
|
).addImports("solanaInstructions", ["AccountRole"]);
|
|
1175
1284
|
}
|
|
1176
1285
|
function getResolverValueNodeFragment2(remainingAccounts, scope) {
|
|
1177
|
-
|
|
1286
|
+
assertIsNode2(remainingAccounts.value, "resolverValueNode");
|
|
1178
1287
|
const isAsync = scope.asyncResolvers.includes(remainingAccounts.value.name);
|
|
1179
1288
|
if (!scope.useAsync && isAsync) return null;
|
|
1180
1289
|
const awaitKeyword = scope.useAsync && isAsync ? "await " : "";
|
|
@@ -1194,8 +1303,8 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1194
1303
|
nameApi,
|
|
1195
1304
|
customInstructionData
|
|
1196
1305
|
} = scope;
|
|
1197
|
-
const instructionNode =
|
|
1198
|
-
const programNode =
|
|
1306
|
+
const instructionNode = getLastNodeFromPath12(instructionPath);
|
|
1307
|
+
const programNode = findProgramNodeFromPath3(instructionPath);
|
|
1199
1308
|
if (useAsync && !hasAsyncFunction(instructionNode, resolvedInputs, asyncResolvers)) {
|
|
1200
1309
|
return fragment("");
|
|
1201
1310
|
}
|
|
@@ -1203,7 +1312,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1203
1312
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1204
1313
|
const hasLegacyOptionalAccounts = instructionNode.optionalAccountStrategy === "omitted" && instructionNode.accounts.some((account) => account.isOptional);
|
|
1205
1314
|
const instructionDependencies = getInstructionDependencies(instructionNode, asyncResolvers, useAsync);
|
|
1206
|
-
const argDependencies = instructionDependencies.filter(
|
|
1315
|
+
const argDependencies = instructionDependencies.filter(isNodeFilter4("argumentValueNode")).map((node) => node.name);
|
|
1207
1316
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
1208
1317
|
const argIsNotOmitted = (arg) => !(arg.defaultValue && arg.defaultValueStrategy === "omitted");
|
|
1209
1318
|
const argIsDependent = (arg) => argDependencies.includes(arg.name);
|
|
@@ -1216,7 +1325,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1216
1325
|
const hasExtraArgs = (instructionNode.extraArguments ?? []).filter(
|
|
1217
1326
|
(field) => argIsNotOmitted(field) && (argIsDependent(field) || argHasDefaultValue(field))
|
|
1218
1327
|
).length > 0;
|
|
1219
|
-
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) =>
|
|
1328
|
+
const hasRemainingAccountArgs = (instructionNode.remainingAccounts ?? []).filter(({ value }) => isNode10(value, "argumentValueNode")).length > 0;
|
|
1220
1329
|
const hasAnyArgs = hasDataArgs || hasExtraArgs || hasRemainingAccountArgs;
|
|
1221
1330
|
const hasInput = hasAccounts || hasAnyArgs;
|
|
1222
1331
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
@@ -1292,18 +1401,18 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1292
1401
|
return functionFragment;
|
|
1293
1402
|
}
|
|
1294
1403
|
function getTypeParams(instructionNode, programAddressConstant) {
|
|
1295
|
-
const typeParams = instructionNode.accounts.map((account) => `TAccount${
|
|
1404
|
+
const typeParams = instructionNode.accounts.map((account) => `TAccount${pascalCase5(account.name)} extends string`);
|
|
1296
1405
|
typeParams.push(`TProgramAddress extends Address = typeof ${programAddressConstant}`);
|
|
1297
1406
|
return fragment(typeParams.filter((x) => !!x).join(", ")).mapRender((r) => `<${r}>`).addImports("generatedPrograms", [programAddressConstant]);
|
|
1298
1407
|
}
|
|
1299
1408
|
function getInstructionType(scope) {
|
|
1300
1409
|
const { instructionPath, nameApi } = scope;
|
|
1301
|
-
const instructionNode =
|
|
1410
|
+
const instructionNode = getLastNodeFromPath12(instructionPath);
|
|
1302
1411
|
const instructionTypeName = nameApi.instructionType(instructionNode.name);
|
|
1303
1412
|
const programAddressFragment = fragment("TProgramAddress");
|
|
1304
1413
|
const accountTypeParamsFragments = instructionNode.accounts.map((account) => {
|
|
1305
|
-
const typeParam = `TAccount${
|
|
1306
|
-
const camelName =
|
|
1414
|
+
const typeParam = `TAccount${pascalCase5(account.name)}`;
|
|
1415
|
+
const camelName = camelCase9(account.name);
|
|
1307
1416
|
if (account.isSigner === "either") {
|
|
1308
1417
|
const signerRole = account.isWritable ? "WritableSignerAccount" : "ReadonlySignerAccount";
|
|
1309
1418
|
return fragment(
|
|
@@ -1319,16 +1428,19 @@ function getInstructionType(scope) {
|
|
|
1319
1428
|
}
|
|
1320
1429
|
function getInputTypeCall(scope) {
|
|
1321
1430
|
const { instructionPath, useAsync, nameApi } = scope;
|
|
1322
|
-
const instructionNode =
|
|
1431
|
+
const instructionNode = getLastNodeFromPath12(instructionPath);
|
|
1323
1432
|
const inputTypeName = useAsync ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name);
|
|
1324
1433
|
if (instructionNode.accounts.length === 0) return fragment(inputTypeName);
|
|
1325
|
-
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${
|
|
1434
|
+
const accountTypeParams = instructionNode.accounts.map((account) => `TAccount${pascalCase5(account.name)}`).join(", ");
|
|
1326
1435
|
return fragment(`${inputTypeName}<${accountTypeParams}>`);
|
|
1327
1436
|
}
|
|
1437
|
+
|
|
1438
|
+
// src/fragments/instructionParseFunction.ts
|
|
1439
|
+
import { findProgramNodeFromPath as findProgramNodeFromPath4, getLastNodeFromPath as getLastNodeFromPath13 } from "@codama/visitors-core";
|
|
1328
1440
|
function getInstructionParseFunctionFragment(scope) {
|
|
1329
1441
|
const { instructionPath, dataArgsManifest, nameApi, customInstructionData } = scope;
|
|
1330
|
-
const instructionNode =
|
|
1331
|
-
const programNode =
|
|
1442
|
+
const instructionNode = getLastNodeFromPath13(instructionPath);
|
|
1443
|
+
const programNode = findProgramNodeFromPath4(instructionPath);
|
|
1332
1444
|
const customData = customInstructionData.get(instructionNode.name);
|
|
1333
1445
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1334
1446
|
const hasOptionalAccounts = instructionNode.accounts.some((account) => account.isOptional);
|
|
@@ -1356,16 +1468,20 @@ function getInstructionParseFunctionFragment(scope) {
|
|
|
1356
1468
|
programAddressConstant
|
|
1357
1469
|
}).mergeImportsWith(dataTypeFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaInstructions", ["type IInstruction"]).addImports("solanaInstructions", hasAccounts ? ["type IInstructionWithAccounts", "type IAccountMeta"] : []).addImports("solanaInstructions", hasData ? ["type IInstructionWithData"] : []);
|
|
1358
1470
|
}
|
|
1471
|
+
|
|
1472
|
+
// src/fragments/instructionType.ts
|
|
1473
|
+
import { pascalCase as pascalCase6 } from "@codama/nodes";
|
|
1474
|
+
import { findProgramNodeFromPath as findProgramNodeFromPath5, getLastNodeFromPath as getLastNodeFromPath14 } from "@codama/visitors-core";
|
|
1359
1475
|
function getInstructionTypeFragment(scope) {
|
|
1360
1476
|
const { instructionPath, nameApi, customInstructionData } = scope;
|
|
1361
|
-
const instructionNode =
|
|
1362
|
-
const programNode =
|
|
1477
|
+
const instructionNode = getLastNodeFromPath14(instructionPath);
|
|
1478
|
+
const programNode = findProgramNodeFromPath5(instructionPath);
|
|
1363
1479
|
const hasAccounts = instructionNode.accounts.length > 0;
|
|
1364
1480
|
const customData = customInstructionData.get(instructionNode.name);
|
|
1365
1481
|
const hasData = !!customData || instructionNode.arguments.length > 0;
|
|
1366
1482
|
const instructionDataName = nameApi.instructionDataType(instructionNode.name);
|
|
1367
1483
|
const programAddressConstant = nameApi.programAddressConstant(programNode.name);
|
|
1368
|
-
const dataType = customData ?
|
|
1484
|
+
const dataType = customData ? pascalCase6(customData.importAs) : pascalCase6(instructionDataName);
|
|
1369
1485
|
const accountTypeParamsFragment = mergeFragments(
|
|
1370
1486
|
instructionNode.accounts.map(
|
|
1371
1487
|
(account) => getInstructionAccountTypeParamFragment({
|
|
@@ -1380,7 +1496,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1380
1496
|
const accountMetasFragment = mergeFragments(
|
|
1381
1497
|
instructionNode.accounts.map(
|
|
1382
1498
|
(account) => getInstructionAccountMetaFragment(account).mapRender((r) => {
|
|
1383
|
-
const typeParam = `TAccount${
|
|
1499
|
+
const typeParam = `TAccount${pascalCase6(account.name)}`;
|
|
1384
1500
|
const isLegacyOptional = account.isOptional && usesLegacyOptionalAccounts;
|
|
1385
1501
|
const type = `${typeParam} extends string ? ${r} : ${typeParam}`;
|
|
1386
1502
|
if (!isLegacyOptional) return type;
|
|
@@ -1406,28 +1522,32 @@ function getInstructionTypeFragment(scope) {
|
|
|
1406
1522
|
]);
|
|
1407
1523
|
return fragment2;
|
|
1408
1524
|
}
|
|
1525
|
+
|
|
1526
|
+
// src/fragments/pdaFunction.ts
|
|
1527
|
+
import { isNode as isNode11, isNodeFilter as isNodeFilter5 } from "@codama/nodes";
|
|
1528
|
+
import { findProgramNodeFromPath as findProgramNodeFromPath6, getLastNodeFromPath as getLastNodeFromPath15, visit as visit4 } from "@codama/visitors-core";
|
|
1409
1529
|
function getPdaFunctionFragment(scope) {
|
|
1410
1530
|
const { pdaPath, typeManifestVisitor, nameApi } = scope;
|
|
1411
|
-
const pdaNode =
|
|
1412
|
-
const programNode =
|
|
1531
|
+
const pdaNode = getLastNodeFromPath15(pdaPath);
|
|
1532
|
+
const programNode = findProgramNodeFromPath6(pdaPath);
|
|
1413
1533
|
const imports = new ImportMap();
|
|
1414
1534
|
const seeds = pdaNode.seeds.map((seed) => {
|
|
1415
|
-
if (
|
|
1416
|
-
const seedManifest2 =
|
|
1535
|
+
if (isNode11(seed, "variablePdaSeedNode")) {
|
|
1536
|
+
const seedManifest2 = visit4(seed.type, typeManifestVisitor);
|
|
1417
1537
|
imports.mergeWith(seedManifest2.looseType, seedManifest2.encoder);
|
|
1418
1538
|
return { ...seed, typeManifest: seedManifest2 };
|
|
1419
1539
|
}
|
|
1420
|
-
if (
|
|
1540
|
+
if (isNode11(seed.value, "programIdValueNode")) {
|
|
1421
1541
|
imports.add("solanaAddresses", "getAddressEncoder");
|
|
1422
1542
|
return seed;
|
|
1423
1543
|
}
|
|
1424
|
-
const seedManifest =
|
|
1544
|
+
const seedManifest = visit4(seed.type, typeManifestVisitor);
|
|
1425
1545
|
imports.mergeWith(seedManifest.encoder);
|
|
1426
|
-
const valueManifest =
|
|
1546
|
+
const valueManifest = visit4(seed.value, typeManifestVisitor).value;
|
|
1427
1547
|
imports.mergeWith(valueManifest.imports);
|
|
1428
1548
|
return { ...seed, typeManifest: seedManifest, valueManifest };
|
|
1429
1549
|
});
|
|
1430
|
-
const hasVariableSeeds = pdaNode.seeds.filter(
|
|
1550
|
+
const hasVariableSeeds = pdaNode.seeds.filter(isNodeFilter5("variablePdaSeedNode")).length > 0;
|
|
1431
1551
|
return fragmentFromTemplate("pdaFunction.njk", {
|
|
1432
1552
|
findPdaFunction: nameApi.pdaFindFunction(pdaNode.name),
|
|
1433
1553
|
hasVariableSeeds,
|
|
@@ -1445,6 +1565,9 @@ function getProgramFragment(scope) {
|
|
|
1445
1565
|
programAddressConstant: nameApi.programAddressConstant(programNode.name)
|
|
1446
1566
|
}).addImports("solanaAddresses", ["type Address"]);
|
|
1447
1567
|
}
|
|
1568
|
+
|
|
1569
|
+
// src/fragments/programAccounts.ts
|
|
1570
|
+
import { resolveNestedTypeNode } from "@codama/nodes";
|
|
1448
1571
|
function getProgramAccountsFragment(scope) {
|
|
1449
1572
|
if (scope.programNode.accounts.length === 0) return fragment("");
|
|
1450
1573
|
return mergeFragments(
|
|
@@ -1506,6 +1629,12 @@ function getProgramErrorsFragment(scope) {
|
|
|
1506
1629
|
programIsErrorFunction: nameApi.programIsErrorFunction(programNode.name)
|
|
1507
1630
|
}).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaPrograms", ["isProgramError"]).addImports("solanaErrors", ["type SolanaError", "type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM"]).addImports("solanaAddresses", ["type Address"]);
|
|
1508
1631
|
}
|
|
1632
|
+
|
|
1633
|
+
// src/fragments/programInstructions.ts
|
|
1634
|
+
import {
|
|
1635
|
+
getAllInstructionsWithSubs,
|
|
1636
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes2
|
|
1637
|
+
} from "@codama/nodes";
|
|
1509
1638
|
function getProgramInstructionsFragment(scope) {
|
|
1510
1639
|
if (scope.programNode.instructions.length === 0) return fragment("");
|
|
1511
1640
|
const allInstructions = getAllInstructionsWithSubs(scope.programNode, {
|
|
@@ -1550,7 +1679,7 @@ function getProgramInstructionsIdentifierFunctionFragment(scope) {
|
|
|
1550
1679
|
dataName: "data",
|
|
1551
1680
|
discriminators: instruction.discriminators ?? [],
|
|
1552
1681
|
ifTrue: `return ${programInstructionsEnum}.${variant};`,
|
|
1553
|
-
struct:
|
|
1682
|
+
struct: structTypeNodeFromInstructionArgumentNodes2(instruction.arguments)
|
|
1554
1683
|
});
|
|
1555
1684
|
}),
|
|
1556
1685
|
(r) => r.join("\n")
|
|
@@ -1583,9 +1712,12 @@ function getProgramInstructionsParsedUnionTypeFragment(scope) {
|
|
|
1583
1712
|
(r) => r.join("\n")
|
|
1584
1713
|
);
|
|
1585
1714
|
}
|
|
1715
|
+
|
|
1716
|
+
// src/fragments/typeDiscriminatedUnionHelpers.ts
|
|
1717
|
+
import { isDataEnum, isNode as isNode12 } from "@codama/nodes";
|
|
1586
1718
|
function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
1587
1719
|
const { name, typeNode, nameApi } = scope;
|
|
1588
|
-
const isDiscriminatedUnion =
|
|
1720
|
+
const isDiscriminatedUnion = isNode12(typeNode, "enumTypeNode") && isDataEnum(typeNode);
|
|
1589
1721
|
if (!isDiscriminatedUnion) {
|
|
1590
1722
|
return fragment("");
|
|
1591
1723
|
}
|
|
@@ -1626,6 +1758,57 @@ function mergeManifests(manifests, options = {}) {
|
|
|
1626
1758
|
value: merge((m) => m.value, mergeValues)
|
|
1627
1759
|
};
|
|
1628
1760
|
}
|
|
1761
|
+
|
|
1762
|
+
// src/getRenderMapVisitor.ts
|
|
1763
|
+
import { join as join3 } from "node:path";
|
|
1764
|
+
import { logWarn } from "@codama/errors";
|
|
1765
|
+
import {
|
|
1766
|
+
camelCase as camelCase12,
|
|
1767
|
+
definedTypeNode as definedTypeNode2,
|
|
1768
|
+
getAllAccounts,
|
|
1769
|
+
getAllDefinedTypes,
|
|
1770
|
+
getAllInstructionsWithSubs as getAllInstructionsWithSubs2,
|
|
1771
|
+
getAllPdas,
|
|
1772
|
+
getAllPrograms,
|
|
1773
|
+
resolveNestedTypeNode as resolveNestedTypeNode3,
|
|
1774
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes4
|
|
1775
|
+
} from "@codama/nodes";
|
|
1776
|
+
import { RenderMap } from "@codama/renderers-core";
|
|
1777
|
+
import {
|
|
1778
|
+
extendVisitor as extendVisitor2,
|
|
1779
|
+
findProgramNodeFromPath as findProgramNodeFromPath7,
|
|
1780
|
+
getResolvedInstructionInputsVisitor,
|
|
1781
|
+
LinkableDictionary as LinkableDictionary3,
|
|
1782
|
+
NodeStack as NodeStack2,
|
|
1783
|
+
pipe as pipe2,
|
|
1784
|
+
recordLinkablesOnFirstVisitVisitor,
|
|
1785
|
+
recordNodeStackVisitor as recordNodeStackVisitor2,
|
|
1786
|
+
staticVisitor as staticVisitor2,
|
|
1787
|
+
visit as visit6
|
|
1788
|
+
} from "@codama/visitors-core";
|
|
1789
|
+
|
|
1790
|
+
// src/getTypeManifestVisitor.ts
|
|
1791
|
+
import {
|
|
1792
|
+
camelCase as camelCase10,
|
|
1793
|
+
isNode as isNode13,
|
|
1794
|
+
isNodeFilter as isNodeFilter6,
|
|
1795
|
+
isScalarEnum,
|
|
1796
|
+
REGISTERED_TYPE_NODE_KINDS,
|
|
1797
|
+
REGISTERED_VALUE_NODE_KINDS,
|
|
1798
|
+
resolveNestedTypeNode as resolveNestedTypeNode2,
|
|
1799
|
+
structFieldTypeNode,
|
|
1800
|
+
structTypeNode,
|
|
1801
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes3
|
|
1802
|
+
} from "@codama/nodes";
|
|
1803
|
+
import {
|
|
1804
|
+
extendVisitor,
|
|
1805
|
+
findLastNodeFromPath,
|
|
1806
|
+
NodeStack,
|
|
1807
|
+
pipe,
|
|
1808
|
+
recordNodeStackVisitor,
|
|
1809
|
+
staticVisitor,
|
|
1810
|
+
visit as visit5
|
|
1811
|
+
} from "@codama/visitors-core";
|
|
1629
1812
|
function getTypeManifestVisitor(input) {
|
|
1630
1813
|
const { nameApi, linkables, nonScalarEnums, customAccountData, customInstructionData, getImportFrom } = input;
|
|
1631
1814
|
const stack = input.stack ?? new NodeStack();
|
|
@@ -1658,15 +1841,15 @@ function getTypeManifestVisitor(input) {
|
|
|
1658
1841
|
strict: nameApi.dataType(account.name)
|
|
1659
1842
|
};
|
|
1660
1843
|
const link = customAccountData.get(account.name)?.linkNode;
|
|
1661
|
-
const manifest = link ?
|
|
1844
|
+
const manifest = link ? visit5(link, self) : visit5(account.data, self);
|
|
1662
1845
|
parentName = null;
|
|
1663
1846
|
return manifest;
|
|
1664
1847
|
},
|
|
1665
1848
|
visitAmountType(amountType, { self }) {
|
|
1666
|
-
return
|
|
1849
|
+
return visit5(amountType.number, self);
|
|
1667
1850
|
},
|
|
1668
1851
|
visitArrayType(arrayType, { self }) {
|
|
1669
|
-
const childManifest =
|
|
1852
|
+
const childManifest = visit5(arrayType.item, self);
|
|
1670
1853
|
childManifest.looseType.mapRender((r) => `Array<${r}>`);
|
|
1671
1854
|
childManifest.strictType.mapRender((r) => `Array<${r}>`);
|
|
1672
1855
|
const sizeManifest = getArrayLikeSizeOption(arrayType.count, self);
|
|
@@ -1678,7 +1861,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1678
1861
|
},
|
|
1679
1862
|
visitArrayValue(node, { self }) {
|
|
1680
1863
|
return mergeManifests(
|
|
1681
|
-
node.items.map((v) =>
|
|
1864
|
+
node.items.map((v) => visit5(v, self)),
|
|
1682
1865
|
{ mergeValues: (renders) => `[${renders.join(", ")}]` }
|
|
1683
1866
|
);
|
|
1684
1867
|
},
|
|
@@ -1687,9 +1870,9 @@ function getTypeManifestVisitor(input) {
|
|
|
1687
1870
|
const decoderImports = new ImportMap().add("solanaCodecsDataStructures", "getBooleanDecoder");
|
|
1688
1871
|
let sizeEncoder = "";
|
|
1689
1872
|
let sizeDecoder = "";
|
|
1690
|
-
const resolvedSize =
|
|
1873
|
+
const resolvedSize = resolveNestedTypeNode2(booleanType.size);
|
|
1691
1874
|
if (resolvedSize.format !== "u8" || resolvedSize.endian !== "le") {
|
|
1692
|
-
const size =
|
|
1875
|
+
const size = visit5(booleanType.size, self);
|
|
1693
1876
|
encoderImports.mergeWith(size.encoder);
|
|
1694
1877
|
decoderImports.mergeWith(size.decoder);
|
|
1695
1878
|
sizeEncoder = `{ size: ${size.encoder.render} }`;
|
|
@@ -1738,26 +1921,26 @@ function getTypeManifestVisitor(input) {
|
|
|
1738
1921
|
return manifest;
|
|
1739
1922
|
},
|
|
1740
1923
|
visitConstantValue(node, { self }) {
|
|
1741
|
-
if (
|
|
1742
|
-
return
|
|
1924
|
+
if (isNode13(node.type, "bytesTypeNode") && isNode13(node.value, "bytesValueNode")) {
|
|
1925
|
+
return visit5(node.value, self);
|
|
1743
1926
|
}
|
|
1744
1927
|
return {
|
|
1745
1928
|
...typeManifest(),
|
|
1746
1929
|
value: mergeFragments(
|
|
1747
|
-
[
|
|
1930
|
+
[visit5(node.type, self).encoder, visit5(node.value, self).value],
|
|
1748
1931
|
([encoderFunction, value]) => `${encoderFunction}.encode(${value})`
|
|
1749
1932
|
)
|
|
1750
1933
|
};
|
|
1751
1934
|
},
|
|
1752
1935
|
visitDateTimeType(dateTimeType, { self }) {
|
|
1753
|
-
return
|
|
1936
|
+
return visit5(dateTimeType.number, self);
|
|
1754
1937
|
},
|
|
1755
1938
|
visitDefinedType(definedType, { self }) {
|
|
1756
1939
|
parentName = {
|
|
1757
1940
|
loose: nameApi.dataArgsType(definedType.name),
|
|
1758
1941
|
strict: nameApi.dataType(definedType.name)
|
|
1759
1942
|
};
|
|
1760
|
-
const manifest =
|
|
1943
|
+
const manifest = visit5(definedType.type, self);
|
|
1761
1944
|
parentName = null;
|
|
1762
1945
|
return manifest;
|
|
1763
1946
|
},
|
|
@@ -1777,7 +1960,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1777
1960
|
};
|
|
1778
1961
|
},
|
|
1779
1962
|
visitEnumEmptyVariantType(enumEmptyVariantType) {
|
|
1780
|
-
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1963
|
+
const discriminator = nameApi.discriminatedUnionDiscriminator(camelCase10(parentName?.strict ?? ""));
|
|
1781
1964
|
const name = nameApi.discriminatedUnionVariant(enumEmptyVariantType.name);
|
|
1782
1965
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1783
1966
|
return {
|
|
@@ -1798,12 +1981,12 @@ function getTypeManifestVisitor(input) {
|
|
|
1798
1981
|
visitEnumStructVariantType(enumStructVariantType, { self }) {
|
|
1799
1982
|
const currentParentName = parentName;
|
|
1800
1983
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1801
|
-
|
|
1984
|
+
camelCase10(currentParentName?.strict ?? "")
|
|
1802
1985
|
);
|
|
1803
1986
|
const name = nameApi.discriminatedUnionVariant(enumStructVariantType.name);
|
|
1804
1987
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1805
1988
|
parentName = null;
|
|
1806
|
-
const structManifest =
|
|
1989
|
+
const structManifest = visit5(enumStructVariantType.struct, self);
|
|
1807
1990
|
parentName = currentParentName;
|
|
1808
1991
|
structManifest.strictType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
1809
1992
|
structManifest.looseType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
@@ -1814,7 +1997,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1814
1997
|
visitEnumTupleVariantType(enumTupleVariantType, { self }) {
|
|
1815
1998
|
const currentParentName = parentName;
|
|
1816
1999
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1817
|
-
|
|
2000
|
+
camelCase10(currentParentName?.strict ?? "")
|
|
1818
2001
|
);
|
|
1819
2002
|
const name = nameApi.discriminatedUnionVariant(enumTupleVariantType.name);
|
|
1820
2003
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
@@ -1825,7 +2008,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1825
2008
|
})
|
|
1826
2009
|
]);
|
|
1827
2010
|
parentName = null;
|
|
1828
|
-
const structManifest =
|
|
2011
|
+
const structManifest = visit5(struct, self);
|
|
1829
2012
|
parentName = currentParentName;
|
|
1830
2013
|
structManifest.strictType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
1831
2014
|
structManifest.looseType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
@@ -1839,16 +2022,16 @@ function getTypeManifestVisitor(input) {
|
|
|
1839
2022
|
const decoderImports = new ImportMap();
|
|
1840
2023
|
const encoderOptions = [];
|
|
1841
2024
|
const decoderOptions = [];
|
|
1842
|
-
const enumSize =
|
|
2025
|
+
const enumSize = resolveNestedTypeNode2(enumType.size);
|
|
1843
2026
|
if (enumSize.format !== "u8" || enumSize.endian !== "le") {
|
|
1844
|
-
const sizeManifest =
|
|
2027
|
+
const sizeManifest = visit5(enumType.size, self);
|
|
1845
2028
|
encoderImports.mergeWith(sizeManifest.encoder);
|
|
1846
2029
|
decoderImports.mergeWith(sizeManifest.decoder);
|
|
1847
2030
|
encoderOptions.push(`size: ${sizeManifest.encoder.render}`);
|
|
1848
2031
|
decoderOptions.push(`size: ${sizeManifest.decoder.render}`);
|
|
1849
2032
|
}
|
|
1850
2033
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1851
|
-
|
|
2034
|
+
camelCase10(currentParentName?.strict ?? "")
|
|
1852
2035
|
);
|
|
1853
2036
|
if (!isScalarEnum(enumType) && discriminator !== "__kind") {
|
|
1854
2037
|
encoderOptions.push(`discriminator: '${discriminator}'`);
|
|
@@ -1879,7 +2062,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1879
2062
|
};
|
|
1880
2063
|
}
|
|
1881
2064
|
const mergedManifest = mergeManifests(
|
|
1882
|
-
enumType.variants.map((variant) =>
|
|
2065
|
+
enumType.variants.map((variant) => visit5(variant, self)),
|
|
1883
2066
|
{
|
|
1884
2067
|
mergeCodecs: (renders) => renders.join(", "),
|
|
1885
2068
|
mergeTypes: (renders) => renders.join(" | ")
|
|
@@ -1895,7 +2078,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1895
2078
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
1896
2079
|
const importFrom = getImportFrom(node.enum);
|
|
1897
2080
|
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
1898
|
-
const isScalar = enumNode &&
|
|
2081
|
+
const isScalar = enumNode && isNode13(enumNode, "enumTypeNode") ? isScalarEnum(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
1899
2082
|
if (!node.value && isScalar) {
|
|
1900
2083
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
1901
2084
|
manifest.value.setRender(`${enumName}.${variantName2}`).addImports(importFrom, enumName);
|
|
@@ -1906,18 +2089,18 @@ function getTypeManifestVisitor(input) {
|
|
|
1906
2089
|
manifest.value.setRender(`${enumFunction}('${variantName}')`).addImports(importFrom, enumFunction);
|
|
1907
2090
|
return manifest;
|
|
1908
2091
|
}
|
|
1909
|
-
manifest.value =
|
|
2092
|
+
manifest.value = visit5(node.value, self).value.mapRender((r) => `${enumFunction}('${variantName}', ${r})`).addImports(importFrom, enumFunction);
|
|
1910
2093
|
return manifest;
|
|
1911
2094
|
},
|
|
1912
2095
|
visitFixedSizeType(node, { self }) {
|
|
1913
|
-
const manifest =
|
|
2096
|
+
const manifest = visit5(node.type, self);
|
|
1914
2097
|
manifest.encoder.mapRender((r) => `fixEncoderSize(${r}, ${node.size})`).addImports("solanaCodecsCore", "fixEncoderSize");
|
|
1915
2098
|
manifest.decoder.mapRender((r) => `fixDecoderSize(${r}, ${node.size})`).addImports("solanaCodecsCore", "fixDecoderSize");
|
|
1916
2099
|
return manifest;
|
|
1917
2100
|
},
|
|
1918
2101
|
visitHiddenPrefixType(node, { self }) {
|
|
1919
|
-
const manifest =
|
|
1920
|
-
const prefixes = node.prefix.map((c) =>
|
|
2102
|
+
const manifest = visit5(node.type, self);
|
|
2103
|
+
const prefixes = node.prefix.map((c) => visit5(c, self).value);
|
|
1921
2104
|
const prefixEncoders = fragment(prefixes.map((c) => `getConstantEncoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantEncoder").mergeImportsWith(...prefixes);
|
|
1922
2105
|
const prefixDecoders = fragment(prefixes.map((c) => `getConstantDecoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantDecoder").mergeImportsWith(...prefixes);
|
|
1923
2106
|
manifest.encoder.mapRender((r) => `getHiddenPrefixEncoder(${r}, [${prefixEncoders.render}])`).mergeImportsWith(prefixEncoders).addImports("solanaCodecsDataStructures", "getHiddenPrefixEncoder");
|
|
@@ -1925,8 +2108,8 @@ function getTypeManifestVisitor(input) {
|
|
|
1925
2108
|
return manifest;
|
|
1926
2109
|
},
|
|
1927
2110
|
visitHiddenSuffixType(node, { self }) {
|
|
1928
|
-
const manifest =
|
|
1929
|
-
const suffixes = node.suffix.map((c) =>
|
|
2111
|
+
const manifest = visit5(node.type, self);
|
|
2112
|
+
const suffixes = node.suffix.map((c) => visit5(c, self).value);
|
|
1930
2113
|
const suffixEncoders = fragment(suffixes.map((c) => `getConstantEncoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantEncoder").mergeImportsWith(...suffixes);
|
|
1931
2114
|
const suffixDecoders = fragment(suffixes.map((c) => `getConstantDecoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantDecoder").mergeImportsWith(...suffixes);
|
|
1932
2115
|
manifest.encoder.mapRender((r) => `getHiddenSuffixEncoder(${r}, [${suffixEncoders.render}])`).mergeImportsWith(suffixEncoders).addImports("solanaCodecsDataStructures", "getHiddenSuffixEncoder");
|
|
@@ -1940,19 +2123,19 @@ function getTypeManifestVisitor(input) {
|
|
|
1940
2123
|
strict: nameApi.dataType(instructionDataName)
|
|
1941
2124
|
};
|
|
1942
2125
|
const link = customInstructionData.get(instruction.name)?.linkNode;
|
|
1943
|
-
const struct =
|
|
1944
|
-
const manifest = link ?
|
|
2126
|
+
const struct = structTypeNodeFromInstructionArgumentNodes3(instruction.arguments);
|
|
2127
|
+
const manifest = link ? visit5(link, self) : visit5(struct, self);
|
|
1945
2128
|
parentName = null;
|
|
1946
2129
|
return manifest;
|
|
1947
2130
|
},
|
|
1948
2131
|
visitMapEntryValue(node, { self }) {
|
|
1949
|
-
return mergeManifests([
|
|
2132
|
+
return mergeManifests([visit5(node.key, self), visit5(node.value, self)], {
|
|
1950
2133
|
mergeValues: (renders) => `[${renders.join(", ")}]`
|
|
1951
2134
|
});
|
|
1952
2135
|
},
|
|
1953
2136
|
visitMapType(mapType, { self }) {
|
|
1954
|
-
const key =
|
|
1955
|
-
const value =
|
|
2137
|
+
const key = visit5(mapType.key, self);
|
|
2138
|
+
const value = visit5(mapType.value, self);
|
|
1956
2139
|
const mergedManifest = mergeManifests([key, value], {
|
|
1957
2140
|
mergeCodecs: ([k, v]) => `${k}, ${v}`,
|
|
1958
2141
|
mergeTypes: ([k, v]) => `Map<${k}, ${v}>`
|
|
@@ -1965,7 +2148,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1965
2148
|
return mergedManifest;
|
|
1966
2149
|
},
|
|
1967
2150
|
visitMapValue(node, { self }) {
|
|
1968
|
-
const entryFragments = node.entries.map((entry) =>
|
|
2151
|
+
const entryFragments = node.entries.map((entry) => visit5(entry, self));
|
|
1969
2152
|
return mergeManifests(entryFragments, {
|
|
1970
2153
|
mergeValues: (renders) => `new Map([${renders.join(", ")}])`
|
|
1971
2154
|
});
|
|
@@ -2002,14 +2185,14 @@ function getTypeManifestVisitor(input) {
|
|
|
2002
2185
|
return manifest;
|
|
2003
2186
|
},
|
|
2004
2187
|
visitOptionType(optionType, { self }) {
|
|
2005
|
-
const childManifest =
|
|
2188
|
+
const childManifest = visit5(optionType.item, self);
|
|
2006
2189
|
childManifest.strictType.mapRender((r) => `Option<${r}>`).addImports("solanaOptions", "type Option");
|
|
2007
2190
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2008
2191
|
const encoderOptions = [];
|
|
2009
2192
|
const decoderOptions = [];
|
|
2010
|
-
const optionPrefix =
|
|
2193
|
+
const optionPrefix = resolveNestedTypeNode2(optionType.prefix);
|
|
2011
2194
|
if (optionPrefix.format !== "u8" || optionPrefix.endian !== "le") {
|
|
2012
|
-
const prefixManifest =
|
|
2195
|
+
const prefixManifest = visit5(optionType.prefix, self);
|
|
2013
2196
|
childManifest.encoder.mergeImportsWith(prefixManifest.encoder);
|
|
2014
2197
|
childManifest.decoder.mergeImportsWith(prefixManifest.decoder);
|
|
2015
2198
|
encoderOptions.push(`prefix: ${prefixManifest.encoder.render}`);
|
|
@@ -2026,7 +2209,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2026
2209
|
return childManifest;
|
|
2027
2210
|
},
|
|
2028
2211
|
visitPostOffsetType(node, { self }) {
|
|
2029
|
-
const manifest =
|
|
2212
|
+
const manifest = visit5(node.type, self);
|
|
2030
2213
|
if (node.strategy === "padded") {
|
|
2031
2214
|
manifest.encoder.mapRender((r) => `padRightEncoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padRightEncoder");
|
|
2032
2215
|
manifest.decoder.mapRender((r) => `padRightDecoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padRightDecoder");
|
|
@@ -2048,7 +2231,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2048
2231
|
return manifest;
|
|
2049
2232
|
},
|
|
2050
2233
|
visitPreOffsetType(node, { self }) {
|
|
2051
|
-
const manifest =
|
|
2234
|
+
const manifest = visit5(node.type, self);
|
|
2052
2235
|
if (node.strategy === "padded") {
|
|
2053
2236
|
manifest.encoder.mapRender((r) => `padLeftEncoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padLeftEncoder");
|
|
2054
2237
|
manifest.decoder.mapRender((r) => `padLeftDecoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padLeftDecoder");
|
|
@@ -2084,7 +2267,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2084
2267
|
return manifest;
|
|
2085
2268
|
},
|
|
2086
2269
|
visitRemainderOptionType(node, { self }) {
|
|
2087
|
-
const childManifest =
|
|
2270
|
+
const childManifest = visit5(node.item, self);
|
|
2088
2271
|
childManifest.strictType.mapRender((r) => `Option<${r}>`).addImports("solanaOptions", "type Option");
|
|
2089
2272
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2090
2273
|
const encoderOptions = ["prefix: null"];
|
|
@@ -2096,14 +2279,14 @@ function getTypeManifestVisitor(input) {
|
|
|
2096
2279
|
return childManifest;
|
|
2097
2280
|
},
|
|
2098
2281
|
visitSentinelType(node, { self }) {
|
|
2099
|
-
const manifest =
|
|
2100
|
-
const sentinel =
|
|
2282
|
+
const manifest = visit5(node.type, self);
|
|
2283
|
+
const sentinel = visit5(node.sentinel, self).value;
|
|
2101
2284
|
manifest.encoder.mapRender((r) => `addEncoderSentinel(${r}, ${sentinel.render})`).mergeImportsWith(sentinel).addImports("solanaCodecsCore", "addEncoderSentinel");
|
|
2102
2285
|
manifest.decoder.mapRender((r) => `addDecoderSentinel(${r}, ${sentinel.render})`).mergeImportsWith(sentinel).addImports("solanaCodecsCore", "addDecoderSentinel");
|
|
2103
2286
|
return manifest;
|
|
2104
2287
|
},
|
|
2105
2288
|
visitSetType(setType, { self }) {
|
|
2106
|
-
const childManifest =
|
|
2289
|
+
const childManifest = visit5(setType.item, self);
|
|
2107
2290
|
childManifest.strictType.mapRender((r) => `Set<${r}>`);
|
|
2108
2291
|
childManifest.looseType.mapRender((r) => `Set<${r}>`);
|
|
2109
2292
|
const sizeManifest = getArrayLikeSizeOption(setType.count, self);
|
|
@@ -2115,19 +2298,19 @@ function getTypeManifestVisitor(input) {
|
|
|
2115
2298
|
},
|
|
2116
2299
|
visitSetValue(node, { self }) {
|
|
2117
2300
|
return mergeManifests(
|
|
2118
|
-
node.items.map((v) =>
|
|
2301
|
+
node.items.map((v) => visit5(v, self)),
|
|
2119
2302
|
{ mergeValues: (renders) => `new Set([${renders.join(", ")}])` }
|
|
2120
2303
|
);
|
|
2121
2304
|
},
|
|
2122
2305
|
visitSizePrefixType(node, { self }) {
|
|
2123
|
-
const manifest =
|
|
2124
|
-
const prefix =
|
|
2306
|
+
const manifest = visit5(node.type, self);
|
|
2307
|
+
const prefix = visit5(node.prefix, self);
|
|
2125
2308
|
manifest.encoder.mapRender((r) => `addEncoderSizePrefix(${r}, ${prefix.encoder.render})`).mergeImportsWith(prefix.encoder).addImports("solanaCodecsCore", "addEncoderSizePrefix");
|
|
2126
2309
|
manifest.decoder.mapRender((r) => `addDecoderSizePrefix(${r}, ${prefix.decoder.render})`).mergeImportsWith(prefix.decoder).addImports("solanaCodecsCore", "addDecoderSizePrefix");
|
|
2127
2310
|
return manifest;
|
|
2128
2311
|
},
|
|
2129
2312
|
visitSolAmountType({ number }, { self }) {
|
|
2130
|
-
const numberManifest =
|
|
2313
|
+
const numberManifest = visit5(number, self);
|
|
2131
2314
|
const lamportsType = "Lamports";
|
|
2132
2315
|
const lamportsImport = new ImportMap().add("solanaRpcTypes", "type Lamports");
|
|
2133
2316
|
return {
|
|
@@ -2140,7 +2323,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2140
2323
|
},
|
|
2141
2324
|
visitSomeValue(node, { self }) {
|
|
2142
2325
|
const manifest = typeManifest();
|
|
2143
|
-
manifest.value =
|
|
2326
|
+
manifest.value = visit5(node.value, self).value.mapRender((r) => `some(${r})`).addImports("solanaOptions", "some");
|
|
2144
2327
|
return manifest;
|
|
2145
2328
|
},
|
|
2146
2329
|
visitStringType(stringType) {
|
|
@@ -2173,8 +2356,8 @@ function getTypeManifestVisitor(input) {
|
|
|
2173
2356
|
return manifest;
|
|
2174
2357
|
},
|
|
2175
2358
|
visitStructFieldType(structFieldType, { self }) {
|
|
2176
|
-
const name =
|
|
2177
|
-
const childManifest =
|
|
2359
|
+
const name = camelCase10(structFieldType.name);
|
|
2360
|
+
const childManifest = visit5(structFieldType.type, self);
|
|
2178
2361
|
const docblock = structFieldType.docs.length > 0 ? `
|
|
2179
2362
|
${jsDocblock(structFieldType.docs)}` : "";
|
|
2180
2363
|
const originalLooseType = childManifest.looseType.render;
|
|
@@ -2194,13 +2377,13 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2194
2377
|
},
|
|
2195
2378
|
visitStructFieldValue(node, { self }) {
|
|
2196
2379
|
const manifest = typeManifest();
|
|
2197
|
-
manifest.value =
|
|
2380
|
+
manifest.value = visit5(node.value, self).value.mapRender((r) => `${node.name}: ${r}`);
|
|
2198
2381
|
return manifest;
|
|
2199
2382
|
},
|
|
2200
2383
|
visitStructType(structType, { self }) {
|
|
2201
2384
|
const optionalFields = structType.fields.filter((f) => !!f.defaultValue);
|
|
2202
2385
|
const mergedManifest = mergeManifests(
|
|
2203
|
-
structType.fields.map((field) =>
|
|
2386
|
+
structType.fields.map((field) => visit5(field, self)),
|
|
2204
2387
|
{
|
|
2205
2388
|
mergeCodecs: (renders) => `([${renders.join(", ")}])`,
|
|
2206
2389
|
mergeTypes: (renders) => `{ ${renders.join("")} }`
|
|
@@ -2216,15 +2399,15 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2216
2399
|
const accountNode = findLastNodeFromPath(parentPath, "accountNode");
|
|
2217
2400
|
const discriminatorPrefix = instructionNode ? instructionNode.name : accountNode?.name;
|
|
2218
2401
|
const discriminators = (instructionNode ? instructionNode.discriminators : accountNode?.discriminators) ?? [];
|
|
2219
|
-
const fieldDiscriminators = discriminators.filter(
|
|
2402
|
+
const fieldDiscriminators = discriminators.filter(isNodeFilter6("fieldDiscriminatorNode"));
|
|
2220
2403
|
const defaultValues = optionalFields.map((f) => {
|
|
2221
|
-
const key =
|
|
2404
|
+
const key = camelCase10(f.name);
|
|
2222
2405
|
if (fieldDiscriminators.some((d) => d.name === f.name)) {
|
|
2223
|
-
const constantName = nameApi.constant(
|
|
2406
|
+
const constantName = nameApi.constant(camelCase10(`${discriminatorPrefix}_${f.name}`));
|
|
2224
2407
|
return f.defaultValueStrategy === "omitted" ? `${key}: ${constantName}` : `${key}: value.${key} ?? ${constantName}`;
|
|
2225
2408
|
}
|
|
2226
2409
|
const defaultValue = f.defaultValue;
|
|
2227
|
-
const { render: renderedValue, imports } =
|
|
2410
|
+
const { render: renderedValue, imports } = visit5(defaultValue, self).value;
|
|
2228
2411
|
mergedManifest.encoder.mergeImportsWith(imports);
|
|
2229
2412
|
return f.defaultValueStrategy === "omitted" ? `${key}: ${renderedValue}` : `${key}: value.${key} ?? ${renderedValue}`;
|
|
2230
2413
|
}).join(", ");
|
|
@@ -2233,12 +2416,12 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2233
2416
|
},
|
|
2234
2417
|
visitStructValue(node, { self }) {
|
|
2235
2418
|
return mergeManifests(
|
|
2236
|
-
node.fields.map((field) =>
|
|
2419
|
+
node.fields.map((field) => visit5(field, self)),
|
|
2237
2420
|
{ mergeValues: (renders) => `{ ${renders.join(", ")} }` }
|
|
2238
2421
|
);
|
|
2239
2422
|
},
|
|
2240
2423
|
visitTupleType(tupleType, { self }) {
|
|
2241
|
-
const items = tupleType.items.map((item) =>
|
|
2424
|
+
const items = tupleType.items.map((item) => visit5(item, self));
|
|
2242
2425
|
const mergedManifest = mergeManifests(items, {
|
|
2243
2426
|
mergeCodecs: (codecs) => `[${codecs.join(", ")}]`,
|
|
2244
2427
|
mergeTypes: (types) => `readonly [${types.join(", ")}]`
|
|
@@ -2249,18 +2432,18 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2249
2432
|
},
|
|
2250
2433
|
visitTupleValue(node, { self }) {
|
|
2251
2434
|
return mergeManifests(
|
|
2252
|
-
node.items.map((v) =>
|
|
2435
|
+
node.items.map((v) => visit5(v, self)),
|
|
2253
2436
|
{ mergeValues: (renders) => `[${renders.join(", ")}]` }
|
|
2254
2437
|
);
|
|
2255
2438
|
},
|
|
2256
2439
|
visitZeroableOptionType(node, { self }) {
|
|
2257
|
-
const childManifest =
|
|
2440
|
+
const childManifest = visit5(node.item, self);
|
|
2258
2441
|
childManifest.strictType.mapRender((r) => `Option<${r}>`).addImports("solanaOptions", "type Option");
|
|
2259
2442
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2260
2443
|
const encoderOptions = ["prefix: null"];
|
|
2261
2444
|
const decoderOptions = ["prefix: null"];
|
|
2262
2445
|
if (node.zeroValue) {
|
|
2263
|
-
const zeroValueManifest =
|
|
2446
|
+
const zeroValueManifest = visit5(node.zeroValue, self);
|
|
2264
2447
|
childManifest.encoder.mergeImportsWith(zeroValueManifest.value);
|
|
2265
2448
|
childManifest.decoder.mergeImportsWith(zeroValueManifest.value);
|
|
2266
2449
|
encoderOptions.push(`noneValue: ${zeroValueManifest.value.render}`);
|
|
@@ -2280,93 +2463,96 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2280
2463
|
);
|
|
2281
2464
|
}
|
|
2282
2465
|
function getArrayLikeSizeOption(count, visitor) {
|
|
2283
|
-
if (
|
|
2466
|
+
if (isNode13(count, "fixedCountNode")) {
|
|
2284
2467
|
return {
|
|
2285
2468
|
decoder: fragment(`size: ${count.value}`),
|
|
2286
2469
|
encoder: fragment(`size: ${count.value}`)
|
|
2287
2470
|
};
|
|
2288
2471
|
}
|
|
2289
|
-
if (
|
|
2472
|
+
if (isNode13(count, "remainderCountNode")) {
|
|
2290
2473
|
return {
|
|
2291
2474
|
decoder: fragment(`size: 'remainder'`),
|
|
2292
2475
|
encoder: fragment(`size: 'remainder'`)
|
|
2293
2476
|
};
|
|
2294
2477
|
}
|
|
2295
|
-
const prefix =
|
|
2478
|
+
const prefix = resolveNestedTypeNode2(count.prefix);
|
|
2296
2479
|
if (prefix.format === "u32" && prefix.endian === "le") {
|
|
2297
2480
|
return { decoder: fragment(""), encoder: fragment("") };
|
|
2298
2481
|
}
|
|
2299
|
-
const prefixManifest =
|
|
2482
|
+
const prefixManifest = visit5(count.prefix, visitor);
|
|
2300
2483
|
prefixManifest.encoder.mapRender((r) => `size: ${r}`);
|
|
2301
2484
|
prefixManifest.decoder.mapRender((r) => `size: ${r}`);
|
|
2302
2485
|
return prefixManifest;
|
|
2303
2486
|
}
|
|
2487
|
+
|
|
2488
|
+
// src/nameTransformers.ts
|
|
2489
|
+
import { camelCase as camelCase11, capitalize, kebabCase as kebabCase2, pascalCase as pascalCase7, snakeCase as snakeCase2, titleCase as titleCase2 } from "@codama/nodes";
|
|
2304
2490
|
function getNameApi(transformers) {
|
|
2305
2491
|
const helpers = {
|
|
2306
|
-
camelCase:
|
|
2492
|
+
camelCase: camelCase11,
|
|
2307
2493
|
capitalize,
|
|
2308
|
-
kebabCase:
|
|
2309
|
-
pascalCase:
|
|
2310
|
-
snakeCase:
|
|
2311
|
-
titleCase:
|
|
2494
|
+
kebabCase: kebabCase2,
|
|
2495
|
+
pascalCase: pascalCase7,
|
|
2496
|
+
snakeCase: snakeCase2,
|
|
2497
|
+
titleCase: titleCase2
|
|
2312
2498
|
};
|
|
2313
2499
|
return Object.fromEntries(
|
|
2314
2500
|
Object.entries(transformers).map(([key, transformer]) => [key, (name) => transformer(name, helpers)])
|
|
2315
2501
|
);
|
|
2316
2502
|
}
|
|
2317
2503
|
var DEFAULT_NAME_TRANSFORMERS = {
|
|
2318
|
-
accountDecodeFunction: (name) => `decode${
|
|
2319
|
-
accountFetchAllFunction: (name) => `fetchAll${
|
|
2320
|
-
accountFetchAllMaybeFunction: (name) => `fetchAllMaybe${
|
|
2321
|
-
accountFetchFromSeedsFunction: (name) => `fetch${
|
|
2322
|
-
accountFetchFunction: (name) => `fetch${
|
|
2323
|
-
accountFetchMaybeFromSeedsFunction: (name) => `fetchMaybe${
|
|
2324
|
-
accountFetchMaybeFunction: (name) => `fetchMaybe${
|
|
2325
|
-
accountGetSizeFunction: (name) => `get${
|
|
2326
|
-
codecFunction: (name) => `get${
|
|
2327
|
-
constant: (name) =>
|
|
2328
|
-
constantFunction: (name) => `get${
|
|
2329
|
-
dataArgsType: (name) => `${
|
|
2330
|
-
dataType: (name) => `${
|
|
2331
|
-
decoderFunction: (name) => `get${
|
|
2504
|
+
accountDecodeFunction: (name) => `decode${pascalCase7(name)}`,
|
|
2505
|
+
accountFetchAllFunction: (name) => `fetchAll${pascalCase7(name)}`,
|
|
2506
|
+
accountFetchAllMaybeFunction: (name) => `fetchAllMaybe${pascalCase7(name)}`,
|
|
2507
|
+
accountFetchFromSeedsFunction: (name) => `fetch${pascalCase7(name)}FromSeeds`,
|
|
2508
|
+
accountFetchFunction: (name) => `fetch${pascalCase7(name)}`,
|
|
2509
|
+
accountFetchMaybeFromSeedsFunction: (name) => `fetchMaybe${pascalCase7(name)}FromSeeds`,
|
|
2510
|
+
accountFetchMaybeFunction: (name) => `fetchMaybe${pascalCase7(name)}`,
|
|
2511
|
+
accountGetSizeFunction: (name) => `get${pascalCase7(name)}Size`,
|
|
2512
|
+
codecFunction: (name) => `get${pascalCase7(name)}Codec`,
|
|
2513
|
+
constant: (name) => snakeCase2(name).toUpperCase(),
|
|
2514
|
+
constantFunction: (name) => `get${pascalCase7(name)}Bytes`,
|
|
2515
|
+
dataArgsType: (name) => `${pascalCase7(name)}Args`,
|
|
2516
|
+
dataType: (name) => `${pascalCase7(name)}`,
|
|
2517
|
+
decoderFunction: (name) => `get${pascalCase7(name)}Decoder`,
|
|
2332
2518
|
discriminatedUnionDiscriminator: () => "__kind",
|
|
2333
|
-
discriminatedUnionFunction: (name) => `${
|
|
2334
|
-
discriminatedUnionVariant: (name) => `${
|
|
2335
|
-
encoderFunction: (name) => `get${
|
|
2336
|
-
enumVariant: (name) => `${
|
|
2337
|
-
instructionAsyncFunction: (name) => `get${
|
|
2338
|
-
instructionAsyncInputType: (name) => `${
|
|
2339
|
-
instructionDataType: (name) => `${
|
|
2340
|
-
instructionExtraType: (name) => `${
|
|
2341
|
-
instructionParseFunction: (name) => `parse${
|
|
2342
|
-
instructionParsedType: (name) => `Parsed${
|
|
2343
|
-
instructionSyncFunction: (name) => `get${
|
|
2344
|
-
instructionSyncInputType: (name) => `${
|
|
2345
|
-
instructionType: (name) => `${
|
|
2346
|
-
isDiscriminatedUnionFunction: (name) => `is${
|
|
2347
|
-
pdaFindFunction: (name) => `find${
|
|
2348
|
-
pdaSeedsType: (name) => `${
|
|
2349
|
-
programAccountsEnum: (name) => `${
|
|
2350
|
-
programAccountsEnumVariant: (name) => `${
|
|
2351
|
-
programAccountsIdentifierFunction: (name) => `identify${
|
|
2352
|
-
programAddressConstant: (name) => `${
|
|
2353
|
-
programErrorConstant: (name) =>
|
|
2354
|
-
programErrorConstantPrefix: (name) => `${
|
|
2355
|
-
programErrorMessagesMap: (name) => `${
|
|
2356
|
-
programErrorUnion: (name) => `${
|
|
2357
|
-
programGetErrorMessageFunction: (name) => `get${
|
|
2358
|
-
programInstructionsEnum: (name) => `${
|
|
2359
|
-
programInstructionsEnumVariant: (name) => `${
|
|
2360
|
-
programInstructionsIdentifierFunction: (name) => `identify${
|
|
2361
|
-
programInstructionsParsedUnionType: (name) => `Parsed${
|
|
2362
|
-
programIsErrorFunction: (name) => `is${
|
|
2363
|
-
resolverFunction: (name) => `${
|
|
2519
|
+
discriminatedUnionFunction: (name) => `${camelCase11(name)}`,
|
|
2520
|
+
discriminatedUnionVariant: (name) => `${pascalCase7(name)}`,
|
|
2521
|
+
encoderFunction: (name) => `get${pascalCase7(name)}Encoder`,
|
|
2522
|
+
enumVariant: (name) => `${pascalCase7(name)}`,
|
|
2523
|
+
instructionAsyncFunction: (name) => `get${pascalCase7(name)}InstructionAsync`,
|
|
2524
|
+
instructionAsyncInputType: (name) => `${pascalCase7(name)}AsyncInput`,
|
|
2525
|
+
instructionDataType: (name) => `${pascalCase7(name)}InstructionData`,
|
|
2526
|
+
instructionExtraType: (name) => `${pascalCase7(name)}InstructionExtra`,
|
|
2527
|
+
instructionParseFunction: (name) => `parse${pascalCase7(name)}Instruction`,
|
|
2528
|
+
instructionParsedType: (name) => `Parsed${pascalCase7(name)}Instruction`,
|
|
2529
|
+
instructionSyncFunction: (name) => `get${pascalCase7(name)}Instruction`,
|
|
2530
|
+
instructionSyncInputType: (name) => `${pascalCase7(name)}Input`,
|
|
2531
|
+
instructionType: (name) => `${pascalCase7(name)}Instruction`,
|
|
2532
|
+
isDiscriminatedUnionFunction: (name) => `is${pascalCase7(name)}`,
|
|
2533
|
+
pdaFindFunction: (name) => `find${pascalCase7(name)}Pda`,
|
|
2534
|
+
pdaSeedsType: (name) => `${pascalCase7(name)}Seeds`,
|
|
2535
|
+
programAccountsEnum: (name) => `${pascalCase7(name)}Account`,
|
|
2536
|
+
programAccountsEnumVariant: (name) => `${pascalCase7(name)}`,
|
|
2537
|
+
programAccountsIdentifierFunction: (name) => `identify${pascalCase7(name)}Account`,
|
|
2538
|
+
programAddressConstant: (name) => `${snakeCase2(name).toUpperCase()}_PROGRAM_ADDRESS`,
|
|
2539
|
+
programErrorConstant: (name) => snakeCase2(name).toUpperCase(),
|
|
2540
|
+
programErrorConstantPrefix: (name) => `${snakeCase2(name).toUpperCase()}_ERROR__`,
|
|
2541
|
+
programErrorMessagesMap: (name) => `${camelCase11(name)}ErrorMessages`,
|
|
2542
|
+
programErrorUnion: (name) => `${pascalCase7(name)}Error`,
|
|
2543
|
+
programGetErrorMessageFunction: (name) => `get${pascalCase7(name)}ErrorMessage`,
|
|
2544
|
+
programInstructionsEnum: (name) => `${pascalCase7(name)}Instruction`,
|
|
2545
|
+
programInstructionsEnumVariant: (name) => `${pascalCase7(name)}`,
|
|
2546
|
+
programInstructionsIdentifierFunction: (name) => `identify${pascalCase7(name)}Instruction`,
|
|
2547
|
+
programInstructionsParsedUnionType: (name) => `Parsed${pascalCase7(name)}Instruction`,
|
|
2548
|
+
programIsErrorFunction: (name) => `is${pascalCase7(name)}Error`,
|
|
2549
|
+
resolverFunction: (name) => `${camelCase11(name)}`
|
|
2364
2550
|
};
|
|
2365
2551
|
|
|
2366
2552
|
// src/getRenderMapVisitor.ts
|
|
2367
2553
|
function getRenderMapVisitor(options = {}) {
|
|
2368
|
-
const linkables = new
|
|
2369
|
-
const stack = new
|
|
2554
|
+
const linkables = new LinkableDictionary3();
|
|
2555
|
+
const stack = new NodeStack2();
|
|
2370
2556
|
const nameTransformers = {
|
|
2371
2557
|
...DEFAULT_NAME_TRANSFORMERS,
|
|
2372
2558
|
...options.nameTransformers
|
|
@@ -2375,9 +2561,9 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2375
2561
|
const renderParentInstructions = options.renderParentInstructions ?? false;
|
|
2376
2562
|
const dependencyMap = options.dependencyMap ?? {};
|
|
2377
2563
|
const useGranularImports = options.useGranularImports ?? false;
|
|
2378
|
-
const asyncResolvers = (options.asyncResolvers ?? []).map(
|
|
2379
|
-
const nonScalarEnums = (options.nonScalarEnums ?? []).map(
|
|
2380
|
-
const internalNodes = (options.internalNodes ?? []).map(
|
|
2564
|
+
const asyncResolvers = (options.asyncResolvers ?? []).map(camelCase12);
|
|
2565
|
+
const nonScalarEnums = (options.nonScalarEnums ?? []).map(camelCase12);
|
|
2566
|
+
const internalNodes = (options.internalNodes ?? []).map(camelCase12);
|
|
2381
2567
|
const customAccountData = parseCustomDataOptions(options.customAccountData ?? [], "AccountData");
|
|
2382
2568
|
const customInstructionData = parseCustomDataOptions(options.customInstructionData ?? [], "InstructionData");
|
|
2383
2569
|
const getImportFrom = getImportFromFactory(options.linkOverrides ?? {}, customAccountData, customInstructionData);
|
|
@@ -2403,24 +2589,24 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2403
2589
|
typeManifestVisitor
|
|
2404
2590
|
};
|
|
2405
2591
|
const render2 = (template, context, renderOptions) => {
|
|
2406
|
-
return render(
|
|
2592
|
+
return render(join3("pages", template), context, renderOptions);
|
|
2407
2593
|
};
|
|
2408
|
-
return
|
|
2409
|
-
|
|
2594
|
+
return pipe2(
|
|
2595
|
+
staticVisitor2(() => new RenderMap(), {
|
|
2410
2596
|
keys: ["rootNode", "programNode", "pdaNode", "accountNode", "definedTypeNode", "instructionNode"]
|
|
2411
2597
|
}),
|
|
2412
|
-
(v) =>
|
|
2598
|
+
(v) => extendVisitor2(v, {
|
|
2413
2599
|
visitAccount(node) {
|
|
2414
2600
|
const accountPath = stack.getPath("accountNode");
|
|
2415
|
-
if (!
|
|
2601
|
+
if (!findProgramNodeFromPath7(accountPath)) {
|
|
2416
2602
|
throw new Error("Account must be visited inside a program.");
|
|
2417
2603
|
}
|
|
2418
2604
|
const scope = {
|
|
2419
2605
|
...globalScope,
|
|
2420
2606
|
accountPath,
|
|
2421
|
-
typeManifest:
|
|
2607
|
+
typeManifest: visit6(node, typeManifestVisitor)
|
|
2422
2608
|
};
|
|
2423
|
-
const fields =
|
|
2609
|
+
const fields = resolveNestedTypeNode3(node.data).fields;
|
|
2424
2610
|
const accountDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2425
2611
|
...scope,
|
|
2426
2612
|
discriminatorNodes: node.discriminators ?? [],
|
|
@@ -2439,7 +2625,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2439
2625
|
accountPdaHelpersFragment
|
|
2440
2626
|
);
|
|
2441
2627
|
return new RenderMap().add(
|
|
2442
|
-
`accounts/${
|
|
2628
|
+
`accounts/${camelCase12(node.name)}.ts`,
|
|
2443
2629
|
render2("accountsPage.njk", {
|
|
2444
2630
|
accountDiscriminatorConstantsFragment,
|
|
2445
2631
|
accountFetchHelpersFragment,
|
|
@@ -2456,7 +2642,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2456
2642
|
codecDocs: [],
|
|
2457
2643
|
decoderDocs: [],
|
|
2458
2644
|
encoderDocs: [],
|
|
2459
|
-
manifest:
|
|
2645
|
+
manifest: visit6(node, typeManifestVisitor),
|
|
2460
2646
|
name: node.name,
|
|
2461
2647
|
typeDocs: node.docs,
|
|
2462
2648
|
typeNode: node.type
|
|
@@ -2471,7 +2657,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2471
2657
|
nameApi.codecFunction(node.name)
|
|
2472
2658
|
]);
|
|
2473
2659
|
return new RenderMap().add(
|
|
2474
|
-
`types/${
|
|
2660
|
+
`types/${camelCase12(node.name)}.ts`,
|
|
2475
2661
|
render2("definedTypesPage.njk", {
|
|
2476
2662
|
imports: imports.toString({
|
|
2477
2663
|
...dependencyMap,
|
|
@@ -2484,23 +2670,23 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2484
2670
|
},
|
|
2485
2671
|
visitInstruction(node) {
|
|
2486
2672
|
const instructionPath = stack.getPath("instructionNode");
|
|
2487
|
-
if (!
|
|
2673
|
+
if (!findProgramNodeFromPath7(instructionPath)) {
|
|
2488
2674
|
throw new Error("Instruction must be visited inside a program.");
|
|
2489
2675
|
}
|
|
2490
2676
|
const instructionExtraName = nameApi.instructionExtraType(node.name);
|
|
2491
2677
|
const scope = {
|
|
2492
2678
|
...globalScope,
|
|
2493
|
-
dataArgsManifest:
|
|
2494
|
-
extraArgsManifest:
|
|
2495
|
-
|
|
2679
|
+
dataArgsManifest: visit6(node, typeManifestVisitor),
|
|
2680
|
+
extraArgsManifest: visit6(
|
|
2681
|
+
definedTypeNode2({
|
|
2496
2682
|
name: instructionExtraName,
|
|
2497
|
-
type:
|
|
2683
|
+
type: structTypeNodeFromInstructionArgumentNodes4(node.extraArguments ?? [])
|
|
2498
2684
|
}),
|
|
2499
2685
|
typeManifestVisitor
|
|
2500
2686
|
),
|
|
2501
2687
|
instructionPath,
|
|
2502
2688
|
renamedArgs: getRenamedArgsMap(node),
|
|
2503
|
-
resolvedInputs:
|
|
2689
|
+
resolvedInputs: visit6(node, resolvedInstructionInputVisitor)
|
|
2504
2690
|
};
|
|
2505
2691
|
const instructionDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2506
2692
|
...scope,
|
|
@@ -2530,7 +2716,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2530
2716
|
instructionParseFunctionFragment
|
|
2531
2717
|
);
|
|
2532
2718
|
return new RenderMap().add(
|
|
2533
|
-
`instructions/${
|
|
2719
|
+
`instructions/${camelCase12(node.name)}.ts`,
|
|
2534
2720
|
render2("instructionsPage.njk", {
|
|
2535
2721
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2536
2722
|
instruction: node,
|
|
@@ -2546,14 +2732,14 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2546
2732
|
},
|
|
2547
2733
|
visitPda(node) {
|
|
2548
2734
|
const pdaPath = stack.getPath("pdaNode");
|
|
2549
|
-
if (!
|
|
2735
|
+
if (!findProgramNodeFromPath7(pdaPath)) {
|
|
2550
2736
|
throw new Error("Account must be visited inside a program.");
|
|
2551
2737
|
}
|
|
2552
2738
|
const scope = { ...globalScope, pdaPath };
|
|
2553
2739
|
const pdaFunctionFragment = getPdaFunctionFragment(scope);
|
|
2554
2740
|
const imports = new ImportMap().mergeWith(pdaFunctionFragment);
|
|
2555
2741
|
return new RenderMap().add(
|
|
2556
|
-
`pdas/${
|
|
2742
|
+
`pdas/${camelCase12(node.name)}.ts`,
|
|
2557
2743
|
render2("pdasPage.njk", {
|
|
2558
2744
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2559
2745
|
pdaFunctionFragment
|
|
@@ -2566,11 +2752,11 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2566
2752
|
...getDefinedTypeNodesToExtract(node.instructions, customInstructionData)
|
|
2567
2753
|
];
|
|
2568
2754
|
const scope = { ...globalScope, programNode: node };
|
|
2569
|
-
const renderMap = new RenderMap().mergeWith(...node.pdas.map((p) =>
|
|
2755
|
+
const renderMap = new RenderMap().mergeWith(...node.pdas.map((p) => visit6(p, self))).mergeWith(...node.accounts.map((a) => visit6(a, self))).mergeWith(...node.definedTypes.map((t) => visit6(t, self))).mergeWith(...customDataDefinedType.map((t) => visit6(t, self)));
|
|
2570
2756
|
if (node.errors.length > 0) {
|
|
2571
2757
|
const programErrorsFragment = getProgramErrorsFragment(scope);
|
|
2572
2758
|
renderMap.add(
|
|
2573
|
-
`errors/${
|
|
2759
|
+
`errors/${camelCase12(node.name)}.ts`,
|
|
2574
2760
|
render2("errorsPage.njk", {
|
|
2575
2761
|
imports: new ImportMap().mergeWith(programErrorsFragment).toString(dependencyMap, useGranularImports),
|
|
2576
2762
|
programErrorsFragment
|
|
@@ -2581,7 +2767,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2581
2767
|
const programAccountsFragment = getProgramAccountsFragment(scope);
|
|
2582
2768
|
const programInstructionsFragment = getProgramInstructionsFragment(scope);
|
|
2583
2769
|
renderMap.add(
|
|
2584
|
-
`programs/${
|
|
2770
|
+
`programs/${camelCase12(node.name)}.ts`,
|
|
2585
2771
|
render2("programsPage.njk", {
|
|
2586
2772
|
imports: new ImportMap().mergeWith(programFragment, programAccountsFragment, programInstructionsFragment).toString(dependencyMap, useGranularImports),
|
|
2587
2773
|
programAccountsFragment,
|
|
@@ -2590,9 +2776,9 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2590
2776
|
})
|
|
2591
2777
|
);
|
|
2592
2778
|
renderMap.mergeWith(
|
|
2593
|
-
...
|
|
2779
|
+
...getAllInstructionsWithSubs2(node, {
|
|
2594
2780
|
leavesOnly: !renderParentInstructions
|
|
2595
|
-
}).map((ix) =>
|
|
2781
|
+
}).map((ix) => visit6(ix, self))
|
|
2596
2782
|
);
|
|
2597
2783
|
return renderMap;
|
|
2598
2784
|
},
|
|
@@ -2602,7 +2788,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2602
2788
|
const programsWithErrorsToExport = programsToExport.filter((p) => p.errors.length > 0);
|
|
2603
2789
|
const pdasToExport = getAllPdas(node);
|
|
2604
2790
|
const accountsToExport = getAllAccounts(node).filter(isNotInternal);
|
|
2605
|
-
const instructionsToExport =
|
|
2791
|
+
const instructionsToExport = getAllInstructionsWithSubs2(node, {
|
|
2606
2792
|
leavesOnly: !renderParentInstructions
|
|
2607
2793
|
}).filter(isNotInternal);
|
|
2608
2794
|
const definedTypesToExport = getAllDefinedTypes(node).filter(isNotInternal);
|
|
@@ -2635,7 +2821,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2635
2821
|
"type IAccountSignerMeta",
|
|
2636
2822
|
"isTransactionSigner",
|
|
2637
2823
|
"type TransactionSigner"
|
|
2638
|
-
]).addAlias("solanaSigners", "isTransactionSigner", "
|
|
2824
|
+
]).addAlias("solanaSigners", "isTransactionSigner", "kitIsTransactionSigner").toString(dependencyMap, useGranularImports)
|
|
2639
2825
|
})
|
|
2640
2826
|
);
|
|
2641
2827
|
}
|
|
@@ -2657,10 +2843,10 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2657
2843
|
if (definedTypesToExport.length > 0) {
|
|
2658
2844
|
map.add("types/index.ts", render2("definedTypesIndex.njk", ctx));
|
|
2659
2845
|
}
|
|
2660
|
-
return map.add("index.ts", render2("rootIndex.njk", ctx)).mergeWith(...getAllPrograms(node).map((p) =>
|
|
2846
|
+
return map.add("index.ts", render2("rootIndex.njk", ctx)).mergeWith(...getAllPrograms(node).map((p) => visit6(p, self)));
|
|
2661
2847
|
}
|
|
2662
2848
|
}),
|
|
2663
|
-
(v) =>
|
|
2849
|
+
(v) => recordNodeStackVisitor2(v, stack),
|
|
2664
2850
|
(v) => recordLinkablesOnFirstVisitVisitor(v, linkables)
|
|
2665
2851
|
);
|
|
2666
2852
|
}
|
|
@@ -2679,8 +2865,15 @@ function getRenamedArgsMap(instruction) {
|
|
|
2679
2865
|
logWarn(
|
|
2680
2866
|
`[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.`
|
|
2681
2867
|
);
|
|
2682
|
-
return new Map(duplicates.map((name) => [
|
|
2868
|
+
return new Map(duplicates.map((name) => [camelCase12(name), camelCase12(`${name}Arg`)]));
|
|
2683
2869
|
}
|
|
2870
|
+
|
|
2871
|
+
// src/renderVisitor.ts
|
|
2872
|
+
import { deleteDirectory } from "@codama/renderers-core";
|
|
2873
|
+
import { rootNodeVisitor, visit as visit7 } from "@codama/visitors-core";
|
|
2874
|
+
import * as estreePlugin from "prettier/plugins/estree";
|
|
2875
|
+
import * as typeScriptPlugin from "prettier/plugins/typescript";
|
|
2876
|
+
import { format } from "prettier/standalone";
|
|
2684
2877
|
var DEFAULT_PRETTIER_OPTIONS = {
|
|
2685
2878
|
arrowParens: "always",
|
|
2686
2879
|
parser: "typescript",
|
|
@@ -2697,7 +2890,7 @@ function renderVisitor(path, options = {}) {
|
|
|
2697
2890
|
if (options.deleteFolderBeforeRendering ?? true) {
|
|
2698
2891
|
deleteDirectory(path);
|
|
2699
2892
|
}
|
|
2700
|
-
const renderMap =
|
|
2893
|
+
const renderMap = visit7(root, getRenderMapVisitor(options));
|
|
2701
2894
|
if (options.formatCode ?? true) {
|
|
2702
2895
|
const prettierOptions = { ...DEFAULT_PRETTIER_OPTIONS, ...options.prettierOptions };
|
|
2703
2896
|
await renderMap.mapContentAsync((code) => format(code, prettierOptions));
|
|
@@ -2705,7 +2898,15 @@ function renderVisitor(path, options = {}) {
|
|
|
2705
2898
|
renderMap.write(path);
|
|
2706
2899
|
});
|
|
2707
2900
|
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2901
|
+
export {
|
|
2902
|
+
DEFAULT_NAME_TRANSFORMERS,
|
|
2903
|
+
ImportMap,
|
|
2904
|
+
renderVisitor as default,
|
|
2905
|
+
getNameApi,
|
|
2906
|
+
getRenderMapVisitor,
|
|
2907
|
+
getTypeManifestVisitor,
|
|
2908
|
+
mergeManifests,
|
|
2909
|
+
renderVisitor,
|
|
2910
|
+
typeManifest
|
|
2911
|
+
};
|
|
2711
2912
|
//# sourceMappingURL=index.node.mjs.map
|