@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,464 @@
|
|
|
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 __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
+
var move_module_builder_exports = {};
|
|
28
|
+
__export(move_module_builder_exports, {
|
|
29
|
+
MoveModuleBuilder: () => MoveModuleBuilder
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(move_module_builder_exports);
|
|
32
|
+
var import_file_builder = require("./file-builder.js");
|
|
33
|
+
var import_promises = require("node:fs/promises");
|
|
34
|
+
var import_render_types = require("./render-types.js");
|
|
35
|
+
var import_utils = require("./utils.js");
|
|
36
|
+
var import_node_path = require("node:path");
|
|
37
|
+
var _depsDir, _addressMappings, _includedTypes, _includedFunctions, _orderedTypes, _mvrNameOrAddress, _MoveModuleBuilder_instances, resolveAddress_fn, getModuleTypeName_fn, renderFieldsAsStruct_fn, renderFieldsAsTuple_fn;
|
|
38
|
+
const _MoveModuleBuilder = class _MoveModuleBuilder extends import_file_builder.FileBuilder {
|
|
39
|
+
constructor({
|
|
40
|
+
mvrNameOrAddress,
|
|
41
|
+
summary,
|
|
42
|
+
addressMappings = {}
|
|
43
|
+
}) {
|
|
44
|
+
super();
|
|
45
|
+
__privateAdd(this, _MoveModuleBuilder_instances);
|
|
46
|
+
__privateAdd(this, _depsDir, "./deps");
|
|
47
|
+
__privateAdd(this, _addressMappings);
|
|
48
|
+
__privateAdd(this, _includedTypes, /* @__PURE__ */ new Set());
|
|
49
|
+
__privateAdd(this, _includedFunctions, /* @__PURE__ */ new Set());
|
|
50
|
+
__privateAdd(this, _orderedTypes, []);
|
|
51
|
+
__privateAdd(this, _mvrNameOrAddress);
|
|
52
|
+
this.summary = summary;
|
|
53
|
+
__privateSet(this, _addressMappings, addressMappings);
|
|
54
|
+
__privateSet(this, _mvrNameOrAddress, mvrNameOrAddress);
|
|
55
|
+
}
|
|
56
|
+
static async fromSummaryFile(file, addressMappings, mvrNameOrAddress) {
|
|
57
|
+
const summary = JSON.parse(await (0, import_promises.readFile)(file, "utf-8"));
|
|
58
|
+
return new _MoveModuleBuilder({
|
|
59
|
+
summary,
|
|
60
|
+
addressMappings,
|
|
61
|
+
mvrNameOrAddress
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async getHeader() {
|
|
65
|
+
if (!this.summary.doc) {
|
|
66
|
+
return super.getHeader();
|
|
67
|
+
}
|
|
68
|
+
return `${await super.getHeader()}
|
|
69
|
+
|
|
70
|
+
/*${await (0, import_utils.formatComment)(this.summary.doc)}*/
|
|
71
|
+
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
includeAllFunctions({ privateMethods = "entry" }) {
|
|
75
|
+
for (const [name, func] of Object.entries(this.summary.functions)) {
|
|
76
|
+
if (func.macro_) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (func.visibility !== "Public") {
|
|
80
|
+
switch (privateMethods) {
|
|
81
|
+
case "none":
|
|
82
|
+
continue;
|
|
83
|
+
case "entry":
|
|
84
|
+
if (!func.entry) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "all":
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
throw new Error(`Unknown privateMethods option: ${privateMethods}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const safeName = (0, import_render_types.getSafeName)((0, import_utils.camelCase)(name));
|
|
95
|
+
this.reservedNames.add(safeName);
|
|
96
|
+
__privateGet(this, _includedFunctions).add(name);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
includeType(name, moduleBuilders) {
|
|
100
|
+
if (__privateGet(this, _includedTypes).has(name)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
__privateGet(this, _includedTypes).add(name);
|
|
104
|
+
this.reservedNames.add(name);
|
|
105
|
+
const struct = this.summary.structs[name];
|
|
106
|
+
const enum_ = this.summary.enums[name];
|
|
107
|
+
if (!struct && !enum_) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Type ${name} not found in ${this.summary.id.address}::${this.summary.id.name}`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (struct) {
|
|
113
|
+
Object.values(struct.fields.fields).forEach((field) => {
|
|
114
|
+
(0, import_render_types.renderTypeSignature)(field.type_, {
|
|
115
|
+
format: "bcs",
|
|
116
|
+
summary: this.summary,
|
|
117
|
+
typeParameters: struct.type_parameters,
|
|
118
|
+
resolveAddress: (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address),
|
|
119
|
+
onDependency: (address, mod, name2) => {
|
|
120
|
+
const builder = moduleBuilders[`${address}::${mod}`];
|
|
121
|
+
if (!builder) {
|
|
122
|
+
throw new Error(`Module builder not found for ${address}::${mod}`);
|
|
123
|
+
}
|
|
124
|
+
builder.includeType(name2, moduleBuilders);
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (enum_) {
|
|
131
|
+
Object.values(enum_.variants).forEach((variant) => {
|
|
132
|
+
Object.values(variant.fields.fields).forEach((field) => {
|
|
133
|
+
(0, import_render_types.renderTypeSignature)(field.type_, {
|
|
134
|
+
format: "bcs",
|
|
135
|
+
summary: this.summary,
|
|
136
|
+
typeParameters: enum_.type_parameters,
|
|
137
|
+
resolveAddress: (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address),
|
|
138
|
+
onDependency: (address, mod, name2) => {
|
|
139
|
+
const builder = moduleBuilders[`${address}::${mod}`];
|
|
140
|
+
if (!builder) {
|
|
141
|
+
throw new Error(`Module builder not found for ${address}::${mod}`);
|
|
142
|
+
}
|
|
143
|
+
builder.includeType(name2, moduleBuilders);
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
__privateGet(this, _orderedTypes).push(name);
|
|
151
|
+
}
|
|
152
|
+
includeAllTypes(moduleBuilders) {
|
|
153
|
+
Object.keys(this.summary.structs).forEach((name) => this.includeType(name, moduleBuilders));
|
|
154
|
+
Object.keys(this.summary.enums).forEach((name) => this.includeType(name, moduleBuilders));
|
|
155
|
+
}
|
|
156
|
+
async renderBCSTypes() {
|
|
157
|
+
if (this.hasBcsTypes()) {
|
|
158
|
+
this.statements.push(
|
|
159
|
+
...import_utils.parseTS`
|
|
160
|
+
const $moduleName = '${__privateMethod(this, _MoveModuleBuilder_instances, getModuleTypeName_fn).call(this)}::${this.summary.id.name}';
|
|
161
|
+
`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
for (const name of __privateGet(this, _orderedTypes)) {
|
|
165
|
+
if (this.summary.structs[name]) {
|
|
166
|
+
await this.renderStruct(name);
|
|
167
|
+
} else if (this.summary.enums[name]) {
|
|
168
|
+
await this.renderEnum(name);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
hasBcsTypes() {
|
|
173
|
+
return __privateGet(this, _includedTypes).size > 0;
|
|
174
|
+
}
|
|
175
|
+
hasFunctions() {
|
|
176
|
+
return __privateGet(this, _includedFunctions).size > 0;
|
|
177
|
+
}
|
|
178
|
+
hasTypesOrFunctions() {
|
|
179
|
+
return this.hasBcsTypes() || this.hasFunctions();
|
|
180
|
+
}
|
|
181
|
+
async renderStruct(name) {
|
|
182
|
+
if (!__privateGet(this, _includedTypes).has(name)) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const struct = this.summary.structs[name];
|
|
186
|
+
if (!struct) {
|
|
187
|
+
throw new Error(
|
|
188
|
+
`Struct ${name} not found in ${this.summary.id.address}::${this.summary.id.name}`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
this.exports.push(name);
|
|
192
|
+
const params = struct.type_parameters.filter((param) => !param.phantom);
|
|
193
|
+
const structName = `\${$moduleName}::${name}`;
|
|
194
|
+
if (params.length === 0) {
|
|
195
|
+
this.statements.push(
|
|
196
|
+
...import_utils.parseTS`export const ${name} = ${struct.fields.positional_fields ? await __privateMethod(this, _MoveModuleBuilder_instances, renderFieldsAsTuple_fn).call(this, structName, struct.fields, struct.type_parameters) : await __privateMethod(this, _MoveModuleBuilder_instances, renderFieldsAsStruct_fn).call(this, structName, struct.fields, struct.type_parameters)}`
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
this.addImport("@haneullabs/haneul/bcs", "type BcsType");
|
|
200
|
+
const typeParams = `...typeParameters: [${params.map((param, i) => param.name ?? `T${i}`).join(", ")}]`;
|
|
201
|
+
const typeGenerics = `${params.map((param, i) => `${param.name ?? `T${i}`} extends BcsType<any>`).join(", ")}`;
|
|
202
|
+
const nameGenerics = `${params.map((param, i) => `\${typeParameters[${i}].name as ${param.name ?? `T${i}`}['name']}`).join(", ")}`;
|
|
203
|
+
this.statements.push(
|
|
204
|
+
...await (0, import_utils.withComment)(
|
|
205
|
+
struct,
|
|
206
|
+
import_utils.parseTS`export function ${name}<${typeGenerics}>(${typeParams}) {
|
|
207
|
+
return ${struct.fields.positional_fields ? await __privateMethod(this, _MoveModuleBuilder_instances, renderFieldsAsTuple_fn).call(this, `${structName}<${nameGenerics}>`, struct.fields, struct.type_parameters) : await __privateMethod(this, _MoveModuleBuilder_instances, renderFieldsAsStruct_fn).call(this, `${structName}<${nameGenerics}>`, struct.fields, struct.type_parameters)}
|
|
208
|
+
}`
|
|
209
|
+
)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async renderEnum(name) {
|
|
214
|
+
if (!__privateGet(this, _includedTypes).has(name)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const enumDef = this.summary.enums[name];
|
|
218
|
+
if (!enumDef) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
`Enum ${name} not found in ${this.summary.id.address}::${this.summary.id.name}`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
this.addImport("~root/../utils/index.js", "MoveEnum");
|
|
224
|
+
this.exports.push(name);
|
|
225
|
+
const enumName = `\${$moduleName}::${name}`;
|
|
226
|
+
const variantsObject = await (0, import_utils.mapToObject)({
|
|
227
|
+
items: Object.entries(enumDef.variants),
|
|
228
|
+
getComment: ([_name, variant]) => variant.doc,
|
|
229
|
+
mapper: async ([variantName, variant]) => [
|
|
230
|
+
variantName,
|
|
231
|
+
Object.keys(variant.fields.fields).length === 0 ? "null" : isPositional(variant.fields) ? Object.keys(variant.fields.fields).length === 1 ? (0, import_render_types.renderTypeSignature)(Object.values(variant.fields.fields)[0].type_, {
|
|
232
|
+
format: "bcs",
|
|
233
|
+
summary: this.summary,
|
|
234
|
+
typeParameters: enumDef.type_parameters,
|
|
235
|
+
onBcsType: () => {
|
|
236
|
+
this.addImport("@haneullabs/haneul/bcs", "bcs");
|
|
237
|
+
},
|
|
238
|
+
resolveAddress: (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address),
|
|
239
|
+
onDependency: (address, mod) => {
|
|
240
|
+
if (address !== this.summary.id.address || mod !== this.summary.id.name) {
|
|
241
|
+
return this.addStarImport(
|
|
242
|
+
address === this.summary.id.address ? `./${mod}.js` : `~root/deps/${address}/${mod}.js`,
|
|
243
|
+
mod
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
}) : await __privateMethod(this, _MoveModuleBuilder_instances, renderFieldsAsTuple_fn).call(this, `${name}.${variantName}`, variant.fields, enumDef.type_parameters) : await __privateMethod(this, _MoveModuleBuilder_instances, renderFieldsAsStruct_fn).call(this, `${name}.${variantName}`, variant.fields, enumDef.type_parameters)
|
|
249
|
+
]
|
|
250
|
+
});
|
|
251
|
+
const params = enumDef.type_parameters.filter((param) => !param.phantom);
|
|
252
|
+
if (params.length === 0) {
|
|
253
|
+
this.statements.push(
|
|
254
|
+
...await (0, import_utils.withComment)(
|
|
255
|
+
enumDef,
|
|
256
|
+
import_utils.parseTS`export const ${name} = new MoveEnum({ name: \`${enumName}\`, fields: ${variantsObject} })`
|
|
257
|
+
)
|
|
258
|
+
);
|
|
259
|
+
} else {
|
|
260
|
+
this.addImport("@haneullabs/haneul/bcs", "type BcsType");
|
|
261
|
+
const typeParams = `...typeParameters: [${params.map((param, i) => param.name ?? `T${i}`).join(", ")}]`;
|
|
262
|
+
const typeGenerics = `${params.map((param, i) => `${param.name ?? `T${i}`} extends BcsType<any>`).join(", ")}`;
|
|
263
|
+
const nameGenerics = `${params.map((param, i) => `\${typeParameters[${i}].name as ${param.name ?? `T${i}`}['name']}`).join(", ")}`;
|
|
264
|
+
this.statements.push(
|
|
265
|
+
...await (0, import_utils.withComment)(
|
|
266
|
+
enumDef,
|
|
267
|
+
import_utils.parseTS`
|
|
268
|
+
export function ${name}<${typeGenerics}>(${typeParams}) {
|
|
269
|
+
return new MoveEnum({ name: \`${enumName}<${nameGenerics}>\`, fields: ${variantsObject} })
|
|
270
|
+
}`
|
|
271
|
+
)
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async renderFunctions() {
|
|
276
|
+
const names = [];
|
|
277
|
+
if (!this.hasFunctions()) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this.addImport("@haneullabs/haneul/transactions", "type Transaction");
|
|
281
|
+
for (const [name, func] of Object.entries(this.summary.functions)) {
|
|
282
|
+
if (func.macro_ || !__privateGet(this, _includedFunctions).has(name)) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const parameters = func.parameters.filter((param) => !this.isContextReference(param.type_));
|
|
286
|
+
const hasAllParameterNames = parameters.length > 0 && parameters.every(
|
|
287
|
+
(param, i) => param.name && parameters.findIndex((p) => p.name === param.name) === i
|
|
288
|
+
);
|
|
289
|
+
const fnName = (0, import_render_types.getSafeName)((0, import_utils.camelCase)(name));
|
|
290
|
+
const requiredParameters = parameters.filter(
|
|
291
|
+
(param) => !(0, import_utils.isWellKnownObjectParameter)(param.type_, (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address))
|
|
292
|
+
);
|
|
293
|
+
if (parameters.length > 0) {
|
|
294
|
+
this.addImport("~root/../utils/index.js", "normalizeMoveArguments");
|
|
295
|
+
}
|
|
296
|
+
names.push(fnName);
|
|
297
|
+
const usedTypeParameters = /* @__PURE__ */ new Set();
|
|
298
|
+
const argumentsTypes = requiredParameters.map(
|
|
299
|
+
(param) => (0, import_render_types.renderTypeSignature)(param.type_, {
|
|
300
|
+
format: "typescriptArg",
|
|
301
|
+
summary: this.summary,
|
|
302
|
+
typeParameters: func.type_parameters,
|
|
303
|
+
resolveAddress: (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address),
|
|
304
|
+
onTypeParameter: (typeParameter) => usedTypeParameters.add(typeParameter)
|
|
305
|
+
})
|
|
306
|
+
).map(
|
|
307
|
+
(type, i) => requiredParameters[i].name ? `${(0, import_utils.camelCase)(requiredParameters[i].name)}: RawTransactionArgument<${type}>` : `RawTransactionArgument<${type}>`
|
|
308
|
+
).join(",\n");
|
|
309
|
+
if (argumentsTypes.length > 0) {
|
|
310
|
+
this.addImport("~root/../utils/index.js", "type RawTransactionArgument");
|
|
311
|
+
}
|
|
312
|
+
if (usedTypeParameters.size > 0) {
|
|
313
|
+
this.addImport("@haneullabs/haneul/bcs", "type BcsType");
|
|
314
|
+
}
|
|
315
|
+
const filteredTypeParameters = func.type_parameters.filter(
|
|
316
|
+
(param, i) => usedTypeParameters.has(i) || param.name && usedTypeParameters.has(param.name)
|
|
317
|
+
);
|
|
318
|
+
const genericTypes = filteredTypeParameters.length > 0 ? `<${filteredTypeParameters.map((param, i) => `${param.name ?? `T${i}`} extends BcsType<any>`).join(", ")}>` : "";
|
|
319
|
+
const genericTypeArgs = filteredTypeParameters.length > 0 ? `<${filteredTypeParameters.map((param, i) => `${param.name ?? `T${i}`}`).join(", ")}>` : "";
|
|
320
|
+
const argumentsInterface = this.getUnusedName(
|
|
321
|
+
`${(0, import_utils.capitalize)(fnName.replace(/^_/, ""))}Arguments`
|
|
322
|
+
);
|
|
323
|
+
if (hasAllParameterNames) {
|
|
324
|
+
this.statements.push(
|
|
325
|
+
...import_utils.parseTS`export interface ${argumentsInterface}${genericTypes} {
|
|
326
|
+
${argumentsTypes}
|
|
327
|
+
}`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
const optionsInterface = this.getUnusedName(`${(0, import_utils.capitalize)(fnName.replace(/^_/, ""))}Options`);
|
|
331
|
+
const requiresOptions = argumentsTypes.length > 0 || func.type_parameters.length > 0;
|
|
332
|
+
this.statements.push(
|
|
333
|
+
...import_utils.parseTS`export interface ${optionsInterface}${genericTypes} {
|
|
334
|
+
package${__privateGet(this, _mvrNameOrAddress) ? "?: string" : ": string"}
|
|
335
|
+
${argumentsTypes.length > 0 ? "arguments: " : "arguments?: "}${hasAllParameterNames ? `${argumentsInterface}${genericTypeArgs} | [${argumentsTypes}]` : `[${argumentsTypes}]`},
|
|
336
|
+
${func.type_parameters.length ? `typeArguments: [${func.type_parameters.map(() => "string").join(", ")}]` : ""}
|
|
337
|
+
}`
|
|
338
|
+
);
|
|
339
|
+
this.statements.push(
|
|
340
|
+
...await (0, import_utils.withComment)(
|
|
341
|
+
func,
|
|
342
|
+
import_utils.parseTS`export function ${fnName}${genericTypes}(options: ${optionsInterface}${genericTypeArgs}${requiresOptions ? "" : " = {}"}) {
|
|
343
|
+
const packageAddress = options.package${__privateGet(this, _mvrNameOrAddress) ? ` ?? '${__privateGet(this, _mvrNameOrAddress)}'` : ""};
|
|
344
|
+
${parameters.length > 0 ? `const argumentsTypes = [
|
|
345
|
+
${parameters.map(
|
|
346
|
+
(param) => (0, import_render_types.renderTypeSignature)(param.type_, {
|
|
347
|
+
format: "typeTag",
|
|
348
|
+
summary: this.summary,
|
|
349
|
+
typeParameters: func.type_parameters,
|
|
350
|
+
resolveAddress: (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address)
|
|
351
|
+
})
|
|
352
|
+
).map((tag) => tag.includes("{") ? `\`${tag}\`` : `'${tag}'`).join(",\n")}
|
|
353
|
+
] satisfies string[]
|
|
354
|
+
` : ""}${hasAllParameterNames ? `const parameterNames = ${JSON.stringify(requiredParameters.map((param) => (0, import_utils.camelCase)(param.name)))}
|
|
355
|
+
` : ""}
|
|
356
|
+
return (tx: Transaction) => tx.moveCall({
|
|
357
|
+
package: packageAddress,
|
|
358
|
+
module: '${this.summary.id.name}',
|
|
359
|
+
function: '${name}',
|
|
360
|
+
${parameters.length > 0 ? `arguments: normalizeMoveArguments(options.arguments${argumentsTypes.length > 0 ? "" : " ?? []"} , argumentsTypes${hasAllParameterNames ? `, parameterNames` : ""}),` : ""}
|
|
361
|
+
${func.type_parameters.length ? "typeArguments: options.typeArguments" : ""}
|
|
362
|
+
})
|
|
363
|
+
}`
|
|
364
|
+
)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
isContextReference(type) {
|
|
369
|
+
if (typeof type === "string") {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
if ("Reference" in type) {
|
|
373
|
+
return this.isContextReference(type.Reference[1]);
|
|
374
|
+
}
|
|
375
|
+
if ("Datatype" in type) {
|
|
376
|
+
return __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, type.Datatype.module.address) === import_render_types.HANEUL_FRAMEWORK_ADDRESS && type.Datatype.module.name === "tx_context" && type.Datatype.name === "TxContext";
|
|
377
|
+
}
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
_depsDir = new WeakMap();
|
|
382
|
+
_addressMappings = new WeakMap();
|
|
383
|
+
_includedTypes = new WeakMap();
|
|
384
|
+
_includedFunctions = new WeakMap();
|
|
385
|
+
_orderedTypes = new WeakMap();
|
|
386
|
+
_mvrNameOrAddress = new WeakMap();
|
|
387
|
+
_MoveModuleBuilder_instances = new WeakSet();
|
|
388
|
+
resolveAddress_fn = function(address) {
|
|
389
|
+
return __privateGet(this, _addressMappings)[address] ?? address;
|
|
390
|
+
};
|
|
391
|
+
getModuleTypeName_fn = function() {
|
|
392
|
+
const resolvedAddress = __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, this.summary.id.address);
|
|
393
|
+
if (resolvedAddress === import_render_types.HANEUL_FRAMEWORK_ADDRESS) {
|
|
394
|
+
return "0x2";
|
|
395
|
+
} else if (resolvedAddress === import_render_types.HANEUL_SYSTEM_ADDRESS) {
|
|
396
|
+
return "0x3";
|
|
397
|
+
} else {
|
|
398
|
+
return __privateGet(this, _mvrNameOrAddress) ?? this.summary.id.address;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
renderFieldsAsStruct_fn = async function(name, { fields }, typeParameters = []) {
|
|
402
|
+
this.addImport("~root/../utils/index.js", "MoveStruct");
|
|
403
|
+
const fieldObject = await (0, import_utils.mapToObject)({
|
|
404
|
+
items: Object.entries(fields),
|
|
405
|
+
getComment: ([_name, field]) => field.doc,
|
|
406
|
+
mapper: ([name2, field]) => [
|
|
407
|
+
name2,
|
|
408
|
+
(0, import_render_types.renderTypeSignature)(field.type_, {
|
|
409
|
+
format: "bcs",
|
|
410
|
+
onBcsType: () => {
|
|
411
|
+
this.addImport("@haneullabs/haneul/bcs", "bcs");
|
|
412
|
+
},
|
|
413
|
+
summary: this.summary,
|
|
414
|
+
typeParameters,
|
|
415
|
+
resolveAddress: (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address),
|
|
416
|
+
onDependency: (address, mod) => {
|
|
417
|
+
if (address !== this.summary.id.address || mod !== this.summary.id.name) {
|
|
418
|
+
return this.addStarImport(
|
|
419
|
+
address === this.summary.id.address ? `./${mod}.js` : (0, import_node_path.join)(`~root`, __privateGet(this, _depsDir), `${address}/${mod}.js`),
|
|
420
|
+
mod
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
return void 0;
|
|
424
|
+
}
|
|
425
|
+
})
|
|
426
|
+
]
|
|
427
|
+
});
|
|
428
|
+
return import_utils.parseTS`new MoveStruct({ name: \`${name}\`, fields: ${fieldObject} })`;
|
|
429
|
+
};
|
|
430
|
+
renderFieldsAsTuple_fn = async function(name, { fields }, typeParameters = []) {
|
|
431
|
+
this.addImport("~root/../utils/index.js", "MoveTuple");
|
|
432
|
+
const values = Object.values(fields).map(
|
|
433
|
+
(field) => (0, import_render_types.renderTypeSignature)(field.type_, {
|
|
434
|
+
format: "bcs",
|
|
435
|
+
summary: this.summary,
|
|
436
|
+
typeParameters,
|
|
437
|
+
onBcsType: () => {
|
|
438
|
+
this.addImport("@haneullabs/haneul/bcs", "bcs");
|
|
439
|
+
},
|
|
440
|
+
resolveAddress: (address) => __privateMethod(this, _MoveModuleBuilder_instances, resolveAddress_fn).call(this, address),
|
|
441
|
+
onDependency: (address, mod) => {
|
|
442
|
+
if (address !== this.summary.id.address || mod !== this.summary.id.name) {
|
|
443
|
+
return this.addStarImport(
|
|
444
|
+
address === this.summary.id.address ? `./${mod}.js` : (0, import_node_path.join)(`~root`, __privateGet(this, _depsDir), `${address}/${mod}.js`),
|
|
445
|
+
mod
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
return void 0;
|
|
449
|
+
}
|
|
450
|
+
})
|
|
451
|
+
);
|
|
452
|
+
return import_utils.parseTS`new MoveTuple({ name: \`${name}\`, fields: [${values.join(", ")}] })`;
|
|
453
|
+
};
|
|
454
|
+
let MoveModuleBuilder = _MoveModuleBuilder;
|
|
455
|
+
function isPositional(fields) {
|
|
456
|
+
if (fields.positional_fields === true) {
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
if (Object.keys(fields.fields).every((field, i) => field === `pos${i}`)) {
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
//# sourceMappingURL=move-module-builder.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/move-module-builder.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { FileBuilder } from './file-builder.js';\nimport { readFile } from 'node:fs/promises';\nimport {\n\tgetSafeName,\n\trenderTypeSignature,\n\tHANEUL_FRAMEWORK_ADDRESS,\n\tHANEUL_SYSTEM_ADDRESS,\n} from './render-types.js';\nimport {\n\tcamelCase,\n\tcapitalize,\n\tformatComment,\n\tisWellKnownObjectParameter,\n\tmapToObject,\n\tparseTS,\n\twithComment,\n} from './utils.js';\nimport type { Fields, ModuleSummary, Type, TypeParameter } from './types/summary.js';\nimport { join } from 'node:path';\n\nexport class MoveModuleBuilder extends FileBuilder {\n\tsummary: ModuleSummary;\n\t#depsDir = './deps';\n\t#addressMappings: Record<string, string>;\n\t#includedTypes: Set<string> = new Set();\n\t#includedFunctions: Set<string> = new Set();\n\t#orderedTypes: string[] = [];\n\t#mvrNameOrAddress?: string;\n\n\tconstructor({\n\t\tmvrNameOrAddress,\n\t\tsummary,\n\t\taddressMappings = {},\n\t}: {\n\t\tsummary: ModuleSummary;\n\t\taddressMappings?: Record<string, string>;\n\t\tmvrNameOrAddress?: string;\n\t}) {\n\t\tsuper();\n\t\tthis.summary = summary;\n\t\tthis.#addressMappings = addressMappings;\n\t\tthis.#mvrNameOrAddress = mvrNameOrAddress;\n\t}\n\n\tstatic async fromSummaryFile(\n\t\tfile: string,\n\t\taddressMappings: Record<string, string>,\n\t\tmvrNameOrAddress?: string,\n\t) {\n\t\tconst summary = JSON.parse(await readFile(file, 'utf-8'));\n\n\t\treturn new MoveModuleBuilder({\n\t\t\tsummary,\n\t\t\taddressMappings,\n\t\t\tmvrNameOrAddress,\n\t\t});\n\t}\n\n\t#resolveAddress(address: string) {\n\t\treturn this.#addressMappings[address] ?? address;\n\t}\n\n\t#getModuleTypeName() {\n\t\tconst resolvedAddress = this.#resolveAddress(this.summary.id.address);\n\t\tif (resolvedAddress === HANEUL_FRAMEWORK_ADDRESS) {\n\t\t\treturn '0x2';\n\t\t} else if (resolvedAddress === HANEUL_SYSTEM_ADDRESS) {\n\t\t\treturn '0x3';\n\t\t} else {\n\t\t\treturn this.#mvrNameOrAddress ?? this.summary.id.address;\n\t\t}\n\t}\n\n\toverride async getHeader() {\n\t\tif (!this.summary.doc) {\n\t\t\treturn super.getHeader();\n\t\t}\n\n\t\treturn `${await super.getHeader()}\\n\\n/*${await formatComment(this.summary.doc)}*/\\n\\n`;\n\t}\n\n\tincludeAllFunctions({ privateMethods = 'entry' }: { privateMethods?: 'none' | 'entry' | 'all' }) {\n\t\tfor (const [name, func] of Object.entries(this.summary.functions)) {\n\t\t\tif (func.macro_) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (func.visibility !== 'Public') {\n\t\t\t\tswitch (privateMethods) {\n\t\t\t\t\tcase 'none':\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcase 'entry':\n\t\t\t\t\t\tif (!func.entry) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'all':\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(`Unknown privateMethods option: ${privateMethods}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst safeName = getSafeName(camelCase(name));\n\n\t\t\tthis.reservedNames.add(safeName);\n\t\t\tthis.#includedFunctions.add(name);\n\t\t}\n\t}\n\n\tincludeType(name: string, moduleBuilders: Record<string, MoveModuleBuilder>) {\n\t\tif (this.#includedTypes.has(name)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#includedTypes.add(name);\n\t\tthis.reservedNames.add(name);\n\n\t\tconst struct = this.summary.structs[name];\n\t\tconst enum_ = this.summary.enums[name];\n\n\t\tif (!struct && !enum_) {\n\t\t\tthrow new Error(\n\t\t\t\t`Type ${name} not found in ${this.summary.id.address}::${this.summary.id.name}`,\n\t\t\t);\n\t\t}\n\n\t\tif (struct) {\n\t\t\tObject.values(struct.fields.fields).forEach((field) => {\n\t\t\t\trenderTypeSignature(field.type_, {\n\t\t\t\t\tformat: 'bcs',\n\t\t\t\t\tsummary: this.summary,\n\t\t\t\t\ttypeParameters: struct.type_parameters,\n\t\t\t\t\tresolveAddress: (address) => this.#resolveAddress(address),\n\t\t\t\t\tonDependency: (address, mod, name) => {\n\t\t\t\t\t\tconst builder = moduleBuilders[`${address}::${mod}`];\n\n\t\t\t\t\t\tif (!builder) {\n\t\t\t\t\t\t\tthrow new Error(`Module builder not found for ${address}::${mod}`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbuilder.includeType(name, moduleBuilders);\n\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tif (enum_) {\n\t\t\tObject.values(enum_.variants).forEach((variant) => {\n\t\t\t\tObject.values(variant.fields.fields).forEach((field) => {\n\t\t\t\t\trenderTypeSignature(field.type_, {\n\t\t\t\t\t\tformat: 'bcs',\n\t\t\t\t\t\tsummary: this.summary,\n\t\t\t\t\t\ttypeParameters: enum_.type_parameters,\n\t\t\t\t\t\tresolveAddress: (address) => this.#resolveAddress(address),\n\t\t\t\t\t\tonDependency: (address, mod, name) => {\n\t\t\t\t\t\t\tconst builder = moduleBuilders[`${address}::${mod}`];\n\n\t\t\t\t\t\t\tif (!builder) {\n\t\t\t\t\t\t\t\tthrow new Error(`Module builder not found for ${address}::${mod}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tbuilder.includeType(name, moduleBuilders);\n\n\t\t\t\t\t\t\treturn 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\n\t\t// Add after all dependencies are included to avoid declaration order issues\n\t\tthis.#orderedTypes.push(name);\n\t}\n\n\tincludeAllTypes(moduleBuilders: Record<string, MoveModuleBuilder>) {\n\t\tObject.keys(this.summary.structs).forEach((name) => this.includeType(name, moduleBuilders));\n\t\tObject.keys(this.summary.enums).forEach((name) => this.includeType(name, moduleBuilders));\n\t}\n\n\tasync renderBCSTypes() {\n\t\tif (this.hasBcsTypes()) {\n\t\t\tthis.statements.push(\n\t\t\t\t...parseTS /* ts */ `\n\t\t\t\tconst $moduleName = '${this.#getModuleTypeName()}::${this.summary.id.name}';\n\t\t\t\t`,\n\t\t\t);\n\t\t}\n\t\tfor (const name of this.#orderedTypes) {\n\t\t\tif (this.summary.structs[name]) {\n\t\t\t\tawait this.renderStruct(name);\n\t\t\t} else if (this.summary.enums[name]) {\n\t\t\t\tawait this.renderEnum(name);\n\t\t\t}\n\t\t}\n\t}\n\n\thasBcsTypes() {\n\t\treturn this.#includedTypes.size > 0;\n\t}\n\n\thasFunctions() {\n\t\treturn this.#includedFunctions.size > 0;\n\t}\n\n\thasTypesOrFunctions() {\n\t\treturn this.hasBcsTypes() || this.hasFunctions();\n\t}\n\n\tasync #renderFieldsAsStruct(\n\t\tname: string,\n\t\t{ fields }: Fields,\n\t\ttypeParameters: TypeParameter[] = [],\n\t) {\n\t\tthis.addImport('~root/../utils/index.js', 'MoveStruct');\n\t\tconst fieldObject = await mapToObject({\n\t\t\titems: Object.entries(fields),\n\t\t\tgetComment: ([_name, field]) => field.doc,\n\t\t\tmapper: ([name, field]) => [\n\t\t\t\tname,\n\t\t\t\trenderTypeSignature(field.type_, {\n\t\t\t\t\tformat: 'bcs',\n\t\t\t\t\tonBcsType: () => {\n\t\t\t\t\t\tthis.addImport('@haneullabs/haneul/bcs', 'bcs');\n\t\t\t\t\t},\n\t\t\t\t\tsummary: this.summary,\n\t\t\t\t\ttypeParameters,\n\t\t\t\t\tresolveAddress: (address) => this.#resolveAddress(address),\n\t\t\t\t\tonDependency: (address, mod) => {\n\t\t\t\t\t\tif (address !== this.summary.id.address || mod !== this.summary.id.name) {\n\t\t\t\t\t\t\treturn this.addStarImport(\n\t\t\t\t\t\t\t\taddress === this.summary.id.address\n\t\t\t\t\t\t\t\t\t? `./${mod}.js`\n\t\t\t\t\t\t\t\t\t: join(`~root`, this.#depsDir, `${address}/${mod}.js`),\n\t\t\t\t\t\t\t\tmod,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t],\n\t\t});\n\n\t\treturn parseTS /* ts */ `new MoveStruct({ name: \\`${name}\\`, fields: ${fieldObject} })`;\n\t}\n\n\tasync #renderFieldsAsTuple(\n\t\tname: string,\n\t\t{ fields }: Fields,\n\t\ttypeParameters: TypeParameter[] = [],\n\t) {\n\t\tthis.addImport('~root/../utils/index.js', 'MoveTuple');\n\t\tconst values = Object.values(fields).map((field) =>\n\t\t\trenderTypeSignature(field.type_, {\n\t\t\t\tformat: 'bcs',\n\t\t\t\tsummary: this.summary,\n\t\t\t\ttypeParameters,\n\t\t\t\tonBcsType: () => {\n\t\t\t\t\tthis.addImport('@haneullabs/haneul/bcs', 'bcs');\n\t\t\t\t},\n\t\t\t\tresolveAddress: (address) => this.#resolveAddress(address),\n\t\t\t\tonDependency: (address, mod) => {\n\t\t\t\t\tif (address !== this.summary.id.address || mod !== this.summary.id.name) {\n\t\t\t\t\t\treturn this.addStarImport(\n\t\t\t\t\t\t\taddress === this.summary.id.address\n\t\t\t\t\t\t\t\t? `./${mod}.js`\n\t\t\t\t\t\t\t\t: join(`~root`, this.#depsDir, `${address}/${mod}.js`),\n\t\t\t\t\t\t\tmod,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\n\t\treturn parseTS /* ts */ `new MoveTuple({ name: \\`${name}\\`, fields: [${values.join(', ')}] })`;\n\t}\n\n\tasync renderStruct(name: string) {\n\t\tif (!this.#includedTypes.has(name)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst struct = this.summary.structs[name];\n\n\t\tif (!struct) {\n\t\t\tthrow new Error(\n\t\t\t\t`Struct ${name} not found in ${this.summary.id.address}::${this.summary.id.name}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.exports.push(name);\n\n\t\tconst params = struct.type_parameters.filter((param) => !param.phantom);\n\t\tconst structName = `\\${$moduleName}::${name}`;\n\n\t\tif (params.length === 0) {\n\t\t\tthis.statements.push(\n\t\t\t\t...parseTS /* ts */ `export const ${name} = ${\n\t\t\t\t\tstruct.fields.positional_fields\n\t\t\t\t\t\t? await this.#renderFieldsAsTuple(structName, struct.fields, struct.type_parameters)\n\t\t\t\t\t\t: await this.#renderFieldsAsStruct(structName, struct.fields, struct.type_parameters)\n\t\t\t\t}`,\n\t\t\t);\n\t\t} else {\n\t\t\tthis.addImport('@haneullabs/haneul/bcs', 'type BcsType');\n\n\t\t\tconst typeParams = `...typeParameters: [${params.map((param, i) => param.name ?? `T${i}`).join(', ')}]`;\n\t\t\tconst typeGenerics = `${params.map((param, i) => `${param.name ?? `T${i}`} extends BcsType<any>`).join(', ')}`;\n\t\t\tconst nameGenerics = `${params.map((param, i) => `\\${typeParameters[${i}].name as ${param.name ?? `T${i}`}['name']}`).join(', ')}`;\n\n\t\t\tthis.statements.push(\n\t\t\t\t...(await withComment(\n\t\t\t\t\tstruct,\n\t\t\t\t\tparseTS /* ts */ `export function ${name}<${typeGenerics}>(${typeParams}) {\n\t\t\t\t\t\treturn ${\n\t\t\t\t\t\t\tstruct.fields.positional_fields\n\t\t\t\t\t\t\t\t? await this.#renderFieldsAsTuple(\n\t\t\t\t\t\t\t\t\t\t`${structName}<${nameGenerics}>`,\n\t\t\t\t\t\t\t\t\t\tstruct.fields,\n\t\t\t\t\t\t\t\t\t\tstruct.type_parameters,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: await this.#renderFieldsAsStruct(\n\t\t\t\t\t\t\t\t\t\t`${structName}<${nameGenerics}>`,\n\t\t\t\t\t\t\t\t\t\tstruct.fields,\n\t\t\t\t\t\t\t\t\t\tstruct.type_parameters,\n\t\t\t\t\t\t\t\t\t)\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}\n\n\tasync renderEnum(name: string) {\n\t\tif (!this.#includedTypes.has(name)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst enumDef = this.summary.enums[name];\n\n\t\tif (!enumDef) {\n\t\t\tthrow new Error(\n\t\t\t\t`Enum ${name} not found in ${this.summary.id.address}::${this.summary.id.name}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.addImport('~root/../utils/index.js', 'MoveEnum');\n\t\tthis.exports.push(name);\n\n\t\tconst enumName = `\\${$moduleName}::${name}`;\n\n\t\tconst variantsObject = await mapToObject({\n\t\t\titems: Object.entries(enumDef.variants),\n\t\t\tgetComment: ([_name, variant]) => variant.doc,\n\t\t\tmapper: async ([variantName, variant]) => [\n\t\t\t\tvariantName,\n\t\t\t\tObject.keys(variant.fields.fields).length === 0\n\t\t\t\t\t? 'null'\n\t\t\t\t\t: isPositional(variant.fields)\n\t\t\t\t\t\t? Object.keys(variant.fields.fields).length === 1\n\t\t\t\t\t\t\t? renderTypeSignature(Object.values(variant.fields.fields)[0].type_, {\n\t\t\t\t\t\t\t\t\tformat: 'bcs',\n\t\t\t\t\t\t\t\t\tsummary: this.summary,\n\t\t\t\t\t\t\t\t\ttypeParameters: enumDef.type_parameters,\n\t\t\t\t\t\t\t\t\tonBcsType: () => {\n\t\t\t\t\t\t\t\t\t\tthis.addImport('@haneullabs/haneul/bcs', 'bcs');\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tresolveAddress: (address) => this.#resolveAddress(address),\n\t\t\t\t\t\t\t\t\tonDependency: (address, mod) => {\n\t\t\t\t\t\t\t\t\t\tif (address !== this.summary.id.address || mod !== this.summary.id.name) {\n\t\t\t\t\t\t\t\t\t\t\treturn this.addStarImport(\n\t\t\t\t\t\t\t\t\t\t\t\taddress === this.summary.id.address\n\t\t\t\t\t\t\t\t\t\t\t\t\t? `./${mod}.js`\n\t\t\t\t\t\t\t\t\t\t\t\t\t: `~root/deps/${address}/${mod}.js`,\n\t\t\t\t\t\t\t\t\t\t\t\tmod,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t: await this.#renderFieldsAsTuple(\n\t\t\t\t\t\t\t\t\t`${name}.${variantName}`,\n\t\t\t\t\t\t\t\t\tvariant.fields,\n\t\t\t\t\t\t\t\t\tenumDef.type_parameters,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: await this.#renderFieldsAsStruct(\n\t\t\t\t\t\t\t\t`${name}.${variantName}`,\n\t\t\t\t\t\t\t\tvariant.fields,\n\t\t\t\t\t\t\t\tenumDef.type_parameters,\n\t\t\t\t\t\t\t),\n\t\t\t],\n\t\t});\n\n\t\tconst params = enumDef.type_parameters.filter((param) => !param.phantom);\n\n\t\tif (params.length === 0) {\n\t\t\tthis.statements.push(\n\t\t\t\t...(await withComment(\n\t\t\t\t\tenumDef,\n\t\t\t\t\tparseTS /* ts */ `export const ${name} = new MoveEnum({ name: \\`${enumName}\\`, fields: ${variantsObject} })`,\n\t\t\t\t)),\n\t\t\t);\n\t\t} else {\n\t\t\tthis.addImport('@haneullabs/haneul/bcs', 'type BcsType');\n\n\t\t\tconst typeParams = `...typeParameters: [${params.map((param, i) => param.name ?? `T${i}`).join(', ')}]`;\n\t\t\tconst typeGenerics = `${params.map((param, i) => `${param.name ?? `T${i}`} extends BcsType<any>`).join(', ')}`;\n\t\t\tconst nameGenerics = `${params.map((param, i) => `\\${typeParameters[${i}].name as ${param.name ?? `T${i}`}['name']}`).join(', ')}`;\n\n\t\t\tthis.statements.push(\n\t\t\t\t...(await withComment(\n\t\t\t\t\tenumDef,\n\t\t\t\t\tparseTS /* ts */ `\n\t\t\t\t\texport function ${name}<${typeGenerics}>(${typeParams}) {\n\t\t\t\t\t\treturn new MoveEnum({ name: \\`${enumName}<${nameGenerics}>\\`, fields: ${variantsObject} })\n\t\t\t\t\t}`,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\tasync renderFunctions() {\n\t\tconst names = [];\n\n\t\tif (!this.hasFunctions()) {\n\t\t\treturn;\n\t\t}\n\t\tthis.addImport('@haneullabs/haneul/transactions', 'type Transaction');\n\n\t\tfor (const [name, func] of Object.entries(this.summary.functions)) {\n\t\t\tif (func.macro_ || !this.#includedFunctions.has(name)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst parameters = func.parameters.filter((param) => !this.isContextReference(param.type_));\n\t\t\tconst hasAllParameterNames =\n\t\t\t\tparameters.length > 0 &&\n\t\t\t\tparameters.every(\n\t\t\t\t\t(param, i) => param.name && parameters.findIndex((p) => p.name === param.name) === i,\n\t\t\t\t);\n\t\t\tconst fnName = getSafeName(camelCase(name));\n\t\t\tconst requiredParameters = parameters.filter(\n\t\t\t\t(param) =>\n\t\t\t\t\t!isWellKnownObjectParameter(param.type_, (address) => this.#resolveAddress(address)),\n\t\t\t);\n\n\t\t\tif (parameters.length > 0) {\n\t\t\t\tthis.addImport('~root/../utils/index.js', 'normalizeMoveArguments');\n\t\t\t}\n\n\t\t\tnames.push(fnName);\n\n\t\t\tconst usedTypeParameters = new Set<number | string>();\n\n\t\t\tconst argumentsTypes = requiredParameters\n\t\t\t\t.map((param) =>\n\t\t\t\t\trenderTypeSignature(param.type_, {\n\t\t\t\t\t\tformat: 'typescriptArg',\n\t\t\t\t\t\tsummary: this.summary,\n\t\t\t\t\t\ttypeParameters: func.type_parameters,\n\t\t\t\t\t\tresolveAddress: (address) => this.#resolveAddress(address),\n\t\t\t\t\t\tonTypeParameter: (typeParameter) => usedTypeParameters.add(typeParameter),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.map((type, i) =>\n\t\t\t\t\trequiredParameters[i].name\n\t\t\t\t\t\t? `${camelCase(requiredParameters[i].name)}: RawTransactionArgument<${type}>`\n\t\t\t\t\t\t: `RawTransactionArgument<${type}>`,\n\t\t\t\t)\n\t\t\t\t.join(',\\n');\n\n\t\t\tif (argumentsTypes.length > 0) {\n\t\t\t\tthis.addImport('~root/../utils/index.js', 'type RawTransactionArgument');\n\t\t\t}\n\n\t\t\tif (usedTypeParameters.size > 0) {\n\t\t\t\tthis.addImport('@haneullabs/haneul/bcs', 'type BcsType');\n\t\t\t}\n\n\t\t\tconst filteredTypeParameters = func.type_parameters.filter(\n\t\t\t\t(param, i) =>\n\t\t\t\t\tusedTypeParameters.has(i) || (param.name && usedTypeParameters.has(param.name)),\n\t\t\t);\n\n\t\t\tconst genericTypes =\n\t\t\t\tfilteredTypeParameters.length > 0\n\t\t\t\t\t? `<${filteredTypeParameters.map((param, i) => `${param.name ?? `T${i}`} extends BcsType<any>`).join(', ')}>`\n\t\t\t\t\t: '';\n\t\t\tconst genericTypeArgs =\n\t\t\t\tfilteredTypeParameters.length > 0\n\t\t\t\t\t? `<${filteredTypeParameters.map((param, i) => `${param.name ?? `T${i}`}`).join(', ')}>`\n\t\t\t\t\t: '';\n\n\t\t\tconst argumentsInterface = this.getUnusedName(\n\t\t\t\t`${capitalize(fnName.replace(/^_/, ''))}Arguments`,\n\t\t\t);\n\t\t\tif (hasAllParameterNames) {\n\t\t\t\tthis.statements.push(\n\t\t\t\t\t...parseTS /* ts */ `export interface ${argumentsInterface}${genericTypes} {\n\t\t\t\t\t\t${argumentsTypes}\n\t\t\t\t\t}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst optionsInterface = this.getUnusedName(`${capitalize(fnName.replace(/^_/, ''))}Options`);\n\t\t\tconst requiresOptions = argumentsTypes.length > 0 || func.type_parameters.length > 0;\n\n\t\t\tthis.statements.push(\n\t\t\t\t...parseTS /* ts */ `export interface ${optionsInterface}${genericTypes} {\n\t\t\t\t\tpackage${this.#mvrNameOrAddress ? '?: string' : ': string'}\n\t\t\t\t\t${argumentsTypes.length > 0 ? 'arguments: ' : 'arguments?: '}${\n\t\t\t\t\t\thasAllParameterNames\n\t\t\t\t\t\t\t? `${argumentsInterface}${genericTypeArgs} | [${argumentsTypes}]`\n\t\t\t\t\t\t\t: `[${argumentsTypes}]`\n\t\t\t\t\t},\n\t\t\t\t\t${\n\t\t\t\t\t\tfunc.type_parameters.length\n\t\t\t\t\t\t\t? `typeArguments: [${func.type_parameters.map(() => 'string').join(', ')}]`\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t}`,\n\t\t\t);\n\n\t\t\tthis.statements.push(\n\t\t\t\t...(await withComment(\n\t\t\t\t\tfunc,\n\t\t\t\t\tparseTS /* ts */ `export function ${fnName}${genericTypes}(options: ${optionsInterface}${genericTypeArgs}${requiresOptions ? '' : ' = {}'}) {\n\t\t\t\t\tconst packageAddress = options.package${this.#mvrNameOrAddress ? ` ?? '${this.#mvrNameOrAddress}'` : ''};\n\t\t\t\t\t${\n\t\t\t\t\t\tparameters.length > 0\n\t\t\t\t\t\t\t? `const argumentsTypes = [\n\t\t\t\t\t\t${parameters\n\t\t\t\t\t\t\t.map((param) =>\n\t\t\t\t\t\t\t\trenderTypeSignature(param.type_, {\n\t\t\t\t\t\t\t\t\tformat: 'typeTag',\n\t\t\t\t\t\t\t\t\tsummary: this.summary,\n\t\t\t\t\t\t\t\t\ttypeParameters: func.type_parameters,\n\t\t\t\t\t\t\t\t\tresolveAddress: (address) => this.#resolveAddress(address),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.map((tag) => (tag.includes('{') ? `\\`${tag}\\`` : `'${tag}'`))\n\t\t\t\t\t\t\t.join(',\\n')}\n\t\t\t\t\t] satisfies string[]\\n`\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}${hasAllParameterNames ? `const parameterNames = ${JSON.stringify(requiredParameters.map((param) => camelCase(param.name!)))}\\n` : ''}\n\t\t\t\t\treturn (tx: Transaction) => tx.moveCall({\n\t\t\t\t\t\tpackage: packageAddress,\n\t\t\t\t\t\tmodule: '${this.summary.id.name}',\n\t\t\t\t\t\tfunction: '${name}',\n\t\t\t\t\t\t${parameters.length > 0 ? `arguments: normalizeMoveArguments(options.arguments${argumentsTypes.length > 0 ? '' : ' ?? []'} , argumentsTypes${hasAllParameterNames ? `, parameterNames` : ''}),` : ''}\n\t\t\t\t\t\t${func.type_parameters.length ? 'typeArguments: options.typeArguments' : ''}\n\t\t\t\t\t})\n\t\t\t\t}`,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\tisContextReference(type: Type): boolean {\n\t\tif (typeof type === 'string') {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ('Reference' in type) {\n\t\t\treturn this.isContextReference(type.Reference[1]);\n\t\t}\n\n\t\tif ('Datatype' in type) {\n\t\t\treturn (\n\t\t\t\tthis.#resolveAddress(type.Datatype.module.address) === HANEUL_FRAMEWORK_ADDRESS &&\n\t\t\t\ttype.Datatype.module.name === 'tx_context' &&\n\t\t\t\ttype.Datatype.name === 'TxContext'\n\t\t\t);\n\t\t}\n\n\t\treturn false;\n\t}\n}\n\nfunction isPositional(fields: Fields) {\n\tif (fields.positional_fields === true) {\n\t\treturn true;\n\t}\n\n\tif (Object.keys(fields.fields).every((field, i) => field === `pos${i}`)) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA4B;AAC5B,sBAAyB;AACzB,0BAKO;AACP,mBAQO;AAEP,uBAAqB;AArBrB;AAuBO,MAAM,qBAAN,MAAM,2BAA0B,gCAAY;AAAA,EASlD,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA,kBAAkB,CAAC;AAAA,EACpB,GAIG;AACF,UAAM;AAlBD;AAEN,iCAAW;AACX;AACA,uCAA8B,oBAAI,IAAI;AACtC,2CAAkC,oBAAI,IAAI;AAC1C,sCAA0B,CAAC;AAC3B;AAYC,SAAK,UAAU;AACf,uBAAK,kBAAmB;AACxB,uBAAK,mBAAoB;AAAA,EAC1B;AAAA,EAEA,aAAa,gBACZ,MACA,iBACA,kBACC;AACD,UAAM,UAAU,KAAK,MAAM,UAAM,0BAAS,MAAM,OAAO,CAAC;AAExD,WAAO,IAAI,mBAAkB;AAAA,MAC5B;AAAA,MACA;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EAiBA,MAAe,YAAY;AAC1B,QAAI,CAAC,KAAK,QAAQ,KAAK;AACtB,aAAO,MAAM,UAAU;AAAA,IACxB;AAEA,WAAO,GAAG,MA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0BAA0B,KAAK;AAAA,MAC/C;AAAA,MACA,gBAAgB,CAAC,YAAY,sBAAK,iDAAL,WAAqB;AAAA,MAClD,cAAc,CAAC,SAAS,QAAQ;AAC/B,YAAI,YAAY,KAAK,QAAQ,GAAG,WAAW,QAAQ,KAAK,QAAQ,GAAG,MAAM;AACxE,iBAAO,KAAK;AAAA,YACX,YAAY,KAAK,QAAQ,GAAG,UACzB,KAAK,GAAG,YACR,uBAAK,SAAS,mBAAK,WAAU,GAAG,OAAO,IAAI,GAAG,KAAK;AAAA,YACtD;AAAA,UACD;AAAA,QACD;AAEA,eAAO;AAAA,MACR;AAAA,IACD,CAAC;AAAA,EACF;AAEA,SAAO,+CAA4C,IAAI,gBAAgB,OAAO,KAAK,IAAI,CAAC;AACzF;AApQM,IAAM,oBAAN;AAqjBP,SAAS,aAAa,QAAgB;AACrC,MAAI,OAAO,sBAAsB,MAAM;AACtC,WAAO;AAAA,EACR;AAEA,MAAI,OAAO,KAAK,OAAO,MAAM,EAAE,MAAM,CAAC,OAAO,MAAM,UAAU,MAAM,CAAC,EAAE,GAAG;AACxE,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": ["name"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ModuleSummary, Type, TypeParameter } from './types/summary.js';
|
|
2
|
+
export declare const MOVE_STDLIB_ADDRESS: string;
|
|
3
|
+
export declare const HANEUL_FRAMEWORK_ADDRESS: string;
|
|
4
|
+
export declare const HANEUL_SYSTEM_ADDRESS: string;
|
|
5
|
+
type TypeSignatureFormat = 'typescriptArg' | 'bcs' | 'typeTag';
|
|
6
|
+
interface RenderTypeSignatureOptions {
|
|
7
|
+
format: TypeSignatureFormat;
|
|
8
|
+
summary: ModuleSummary;
|
|
9
|
+
typeParameters?: TypeParameter[];
|
|
10
|
+
onDependency?: (address: string, module: string, type: string) => string | undefined;
|
|
11
|
+
onBcsType?: () => void;
|
|
12
|
+
onTypeParameter?: (typeParameter: number | string) => void;
|
|
13
|
+
resolveAddress: (address: string) => string;
|
|
14
|
+
}
|
|
15
|
+
export declare function renderTypeSignature(type: Type, options: RenderTypeSignatureOptions): string;
|
|
16
|
+
export declare function usesBcs(type: Type, options: RenderTypeSignatureOptions): boolean;
|
|
17
|
+
export declare function isPureSignature(type: Type, options: RenderTypeSignatureOptions): boolean;
|
|
18
|
+
export declare function getSafeName(name: string): string;
|
|
19
|
+
export {};
|