@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.
@@ -552,43 +552,49 @@ function getTypeFragment(scope) {
552
552
  // src/fragments/typeDecoder.ts
553
553
  function getTypeDecoderFragment(scope) {
554
554
  const { name, manifest, nameApi, docs = [] } = scope;
555
+ const decoderType = typeof scope.size === "number" ? "FixedSizeDecoder" : "Decoder";
555
556
  return fragmentFromTemplate("typeDecoder.njk", {
556
557
  decoderFunction: nameApi.decoderFunction(name),
558
+ decoderType,
557
559
  docs,
558
560
  looseName: nameApi.dataArgsType(name),
559
561
  manifest,
560
562
  strictName: nameApi.dataType(name)
561
- }).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore", "type Decoder");
563
+ }).mergeImportsWith(manifest.decoder).addImports("solanaCodecsCore", `type ${decoderType}`);
562
564
  }
563
565
 
564
566
  // src/fragments/typeEncoder.ts
565
567
  function getTypeEncoderFragment(scope) {
566
568
  const { name, manifest, nameApi, docs = [] } = scope;
569
+ const encoderType = typeof scope.size === "number" ? "FixedSizeEncoder" : "Encoder";
567
570
  return fragmentFromTemplate("typeEncoder.njk", {
568
571
  docs,
569
572
  encoderFunction: nameApi.encoderFunction(name),
573
+ encoderType,
570
574
  looseName: nameApi.dataArgsType(name),
571
575
  manifest,
572
576
  strictName: nameApi.dataType(name)
573
- }).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore", "type Encoder");
577
+ }).mergeImportsWith(manifest.encoder).addImports("solanaCodecsCore", `type ${encoderType}`);
574
578
  }
575
579
 
576
580
  // src/fragments/typeCodec.ts
577
581
  function getTypeCodecFragment(scope) {
578
582
  const { name, manifest, nameApi } = scope;
583
+ const codecType = typeof scope.size === "number" ? "FixedSizeCodec" : "Codec";
579
584
  return mergeFragments(
580
585
  [
581
586
  getTypeEncoderFragment({ ...scope, docs: scope.encoderDocs }),
582
587
  getTypeDecoderFragment({ ...scope, docs: scope.decoderDocs }),
583
588
  fragmentFromTemplate("typeCodec.njk", {
584
589
  codecFunction: nameApi.codecFunction(name),
590
+ codecType,
585
591
  decoderFunction: nameApi.decoderFunction(name),
586
592
  docs: scope.codecDocs,
587
593
  encoderFunction: nameApi.encoderFunction(name),
588
594
  looseName: nameApi.dataArgsType(name),
589
595
  manifest,
590
596
  strictName: nameApi.dataType(name)
591
- }).addImports("solanaCodecsCore", ["type Codec", "combineCodec"])
597
+ }).addImports("solanaCodecsCore", [`type ${codecType}`, "combineCodec"])
592
598
  ],
593
599
  (renders) => renders.join("\n\n")
594
600
  );
@@ -612,7 +618,8 @@ function getAccountTypeFragment(scope) {
612
618
  return getTypeWithCodecFragment({
613
619
  manifest: typeManifest2,
614
620
  name: accountNode.name,
615
- nameApi
621
+ nameApi,
622
+ size: scope.size
616
623
  });
617
624
  }
618
625
 
