@macalinao/codama-rename-visitor 0.1.0 → 0.2.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.
- package/README.md +24 -1
- package/dist/index.d.ts +5 -97
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -220
- package/dist/index.js.map +1 -1
- package/dist/rename-accounts-visitor.d.ts +26 -0
- package/dist/rename-accounts-visitor.d.ts.map +1 -0
- package/dist/rename-accounts-visitor.js +43 -0
- package/dist/rename-accounts-visitor.js.map +1 -0
- package/dist/rename-defined-types-visitor.d.ts +27 -0
- package/dist/rename-defined-types-visitor.d.ts.map +1 -0
- package/dist/rename-defined-types-visitor.js +46 -0
- package/dist/rename-defined-types-visitor.js.map +1 -0
- package/dist/rename-instructions-visitor.d.ts +26 -0
- package/dist/rename-instructions-visitor.d.ts.map +1 -0
- package/dist/rename-instructions-visitor.js +43 -0
- package/dist/rename-instructions-visitor.js.map +1 -0
- package/dist/rename-visitor.d.ts +35 -0
- package/dist/rename-visitor.d.ts.map +1 -0
- package/dist/rename-visitor.js +75 -0
- package/dist/rename-visitor.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +7 -5
- package/src/index.ts +14 -291
- package/src/rename-accounts-visitor.ts +50 -0
- package/src/rename-defined-types-visitor.test.ts +44 -0
- package/src/rename-defined-types-visitor.ts +59 -0
- package/src/rename-instructions-visitor.test.ts +83 -0
- package/src/rename-instructions-visitor.ts +50 -0
- package/src/rename-visitor.test.ts +175 -0
- package/src/rename-visitor.ts +94 -0
- package/src/types.ts +11 -0
- package/src/index.test.ts +0 -409
package/README.md
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
# @macalinao/codama-rename-visitor
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@macalinao/codama-rename-visitor)
|
|
4
|
+
[](https://www.npmjs.com/package/@macalinao/codama-rename-visitor)
|
|
5
|
+
|
|
3
6
|
A Codama visitor for renaming instructions and events within a Solana program.
|
|
4
7
|
|
|
8
|
+
## Quick Start with Coda CLI
|
|
9
|
+
|
|
10
|
+
This visitor works seamlessly with the [Coda CLI](https://coda.ianm.com) for automated client generation:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Install Coda CLI
|
|
14
|
+
bun add -D @macalinao/coda
|
|
15
|
+
|
|
16
|
+
# Initialize configuration
|
|
17
|
+
coda init
|
|
18
|
+
|
|
19
|
+
# Add this visitor to your coda.config.mjs
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Coda provides zero-config client generation with powerful customization through visitors like this one. Learn more at [coda.ianm.com](https://coda.ianm.com).
|
|
23
|
+
|
|
5
24
|
## Installation
|
|
6
25
|
|
|
26
|
+
For direct usage:
|
|
27
|
+
|
|
7
28
|
```bash
|
|
8
29
|
npm install @macalinao/codama-rename-visitor
|
|
9
30
|
```
|
|
@@ -118,4 +139,6 @@ Creates a visitor that renames events (defined types) based on the provided mapp
|
|
|
118
139
|
|
|
119
140
|
## License
|
|
120
141
|
|
|
121
|
-
|
|
142
|
+
Copyright © 2025 Ian Macalinao
|
|
143
|
+
|
|
144
|
+
Licensed under the Apache License, Version 2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -1,98 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
/** Mapping of old instruction names to new instruction names */
|
|
7
|
-
instructions?: Record<string, string>;
|
|
8
|
-
/** Mapping of old event names (as defined types) to new event names */
|
|
9
|
-
events?: Record<string, string>;
|
|
10
|
-
/** Mapping of old defined type names to new defined type names */
|
|
11
|
-
definedTypes?: Record<string, string>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Options for the rename visitor (legacy interface)
|
|
15
|
-
*/
|
|
16
|
-
export type RenameVisitorOptions = ProgramRenameOptions;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a visitor that renames instructions in a Codama IDL.
|
|
19
|
-
*
|
|
20
|
-
* @param mapping - Object mapping old instruction names to new instruction names
|
|
21
|
-
* @returns A root node visitor that renames instructions
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const visitor = renameInstructionsVisitor({
|
|
26
|
-
* "transfer": "transferTokens",
|
|
27
|
-
* "mint": "mintNft"
|
|
28
|
-
* });
|
|
29
|
-
* codama.update(visitor);
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function renameInstructionsVisitor(mapping: Record<string, string>): ReturnType<typeof rootNodeVisitor>;
|
|
33
|
-
/**
|
|
34
|
-
* Creates a visitor that renames events (as defined types) in a Codama IDL.
|
|
35
|
-
*
|
|
36
|
-
* Events in Anchor IDLs are typically converted to defined types in Codama,
|
|
37
|
-
* so this visitor renames specific defined types that represent events.
|
|
38
|
-
*
|
|
39
|
-
* @param mapping - Object mapping old event names to new event names
|
|
40
|
-
* @param eventSuffix - Optional suffix to identify event types (default: "Event")
|
|
41
|
-
* @returns A root node visitor that renames events
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const visitor = renameEventsVisitor({
|
|
46
|
-
* "tokenMinted": "nftMinted",
|
|
47
|
-
* "transferComplete": "transferFinished"
|
|
48
|
-
* });
|
|
49
|
-
* codama.update(visitor);
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export declare function renameEventsVisitor(mapping: Record<string, string>, eventSuffix?: string): ReturnType<typeof rootNodeVisitor>;
|
|
53
|
-
/**
|
|
54
|
-
* Creates a visitor that renames defined types in a Codama IDL.
|
|
55
|
-
*
|
|
56
|
-
* @param mapping - Object mapping old defined type names to new defined type names
|
|
57
|
-
* @returns A root node visitor that renames defined types
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const visitor = renameDefinedTypesVisitor({
|
|
62
|
-
* "counter": "counterAccount",
|
|
63
|
-
* "config": "programConfig"
|
|
64
|
-
* });
|
|
65
|
-
* codama.update(visitor);
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
export declare function renameDefinedTypesVisitor(mapping: Record<string, string>): ReturnType<typeof rootNodeVisitor>;
|
|
69
|
-
/**
|
|
70
|
-
* Creates a visitor that renames instructions, events, and defined types in specific programs.
|
|
71
|
-
* This follows the same pattern as addPdasVisitor from Codama.
|
|
72
|
-
*
|
|
73
|
-
* @param renamesByProgram - Object mapping program names to their rename configurations
|
|
74
|
-
* @returns A root node visitor that performs all specified renames
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* const visitor = renameVisitor({
|
|
79
|
-
* quarryMine: {
|
|
80
|
-
* instructions: {
|
|
81
|
-
* claimRewards: "claimRewardsMine"
|
|
82
|
-
* }
|
|
83
|
-
* },
|
|
84
|
-
* token: {
|
|
85
|
-
* instructions: {
|
|
86
|
-
* transfer: "transferTokens",
|
|
87
|
-
* mint: "mintNft"
|
|
88
|
-
* },
|
|
89
|
-
* events: {
|
|
90
|
-
* tokenMinted: "nftMinted"
|
|
91
|
-
* }
|
|
92
|
-
* }
|
|
93
|
-
* });
|
|
94
|
-
* codama.update(visitor);
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
export declare function renameVisitor(renamesByProgram: Record<string, ProgramRenameOptions>): ReturnType<typeof rootNodeVisitor>;
|
|
1
|
+
export { renameAccountsVisitor, renameAccountTransform, } from "./rename-accounts-visitor.js";
|
|
2
|
+
export { renameDefinedTypesVisitor, renameDefinedTypeTransform, } from "./rename-defined-types-visitor.js";
|
|
3
|
+
export { renameInstructionsVisitor, renameInstructionTransform, } from "./rename-instructions-visitor.js";
|
|
4
|
+
export { renameVisitor } from "./rename-visitor.js";
|
|
5
|
+
export type { ProgramRenameOptions } from "./types.js";
|
|
98
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,221 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @param mapping - Object mapping old instruction names to new instruction names
|
|
6
|
-
* @returns A root node visitor that renames instructions
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const visitor = renameInstructionsVisitor({
|
|
11
|
-
* "transfer": "transferTokens",
|
|
12
|
-
* "mint": "mintNft"
|
|
13
|
-
* });
|
|
14
|
-
* codama.update(visitor);
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export function renameInstructionsVisitor(mapping) {
|
|
18
|
-
return rootNodeVisitor((root) => {
|
|
19
|
-
const instructionVisitor = bottomUpTransformerVisitor([
|
|
20
|
-
{
|
|
21
|
-
select: "[instructionNode]",
|
|
22
|
-
transform: (node) => {
|
|
23
|
-
assertIsNode(node, "instructionNode");
|
|
24
|
-
const newName = mapping[node.name];
|
|
25
|
-
if (!newName) {
|
|
26
|
-
return node;
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
...node,
|
|
30
|
-
name: camelCase(newName),
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
]);
|
|
35
|
-
return visit(root, instructionVisitor);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Creates a visitor that renames events (as defined types) in a Codama IDL.
|
|
40
|
-
*
|
|
41
|
-
* Events in Anchor IDLs are typically converted to defined types in Codama,
|
|
42
|
-
* so this visitor renames specific defined types that represent events.
|
|
43
|
-
*
|
|
44
|
-
* @param mapping - Object mapping old event names to new event names
|
|
45
|
-
* @param eventSuffix - Optional suffix to identify event types (default: "Event")
|
|
46
|
-
* @returns A root node visitor that renames events
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const visitor = renameEventsVisitor({
|
|
51
|
-
* "tokenMinted": "nftMinted",
|
|
52
|
-
* "transferComplete": "transferFinished"
|
|
53
|
-
* });
|
|
54
|
-
* codama.update(visitor);
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export function renameEventsVisitor(mapping, eventSuffix = "Event") {
|
|
58
|
-
return rootNodeVisitor((root) => {
|
|
59
|
-
const eventVisitor = bottomUpTransformerVisitor([
|
|
60
|
-
{
|
|
61
|
-
select: "[definedTypeNode]",
|
|
62
|
-
transform: (node) => {
|
|
63
|
-
assertIsNode(node, "definedTypeNode");
|
|
64
|
-
// Check if this is an event type (by suffix or by being in the mapping)
|
|
65
|
-
const isEventBySuffix = node.name.endsWith(eventSuffix);
|
|
66
|
-
const isEventInMapping = mapping[node.name] !== undefined;
|
|
67
|
-
if (!(isEventBySuffix || isEventInMapping)) {
|
|
68
|
-
return node;
|
|
69
|
-
}
|
|
70
|
-
const newName = mapping[node.name];
|
|
71
|
-
if (!newName) {
|
|
72
|
-
return node;
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
...node,
|
|
76
|
-
name: camelCase(newName),
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
]);
|
|
81
|
-
return visit(root, eventVisitor);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Creates a visitor that renames defined types in a Codama IDL.
|
|
86
|
-
*
|
|
87
|
-
* @param mapping - Object mapping old defined type names to new defined type names
|
|
88
|
-
* @returns A root node visitor that renames defined types
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const visitor = renameDefinedTypesVisitor({
|
|
93
|
-
* "counter": "counterAccount",
|
|
94
|
-
* "config": "programConfig"
|
|
95
|
-
* });
|
|
96
|
-
* codama.update(visitor);
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export function renameDefinedTypesVisitor(mapping) {
|
|
100
|
-
return rootNodeVisitor((root) => {
|
|
101
|
-
const typeVisitor = bottomUpTransformerVisitor([
|
|
102
|
-
{
|
|
103
|
-
select: "[definedTypeNode]",
|
|
104
|
-
transform: (node) => {
|
|
105
|
-
assertIsNode(node, "definedTypeNode");
|
|
106
|
-
const newName = mapping[node.name];
|
|
107
|
-
if (!newName) {
|
|
108
|
-
return node;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
...node,
|
|
112
|
-
name: camelCase(newName),
|
|
113
|
-
};
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
]);
|
|
117
|
-
return visit(root, typeVisitor);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Creates a visitor that renames instructions, events, and defined types in specific programs.
|
|
122
|
-
* This follows the same pattern as addPdasVisitor from Codama.
|
|
123
|
-
*
|
|
124
|
-
* @param renamesByProgram - Object mapping program names to their rename configurations
|
|
125
|
-
* @returns A root node visitor that performs all specified renames
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```typescript
|
|
129
|
-
* const visitor = renameVisitor({
|
|
130
|
-
* quarryMine: {
|
|
131
|
-
* instructions: {
|
|
132
|
-
* claimRewards: "claimRewardsMine"
|
|
133
|
-
* }
|
|
134
|
-
* },
|
|
135
|
-
* token: {
|
|
136
|
-
* instructions: {
|
|
137
|
-
* transfer: "transferTokens",
|
|
138
|
-
* mint: "mintNft"
|
|
139
|
-
* },
|
|
140
|
-
* events: {
|
|
141
|
-
* tokenMinted: "nftMinted"
|
|
142
|
-
* }
|
|
143
|
-
* }
|
|
144
|
-
* });
|
|
145
|
-
* codama.update(visitor);
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
export function renameVisitor(renamesByProgram) {
|
|
149
|
-
return rootNodeVisitor((root) => {
|
|
150
|
-
// Check if this is the legacy single-program format
|
|
151
|
-
// (has instructions, events, or definedTypes at the top level)
|
|
152
|
-
const isLegacyFormat = "instructions" in renamesByProgram ||
|
|
153
|
-
"events" in renamesByProgram ||
|
|
154
|
-
"definedTypes" in renamesByProgram;
|
|
155
|
-
if (isLegacyFormat) {
|
|
156
|
-
// Legacy support: treat as single program renames
|
|
157
|
-
const options = renamesByProgram;
|
|
158
|
-
let transformedRoot = root;
|
|
159
|
-
// Apply instruction renaming
|
|
160
|
-
if (options.instructions &&
|
|
161
|
-
Object.keys(options.instructions).length > 0) {
|
|
162
|
-
transformedRoot = visit(transformedRoot, renameInstructionsVisitor(options.instructions));
|
|
163
|
-
}
|
|
164
|
-
// Apply event renaming
|
|
165
|
-
if (options.events && Object.keys(options.events).length > 0) {
|
|
166
|
-
transformedRoot = visit(transformedRoot, renameEventsVisitor(options.events));
|
|
167
|
-
}
|
|
168
|
-
// Apply defined type renaming
|
|
169
|
-
if (options.definedTypes &&
|
|
170
|
-
Object.keys(options.definedTypes).length > 0) {
|
|
171
|
-
transformedRoot = visit(transformedRoot, renameDefinedTypesVisitor(options.definedTypes));
|
|
172
|
-
}
|
|
173
|
-
return transformedRoot;
|
|
174
|
-
}
|
|
175
|
-
// New format: program-specific renames
|
|
176
|
-
const transforms = [];
|
|
177
|
-
// Process each program's rename configuration
|
|
178
|
-
Object.entries(renamesByProgram).forEach(([programName, renameOptions]) => {
|
|
179
|
-
// Add instruction renames for this program
|
|
180
|
-
if (renameOptions.instructions) {
|
|
181
|
-
Object.entries(renameOptions.instructions).forEach(([oldName, newName]) => {
|
|
182
|
-
transforms.push({
|
|
183
|
-
select: `[programNode]${programName}.[instructionNode]${oldName}`,
|
|
184
|
-
transform: (node) => {
|
|
185
|
-
assertIsNode(node, "instructionNode");
|
|
186
|
-
return {
|
|
187
|
-
...node,
|
|
188
|
-
name: camelCase(newName),
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
// Add event/defined type renames for this program
|
|
195
|
-
if (renameOptions.events || renameOptions.definedTypes) {
|
|
196
|
-
const allTypeRenames = {
|
|
197
|
-
...(renameOptions.events ?? {}),
|
|
198
|
-
...(renameOptions.definedTypes ?? {}),
|
|
199
|
-
};
|
|
200
|
-
Object.entries(allTypeRenames).forEach(([oldName, newName]) => {
|
|
201
|
-
transforms.push({
|
|
202
|
-
select: `[programNode]${programName}.[definedTypeNode]${oldName}`,
|
|
203
|
-
transform: (node) => {
|
|
204
|
-
assertIsNode(node, "definedTypeNode");
|
|
205
|
-
return {
|
|
206
|
-
...node,
|
|
207
|
-
name: camelCase(newName),
|
|
208
|
-
};
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
if (transforms.length === 0) {
|
|
215
|
-
return root;
|
|
216
|
-
}
|
|
217
|
-
const visitor = bottomUpTransformerVisitor(transforms);
|
|
218
|
-
return visit(root, visitor);
|
|
219
|
-
});
|
|
220
|
-
}
|
|
1
|
+
export { renameAccountsVisitor, renameAccountTransform, } from "./rename-accounts-visitor.js";
|
|
2
|
+
export { renameDefinedTypesVisitor, renameDefinedTypeTransform, } from "./rename-defined-types-visitor.js";
|
|
3
|
+
export { renameInstructionsVisitor, renameInstructionTransform, } from "./rename-instructions-visitor.js";
|
|
4
|
+
export { renameVisitor } from "./rename-visitor.js";
|
|
221
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,0BAA0B,EAC1B,SAAS,EACT,eAAe,EACf,KAAK,GACN,MAAM,QAAQ,CAAC;AAmBhB;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAA+B;IAE/B,OAAO,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;YACpD;gBACE,MAAM,EAAE,mBAAmB;gBAC3B,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;oBAClB,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;oBACtC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACnC,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,OAAO,IAAI,CAAC;oBACd,CAAC;oBACD,OAAO;wBACL,GAAG,IAAI;wBACP,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC;qBACN,CAAC;gBACvB,CAAC;aACF;SACF,CAAC,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA+B,EAC/B,WAAW,GAAG,OAAO;IAErB,OAAO,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,YAAY,GAAG,0BAA0B,CAAC;YAC9C;gBACE,MAAM,EAAE,mBAAmB;gBAC3B,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;oBAClB,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;oBAEtC,wE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;qBACF,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,0BAA0B,CAAC,UAAU,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DefinedTypeNode, InstructionNode, Node, RootNode } from \"codama\";\nimport {\n assertIsNode,\n bottomUpTransformerVisitor,\n camelCase,\n rootNodeVisitor,\n visit,\n} from \"codama\";\n\n/**\n * Rename mapping for a single program\n */\nexport interface ProgramRenameOptions {\n /** Mapping of old instruction names to new instruction names */\n instructions?: Record<string, string>;\n /** Mapping of old event names (as defined types) to new event names */\n events?: Record<string, string>;\n /** Mapping of old defined type names to new defined type names */\n definedTypes?: Record<string, string>;\n}\n\n/**\n * Options for the rename visitor (legacy interface)\n */\nexport type RenameVisitorOptions = ProgramRenameOptions;\n\n/**\n * Creates a visitor that renames instructions in a Codama IDL.\n *\n * @param mapping - Object mapping old instruction names to new instruction names\n * @returns A root node visitor that renames instructions\n *\n * @example\n * ```typescript\n * const visitor = renameInstructionsVisitor({\n * \"transfer\": \"transferTokens\",\n * \"mint\": \"mintNft\"\n * });\n * codama.update(visitor);\n * ```\n */\nexport function renameInstructionsVisitor(\n mapping: Record<string, string>,\n): ReturnType<typeof rootNodeVisitor> {\n return rootNodeVisitor((root) => {\n const instructionVisitor = bottomUpTransformerVisitor([\n {\n select: \"[instructionNode]\",\n transform: (node) => {\n assertIsNode(node, \"instructionNode\");\n const newName = mapping[node.name];\n if (!newName) {\n return node;\n }\n return {\n ...node,\n name: camelCase(newName),\n } as InstructionNode;\n },\n },\n ]);\n return visit(root, instructionVisitor);\n });\n}\n\n/**\n * Creates a visitor that renames events (as defined types) in a Codama IDL.\n *\n * Events in Anchor IDLs are typically converted to defined types in Codama,\n * so this visitor renames specific defined types that represent events.\n *\n * @param mapping - Object mapping old event names to new event names\n * @param eventSuffix - Optional suffix to identify event types (default: \"Event\")\n * @returns A root node visitor that renames events\n *\n * @example\n * ```typescript\n * const visitor = renameEventsVisitor({\n * \"tokenMinted\": \"nftMinted\",\n * \"transferComplete\": \"transferFinished\"\n * });\n * codama.update(visitor);\n * ```\n */\nexport function renameEventsVisitor(\n mapping: Record<string, string>,\n eventSuffix = \"Event\",\n): ReturnType<typeof rootNodeVisitor> {\n return rootNodeVisitor((root) => {\n const eventVisitor = bottomUpTransformerVisitor([\n {\n select: \"[definedTypeNode]\",\n transform: (node) => {\n assertIsNode(node, \"definedTypeNode\");\n\n // Check if this is an event type (by suffix or by being in the mapping)\n const isEventBySuffix = node.name.endsWith(eventSuffix);\n const isEventInMapping = mapping[node.name] !== undefined;\n\n if (!(isEventBySuffix || isEventInMapping)) {\n return node;\n }\n\n const newName = mapping[node.name];\n if (!newName) {\n return node;\n }\n\n return {\n ...node,\n name: camelCase(newName),\n } as DefinedTypeNode;\n },\n },\n ]);\n return visit(root, eventVisitor);\n });\n}\n\n/**\n * Creates a visitor that renames defined types in a Codama IDL.\n *\n * @param mapping - Object mapping old defined type names to new defined type names\n * @returns A root node visitor that renames defined types\n *\n * @example\n * ```typescript\n * const visitor = renameDefinedTypesVisitor({\n * \"counter\": \"counterAccount\",\n * \"config\": \"programConfig\"\n * });\n * codama.update(visitor);\n * ```\n */\nexport function renameDefinedTypesVisitor(\n mapping: Record<string, string>,\n): ReturnType<typeof rootNodeVisitor> {\n return rootNodeVisitor((root) => {\n const typeVisitor = bottomUpTransformerVisitor([\n {\n select: \"[definedTypeNode]\",\n transform: (node) => {\n assertIsNode(node, \"definedTypeNode\");\n const newName = mapping[node.name];\n if (!newName) {\n return node;\n }\n return {\n ...node,\n name: camelCase(newName),\n } as DefinedTypeNode;\n },\n },\n ]);\n return visit(root, typeVisitor);\n });\n}\n\n/**\n * Creates a visitor that renames instructions, events, and defined types in specific programs.\n * This follows the same pattern as addPdasVisitor from Codama.\n *\n * @param renamesByProgram - Object mapping program names to their rename configurations\n * @returns A root node visitor that performs all specified renames\n *\n * @example\n * ```typescript\n * const visitor = renameVisitor({\n * quarryMine: {\n * instructions: {\n * claimRewards: \"claimRewardsMine\"\n * }\n * },\n * token: {\n * instructions: {\n * transfer: \"transferTokens\",\n * mint: \"mintNft\"\n * },\n * events: {\n * tokenMinted: \"nftMinted\"\n * }\n * }\n * });\n * codama.update(visitor);\n * ```\n */\nexport function renameVisitor(\n renamesByProgram: Record<string, ProgramRenameOptions>,\n): ReturnType<typeof rootNodeVisitor> {\n return rootNodeVisitor((root) => {\n // Check if this is the legacy single-program format\n // (has instructions, events, or definedTypes at the top level)\n const isLegacyFormat =\n \"instructions\" in renamesByProgram ||\n \"events\" in renamesByProgram ||\n \"definedTypes\" in renamesByProgram;\n\n if (isLegacyFormat) {\n // Legacy support: treat as single program renames\n const options = renamesByProgram as unknown as RenameVisitorOptions;\n let transformedRoot = root;\n\n // Apply instruction renaming\n if (\n options.instructions &&\n Object.keys(options.instructions).length > 0\n ) {\n transformedRoot = visit(\n transformedRoot,\n renameInstructionsVisitor(options.instructions),\n ) as RootNode;\n }\n\n // Apply event renaming\n if (options.events && Object.keys(options.events).length > 0) {\n transformedRoot = visit(\n transformedRoot,\n renameEventsVisitor(options.events),\n ) as RootNode;\n }\n\n // Apply defined type renaming\n if (\n options.definedTypes &&\n Object.keys(options.definedTypes).length > 0\n ) {\n transformedRoot = visit(\n transformedRoot,\n renameDefinedTypesVisitor(options.definedTypes),\n ) as RootNode;\n }\n\n return transformedRoot;\n }\n\n // New format: program-specific renames\n const transforms: {\n select: string;\n transform: (node: Node) => Node | null;\n }[] = [];\n\n // Process each program's rename configuration\n Object.entries(renamesByProgram).forEach(([programName, renameOptions]) => {\n // Add instruction renames for this program\n if (renameOptions.instructions) {\n Object.entries(renameOptions.instructions).forEach(\n ([oldName, newName]) => {\n transforms.push({\n select: `[programNode]${programName}.[instructionNode]${oldName}`,\n transform: (node) => {\n assertIsNode(node, \"instructionNode\");\n return {\n ...node,\n name: camelCase(newName),\n } as InstructionNode;\n },\n });\n },\n );\n }\n\n // Add event/defined type renames for this program\n if (renameOptions.events || renameOptions.definedTypes) {\n const allTypeRenames = {\n ...(renameOptions.events ?? {}),\n ...(renameOptions.definedTypes ?? {}),\n };\n\n Object.entries(allTypeRenames).forEach(([oldName, newName]) => {\n transforms.push({\n select: `[programNode]${programName}.[definedTypeNode]${oldName}`,\n transform: (node) => {\n assertIsNode(node, \"definedTypeNode\");\n return {\n ...node,\n name: camelCase(newName),\n } as DefinedTypeNode;\n },\n });\n });\n }\n });\n\n if (transforms.length === 0) {\n return root;\n }\n\n const visitor = bottomUpTransformerVisitor(transforms);\n return visit(root, visitor);\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n renameAccountsVisitor,\n renameAccountTransform,\n} from \"./rename-accounts-visitor.js\";\nexport {\n renameDefinedTypesVisitor,\n renameDefinedTypeTransform,\n} from \"./rename-defined-types-visitor.js\";\nexport {\n renameInstructionsVisitor,\n renameInstructionTransform,\n} from \"./rename-instructions-visitor.js\";\nexport { renameVisitor } from \"./rename-visitor.js\";\nexport type { ProgramRenameOptions } from \"./types.js\";\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AccountNode, Node, rootNodeVisitor } from "codama";
|
|
2
|
+
/**
|
|
3
|
+
* Transform function that renames an account node based on a mapping.
|
|
4
|
+
*
|
|
5
|
+
* @param node - The node to transform
|
|
6
|
+
* @param mapping - Object mapping old account names to new account names
|
|
7
|
+
* @returns The transformed account node
|
|
8
|
+
*/
|
|
9
|
+
export declare function renameAccountTransform(node: Node, mapping: Record<string, string>): AccountNode;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a visitor that renames accounts in a Codama IDL.
|
|
12
|
+
*
|
|
13
|
+
* @param mapping - Object mapping old account names to new account names
|
|
14
|
+
* @returns A root node visitor that renames accounts
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const visitor = renameAccountsVisitor({
|
|
19
|
+
* "userAccount": "user",
|
|
20
|
+
* "configAccount": "config"
|
|
21
|
+
* });
|
|
22
|
+
* codama.update(visitor);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function renameAccountsVisitor(mapping: Record<string, string>): ReturnType<typeof rootNodeVisitor>;
|
|
26
|
+
//# sourceMappingURL=rename-accounts-visitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-accounts-visitor.d.ts","sourceRoot":"","sources":["../src/rename-accounts-visitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGjE;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,WAAW,CAUb;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,UAAU,CAAC,OAAO,eAAe,CAAC,CAOpC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { assertIsNode, bottomUpTransformerVisitor, camelCase } from "codama";
|
|
2
|
+
/**
|
|
3
|
+
* Transform function that renames an account node based on a mapping.
|
|
4
|
+
*
|
|
5
|
+
* @param node - The node to transform
|
|
6
|
+
* @param mapping - Object mapping old account names to new account names
|
|
7
|
+
* @returns The transformed account node
|
|
8
|
+
*/
|
|
9
|
+
export function renameAccountTransform(node, mapping) {
|
|
10
|
+
assertIsNode(node, "accountNode");
|
|
11
|
+
const newName = mapping[node.name];
|
|
12
|
+
if (!newName) {
|
|
13
|
+
return node;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...node,
|
|
17
|
+
name: camelCase(newName),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a visitor that renames accounts in a Codama IDL.
|
|
22
|
+
*
|
|
23
|
+
* @param mapping - Object mapping old account names to new account names
|
|
24
|
+
* @returns A root node visitor that renames accounts
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const visitor = renameAccountsVisitor({
|
|
29
|
+
* "userAccount": "user",
|
|
30
|
+
* "configAccount": "config"
|
|
31
|
+
* });
|
|
32
|
+
* codama.update(visitor);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function renameAccountsVisitor(mapping) {
|
|
36
|
+
return bottomUpTransformerVisitor([
|
|
37
|
+
{
|
|
38
|
+
select: "[accountNode]",
|
|
39
|
+
transform: (node) => renameAccountTransform(node, mapping),
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=rename-accounts-visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-accounts-visitor.js","sourceRoot":"","sources":["../src/rename-accounts-visitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,IAAU,EACV,OAA+B;IAE/B,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC;KACzB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAA+B;IAE/B,OAAO,0BAA0B,CAAC;QAChC;YACE,MAAM,EAAE,eAAe;YACvB,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC;SAC3D;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { AccountNode, Node, rootNodeVisitor } from \"codama\";\nimport { assertIsNode, bottomUpTransformerVisitor, camelCase } from \"codama\";\n\n/**\n * Transform function that renames an account node based on a mapping.\n *\n * @param node - The node to transform\n * @param mapping - Object mapping old account names to new account names\n * @returns The transformed account node\n */\nexport function renameAccountTransform(\n node: Node,\n mapping: Record<string, string>,\n): AccountNode {\n assertIsNode(node, \"accountNode\");\n const newName = mapping[node.name];\n if (!newName) {\n return node;\n }\n return {\n ...node,\n name: camelCase(newName),\n };\n}\n\n/**\n * Creates a visitor that renames accounts in a Codama IDL.\n *\n * @param mapping - Object mapping old account names to new account names\n * @returns A root node visitor that renames accounts\n *\n * @example\n * ```typescript\n * const visitor = renameAccountsVisitor({\n * \"userAccount\": \"user\",\n * \"configAccount\": \"config\"\n * });\n * codama.update(visitor);\n * ```\n */\nexport function renameAccountsVisitor(\n mapping: Record<string, string>,\n): ReturnType<typeof rootNodeVisitor> {\n return bottomUpTransformerVisitor([\n {\n select: \"[accountNode]\",\n transform: (node) => renameAccountTransform(node, mapping),\n },\n ]);\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DefinedTypeNode, Node } from "codama";
|
|
2
|
+
import { rootNodeVisitor } from "codama";
|
|
3
|
+
/**
|
|
4
|
+
* Transform function that renames a defined type node based on a mapping.
|
|
5
|
+
*
|
|
6
|
+
* @param node - The node to transform
|
|
7
|
+
* @param mapping - Object mapping old defined type names to new defined type names
|
|
8
|
+
* @returns The transformed defined type node
|
|
9
|
+
*/
|
|
10
|
+
export declare function renameDefinedTypeTransform(node: Node, mapping: Record<string, string>): DefinedTypeNode;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a visitor that renames defined types in a Codama IDL.
|
|
13
|
+
*
|
|
14
|
+
* @param mapping - Object mapping old defined type names to new defined type names
|
|
15
|
+
* @returns A root node visitor that renames defined types
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const visitor = renameDefinedTypesVisitor({
|
|
20
|
+
* "counter": "counterAccount",
|
|
21
|
+
* "config": "programConfig"
|
|
22
|
+
* });
|
|
23
|
+
* codama.update(visitor);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function renameDefinedTypesVisitor(mapping: Record<string, string>): ReturnType<typeof rootNodeVisitor>;
|
|
27
|
+
//# sourceMappingURL=rename-defined-types-visitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-defined-types-visitor.d.ts","sourceRoot":"","sources":["../src/rename-defined-types-visitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAIL,eAAe,EAEhB,MAAM,QAAQ,CAAC;AAEhB;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,eAAe,CAUjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,UAAU,CAAC,OAAO,eAAe,CAAC,CAUpC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { assertIsNode, bottomUpTransformerVisitor, camelCase, rootNodeVisitor, visit, } from "codama";
|
|
2
|
+
/**
|
|
3
|
+
* Transform function that renames a defined type node based on a mapping.
|
|
4
|
+
*
|
|
5
|
+
* @param node - The node to transform
|
|
6
|
+
* @param mapping - Object mapping old defined type names to new defined type names
|
|
7
|
+
* @returns The transformed defined type node
|
|
8
|
+
*/
|
|
9
|
+
export function renameDefinedTypeTransform(node, mapping) {
|
|
10
|
+
assertIsNode(node, "definedTypeNode");
|
|
11
|
+
const newName = mapping[node.name];
|
|
12
|
+
if (!newName) {
|
|
13
|
+
return node;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...node,
|
|
17
|
+
name: camelCase(newName),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a visitor that renames defined types in a Codama IDL.
|
|
22
|
+
*
|
|
23
|
+
* @param mapping - Object mapping old defined type names to new defined type names
|
|
24
|
+
* @returns A root node visitor that renames defined types
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const visitor = renameDefinedTypesVisitor({
|
|
29
|
+
* "counter": "counterAccount",
|
|
30
|
+
* "config": "programConfig"
|
|
31
|
+
* });
|
|
32
|
+
* codama.update(visitor);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function renameDefinedTypesVisitor(mapping) {
|
|
36
|
+
return rootNodeVisitor((root) => {
|
|
37
|
+
const typeVisitor = bottomUpTransformerVisitor([
|
|
38
|
+
{
|
|
39
|
+
select: "[definedTypeNode]",
|
|
40
|
+
transform: (node) => renameDefinedTypeTransform(node, mapping),
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
return visit(root, typeVisitor);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=rename-defined-types-visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-defined-types-visitor.js","sourceRoot":"","sources":["../src/rename-defined-types-visitor.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,0BAA0B,EAC1B,SAAS,EACT,eAAe,EACf,KAAK,GACN,MAAM,QAAQ,CAAC;AAEhB;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAU,EACV,OAA+B;IAE/B,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC;KACzB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAA+B;IAE/B,OAAO,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,WAAW,GAAG,0BAA0B,CAAC;YAC7C;gBACE,MAAM,EAAE,mBAAmB;gBAC3B,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC;aAC/D;SACF,CAAC,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DefinedTypeNode, Node } from \"codama\";\nimport {\n assertIsNode,\n bottomUpTransformerVisitor,\n camelCase,\n rootNodeVisitor,\n visit,\n} from \"codama\";\n\n/**\n * Transform function that renames a defined type node based on a mapping.\n *\n * @param node - The node to transform\n * @param mapping - Object mapping old defined type names to new defined type names\n * @returns The transformed defined type node\n */\nexport function renameDefinedTypeTransform(\n node: Node,\n mapping: Record<string, string>,\n): DefinedTypeNode {\n assertIsNode(node, \"definedTypeNode\");\n const newName = mapping[node.name];\n if (!newName) {\n return node;\n }\n return {\n ...node,\n name: camelCase(newName),\n };\n}\n\n/**\n * Creates a visitor that renames defined types in a Codama IDL.\n *\n * @param mapping - Object mapping old defined type names to new defined type names\n * @returns A root node visitor that renames defined types\n *\n * @example\n * ```typescript\n * const visitor = renameDefinedTypesVisitor({\n * \"counter\": \"counterAccount\",\n * \"config\": \"programConfig\"\n * });\n * codama.update(visitor);\n * ```\n */\nexport function renameDefinedTypesVisitor(\n mapping: Record<string, string>,\n): ReturnType<typeof rootNodeVisitor> {\n return rootNodeVisitor((root) => {\n const typeVisitor = bottomUpTransformerVisitor([\n {\n select: \"[definedTypeNode]\",\n transform: (node) => renameDefinedTypeTransform(node, mapping),\n },\n ]);\n return visit(root, typeVisitor);\n });\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { InstructionNode, Node, NodeKind, Visitor } from "codama";
|
|
2
|
+
/**
|
|
3
|
+
* Transform function that renames an instruction node based on a mapping.
|
|
4
|
+
*
|
|
5
|
+
* @param node - The node to transform
|
|
6
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
7
|
+
* @returns The transformed instruction node
|
|
8
|
+
*/
|
|
9
|
+
export declare function renameInstructionTransform(node: Node, mapping: Record<string, string>): InstructionNode;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a visitor that renames instructions in a Codama IDL.
|
|
12
|
+
*
|
|
13
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
14
|
+
* @returns A root node visitor that renames instructions
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const visitor = renameInstructionsVisitor({
|
|
19
|
+
* "transfer": "transferTokens",
|
|
20
|
+
* "mint": "mintNft"
|
|
21
|
+
* });
|
|
22
|
+
* codama.update(visitor);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function renameInstructionsVisitor<TNodeKind extends NodeKind = NodeKind>(mapping: Record<string, string>): Visitor<Node | null, TNodeKind>;
|
|
26
|
+
//# sourceMappingURL=rename-instructions-visitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-instructions-visitor.d.ts","sourceRoot":"","sources":["../src/rename-instructions-visitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGvE;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,eAAe,CAUjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,EAAE,SAAS,CAAC,CAOlE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { assertIsNode, bottomUpTransformerVisitor, camelCase } from "codama";
|
|
2
|
+
/**
|
|
3
|
+
* Transform function that renames an instruction node based on a mapping.
|
|
4
|
+
*
|
|
5
|
+
* @param node - The node to transform
|
|
6
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
7
|
+
* @returns The transformed instruction node
|
|
8
|
+
*/
|
|
9
|
+
export function renameInstructionTransform(node, mapping) {
|
|
10
|
+
assertIsNode(node, "instructionNode");
|
|
11
|
+
const newName = mapping[node.name];
|
|
12
|
+
if (!newName) {
|
|
13
|
+
return node;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...node,
|
|
17
|
+
name: camelCase(newName),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a visitor that renames instructions in a Codama IDL.
|
|
22
|
+
*
|
|
23
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
24
|
+
* @returns A root node visitor that renames instructions
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const visitor = renameInstructionsVisitor({
|
|
29
|
+
* "transfer": "transferTokens",
|
|
30
|
+
* "mint": "mintNft"
|
|
31
|
+
* });
|
|
32
|
+
* codama.update(visitor);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function renameInstructionsVisitor(mapping) {
|
|
36
|
+
return bottomUpTransformerVisitor([
|
|
37
|
+
{
|
|
38
|
+
select: "[instructionNode]",
|
|
39
|
+
transform: (node) => renameInstructionTransform(node, mapping),
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=rename-instructions-visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-instructions-visitor.js","sourceRoot":"","sources":["../src/rename-instructions-visitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAU,EACV,OAA+B;IAE/B,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC;KACzB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CAEvC,OAA+B;IAC/B,OAAO,0BAA0B,CAAC;QAChC;YACE,MAAM,EAAE,mBAAmB;YAC3B,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC;SAC/D;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { InstructionNode, Node, NodeKind, Visitor } from \"codama\";\nimport { assertIsNode, bottomUpTransformerVisitor, camelCase } from \"codama\";\n\n/**\n * Transform function that renames an instruction node based on a mapping.\n *\n * @param node - The node to transform\n * @param mapping - Object mapping old instruction names to new instruction names\n * @returns The transformed instruction node\n */\nexport function renameInstructionTransform(\n node: Node,\n mapping: Record<string, string>,\n): InstructionNode {\n assertIsNode(node, \"instructionNode\");\n const newName = mapping[node.name];\n if (!newName) {\n return node;\n }\n return {\n ...node,\n name: camelCase(newName),\n };\n}\n\n/**\n * Creates a visitor that renames instructions in a Codama IDL.\n *\n * @param mapping - Object mapping old instruction names to new instruction names\n * @returns A root node visitor that renames instructions\n *\n * @example\n * ```typescript\n * const visitor = renameInstructionsVisitor({\n * \"transfer\": \"transferTokens\",\n * \"mint\": \"mintNft\"\n * });\n * codama.update(visitor);\n * ```\n */\nexport function renameInstructionsVisitor<\n TNodeKind extends NodeKind = NodeKind,\n>(mapping: Record<string, string>): Visitor<Node | null, TNodeKind> {\n return bottomUpTransformerVisitor([\n {\n select: \"[instructionNode]\",\n transform: (node) => renameInstructionTransform(node, mapping),\n },\n ]);\n}\n"]}
|