@codama/renderers-js 1.2.6 → 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/dist/index.node.cjs +535 -408
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +474 -272
- package/dist/index.node.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.node.mjs
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import { NodeStack, pipe, staticVisitor, extendVisitor, visit, findLastNodeFromPath, recordNodeStackVisitor, LinkableDictionary, getResolvedInstructionInputsVisitor, findProgramNodeFromPath, recordLinkablesOnFirstVisitVisitor, rootNodeVisitor, getLastNodeFromPath, findInstructionNodeFromPath, deduplicateInstructionDependencies } from '@codama/visitors-core';
|
|
2
|
-
import { join, dirname } from 'node:path';
|
|
3
|
-
import { camelCase, pascalCase, snakeCase, REGISTERED_TYPE_NODE_KINDS, REGISTERED_VALUE_NODE_KINDS, isNodeFilter, resolveNestedTypeNode, structTypeNodeFromInstructionArgumentNodes, isNode, isScalarEnum, structTypeNode, structFieldTypeNode, titleCase, kebabCase, capitalize, getAllPrograms, getAllPdas, getAllAccounts, getAllInstructionsWithSubs, getAllDefinedTypes, definedTypeNode, definedTypeLinkNode, isDataEnum, accountValueNode, argumentValueNode, VALUE_NODES, getAllInstructionArguments, constantDiscriminatorNode, constantValueNodeFromBytes, constantValueNode, assertIsNode } 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
3
|
solanaAccounts: "@solana/kit",
|
|
@@ -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,9 +448,13 @@ 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
459
|
const pdaNode = accountNode.pda ? linkables.get([...accountPath, accountNode.pda]) : void 0;
|
|
433
460
|
if (!pdaNode) {
|
|
@@ -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,15 +655,23 @@ 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
|
-
const { instructionAccountPath, linkables } = scope;
|
|
613
|
-
const instructionAccountNode =
|
|
667
|
+
const { instructionAccountPath, allowAccountMeta, linkables } = scope;
|
|
668
|
+
const instructionAccountNode = getLastNodeFromPath5(instructionAccountPath);
|
|
614
669
|
const instructionNode = findInstructionNodeFromPath(instructionAccountPath);
|
|
615
|
-
const programNode =
|
|
616
|
-
const typeParam = `TAccount${
|
|
617
|
-
const accountMeta = " | IAccountMeta<string>" ;
|
|
670
|
+
const programNode = findProgramNodeFromPath2(instructionAccountPath);
|
|
671
|
+
const typeParam = `TAccount${pascalCase3(instructionAccountNode.name)}`;
|
|
672
|
+
const accountMeta = allowAccountMeta ? " | IAccountMeta<string>" : "";
|
|
618
673
|
const imports = new ImportMap();
|
|
619
|
-
{
|
|
674
|
+
if (allowAccountMeta) {
|
|
620
675
|
imports.add("solanaInstructions", "type IAccountMeta");
|
|
621
676
|
}
|
|
622
677
|
if (instructionNode.optionalAccountStrategy === "omitted" && instructionAccountNode.isOptional) {
|
|
@@ -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,8 +866,8 @@ 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
873
|
if (input.kind === "instructionAccountNode" && isWritable === void 0) {
|
|
@@ -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,7 +1050,7 @@ ${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
|
}
|
|
@@ -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,20 +1468,25 @@ 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({
|
|
1372
1488
|
...scope,
|
|
1489
|
+
allowAccountMeta: true,
|
|
1373
1490
|
instructionAccountPath: [...instructionPath, account]
|
|
1374
1491
|
})
|
|
1375
1492
|
),
|
|
@@ -1379,7 +1496,7 @@ function getInstructionTypeFragment(scope) {
|
|
|
1379
1496
|
const accountMetasFragment = mergeFragments(
|
|
1380
1497
|
instructionNode.accounts.map(
|
|
1381
1498
|
(account) => getInstructionAccountMetaFragment(account).mapRender((r) => {
|
|
1382
|
-
const typeParam = `TAccount${
|
|
1499
|
+
const typeParam = `TAccount${pascalCase6(account.name)}`;
|
|
1383
1500
|
const isLegacyOptional = account.isOptional && usesLegacyOptionalAccounts;
|
|
1384
1501
|
const type = `${typeParam} extends string ? ${r} : ${typeParam}`;
|
|
1385
1502
|
if (!isLegacyOptional) return type;
|
|
@@ -1405,28 +1522,32 @@ function getInstructionTypeFragment(scope) {
|
|
|
1405
1522
|
]);
|
|
1406
1523
|
return fragment2;
|
|
1407
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";
|
|
1408
1529
|
function getPdaFunctionFragment(scope) {
|
|
1409
1530
|
const { pdaPath, typeManifestVisitor, nameApi } = scope;
|
|
1410
|
-
const pdaNode =
|
|
1411
|
-
const programNode =
|
|
1531
|
+
const pdaNode = getLastNodeFromPath15(pdaPath);
|
|
1532
|
+
const programNode = findProgramNodeFromPath6(pdaPath);
|
|
1412
1533
|
const imports = new ImportMap();
|
|
1413
1534
|
const seeds = pdaNode.seeds.map((seed) => {
|
|
1414
|
-
if (
|
|
1415
|
-
const seedManifest2 =
|
|
1535
|
+
if (isNode11(seed, "variablePdaSeedNode")) {
|
|
1536
|
+
const seedManifest2 = visit4(seed.type, typeManifestVisitor);
|
|
1416
1537
|
imports.mergeWith(seedManifest2.looseType, seedManifest2.encoder);
|
|
1417
1538
|
return { ...seed, typeManifest: seedManifest2 };
|
|
1418
1539
|
}
|
|
1419
|
-
if (
|
|
1540
|
+
if (isNode11(seed.value, "programIdValueNode")) {
|
|
1420
1541
|
imports.add("solanaAddresses", "getAddressEncoder");
|
|
1421
1542
|
return seed;
|
|
1422
1543
|
}
|
|
1423
|
-
const seedManifest =
|
|
1544
|
+
const seedManifest = visit4(seed.type, typeManifestVisitor);
|
|
1424
1545
|
imports.mergeWith(seedManifest.encoder);
|
|
1425
|
-
const valueManifest =
|
|
1546
|
+
const valueManifest = visit4(seed.value, typeManifestVisitor).value;
|
|
1426
1547
|
imports.mergeWith(valueManifest.imports);
|
|
1427
1548
|
return { ...seed, typeManifest: seedManifest, valueManifest };
|
|
1428
1549
|
});
|
|
1429
|
-
const hasVariableSeeds = pdaNode.seeds.filter(
|
|
1550
|
+
const hasVariableSeeds = pdaNode.seeds.filter(isNodeFilter5("variablePdaSeedNode")).length > 0;
|
|
1430
1551
|
return fragmentFromTemplate("pdaFunction.njk", {
|
|
1431
1552
|
findPdaFunction: nameApi.pdaFindFunction(pdaNode.name),
|
|
1432
1553
|
hasVariableSeeds,
|
|
@@ -1444,6 +1565,9 @@ function getProgramFragment(scope) {
|
|
|
1444
1565
|
programAddressConstant: nameApi.programAddressConstant(programNode.name)
|
|
1445
1566
|
}).addImports("solanaAddresses", ["type Address"]);
|
|
1446
1567
|
}
|
|
1568
|
+
|
|
1569
|
+
// src/fragments/programAccounts.ts
|
|
1570
|
+
import { resolveNestedTypeNode } from "@codama/nodes";
|
|
1447
1571
|
function getProgramAccountsFragment(scope) {
|
|
1448
1572
|
if (scope.programNode.accounts.length === 0) return fragment("");
|
|
1449
1573
|
return mergeFragments(
|
|
@@ -1505,6 +1629,12 @@ function getProgramErrorsFragment(scope) {
|
|
|
1505
1629
|
programIsErrorFunction: nameApi.programIsErrorFunction(programNode.name)
|
|
1506
1630
|
}).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaPrograms", ["isProgramError"]).addImports("solanaErrors", ["type SolanaError", "type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM"]).addImports("solanaAddresses", ["type Address"]);
|
|
1507
1631
|
}
|
|
1632
|
+
|
|
1633
|
+
// src/fragments/programInstructions.ts
|
|
1634
|
+
import {
|
|
1635
|
+
getAllInstructionsWithSubs,
|
|
1636
|
+
structTypeNodeFromInstructionArgumentNodes as structTypeNodeFromInstructionArgumentNodes2
|
|
1637
|
+
} from "@codama/nodes";
|
|
1508
1638
|
function getProgramInstructionsFragment(scope) {
|
|
1509
1639
|
if (scope.programNode.instructions.length === 0) return fragment("");
|
|
1510
1640
|
const allInstructions = getAllInstructionsWithSubs(scope.programNode, {
|
|
@@ -1549,7 +1679,7 @@ function getProgramInstructionsIdentifierFunctionFragment(scope) {
|
|
|
1549
1679
|
dataName: "data",
|
|
1550
1680
|
discriminators: instruction.discriminators ?? [],
|
|
1551
1681
|
ifTrue: `return ${programInstructionsEnum}.${variant};`,
|
|
1552
|
-
struct:
|
|
1682
|
+
struct: structTypeNodeFromInstructionArgumentNodes2(instruction.arguments)
|
|
1553
1683
|
});
|
|
1554
1684
|
}),
|
|
1555
1685
|
(r) => r.join("\n")
|
|
@@ -1582,9 +1712,12 @@ function getProgramInstructionsParsedUnionTypeFragment(scope) {
|
|
|
1582
1712
|
(r) => r.join("\n")
|
|
1583
1713
|
);
|
|
1584
1714
|
}
|
|
1715
|
+
|
|
1716
|
+
// src/fragments/typeDiscriminatedUnionHelpers.ts
|
|
1717
|
+
import { isDataEnum, isNode as isNode12 } from "@codama/nodes";
|
|
1585
1718
|
function getTypeDiscriminatedUnionHelpersFragment(scope) {
|
|
1586
1719
|
const { name, typeNode, nameApi } = scope;
|
|
1587
|
-
const isDiscriminatedUnion =
|
|
1720
|
+
const isDiscriminatedUnion = isNode12(typeNode, "enumTypeNode") && isDataEnum(typeNode);
|
|
1588
1721
|
if (!isDiscriminatedUnion) {
|
|
1589
1722
|
return fragment("");
|
|
1590
1723
|
}
|
|
@@ -1625,6 +1758,57 @@ function mergeManifests(manifests, options = {}) {
|
|
|
1625
1758
|
value: merge((m) => m.value, mergeValues)
|
|
1626
1759
|
};
|
|
1627
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";
|
|
1628
1812
|
function getTypeManifestVisitor(input) {
|
|
1629
1813
|
const { nameApi, linkables, nonScalarEnums, customAccountData, customInstructionData, getImportFrom } = input;
|
|
1630
1814
|
const stack = input.stack ?? new NodeStack();
|
|
@@ -1657,15 +1841,15 @@ function getTypeManifestVisitor(input) {
|
|
|
1657
1841
|
strict: nameApi.dataType(account.name)
|
|
1658
1842
|
};
|
|
1659
1843
|
const link = customAccountData.get(account.name)?.linkNode;
|
|
1660
|
-
const manifest = link ?
|
|
1844
|
+
const manifest = link ? visit5(link, self) : visit5(account.data, self);
|
|
1661
1845
|
parentName = null;
|
|
1662
1846
|
return manifest;
|
|
1663
1847
|
},
|
|
1664
1848
|
visitAmountType(amountType, { self }) {
|
|
1665
|
-
return
|
|
1849
|
+
return visit5(amountType.number, self);
|
|
1666
1850
|
},
|
|
1667
1851
|
visitArrayType(arrayType, { self }) {
|
|
1668
|
-
const childManifest =
|
|
1852
|
+
const childManifest = visit5(arrayType.item, self);
|
|
1669
1853
|
childManifest.looseType.mapRender((r) => `Array<${r}>`);
|
|
1670
1854
|
childManifest.strictType.mapRender((r) => `Array<${r}>`);
|
|
1671
1855
|
const sizeManifest = getArrayLikeSizeOption(arrayType.count, self);
|
|
@@ -1677,7 +1861,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1677
1861
|
},
|
|
1678
1862
|
visitArrayValue(node, { self }) {
|
|
1679
1863
|
return mergeManifests(
|
|
1680
|
-
node.items.map((v) =>
|
|
1864
|
+
node.items.map((v) => visit5(v, self)),
|
|
1681
1865
|
{ mergeValues: (renders) => `[${renders.join(", ")}]` }
|
|
1682
1866
|
);
|
|
1683
1867
|
},
|
|
@@ -1686,9 +1870,9 @@ function getTypeManifestVisitor(input) {
|
|
|
1686
1870
|
const decoderImports = new ImportMap().add("solanaCodecsDataStructures", "getBooleanDecoder");
|
|
1687
1871
|
let sizeEncoder = "";
|
|
1688
1872
|
let sizeDecoder = "";
|
|
1689
|
-
const resolvedSize =
|
|
1873
|
+
const resolvedSize = resolveNestedTypeNode2(booleanType.size);
|
|
1690
1874
|
if (resolvedSize.format !== "u8" || resolvedSize.endian !== "le") {
|
|
1691
|
-
const size =
|
|
1875
|
+
const size = visit5(booleanType.size, self);
|
|
1692
1876
|
encoderImports.mergeWith(size.encoder);
|
|
1693
1877
|
decoderImports.mergeWith(size.decoder);
|
|
1694
1878
|
sizeEncoder = `{ size: ${size.encoder.render} }`;
|
|
@@ -1737,26 +1921,26 @@ function getTypeManifestVisitor(input) {
|
|
|
1737
1921
|
return manifest;
|
|
1738
1922
|
},
|
|
1739
1923
|
visitConstantValue(node, { self }) {
|
|
1740
|
-
if (
|
|
1741
|
-
return
|
|
1924
|
+
if (isNode13(node.type, "bytesTypeNode") && isNode13(node.value, "bytesValueNode")) {
|
|
1925
|
+
return visit5(node.value, self);
|
|
1742
1926
|
}
|
|
1743
1927
|
return {
|
|
1744
1928
|
...typeManifest(),
|
|
1745
1929
|
value: mergeFragments(
|
|
1746
|
-
[
|
|
1930
|
+
[visit5(node.type, self).encoder, visit5(node.value, self).value],
|
|
1747
1931
|
([encoderFunction, value]) => `${encoderFunction}.encode(${value})`
|
|
1748
1932
|
)
|
|
1749
1933
|
};
|
|
1750
1934
|
},
|
|
1751
1935
|
visitDateTimeType(dateTimeType, { self }) {
|
|
1752
|
-
return
|
|
1936
|
+
return visit5(dateTimeType.number, self);
|
|
1753
1937
|
},
|
|
1754
1938
|
visitDefinedType(definedType, { self }) {
|
|
1755
1939
|
parentName = {
|
|
1756
1940
|
loose: nameApi.dataArgsType(definedType.name),
|
|
1757
1941
|
strict: nameApi.dataType(definedType.name)
|
|
1758
1942
|
};
|
|
1759
|
-
const manifest =
|
|
1943
|
+
const manifest = visit5(definedType.type, self);
|
|
1760
1944
|
parentName = null;
|
|
1761
1945
|
return manifest;
|
|
1762
1946
|
},
|
|
@@ -1776,7 +1960,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1776
1960
|
};
|
|
1777
1961
|
},
|
|
1778
1962
|
visitEnumEmptyVariantType(enumEmptyVariantType) {
|
|
1779
|
-
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1963
|
+
const discriminator = nameApi.discriminatedUnionDiscriminator(camelCase10(parentName?.strict ?? ""));
|
|
1780
1964
|
const name = nameApi.discriminatedUnionVariant(enumEmptyVariantType.name);
|
|
1781
1965
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1782
1966
|
return {
|
|
@@ -1797,12 +1981,12 @@ function getTypeManifestVisitor(input) {
|
|
|
1797
1981
|
visitEnumStructVariantType(enumStructVariantType, { self }) {
|
|
1798
1982
|
const currentParentName = parentName;
|
|
1799
1983
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1800
|
-
|
|
1984
|
+
camelCase10(currentParentName?.strict ?? "")
|
|
1801
1985
|
);
|
|
1802
1986
|
const name = nameApi.discriminatedUnionVariant(enumStructVariantType.name);
|
|
1803
1987
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
1804
1988
|
parentName = null;
|
|
1805
|
-
const structManifest =
|
|
1989
|
+
const structManifest = visit5(enumStructVariantType.struct, self);
|
|
1806
1990
|
parentName = currentParentName;
|
|
1807
1991
|
structManifest.strictType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
1808
1992
|
structManifest.looseType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
@@ -1813,7 +1997,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1813
1997
|
visitEnumTupleVariantType(enumTupleVariantType, { self }) {
|
|
1814
1998
|
const currentParentName = parentName;
|
|
1815
1999
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1816
|
-
|
|
2000
|
+
camelCase10(currentParentName?.strict ?? "")
|
|
1817
2001
|
);
|
|
1818
2002
|
const name = nameApi.discriminatedUnionVariant(enumTupleVariantType.name);
|
|
1819
2003
|
const kindAttribute = `${discriminator}: "${name}"`;
|
|
@@ -1824,7 +2008,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1824
2008
|
})
|
|
1825
2009
|
]);
|
|
1826
2010
|
parentName = null;
|
|
1827
|
-
const structManifest =
|
|
2011
|
+
const structManifest = visit5(struct, self);
|
|
1828
2012
|
parentName = currentParentName;
|
|
1829
2013
|
structManifest.strictType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
1830
2014
|
structManifest.looseType.mapRender((r) => `{ ${kindAttribute},${r.slice(1, -1)}}`);
|
|
@@ -1838,16 +2022,16 @@ function getTypeManifestVisitor(input) {
|
|
|
1838
2022
|
const decoderImports = new ImportMap();
|
|
1839
2023
|
const encoderOptions = [];
|
|
1840
2024
|
const decoderOptions = [];
|
|
1841
|
-
const enumSize =
|
|
2025
|
+
const enumSize = resolveNestedTypeNode2(enumType.size);
|
|
1842
2026
|
if (enumSize.format !== "u8" || enumSize.endian !== "le") {
|
|
1843
|
-
const sizeManifest =
|
|
2027
|
+
const sizeManifest = visit5(enumType.size, self);
|
|
1844
2028
|
encoderImports.mergeWith(sizeManifest.encoder);
|
|
1845
2029
|
decoderImports.mergeWith(sizeManifest.decoder);
|
|
1846
2030
|
encoderOptions.push(`size: ${sizeManifest.encoder.render}`);
|
|
1847
2031
|
decoderOptions.push(`size: ${sizeManifest.decoder.render}`);
|
|
1848
2032
|
}
|
|
1849
2033
|
const discriminator = nameApi.discriminatedUnionDiscriminator(
|
|
1850
|
-
|
|
2034
|
+
camelCase10(currentParentName?.strict ?? "")
|
|
1851
2035
|
);
|
|
1852
2036
|
if (!isScalarEnum(enumType) && discriminator !== "__kind") {
|
|
1853
2037
|
encoderOptions.push(`discriminator: '${discriminator}'`);
|
|
@@ -1878,7 +2062,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1878
2062
|
};
|
|
1879
2063
|
}
|
|
1880
2064
|
const mergedManifest = mergeManifests(
|
|
1881
|
-
enumType.variants.map((variant) =>
|
|
2065
|
+
enumType.variants.map((variant) => visit5(variant, self)),
|
|
1882
2066
|
{
|
|
1883
2067
|
mergeCodecs: (renders) => renders.join(", "),
|
|
1884
2068
|
mergeTypes: (renders) => renders.join(" | ")
|
|
@@ -1894,7 +2078,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1894
2078
|
const enumFunction = nameApi.discriminatedUnionFunction(node.enum.name);
|
|
1895
2079
|
const importFrom = getImportFrom(node.enum);
|
|
1896
2080
|
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
|
|
1897
|
-
const isScalar = enumNode &&
|
|
2081
|
+
const isScalar = enumNode && isNode13(enumNode, "enumTypeNode") ? isScalarEnum(enumNode) : !nonScalarEnums.includes(node.enum.name);
|
|
1898
2082
|
if (!node.value && isScalar) {
|
|
1899
2083
|
const variantName2 = nameApi.enumVariant(node.variant);
|
|
1900
2084
|
manifest.value.setRender(`${enumName}.${variantName2}`).addImports(importFrom, enumName);
|
|
@@ -1905,18 +2089,18 @@ function getTypeManifestVisitor(input) {
|
|
|
1905
2089
|
manifest.value.setRender(`${enumFunction}('${variantName}')`).addImports(importFrom, enumFunction);
|
|
1906
2090
|
return manifest;
|
|
1907
2091
|
}
|
|
1908
|
-
manifest.value =
|
|
2092
|
+
manifest.value = visit5(node.value, self).value.mapRender((r) => `${enumFunction}('${variantName}', ${r})`).addImports(importFrom, enumFunction);
|
|
1909
2093
|
return manifest;
|
|
1910
2094
|
},
|
|
1911
2095
|
visitFixedSizeType(node, { self }) {
|
|
1912
|
-
const manifest =
|
|
2096
|
+
const manifest = visit5(node.type, self);
|
|
1913
2097
|
manifest.encoder.mapRender((r) => `fixEncoderSize(${r}, ${node.size})`).addImports("solanaCodecsCore", "fixEncoderSize");
|
|
1914
2098
|
manifest.decoder.mapRender((r) => `fixDecoderSize(${r}, ${node.size})`).addImports("solanaCodecsCore", "fixDecoderSize");
|
|
1915
2099
|
return manifest;
|
|
1916
2100
|
},
|
|
1917
2101
|
visitHiddenPrefixType(node, { self }) {
|
|
1918
|
-
const manifest =
|
|
1919
|
-
const prefixes = node.prefix.map((c) =>
|
|
2102
|
+
const manifest = visit5(node.type, self);
|
|
2103
|
+
const prefixes = node.prefix.map((c) => visit5(c, self).value);
|
|
1920
2104
|
const prefixEncoders = fragment(prefixes.map((c) => `getConstantEncoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantEncoder").mergeImportsWith(...prefixes);
|
|
1921
2105
|
const prefixDecoders = fragment(prefixes.map((c) => `getConstantDecoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantDecoder").mergeImportsWith(...prefixes);
|
|
1922
2106
|
manifest.encoder.mapRender((r) => `getHiddenPrefixEncoder(${r}, [${prefixEncoders.render}])`).mergeImportsWith(prefixEncoders).addImports("solanaCodecsDataStructures", "getHiddenPrefixEncoder");
|
|
@@ -1924,8 +2108,8 @@ function getTypeManifestVisitor(input) {
|
|
|
1924
2108
|
return manifest;
|
|
1925
2109
|
},
|
|
1926
2110
|
visitHiddenSuffixType(node, { self }) {
|
|
1927
|
-
const manifest =
|
|
1928
|
-
const suffixes = node.suffix.map((c) =>
|
|
2111
|
+
const manifest = visit5(node.type, self);
|
|
2112
|
+
const suffixes = node.suffix.map((c) => visit5(c, self).value);
|
|
1929
2113
|
const suffixEncoders = fragment(suffixes.map((c) => `getConstantEncoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantEncoder").mergeImportsWith(...suffixes);
|
|
1930
2114
|
const suffixDecoders = fragment(suffixes.map((c) => `getConstantDecoder(${c.render})`).join(", ")).addImports("solanaCodecsCore", "getConstantDecoder").mergeImportsWith(...suffixes);
|
|
1931
2115
|
manifest.encoder.mapRender((r) => `getHiddenSuffixEncoder(${r}, [${suffixEncoders.render}])`).mergeImportsWith(suffixEncoders).addImports("solanaCodecsDataStructures", "getHiddenSuffixEncoder");
|
|
@@ -1939,19 +2123,19 @@ function getTypeManifestVisitor(input) {
|
|
|
1939
2123
|
strict: nameApi.dataType(instructionDataName)
|
|
1940
2124
|
};
|
|
1941
2125
|
const link = customInstructionData.get(instruction.name)?.linkNode;
|
|
1942
|
-
const struct =
|
|
1943
|
-
const manifest = link ?
|
|
2126
|
+
const struct = structTypeNodeFromInstructionArgumentNodes3(instruction.arguments);
|
|
2127
|
+
const manifest = link ? visit5(link, self) : visit5(struct, self);
|
|
1944
2128
|
parentName = null;
|
|
1945
2129
|
return manifest;
|
|
1946
2130
|
},
|
|
1947
2131
|
visitMapEntryValue(node, { self }) {
|
|
1948
|
-
return mergeManifests([
|
|
2132
|
+
return mergeManifests([visit5(node.key, self), visit5(node.value, self)], {
|
|
1949
2133
|
mergeValues: (renders) => `[${renders.join(", ")}]`
|
|
1950
2134
|
});
|
|
1951
2135
|
},
|
|
1952
2136
|
visitMapType(mapType, { self }) {
|
|
1953
|
-
const key =
|
|
1954
|
-
const value =
|
|
2137
|
+
const key = visit5(mapType.key, self);
|
|
2138
|
+
const value = visit5(mapType.value, self);
|
|
1955
2139
|
const mergedManifest = mergeManifests([key, value], {
|
|
1956
2140
|
mergeCodecs: ([k, v]) => `${k}, ${v}`,
|
|
1957
2141
|
mergeTypes: ([k, v]) => `Map<${k}, ${v}>`
|
|
@@ -1964,7 +2148,7 @@ function getTypeManifestVisitor(input) {
|
|
|
1964
2148
|
return mergedManifest;
|
|
1965
2149
|
},
|
|
1966
2150
|
visitMapValue(node, { self }) {
|
|
1967
|
-
const entryFragments = node.entries.map((entry) =>
|
|
2151
|
+
const entryFragments = node.entries.map((entry) => visit5(entry, self));
|
|
1968
2152
|
return mergeManifests(entryFragments, {
|
|
1969
2153
|
mergeValues: (renders) => `new Map([${renders.join(", ")}])`
|
|
1970
2154
|
});
|
|
@@ -2001,14 +2185,14 @@ function getTypeManifestVisitor(input) {
|
|
|
2001
2185
|
return manifest;
|
|
2002
2186
|
},
|
|
2003
2187
|
visitOptionType(optionType, { self }) {
|
|
2004
|
-
const childManifest =
|
|
2188
|
+
const childManifest = visit5(optionType.item, self);
|
|
2005
2189
|
childManifest.strictType.mapRender((r) => `Option<${r}>`).addImports("solanaOptions", "type Option");
|
|
2006
2190
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2007
2191
|
const encoderOptions = [];
|
|
2008
2192
|
const decoderOptions = [];
|
|
2009
|
-
const optionPrefix =
|
|
2193
|
+
const optionPrefix = resolveNestedTypeNode2(optionType.prefix);
|
|
2010
2194
|
if (optionPrefix.format !== "u8" || optionPrefix.endian !== "le") {
|
|
2011
|
-
const prefixManifest =
|
|
2195
|
+
const prefixManifest = visit5(optionType.prefix, self);
|
|
2012
2196
|
childManifest.encoder.mergeImportsWith(prefixManifest.encoder);
|
|
2013
2197
|
childManifest.decoder.mergeImportsWith(prefixManifest.decoder);
|
|
2014
2198
|
encoderOptions.push(`prefix: ${prefixManifest.encoder.render}`);
|
|
@@ -2025,7 +2209,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2025
2209
|
return childManifest;
|
|
2026
2210
|
},
|
|
2027
2211
|
visitPostOffsetType(node, { self }) {
|
|
2028
|
-
const manifest =
|
|
2212
|
+
const manifest = visit5(node.type, self);
|
|
2029
2213
|
if (node.strategy === "padded") {
|
|
2030
2214
|
manifest.encoder.mapRender((r) => `padRightEncoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padRightEncoder");
|
|
2031
2215
|
manifest.decoder.mapRender((r) => `padRightDecoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padRightDecoder");
|
|
@@ -2047,7 +2231,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2047
2231
|
return manifest;
|
|
2048
2232
|
},
|
|
2049
2233
|
visitPreOffsetType(node, { self }) {
|
|
2050
|
-
const manifest =
|
|
2234
|
+
const manifest = visit5(node.type, self);
|
|
2051
2235
|
if (node.strategy === "padded") {
|
|
2052
2236
|
manifest.encoder.mapRender((r) => `padLeftEncoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padLeftEncoder");
|
|
2053
2237
|
manifest.decoder.mapRender((r) => `padLeftDecoder(${r}, ${node.offset})`).addImports("solanaCodecsCore", "padLeftDecoder");
|
|
@@ -2083,7 +2267,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2083
2267
|
return manifest;
|
|
2084
2268
|
},
|
|
2085
2269
|
visitRemainderOptionType(node, { self }) {
|
|
2086
|
-
const childManifest =
|
|
2270
|
+
const childManifest = visit5(node.item, self);
|
|
2087
2271
|
childManifest.strictType.mapRender((r) => `Option<${r}>`).addImports("solanaOptions", "type Option");
|
|
2088
2272
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2089
2273
|
const encoderOptions = ["prefix: null"];
|
|
@@ -2095,14 +2279,14 @@ function getTypeManifestVisitor(input) {
|
|
|
2095
2279
|
return childManifest;
|
|
2096
2280
|
},
|
|
2097
2281
|
visitSentinelType(node, { self }) {
|
|
2098
|
-
const manifest =
|
|
2099
|
-
const sentinel =
|
|
2282
|
+
const manifest = visit5(node.type, self);
|
|
2283
|
+
const sentinel = visit5(node.sentinel, self).value;
|
|
2100
2284
|
manifest.encoder.mapRender((r) => `addEncoderSentinel(${r}, ${sentinel.render})`).mergeImportsWith(sentinel).addImports("solanaCodecsCore", "addEncoderSentinel");
|
|
2101
2285
|
manifest.decoder.mapRender((r) => `addDecoderSentinel(${r}, ${sentinel.render})`).mergeImportsWith(sentinel).addImports("solanaCodecsCore", "addDecoderSentinel");
|
|
2102
2286
|
return manifest;
|
|
2103
2287
|
},
|
|
2104
2288
|
visitSetType(setType, { self }) {
|
|
2105
|
-
const childManifest =
|
|
2289
|
+
const childManifest = visit5(setType.item, self);
|
|
2106
2290
|
childManifest.strictType.mapRender((r) => `Set<${r}>`);
|
|
2107
2291
|
childManifest.looseType.mapRender((r) => `Set<${r}>`);
|
|
2108
2292
|
const sizeManifest = getArrayLikeSizeOption(setType.count, self);
|
|
@@ -2114,19 +2298,19 @@ function getTypeManifestVisitor(input) {
|
|
|
2114
2298
|
},
|
|
2115
2299
|
visitSetValue(node, { self }) {
|
|
2116
2300
|
return mergeManifests(
|
|
2117
|
-
node.items.map((v) =>
|
|
2301
|
+
node.items.map((v) => visit5(v, self)),
|
|
2118
2302
|
{ mergeValues: (renders) => `new Set([${renders.join(", ")}])` }
|
|
2119
2303
|
);
|
|
2120
2304
|
},
|
|
2121
2305
|
visitSizePrefixType(node, { self }) {
|
|
2122
|
-
const manifest =
|
|
2123
|
-
const prefix =
|
|
2306
|
+
const manifest = visit5(node.type, self);
|
|
2307
|
+
const prefix = visit5(node.prefix, self);
|
|
2124
2308
|
manifest.encoder.mapRender((r) => `addEncoderSizePrefix(${r}, ${prefix.encoder.render})`).mergeImportsWith(prefix.encoder).addImports("solanaCodecsCore", "addEncoderSizePrefix");
|
|
2125
2309
|
manifest.decoder.mapRender((r) => `addDecoderSizePrefix(${r}, ${prefix.decoder.render})`).mergeImportsWith(prefix.decoder).addImports("solanaCodecsCore", "addDecoderSizePrefix");
|
|
2126
2310
|
return manifest;
|
|
2127
2311
|
},
|
|
2128
2312
|
visitSolAmountType({ number }, { self }) {
|
|
2129
|
-
const numberManifest =
|
|
2313
|
+
const numberManifest = visit5(number, self);
|
|
2130
2314
|
const lamportsType = "Lamports";
|
|
2131
2315
|
const lamportsImport = new ImportMap().add("solanaRpcTypes", "type Lamports");
|
|
2132
2316
|
return {
|
|
@@ -2139,7 +2323,7 @@ function getTypeManifestVisitor(input) {
|
|
|
2139
2323
|
},
|
|
2140
2324
|
visitSomeValue(node, { self }) {
|
|
2141
2325
|
const manifest = typeManifest();
|
|
2142
|
-
manifest.value =
|
|
2326
|
+
manifest.value = visit5(node.value, self).value.mapRender((r) => `some(${r})`).addImports("solanaOptions", "some");
|
|
2143
2327
|
return manifest;
|
|
2144
2328
|
},
|
|
2145
2329
|
visitStringType(stringType) {
|
|
@@ -2172,8 +2356,8 @@ function getTypeManifestVisitor(input) {
|
|
|
2172
2356
|
return manifest;
|
|
2173
2357
|
},
|
|
2174
2358
|
visitStructFieldType(structFieldType, { self }) {
|
|
2175
|
-
const name =
|
|
2176
|
-
const childManifest =
|
|
2359
|
+
const name = camelCase10(structFieldType.name);
|
|
2360
|
+
const childManifest = visit5(structFieldType.type, self);
|
|
2177
2361
|
const docblock = structFieldType.docs.length > 0 ? `
|
|
2178
2362
|
${jsDocblock(structFieldType.docs)}` : "";
|
|
2179
2363
|
const originalLooseType = childManifest.looseType.render;
|
|
@@ -2193,13 +2377,13 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2193
2377
|
},
|
|
2194
2378
|
visitStructFieldValue(node, { self }) {
|
|
2195
2379
|
const manifest = typeManifest();
|
|
2196
|
-
manifest.value =
|
|
2380
|
+
manifest.value = visit5(node.value, self).value.mapRender((r) => `${node.name}: ${r}`);
|
|
2197
2381
|
return manifest;
|
|
2198
2382
|
},
|
|
2199
2383
|
visitStructType(structType, { self }) {
|
|
2200
2384
|
const optionalFields = structType.fields.filter((f) => !!f.defaultValue);
|
|
2201
2385
|
const mergedManifest = mergeManifests(
|
|
2202
|
-
structType.fields.map((field) =>
|
|
2386
|
+
structType.fields.map((field) => visit5(field, self)),
|
|
2203
2387
|
{
|
|
2204
2388
|
mergeCodecs: (renders) => `([${renders.join(", ")}])`,
|
|
2205
2389
|
mergeTypes: (renders) => `{ ${renders.join("")} }`
|
|
@@ -2215,15 +2399,15 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2215
2399
|
const accountNode = findLastNodeFromPath(parentPath, "accountNode");
|
|
2216
2400
|
const discriminatorPrefix = instructionNode ? instructionNode.name : accountNode?.name;
|
|
2217
2401
|
const discriminators = (instructionNode ? instructionNode.discriminators : accountNode?.discriminators) ?? [];
|
|
2218
|
-
const fieldDiscriminators = discriminators.filter(
|
|
2402
|
+
const fieldDiscriminators = discriminators.filter(isNodeFilter6("fieldDiscriminatorNode"));
|
|
2219
2403
|
const defaultValues = optionalFields.map((f) => {
|
|
2220
|
-
const key =
|
|
2404
|
+
const key = camelCase10(f.name);
|
|
2221
2405
|
if (fieldDiscriminators.some((d) => d.name === f.name)) {
|
|
2222
|
-
const constantName = nameApi.constant(
|
|
2406
|
+
const constantName = nameApi.constant(camelCase10(`${discriminatorPrefix}_${f.name}`));
|
|
2223
2407
|
return f.defaultValueStrategy === "omitted" ? `${key}: ${constantName}` : `${key}: value.${key} ?? ${constantName}`;
|
|
2224
2408
|
}
|
|
2225
2409
|
const defaultValue = f.defaultValue;
|
|
2226
|
-
const { render: renderedValue, imports } =
|
|
2410
|
+
const { render: renderedValue, imports } = visit5(defaultValue, self).value;
|
|
2227
2411
|
mergedManifest.encoder.mergeImportsWith(imports);
|
|
2228
2412
|
return f.defaultValueStrategy === "omitted" ? `${key}: ${renderedValue}` : `${key}: value.${key} ?? ${renderedValue}`;
|
|
2229
2413
|
}).join(", ");
|
|
@@ -2232,12 +2416,12 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2232
2416
|
},
|
|
2233
2417
|
visitStructValue(node, { self }) {
|
|
2234
2418
|
return mergeManifests(
|
|
2235
|
-
node.fields.map((field) =>
|
|
2419
|
+
node.fields.map((field) => visit5(field, self)),
|
|
2236
2420
|
{ mergeValues: (renders) => `{ ${renders.join(", ")} }` }
|
|
2237
2421
|
);
|
|
2238
2422
|
},
|
|
2239
2423
|
visitTupleType(tupleType, { self }) {
|
|
2240
|
-
const items = tupleType.items.map((item) =>
|
|
2424
|
+
const items = tupleType.items.map((item) => visit5(item, self));
|
|
2241
2425
|
const mergedManifest = mergeManifests(items, {
|
|
2242
2426
|
mergeCodecs: (codecs) => `[${codecs.join(", ")}]`,
|
|
2243
2427
|
mergeTypes: (types) => `readonly [${types.join(", ")}]`
|
|
@@ -2248,18 +2432,18 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2248
2432
|
},
|
|
2249
2433
|
visitTupleValue(node, { self }) {
|
|
2250
2434
|
return mergeManifests(
|
|
2251
|
-
node.items.map((v) =>
|
|
2435
|
+
node.items.map((v) => visit5(v, self)),
|
|
2252
2436
|
{ mergeValues: (renders) => `[${renders.join(", ")}]` }
|
|
2253
2437
|
);
|
|
2254
2438
|
},
|
|
2255
2439
|
visitZeroableOptionType(node, { self }) {
|
|
2256
|
-
const childManifest =
|
|
2440
|
+
const childManifest = visit5(node.item, self);
|
|
2257
2441
|
childManifest.strictType.mapRender((r) => `Option<${r}>`).addImports("solanaOptions", "type Option");
|
|
2258
2442
|
childManifest.looseType.mapRender((r) => `OptionOrNullable<${r}>`).addImports("solanaOptions", "type OptionOrNullable");
|
|
2259
2443
|
const encoderOptions = ["prefix: null"];
|
|
2260
2444
|
const decoderOptions = ["prefix: null"];
|
|
2261
2445
|
if (node.zeroValue) {
|
|
2262
|
-
const zeroValueManifest =
|
|
2446
|
+
const zeroValueManifest = visit5(node.zeroValue, self);
|
|
2263
2447
|
childManifest.encoder.mergeImportsWith(zeroValueManifest.value);
|
|
2264
2448
|
childManifest.decoder.mergeImportsWith(zeroValueManifest.value);
|
|
2265
2449
|
encoderOptions.push(`noneValue: ${zeroValueManifest.value.render}`);
|
|
@@ -2279,93 +2463,96 @@ ${jsDocblock(structFieldType.docs)}` : "";
|
|
|
2279
2463
|
);
|
|
2280
2464
|
}
|
|
2281
2465
|
function getArrayLikeSizeOption(count, visitor) {
|
|
2282
|
-
if (
|
|
2466
|
+
if (isNode13(count, "fixedCountNode")) {
|
|
2283
2467
|
return {
|
|
2284
2468
|
decoder: fragment(`size: ${count.value}`),
|
|
2285
2469
|
encoder: fragment(`size: ${count.value}`)
|
|
2286
2470
|
};
|
|
2287
2471
|
}
|
|
2288
|
-
if (
|
|
2472
|
+
if (isNode13(count, "remainderCountNode")) {
|
|
2289
2473
|
return {
|
|
2290
2474
|
decoder: fragment(`size: 'remainder'`),
|
|
2291
2475
|
encoder: fragment(`size: 'remainder'`)
|
|
2292
2476
|
};
|
|
2293
2477
|
}
|
|
2294
|
-
const prefix =
|
|
2478
|
+
const prefix = resolveNestedTypeNode2(count.prefix);
|
|
2295
2479
|
if (prefix.format === "u32" && prefix.endian === "le") {
|
|
2296
2480
|
return { decoder: fragment(""), encoder: fragment("") };
|
|
2297
2481
|
}
|
|
2298
|
-
const prefixManifest =
|
|
2482
|
+
const prefixManifest = visit5(count.prefix, visitor);
|
|
2299
2483
|
prefixManifest.encoder.mapRender((r) => `size: ${r}`);
|
|
2300
2484
|
prefixManifest.decoder.mapRender((r) => `size: ${r}`);
|
|
2301
2485
|
return prefixManifest;
|
|
2302
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";
|
|
2303
2490
|
function getNameApi(transformers) {
|
|
2304
2491
|
const helpers = {
|
|
2305
|
-
camelCase:
|
|
2492
|
+
camelCase: camelCase11,
|
|
2306
2493
|
capitalize,
|
|
2307
|
-
kebabCase:
|
|
2308
|
-
pascalCase:
|
|
2309
|
-
snakeCase:
|
|
2310
|
-
titleCase:
|
|
2494
|
+
kebabCase: kebabCase2,
|
|
2495
|
+
pascalCase: pascalCase7,
|
|
2496
|
+
snakeCase: snakeCase2,
|
|
2497
|
+
titleCase: titleCase2
|
|
2311
2498
|
};
|
|
2312
2499
|
return Object.fromEntries(
|
|
2313
2500
|
Object.entries(transformers).map(([key, transformer]) => [key, (name) => transformer(name, helpers)])
|
|
2314
2501
|
);
|
|
2315
2502
|
}
|
|
2316
2503
|
var DEFAULT_NAME_TRANSFORMERS = {
|
|
2317
|
-
accountDecodeFunction: (name) => `decode${
|
|
2318
|
-
accountFetchAllFunction: (name) => `fetchAll${
|
|
2319
|
-
accountFetchAllMaybeFunction: (name) => `fetchAllMaybe${
|
|
2320
|
-
accountFetchFromSeedsFunction: (name) => `fetch${
|
|
2321
|
-
accountFetchFunction: (name) => `fetch${
|
|
2322
|
-
accountFetchMaybeFromSeedsFunction: (name) => `fetchMaybe${
|
|
2323
|
-
accountFetchMaybeFunction: (name) => `fetchMaybe${
|
|
2324
|
-
accountGetSizeFunction: (name) => `get${
|
|
2325
|
-
codecFunction: (name) => `get${
|
|
2326
|
-
constant: (name) =>
|
|
2327
|
-
constantFunction: (name) => `get${
|
|
2328
|
-
dataArgsType: (name) => `${
|
|
2329
|
-
dataType: (name) => `${
|
|
2330
|
-
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`,
|
|
2331
2518
|
discriminatedUnionDiscriminator: () => "__kind",
|
|
2332
|
-
discriminatedUnionFunction: (name) => `${
|
|
2333
|
-
discriminatedUnionVariant: (name) => `${
|
|
2334
|
-
encoderFunction: (name) => `get${
|
|
2335
|
-
enumVariant: (name) => `${
|
|
2336
|
-
instructionAsyncFunction: (name) => `get${
|
|
2337
|
-
instructionAsyncInputType: (name) => `${
|
|
2338
|
-
instructionDataType: (name) => `${
|
|
2339
|
-
instructionExtraType: (name) => `${
|
|
2340
|
-
instructionParseFunction: (name) => `parse${
|
|
2341
|
-
instructionParsedType: (name) => `Parsed${
|
|
2342
|
-
instructionSyncFunction: (name) => `get${
|
|
2343
|
-
instructionSyncInputType: (name) => `${
|
|
2344
|
-
instructionType: (name) => `${
|
|
2345
|
-
isDiscriminatedUnionFunction: (name) => `is${
|
|
2346
|
-
pdaFindFunction: (name) => `find${
|
|
2347
|
-
pdaSeedsType: (name) => `${
|
|
2348
|
-
programAccountsEnum: (name) => `${
|
|
2349
|
-
programAccountsEnumVariant: (name) => `${
|
|
2350
|
-
programAccountsIdentifierFunction: (name) => `identify${
|
|
2351
|
-
programAddressConstant: (name) => `${
|
|
2352
|
-
programErrorConstant: (name) =>
|
|
2353
|
-
programErrorConstantPrefix: (name) => `${
|
|
2354
|
-
programErrorMessagesMap: (name) => `${
|
|
2355
|
-
programErrorUnion: (name) => `${
|
|
2356
|
-
programGetErrorMessageFunction: (name) => `get${
|
|
2357
|
-
programInstructionsEnum: (name) => `${
|
|
2358
|
-
programInstructionsEnumVariant: (name) => `${
|
|
2359
|
-
programInstructionsIdentifierFunction: (name) => `identify${
|
|
2360
|
-
programInstructionsParsedUnionType: (name) => `Parsed${
|
|
2361
|
-
programIsErrorFunction: (name) => `is${
|
|
2362
|
-
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)}`
|
|
2363
2550
|
};
|
|
2364
2551
|
|
|
2365
2552
|
// src/getRenderMapVisitor.ts
|
|
2366
2553
|
function getRenderMapVisitor(options = {}) {
|
|
2367
|
-
const linkables = new
|
|
2368
|
-
const stack = new
|
|
2554
|
+
const linkables = new LinkableDictionary3();
|
|
2555
|
+
const stack = new NodeStack2();
|
|
2369
2556
|
const nameTransformers = {
|
|
2370
2557
|
...DEFAULT_NAME_TRANSFORMERS,
|
|
2371
2558
|
...options.nameTransformers
|
|
@@ -2374,9 +2561,9 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2374
2561
|
const renderParentInstructions = options.renderParentInstructions ?? false;
|
|
2375
2562
|
const dependencyMap = options.dependencyMap ?? {};
|
|
2376
2563
|
const useGranularImports = options.useGranularImports ?? false;
|
|
2377
|
-
const asyncResolvers = (options.asyncResolvers ?? []).map(
|
|
2378
|
-
const nonScalarEnums = (options.nonScalarEnums ?? []).map(
|
|
2379
|
-
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);
|
|
2380
2567
|
const customAccountData = parseCustomDataOptions(options.customAccountData ?? [], "AccountData");
|
|
2381
2568
|
const customInstructionData = parseCustomDataOptions(options.customInstructionData ?? [], "InstructionData");
|
|
2382
2569
|
const getImportFrom = getImportFromFactory(options.linkOverrides ?? {}, customAccountData, customInstructionData);
|
|
@@ -2402,24 +2589,24 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2402
2589
|
typeManifestVisitor
|
|
2403
2590
|
};
|
|
2404
2591
|
const render2 = (template, context, renderOptions) => {
|
|
2405
|
-
return render(
|
|
2592
|
+
return render(join3("pages", template), context, renderOptions);
|
|
2406
2593
|
};
|
|
2407
|
-
return
|
|
2408
|
-
|
|
2594
|
+
return pipe2(
|
|
2595
|
+
staticVisitor2(() => new RenderMap(), {
|
|
2409
2596
|
keys: ["rootNode", "programNode", "pdaNode", "accountNode", "definedTypeNode", "instructionNode"]
|
|
2410
2597
|
}),
|
|
2411
|
-
(v) =>
|
|
2598
|
+
(v) => extendVisitor2(v, {
|
|
2412
2599
|
visitAccount(node) {
|
|
2413
2600
|
const accountPath = stack.getPath("accountNode");
|
|
2414
|
-
if (!
|
|
2601
|
+
if (!findProgramNodeFromPath7(accountPath)) {
|
|
2415
2602
|
throw new Error("Account must be visited inside a program.");
|
|
2416
2603
|
}
|
|
2417
2604
|
const scope = {
|
|
2418
2605
|
...globalScope,
|
|
2419
2606
|
accountPath,
|
|
2420
|
-
typeManifest:
|
|
2607
|
+
typeManifest: visit6(node, typeManifestVisitor)
|
|
2421
2608
|
};
|
|
2422
|
-
const fields =
|
|
2609
|
+
const fields = resolveNestedTypeNode3(node.data).fields;
|
|
2423
2610
|
const accountDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2424
2611
|
...scope,
|
|
2425
2612
|
discriminatorNodes: node.discriminators ?? [],
|
|
@@ -2438,7 +2625,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2438
2625
|
accountPdaHelpersFragment
|
|
2439
2626
|
);
|
|
2440
2627
|
return new RenderMap().add(
|
|
2441
|
-
`accounts/${
|
|
2628
|
+
`accounts/${camelCase12(node.name)}.ts`,
|
|
2442
2629
|
render2("accountsPage.njk", {
|
|
2443
2630
|
accountDiscriminatorConstantsFragment,
|
|
2444
2631
|
accountFetchHelpersFragment,
|
|
@@ -2455,7 +2642,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2455
2642
|
codecDocs: [],
|
|
2456
2643
|
decoderDocs: [],
|
|
2457
2644
|
encoderDocs: [],
|
|
2458
|
-
manifest:
|
|
2645
|
+
manifest: visit6(node, typeManifestVisitor),
|
|
2459
2646
|
name: node.name,
|
|
2460
2647
|
typeDocs: node.docs,
|
|
2461
2648
|
typeNode: node.type
|
|
@@ -2470,7 +2657,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2470
2657
|
nameApi.codecFunction(node.name)
|
|
2471
2658
|
]);
|
|
2472
2659
|
return new RenderMap().add(
|
|
2473
|
-
`types/${
|
|
2660
|
+
`types/${camelCase12(node.name)}.ts`,
|
|
2474
2661
|
render2("definedTypesPage.njk", {
|
|
2475
2662
|
imports: imports.toString({
|
|
2476
2663
|
...dependencyMap,
|
|
@@ -2483,23 +2670,23 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2483
2670
|
},
|
|
2484
2671
|
visitInstruction(node) {
|
|
2485
2672
|
const instructionPath = stack.getPath("instructionNode");
|
|
2486
|
-
if (!
|
|
2673
|
+
if (!findProgramNodeFromPath7(instructionPath)) {
|
|
2487
2674
|
throw new Error("Instruction must be visited inside a program.");
|
|
2488
2675
|
}
|
|
2489
2676
|
const instructionExtraName = nameApi.instructionExtraType(node.name);
|
|
2490
2677
|
const scope = {
|
|
2491
2678
|
...globalScope,
|
|
2492
|
-
dataArgsManifest:
|
|
2493
|
-
extraArgsManifest:
|
|
2494
|
-
|
|
2679
|
+
dataArgsManifest: visit6(node, typeManifestVisitor),
|
|
2680
|
+
extraArgsManifest: visit6(
|
|
2681
|
+
definedTypeNode2({
|
|
2495
2682
|
name: instructionExtraName,
|
|
2496
|
-
type:
|
|
2683
|
+
type: structTypeNodeFromInstructionArgumentNodes4(node.extraArguments ?? [])
|
|
2497
2684
|
}),
|
|
2498
2685
|
typeManifestVisitor
|
|
2499
2686
|
),
|
|
2500
2687
|
instructionPath,
|
|
2501
2688
|
renamedArgs: getRenamedArgsMap(node),
|
|
2502
|
-
resolvedInputs:
|
|
2689
|
+
resolvedInputs: visit6(node, resolvedInstructionInputVisitor)
|
|
2503
2690
|
};
|
|
2504
2691
|
const instructionDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2505
2692
|
...scope,
|
|
@@ -2529,7 +2716,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2529
2716
|
instructionParseFunctionFragment
|
|
2530
2717
|
);
|
|
2531
2718
|
return new RenderMap().add(
|
|
2532
|
-
`instructions/${
|
|
2719
|
+
`instructions/${camelCase12(node.name)}.ts`,
|
|
2533
2720
|
render2("instructionsPage.njk", {
|
|
2534
2721
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2535
2722
|
instruction: node,
|
|
@@ -2545,14 +2732,14 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2545
2732
|
},
|
|
2546
2733
|
visitPda(node) {
|
|
2547
2734
|
const pdaPath = stack.getPath("pdaNode");
|
|
2548
|
-
if (!
|
|
2735
|
+
if (!findProgramNodeFromPath7(pdaPath)) {
|
|
2549
2736
|
throw new Error("Account must be visited inside a program.");
|
|
2550
2737
|
}
|
|
2551
2738
|
const scope = { ...globalScope, pdaPath };
|
|
2552
2739
|
const pdaFunctionFragment = getPdaFunctionFragment(scope);
|
|
2553
2740
|
const imports = new ImportMap().mergeWith(pdaFunctionFragment);
|
|
2554
2741
|
return new RenderMap().add(
|
|
2555
|
-
`pdas/${
|
|
2742
|
+
`pdas/${camelCase12(node.name)}.ts`,
|
|
2556
2743
|
render2("pdasPage.njk", {
|
|
2557
2744
|
imports: imports.toString(dependencyMap, useGranularImports),
|
|
2558
2745
|
pdaFunctionFragment
|
|
@@ -2565,11 +2752,11 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2565
2752
|
...getDefinedTypeNodesToExtract(node.instructions, customInstructionData)
|
|
2566
2753
|
];
|
|
2567
2754
|
const scope = { ...globalScope, programNode: node };
|
|
2568
|
-
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)));
|
|
2569
2756
|
if (node.errors.length > 0) {
|
|
2570
2757
|
const programErrorsFragment = getProgramErrorsFragment(scope);
|
|
2571
2758
|
renderMap.add(
|
|
2572
|
-
`errors/${
|
|
2759
|
+
`errors/${camelCase12(node.name)}.ts`,
|
|
2573
2760
|
render2("errorsPage.njk", {
|
|
2574
2761
|
imports: new ImportMap().mergeWith(programErrorsFragment).toString(dependencyMap, useGranularImports),
|
|
2575
2762
|
programErrorsFragment
|
|
@@ -2580,7 +2767,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2580
2767
|
const programAccountsFragment = getProgramAccountsFragment(scope);
|
|
2581
2768
|
const programInstructionsFragment = getProgramInstructionsFragment(scope);
|
|
2582
2769
|
renderMap.add(
|
|
2583
|
-
`programs/${
|
|
2770
|
+
`programs/${camelCase12(node.name)}.ts`,
|
|
2584
2771
|
render2("programsPage.njk", {
|
|
2585
2772
|
imports: new ImportMap().mergeWith(programFragment, programAccountsFragment, programInstructionsFragment).toString(dependencyMap, useGranularImports),
|
|
2586
2773
|
programAccountsFragment,
|
|
@@ -2589,9 +2776,9 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2589
2776
|
})
|
|
2590
2777
|
);
|
|
2591
2778
|
renderMap.mergeWith(
|
|
2592
|
-
...
|
|
2779
|
+
...getAllInstructionsWithSubs2(node, {
|
|
2593
2780
|
leavesOnly: !renderParentInstructions
|
|
2594
|
-
}).map((ix) =>
|
|
2781
|
+
}).map((ix) => visit6(ix, self))
|
|
2595
2782
|
);
|
|
2596
2783
|
return renderMap;
|
|
2597
2784
|
},
|
|
@@ -2601,7 +2788,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2601
2788
|
const programsWithErrorsToExport = programsToExport.filter((p) => p.errors.length > 0);
|
|
2602
2789
|
const pdasToExport = getAllPdas(node);
|
|
2603
2790
|
const accountsToExport = getAllAccounts(node).filter(isNotInternal);
|
|
2604
|
-
const instructionsToExport =
|
|
2791
|
+
const instructionsToExport = getAllInstructionsWithSubs2(node, {
|
|
2605
2792
|
leavesOnly: !renderParentInstructions
|
|
2606
2793
|
}).filter(isNotInternal);
|
|
2607
2794
|
const definedTypesToExport = getAllDefinedTypes(node).filter(isNotInternal);
|
|
@@ -2656,10 +2843,10 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2656
2843
|
if (definedTypesToExport.length > 0) {
|
|
2657
2844
|
map.add("types/index.ts", render2("definedTypesIndex.njk", ctx));
|
|
2658
2845
|
}
|
|
2659
|
-
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)));
|
|
2660
2847
|
}
|
|
2661
2848
|
}),
|
|
2662
|
-
(v) =>
|
|
2849
|
+
(v) => recordNodeStackVisitor2(v, stack),
|
|
2663
2850
|
(v) => recordLinkablesOnFirstVisitVisitor(v, linkables)
|
|
2664
2851
|
);
|
|
2665
2852
|
}
|
|
@@ -2678,8 +2865,15 @@ function getRenamedArgsMap(instruction) {
|
|
|
2678
2865
|
logWarn(
|
|
2679
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.`
|
|
2680
2867
|
);
|
|
2681
|
-
return new Map(duplicates.map((name) => [
|
|
2868
|
+
return new Map(duplicates.map((name) => [camelCase12(name), camelCase12(`${name}Arg`)]));
|
|
2682
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";
|
|
2683
2877
|
var DEFAULT_PRETTIER_OPTIONS = {
|
|
2684
2878
|
arrowParens: "always",
|
|
2685
2879
|
parser: "typescript",
|
|
@@ -2696,7 +2890,7 @@ function renderVisitor(path, options = {}) {
|
|
|
2696
2890
|
if (options.deleteFolderBeforeRendering ?? true) {
|
|
2697
2891
|
deleteDirectory(path);
|
|
2698
2892
|
}
|
|
2699
|
-
const renderMap =
|
|
2893
|
+
const renderMap = visit7(root, getRenderMapVisitor(options));
|
|
2700
2894
|
if (options.formatCode ?? true) {
|
|
2701
2895
|
const prettierOptions = { ...DEFAULT_PRETTIER_OPTIONS, ...options.prettierOptions };
|
|
2702
2896
|
await renderMap.mapContentAsync((code) => format(code, prettierOptions));
|
|
@@ -2704,7 +2898,15 @@ function renderVisitor(path, options = {}) {
|
|
|
2704
2898
|
renderMap.write(path);
|
|
2705
2899
|
});
|
|
2706
2900
|
}
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
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
|
+
};
|
|
2710
2912
|
//# sourceMappingURL=index.node.mjs.map
|