@macalinao/codama-rename-visitor 0.3.3 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/rename-accounts-visitor.d.ts +27 -23
- package/dist/rename-accounts-visitor.d.ts.map +1 -1
- package/dist/rename-accounts-visitor.js +37 -37
- package/dist/rename-accounts-visitor.js.map +1 -1
- package/dist/rename-defined-types-visitor.d.ts +27 -24
- package/dist/rename-defined-types-visitor.d.ts.map +1 -1
- package/dist/rename-defined-types-visitor.js +40 -41
- package/dist/rename-defined-types-visitor.js.map +1 -1
- package/dist/rename-instructions-visitor.d.ts +27 -23
- package/dist/rename-instructions-visitor.d.ts.map +1 -1
- package/dist/rename-instructions-visitor.js +37 -37
- package/dist/rename-instructions-visitor.js.map +1 -1
- package/dist/rename-visitor.d.ts +7 -34
- package/dist/rename-visitor.d.ts.map +1 -1
- package/dist/rename-visitor.js +22 -69
- package/dist/rename-visitor.js.map +1 -1
- package/dist/types.d.ts +12 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/rename-accounts-visitor.ts +2 -2
- package/src/rename-defined-types-visitor.ts +3 -3
- package/src/rename-visitor.ts +52 -44
- package/dist/.tsbuildinfo +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ProgramRenameOptions } from "./types.js";
|
|
2
|
+
import { renameAccountTransform, renameAccountsVisitor } from "./rename-accounts-visitor.js";
|
|
3
|
+
import { renameDefinedTypeTransform, renameDefinedTypesVisitor } from "./rename-defined-types-visitor.js";
|
|
4
|
+
import { renameInstructionTransform, renameInstructionsVisitor } from "./rename-instructions-visitor.js";
|
|
5
|
+
import { renameVisitor } from "./rename-visitor.js";
|
|
6
|
+
export { type ProgramRenameOptions, renameAccountTransform, renameAccountsVisitor, renameDefinedTypeTransform, renameDefinedTypesVisitor, renameInstructionTransform, renameInstructionsVisitor, renameVisitor };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { renameAccountTransform, renameAccountsVisitor } from "./rename-accounts-visitor.js";
|
|
2
|
+
import { renameDefinedTypeTransform, renameDefinedTypesVisitor } from "./rename-defined-types-visitor.js";
|
|
3
|
+
import { renameInstructionTransform, renameInstructionsVisitor } from "./rename-instructions-visitor.js";
|
|
4
|
+
import { renameVisitor } from "./rename-visitor.js";
|
|
5
|
+
export { renameAccountTransform, renameAccountsVisitor, renameDefinedTypeTransform, renameDefinedTypesVisitor, renameInstructionTransform, renameInstructionsVisitor, renameVisitor };
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AccountNode, Node, Visitor } from "codama";
|
|
2
|
+
|
|
3
|
+
//#region src/rename-accounts-visitor.d.ts
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
* Transform function that renames an account node based on a mapping.
|
|
6
|
+
*
|
|
7
|
+
* @param node - The node to transform
|
|
8
|
+
* @param mapping - Object mapping old account names to new account names
|
|
9
|
+
* @returns The transformed account node
|
|
10
|
+
*/
|
|
11
|
+
declare function renameAccountTransform(node: Node, mapping: Record<string, string>): AccountNode;
|
|
10
12
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
* Creates a visitor that renames accounts in a Codama IDL.
|
|
14
|
+
*
|
|
15
|
+
* @param mapping - Object mapping old account names to new account names
|
|
16
|
+
* @returns A root node visitor that renames accounts
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const visitor = renameAccountsVisitor({
|
|
21
|
+
* "userAccount": "user",
|
|
22
|
+
* "configAccount": "config"
|
|
23
|
+
* });
|
|
24
|
+
* codama.update(visitor);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function renameAccountsVisitor(mapping: Record<string, string>): Visitor<Node | null, "rootNode">;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { renameAccountTransform, renameAccountsVisitor };
|
|
26
30
|
//# sourceMappingURL=rename-accounts-visitor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-accounts-visitor.d.ts","
|
|
1
|
+
{"version":3,"file":"rename-accounts-visitor.d.ts","names":[],"sources":["../src/rename-accounts-visitor.ts"],"mappings":";;;;;AAUA;;;;;iBAAgB,sBAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,EAAS,MAAA,mBACR,WAAA;;;;;;;;;AAAA;AA2BH;;;;;;iBAAgB,qBAAA,CACd,OAAA,EAAS,MAAA,mBACR,OAAA,CAAQ,IAAA"}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import { assertIsNode, bottomUpTransformerVisitor, camelCase } from "codama";
|
|
2
|
+
//#region src/rename-accounts-visitor.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name: camelCase(newName),
|
|
18
|
-
};
|
|
4
|
+
* Transform function that renames an account node based on a mapping.
|
|
5
|
+
*
|
|
6
|
+
* @param node - The node to transform
|
|
7
|
+
* @param mapping - Object mapping old account names to new account names
|
|
8
|
+
* @returns The transformed account node
|
|
9
|
+
*/
|
|
10
|
+
function renameAccountTransform(node, mapping) {
|
|
11
|
+
assertIsNode(node, "accountNode");
|
|
12
|
+
const newName = mapping[node.name];
|
|
13
|
+
if (!newName) return node;
|
|
14
|
+
return {
|
|
15
|
+
...node,
|
|
16
|
+
name: camelCase(newName)
|
|
17
|
+
};
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
20
|
+
* Creates a visitor that renames accounts in a Codama IDL.
|
|
21
|
+
*
|
|
22
|
+
* @param mapping - Object mapping old account names to new account names
|
|
23
|
+
* @returns A root node visitor that renames accounts
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const visitor = renameAccountsVisitor({
|
|
28
|
+
* "userAccount": "user",
|
|
29
|
+
* "configAccount": "config"
|
|
30
|
+
* });
|
|
31
|
+
* codama.update(visitor);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function renameAccountsVisitor(mapping) {
|
|
35
|
+
return bottomUpTransformerVisitor([{
|
|
36
|
+
select: "[accountNode]",
|
|
37
|
+
transform: (node) => renameAccountTransform(node, mapping)
|
|
38
|
+
}]);
|
|
42
39
|
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { renameAccountTransform, renameAccountsVisitor };
|
|
42
|
+
|
|
43
43
|
//# sourceMappingURL=rename-accounts-visitor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-accounts-visitor.js","
|
|
1
|
+
{"version":3,"file":"rename-accounts-visitor.js","names":[],"sources":["../src/rename-accounts-visitor.ts"],"sourcesContent":["import type { AccountNode, Node, Visitor } 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): Visitor<Node | null, \"rootNode\"> {\n return bottomUpTransformerVisitor([\n {\n select: \"[accountNode]\",\n transform: (node) => renameAccountTransform(node, mapping),\n },\n ]);\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,uBACd,MACA,SACa;CACb,aAAa,MAAM,aAAa;CAChC,MAAM,UAAU,QAAQ,KAAK;CAC7B,IAAI,CAAC,SACH,OAAO;CAET,OAAO;EACL,GAAG;EACH,MAAM,UAAU,OAAO;CACzB;AACF;;;;;;;;;;;;;;;;AAiBA,SAAgB,sBACd,SACkC;CAClC,OAAO,2BAA2B,CAChC;EACE,QAAQ;EACR,YAAY,SAAS,uBAAuB,MAAM,OAAO;CAC3D,CACF,CAAC;AACH"}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { DefinedTypeNode, Node, Visitor } from "codama";
|
|
2
|
+
|
|
3
|
+
//#region src/rename-defined-types-visitor.d.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
* Transform function that renames a defined type node based on a mapping.
|
|
6
|
+
*
|
|
7
|
+
* @param node - The node to transform
|
|
8
|
+
* @param mapping - Object mapping old defined type names to new defined type names
|
|
9
|
+
* @returns The transformed defined type node
|
|
10
|
+
*/
|
|
11
|
+
declare function renameDefinedTypeTransform(node: Node, mapping: Record<string, string>): DefinedTypeNode;
|
|
11
12
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
* Creates a visitor that renames defined types in a Codama IDL.
|
|
14
|
+
*
|
|
15
|
+
* @param mapping - Object mapping old defined type names to new defined type names
|
|
16
|
+
* @returns A root node visitor that renames defined types
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const visitor = renameDefinedTypesVisitor({
|
|
21
|
+
* "counter": "counterAccount",
|
|
22
|
+
* "config": "programConfig"
|
|
23
|
+
* });
|
|
24
|
+
* codama.update(visitor);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function renameDefinedTypesVisitor(mapping: Record<string, string>): Visitor<Node | null, "rootNode">;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { renameDefinedTypeTransform, renameDefinedTypesVisitor };
|
|
27
30
|
//# sourceMappingURL=rename-defined-types-visitor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-defined-types-visitor.d.ts","
|
|
1
|
+
{"version":3,"file":"rename-defined-types-visitor.d.ts","names":[],"sources":["../src/rename-defined-types-visitor.ts"],"mappings":";;;;;AAgBA;;;;;iBAAgB,0BAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,EAAS,MAAA,mBACR,eAAA;;;;;;;;;AAAA;AA2BH;;;;;;iBAAgB,yBAAA,CACd,OAAA,EAAS,MAAA,mBACR,OAAA,CAAQ,IAAA"}
|
|
@@ -1,46 +1,45 @@
|
|
|
1
|
-
import { assertIsNode, bottomUpTransformerVisitor, camelCase, rootNodeVisitor, visit
|
|
1
|
+
import { assertIsNode, bottomUpTransformerVisitor, camelCase, rootNodeVisitor, visit } from "codama";
|
|
2
|
+
//#region src/rename-defined-types-visitor.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name: camelCase(newName),
|
|
18
|
-
};
|
|
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
|
+
function renameDefinedTypeTransform(node, mapping) {
|
|
11
|
+
assertIsNode(node, "definedTypeNode");
|
|
12
|
+
const newName = mapping[node.name];
|
|
13
|
+
if (!newName) return node;
|
|
14
|
+
return {
|
|
15
|
+
...node,
|
|
16
|
+
name: camelCase(newName)
|
|
17
|
+
};
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
]);
|
|
43
|
-
return visit(root, typeVisitor);
|
|
44
|
-
});
|
|
20
|
+
* Creates a visitor that renames defined types in a Codama IDL.
|
|
21
|
+
*
|
|
22
|
+
* @param mapping - Object mapping old defined type names to new defined type names
|
|
23
|
+
* @returns A root node visitor that renames defined types
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const visitor = renameDefinedTypesVisitor({
|
|
28
|
+
* "counter": "counterAccount",
|
|
29
|
+
* "config": "programConfig"
|
|
30
|
+
* });
|
|
31
|
+
* codama.update(visitor);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function renameDefinedTypesVisitor(mapping) {
|
|
35
|
+
return rootNodeVisitor((root) => {
|
|
36
|
+
return visit(root, bottomUpTransformerVisitor([{
|
|
37
|
+
select: "[definedTypeNode]",
|
|
38
|
+
transform: (node) => renameDefinedTypeTransform(node, mapping)
|
|
39
|
+
}]));
|
|
40
|
+
});
|
|
45
41
|
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { renameDefinedTypeTransform, renameDefinedTypesVisitor };
|
|
44
|
+
|
|
46
45
|
//# sourceMappingURL=rename-defined-types-visitor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-defined-types-visitor.js","
|
|
1
|
+
{"version":3,"file":"rename-defined-types-visitor.js","names":[],"sources":["../src/rename-defined-types-visitor.ts"],"sourcesContent":["import type { DefinedTypeNode, Node, Visitor } 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): Visitor<Node | null, \"rootNode\"> {\n return rootNodeVisitor<Node | null>((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"],"mappings":";;;;;;;;;AAgBA,SAAgB,2BACd,MACA,SACiB;CACjB,aAAa,MAAM,iBAAiB;CACpC,MAAM,UAAU,QAAQ,KAAK;CAC7B,IAAI,CAAC,SACH,OAAO;CAET,OAAO;EACL,GAAG;EACH,MAAM,UAAU,OAAO;CACzB;AACF;;;;;;;;;;;;;;;;AAiBA,SAAgB,0BACd,SACkC;CAClC,OAAO,iBAA8B,SAAS;EAO5C,OAAO,MAAM,MANO,2BAA2B,CAC7C;GACE,QAAQ;GACR,YAAY,SAAS,2BAA2B,MAAM,OAAO;EAC/D,CACF,CAC6B,CAAC;CAChC,CAAC;AACH"}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { InstructionNode, Node, NodeKind, Visitor } from "codama";
|
|
2
|
+
|
|
3
|
+
//#region src/rename-instructions-visitor.d.ts
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
* Transform function that renames an instruction node based on a mapping.
|
|
6
|
+
*
|
|
7
|
+
* @param node - The node to transform
|
|
8
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
9
|
+
* @returns The transformed instruction node
|
|
10
|
+
*/
|
|
11
|
+
declare function renameInstructionTransform(node: Node, mapping: Record<string, string>): InstructionNode;
|
|
10
12
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
* Creates a visitor that renames instructions in a Codama IDL.
|
|
14
|
+
*
|
|
15
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
16
|
+
* @returns A root node visitor that renames instructions
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const visitor = renameInstructionsVisitor({
|
|
21
|
+
* "transfer": "transferTokens",
|
|
22
|
+
* "mint": "mintNft"
|
|
23
|
+
* });
|
|
24
|
+
* codama.update(visitor);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function renameInstructionsVisitor<TNodeKind extends NodeKind = NodeKind>(mapping: Record<string, string>): Visitor<Node | null, TNodeKind>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { renameInstructionTransform, renameInstructionsVisitor };
|
|
26
30
|
//# sourceMappingURL=rename-instructions-visitor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-instructions-visitor.d.ts","
|
|
1
|
+
{"version":3,"file":"rename-instructions-visitor.d.ts","names":[],"sources":["../src/rename-instructions-visitor.ts"],"mappings":";;;;;AAUA;;;;;iBAAgB,0BAAA,CACd,IAAA,EAAM,IAAA,EACN,OAAA,EAAS,MAAA,mBACR,eAAA;;;;;;;;;AAAA;AA2BH;;;;;;iBAAgB,yBAAA,mBACI,QAAA,GAAW,QAAA,EAC7B,OAAA,EAAS,MAAA,mBAAyB,OAAA,CAAQ,IAAA,SAAa,SAAA"}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import { assertIsNode, bottomUpTransformerVisitor, camelCase } from "codama";
|
|
2
|
+
//#region src/rename-instructions-visitor.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name: camelCase(newName),
|
|
18
|
-
};
|
|
4
|
+
* Transform function that renames an instruction node based on a mapping.
|
|
5
|
+
*
|
|
6
|
+
* @param node - The node to transform
|
|
7
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
8
|
+
* @returns The transformed instruction node
|
|
9
|
+
*/
|
|
10
|
+
function renameInstructionTransform(node, mapping) {
|
|
11
|
+
assertIsNode(node, "instructionNode");
|
|
12
|
+
const newName = mapping[node.name];
|
|
13
|
+
if (!newName) return node;
|
|
14
|
+
return {
|
|
15
|
+
...node,
|
|
16
|
+
name: camelCase(newName)
|
|
17
|
+
};
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
20
|
+
* Creates a visitor that renames instructions in a Codama IDL.
|
|
21
|
+
*
|
|
22
|
+
* @param mapping - Object mapping old instruction names to new instruction names
|
|
23
|
+
* @returns A root node visitor that renames instructions
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const visitor = renameInstructionsVisitor({
|
|
28
|
+
* "transfer": "transferTokens",
|
|
29
|
+
* "mint": "mintNft"
|
|
30
|
+
* });
|
|
31
|
+
* codama.update(visitor);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function renameInstructionsVisitor(mapping) {
|
|
35
|
+
return bottomUpTransformerVisitor([{
|
|
36
|
+
select: "[instructionNode]",
|
|
37
|
+
transform: (node) => renameInstructionTransform(node, mapping)
|
|
38
|
+
}]);
|
|
42
39
|
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { renameInstructionTransform, renameInstructionsVisitor };
|
|
42
|
+
|
|
43
43
|
//# sourceMappingURL=rename-instructions-visitor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-instructions-visitor.js","
|
|
1
|
+
{"version":3,"file":"rename-instructions-visitor.js","names":[],"sources":["../src/rename-instructions-visitor.ts"],"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"],"mappings":";;;;;;;;;AAUA,SAAgB,2BACd,MACA,SACiB;CACjB,aAAa,MAAM,iBAAiB;CACpC,MAAM,UAAU,QAAQ,KAAK;CAC7B,IAAI,CAAC,SACH,OAAO;CAET,OAAO;EACL,GAAG;EACH,MAAM,UAAU,OAAO;CACzB;AACF;;;;;;;;;;;;;;;;AAiBA,SAAgB,0BAEd,SAAkE;CAClE,OAAO,2BAA2B,CAChC;EACE,QAAQ;EACR,YAAY,SAAS,2BAA2B,MAAM,OAAO;CAC/D,CACF,CAAC;AACH"}
|
package/dist/rename-visitor.d.ts
CHANGED
|
@@ -1,35 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @returns A root node visitor that performs all specified renames
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const visitor = renameVisitor({
|
|
13
|
-
* quarryMine: {
|
|
14
|
-
* instructions: {
|
|
15
|
-
* claimRewards: "claimRewardsMine"
|
|
16
|
-
* },
|
|
17
|
-
* accounts: {
|
|
18
|
-
* miner: "minerAccount"
|
|
19
|
-
* }
|
|
20
|
-
* },
|
|
21
|
-
* token: {
|
|
22
|
-
* instructions: {
|
|
23
|
-
* transfer: "transferTokens",
|
|
24
|
-
* mint: "mintNft"
|
|
25
|
-
* },
|
|
26
|
-
* definedTypes: {
|
|
27
|
-
* tokenData: "tokenMetadata"
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* });
|
|
31
|
-
* codama.update(visitor);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare function renameVisitor(renamesByProgram: Record<string, ProgramRenameOptions>): ReturnType<typeof rootNodeVisitor>;
|
|
1
|
+
import { ProgramRenameOptions } from "./types.js";
|
|
2
|
+
import { Node, Visitor } from "codama";
|
|
3
|
+
|
|
4
|
+
//#region src/rename-visitor.d.ts
|
|
5
|
+
declare function renameVisitor(renamesByProgram: Record<string, ProgramRenameOptions>): Visitor<Node | null, "rootNode">;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { renameVisitor };
|
|
35
8
|
//# sourceMappingURL=rename-visitor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-visitor.d.ts","
|
|
1
|
+
{"version":3,"file":"rename-visitor.d.ts","names":[],"sources":["../src/rename-visitor.ts"],"mappings":";;;;iBA8DgB,aAAA,CACd,gBAAA,EAAkB,MAAA,SAAe,oBAAA,IAChC,OAAA,CAAQ,IAAA"}
|