codama-renderers-dart 0.5.5 → 0.5.6

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ifiok Jr.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -386,7 +386,8 @@ var WELL_KNOWN_ADDRESSES = /* @__PURE__ */ new Map([
386
386
  ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", "tokenProgramAddress"],
387
387
  ["TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb", "token2022ProgramAddress"],
388
388
  ["ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", "associatedTokenProgramAddress"],
389
- ["MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr", "memoProgramAddress"],
389
+ ["Memo4c2pN8afCj432Lb7RMVKi9PbQnnW7ewFFaV3oAH", "memoProgramAddress"],
390
+ ["MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr", "memoLegacyProgramAddressV3"],
390
391
  ["Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo", "memoLegacyProgramAddress"],
391
392
  // Metaplex programs
392
393
  ["metaqbxxU9qX8rZXkmUJ7haCrXXz2W1PSUq1Rn3E1od", "tokenMetadataProgramAddress"],
@@ -505,7 +506,8 @@ function getDiscriminatorValidationFragment(node, scope) {
505
506
  `Discriminator size must be a non-negative safe integer, got ${discriminator.size}.`
506
507
  );
507
508
  }
508
- return fragment`if (bytes.length - offset != ${fragmentFromString(String(discriminator.size))}) {
509
+ const comparison = node.kind === "accountNode" ? "<" : "!=";
510
+ return fragment`if (bytes.length - offset ${fragmentFromString(comparison)} ${fragmentFromString(String(discriminator.size))}) {
509
511
  throw ${use("SolanaError", "solanaErrors")}(
510
512
  ${use("SolanaErrorCode", "solanaErrors")}.codecsInvalidByteLength,
511
513
  {
@@ -619,7 +621,12 @@ function emptyTypeManifest() {
619
621
 
620
622
  // src/visitors/getTypeManifestVisitor.ts
621
623
  function getTypeManifestVisitor(input) {
622
- const { nameApi, linkables, nonScalarEnums = [] } = input;
624
+ const {
625
+ nameApi,
626
+ linkables,
627
+ nonScalarEnums = [],
628
+ linkOverrides = {}
629
+ } = input;
623
630
  const baseVisitor = visitorsCore.staticVisitor(
624
631
  (node) => {
625
632
  throw new errors.CodamaError(errors.CODAMA_ERROR__UNEXPECTED_NODE_KIND, {
@@ -1100,6 +1107,17 @@ function getTypeManifestVisitor(input) {
1100
1107
  },
1101
1108
  visitDefinedTypeLink(node, { self }) {
1102
1109
  const name = node.name;
1110
+ const override = linkOverrides[name];
1111
+ if (override != null) {
1112
+ const moduleKey2 = `linkOverride:${override.path}`;
1113
+ return {
1114
+ type: use(override.type, moduleKey2),
1115
+ encoder: use(override.encoder, moduleKey2),
1116
+ decoder: use(override.decoder, moduleKey2),
1117
+ value: emptyTypeManifest().value,
1118
+ isEnum: false
1119
+ };
1120
+ }
1103
1121
  const typeName = nameApi.dataType(name);
1104
1122
  const isNonScalar = nonScalarEnums.includes(node.name);
1105
1123
  const moduleKey = `definedType:${snakeCase(name)}`;
@@ -2719,7 +2737,9 @@ function getRenderMapVisitor(options = {}) {
2719
2737
  const linkables = new visitorsCore.LinkableDictionary();
2720
2738
  const typeManifestVisitor = getTypeManifestVisitor({
2721
2739
  nameApi,
2722
- linkables});
2740
+ linkables,
2741
+ linkOverrides: options.linkOverrides
2742
+ });
2723
2743
  const scope = {
2724
2744
  nameApi,
2725
2745
  typeManifestVisitor};
@@ -2898,13 +2918,14 @@ function renderVisitor(outputDir, options = {}) {
2898
2918
  deleteFolderBeforeRendering = true,
2899
2919
  formatCode = false,
2900
2920
  nameApi,
2901
- dependencyMap
2921
+ dependencyMap,
2922
+ linkOverrides
2902
2923
  } = options;
2903
2924
  return visitorsCore.rootNodeVisitor((root) => {
2904
2925
  const normalizedRoot = normalizeRootNode(root);
2905
2926
  const renderMap = visitorsCore.visit(
2906
2927
  normalizedRoot,
2907
- getRenderMapVisitor({ nameApi, dependencyMap })
2928
+ getRenderMapVisitor({ nameApi, dependencyMap, linkOverrides })
2908
2929
  );
2909
2930
  const typePathMap = {};
2910
2931
  for (const renderPath of renderMap.keys()) {
@@ -2929,7 +2950,14 @@ function renderVisitor(outputDir, options = {}) {
2929
2950
  }
2930
2951
  internalMap[key] = rel;
2931
2952
  }
2932
- const content = resolveFragmentContent(frag, dependencyMap ?? {}, internalMap);
2953
+ const content = resolveFragmentContent(
2954
+ frag,
2955
+ {
2956
+ ...dependencyMap ?? {},
2957
+ ...linkOverrideImports(outputDir, filePath, options.linkOverrides ?? {})
2958
+ },
2959
+ internalMap
2960
+ );
2933
2961
  files.push([fullPath, content]);
2934
2962
  }
2935
2963
  if (deleteFolderBeforeRendering && fs.existsSync(outputDir)) {
@@ -2944,6 +2972,35 @@ function renderVisitor(outputDir, options = {}) {
2944
2972
  }
2945
2973
  });
2946
2974
  }
2975
+ function linkOverrideImports(outputDir, generatedFilePath, overrides) {
2976
+ const resolved = {};
2977
+ if (Object.keys(overrides).length === 0) return resolved;
2978
+ const libRoot = findLibRoot(outputDir);
2979
+ if (libRoot == null) {
2980
+ throw new Error(
2981
+ `Cannot resolve linkOverrides because the render output directory "${outputDir}" has no "lib" ancestor.`
2982
+ );
2983
+ }
2984
+ const generatedAbsolute = path.posix.join(
2985
+ path.posix.resolve(outputDir),
2986
+ generatedFilePath
2987
+ );
2988
+ for (const override of Object.values(overrides)) {
2989
+ const overrideAbsolute = path.posix.join(libRoot, override.path);
2990
+ let rel = path.posix.relative(path.posix.dirname(generatedAbsolute), overrideAbsolute);
2991
+ if (!rel.startsWith(".")) {
2992
+ rel = `./${rel}`;
2993
+ }
2994
+ resolved[`linkOverride:${override.path}`] = rel;
2995
+ }
2996
+ return resolved;
2997
+ }
2998
+ function findLibRoot(outputDir) {
2999
+ const segments = path.posix.resolve(outputDir).split("/");
3000
+ const libIndex = segments.lastIndexOf("lib");
3001
+ if (libIndex < 0) return null;
3002
+ return segments.slice(0, libIndex + 1).join("/");
3003
+ }
2947
3004
  function resolveFragmentContent(frag, dependencyMap, internalMap = {}) {
2948
3005
  const { content, imports } = frag;
2949
3006
  const importStr = imports.toString({