@codama/renderers-js 1.2.14 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.node.cjs +37 -25
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +42 -29
- package/dist/index.node.mjs.map +1 -1
- package/dist/templates/fragments/instructionParseFunction.njk +11 -11
- package/dist/templates/fragments/instructionType.njk +5 -5
- package/dist/templates/fragments/typeCodec.njk +1 -1
- package/dist/templates/fragments/typeDecoder.njk +1 -1
- package/dist/templates/fragments/typeEncoder.njk +1 -1
- package/dist/templates/pages/sharedPage.njk +2 -2
- package/dist/types/fragments/accountType.d.ts +1 -0
- package/dist/types/fragments/accountType.d.ts.map +1 -1
- package/dist/types/fragments/instructionData.d.ts +1 -0
- package/dist/types/fragments/instructionData.d.ts.map +1 -1
- package/dist/types/fragments/instructionParseFunction.d.ts.map +1 -1
- package/dist/types/fragments/instructionType.d.ts.map +1 -1
- package/dist/types/fragments/typeCodec.d.ts +1 -0
- package/dist/types/fragments/typeCodec.d.ts.map +1 -1
- package/dist/types/fragments/typeDecoder.d.ts +1 -0
- package/dist/types/fragments/typeDecoder.d.ts.map +1 -1
- package/dist/types/fragments/typeEncoder.d.ts +1 -0
- package/dist/types/fragments/typeEncoder.d.ts.map +1 -1
- package/dist/types/fragments/typeWithCodec.d.ts +1 -0
- package/dist/types/fragments/typeWithCodec.d.ts.map +1 -1
- package/dist/types/getRenderMapVisitor.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.node.mjs
CHANGED
|
@@ -135,7 +135,7 @@ var ImportMap = class {
|
|
|
135
135
|
import { getLastNodeFromPath } from "@codama/visitors-core";
|
|
136
136
|
|
|
137
137
|
// src/fragments/common.ts
|
|
138
|
-
import { join as join2 } from "
|
|
138
|
+
import { join as join2 } from "path";
|
|
139
139
|
|
|
140
140
|
// src/utils/async.ts
|
|
141
141
|
import {
|
|
@@ -319,8 +319,8 @@ function getImportFromFactory(overrides, customAccountData, customInstructionDat
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
// src/utils/render.ts
|
|
322
|
-
import { dirname as pathDirname, join } from "
|
|
323
|
-
import { fileURLToPath } from "
|
|
322
|
+
import { dirname as pathDirname, join } from "path";
|
|
323
|
+
import { fileURLToPath } from "url";
|
|
324
324
|
import { camelCase as camelCase2, kebabCase, pascalCase, snakeCase, titleCase } from "@codama/nodes";
|
|
325
325
|
import nunjucks from "nunjucks";
|
|
326
326
|
function jsDocblock(docs) {
|
|
@@ -518,43 +518,49 @@ function getTypeFragment(scope) {
|
|
|
518
518
|
// src/fragments/typeDecoder.ts
|
|
519
519
|
function getTypeDecoderFragment(scope) {
|
|
520
520
|
const { name, manifest, nameApi, docs = [] } = scope;
|
|
521
|
+
const decoderType = typeof scope.size === "number" ? "FixedSizeDecoder" : "Decoder";
|
|
521
522
|
return fragmentFromTemplate("typeDecoder.njk", {
|
|
522
523
|
decoderFunction: nameApi.decoderFunction(name),
|
|
524
|
+
decoderType,
|
|
523
525
|
docs,
|
|
524
526
|
looseName: nameApi.dataArgsType(name),
|
|
525
527
|
manifest,
|
|
526
528
|
strictName: nameApi.dataType(name)
|
|
527
|
-
}).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore",
|
|
529
|
+
}).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore", `type ${decoderType}`);
|
|
528
530
|
}
|
|
529
531
|
|
|
530
532
|
// src/fragments/typeEncoder.ts
|
|
531
533
|
function getTypeEncoderFragment(scope) {
|
|
532
534
|
const { name, manifest, nameApi, docs = [] } = scope;
|
|
535
|
+
const encoderType = typeof scope.size === "number" ? "FixedSizeEncoder" : "Encoder";
|
|
533
536
|
return fragmentFromTemplate("typeEncoder.njk", {
|
|
534
537
|
docs,
|
|
535
538
|
encoderFunction: nameApi.encoderFunction(name),
|
|
539
|
+
encoderType,
|
|
536
540
|
looseName: nameApi.dataArgsType(name),
|
|
537
541
|
manifest,
|
|
538
542
|
strictName: nameApi.dataType(name)
|
|
539
|
-
}).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore",
|
|
543
|
+
}).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore", `type ${encoderType}`);
|
|
540
544
|
}
|
|
541
545
|
|
|
542
546
|
// src/fragments/typeCodec.ts
|
|
543
547
|
function getTypeCodecFragment(scope) {
|
|
544
548
|
const { name, manifest, nameApi } = scope;
|
|
549
|
+
const codecType = typeof scope.size === "number" ? "FixedSizeCodec" : "Codec";
|
|
545
550
|
return mergeFragments(
|
|
546
551
|
[
|
|
547
552
|
getTypeEncoderFragment({ ...scope, docs: scope.encoderDocs }),
|
|
548
553
|
getTypeDecoderFragment({ ...scope, docs: scope.decoderDocs }),
|
|
549
554
|
fragmentFromTemplate("typeCodec.njk", {
|
|
550
555
|
codecFunction: nameApi.codecFunction(name),
|
|
556
|
+
codecType,
|
|
551
557
|
decoderFunction: nameApi.decoderFunction(name),
|
|
552
558
|
docs: scope.codecDocs,
|
|
553
559
|
encoderFunction: nameApi.encoderFunction(name),
|
|
554
560
|
looseName: nameApi.dataArgsType(name),
|
|
555
561
|
manifest,
|
|
556
562
|
strictName: nameApi.dataType(name)
|
|
557
|
-
}).addImports("solanaCodecsCore", [
|
|
563
|
+
}).addImports("solanaCodecsCore", [`type ${codecType}`, "combineCodec"])
|
|
558
564
|
],
|
|
559
565
|
(renders) => renders.join("\n\n")
|
|
560
566
|
);
|
|
@@ -578,7 +584,8 @@ function getAccountTypeFragment(scope) {
|
|
|
578
584
|
return getTypeWithCodecFragment({
|
|
579
585
|
manifest: typeManifest2,
|
|
580
586
|
name: accountNode.name,
|
|
581
|
-
nameApi
|
|
587
|
+
nameApi,
|
|
588
|
+
size: scope.size
|
|
582
589
|
});
|
|
583
590
|
}
|
|
584
591
|
|
|
@@ -645,10 +652,10 @@ import { pascalCase as pascalCase2 } from "@codama/nodes";
|
|
|
645
652
|
function getInstructionAccountMetaFragment(instructionAccountNode) {
|
|
646
653
|
const typeParam = `TAccount${pascalCase2(instructionAccountNode.name)}`;
|
|
647
654
|
if (instructionAccountNode.isSigner === true && instructionAccountNode.isWritable) {
|
|
648
|
-
return fragment(`WritableSignerAccount<${typeParam}> &
|
|
655
|
+
return fragment(`WritableSignerAccount<${typeParam}> & AccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type WritableSignerAccount"]).addImports("solanaSigners", ["type AccountSignerMeta"]);
|
|
649
656
|
}
|
|
650
657
|
if (instructionAccountNode.isSigner === true) {
|
|
651
|
-
return fragment(`ReadonlySignerAccount<${typeParam}> &
|
|
658
|
+
return fragment(`ReadonlySignerAccount<${typeParam}> & AccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type ReadonlySignerAccount"]).addImports("solanaSigners", ["type AccountSignerMeta"]);
|
|
652
659
|
}
|
|
653
660
|
if (instructionAccountNode.isWritable) {
|
|
654
661
|
return fragment(`WritableAccount<${typeParam}>`).addImports("solanaInstructions", "type WritableAccount");
|
|
@@ -669,10 +676,10 @@ function getInstructionAccountTypeParamFragment(scope) {
|
|
|
669
676
|
const instructionNode = findInstructionNodeFromPath(instructionAccountPath);
|
|
670
677
|
const programNode = findProgramNodeFromPath2(instructionAccountPath);
|
|
671
678
|
const typeParam = `TAccount${pascalCase3(instructionAccountNode.name)}`;
|
|
672
|
-
const accountMeta = allowAccountMeta ? " |
|
|
679
|
+
const accountMeta = allowAccountMeta ? " | AccountMeta<string>" : "";
|
|
673
680
|
const imports = new ImportMap();
|
|
674
681
|
if (allowAccountMeta) {
|
|
675
|
-
imports.add("solanaInstructions", "type
|
|
682
|
+
imports.add("solanaInstructions", "type AccountMeta");
|
|
676
683
|
}
|
|
677
684
|
if (instructionNode.optionalAccountStrategy === "omitted" && instructionAccountNode.isOptional) {
|
|
678
685
|
return fragment(`${typeParam} extends string${accountMeta} | undefined = undefined`, imports);
|
|
@@ -767,7 +774,8 @@ function getInstructionDataFragment(scope) {
|
|
|
767
774
|
return getTypeWithCodecFragment({
|
|
768
775
|
manifest: dataArgsManifest,
|
|
769
776
|
name: instructionDataName,
|
|
770
|
-
nameApi
|
|
777
|
+
nameApi,
|
|
778
|
+
size: scope.size
|
|
771
779
|
});
|
|
772
780
|
}
|
|
773
781
|
|
|
@@ -1237,8 +1245,8 @@ function getInstructionRemainingAccountsFragment(scope) {
|
|
|
1237
1245
|
return mergeFragments(
|
|
1238
1246
|
fragments,
|
|
1239
1247
|
(r) => `// Remaining accounts.
|
|
1240
|
-
const remainingAccounts:
|
|
1241
|
-
).addImports("solanaInstructions", ["type
|
|
1248
|
+
const remainingAccounts: AccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.join(", ...")}]`}`
|
|
1249
|
+
).addImports("solanaInstructions", ["type AccountMeta"]);
|
|
1242
1250
|
}
|
|
1243
1251
|
function getRemainingAccountsFragment2(remainingAccounts, scope) {
|
|
1244
1252
|
const remainingAccountsFragment = (() => {
|
|
@@ -1358,7 +1366,7 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1358
1366
|
const getReturnType = (instructionType) => {
|
|
1359
1367
|
let returnType = instructionType;
|
|
1360
1368
|
if (hasByteDeltas) {
|
|
1361
|
-
returnType = `${returnType} &
|
|
1369
|
+
returnType = `${returnType} & InstructionWithByteDelta`;
|
|
1362
1370
|
}
|
|
1363
1371
|
return useAsync ? `Promise<${returnType}>` : returnType;
|
|
1364
1372
|
};
|
|
@@ -1395,10 +1403,10 @@ function getInstructionFunctionFragment(scope) {
|
|
|
1395
1403
|
argsTypeFragment
|
|
1396
1404
|
).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaAddresses", ["type Address"]);
|
|
1397
1405
|
if (hasAccounts) {
|
|
1398
|
-
functionFragment.addImports("solanaInstructions", ["type
|
|
1406
|
+
functionFragment.addImports("solanaInstructions", ["type AccountMeta"]).addImports("shared", ["getAccountMetaFactory", "type ResolvedAccount"]);
|
|
1399
1407
|
}
|
|
1400
1408
|
if (hasByteDeltas) {
|
|
1401
|
-
functionFragment.addImports("shared", ["type
|
|
1409
|
+
functionFragment.addImports("shared", ["type InstructionWithByteDelta"]);
|
|
1402
1410
|
}
|
|
1403
1411
|
return functionFragment;
|
|
1404
1412
|
}
|
|
@@ -1418,8 +1426,8 @@ function getInstructionType(scope) {
|
|
|
1418
1426
|
if (account.isSigner === "either") {
|
|
1419
1427
|
const signerRole = account.isWritable ? "WritableSignerAccount" : "ReadonlySignerAccount";
|
|
1420
1428
|
return fragment(
|
|
1421
|
-
`typeof input["${camelName}"] extends TransactionSigner<${typeParam}> ? ${signerRole}<${typeParam}> &
|
|
1422
|
-
).addImports("solanaInstructions", [`type ${signerRole}`]).addImports("solanaSigners", ["type
|
|
1429
|
+
`typeof input["${camelName}"] extends TransactionSigner<${typeParam}> ? ${signerRole}<${typeParam}> & AccountSignerMeta<${typeParam}> : ${typeParam}`
|
|
1430
|
+
).addImports("solanaInstructions", [`type ${signerRole}`]).addImports("solanaSigners", ["type AccountSignerMeta"]);
|
|
1423
1431
|
}
|
|
1424
1432
|
return fragment(typeParam);
|
|
1425
1433
|
});
|
|
@@ -1468,7 +1476,7 @@ function getInstructionParseFunctionFragment(scope) {
|
|
|
1468
1476
|
instructionParsedType: nameApi.instructionParsedType(instructionNode.name),
|
|
1469
1477
|
minimumNumberOfAccounts,
|
|
1470
1478
|
programAddressConstant
|
|
1471
|
-
}).mergeImportsWith(dataTypeFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaInstructions", ["type
|
|
1479
|
+
}).mergeImportsWith(dataTypeFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaInstructions", ["type Instruction"]).addImports("solanaInstructions", hasAccounts ? ["type InstructionWithAccounts", "type AccountMeta"] : []).addImports("solanaInstructions", hasData ? ["type InstructionWithData"] : []).addImports("solanaCodecsCore", hasData ? ["type ReadonlyUint8Array"] : []);
|
|
1472
1480
|
}
|
|
1473
1481
|
|
|
1474
1482
|
// src/fragments/instructionType.ts
|
|
@@ -1516,11 +1524,11 @@ function getInstructionTypeFragment(scope) {
|
|
|
1516
1524
|
instruction: instructionNode,
|
|
1517
1525
|
instructionType: nameApi.instructionType(instructionNode.name),
|
|
1518
1526
|
programAddressConstant
|
|
1519
|
-
}).mergeImportsWith(accountTypeParamsFragment, accountMetasFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaInstructions", [
|
|
1520
|
-
"type
|
|
1521
|
-
"type
|
|
1522
|
-
"type
|
|
1523
|
-
...hasData ? ["type
|
|
1527
|
+
}).mergeImportsWith(accountTypeParamsFragment, accountMetasFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaCodecsCore", hasData ? ["type ReadonlyUint8Array"] : []).addImports("solanaInstructions", [
|
|
1528
|
+
"type AccountMeta",
|
|
1529
|
+
"type Instruction",
|
|
1530
|
+
"type InstructionWithAccounts",
|
|
1531
|
+
...hasData ? ["type InstructionWithData"] : []
|
|
1524
1532
|
]);
|
|
1525
1533
|
return fragment2;
|
|
1526
1534
|
}
|
|
@@ -1763,7 +1771,7 @@ function mergeManifests(manifests, options = {}) {
|
|
|
1763
1771
|
}
|
|
1764
1772
|
|
|
1765
1773
|
// src/getRenderMapVisitor.ts
|
|
1766
|
-
import { join as join3 } from "
|
|
1774
|
+
import { join as join3 } from "path";
|
|
1767
1775
|
import { logWarn } from "@codama/errors";
|
|
1768
1776
|
import {
|
|
1769
1777
|
camelCase as camelCase12,
|
|
@@ -1780,6 +1788,7 @@ import { RenderMap } from "@codama/renderers-core";
|
|
|
1780
1788
|
import {
|
|
1781
1789
|
extendVisitor as extendVisitor2,
|
|
1782
1790
|
findProgramNodeFromPath as findProgramNodeFromPath7,
|
|
1791
|
+
getByteSizeVisitor,
|
|
1783
1792
|
getResolvedInstructionInputsVisitor,
|
|
1784
1793
|
LinkableDictionary as LinkableDictionary3,
|
|
1785
1794
|
NodeStack as NodeStack2,
|
|
@@ -2582,6 +2591,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2582
2591
|
stack
|
|
2583
2592
|
});
|
|
2584
2593
|
const resolvedInstructionInputVisitor = getResolvedInstructionInputsVisitor();
|
|
2594
|
+
const byteSizeVisitor = getByteSizeVisitor(linkables, { stack });
|
|
2585
2595
|
const globalScope = {
|
|
2586
2596
|
asyncResolvers,
|
|
2587
2597
|
customAccountData,
|
|
@@ -2609,6 +2619,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2609
2619
|
const scope = {
|
|
2610
2620
|
...globalScope,
|
|
2611
2621
|
accountPath,
|
|
2622
|
+
size: visit6(node, byteSizeVisitor),
|
|
2612
2623
|
typeManifest: visit6(node, typeManifestVisitor)
|
|
2613
2624
|
};
|
|
2614
2625
|
const fields = resolveNestedTypeNode3(node.data).fields;
|
|
@@ -2649,6 +2660,7 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2649
2660
|
encoderDocs: [],
|
|
2650
2661
|
manifest: visit6(node, typeManifestVisitor),
|
|
2651
2662
|
name: node.name,
|
|
2663
|
+
size: visit6(node, byteSizeVisitor),
|
|
2652
2664
|
typeDocs: node.docs,
|
|
2653
2665
|
typeNode: node.type
|
|
2654
2666
|
};
|
|
@@ -2691,7 +2703,8 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2691
2703
|
),
|
|
2692
2704
|
instructionPath,
|
|
2693
2705
|
renamedArgs: getRenamedArgsMap(node),
|
|
2694
|
-
resolvedInputs: visit6(node, resolvedInstructionInputVisitor)
|
|
2706
|
+
resolvedInputs: visit6(node, resolvedInstructionInputVisitor),
|
|
2707
|
+
size: visit6(node, byteSizeVisitor)
|
|
2695
2708
|
};
|
|
2696
2709
|
const instructionDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
|
|
2697
2710
|
...scope,
|
|
@@ -2820,10 +2833,10 @@ function getRenderMapVisitor(options = {}) {
|
|
|
2820
2833
|
"type ProgramDerivedAddress"
|
|
2821
2834
|
]).add("solanaInstructions", [
|
|
2822
2835
|
"AccountRole",
|
|
2823
|
-
"type
|
|
2836
|
+
"type AccountMeta",
|
|
2824
2837
|
"upgradeRoleToSigner"
|
|
2825
2838
|
]).add("solanaSigners", [
|
|
2826
|
-
"type
|
|
2839
|
+
"type AccountSignerMeta",
|
|
2827
2840
|
"isTransactionSigner",
|
|
2828
2841
|
"type TransactionSigner"
|
|
2829
2842
|
]).addAlias("solanaSigners", "isTransactionSigner", "kitIsTransactionSigner").toString(dependencyMap, useGranularImports)
|