@codama/fragments 0.1.0

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.
Files changed (97) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +542 -0
  3. package/dist/index.browser.cjs +208 -0
  4. package/dist/index.browser.cjs.map +1 -0
  5. package/dist/index.browser.mjs +176 -0
  6. package/dist/index.browser.mjs.map +1 -0
  7. package/dist/index.node.cjs +195 -0
  8. package/dist/index.node.cjs.map +1 -0
  9. package/dist/index.node.mjs +163 -0
  10. package/dist/index.node.mjs.map +1 -0
  11. package/dist/index.react-native.mjs +176 -0
  12. package/dist/index.react-native.mjs.map +1 -0
  13. package/dist/javascript.browser.cjs +403 -0
  14. package/dist/javascript.browser.cjs.map +1 -0
  15. package/dist/javascript.browser.mjs +353 -0
  16. package/dist/javascript.browser.mjs.map +1 -0
  17. package/dist/javascript.node.cjs +390 -0
  18. package/dist/javascript.node.cjs.map +1 -0
  19. package/dist/javascript.node.mjs +340 -0
  20. package/dist/javascript.node.mjs.map +1 -0
  21. package/dist/javascript.react-native.mjs +353 -0
  22. package/dist/javascript.react-native.mjs.map +1 -0
  23. package/dist/rust.browser.cjs +371 -0
  24. package/dist/rust.browser.cjs.map +1 -0
  25. package/dist/rust.browser.mjs +322 -0
  26. package/dist/rust.browser.mjs.map +1 -0
  27. package/dist/rust.node.cjs +358 -0
  28. package/dist/rust.node.cjs.map +1 -0
  29. package/dist/rust.node.mjs +309 -0
  30. package/dist/rust.node.mjs.map +1 -0
  31. package/dist/rust.react-native.mjs +322 -0
  32. package/dist/rust.react-native.mjs.map +1 -0
  33. package/dist/types/core/BaseFragment.d.ts +21 -0
  34. package/dist/types/core/BaseFragment.d.ts.map +1 -0
  35. package/dist/types/core/casing.d.ts +52 -0
  36. package/dist/types/core/casing.d.ts.map +1 -0
  37. package/dist/types/core/createFragmentTemplate.d.ts +38 -0
  38. package/dist/types/core/createFragmentTemplate.d.ts.map +1 -0
  39. package/dist/types/core/fs.d.ts +28 -0
  40. package/dist/types/core/fs.d.ts.map +1 -0
  41. package/dist/types/core/index.d.ts +9 -0
  42. package/dist/types/core/index.d.ts.map +1 -0
  43. package/dist/types/core/mapFragmentContent.d.ts +43 -0
  44. package/dist/types/core/mapFragmentContent.d.ts.map +1 -0
  45. package/dist/types/core/path.d.ts +43 -0
  46. package/dist/types/core/path.d.ts.map +1 -0
  47. package/dist/types/core/renderMap.d.ts +61 -0
  48. package/dist/types/core/renderMap.d.ts.map +1 -0
  49. package/dist/types/core/setFragmentContent.d.ts +23 -0
  50. package/dist/types/core/setFragmentContent.d.ts.map +1 -0
  51. package/dist/types/index.d.ts +17 -0
  52. package/dist/types/index.d.ts.map +1 -0
  53. package/dist/types/javascript/ImportMap.d.ts +61 -0
  54. package/dist/types/javascript/ImportMap.d.ts.map +1 -0
  55. package/dist/types/javascript/addToImportMap.d.ts +25 -0
  56. package/dist/types/javascript/addToImportMap.d.ts.map +1 -0
  57. package/dist/types/javascript/fragment.d.ts +135 -0
  58. package/dist/types/javascript/fragment.d.ts.map +1 -0
  59. package/dist/types/javascript/getDocblockFragment.d.ts +53 -0
  60. package/dist/types/javascript/getDocblockFragment.d.ts.map +1 -0
  61. package/dist/types/javascript/getExportAllFragment.d.ts +21 -0
  62. package/dist/types/javascript/getExportAllFragment.d.ts.map +1 -0
  63. package/dist/types/javascript/getExternalDependencies.d.ts +29 -0
  64. package/dist/types/javascript/getExternalDependencies.d.ts.map +1 -0
  65. package/dist/types/javascript/importMapToString.d.ts +40 -0
  66. package/dist/types/javascript/importMapToString.d.ts.map +1 -0
  67. package/dist/types/javascript/index.d.ts +23 -0
  68. package/dist/types/javascript/index.d.ts.map +1 -0
  69. package/dist/types/javascript/mergeImportMaps.d.ts +34 -0
  70. package/dist/types/javascript/mergeImportMaps.d.ts.map +1 -0
  71. package/dist/types/javascript/removeFromImportMap.d.ts +21 -0
  72. package/dist/types/javascript/removeFromImportMap.d.ts.map +1 -0
  73. package/dist/types/javascript/resolveImportMap.d.ts +33 -0
  74. package/dist/types/javascript/resolveImportMap.d.ts.map +1 -0
  75. package/dist/types/rust/ImportMap.d.ts +52 -0
  76. package/dist/types/rust/ImportMap.d.ts.map +1 -0
  77. package/dist/types/rust/addAliasToImportMap.d.ts +24 -0
  78. package/dist/types/rust/addAliasToImportMap.d.ts.map +1 -0
  79. package/dist/types/rust/addToImportMap.d.ts +27 -0
  80. package/dist/types/rust/addToImportMap.d.ts.map +1 -0
  81. package/dist/types/rust/fragment.d.ts +118 -0
  82. package/dist/types/rust/fragment.d.ts.map +1 -0
  83. package/dist/types/rust/getDocblockFragment.d.ts +53 -0
  84. package/dist/types/rust/getDocblockFragment.d.ts.map +1 -0
  85. package/dist/types/rust/getExternalDependencies.d.ts +30 -0
  86. package/dist/types/rust/getExternalDependencies.d.ts.map +1 -0
  87. package/dist/types/rust/importMapToString.d.ts +30 -0
  88. package/dist/types/rust/importMapToString.d.ts.map +1 -0
  89. package/dist/types/rust/index.d.ts +23 -0
  90. package/dist/types/rust/index.d.ts.map +1 -0
  91. package/dist/types/rust/mergeImportMaps.d.ts +23 -0
  92. package/dist/types/rust/mergeImportMaps.d.ts.map +1 -0
  93. package/dist/types/rust/removeFromImportMap.d.ts +20 -0
  94. package/dist/types/rust/removeFromImportMap.d.ts.map +1 -0
  95. package/dist/types/rust/resolveImportMap.d.ts +32 -0
  96. package/dist/types/rust/resolveImportMap.d.ts.map +1 -0
  97. package/package.json +106 -0