@@ -673,10 +680,10 @@ var import_nodes6 = require("@codama/nodes");
673
680
  function getInstructionAccountMetaFragment(instructionAccountNode) {
674
681
  const typeParam = `TAccount${(0, import_nodes6.pascalCase)(instructionAccountNode.name)}`;
675
682
  if (instructionAccountNode.isSigner === true && instructionAccountNode.isWritable) {
676
- return fragment(`WritableSignerAccount<${typeParam}> & IAccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type WritableSignerAccount"]).addImports("solanaSigners", ["type IAccountSignerMeta"]);
683
+ return fragment(`WritableSignerAccount<${typeParam}> & AccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type WritableSignerAccount"]).addImports("solanaSigners", ["type AccountSignerMeta"]);
677
684
  }
678
685
  if (instructionAccountNode.isSigner === true) {
679
- return fragment(`ReadonlySignerAccount<${typeParam}> & IAccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type ReadonlySignerAccount"]).addImports("solanaSigners", ["type IAccountSignerMeta"]);
686
+ return fragment(`ReadonlySignerAccount<${typeParam}> & AccountSignerMeta<${typeParam}>`).addImports("solanaInstructions", ["type ReadonlySignerAccount"]).addImports("solanaSigners", ["type AccountSignerMeta"]);
680
687
  }
681
688
  if (instructionAccountNode.isWritable) {
682
689
  return fragment(`WritableAccount<${typeParam}>`).addImports("solanaInstructions", "type WritableAccount");
@@ -693,10 +700,10 @@ function getInstructionAccountTypeParamFragment(scope) {
693
700
  const instructionNode = (0, import_visitors_core7.findInstructionNodeFromPath)(instructionAccountPath);
694
701
  const programNode = (0, import_visitors_core7.findProgramNodeFromPath)(instructionAccountPath);
695
702
  const typeParam = `TAccount${(0, import_nodes7.pascalCase)(instructionAccountNode.name)}`;
696
- const accountMeta = allowAccountMeta ? " | IAccountMeta<string>" : "";
703
+ const accountMeta = allowAccountMeta ? " | AccountMeta<string>" : "";
697
704
  const imports = new ImportMap();
698
705
  if (allowAccountMeta) {
699
- imports.add("solanaInstructions", "type IAccountMeta");
706
+ imports.add("solanaInstructions", "type AccountMeta");
700
707
  }
701
708
  if (instructionNode.optionalAccountStrategy === "omitted" && instructionAccountNode.isOptional) {
702
709
  return fragment(`${typeParam} extends string${accountMeta} | undefined = undefined`, imports);
@@ -791,7 +798,8 @@ function getInstructionDataFragment(scope) {
791
798
  return getTypeWithCodecFragment({
792
799
  manifest: dataArgsManifest,
793
800
  name: instructionDataName,
794
- nameApi
801
+ nameApi,
802
+ size: scope.size
795
803
  });
796
804
  }
797
805
 
@@ -1240,8 +1248,8 @@ function getInstructionRemainingAccountsFragment(scope) {
1240
1248
  return mergeFragments(
1241
1249
  fragments,
1242
1250
  (r) => `// Remaining accounts.
1243
- const remainingAccounts: IAccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.join(", ...")}]`}`
1244
- ).addImports("solanaInstructions", ["type IAccountMeta"]);
1251
+ const remainingAccounts: AccountMeta[] = ${r.length === 1 ? r[0] : `[...${r.join(", ...")}]`}`
1252
+ ).addImports("solanaInstructions", ["type AccountMeta"]);
1245
1253
  }
1246
1254
  function getRemainingAccountsFragment2(remainingAccounts, scope) {
1247
1255
  const remainingAccountsFragment = (() => {
@@ -1361,7 +1369,7 @@ function getInstructionFunctionFragment(scope) {
1361
1369
  const getReturnType = (instructionType) => {
1362
1370
  let returnType = instructionType;
1363
1371
  if (hasByteDeltas) {
1364
- returnType = `${returnType} & IInstructionWithByteDelta`;
1372
+ returnType = `${returnType} & InstructionWithByteDelta`;
1365
1373
  }
1366
1374
  return useAsync ? `Promise<${returnType}>` : returnType;
1367
1375
  };
@@ -1398,10 +1406,10 @@ function getInstructionFunctionFragment(scope) {
1398
1406
  argsTypeFragment
1399
1407
  ).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaAddresses", ["type Address"]);
1400
1408
  if (hasAccounts) {
1401
- functionFragment.addImports("solanaInstructions", ["type IAccountMeta"]).addImports("shared", ["getAccountMetaFactory", "type ResolvedAccount"]);
1409
+ functionFragment.addImports("solanaInstructions", ["type AccountMeta"]).addImports("shared", ["getAccountMetaFactory", "type ResolvedAccount"]);
1402
1410
  }
1403
1411
  if (hasByteDeltas) {
1404
- functionFragment.addImports("shared", ["type IInstructionWithByteDelta"]);
1412
+ functionFragment.addImports("shared", ["type InstructionWithByteDelta"]);
1405
1413
  }
1406
1414
  return functionFragment;
1407
1415
  }
@@ -1421,8 +1429,8 @@ function getInstructionType(scope) {
1421
1429
  if (account.isSigner === "either") {
1422
1430
  const signerRole = account.isWritable ? "WritableSignerAccount" : "ReadonlySignerAccount";
1423
1431
  return fragment(
1424
- `typeof input["${camelName}"] extends TransactionSigner<${typeParam}> ? ${signerRole}<${typeParam}> & IAccountSignerMeta<${typeParam}> : ${typeParam}`
1425
- ).addImports("solanaInstructions", [`type ${signerRole}`]).addImports("solanaSigners", ["type IAccountSignerMeta"]);
1432
+ `typeof input["${camelName}"] extends TransactionSigner<${typeParam}> ? ${signerRole}<${typeParam}> & AccountSignerMeta<${typeParam}> : ${typeParam}`
1433
+ ).addImports("solanaInstructions", [`type ${signerRole}`]).addImports("solanaSigners", ["type AccountSignerMeta"]);
1426
1434
  }
1427
1435
  return fragment(typeParam);
1428
1436
  });
@@ -1471,7 +1479,7 @@ function getInstructionParseFunctionFragment(scope) {
1471
1479
  instructionParsedType: nameApi.instructionParsedType(instructionNode.name),
1472
1480
  minimumNumberOfAccounts,
1473
1481
  programAddressConstant
1474
- }).mergeImportsWith(dataTypeFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaInstructions", ["type IInstruction"]).addImports("solanaInstructions", hasAccounts ? ["type IInstructionWithAccounts", "type IAccountMeta"] : []).addImports("solanaInstructions", hasData ? ["type IInstructionWithData"] : []);
1482
+ }).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"] : []);
1475
1483
  }
1476
1484
 
1477
1485
  // src/fragments/instructionType.ts
@@ -1519,11 +1527,11 @@ function getInstructionTypeFragment(scope) {
1519
1527
  instruction: instructionNode,
1520
1528
  instructionType: nameApi.instructionType(instructionNode.name),
1521
1529
  programAddressConstant
1522
- }).mergeImportsWith(accountTypeParamsFragment, accountMetasFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaInstructions", [
1523
- "type IAccountMeta",
1524
- "type IInstruction",
1525
- "type IInstructionWithAccounts",
1526
- ...hasData ? ["type IInstructionWithData"] : []
1530
+ }).mergeImportsWith(accountTypeParamsFragment, accountMetasFragment).addImports("generatedPrograms", [programAddressConstant]).addImports("solanaCodecsCore", hasData ? ["type ReadonlyUint8Array"] : []).addImports("solanaInstructions", [
1531
+ "type AccountMeta",
1532
+ "type Instruction",
1533
+ "type InstructionWithAccounts",
1534
+ ...hasData ? ["type InstructionWithData"] : []
1527
1535
  ]);
1528
1536
  return fragment2;
1529
1537
  }
@@ -2541,6 +2549,7 @@ function getRenderMapVisitor(options = {}) {
2541
2549
  stack
2542
2550
  });
2543
2551
  const resolvedInstructionInputVisitor = (0, import_visitors_core21.getResolvedInstructionInputsVisitor)();
2552
+ const byteSizeVisitor = (0, import_visitors_core21.getByteSizeVisitor)(linkables, { stack });
2544
2553
  const globalScope = {
2545
2554
  asyncResolvers,
2546
2555
  customAccountData,
@@ -2568,6 +2577,7 @@ function getRenderMapVisitor(options = {}) {
2568
2577
  const scope = {
2569
2578
  ...globalScope,
2570
2579
  accountPath,
2580
+ size: (0, import_visitors_core21.visit)(node, byteSizeVisitor),
2571
2581
  typeManifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor)
2572
2582
  };
2573
2583
  const fields = (0, import_nodes22.resolveNestedTypeNode)(node.data).fields;
@@ -2608,6 +2618,7 @@ function getRenderMapVisitor(options = {}) {
2608
2618
  encoderDocs: [],
2609
2619
  manifest: (0, import_visitors_core21.visit)(node, typeManifestVisitor),
2610
2620
  name: node.name,
2621
+ size: (0, import_visitors_core21.visit)(node, byteSizeVisitor),
2611
2622
  typeDocs: node.docs,
2612
2623
  typeNode: node.type
2613
2624
  };
@@ -2650,7 +2661,8 @@ function getRenderMapVisitor(options = {}) {
2650
2661
  ),
2651
2662
  instructionPath,
2652
2663
  renamedArgs: getRenamedArgsMap(node),
2653
- resolvedInputs: (0, import_visitors_core21.visit)(node, resolvedInstructionInputVisitor)
2664
+ resolvedInputs: (0, import_visitors_core21.visit)(node, resolvedInstructionInputVisitor),
2665
+ size: (0, import_visitors_core21.visit)(node, byteSizeVisitor)
2654
2666
  };
2655
2667
  const instructionDiscriminatorConstantsFragment = getDiscriminatorConstantsFragment({
2656
2668
  ...scope,
@@ -2779,10 +2791,10 @@ function getRenderMapVisitor(options = {}) {
2779
2791
  "type ProgramDerivedAddress"
2780
2792
  ]).add("solanaInstructions", [
2781
2793
  "AccountRole",
2782
- "type IAccountMeta",
2794
+ "type AccountMeta",
2783
2795
  "upgradeRoleToSigner"
2784
2796
  ]).add("solanaSigners", [
2785
- "type IAccountSignerMeta",
2797
+ "type AccountSignerMeta",
2786
2798
  "isTransactionSigner",
2787
2799
  "type TransactionSigner"
2788
2800
  ]).addAlias("solanaSigners", "isTransactionSigner", "kitIsTransactionSigner").toString(dependencyMap, useGranularImports)