@haneullabs/codegen 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.
- package/CHANGELOG.md +259 -0
- package/README.md +195 -0
- package/dist/cjs/bin/bash-complete.d.ts +2 -0
- package/dist/cjs/bin/bash-complete.js +51 -0
- package/dist/cjs/bin/bash-complete.js.map +7 -0
- package/dist/cjs/bin/cli.d.ts +2 -0
- package/dist/cjs/bin/cli.js +34 -0
- package/dist/cjs/bin/cli.js.map +7 -0
- package/dist/cjs/cli/cli.d.ts +1 -0
- package/dist/cjs/cli/cli.js +49 -0
- package/dist/cjs/cli/cli.js.map +7 -0
- package/dist/cjs/cli/commands/generate/command.d.ts +1 -0
- package/dist/cjs/cli/commands/generate/command.js +80 -0
- package/dist/cjs/cli/commands/generate/command.js.map +7 -0
- package/dist/cjs/cli/commands/generate/impl.d.ts +8 -0
- package/dist/cjs/cli/commands/generate/impl.js +66 -0
- package/dist/cjs/cli/commands/generate/impl.js.map +7 -0
- package/dist/cjs/cli/context.d.ts +6 -0
- package/dist/cjs/cli/context.js +45 -0
- package/dist/cjs/cli/context.js.map +7 -0
- package/dist/cjs/config.d.ts +51 -0
- package/dist/cjs/config.js +75 -0
- package/dist/cjs/config.js.map +7 -0
- package/dist/cjs/file-builder.d.ts +13 -0
- package/dist/cjs/file-builder.js +83 -0
- package/dist/cjs/file-builder.js.map +7 -0
- package/dist/cjs/generate-utils.d.ts +1 -0
- package/dist/cjs/generate-utils.js +187 -0
- package/dist/cjs/generate-utils.js.map +7 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.js +124 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/move-module-builder.d.ts +26 -0
- package/dist/cjs/move-module-builder.js +464 -0
- package/dist/cjs/move-module-builder.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/render-types.d.ts +19 -0
- package/dist/cjs/render-types.js +313 -0
- package/dist/cjs/render-types.js.map +7 -0
- package/dist/cjs/summary.d.ts +3 -0
- package/dist/cjs/summary.js +218 -0
- package/dist/cjs/summary.js.map +7 -0
- package/dist/cjs/types/deserialized.d.ts +89 -0
- package/dist/cjs/types/deserialized.js +17 -0
- package/dist/cjs/types/deserialized.js.map +7 -0
- package/dist/cjs/types/summary.d.ts +105 -0
- package/dist/cjs/types/summary.js +17 -0
- package/dist/cjs/types/summary.js.map +7 -0
- package/dist/cjs/utils.d.ts +22 -0
- package/dist/cjs/utils.js +164 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/bin/bash-complete.d.ts +2 -0
- package/dist/esm/bin/bash-complete.js +31 -0
- package/dist/esm/bin/bash-complete.js.map +7 -0
- package/dist/esm/bin/cli.d.ts +2 -0
- package/dist/esm/bin/cli.js +32 -0
- package/dist/esm/bin/cli.js.map +7 -0
- package/dist/esm/cli/cli.d.ts +1 -0
- package/dist/esm/cli/cli.js +29 -0
- package/dist/esm/cli/cli.js.map +7 -0
- package/dist/esm/cli/commands/generate/command.d.ts +1 -0
- package/dist/esm/cli/commands/generate/command.js +50 -0
- package/dist/esm/cli/commands/generate/command.js.map +7 -0
- package/dist/esm/cli/commands/generate/impl.d.ts +8 -0
- package/dist/esm/cli/commands/generate/impl.js +46 -0
- package/dist/esm/cli/commands/generate/impl.js.map +7 -0
- package/dist/esm/cli/context.d.ts +6 -0
- package/dist/esm/cli/context.js +15 -0
- package/dist/esm/cli/context.js.map +7 -0
- package/dist/esm/config.d.ts +51 -0
- package/dist/esm/config.js +45 -0
- package/dist/esm/config.js.map +7 -0
- package/dist/esm/file-builder.d.ts +13 -0
- package/dist/esm/file-builder.js +63 -0
- package/dist/esm/file-builder.js.map +7 -0
- package/dist/esm/generate-utils.d.ts +1 -0
- package/dist/esm/generate-utils.js +167 -0
- package/dist/esm/generate-utils.js.map +7 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +104 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/move-module-builder.d.ts +26 -0
- package/dist/esm/move-module-builder.js +457 -0
- package/dist/esm/move-module-builder.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/render-types.d.ts +19 -0
- package/dist/esm/render-types.js +293 -0
- package/dist/esm/render-types.js.map +7 -0
- package/dist/esm/summary.d.ts +3 -0
- package/dist/esm/summary.js +198 -0
- package/dist/esm/summary.js.map +7 -0
- package/dist/esm/types/deserialized.d.ts +89 -0
- package/dist/esm/types/deserialized.js +1 -0
- package/dist/esm/types/deserialized.js.map +7 -0
- package/dist/esm/types/summary.d.ts +105 -0
- package/dist/esm/types/summary.js +1 -0
- package/dist/esm/types/summary.js.map +7 -0
- package/dist/esm/utils.d.ts +22 -0
- package/dist/esm/utils.js +134 -0
- package/dist/esm/utils.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +70 -0
- package/src/bin/bash-complete.ts +35 -0
- package/src/bin/cli.ts +40 -0
- package/src/cli/cli.ts +29 -0
- package/src/cli/commands/generate/command.ts +50 -0
- package/src/cli/commands/generate/impl.ts +66 -0
- package/src/cli/context.ts +21 -0
- package/src/config.ts +54 -0
- package/src/file-builder.ts +74 -0
- package/src/generate-utils.ts +163 -0
- package/src/index.ts +131 -0
- package/src/move-module-builder.ts +599 -0
- package/src/render-types.ts +349 -0
- package/src/summary.ts +242 -0
- package/src/types/deserialized.ts +107 -0
- package/src/types/summary.ts +144 -0
- package/src/utils.ts +180 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var generate_utils_exports = {};
|
|
20
|
+
__export(generate_utils_exports, {
|
|
21
|
+
utilsContent: () => utilsContent
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(generate_utils_exports);
|
|
24
|
+
const utilsContent = (
|
|
25
|
+
/* ts */
|
|
26
|
+
`
|
|
27
|
+
import { bcs, BcsType, TypeTag, TypeTagSerializer, BcsStruct, BcsEnum, BcsTuple } from '@haneullabs/haneul/bcs';
|
|
28
|
+
import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
|
|
29
|
+
import { TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';
|
|
30
|
+
|
|
31
|
+
const MOVE_STDLIB_ADDRESS = normalizeHaneulAddress('0x1');
|
|
32
|
+
const HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress('0x2');
|
|
33
|
+
const HANEUL_SYSTEM_ADDRESS = normalizeHaneulAddress('0x3');
|
|
34
|
+
|
|
35
|
+
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
36
|
+
|
|
37
|
+
export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {
|
|
38
|
+
const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
|
|
39
|
+
|
|
40
|
+
if ('u8' in parsedTag) {
|
|
41
|
+
return bcs.U8;
|
|
42
|
+
} else if ('u16' in parsedTag) {
|
|
43
|
+
return bcs.U16;
|
|
44
|
+
} else if ('u32' in parsedTag) {
|
|
45
|
+
return bcs.U32;
|
|
46
|
+
} else if ('u64' in parsedTag) {
|
|
47
|
+
return bcs.U64;
|
|
48
|
+
} else if ('u128' in parsedTag) {
|
|
49
|
+
return bcs.U128;
|
|
50
|
+
} else if ('u256' in parsedTag) {
|
|
51
|
+
return bcs.U256;
|
|
52
|
+
} else if ('address' in parsedTag) {
|
|
53
|
+
return bcs.Address;
|
|
54
|
+
} else if ('bool' in parsedTag) {
|
|
55
|
+
return bcs.Bool;
|
|
56
|
+
} else if ('vector' in parsedTag) {
|
|
57
|
+
const type = getPureBcsSchema(parsedTag.vector);
|
|
58
|
+
return type ? bcs.vector(type) : null;
|
|
59
|
+
} else if ('struct' in parsedTag) {
|
|
60
|
+
const structTag = parsedTag.struct;
|
|
61
|
+
const pkg = normalizeHaneulAddress(parsedTag.struct.address);
|
|
62
|
+
|
|
63
|
+
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
64
|
+
if (
|
|
65
|
+
(structTag.module === 'ascii' || structTag.module === 'string') &&
|
|
66
|
+
structTag.name === 'String'
|
|
67
|
+
) {
|
|
68
|
+
return bcs.String;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (structTag.module === 'option' && structTag.name === 'Option') {
|
|
72
|
+
const type = getPureBcsSchema(structTag.typeParams[0]!);
|
|
73
|
+
return type ? bcs.option(type) : null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (pkg === HANEUL_FRAMEWORK_ADDRESS && structTag.module === 'Object' && structTag.name === 'ID') {
|
|
78
|
+
return bcs.Address;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function normalizeMoveArguments(args: unknown[] | object, argTypes: string[], parameterNames?: string[]) {
|
|
86
|
+
const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
|
|
87
|
+
if (parameterNames && argLen !== parameterNames.length) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
\`Invalid number of arguments, expected \${parameterNames.length}, got \${argLen}\`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const normalizedArgs: TransactionArgument[] = [];
|
|
94
|
+
|
|
95
|
+
let index = 0;
|
|
96
|
+
for (const [i, argType] of argTypes.entries()) {
|
|
97
|
+
if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::deny_list::DenyList\`) {
|
|
98
|
+
normalizedArgs.push((tx) => tx.object.denyList());
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::random::Random\`) {
|
|
103
|
+
normalizedArgs.push((tx) => tx.object.random());
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::clock::Clock\`) {
|
|
108
|
+
normalizedArgs.push((tx) => tx.object.clock());
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (argType === \`\${HANEUL_SYSTEM_ADDRESS}::haneul_system::HaneulSystemState\`) {
|
|
113
|
+
normalizedArgs.push((tx) => tx.object.system());
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let arg
|
|
118
|
+
if (Array.isArray(args)) {
|
|
119
|
+
if (index >= args.length) {
|
|
120
|
+
throw new Error(\`Invalid number of arguments, expected at least \${index + 1}, got \${args.length}\`);
|
|
121
|
+
}
|
|
122
|
+
arg = args[index];
|
|
123
|
+
} else {
|
|
124
|
+
if (!parameterNames) {
|
|
125
|
+
throw new Error(\`Expected arguments to be passed as an array\`);
|
|
126
|
+
}
|
|
127
|
+
const name = parameterNames[index];
|
|
128
|
+
arg = args[name as keyof typeof args];
|
|
129
|
+
|
|
130
|
+
if (arg === undefined) {
|
|
131
|
+
throw new Error(\`Parameter \${name} is required\`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
index += 1;
|
|
136
|
+
|
|
137
|
+
if (typeof arg === 'function' || isArgument(arg)) {
|
|
138
|
+
normalizedArgs.push(arg as TransactionArgument);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const type = argTypes[i]!;
|
|
143
|
+
const bcsType = getPureBcsSchema(type);
|
|
144
|
+
|
|
145
|
+
if (bcsType) {
|
|
146
|
+
const bytes = bcsType.serialize(arg as never);
|
|
147
|
+
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
148
|
+
continue;
|
|
149
|
+
} else if (typeof arg === 'string') {
|
|
150
|
+
normalizedArgs.push((tx) => tx.object(arg));
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
throw new Error(\`Invalid argument \${stringify(arg)} for type \${type}\`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return normalizedArgs;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class MoveStruct<
|
|
161
|
+
T extends Record<string, BcsType<any>>,
|
|
162
|
+
const Name extends string = string,
|
|
163
|
+
> extends BcsStruct<T, Name> {}
|
|
164
|
+
|
|
165
|
+
export class MoveEnum<
|
|
166
|
+
T extends Record<string, BcsType<any> | null>,
|
|
167
|
+
const Name extends string,
|
|
168
|
+
> extends BcsEnum<T, Name> {}
|
|
169
|
+
|
|
170
|
+
export class MoveTuple<
|
|
171
|
+
T extends readonly BcsType<any>[],
|
|
172
|
+
const Name extends string,
|
|
173
|
+
> extends BcsTuple<T, Name> {}
|
|
174
|
+
|
|
175
|
+
function stringify(val: unknown) {
|
|
176
|
+
if (typeof val === 'object') {
|
|
177
|
+
return JSON.stringify(val, (val: unknown) => val);
|
|
178
|
+
}
|
|
179
|
+
if (typeof val === 'bigint') {
|
|
180
|
+
return val.toString();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return val;
|
|
184
|
+
}
|
|
185
|
+
`
|
|
186
|
+
);
|
|
187
|
+
//# sourceMappingURL=generate-utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/generate-utils.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport const utilsContent = /* ts */ `\nimport { bcs, BcsType, TypeTag, TypeTagSerializer, BcsStruct, BcsEnum, BcsTuple } from '@haneullabs/haneul/bcs';\nimport { normalizeHaneulAddress } from '@haneullabs/haneul/utils';\nimport { TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';\n\nconst MOVE_STDLIB_ADDRESS = normalizeHaneulAddress('0x1');\nconst HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress('0x2');\nconst HANEUL_SYSTEM_ADDRESS = normalizeHaneulAddress('0x3');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeHaneulAddress(parsedTag.struct.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst type = getPureBcsSchema(structTag.typeParams[0]!);\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (pkg === HANEUL_FRAMEWORK_ADDRESS && structTag.module === 'Object' && structTag.name === 'ID') {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(args: unknown[] | object, argTypes: string[], parameterNames?: string[]) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t\\`Invalid number of arguments, expected \\${parameterNames.length}, got \\${argLen}\\`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const [i, argType] of argTypes.entries()) {\n\t\tif (argType === \\`\\${HANEUL_FRAMEWORK_ADDRESS}::deny_list::DenyList\\`) {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === \\`\\${HANEUL_FRAMEWORK_ADDRESS}::random::Random\\`) {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === \\`\\${HANEUL_FRAMEWORK_ADDRESS}::clock::Clock\\`) {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === \\`\\${HANEUL_SYSTEM_ADDRESS}::haneul_system::HaneulSystemState\\`) {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\\`Invalid number of arguments, expected at least \\${index + 1}, got \\${args.length}\\`);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(\\`Expected arguments to be passed as an array\\`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(\\`Parameter \\${name} is required\\`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst type = argTypes[i]!;\n\t\tconst bcsType = getPureBcsSchema(type);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t} else if (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(\\`Invalid argument \\${stringify(arg)} for type \\${type}\\`);\n\t}\n\n\treturn normalizedArgs;\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {}\n\nexport class MoveTuple<\n\tT extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (val: unknown) => val);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n`;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM;AAAA;AAAA,EAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PackageConfig } from './config.js';
|
|
2
|
+
export { type HaneulCodegenConfig } from './config.js';
|
|
3
|
+
export declare function generateFromPackageSummary({ package: pkg, prune, outputDir, privateMethods, }: {
|
|
4
|
+
package: PackageConfig;
|
|
5
|
+
prune: boolean;
|
|
6
|
+
outputDir: string;
|
|
7
|
+
privateMethods: 'none' | 'entry' | 'all';
|
|
8
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
generateFromPackageSummary: () => generateFromPackageSummary
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(index_exports);
|
|
24
|
+
var import_promises = require("node:fs/promises");
|
|
25
|
+
var import_node_path = require("node:path");
|
|
26
|
+
var import_move_module_builder = require("./move-module-builder.js");
|
|
27
|
+
var import_node_fs = require("node:fs");
|
|
28
|
+
var import_generate_utils = require("./generate-utils.js");
|
|
29
|
+
var import_toml = require("toml");
|
|
30
|
+
async function generateFromPackageSummary({
|
|
31
|
+
package: pkg,
|
|
32
|
+
prune,
|
|
33
|
+
outputDir,
|
|
34
|
+
privateMethods
|
|
35
|
+
}) {
|
|
36
|
+
if (!pkg.path) {
|
|
37
|
+
throw new Error(`On-chain packages are not supported yet (got ${pkg.package})`);
|
|
38
|
+
}
|
|
39
|
+
const summaryDir = (0, import_node_path.join)(pkg.path, "package_summaries");
|
|
40
|
+
if (!(0, import_node_fs.existsSync)(summaryDir)) {
|
|
41
|
+
throw new Error(`Package summary directory not found: ${summaryDir}`);
|
|
42
|
+
}
|
|
43
|
+
let packageName = pkg.packageName;
|
|
44
|
+
const mvrNameOrAddress = pkg.package;
|
|
45
|
+
if (!pkg.packageName) {
|
|
46
|
+
try {
|
|
47
|
+
const packageToml = await (0, import_promises.readFile)((0, import_node_path.join)(pkg.path, "Move.toml"), "utf-8");
|
|
48
|
+
packageName = (0, import_toml.parse)(packageToml).package.name.toLowerCase();
|
|
49
|
+
} catch {
|
|
50
|
+
const message = `Package name not found in package.toml for ${pkg.path}`;
|
|
51
|
+
if (packageName) {
|
|
52
|
+
console.warn(message);
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error(message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!(0, import_node_fs.existsSync)(summaryDir)) {
|
|
59
|
+
throw new Error(`Package summary directory not found: ${summaryDir}`);
|
|
60
|
+
}
|
|
61
|
+
const addressMappings = JSON.parse(
|
|
62
|
+
await (0, import_promises.readFile)((0, import_node_path.join)(summaryDir, "address_mapping.json"), "utf-8")
|
|
63
|
+
);
|
|
64
|
+
const packages = (await (0, import_promises.readdir)(summaryDir)).filter(
|
|
65
|
+
(file) => (0, import_node_fs.statSync)((0, import_node_path.join)(summaryDir, file)).isDirectory()
|
|
66
|
+
);
|
|
67
|
+
const modules = (await Promise.all(
|
|
68
|
+
packages.map(async (pkg2) => {
|
|
69
|
+
const modules2 = await (0, import_promises.readdir)((0, import_node_path.join)(summaryDir, pkg2));
|
|
70
|
+
return Promise.all(
|
|
71
|
+
modules2.map(async (mod) => ({
|
|
72
|
+
package: pkg2,
|
|
73
|
+
isMainPackage: pkg2 === packageName,
|
|
74
|
+
module: (0, import_node_path.basename)(mod, ".json"),
|
|
75
|
+
builder: await import_move_module_builder.MoveModuleBuilder.fromSummaryFile(
|
|
76
|
+
(0, import_node_path.join)(summaryDir, pkg2, mod),
|
|
77
|
+
addressMappings,
|
|
78
|
+
pkg2 === packageName ? mvrNameOrAddress : void 0
|
|
79
|
+
)
|
|
80
|
+
}))
|
|
81
|
+
);
|
|
82
|
+
})
|
|
83
|
+
)).flat();
|
|
84
|
+
const moduleBuilders = Object.fromEntries(
|
|
85
|
+
modules.map((mod) => [`${mod.package}::${mod.module}`, mod.builder])
|
|
86
|
+
);
|
|
87
|
+
modules.forEach((mod) => {
|
|
88
|
+
if (mod.isMainPackage || !prune) {
|
|
89
|
+
mod.builder.includeAllTypes(moduleBuilders);
|
|
90
|
+
mod.builder.includeAllFunctions({ privateMethods });
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
await generateUtils({ outputDir });
|
|
94
|
+
await Promise.all(
|
|
95
|
+
modules.map(async (mod) => {
|
|
96
|
+
if ((mod.isMainPackage || !prune) && mod.builder.hasTypesOrFunctions()) {
|
|
97
|
+
await mod.builder.renderBCSTypes();
|
|
98
|
+
await mod.builder.renderFunctions();
|
|
99
|
+
} else if (mod.isMainPackage) {
|
|
100
|
+
return;
|
|
101
|
+
} else if (mod.builder.hasBcsTypes()) {
|
|
102
|
+
await mod.builder.renderBCSTypes();
|
|
103
|
+
} else {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
await (0, import_promises.mkdir)(
|
|
107
|
+
mod.isMainPackage ? (0, import_node_path.join)(outputDir, packageName) : (0, import_node_path.join)(outputDir, packageName, "deps", mod.package),
|
|
108
|
+
{ recursive: true }
|
|
109
|
+
);
|
|
110
|
+
await (0, import_promises.writeFile)(
|
|
111
|
+
mod.isMainPackage ? (0, import_node_path.join)(outputDir, packageName, `${mod.module}.ts`) : (0, import_node_path.join)(outputDir, packageName, "deps", mod.package, `${mod.module}.ts`),
|
|
112
|
+
await mod.builder.toString(
|
|
113
|
+
"./",
|
|
114
|
+
mod.isMainPackage ? `./${mod.module}.ts` : `./deps/${mod.package}/${mod.module}.ts`
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
async function generateUtils({ outputDir }) {
|
|
121
|
+
await (0, import_promises.mkdir)((0, import_node_path.join)(outputDir, "utils"), { recursive: true });
|
|
122
|
+
await (0, import_promises.writeFile)((0, import_node_path.join)(outputDir, "utils", "index.ts"), import_generate_utils.utilsContent);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';\nimport { basename, join } from 'node:path';\nimport { MoveModuleBuilder } from './move-module-builder.js';\nimport { existsSync, statSync } from 'node:fs';\nimport { utilsContent } from './generate-utils.js';\nimport { parse } from 'toml';\nimport type { PackageConfig } from './config.js';\nexport { type HaneulCodegenConfig } from './config.js';\n\nexport async function generateFromPackageSummary({\n\tpackage: pkg,\n\tprune,\n\toutputDir,\n\tprivateMethods,\n}: {\n\tpackage: PackageConfig;\n\tprune: boolean;\n\toutputDir: string;\n\tprivateMethods: 'none' | 'entry' | 'all';\n}) {\n\tif (!pkg.path) {\n\t\tthrow new Error(`On-chain packages are not supported yet (got ${pkg.package})`);\n\t}\n\n\tconst summaryDir = join(pkg.path, 'package_summaries');\n\n\tif (!existsSync(summaryDir)) {\n\t\tthrow new Error(`Package summary directory not found: ${summaryDir}`);\n\t}\n\n\tlet packageName = pkg.packageName!;\n\tconst mvrNameOrAddress = pkg.package;\n\n\tif (!pkg.packageName) {\n\t\ttry {\n\t\t\tconst packageToml = await readFile(join(pkg.path, 'Move.toml'), 'utf-8');\n\t\t\tpackageName = parse(packageToml).package.name.toLowerCase();\n\t\t} catch {\n\t\t\tconst message = `Package name not found in package.toml for ${pkg.path}`;\n\t\t\tif (packageName) {\n\t\t\t\tconsole.warn(message);\n\t\t\t} else {\n\t\t\t\tthrow new Error(message);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!existsSync(summaryDir)) {\n\t\tthrow new Error(`Package summary directory not found: ${summaryDir}`);\n\t}\n\n\tconst addressMappings: Record<string, string> = JSON.parse(\n\t\tawait readFile(join(summaryDir, 'address_mapping.json'), 'utf-8'),\n\t);\n\n\tconst packages = (await readdir(summaryDir)).filter((file) =>\n\t\tstatSync(join(summaryDir, file)).isDirectory(),\n\t);\n\tconst modules = (\n\t\tawait Promise.all(\n\t\t\tpackages.map(async (pkg) => {\n\t\t\t\tconst modules = await readdir(join(summaryDir, pkg));\n\t\t\t\treturn Promise.all(\n\t\t\t\t\tmodules.map(async (mod) => ({\n\t\t\t\t\t\tpackage: pkg,\n\t\t\t\t\t\tisMainPackage: pkg === packageName,\n\t\t\t\t\t\tmodule: basename(mod, '.json'),\n\t\t\t\t\t\tbuilder: await MoveModuleBuilder.fromSummaryFile(\n\t\t\t\t\t\t\tjoin(summaryDir, pkg, mod),\n\t\t\t\t\t\t\taddressMappings,\n\t\t\t\t\t\t\tpkg === packageName ? mvrNameOrAddress : undefined,\n\t\t\t\t\t\t),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}),\n\t\t)\n\t).flat();\n\n\tconst moduleBuilders = Object.fromEntries(\n\t\tmodules.map((mod) => [`${mod.package}::${mod.module}`, mod.builder]),\n\t);\n\n\tmodules.forEach((mod) => {\n\t\tif (mod.isMainPackage || !prune) {\n\t\t\tmod.builder.includeAllTypes(moduleBuilders);\n\t\t\tmod.builder.includeAllFunctions({ privateMethods });\n\t\t}\n\t});\n\n\tawait generateUtils({ outputDir });\n\n\tawait Promise.all(\n\t\tmodules.map(async (mod) => {\n\t\t\tif ((mod.isMainPackage || !prune) && mod.builder.hasTypesOrFunctions()) {\n\t\t\t\tawait mod.builder.renderBCSTypes();\n\t\t\t\tawait mod.builder.renderFunctions();\n\t\t\t} else if (mod.isMainPackage) {\n\t\t\t\treturn;\n\t\t\t} else if (mod.builder.hasBcsTypes()) {\n\t\t\t\tawait mod.builder.renderBCSTypes();\n\t\t\t} else {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tawait mkdir(\n\t\t\t\tmod.isMainPackage\n\t\t\t\t\t? join(outputDir, packageName)\n\t\t\t\t\t: join(outputDir, packageName, 'deps', mod.package),\n\t\t\t\t{ recursive: true },\n\t\t\t);\n\n\t\t\tawait writeFile(\n\t\t\t\tmod.isMainPackage\n\t\t\t\t\t? join(outputDir, packageName, `${mod.module}.ts`)\n\t\t\t\t\t: join(outputDir, packageName, 'deps', mod.package, `${mod.module}.ts`),\n\t\t\t\tawait mod.builder.toString(\n\t\t\t\t\t'./',\n\t\t\t\t\tmod.isMainPackage ? `./${mod.module}.ts` : `./deps/${mod.package}/${mod.module}.ts`,\n\t\t\t\t),\n\t\t\t);\n\t\t}),\n\t);\n}\n\nasync function generateUtils({ outputDir }: { outputDir: string }) {\n\tawait mkdir(join(outputDir, 'utils'), { recursive: true });\n\tawait writeFile(join(outputDir, 'utils', 'index.ts'), utilsContent);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAoD;AACpD,uBAA+B;AAC/B,iCAAkC;AAClC,qBAAqC;AACrC,4BAA6B;AAC7B,kBAAsB;AAItB,eAAsB,2BAA2B;AAAA,EAChD,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACD,GAKG;AACF,MAAI,CAAC,IAAI,MAAM;AACd,UAAM,IAAI,MAAM,gDAAgD,IAAI,OAAO,GAAG;AAAA,EAC/E;AAEA,QAAM,iBAAa,uBAAK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F;AACD;AAEA,eAAe,cAAc,EAAE,UAAU,GAA0B;AAClE,YAAM,2BAAM,uBAAK,WAAW,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,YAAM,+BAAU,uBAAK,WAAW,SAAS,UAAU,GAAG,kCAAY;AACnE;",
|
|
6
|
+
"names": ["pkg", "modules"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FileBuilder } from './file-builder.js';
|
|
2
|
+
import type { ModuleSummary, Type } from './types/summary.js';
|
|
3
|
+
export declare class MoveModuleBuilder extends FileBuilder {
|
|
4
|
+
#private;
|
|
5
|
+
summary: ModuleSummary;
|
|
6
|
+
constructor({ mvrNameOrAddress, summary, addressMappings, }: {
|
|
7
|
+
summary: ModuleSummary;
|
|
8
|
+
addressMappings?: Record<string, string>;
|
|
9
|
+
mvrNameOrAddress?: string;
|
|
10
|
+
});
|
|
11
|
+
static fromSummaryFile(file: string, addressMappings: Record<string, string>, mvrNameOrAddress?: string): Promise<MoveModuleBuilder>;
|
|
12
|
+
getHeader(): Promise<string>;
|
|
13
|
+
includeAllFunctions({ privateMethods }: {
|
|
14
|
+
privateMethods?: 'none' | 'entry' | 'all';
|
|
15
|
+
}): void;
|
|
16
|
+
includeType(name: string, moduleBuilders: Record<string, MoveModuleBuilder>): void;
|
|
17
|
+
includeAllTypes(moduleBuilders: Record<string, MoveModuleBuilder>): void;
|
|
18
|
+
renderBCSTypes(): Promise<void>;
|
|
19
|
+
hasBcsTypes(): boolean;
|
|
20
|
+
hasFunctions(): boolean;
|
|
21
|
+
hasTypesOrFunctions(): boolean;
|
|
22
|
+
renderStruct(name: string): Promise<void>;
|
|
23
|
+
renderEnum(name: string): Promise<void>;
|
|
24
|
+
renderFunctions(): Promise<void>;
|
|
25
|
+
isContextReference(type: Type): boolean;
|
|
26
|
+
}
|