@@ -0,0 +1,322 @@
1
+ import 'fs';
2
+ import { CodamaError, CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND } from '@codama/errors';
3
+ import 'path';
4
+
5
+ // src/core/casing.ts
6
+ function capitalize(str) {
7
+ if (str.length === 0) return str;
8
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
9
+ }
10
+ function titleCase(str) {
11
+ return str.replace(/([A-Z])/g, " $1").split(/[^a-zA-Z0-9]+/).filter((word) => word.length > 0).map(capitalize).join(" ");
12
+ }
13
+ function pascalCase(str) {
14
+ return titleCase(str).split(" ").join("");
15
+ }
16
+ function camelCase(str) {
17
+ if (str.length === 0) return str;
18
+ const pascalStr = pascalCase(str);
19
+ return pascalStr.charAt(0).toLowerCase() + pascalStr.slice(1);
20
+ }
21
+ function kebabCase(str) {
22
+ return titleCase(str).split(" ").join("-").toLowerCase();
23
+ }
24
+ function snakeCase(str) {
25
+ return titleCase(str).split(" ").join("_").toLowerCase();
26
+ }
27
+
28
+ // src/core/createFragmentTemplate.ts
29
+ function createFragmentTemplate(template, items, isFragment2, mergeFragments2) {
30
+ const fragments = items.filter(isFragment2);
31
+ const zippedItems = items.map((item, i) => {
32
+ const itemPrefix = template[i];
33
+ if (typeof item === "undefined") return itemPrefix;
34
+ if (isFragment2(item)) return itemPrefix + item.content;
35
+ return itemPrefix + String(item);
36
+ });
37
+ return mergeFragments2(fragments, () => zippedItems.join("") + template[template.length - 1]);
38
+ }
39
+ function joinPath(...paths) {
40
+ {
41
+ return paths.join("/").replace(/\/+/g, "/");
42
+ }
43
+ }
44
+ function pathDirectory(path) {
45
+ {
46
+ return path.substring(0, path.lastIndexOf("/"));
47
+ }
48
+ }
49
+ function pathBasename(path) {
50
+ {
51
+ const slash = path.lastIndexOf("/");
52
+ return slash >= 0 ? path.substring(slash + 1) : path;
53
+ }
54
+ }
55
+ function relativePath(from, to) {
56
+ {
57
+ throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: "relative" });
58
+ }
59
+ }
60
+
61
+ // src/core/fs.ts
62
+ function createDirectory(path) {
63
+ {
64
+ throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: "mkdirSync" });
65
+ }
66
+ }
67
+ function deleteDirectory(path) {
68
+ {
69
+ throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: "rmSync" });
70
+ }
71
+ }
72
+ function writeFile(path, content) {
73
+ {
74
+ throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: "writeFileSync" });
75
+ }
76
+ }
77
+ function fileExists(path) {
78
+ {
79
+ throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: "existsSync" });
80
+ }
81
+ }
82
+ function readFile(path) {
83
+ {
84
+ throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: "readFileSync" });
85
+ }
86
+ }
87
+ function readJson(path) {
88
+ return JSON.parse(readFile());
89
+ }
90
+
91
+ // src/core/setFragmentContent.ts
92
+ function setFragmentContent(fragment2, content) {
93
+ return Object.freeze({ ...fragment2, content });
94
+ }
95
+
96
+ // src/core/mapFragmentContent.ts
97
+ function mapFragmentContent(fragment2, mapContent) {
98
+ return setFragmentContent(fragment2, mapContent(fragment2.content));
99
+ }
100
+ async function mapFragmentContentAsync(fragment2, mapContent) {
101
+ return setFragmentContent(fragment2, await mapContent(fragment2.content));
102
+ }
103
+ function createRenderMap(pathOrEntries, content) {
104
+ let entries = [];
105
+ if (typeof pathOrEntries === "string" && content !== void 0) {
106
+ entries = [[pathOrEntries, content]];
107
+ } else if (typeof pathOrEntries === "object" && pathOrEntries !== null) {
108
+ entries = Object.entries(pathOrEntries).flatMap(
109
+ ([key, value]) => value === void 0 ? [] : [[key, value]]
110
+ );
111
+ }
112
+ return Object.freeze(new Map(entries));
113
+ }
114
+ function addToRenderMap(renderMap, path, content) {
115
+ return mergeRenderMaps([renderMap, createRenderMap(path, content)]);
116
+ }
117
+ function removeFromRenderMap(renderMap, path) {
118
+ const newMap = new Map(renderMap);
119
+ newMap.delete(path);
120
+ return Object.freeze(newMap);
121
+ }
122
+ function mergeRenderMaps(renderMaps) {
123
+ if (renderMaps.length === 0) return createRenderMap();
124
+ if (renderMaps.length === 1) return renderMaps[0];
125
+ const merged = new Map(renderMaps[0]);
126
+ for (const map of renderMaps.slice(1)) {
127
+ for (const [key, value] of map) {
128
+ merged.set(key, value);
129
+ }
130
+ }
131
+ return Object.freeze(merged);
132
+ }
133
+ function mapRenderMapFragment(renderMap, fn) {
134
+ return Object.freeze(new Map([...[...renderMap.entries()].map(([key, value]) => [key, fn(value, key)])]));
135
+ }
136
+ async function mapRenderMapFragmentAsync(renderMap, fn) {
137
+ return Object.freeze(
138
+ new Map(
139
+ await Promise.all([
140
+ ...[...renderMap.entries()].map(async ([key, value]) => [key, await fn(value, key)])
141
+ ])
142
+ )
143
+ );
144
+ }
145
+ function mapRenderMapContent(renderMap, fn) {
146
+ return mapRenderMapFragment(
147
+ renderMap,
148
+ (fragment2, path) => mapFragmentContent(fragment2, (content) => fn(content, path))
149
+ );
150
+ }
151
+ async function mapRenderMapContentAsync(renderMap, fn) {
152
+ return await mapRenderMapFragmentAsync(
153
+ renderMap,
154
+ (fragment2, path) => mapFragmentContentAsync(fragment2, (content) => fn(content, path))
155
+ );
156
+ }
157
+ function getFromRenderMap(renderMap, path) {
158
+ const value = renderMap.get(path);
159
+ if (value === void 0) {
160
+ throw new CodamaError(CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND, { key: path });
161
+ }
162
+ return value;
163
+ }
164
+ function renderMapContains(renderMap, path, value) {
165
+ const { content } = getFromRenderMap(renderMap, path);
166
+ return typeof value === "string" ? content.includes(value) : value.test(content);
167
+ }
168
+ function writeRenderMap(renderMap, basePath) {
169
+ renderMap.forEach(({ content }, relativePath2) => {
170
+ writeFile(joinPath(basePath, relativePath2));
171
+ });
172
+ }
173
+
174
+ // src/rust/ImportMap.ts
175
+ var RUST_CORE_IMPORTS = /* @__PURE__ */ new Set([
176
+ "alloc",
177
+ "clippy",
178
+ "core",
179
+ "crate",
180
+ "self",
181
+ "std",
182
+ "super"
183
+ ]);
184
+ function createImportMap() {
185
+ return Object.freeze(/* @__PURE__ */ new Map());
186
+ }
187
+
188
+ // src/rust/mergeImportMaps.ts
189
+ function mergeImportMaps(importMaps) {
190
+ if (importMaps.length === 0) return createImportMap();
191
+ if (importMaps.length === 1) return importMaps[0];
192
+ const merged = new Map(importMaps[0]);
193
+ for (const map of importMaps.slice(1)) {
194
+ for (const [path, info] of map) {
195
+ merged.set(path, info);
196
+ }
197
+ }
198
+ return Object.freeze(merged);
199
+ }
200
+
201
+ // src/rust/addToImportMap.ts
202
+ function addToImportMap(importMap, paths) {
203
+ const inputs = typeof paths === "string" ? [paths] : [...paths];
204
+ if (inputs.length === 0) return importMap;
205
+ const additions = /* @__PURE__ */ new Map();
206
+ for (const path of inputs) {
207
+ if (!additions.has(path) && !importMap.has(path)) {
208
+ additions.set(path, Object.freeze({ importedPath: path }));
209
+ }
210
+ }
211
+ if (additions.size === 0) return importMap;
212
+ return mergeImportMaps([importMap, additions]);
213
+ }
214
+
215
+ // src/rust/addAliasToImportMap.ts
216
+ function addAliasToImportMap(importMap, path, alias) {
217
+ const next = new Map(importMap);
218
+ next.set(path, Object.freeze({ alias, importedPath: path }));
219
+ return Object.freeze(next);
220
+ }
221
+
222
+ // src/rust/removeFromImportMap.ts
223
+ function removeFromImportMap(importMap, paths) {
224
+ const targets = typeof paths === "string" ? [paths] : [...paths];
225
+ if (targets.length === 0) return importMap;
226
+ const next = new Map(importMap);
227
+ for (const path of targets) next.delete(path);
228
+ return Object.freeze(next);
229
+ }
230
+
231
+ // src/rust/resolveImportMap.ts
232
+ function resolveImportMap(importMap, dependencies) {
233
+ const prefixes = Object.keys(dependencies);
234
+ if (prefixes.length === 0 || importMap.size === 0) return importMap;
235
+ const next = new Map(importMap);
236
+ let mutated = false;
237
+ for (const [path, info] of importMap) {
238
+ const resolvedPath = resolvePath(path, dependencies, prefixes);
239
+ if (resolvedPath === path) continue;
240
+ next.delete(path);
241
+ next.set(resolvedPath, Object.freeze({ ...info, importedPath: resolvedPath }));
242
+ mutated = true;
243
+ }
244
+ return mutated ? Object.freeze(next) : importMap;
245
+ }
246
+ function resolvePath(path, dependencies, prefixes) {
247
+ for (const prefix of prefixes) {
248
+ if (path.startsWith(`${prefix}::`)) {
249
+ return dependencies[prefix] + path.slice(prefix.length);
250
+ }
251
+ }
252
+ return path;
253
+ }
254
+
255
+ // src/rust/getExternalDependencies.ts
256
+ function getExternalDependencies(importMap, dependencies = {}) {
257
+ const resolved = resolveImportMap(importMap, dependencies);
258
+ const crates = /* @__PURE__ */ new Set();
259
+ for (const path of resolved.keys()) {
260
+ const root = path.split("::")[0];
261
+ if (!RUST_CORE_IMPORTS.has(root)) crates.add(root);
262
+ }
263
+ return crates;
264
+ }
265
+
266
+ // src/rust/importMapToString.ts
267
+ function importMapToString(importMap, dependencies = {}) {
268
+ const resolved = resolveImportMap(importMap, dependencies);
269
+ return [...resolved.values()].map((info) => info.alias ? `use ${info.importedPath} as ${info.alias};` : `use ${info.importedPath};`).sort((a, b) => a.localeCompare(b)).join("\n");
270
+ }
271
+
272
+ // src/rust/fragment.ts
273
+ function isFragment(value) {
274
+ return typeof value === "object" && value !== null && "content" in value && "imports" in value;
275
+ }
276
+ function fragment(template, ...items) {
277
+ return createFragmentTemplate(template, items, isFragment, mergeFragments);
278
+ }
279
+ function mergeFragments(fragments, mergeContent) {
280
+ const filtered = fragments.filter((f) => f !== void 0);
281
+ return Object.freeze({
282
+ content: mergeContent(filtered.map((f) => f.content)),
283
+ imports: mergeImportMaps(filtered.map((f) => f.imports))
284
+ });
285
+ }
286
+ function addFragmentImports(fragment2, paths) {
287
+ return Object.freeze({
288
+ ...fragment2,
289
+ imports: addToImportMap(fragment2.imports, paths)
290
+ });
291
+ }
292
+ function addFragmentImportAlias(fragment2, path, alias) {
293
+ return Object.freeze({
294
+ ...fragment2,
295
+ imports: addAliasToImportMap(fragment2.imports, path, alias)
296
+ });
297
+ }
298
+ function mergeFragmentImports(fragment2, importMaps) {
299
+ return Object.freeze({
300
+ ...fragment2,
301
+ imports: mergeImportMaps([fragment2.imports, ...importMaps])
302
+ });
303
+ }
304
+ function removeFragmentImports(fragment2, paths) {
305
+ return Object.freeze({
306
+ ...fragment2,
307
+ imports: removeFromImportMap(fragment2.imports, paths)
308
+ });
309
+ }
310
+
311
+ // src/rust/getDocblockFragment.ts
312
+ function getDocblockFragment(lines, options = {}) {
313
+ if (!lines || lines.length === 0) return void 0;
314
+ const prefix = options.internal ? "//!" : "///";
315
+ const lineJump = options.withLineJump ? "\n" : "";
316
+ const prefixedLines = lines.map((line) => line ? `${prefix} ${line}` : prefix);
317
+ return fragment`${prefixedLines.join("\n")}${lineJump}`;
318
+ }
319
+
320
+ export { RUST_CORE_IMPORTS, addAliasToImportMap, addFragmentImportAlias, addFragmentImports, addToImportMap, addToRenderMap, camelCase, capitalize, createDirectory, createFragmentTemplate, createImportMap, createRenderMap, deleteDirectory, fileExists, fragment, getDocblockFragment, getExternalDependencies, getFromRenderMap, importMapToString, isFragment, joinPath, kebabCase, mapFragmentContent, mapFragmentContentAsync, mapRenderMapContent, mapRenderMapContentAsync, mapRenderMapFragment, mapRenderMapFragmentAsync, mergeFragmentImports, mergeFragments, mergeImportMaps, mergeRenderMaps, pascalCase, pathBasename, pathDirectory, readFile, readJson, relativePath, removeFragmentImports, removeFromImportMap, removeFromRenderMap, renderMapContains, resolveImportMap, setFragmentContent, snakeCase, titleCase, writeFile, writeRenderMap };
321
+ //# sourceMappingURL=rust.browser.mjs.map
322
+ //# sourceMappingURL=rust.browser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/casing.ts","../src/core/createFragmentTemplate.ts","../src/core/path.ts","../src/core/fs.ts","../src/core/setFragmentContent.ts","../src/core/mapFragmentContent.ts","../src/core/renderMap.ts","../src/rust/ImportMap.ts","../src/rust/mergeImportMaps.ts","../src/rust/addToImportMap.ts","../src/rust/addAliasToImportMap.ts","../src/rust/removeFromImportMap.ts","../src/rust/resolveImportMap.ts","../src/rust/getExternalDependencies.ts","../src/rust/importMapToString.ts","../src/rust/fragment.ts","../src/rust/getDocblockFragment.ts"],"names":["isFragment","mergeFragments","CodamaError","CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE","fragment","relativePath"],"mappings":";;;;;AAsBO,SAAS,WAAW,GAAA,EAAqB;AAC5C,EAAA,IAAI,GAAA,CAAI,MAAA,KAAW,CAAA,EAAG,OAAO,GAAA;AAC7B,EAAA,OAAO,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,KAAgB,GAAA,CAAI,KAAA,CAAM,CAAC,CAAA,CAAE,WAAA,EAAY;AAClE;AAQO,SAAS,UAAU,GAAA,EAAqB;AAC3C,EAAA,OAAO,IACF,OAAA,CAAQ,UAAA,EAAY,KAAK,CAAA,CACzB,KAAA,CAAM,eAAe,CAAA,CACrB,MAAA,CAAO,CAAA,IAAA,KAAQ,IAAA,CAAK,SAAS,CAAC,CAAA,CAC9B,IAAI,UAAU,CAAA,CACd,KAAK,GAAG,CAAA;AACjB;AAMO,SAAS,WAAW,GAAA,EAAqB;AAC5C,EAAA,OAAO,UAAU,GAAG,CAAA,CAAE,MAAM,GAAG,CAAA,CAAE,KAAK,EAAE,CAAA;AAC5C;AAMO,SAAS,UAAU,GAAA,EAAqB;AAC3C,EAAA,IAAI,GAAA,CAAI,MAAA,KAAW,CAAA,EAAG,OAAO,GAAA;AAC7B,EAAA,MAAM,SAAA,GAAY,WAAW,GAAG,CAAA;AAChC,EAAA,OAAO,SAAA,CAAU,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,SAAA,CAAU,MAAM,CAAC,CAAA;AAChE;AAOO,SAAS,UAAU,GAAA,EAAqB;AAC3C,EAAA,OAAO,SAAA,CAAU,GAAG,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,CAAE,WAAA,EAAY;AAC3D;AAOO,SAAS,UAAU,GAAA,EAAqB;AAC3C,EAAA,OAAO,SAAA,CAAU,GAAG,CAAA,CAA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aAAA,CAAc,IAAA,CAAK,IAAI,CAAC,GAAG,QAAQ,CAAA,CAAA;AACzD","file":"rust.browser.mjs","sourcesContent":["/**\n * String-casing helpers used by code generators when emitting\n * identifiers. They normalise an arbitrary input string into a\n * conventional shape (camelCase, PascalCase, kebab-case, snake_case,\n * Title Case) by inserting word boundaries before uppercase letters and\n * splitting on any sequence of non-alphanumeric characters.\n *\n * Returned values are plain `string`. This package deliberately does\n * not depend on `@codama/node-types`, so the branded `CamelCaseString`\n * / `PascalCaseString` / … types are not applied here. Consumers that\n * want the brand (e.g. `@codama/nodes`) can wrap these helpers and\n * apply the cast at their own boundary.\n *\n * The implementations all run through {@link titleCase} as a common\n * intermediate form, so a single deterministic word-splitting policy\n * is shared across every output shape.\n */\n\n/**\n * Uppercase the first character and lowercase the rest. Returns the\n * input unchanged when it is empty.\n */\nexport function capitalize(str: string): string {\n if (str.length === 0) return str;\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();\n}\n\n/**\n * Normalise an arbitrary string into Title Case — a space-separated\n * sequence of {@link capitalize}d words. Inserts a space before each\n * uppercase letter, then splits on any run of non-alphanumeric\n * characters and re-joins with single spaces.\n */\nexport function titleCase(str: string): string {\n return str\n .replace(/([A-Z])/g, ' $1')\n .split(/[^a-zA-Z0-9]+/)\n .filter(word => word.length > 0)\n .map(capitalize)\n .join(' ');\n}\n\n/**\n * Normalise an arbitrary string into PascalCase by stripping the\n * spaces from its {@link titleCase} form.\n */\nexport function pascalCase(str: string): string {\n return titleCase(str).split(' ').join('');\n}\n\n/**\n * Normalise an arbitrary string into camelCase by lowercasing the\n * first character of its {@link pascalCase} form.\n */\nexport function camelCase(str: string): string {\n if (str.length === 0) return str;\n const pascalStr = pascalCase(str);\n return pascalStr.charAt(0).toLowerCase() + pascalStr.slice(1);\n}\n\n/**\n * Normalise an arbitrary string into kebab-case — lowercase words\n * joined with `-` — by replacing the spaces in its {@link titleCase}\n * form.\n */\nexport function kebabCase(str: string): string {\n return titleCase(str).split(' ').join('-').toLowerCase();\n}\n\n/**\n * Normalise an arbitrary string into snake_case — lowercase words\n * joined with `_` — by replacing the spaces in its {@link titleCase}\n * form.\n */\nexport function snakeCase(str: string): string {\n return titleCase(str).split(' ').join('_').toLowerCase();\n}\n","import type { BaseFragment } from './BaseFragment';\n\n/**\n * Generic template-tag implementation used by every flavor's `fragment`\n * tagged template.\n *\n * Walks the template/items pair, interpolating fragments verbatim and\n * coercing other values to strings, then defers to the caller-provided\n * `mergeFragments` for combining the surviving sub-fragments. This keeps the\n * fragment shape (imports, features, etc.) opaque to the core layer; each\n * flavor plugs in its own merge logic.\n *\n * Most consumers never call this directly — they use the `fragment` tag\n * exported by `@codama/fragments/javascript` or `@codama/fragments/rust`,\n * which both wrap this helper.\n *\n * @typeParam TFragment - The concrete fragment type. Must extend {@link BaseFragment}.\n * @param template - The template-strings array supplied by the tag call site.\n * @param items - The interpolated values, in order. May be fragments,\n * strings, numbers, booleans, `undefined`, or anything coercible to a string.\n * @param isFragment - A predicate that identifies values of the concrete\n * fragment type so they can be inlined and forwarded to the merger.\n * @param mergeFragments - The flavor-specific merger that knows how to\n * combine fragments' non-content fields (e.g. imports, features). Receives\n * only the sub-fragments found in the template, plus a callback that\n * produces the final merged content string from each sub-fragment's content.\n * @return The fragment produced by `mergeFragments`.\n *\n * @example\n * ```ts\n * import { createFragmentTemplate } from '@codama/fragments';\n *\n * function fragment(template: TemplateStringsArray, ...items: unknown[]) {\n * return createFragmentTemplate(template, items, isFragment, mergeFragments);\n * }\n * ```\n */\nexport function createFragmentTemplate<TFragment extends BaseFragment>(\n template: TemplateStringsArray,\n items: unknown[],\n isFragment: (value: unknown) => value is TFragment,\n mergeFragments: (fragments: TFragment[], mergeContent: (contents: string[]) => string) => TFragment,\n): TFragment {\n const fragments = items.filter(isFragment);\n const zippedItems = items.map((item, i) => {\n const itemPrefix = template[i];\n if (typeof item === 'undefined') return itemPrefix;\n if (isFragment(item)) return itemPrefix + item.content;\n return itemPrefix + String(item as string);\n });\n return mergeFragments(fragments, () => zippedItems.join('') + template[template.length - 1]);\n}\n","/**\n * Path manipulation helpers used by code generators to assemble output\n * file paths.\n *\n * The {@link Path} type is a thin documentation alias for `string` —\n * any place a generator stores or threads a filesystem-relative path,\n * use this name to communicate intent. The {@link joinPath} and\n * {@link pathDirectory} helpers delegate to `node:path` on Node and\n * fall back to lightweight string manipulation on non-Node platforms.\n */\n\nimport { basename, dirname, join, posix } from 'node:path';\n\nimport { CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, CodamaError } from '@codama/errors';\n\n/** A filesystem path inside the generator's output tree. */\nexport type Path = string;\n\n/**\n * Join two or more path segments together. Uses `node:path`'s\n * platform-aware {@link join} on Node; on other platforms (browser,\n * react-native) falls back to a `/`-joined form with consecutive\n * slashes collapsed.\n */\nexport function joinPath(...paths: Path[]): string {\n if (!__NODEJS__) {\n return paths.join('/').replace(/\\/+/g, '/');\n }\n\n return join(...paths);\n}\n\n/**\n * Return the directory portion of a path (i.e. everything up to the\n * last `/` segment). Uses `node:path`'s {@link dirname} on Node and a\n * plain `lastIndexOf` fallback on other platforms.\n */\nexport function pathDirectory(path: Path): Path {\n if (!__NODEJS__) {\n return path.substring(0, path.lastIndexOf('/'));\n }\n\n return dirname(path);\n}\n\n/**\n * Return the trailing segment of a path (everything after the last\n * `/`). Uses `node:path`'s {@link basename} on Node and a plain\n * `lastIndexOf` fallback on other platforms.\n */\nexport function pathBasename(path: Path): Path {\n if (!__NODEJS__) {\n const slash = path.lastIndexOf('/');\n return slash >= 0 ? path.substring(slash + 1) : path;\n }\n\n return basename(path);\n}\n\n/**\n * Compute the POSIX-style relative path from `from` to `to`. Both\n * arguments are treated as `/`-separated logical paths regardless of\n * platform, so the result is consistent across operating systems —\n * suitable for emitting into source code as an import specifier.\n *\n * Node only: non-Node platforms throw {@link CodamaError} because\n * implementing a correct POSIX relative-path algorithm without\n * `node:path` is non-trivial and no current consumer needs it.\n */\nexport function relativePath(from: Path, to: Path): string {\n if (!__NODEJS__) {\n throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: 'relative' });\n }\n\n return posix.relative(from, to);\n}\n","/**\n * Node-only filesystem helpers used by code generators to write their\n * output to disk. Each function checks the `__NODEJS__` build flag and\n * throws a structured {@link CodamaError} on non-Node platforms so\n * accidental calls from a browser bundle fail loudly rather than\n * silently no-oping.\n */\n\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\n\nimport { CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, CodamaError } from '@codama/errors';\n\nimport { Path, pathDirectory } from './path';\n\n/** Create a directory (and any missing parents) at the given path. */\nexport function createDirectory(path: Path): void {\n if (!__NODEJS__) {\n throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: 'mkdirSync' });\n }\n\n mkdirSync(path, { recursive: true });\n}\n\n/** Recursively delete the directory at the given path, if it exists. */\nexport function deleteDirectory(path: Path): void {\n if (!__NODEJS__) {\n throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: 'rmSync' });\n }\n\n if (existsSync(path)) {\n rmSync(path, { recursive: true });\n }\n}\n\n/**\n * Write `content` to a file at `path`, creating intermediate\n * directories as needed.\n */\nexport function writeFile(path: Path, content: string): void {\n if (!__NODEJS__) {\n throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: 'writeFileSync' });\n }\n\n const directory = pathDirectory(path);\n if (!existsSync(directory)) {\n createDirectory(directory);\n }\n writeFileSync(path, content);\n}\n\n/** Check whether a file or directory exists at the given path. */\nexport function fileExists(path: Path): boolean {\n if (!__NODEJS__) {\n throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: 'existsSync' });\n }\n\n return existsSync(path);\n}\n\n/** Read the file at the given path as a UTF-8 string. */\nexport function readFile(path: Path): string {\n if (!__NODEJS__) {\n throw new CodamaError(CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE, { fsFunction: 'readFileSync' });\n }\n\n return readFileSync(path, 'utf-8');\n}\n\n/**\n * Read the file at the given path as a UTF-8 string and parse it as\n * JSON. The result is typed as the caller-supplied `T`; no runtime\n * validation is performed.\n */\nexport function readJson<T>(path: Path): T {\n return JSON.parse(readFile(path)) as T;\n}\n","import type { BaseFragment } from './BaseFragment';\n\n/**\n * Return a new frozen fragment whose `content` field has been replaced with\n * `content`, preserving every other field of the input fragment.\n *\n * The output keeps the input's exact concrete type (`TFragment`) so callers\n * never lose any extra fields a flavored fragment may carry (imports,\n * features, etc.).\n *\n * @typeParam TFragment - The concrete fragment type. Must extend {@link BaseFragment}.\n * @param fragment - The source fragment to copy.\n * @param content - The new code string.\n * @return A frozen fragment of the same shape as `fragment` with `content` replaced.\n *\n * @example\n * ```ts\n * import { setFragmentContent } from '@codama/fragments';\n *\n * const next = setFragmentContent(prev, prev.content.toUpperCase());\n * ```\n */\nexport function setFragmentContent<TFragment extends BaseFragment>(fragment: TFragment, content: string): TFragment {\n return Object.freeze({ ...fragment, content });\n}\n","import type { BaseFragment } from './BaseFragment';\nimport { setFragmentContent } from './setFragmentContent';\n\n/**\n * Apply a synchronous transformation to a fragment's `content`, returning a\n * new fragment with every other field preserved.\n *\n * @typeParam TFragment - The concrete fragment type. Must extend {@link BaseFragment}.\n * @param fragment - The source fragment.\n * @param mapContent - A function that receives the current content and\n * returns the new content.\n * @return A frozen fragment with the transformed content.\n *\n * @example\n * ```ts\n * import { mapFragmentContent } from '@codama/fragments';\n *\n * const trimmed = mapFragmentContent(fragment, c => c.trimEnd());\n * ```\n *\n * @see {@link mapFragmentContentAsync} for the async variant.\n */\nexport function mapFragmentContent<TFragment extends BaseFragment>(\n fragment: TFragment,\n mapContent: (content: string) => string,\n): TFragment {\n return setFragmentContent(fragment, mapContent(fragment.content));\n}\n\n/**\n * Async variant of {@link mapFragmentContent}: apply an async transformation\n * to a fragment's `content`.\n *\n * @typeParam TFragment - The concrete fragment type. Must extend {@link BaseFragment}.\n * @param fragment - The source fragment.\n * @param mapContent - An async function that receives the current content\n * and returns a promise resolving to the new content.\n * @return A promise that resolves to a frozen fragment with the transformed\n * content.\n *\n * @example\n * ```ts\n * import { mapFragmentContentAsync } from '@codama/fragments';\n *\n * const formatted = await mapFragmentContentAsync(fragment, formatWithPrettier);\n * ```\n *\n * @see {@link mapFragmentContent} for the sync variant.\n */\nexport async function mapFragmentContentAsync<TFragment extends BaseFragment>(\n fragment: TFragment,\n mapContent: (content: string) => Promise<string>,\n): Promise<TFragment> {\n return setFragmentContent(fragment, await mapContent(fragment.content));\n}\n","/**\n * A `RenderMap` is the in-memory data structure a code generator builds\n * up before writing anything to disk: a frozen `ReadonlyMap` keyed by\n * output path, with a `BaseFragment` (or a concrete subtype carrying\n * imports / features / …) as the value. The helpers in this module are\n * pure data operations — they construct, merge, transform, and query\n * render maps without touching the filesystem.\n *\n * {@link writeRenderMap} is the single filesystem-touching entry point\n * here: it walks a finished map and writes every entry. Renderers that\n * tie a render map to a `Visitor` (see `@codama/renderers-core`) layer\n * that on top.\n */\n\nimport { CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND, CodamaError } from '@codama/errors';\n\nimport type { BaseFragment } from './BaseFragment';\nimport { writeFile } from './fs';\nimport { mapFragmentContent, mapFragmentContentAsync } from './mapFragmentContent';\nimport { joinPath, type Path } from './path';\n\n/**\n * A frozen map keyed by output {@link Path}, with each entry holding a\n * fragment that will be written to that path. `TFragment` defaults to\n * {@link BaseFragment} but generators typically pass a richer flavor\n * (e.g. `Fragment` from `@codama/fragments/javascript`) to carry\n * imports and other per-file metadata.\n */\nexport type RenderMap<TFragment extends BaseFragment> = ReadonlyMap<Path, TFragment>;\n\nexport function createRenderMap<TFragment extends BaseFragment = BaseFragment>(): RenderMap<TFragment>;\nexport function createRenderMap<TFragment extends BaseFragment>(path: Path, content: TFragment): RenderMap<TFragment>;\nexport function createRenderMap<TFragment extends BaseFragment>(\n entries: Record<Path, TFragment | undefined>,\n): RenderMap<TFragment>;\nexport function createRenderMap<TFragment extends BaseFragment>(\n pathOrEntries?: Path | Record<Path, TFragment | undefined>,\n content?: TFragment,\n): RenderMap<TFragment> {\n let entries: [Path, TFragment][] = [];\n if (typeof pathOrEntries === 'string' && content !== undefined) {\n entries = [[pathOrEntries, content]];\n } else if (typeof pathOrEntries === 'object' && pathOrEntries !== null) {\n entries = Object.entries(pathOrEntries).flatMap(([key, value]) =>\n value === undefined ? [] : ([[key, value]] as const),\n );\n }\n return Object.freeze(new Map(entries));\n}\n\n/** Add or overwrite a single `(path, fragment)` entry. */\nexport function addToRenderMap<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n path: Path,\n content: TFragment,\n): RenderMap<TFragment> {\n return mergeRenderMaps([renderMap, createRenderMap(path, content)]);\n}\n\n/** Remove the entry at `path`, returning a new frozen map. */\nexport function removeFromRenderMap<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n path: Path,\n): RenderMap<TFragment> {\n const newMap = new Map(renderMap);\n newMap.delete(path);\n return Object.freeze(newMap);\n}\n\n/**\n * Combine multiple render maps into one. Later maps overwrite earlier\n * entries at the same path.\n */\nexport function mergeRenderMaps<TFragment extends BaseFragment>(\n renderMaps: RenderMap<TFragment>[],\n): RenderMap<TFragment> {\n if (renderMaps.length === 0) return createRenderMap();\n if (renderMaps.length === 1) return renderMaps[0];\n const merged = new Map(renderMaps[0]);\n for (const map of renderMaps.slice(1)) {\n for (const [key, value] of map) {\n merged.set(key, value);\n }\n }\n return Object.freeze(merged);\n}\n\n/** Transform every fragment in the map, preserving the keys. */\nexport function mapRenderMapFragment<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n fn: (fragment: TFragment, path: Path) => TFragment,\n): RenderMap<TFragment> {\n return Object.freeze(new Map([...[...renderMap.entries()].map(([key, value]) => [key, fn(value, key)] as const)]));\n}\n\n/** Async variant of {@link mapRenderMapFragment}. */\nexport async function mapRenderMapFragmentAsync<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n fn: (fragment: TFragment, path: Path) => Promise<TFragment>,\n): Promise<RenderMap<TFragment>> {\n return Object.freeze(\n new Map(\n await Promise.all([\n ...[...renderMap.entries()].map(async ([key, value]) => [key, await fn(value, key)] as const),\n ]),\n ),\n );\n}\n\n/** Transform the `content` of every fragment in the map. */\nexport function mapRenderMapContent<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n fn: (content: string, path: Path) => string,\n): RenderMap<TFragment> {\n return mapRenderMapFragment(renderMap, (fragment, path) =>\n mapFragmentContent(fragment, content => fn(content, path)),\n );\n}\n\n/** Async variant of {@link mapRenderMapContent}. */\nexport async function mapRenderMapContentAsync<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n fn: (content: string, path: Path) => Promise<string>,\n): Promise<RenderMap<TFragment>> {\n return await mapRenderMapFragmentAsync(renderMap, (fragment, path) =>\n mapFragmentContentAsync(fragment, content => fn(content, path)),\n );\n}\n\n/**\n * Look up the fragment at `path`, throwing a structured\n * {@link CodamaError} when the key is missing.\n */\nexport function getFromRenderMap<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n path: Path,\n): TFragment {\n const value = renderMap.get(path);\n if (value === undefined) {\n throw new CodamaError(CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND, { key: path });\n }\n return value;\n}\n\n/**\n * Test whether the fragment at `path` contains `value`. Accepts either\n * a plain substring or a regular expression.\n */\nexport function renderMapContains<TFragment extends BaseFragment>(\n renderMap: RenderMap<TFragment>,\n path: Path,\n value: RegExp | string,\n): boolean {\n const { content } = getFromRenderMap(renderMap, path);\n return typeof value === 'string' ? content.includes(value) : value.test(content);\n}\n\n/**\n * Walk the render map and write every entry to disk, rooted at\n * `basePath`. Each path is joined with `basePath` via {@link joinPath}\n * and written via {@link writeFile}; the directory structure is\n * created on demand.\n */\nexport function writeRenderMap<TFragment extends BaseFragment>(renderMap: RenderMap<TFragment>, basePath: Path): void {\n renderMap.forEach(({ content }, relativePath) => {\n writeFile(joinPath(basePath, relativePath), content);\n });\n}\n","/**\n * Rust crate keywords that should never be reported as external dependencies.\n *\n * {@link getExternalDependencies} filters these out when computing the\n * package's Cargo dependencies from the imports actually used. They\n * correspond to paths that resolve inside the crate or to the standard\n * library.\n */\nexport const RUST_CORE_IMPORTS: ReadonlySet<string> = new Set([\n 'alloc',\n 'clippy',\n 'core',\n 'crate',\n 'self',\n 'std',\n 'super',\n]);\n\n/**\n * The fully-qualified Rust path of an imported item — e.g.\n * `'solana_program::pubkey::Pubkey'` or `'crate::generated::accounts::AccountNode'`.\n *\n * Symbolic prefixes (e.g. `'generated::accounts::Foo'`) are accepted too;\n * they are resolved into concrete paths by {@link resolveImportMap} just\n * before stringification.\n */\nexport type ImportPath = string;\n\n/** The local name an imported path is bound to (the right-hand side of `as`). */\nexport type Alias = string;\n\n/** A parsed Rust import. */\nexport interface ImportInfo {\n readonly alias?: Alias;\n readonly importedPath: ImportPath;\n}\n\n/**\n * The data model used by `@codama/fragments/rust` to track imports\n * symbolically until they are stringified into actual `use foo::Bar;` lines.\n *\n * Unlike the JavaScript flavor, Rust's `use` statement always references a\n * single fully-qualified path. There is no per-module identifier list, so\n * the map is flat: keyed by the imported path, with optional alias info as\n * the value.\n *\n * The map is frozen and its operations are pure functions (no methods, no\n * mutation), matching the JavaScript subpath's paradigm.\n */\nexport type ImportMap = ReadonlyMap<ImportPath, ImportInfo>;\n\n/**\n * Construct an empty, frozen import map.\n *\n * @return A new {@link ImportMap} with no entries.\n *\n * @example\n * ```ts\n * import { createImportMap } from '@codama/fragments/rust';\n *\n * const empty = createImportMap();\n * ```\n */\nexport function createImportMap(): ImportMap {\n return Object.freeze(new Map<ImportPath, ImportInfo>());\n}\n","import type { ImportMap } from './ImportMap';\nimport { createImportMap } from './ImportMap';\n\n/**\n * Merge multiple import maps into one. Paths from later maps are layered\n * over earlier ones; if the same path appears in multiple maps, the\n * latest occurrence's alias info wins.\n *\n * The merge is a pure function: input maps are not mutated. The returned\n * map is frozen.\n *\n * @param importMaps - The import maps to merge, in priority order.\n * @return A frozen import map containing every entry from every input.\n *\n * @example\n * ```ts\n * import { addToImportMap, createImportMap, mergeImportMaps } from '@codama/fragments/rust';\n *\n * const a = addToImportMap(createImportMap(), ['borsh::BorshDeserialize']);\n * const b = addToImportMap(createImportMap(), ['solana_program::pubkey::Pubkey']);\n * const merged = mergeImportMaps([a, b]);\n * ```\n */\nexport function mergeImportMaps(importMaps: readonly ImportMap[]): ImportMap {\n if (importMaps.length === 0) return createImportMap();\n if (importMaps.length === 1) return importMaps[0];\n const merged = new Map(importMaps[0]);\n for (const map of importMaps.slice(1)) {\n for (const [path, info] of map) {\n merged.set(path, info);\n }\n }\n return Object.freeze(merged);\n}\n","import type { ImportMap, ImportPath } from './ImportMap';\nimport { mergeImportMaps } from './mergeImportMaps';\n\n/**\n * Append imports to an import map, returning a new frozen map. The input\n * map is not mutated.\n *\n * Aliases are not added by this function — call\n * {@link addAliasToImportMap} separately when the import needs an `as`\n * clause.\n *\n * @param importMap - The import map to extend.\n * @param paths - The Rust paths to add. May be a single string, an array,\n * or a {@link Set}. An empty array short-circuits and returns `importMap`\n * unchanged.\n * @return A frozen import map that includes the new entries.\n *\n * @example\n * ```ts\n * import { addToImportMap, createImportMap } from '@codama/fragments/rust';\n *\n * const map = addToImportMap(createImportMap(), [\n * 'borsh::BorshDeserialize',\n * 'borsh::BorshSerialize',\n * ]);\n * ```\n */\nexport function addToImportMap(\n importMap: ImportMap,\n paths: ReadonlySet<string> | string | readonly string[],\n): ImportMap {\n const inputs = typeof paths === 'string' ? [paths] : [...paths];\n if (inputs.length === 0) return importMap;\n const additions = new Map<ImportPath, { importedPath: ImportPath }>();\n for (const path of inputs) {\n if (!additions.has(path) && !importMap.has(path)) {\n additions.set(path, Object.freeze({ importedPath: path }));\n }\n }\n if (additions.size === 0) return importMap;\n return mergeImportMaps([importMap, additions]);\n}\n","import type { Alias, ImportMap, ImportPath } from './ImportMap';\n\n/**\n * Record an alias (`use foo::Bar as Baz;`) for an imported path. If the\n * path isn't yet in the map, it is added; if it's already present, the\n * alias is set or replaced. The input map is not mutated.\n *\n * @param importMap - The import map to extend.\n * @param path - The full Rust path being aliased (e.g. `'foo::Bar'`).\n * @param alias - The local name to use (e.g. `'Baz'`).\n * @return A new frozen import map with the alias recorded.\n *\n * @example\n * ```ts\n * import { addAliasToImportMap, createImportMap } from '@codama/fragments/rust';\n *\n * const map = addAliasToImportMap(\n * createImportMap(),\n * 'solana_program::program_error::ProgramError',\n * 'ProgError',\n * );\n * ```\n */\nexport function addAliasToImportMap(importMap: ImportMap, path: ImportPath, alias: Alias): ImportMap {\n const next = new Map(importMap);\n next.set(path, Object.freeze({ alias, importedPath: path }));\n return Object.freeze(next);\n}\n","import type { ImportMap, ImportPath } from './ImportMap';\n\n/**\n * Drop one or more imported paths from an import map. Paths that aren't\n * present are silently ignored. The input map is not mutated.\n *\n * @param importMap - The import map to trim.\n * @param paths - The Rust paths to remove. May be a single string, an\n * array, or a {@link Set}.\n * @return A new frozen import map without those entries.\n *\n * @example\n * ```ts\n * import { addToImportMap, createImportMap, removeFromImportMap } from '@codama/fragments/rust';\n *\n * let map = addToImportMap(createImportMap(), ['foo::A', 'foo::B']);\n * map = removeFromImportMap(map, 'foo::A');\n * ```\n */\nexport function removeFromImportMap(\n importMap: ImportMap,\n paths: ImportPath | ReadonlySet<string> | readonly ImportPath[],\n): ImportMap {\n const targets = typeof paths === 'string' ? [paths] : [...paths];\n if (targets.length === 0) return importMap;\n const next = new Map(importMap);\n for (const path of targets) next.delete(path);\n return Object.freeze(next);\n}\n","import type { ImportMap, ImportPath } from './ImportMap';\n\n/**\n * Rewrite the symbolic prefixes of an import map's paths against a\n * dependency map.\n *\n * Resolution is by prefix match on the `::` separator: an import\n * `'generated::accounts::AccountNode'` against\n * `{ generated: 'crate::generated' }` becomes\n * `'crate::generated::accounts::AccountNode'`. Paths that don't match any\n * prefix are kept unchanged. Aliases follow their path.\n *\n * Renderers typically pre-define a base set of symbolic modules\n * (`generated → crate::generated`, `mplToolbox → mpl_toolbox`, etc.) and\n * pass them through this function just before calling\n * {@link importMapToString} or {@link getExternalDependencies}.\n *\n * @param importMap - The import map to resolve.\n * @param dependencies - A record mapping symbolic prefixes to resolved\n * Rust paths.\n * @return A new frozen import map with all paths resolved.\n *\n * @example\n * ```ts\n * import { addToImportMap, createImportMap, resolveImportMap } from '@codama/fragments/rust';\n *\n * const map = addToImportMap(createImportMap(), 'generated::accounts::AccountNode');\n * const resolved = resolveImportMap(map, { generated: 'crate::generated' });\n * // resolved has 'crate::generated::accounts::AccountNode'\n * ```\n */\nexport function resolveImportMap(importMap: ImportMap, dependencies: Record<string, string>): ImportMap {\n const prefixes = Object.keys(dependencies);\n if (prefixes.length === 0 || importMap.size === 0) return importMap;\n const next = new Map(importMap);\n let mutated = false;\n for (const [path, info] of importMap) {\n const resolvedPath = resolvePath(path, dependencies, prefixes);\n if (resolvedPath === path) continue;\n next.delete(path);\n next.set(resolvedPath, Object.freeze({ ...info, importedPath: resolvedPath }));\n mutated = true;\n }\n return mutated ? Object.freeze(next) : importMap;\n}\n\nfunction resolvePath(path: ImportPath, dependencies: Record<string, string>, prefixes: readonly string[]): ImportPath {\n for (const prefix of prefixes) {\n if (path.startsWith(`${prefix}::`)) {\n return dependencies[prefix] + path.slice(prefix.length);\n }\n }\n return path;\n}\n","import type { ImportMap } from './ImportMap';\nimport { RUST_CORE_IMPORTS } from './ImportMap';\nimport { resolveImportMap } from './resolveImportMap';\n\n/**\n * Compute the top-level crate names actually imported, with\n * {@link RUST_CORE_IMPORTS} excluded. Useful for syncing a renderer's\n * generated `Cargo.toml` from the imports it ends up emitting.\n *\n * Imports are first resolved against the dependency map (so symbolic\n * prefixes like `'generated::…'` are expanded before crate names are\n * extracted), then the leading `::` segment of each path is collected.\n *\n * @param importMap - The import map to inspect.\n * @param dependencies - The dependency map to apply before extracting\n * crate names. Defaults to no resolution.\n * @return A {@link Set} of external crate names.\n *\n * @example\n * ```ts\n * import { addToImportMap, createImportMap, getExternalDependencies } from '@codama/fragments/rust';\n *\n * const map = addToImportMap(createImportMap(), [\n * 'borsh::BorshSerialize',\n * 'std::collections::HashMap',\n * 'generated::accounts::A',\n * ]);\n * getExternalDependencies(map, { generated: 'crate::generated' });\n * // → Set { 'borsh' }\n * ```\n */\nexport function getExternalDependencies(importMap: ImportMap, dependencies: Record<string, string> = {}): Set<string> {\n const resolved = resolveImportMap(importMap, dependencies);\n const crates = new Set<string>();\n for (const path of resolved.keys()) {\n const root = path.split('::')[0];\n if (!RUST_CORE_IMPORTS.has(root)) crates.add(root);\n }\n return crates;\n}\n","import type { ImportMap } from './ImportMap';\nimport { resolveImportMap } from './resolveImportMap';\n\n/**\n * Render an import map as a block of `use foo::Bar;` (and `use foo::Bar as Baz;`)\n * statements.\n *\n * The map is first resolved against `dependencies` so symbolic prefixes\n * like `'generated::…'` expand to concrete crate paths. The output is\n * sorted alphabetically by path for stable, reviewable diffs.\n *\n * @param importMap - The import map to render.\n * @param dependencies - The dependency map to apply before rendering.\n * Defaults to no resolution.\n * @return The block of `use` statements joined by newlines, or the empty\n * string if the map is empty.\n *\n * @example\n * ```ts\n * import { addAliasToImportMap, addToImportMap, createImportMap, importMapToString } from '@codama/fragments/rust';\n *\n * let map = createImportMap();\n * map = addToImportMap(map, ['borsh::BorshSerialize', 'solana_program::pubkey::Pubkey']);\n * map = addAliasToImportMap(map, 'solana_program::program_error::ProgramError', 'ProgError');\n * importMapToString(map);\n * // use borsh::BorshSerialize;\n * // use solana_program::program_error::ProgramError as ProgError;\n * // use solana_program::pubkey::Pubkey;\n * ```\n */\nexport function importMapToString(importMap: ImportMap, dependencies: Record<string, string> = {}): string {\n const resolved = resolveImportMap(importMap, dependencies);\n return [...resolved.values()]\n .map(info => (info.alias ? `use ${info.importedPath} as ${info.alias};` : `use ${info.importedPath};`))\n .sort((a, b) => a.localeCompare(b))\n .join('\\n');\n}\n","import type { BaseFragment } from '../core/BaseFragment';\nimport { createFragmentTemplate } from '../core/createFragmentTemplate';\nimport { addAliasToImportMap } from './addAliasToImportMap';\nimport { addToImportMap } from './addToImportMap';\nimport type { Alias, ImportMap, ImportPath } from './ImportMap';\nimport { mergeImportMaps } from './mergeImportMaps';\nimport { removeFromImportMap } from './removeFromImportMap';\n\n/**\n * The Rust-flavored fragment shape: {@link BaseFragment} plus a frozen\n * {@link ImportMap} carrying the `use` paths the content depends on.\n *\n * Both the fragment and its import map are immutable. Every operation in\n * this subpath that returns a fragment produces a new frozen wrapper, so\n * fragments compose without aliasing risks.\n */\nexport type Fragment = BaseFragment & Readonly<{ imports: ImportMap }>;\n\n/**\n * Type guard for the Rust-flavored {@link Fragment} shape.\n *\n * @param value - The value to test.\n * @return `true` when `value` is an object carrying both `content` and\n * `imports` fields.\n */\nexport function isFragment(value: unknown): value is Fragment {\n return typeof value === 'object' && value !== null && 'content' in value && 'imports' in value;\n}\n\n/**\n * Tagged-template helper for composing Rust-flavored fragments.\n * Interpolated values may be:\n *\n * - A {@link Fragment} — content is inlined and imports propagate.\n * - `undefined` — rendered as the empty string.\n * - Anything else — coerced to a string via `String(value)`.\n *\n * Rust does not have a `use(input, module)` shorthand because identifiers\n * can be referenced inline by their full `::`-qualified path; build\n * content with the tag and attach imports separately via\n * {@link addFragmentImports}.\n *\n * @param template - The template-strings array supplied by the tag call site.\n * @param items - The interpolated values, in order.\n * @return A frozen {@link Fragment} with merged content and imports.\n *\n * @example\n * ```ts\n * import { addFragmentImports, fragment } from '@codama/fragments/rust';\n *\n * const body = fragment`pub struct AccountNode { pubkey: Pubkey }`;\n * const withImports = addFragmentImports(body, ['solana_program::pubkey::Pubkey']);\n * ```\n */\nexport function fragment(template: TemplateStringsArray, ...items: unknown[]): Fragment {\n return createFragmentTemplate(template, items, isFragment, mergeFragments);\n}\n\n/**\n * Combine multiple fragments into one. The merge strategy for content is\n * supplied by the caller (`mergeContent`); imports are merged\n * automatically via {@link mergeImportMaps}. Undefined inputs are skipped.\n *\n * @param fragments - The fragments to merge, in order.\n * @param mergeContent - A function that produces the final content string\n * from each surviving fragment's content.\n * @return A frozen merged {@link Fragment}.\n */\nexport function mergeFragments(\n fragments: readonly (Fragment | undefined)[],\n mergeContent: (contents: string[]) => string,\n): Fragment {\n const filtered = fragments.filter((f): f is Fragment => f !== undefined);\n return Object.freeze({\n content: mergeContent(filtered.map(f => f.content)),\n imports: mergeImportMaps(filtered.map(f => f.imports)),\n });\n}\n\n/**\n * Append imports to an existing fragment's import map. The fragment's\n * content and any other fields are preserved.\n *\n * @param fragment - The source fragment.\n * @param paths - The Rust paths to add. May be a single string, an array,\n * or a {@link Set}.\n * @return A new frozen fragment with the extended import map.\n *\n * @example\n * ```ts\n * import { addFragmentImports, fragment } from '@codama/fragments/rust';\n *\n * const f = addFragmentImports(fragment`Pubkey`, ['solana_program::pubkey::Pubkey']);\n * ```\n */\nexport function addFragmentImports(\n fragment: Fragment,\n paths: ImportPath | ReadonlySet<string> | readonly ImportPath[],\n): Fragment {\n return Object.freeze({\n ...fragment,\n imports: addToImportMap(fragment.imports, paths),\n });\n}\n\n/**\n * Record an alias for an imported path on the fragment's import map. If\n * the path isn't yet imported, it is added; if it's already present, the\n * alias replaces any existing one. The fragment's content and any other\n * fields are preserved.\n *\n * @param fragment - The source fragment.\n * @param path - The full Rust path being aliased.\n * @param alias - The local name to use.\n * @return A new frozen fragment with the alias recorded.\n *\n * @example\n * ```ts\n * import { addFragmentImportAlias, fragment } from '@codama/fragments/rust';\n *\n * const f = addFragmentImportAlias(\n * fragment`ProgError::InvalidArgument`,\n * 'solana_program::program_error::ProgramError',\n * 'ProgError',\n * );\n * ```\n */\nexport function addFragmentImportAlias(fragment: Fragment, path: ImportPath, alias: Alias): Fragment {\n return Object.freeze({\n ...fragment,\n imports: addAliasToImportMap(fragment.imports, path, alias),\n });\n}\n\n/**\n * Merge additional import maps into an existing fragment's import map.\n * The fragment's content and any other fields are preserved.\n *\n * @param fragment - The source fragment.\n * @param importMaps - The maps to merge in.\n * @return A new frozen fragment with the merged import map.\n */\nexport function mergeFragmentImports(fragment: Fragment, importMaps: readonly ImportMap[]): Fragment {\n return Object.freeze({\n ...fragment,\n imports: mergeImportMaps([fragment.imports, ...importMaps]),\n });\n}\n\n/**\n * Drop paths from a fragment's import map. The fragment's content and any\n * other fields are preserved.\n *\n * @param fragment - The source fragment.\n * @param paths - The Rust paths to remove. May be a single string, an\n * array, or a {@link Set}.\n * @return A new frozen fragment with the trimmed import map.\n */\nexport function removeFragmentImports(\n fragment: Fragment,\n paths: ImportPath | ReadonlySet<string> | readonly ImportPath[],\n): Fragment {\n return Object.freeze({\n ...fragment,\n imports: removeFromImportMap(fragment.imports, paths),\n });\n}\n","import type { Fragment } from './fragment';\nimport { fragment } from './fragment';\n\n/**\n * Build a Rust doc-comment fragment from an array of lines.\n *\n * Empty or `undefined` input returns `undefined` so the helper composes\n * naturally with the {@link fragment} tag's optional-interpolation\n * behavior — a node's `docs` attribute can be threaded straight in\n * without a ternary guard:\n *\n * ```ts\n * fragment`${getDocblockFragment(node.docs)}\\npub struct X;`;\n * ```\n *\n * Each line is prefixed with `///` (outer doc) by default, or `//!`\n * (inner doc) when `internal` is `true`. Empty elements in the array\n * render as a bare prefix line (`///` or `//!` with no trailing space),\n * useful for paragraph breaks inside a doc comment.\n *\n * @param lines - The lines of the doc comment, or `undefined`. Empty\n * array and `undefined` both return `undefined`.\n * @param options - Optional settings.\n * @param options.internal - When `true`, emit inner doc comments (`//!`)\n * instead of outer doc comments (`///`). Useful for module- or crate-level\n * documentation.\n * @param options.withLineJump - When `true`, appends a trailing `\\n` after\n * the last line.\n * @return A {@link Fragment} carrying the rendered doc comment, or\n * `undefined` when `lines` is empty or `undefined`.\n *\n * @example\n * ```ts\n * import { getDocblockFragment } from '@codama/fragments/rust';\n *\n * getDocblockFragment(['Greets the user.'])?.content;\n * // /// Greets the user.\n *\n * getDocblockFragment(['First line.', '', 'Second paragraph.'])?.content;\n * // /// First line.\n * // ///\n * // /// Second paragraph.\n *\n * getDocblockFragment(['Module docs.'], { internal: true })?.content;\n * // //! Module docs.\n *\n * getDocblockFragment(undefined);\n * // undefined\n * ```\n */\nexport function getDocblockFragment(\n lines: readonly string[] | undefined,\n options: { internal?: boolean; withLineJump?: boolean } = {},\n): Fragment | undefined {\n if (!lines || lines.length === 0) return undefined;\n const prefix = options.internal ? '//!' : '///';\n const lineJump = options.withLineJump ? '\\n' : '';\n const prefixedLines = lines.map(line => (line ? `${prefix} ${line}` : prefix));\n return fragment`${prefixedLines.join('\\n')}${lineJump}`;\n}\n"]}