@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,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var command_exports = {};
|
|
30
|
+
__export(command_exports, {
|
|
31
|
+
generateCommand: () => generateCommand
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(command_exports);
|
|
34
|
+
var import_core = require("@stricli/core");
|
|
35
|
+
const generateCommand = (0, import_core.buildCommand)({
|
|
36
|
+
loader: async () => (await import("./impl.js")).default,
|
|
37
|
+
parameters: {
|
|
38
|
+
positional: {
|
|
39
|
+
kind: "array",
|
|
40
|
+
parameter: {
|
|
41
|
+
parse: String,
|
|
42
|
+
brief: "package name, mvr name, or path to a move package"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
flags: {
|
|
46
|
+
outputDir: {
|
|
47
|
+
kind: "parsed",
|
|
48
|
+
parse: String,
|
|
49
|
+
brief: "Output directory",
|
|
50
|
+
optional: true
|
|
51
|
+
},
|
|
52
|
+
noPrune: {
|
|
53
|
+
kind: "parsed",
|
|
54
|
+
parse: Boolean,
|
|
55
|
+
optional: true,
|
|
56
|
+
brief: "generate all types and functions in dependencies"
|
|
57
|
+
},
|
|
58
|
+
noSummaries: {
|
|
59
|
+
kind: "parsed",
|
|
60
|
+
parse: Boolean,
|
|
61
|
+
optional: true,
|
|
62
|
+
brief: "Do not generate summaries for packages"
|
|
63
|
+
},
|
|
64
|
+
network: {
|
|
65
|
+
kind: "enum",
|
|
66
|
+
values: ["mainnet", "testnet"],
|
|
67
|
+
optional: true,
|
|
68
|
+
brief: "Network to generate for (default: testnet)"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
aliases: {
|
|
72
|
+
o: "outputDir",
|
|
73
|
+
n: "network"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
docs: {
|
|
77
|
+
brief: "Generate BCS and moveCall helpers from you Move code"
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/cli/commands/generate/command.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { buildCommand } from '@stricli/core';\n\nexport const generateCommand = buildCommand({\n\tloader: async () => (await import('./impl.js')).default,\n\tparameters: {\n\t\tpositional: {\n\t\t\tkind: 'array',\n\t\t\tparameter: {\n\t\t\t\tparse: String,\n\t\t\t\tbrief: 'package name, mvr name, or path to a move package',\n\t\t\t},\n\t\t},\n\t\tflags: {\n\t\t\toutputDir: {\n\t\t\t\tkind: 'parsed',\n\t\t\t\tparse: String,\n\t\t\t\tbrief: 'Output directory',\n\t\t\t\toptional: true,\n\t\t\t},\n\t\t\tnoPrune: {\n\t\t\t\tkind: 'parsed',\n\t\t\t\tparse: Boolean,\n\t\t\t\toptional: true,\n\t\t\t\tbrief: 'generate all types and functions in dependencies',\n\t\t\t},\n\t\t\tnoSummaries: {\n\t\t\t\tkind: 'parsed',\n\t\t\t\tparse: Boolean,\n\t\t\t\toptional: true,\n\t\t\t\tbrief: 'Do not generate summaries for packages',\n\t\t\t},\n\t\t\tnetwork: {\n\t\t\t\tkind: 'enum',\n\t\t\t\tvalues: ['mainnet', 'testnet'],\n\t\t\t\toptional: true,\n\t\t\t\tbrief: 'Network to generate for (default: testnet)',\n\t\t\t},\n\t\t},\n\t\taliases: {\n\t\t\to: 'outputDir',\n\t\t\tn: 'network',\n\t\t},\n\t},\n\tdocs: {\n\t\tbrief: 'Generate BCS and moveCall helpers from you Move code',\n\t},\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA6B;AAEtB,MAAM,sBAAkB,0BAAa;AAAA,EAC3C,QAAQ,aAAa,MAAM,OAAO,WAAW,GAAG;AAAA,EAChD,YAAY;AAAA,IACX,YAAY;AAAA,MACX,MAAM;AAAA,MACN,WAAW;AAAA,QACV,OAAO;AAAA,QACP,OAAO;AAAA,MACR;AAAA,IACD;AAAA,IACA,OAAO;AAAA,MACN,WAAW;AAAA,QACV,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO;AAAA,QACP,UAAU;AAAA,MACX;AAAA,MACA,SAAS;AAAA,QACR,MAAM;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO;AAAA,MACR;AAAA,MACA,aAAa;AAAA,QACZ,MAAM;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO;AAAA,MACR;AAAA,MACA,SAAS;AAAA,QACR,MAAM;AAAA,QACN,QAAQ,CAAC,WAAW,SAAS;AAAA,QAC7B,UAAU;AAAA,QACV,OAAO;AAAA,MACR;AAAA,IACD;AAAA,IACA,SAAS;AAAA,MACR,GAAG;AAAA,MACH,GAAG;AAAA,IACJ;AAAA,EACD;AAAA,EACA,MAAM;AAAA,IACL,OAAO;AAAA,EACR;AACD,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LocalContext } from '../../context.js';
|
|
2
|
+
export interface SubdirCommandFlags {
|
|
3
|
+
outputDir?: string;
|
|
4
|
+
noPrune?: boolean;
|
|
5
|
+
noSummaries?: boolean;
|
|
6
|
+
network?: 'mainnet' | 'testnet';
|
|
7
|
+
}
|
|
8
|
+
export default function generate(this: LocalContext, flags: SubdirCommandFlags, ...packages: string[]): Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 impl_exports = {};
|
|
20
|
+
__export(impl_exports, {
|
|
21
|
+
default: () => generate
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(impl_exports);
|
|
24
|
+
var import__ = require("../../../index.js");
|
|
25
|
+
var import_config = require("../../../config.js");
|
|
26
|
+
var import_utils = require("@haneullabs/haneul/utils");
|
|
27
|
+
var import_node_child_process = require("node:child_process");
|
|
28
|
+
var import_node_fs = require("node:fs");
|
|
29
|
+
async function generate(flags, ...packages) {
|
|
30
|
+
const config = await (0, import_config.loadConfig)();
|
|
31
|
+
const normalizedPackages = packages.length > 0 ? packages.map((p) => {
|
|
32
|
+
const trimmed = p.trim();
|
|
33
|
+
if ((0, import_utils.isValidHaneulObjectId)(trimmed) || (0, import_utils.isValidNamedPackage)(trimmed)) {
|
|
34
|
+
return {
|
|
35
|
+
network: flags.network ?? "testnet",
|
|
36
|
+
packageName: (0, import_utils.isValidHaneulObjectId)(trimmed) ? trimmed : trimmed.split("/")[1],
|
|
37
|
+
package: trimmed
|
|
38
|
+
};
|
|
39
|
+
} else {
|
|
40
|
+
return {
|
|
41
|
+
package: "@local-pkg/" + trimmed,
|
|
42
|
+
packageName: trimmed,
|
|
43
|
+
path: trimmed
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}) : config.packages;
|
|
47
|
+
const generateSummaries = flags.noSummaries === void 0 ? config.generateSummaries : !flags.noSummaries;
|
|
48
|
+
for (const pkg of normalizedPackages) {
|
|
49
|
+
if (generateSummaries && pkg.path) {
|
|
50
|
+
if (!(0, import_node_fs.existsSync)(pkg.path)) {
|
|
51
|
+
throw new Error(`Package path does not exist: ${pkg.path}`);
|
|
52
|
+
}
|
|
53
|
+
(0, import_node_child_process.execSync)("haneul move summary", {
|
|
54
|
+
cwd: pkg.path,
|
|
55
|
+
stdio: "inherit"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
await (0, import__.generateFromPackageSummary)({
|
|
59
|
+
package: pkg,
|
|
60
|
+
prune: flags.noPrune === void 0 ? config.prune : !flags.noPrune,
|
|
61
|
+
outputDir: flags.outputDir ?? config.output,
|
|
62
|
+
privateMethods: config.privateMethods
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=impl.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/cli/commands/generate/impl.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { LocalContext } from '../../context.js';\nimport { generateFromPackageSummary } from '../../../index.js';\nimport { loadConfig } from '../../../config.js';\nimport { isValidNamedPackage, isValidHaneulObjectId } from '@haneullabs/haneul/utils';\nimport { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\n\nexport interface SubdirCommandFlags {\n\toutputDir?: string;\n\tnoPrune?: boolean;\n\tnoSummaries?: boolean;\n\tnetwork?: 'mainnet' | 'testnet';\n}\n\nexport default async function generate(\n\tthis: LocalContext,\n\tflags: SubdirCommandFlags,\n\t...packages: string[]\n): Promise<void> {\n\tconst config = await loadConfig();\n\n\tconst normalizedPackages =\n\t\tpackages.length > 0\n\t\t\t? packages.map((p) => {\n\t\t\t\t\tconst trimmed = p.trim();\n\t\t\t\t\tif (isValidHaneulObjectId(trimmed) || isValidNamedPackage(trimmed)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnetwork: flags.network ?? 'testnet',\n\t\t\t\t\t\t\tpackageName: isValidHaneulObjectId(trimmed) ? trimmed : trimmed.split('/')[1],\n\t\t\t\t\t\t\tpackage: trimmed,\n\t\t\t\t\t\t};\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tpackage: '@local-pkg/' + trimmed,\n\t\t\t\t\t\t\tpackageName: trimmed,\n\t\t\t\t\t\t\tpath: trimmed,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t: config.packages;\n\n\tconst generateSummaries =\n\t\tflags.noSummaries === undefined ? config.generateSummaries : !flags.noSummaries;\n\n\tfor (const pkg of normalizedPackages) {\n\t\tif (generateSummaries && pkg.path) {\n\t\t\tif (!existsSync(pkg.path)) {\n\t\t\t\tthrow new Error(`Package path does not exist: ${pkg.path}`);\n\t\t\t}\n\n\t\t\texecSync('haneul move summary', {\n\t\t\t\tcwd: pkg.path,\n\t\t\t\tstdio: 'inherit',\n\t\t\t});\n\t\t}\n\t\tawait generateFromPackageSummary({\n\t\t\tpackage: pkg,\n\t\t\tprune: flags.noPrune === undefined ? config.prune : !flags.noPrune,\n\t\t\toutputDir: flags.outputDir ?? config.output,\n\t\t\tprivateMethods: config.privateMethods,\n\t\t});\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,eAA2C;AAC3C,oBAA2B;AAC3B,mBAA2D;AAC3D,gCAAyB;AACzB,qBAA2B;AAS3B,eAAO,SAEN,UACG,UACa;AAChB,QAAM,SAAS,UAAM,0BAAW;AAEhC,QAAM,qBACL,SAAS,SAAS,IACf,SAAS,IAAI,CAAC,MAAM;AACpB,UAAM,UAAU,EAAE,KAAK;AACvB,YAAI,oCAAsB,OAAO,SAAK,kCAAoB,OAAO,GAAG;AACnE,aAAO;AAAA,QACN,SAAS,MAAM,WAAW;AAAA,QAC1B,iBAAa,oCAAsB,OAAO,IAAI,UAAU,QAAQ,MAAM,GAAG,EAAE,CAAC;AAAA,QAC5E,SAAS;AAAA,MACV;AAAA,IACD,OAAO;AACN,aAAO;AAAA,QACN,SAAS,gBAAgB;AAAA,QACzB,aAAa;AAAA,QACb,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD,CAAC,IACA,OAAO;AAEX,QAAM,oBACL,MAAM,gBAAgB,SAAY,OAAO,oBAAoB,CAAC,MAAM;AAErE,aAAW,OAAO,oBAAoB;AACrC,QAAI,qBAAqB,IAAI,MAAM;AAClC,UAAI,KAAC,2BAAW,IAAI,IAAI,GAAG;AAC1B,cAAM,IAAI,MAAM,gCAAgC,IAAI,IAAI,EAAE;AAAA,MAC3D;AAEA,8CAAS,uBAAuB;AAAA,QAC/B,KAAK,IAAI;AAAA,QACT,OAAO;AAAA,MACR,CAAC;AAAA,IACF;AACA,cAAM,qCAA2B;AAAA,MAChC,SAAS;AAAA,MACT,OAAO,MAAM,YAAY,SAAY,OAAO,QAAQ,CAAC,MAAM;AAAA,MAC3D,WAAW,MAAM,aAAa,OAAO;AAAA,MACrC,gBAAgB,OAAO;AAAA,IACxB,CAAC;AAAA,EACF;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CommandContext } from '@stricli/core';
|
|
2
|
+
import type { StricliAutoCompleteContext } from '@stricli/auto-complete';
|
|
3
|
+
export interface LocalContext extends CommandContext, StricliAutoCompleteContext {
|
|
4
|
+
readonly process: NodeJS.Process;
|
|
5
|
+
}
|
|
6
|
+
export declare function buildContext(process: NodeJS.Process): LocalContext;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var context_exports = {};
|
|
30
|
+
__export(context_exports, {
|
|
31
|
+
buildContext: () => buildContext
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(context_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
35
|
+
var import_node_os = __toESM(require("node:os"));
|
|
36
|
+
var import_node_path = __toESM(require("node:path"));
|
|
37
|
+
function buildContext(process) {
|
|
38
|
+
return {
|
|
39
|
+
process,
|
|
40
|
+
os: import_node_os.default,
|
|
41
|
+
fs: import_node_fs.default,
|
|
42
|
+
path: import_node_path.default
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/cli/context.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { CommandContext } from '@stricli/core';\nimport type { StricliAutoCompleteContext } from '@stricli/auto-complete';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport interface LocalContext extends CommandContext, StricliAutoCompleteContext {\n\treadonly process: NodeJS.Process;\n}\n\nexport function buildContext(process: NodeJS.Process): LocalContext {\n\treturn {\n\t\tprocess,\n\t\tos,\n\t\tfs,\n\t\tpath,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,qBAAe;AACf,qBAAe;AACf,uBAAiB;AAMV,SAAS,aAAa,SAAuC;AACnE,SAAO;AAAA,IACN;AAAA,IACA,mBAAAA;AAAA,IACA,mBAAAC;AAAA,IACA,uBAAAC;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["os", "fs", "path"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
export declare const onChainPackageSchema: z.ZodObject<{
|
|
3
|
+
package: z.ZodString;
|
|
4
|
+
packageName: z.ZodString;
|
|
5
|
+
path: z.ZodOptional<z.ZodNever>;
|
|
6
|
+
network: z.ZodEnum<{
|
|
7
|
+
mainnet: "mainnet";
|
|
8
|
+
testnet: "testnet";
|
|
9
|
+
}>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const localPackageSchema: z.ZodObject<{
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
package: z.ZodString;
|
|
14
|
+
packageName: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export declare const packageConfigSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
17
|
+
package: z.ZodString;
|
|
18
|
+
packageName: z.ZodString;
|
|
19
|
+
path: z.ZodOptional<z.ZodNever>;
|
|
20
|
+
network: z.ZodEnum<{
|
|
21
|
+
mainnet: "mainnet";
|
|
22
|
+
testnet: "testnet";
|
|
23
|
+
}>;
|
|
24
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
25
|
+
path: z.ZodString;
|
|
26
|
+
package: z.ZodString;
|
|
27
|
+
packageName: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strip>]>;
|
|
29
|
+
export declare const configSchema: z.ZodObject<{
|
|
30
|
+
output: z.ZodString;
|
|
31
|
+
prune: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
32
|
+
generateSummaries: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
33
|
+
packages: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
34
|
+
package: z.ZodString;
|
|
35
|
+
packageName: z.ZodString;
|
|
36
|
+
path: z.ZodOptional<z.ZodNever>;
|
|
37
|
+
network: z.ZodEnum<{
|
|
38
|
+
mainnet: "mainnet";
|
|
39
|
+
testnet: "testnet";
|
|
40
|
+
}>;
|
|
41
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
42
|
+
path: z.ZodString;
|
|
43
|
+
package: z.ZodString;
|
|
44
|
+
packageName: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strip>]>>;
|
|
46
|
+
privateMethods: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"none">, z.ZodLiteral<"entry">, z.ZodLiteral<"all">]>>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export type PackageConfig = z.infer<typeof packageConfigSchema>;
|
|
49
|
+
export type HaneulCodegenConfig = z.input<typeof configSchema>;
|
|
50
|
+
export type ParsedHaneulCodegenConfig = z.infer<typeof configSchema>;
|
|
51
|
+
export declare function loadConfig(): Promise<ParsedHaneulCodegenConfig>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var config_exports = {};
|
|
30
|
+
__export(config_exports, {
|
|
31
|
+
configSchema: () => configSchema,
|
|
32
|
+
loadConfig: () => loadConfig,
|
|
33
|
+
localPackageSchema: () => localPackageSchema,
|
|
34
|
+
onChainPackageSchema: () => onChainPackageSchema,
|
|
35
|
+
packageConfigSchema: () => packageConfigSchema
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(config_exports);
|
|
38
|
+
var import_utils = require("@haneullabs/haneul/utils");
|
|
39
|
+
var import_cosmiconfig = require("cosmiconfig");
|
|
40
|
+
var z = __toESM(require("zod/v4"));
|
|
41
|
+
const onChainPackageSchema = z.object({
|
|
42
|
+
package: z.string().refine((name) => (0, import_utils.isValidNamedPackage)(name) || (0, import_utils.isValidHaneulObjectId)(name), {
|
|
43
|
+
message: "Invalid package name or package ID"
|
|
44
|
+
}),
|
|
45
|
+
packageName: z.string(),
|
|
46
|
+
path: z.never().optional(),
|
|
47
|
+
network: z.enum(["mainnet", "testnet"])
|
|
48
|
+
});
|
|
49
|
+
const localPackageSchema = z.object({
|
|
50
|
+
path: z.string(),
|
|
51
|
+
package: z.string(),
|
|
52
|
+
packageName: z.string().optional()
|
|
53
|
+
});
|
|
54
|
+
const packageConfigSchema = z.union([onChainPackageSchema, localPackageSchema]);
|
|
55
|
+
const configSchema = z.object({
|
|
56
|
+
output: z.string(),
|
|
57
|
+
prune: z.boolean().optional().default(true),
|
|
58
|
+
generateSummaries: z.boolean().optional().default(true),
|
|
59
|
+
packages: z.array(packageConfigSchema),
|
|
60
|
+
privateMethods: z.union([z.literal("none"), z.literal("entry"), z.literal("all")]).optional().default("entry")
|
|
61
|
+
});
|
|
62
|
+
async function loadConfig() {
|
|
63
|
+
const config = await (0, import_cosmiconfig.cosmiconfig)("haneul-codegen").search();
|
|
64
|
+
if (!config) {
|
|
65
|
+
return {
|
|
66
|
+
output: "./generated",
|
|
67
|
+
packages: [],
|
|
68
|
+
prune: true,
|
|
69
|
+
generateSummaries: true,
|
|
70
|
+
privateMethods: "entry"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return configSchema.parse(config.config);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/config.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedPackage, isValidHaneulObjectId } from '@haneullabs/haneul/utils';\nimport { cosmiconfig } from 'cosmiconfig';\nimport * as z from 'zod/v4';\n\nexport const onChainPackageSchema = z.object({\n\tpackage: z.string().refine((name) => isValidNamedPackage(name) || isValidHaneulObjectId(name), {\n\t\tmessage: 'Invalid package name or package ID',\n\t}),\n\tpackageName: z.string(),\n\tpath: z.never().optional(),\n\tnetwork: z.enum(['mainnet', 'testnet']),\n});\n\nexport const localPackageSchema = z.object({\n\tpath: z.string(),\n\tpackage: z.string(),\n\tpackageName: z.string().optional(),\n});\n\nexport const packageConfigSchema = z.union([onChainPackageSchema, localPackageSchema]);\n\nexport const configSchema = z.object({\n\toutput: z.string(),\n\tprune: z.boolean().optional().default(true),\n\tgenerateSummaries: z.boolean().optional().default(true),\n\tpackages: z.array(packageConfigSchema),\n\tprivateMethods: z\n\t\t.union([z.literal('none'), z.literal('entry'), z.literal('all')])\n\t\t.optional()\n\t\t.default('entry'),\n});\n\nexport type PackageConfig = z.infer<typeof packageConfigSchema>;\nexport type HaneulCodegenConfig = z.input<typeof configSchema>;\nexport type ParsedHaneulCodegenConfig = z.infer<typeof configSchema>;\n\nexport async function loadConfig(): Promise<ParsedHaneulCodegenConfig> {\n\tconst config = await cosmiconfig('haneul-codegen').search();\n\n\tif (!config) {\n\t\treturn {\n\t\t\toutput: './generated',\n\t\t\tpackages: [],\n\t\t\tprune: true,\n\t\t\tgenerateSummaries: true,\n\t\t\tprivateMethods: 'entry',\n\t\t};\n\t}\n\n\treturn configSchema.parse(config.config);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA2D;AAC3D,yBAA4B;AAC5B,QAAmB;AAEZ,MAAM,uBAAuB,EAAE,OAAO;AAAA,EAC5C,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,aAAS,kCAAoB,IAAI,SAAK,oCAAsB,IAAI,GAAG;AAAA,IAC9F,SAAS;AAAA,EACV,CAAC;AAAA,EACD,aAAa,EAAE,OAAO;AAAA,EACtB,MAAM,EAAE,MAAM,EAAE,SAAS;AAAA,EACzB,SAAS,EAAE,KAAK,CAAC,WAAW,SAAS,CAAC;AACvC,CAAC;AAEM,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAC1C,MAAM,EAAE,OAAO;AAAA,EACf,SAAS,EAAE,OAAO;AAAA,EAClB,aAAa,EAAE,OAAO,EAAE,SAAS;AAClC,CAAC;AAEM,MAAM,sBAAsB,EAAE,MAAM,CAAC,sBAAsB,kBAAkB,CAAC;AAE9E,MAAM,eAAe,EAAE,OAAO;AAAA,EACpC,QAAQ,EAAE,OAAO;AAAA,EACjB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,IAAI;AAAA,EAC1C,mBAAmB,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,IAAI;AAAA,EACtD,UAAU,EAAE,MAAM,mBAAmB;AAAA,EACrC,gBAAgB,EACd,MAAM,CAAC,EAAE,QAAQ,MAAM,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,KAAK,CAAC,CAAC,EAC/D,SAAS,EACT,QAAQ,OAAO;AAClB,CAAC;AAMD,eAAsB,aAAiD;AACtE,QAAM,SAAS,UAAM,gCAAY,gBAAgB,EAAE,OAAO;AAE1D,MAAI,CAAC,QAAQ;AACZ,WAAO;AAAA,MACN,QAAQ;AAAA,MACR,UAAU,CAAC;AAAA,MACX,OAAO;AAAA,MACP,mBAAmB;AAAA,MACnB,gBAAgB;AAAA,IACjB;AAAA,EACD;AAEA,SAAO,aAAa,MAAM,OAAO,MAAM;AACxC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
export declare class FileBuilder {
|
|
3
|
+
statements: ts.Statement[];
|
|
4
|
+
exports: string[];
|
|
5
|
+
imports: Map<string, Set<string>>;
|
|
6
|
+
starImports: Map<string, string>;
|
|
7
|
+
protected reservedNames: Set<string>;
|
|
8
|
+
addImport(module: string, name: string): void;
|
|
9
|
+
addStarImport(module: string, name: string): string;
|
|
10
|
+
getUnusedName(name: string): string;
|
|
11
|
+
getHeader(): Promise<string>;
|
|
12
|
+
toString(modDir: string, filePath: string): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 file_builder_exports = {};
|
|
20
|
+
__export(file_builder_exports, {
|
|
21
|
+
FileBuilder: () => FileBuilder
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(file_builder_exports);
|
|
24
|
+
var import_utils = require("./utils.js");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_render_types = require("./render-types.js");
|
|
27
|
+
class FileBuilder {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.statements = [];
|
|
30
|
+
this.exports = [];
|
|
31
|
+
this.imports = /* @__PURE__ */ new Map();
|
|
32
|
+
this.starImports = /* @__PURE__ */ new Map();
|
|
33
|
+
this.reservedNames = /* @__PURE__ */ new Set();
|
|
34
|
+
}
|
|
35
|
+
addImport(module2, name) {
|
|
36
|
+
if (!this.imports.has(module2)) {
|
|
37
|
+
this.imports.set(module2, /* @__PURE__ */ new Set());
|
|
38
|
+
}
|
|
39
|
+
this.imports.get(module2).add(name);
|
|
40
|
+
}
|
|
41
|
+
addStarImport(module2, name) {
|
|
42
|
+
const importName = this.getUnusedName(name);
|
|
43
|
+
this.starImports.set(importName, module2);
|
|
44
|
+
return importName;
|
|
45
|
+
}
|
|
46
|
+
getUnusedName(name) {
|
|
47
|
+
let deConflictedName = (0, import_render_types.getSafeName)(name);
|
|
48
|
+
let i = 1;
|
|
49
|
+
while (this.reservedNames.has(deConflictedName)) {
|
|
50
|
+
deConflictedName = `${name}_${i}`;
|
|
51
|
+
i++;
|
|
52
|
+
}
|
|
53
|
+
return deConflictedName;
|
|
54
|
+
}
|
|
55
|
+
async getHeader() {
|
|
56
|
+
return [
|
|
57
|
+
"/**************************************************************",
|
|
58
|
+
" * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *",
|
|
59
|
+
" **************************************************************/",
|
|
60
|
+
""
|
|
61
|
+
].join("\n");
|
|
62
|
+
}
|
|
63
|
+
async toString(modDir, filePath) {
|
|
64
|
+
const importStatements = [...this.imports.entries()].flatMap(
|
|
65
|
+
([module2, names]) => import_utils.parseTS`import { ${[...names].join(", ")} } from '${modulePath(module2)}'`
|
|
66
|
+
);
|
|
67
|
+
const starImportStatements = [...this.starImports.entries()].flatMap(
|
|
68
|
+
([name, module2]) => import_utils.parseTS`import * as ${name} from '${modulePath(module2)}'`
|
|
69
|
+
);
|
|
70
|
+
return `${await this.getHeader()}${(0, import_utils.printNodes)(...importStatements, ...starImportStatements, ...this.statements)}`;
|
|
71
|
+
function modulePath(mod) {
|
|
72
|
+
if (!mod.startsWith("~root/")) {
|
|
73
|
+
return mod;
|
|
74
|
+
}
|
|
75
|
+
const sourcePath = (0, import_path.resolve)(modDir, filePath);
|
|
76
|
+
const destPath = (0, import_path.resolve)(modDir, mod.replace("~root/", "./"));
|
|
77
|
+
const sourceDirectory = sourcePath.split("/").slice(0, -1).join("/");
|
|
78
|
+
const relativePath = (0, import_path.relative)(sourceDirectory, destPath);
|
|
79
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=file-builder.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/file-builder.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type ts from 'typescript';\nimport { parseTS, printNodes } from './utils.js';\nimport { relative, resolve } from 'path';\nimport { getSafeName } from './render-types.js';\n\nexport class FileBuilder {\n\tstatements: ts.Statement[] = [];\n\texports: string[] = [];\n\timports: Map<string, Set<string>> = new Map();\n\tstarImports: Map<string, string> = new Map();\n\tprotected reservedNames: Set<string> = new Set();\n\n\taddImport(module: string, name: string) {\n\t\tif (!this.imports.has(module)) {\n\t\t\tthis.imports.set(module, new Set());\n\t\t}\n\n\t\tthis.imports.get(module)!.add(name);\n\t}\n\n\taddStarImport(module: string, name: string) {\n\t\tconst importName = this.getUnusedName(name);\n\t\tthis.starImports.set(importName, module);\n\t\treturn importName;\n\t}\n\n\tgetUnusedName(name: string) {\n\t\tlet deConflictedName = getSafeName(name);\n\n\t\tlet i = 1;\n\t\twhile (this.reservedNames.has(deConflictedName)) {\n\t\t\tdeConflictedName = `${name}_${i}`;\n\t\t\ti++;\n\t\t}\n\n\t\treturn deConflictedName;\n\t}\n\n\tasync getHeader() {\n\t\treturn [\n\t\t\t'/**************************************************************',\n\t\t\t' * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *',\n\t\t\t' **************************************************************/',\n\t\t\t'',\n\t\t].join('\\n');\n\t}\n\n\tasync toString(modDir: string, filePath: string) {\n\t\tconst importStatements = [...this.imports.entries()].flatMap(\n\t\t\t([module, names]) =>\n\t\t\t\tparseTS`import { ${[...names].join(', ')} } from '${modulePath(module)}'`,\n\t\t);\n\t\tconst starImportStatements = [...this.starImports.entries()].flatMap(\n\t\t\t([name, module]) => parseTS`import * as ${name} from '${modulePath(module)}'`,\n\t\t);\n\n\t\treturn `${await this.getHeader()}${printNodes(...importStatements, ...starImportStatements, ...this.statements)}`;\n\n\t\tfunction modulePath(mod: string) {\n\t\t\tif (!mod.startsWith('~root/')) {\n\t\t\t\treturn mod;\n\t\t\t}\n\n\t\t\tconst sourcePath = resolve(modDir, filePath);\n\t\t\tconst destPath = resolve(modDir, mod.replace('~root/', './'));\n\t\t\tconst sourceDirectory = sourcePath.split('/').slice(0, -1).join('/');\n\t\t\tconst relativePath = relative(sourceDirectory, destPath);\n\t\t\treturn relativePath.startsWith('.') ? relativePath : `./${relativePath}`;\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAoC;AACpC,kBAAkC;AAClC,0BAA4B;AAErB,MAAM,YAAY;AAAA,EAAlB;AACN,sBAA6B,CAAC;AAC9B,mBAAoB,CAAC;AACrB,mBAAoC,oBAAI,IAAI;AAC5C,uBAAmC,oBAAI,IAAI;AAC3C,SAAU,gBAA6B,oBAAI,IAAI;AAAA;AAAA,EAE/C,UAAUA,SAAgB,MAAc;AACvC,QAAI,CAAC,KAAK,QAAQ,IAAIA,OAAM,GAAG;AAC9B,WAAK,QAAQ,IAAIA,SAAQ,oBAAI,IAAI,CAAC;AAAA,IACnC;AAEA,SAAK,QAAQ,IAAIA,OAAM,EAAG,IAAI,IAAI;AAAA,EACnC;AAAA,EAEA,cAAcA,SAAgB,MAAc;AAC3C,UAAM,aAAa,KAAK,cAAc,IAAI;AAC1C,SAAK,YAAY,IAAI,YAAYA,OAAM;AACvC,WAAO;AAAA,EACR;AAAA,EAEA,cAAc,MAAc;AAC3B,QAAI,uBAAmB,iCAAY,IAAI;AAEvC,QAAI,IAAI;AACR,WAAO,KAAK,cAAc,IAAI,gBAAgB,GAAG;AAChD,yBAAmB,GAAG,IAAI,IAAI,CAAC;AAC/B;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,YAAY;AACjB,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,EAAE,KAAK,IAAI;AAAA,EACZ;AAAA,EAEA,MAAM,SAAS,QAAgB,UAAkB;AAChD,UAAM,mBAAmB,CAAC,GAAG,KAAK,QAAQ,QAAQ,CAAC,EAAE;AAAA,MACpD,CAAC,CAACA,SAAQ,KAAK,MACd,gCAAmB,CAAC,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC,YAAY,WAAWA,OAAM,CAAC;AAAA,IACxE;AACA,UAAM,uBAAuB,CAAC,GAAG,KAAK,YAAY,QAAQ,CAAC,EAAE;AAAA,MAC5D,CAAC,CAAC,MAAMA,OAAM,MAAM,mCAAsB,IAAI,UAAU,WAAWA,OAAM,CAAC;AAAA,IAC3E;AAEA,WAAO,GAAG,MAAM,KAAK,UAAU,CAAC,OAAG,yBAAW,GAAG,kBAAkB,GAAG,sBAAsB,GAAG,KAAK,UAAU,CAAC;AAE/G,aAAS,WAAW,KAAa;AAChC,UAAI,CAAC,IAAI,WAAW,QAAQ,GAAG;AAC9B,eAAO;AAAA,MACR;AAEA,YAAM,iBAAa,qBAAQ,QAAQ,QAAQ;AAC3C,YAAM,eAAW,qBAAQ,QAAQ,IAAI,QAAQ,UAAU,IAAI,CAAC;AAC5D,YAAM,kBAAkB,WAAW,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,KAAK,GAAG;AACnE,YAAM,mBAAe,sBAAS,iBAAiB,QAAQ;AACvD,aAAO,aAAa,WAAW,GAAG,IAAI,eAAe,KAAK,YAAY;AAAA,IACvE;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["module"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const utilsContent = "\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";
|