@haneullabs/codegen 0.1.0 → 0.8.3

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.
Files changed (147) hide show
  1. package/CHANGELOG.md +138 -33
  2. package/README.md +40 -38
  3. package/dist/bin/bash-complete.d.mts +6 -0
  4. package/dist/bin/bash-complete.d.mts.map +1 -0
  5. package/dist/bin/bash-complete.mjs +29 -0
  6. package/dist/bin/bash-complete.mjs.map +1 -0
  7. package/dist/bin/cli.d.mts +1 -0
  8. package/dist/bin/cli.mjs +24 -0
  9. package/dist/bin/cli.mjs.map +1 -0
  10. package/dist/cli/cli.mjs +28 -0
  11. package/dist/cli/cli.mjs.map +1 -0
  12. package/dist/cli/commands/generate/command.mjs +90 -0
  13. package/dist/cli/commands/generate/command.mjs.map +1 -0
  14. package/dist/cli/commands/generate/impl.mjs +72 -0
  15. package/dist/cli/commands/generate/impl.mjs.map +1 -0
  16. package/dist/cli/context.mjs +17 -0
  17. package/dist/cli/context.mjs.map +1 -0
  18. package/dist/config.d.mts +105 -0
  19. package/dist/config.d.mts.map +1 -0
  20. package/dist/config.mjs +70 -0
  21. package/dist/config.mjs.map +1 -0
  22. package/dist/file-builder.mjs +66 -0
  23. package/dist/file-builder.mjs.map +1 -0
  24. package/dist/{esm/generate-utils.js → generate-utils.mjs} +95 -27
  25. package/dist/generate-utils.mjs.map +1 -0
  26. package/dist/index.d.mts +21 -0
  27. package/dist/index.d.mts.map +1 -0
  28. package/dist/index.mjs +80 -0
  29. package/dist/index.mjs.map +1 -0
  30. package/dist/move-module-builder.mjs +350 -0
  31. package/dist/move-module-builder.mjs.map +1 -0
  32. package/dist/render-types.mjs +207 -0
  33. package/dist/render-types.mjs.map +1 -0
  34. package/dist/utils.mjs +89 -0
  35. package/dist/utils.mjs.map +1 -0
  36. package/docs/index.md +436 -0
  37. package/docs/llms-index.md +6 -0
  38. package/package.json +29 -28
  39. package/src/bin/bash-complete.ts +18 -7
  40. package/src/bin/cli.ts +3 -9
  41. package/src/cli/commands/generate/command.ts +32 -0
  42. package/src/cli/commands/generate/impl.ts +93 -5
  43. package/src/config.ts +53 -5
  44. package/src/file-builder.ts +15 -1
  45. package/src/generate-utils.ts +88 -18
  46. package/src/index.ts +89 -29
  47. package/src/move-module-builder.ts +181 -76
  48. package/src/render-types.ts +82 -29
  49. package/dist/cjs/bin/bash-complete.d.ts +0 -2
  50. package/dist/cjs/bin/bash-complete.js +0 -51
  51. package/dist/cjs/bin/bash-complete.js.map +0 -7
  52. package/dist/cjs/bin/cli.d.ts +0 -2
  53. package/dist/cjs/bin/cli.js +0 -34
  54. package/dist/cjs/bin/cli.js.map +0 -7
  55. package/dist/cjs/cli/cli.d.ts +0 -1
  56. package/dist/cjs/cli/cli.js +0 -49
  57. package/dist/cjs/cli/cli.js.map +0 -7
  58. package/dist/cjs/cli/commands/generate/command.d.ts +0 -1
  59. package/dist/cjs/cli/commands/generate/command.js +0 -80
  60. package/dist/cjs/cli/commands/generate/command.js.map +0 -7
  61. package/dist/cjs/cli/commands/generate/impl.d.ts +0 -8
  62. package/dist/cjs/cli/commands/generate/impl.js +0 -66
  63. package/dist/cjs/cli/commands/generate/impl.js.map +0 -7
  64. package/dist/cjs/cli/context.d.ts +0 -6
  65. package/dist/cjs/cli/context.js +0 -45
  66. package/dist/cjs/cli/context.js.map +0 -7
  67. package/dist/cjs/config.d.ts +0 -51
  68. package/dist/cjs/config.js +0 -75
  69. package/dist/cjs/config.js.map +0 -7
  70. package/dist/cjs/file-builder.d.ts +0 -13
  71. package/dist/cjs/file-builder.js +0 -83
  72. package/dist/cjs/file-builder.js.map +0 -7
  73. package/dist/cjs/generate-utils.d.ts +0 -1
  74. package/dist/cjs/generate-utils.js +0 -187
  75. package/dist/cjs/generate-utils.js.map +0 -7
  76. package/dist/cjs/index.d.ts +0 -8
  77. package/dist/cjs/index.js +0 -124
  78. package/dist/cjs/index.js.map +0 -7
  79. package/dist/cjs/move-module-builder.d.ts +0 -26
  80. package/dist/cjs/move-module-builder.js +0 -464
  81. package/dist/cjs/move-module-builder.js.map +0 -7
  82. package/dist/cjs/package.json +0 -5
  83. package/dist/cjs/render-types.d.ts +0 -19
  84. package/dist/cjs/render-types.js +0 -313
  85. package/dist/cjs/render-types.js.map +0 -7
  86. package/dist/cjs/summary.d.ts +0 -3
  87. package/dist/cjs/summary.js +0 -218
  88. package/dist/cjs/summary.js.map +0 -7
  89. package/dist/cjs/types/deserialized.d.ts +0 -89
  90. package/dist/cjs/types/deserialized.js +0 -17
  91. package/dist/cjs/types/deserialized.js.map +0 -7
  92. package/dist/cjs/types/summary.d.ts +0 -105
  93. package/dist/cjs/types/summary.js +0 -17
  94. package/dist/cjs/types/summary.js.map +0 -7
  95. package/dist/cjs/utils.d.ts +0 -22
  96. package/dist/cjs/utils.js +0 -164
  97. package/dist/cjs/utils.js.map +0 -7
  98. package/dist/esm/bin/bash-complete.d.ts +0 -2
  99. package/dist/esm/bin/bash-complete.js +0 -31
  100. package/dist/esm/bin/bash-complete.js.map +0 -7
  101. package/dist/esm/bin/cli.d.ts +0 -2
  102. package/dist/esm/bin/cli.js +0 -32
  103. package/dist/esm/bin/cli.js.map +0 -7
  104. package/dist/esm/cli/cli.d.ts +0 -1
  105. package/dist/esm/cli/cli.js +0 -29
  106. package/dist/esm/cli/cli.js.map +0 -7
  107. package/dist/esm/cli/commands/generate/command.d.ts +0 -1
  108. package/dist/esm/cli/commands/generate/command.js +0 -50
  109. package/dist/esm/cli/commands/generate/command.js.map +0 -7
  110. package/dist/esm/cli/commands/generate/impl.d.ts +0 -8
  111. package/dist/esm/cli/commands/generate/impl.js +0 -46
  112. package/dist/esm/cli/commands/generate/impl.js.map +0 -7
  113. package/dist/esm/cli/context.d.ts +0 -6
  114. package/dist/esm/cli/context.js +0 -15
  115. package/dist/esm/cli/context.js.map +0 -7
  116. package/dist/esm/config.d.ts +0 -51
  117. package/dist/esm/config.js +0 -45
  118. package/dist/esm/config.js.map +0 -7
  119. package/dist/esm/file-builder.d.ts +0 -13
  120. package/dist/esm/file-builder.js +0 -63
  121. package/dist/esm/file-builder.js.map +0 -7
  122. package/dist/esm/generate-utils.d.ts +0 -1
  123. package/dist/esm/generate-utils.js.map +0 -7
  124. package/dist/esm/index.d.ts +0 -8
  125. package/dist/esm/index.js +0 -104
  126. package/dist/esm/index.js.map +0 -7
  127. package/dist/esm/move-module-builder.d.ts +0 -26
  128. package/dist/esm/move-module-builder.js +0 -457
  129. package/dist/esm/move-module-builder.js.map +0 -7
  130. package/dist/esm/package.json +0 -5
  131. package/dist/esm/render-types.d.ts +0 -19
  132. package/dist/esm/render-types.js +0 -293
  133. package/dist/esm/render-types.js.map +0 -7
  134. package/dist/esm/summary.d.ts +0 -3
  135. package/dist/esm/summary.js +0 -198
  136. package/dist/esm/summary.js.map +0 -7
  137. package/dist/esm/types/deserialized.d.ts +0 -89
  138. package/dist/esm/types/deserialized.js +0 -1
  139. package/dist/esm/types/deserialized.js.map +0 -7
  140. package/dist/esm/types/summary.d.ts +0 -105
  141. package/dist/esm/types/summary.js +0 -1
  142. package/dist/esm/types/summary.js.map +0 -7
  143. package/dist/esm/utils.d.ts +0 -22
  144. package/dist/esm/utils.js +0 -134
  145. package/dist/esm/utils.js.map +0 -7
  146. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  147. package/dist/tsconfig.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,32 +1,33 @@
1
1
  {
2
2
  "name": "@haneullabs/codegen",
3
- "version": "0.1.0",
4
- "description": "typescript codegen for Haneul Move",
3
+ "version": "0.8.3",
4
+ "description": "typescript codegen for haneul move",
5
5
  "license": "Apache-2.0",
6
- "author": "Haneul Labs <build@haneullabs.com>",
6
+ "author": "Haneul Labs <build@haneul-labs.com>",
7
7
  "sideEffects": false,
8
- "type": "commonjs",
9
- "main": "./dist/cjs/index.js",
10
- "module": "./dist/esm/index.js",
11
- "types": "./dist/cjs/index.d.ts",
8
+ "type": "module",
9
+ "main": "./dist/index.mjs",
10
+ "types": "./dist/index.d.mts",
12
11
  "exports": {
13
12
  ".": {
14
- "import": "./dist/esm/index.js",
15
- "require": "./dist/cjs/index.js"
13
+ "types": "./dist/index.d.mts",
14
+ "import": "./dist/index.mjs",
15
+ "default": "./dist/index.mjs"
16
16
  }
17
17
  },
18
18
  "files": [
19
19
  "CHANGELOG.md",
20
20
  "dist",
21
+ "docs",
21
22
  "src"
22
23
  ],
23
24
  "bin": {
24
- "haneul-ts-codegen": "dist/cjs/bin/cli.js",
25
- "__haneul-ts-codegen_bash_complete": "dist/cjs/bin/bash-complete.js"
25
+ "haneul-ts-codegen": "dist/bin/cli.mjs",
26
+ "__haneul-ts-codegen_bash_complete": "dist/bin/bash-complete.mjs"
26
27
  },
27
28
  "repository": {
28
29
  "type": "git",
29
- "url": "git+https://github.com/GeunhwaJeong/haneul-ts-sdks.git"
30
+ "url": "git+https://github.com/GeunhwaJeong/ts-sdks.git"
30
31
  },
31
32
  "keywords": [
32
33
  "move",
@@ -34,37 +35,37 @@
34
35
  "haneul"
35
36
  ],
36
37
  "bugs": {
37
- "url": "https://github.com/GeunhwaJeong/haneul-ts-sdks/issues"
38
+ "url": "https://github.com/GeunhwaJeong/ts-sdks/issues"
38
39
  },
39
- "homepage": "https://github.com/GeunhwaJeong/haneul-ts-sdks/blob/main/packages/codegen#readme",
40
+ "homepage": "https://github.com/GeunhwaJeong/ts-sdks/blob/main/packages/codegen#readme",
40
41
  "devDependencies": {
41
- "vitest": "^4.0.15",
42
- "@haneullabs/build-scripts": "0.1.0"
42
+ "vitest": "^4.0.17"
43
43
  },
44
44
  "dependencies": {
45
- "@stricli/auto-complete": "^1.2.4",
46
- "@stricli/core": "^1.2.4",
47
- "@types/node": "^24.10.1",
45
+ "@stricli/auto-complete": "^1.2.5",
46
+ "@stricli/core": "^1.2.5",
47
+ "@types/node": "^25.0.8",
48
48
  "cosmiconfig": "^9.0.0",
49
- "prettier": "^3.7.3",
49
+ "prettier": "^3.7.4",
50
50
  "toml": "^3.0.0",
51
51
  "typescript": "^5.9.3",
52
- "zod": "^3.25.67",
53
- "@haneullabs/bcs": "0.1.0",
54
- "@haneullabs/haneul": "0.1.0"
52
+ "zod": "^4.3.5",
53
+ "@haneullabs/bcs": "^2.0.3",
54
+ "@haneullabs/haneul": "^2.13.0"
55
55
  },
56
56
  "scripts": {
57
57
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
58
58
  "dev": "pnpm build --watch",
59
- "build": "build-package",
59
+ "build": "rm -rf dist && tsc --noEmit && tsdown",
60
+ "build:docs": "tsx ../docs/scripts/build-docs.ts",
60
61
  "codegen": "pnpm tsx src/bin/cli.ts generate && pnpm lint:fix",
61
62
  "test": "vitest run",
62
63
  "test:watch": "vitest",
63
64
  "prettier:check": "prettier -c --ignore-unknown .",
64
65
  "prettier:fix": "prettier -w --ignore-unknown .",
65
- "eslint:check": "eslint --max-warnings=0 .",
66
- "eslint:fix": "pnpm run eslint:check --fix",
67
- "lint": "pnpm run eslint:check && pnpm run prettier:check",
68
- "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix"
66
+ "oxlint:check": "oxlint .",
67
+ "oxlint:fix": "oxlint --fix",
68
+ "lint": "pnpm run oxlint:check && pnpm run prettier:check",
69
+ "lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix"
69
70
  }
70
71
  }
@@ -3,19 +3,30 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  import { proposeCompletions } from '@stricli/core';
6
+ import { readFile } from 'node:fs/promises';
7
+ import { resolve } from 'node:path';
6
8
  import { buildContext } from '../cli/context.js';
7
9
  import { buildCli } from '../cli/cli.js';
8
10
 
9
- const { version }: { version: string } = require('../../../package.json');
10
- const cli = buildCli(version);
11
-
12
- const inputs = process.argv.slice(3);
13
- if (process.env['COMP_LINE']?.endsWith(' ')) {
14
- inputs.push('');
11
+ async function getVersion() {
12
+ // @ts-ignore
13
+ const dirname = import.meta.dirname;
14
+ const packageJsonPath = resolve(
15
+ dirname,
16
+ dirname.endsWith('src/bin') ? '../../package.json' : '../../package.json',
17
+ );
18
+ const packageJson: { version: string } = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
19
+ return packageJson.version;
15
20
  }
16
21
 
17
22
  export async function main() {
18
- await proposeCompletions(cli, inputs, buildContext(process));
23
+ const version = await getVersion();
24
+ const cli = buildCli(version);
25
+
26
+ const inputs = process.argv.slice(3);
27
+ if (process.env['COMP_LINE']?.endsWith(' ')) {
28
+ inputs.push('');
29
+ }
19
30
 
20
31
  try {
21
32
  for (const { completion } of await proposeCompletions(cli, inputs, buildContext(process))) {
package/src/bin/cli.ts CHANGED
@@ -9,18 +9,12 @@ import { readFile } from 'node:fs/promises';
9
9
  import { resolve } from 'node:path';
10
10
 
11
11
  async function getVersion() {
12
- let dirname;
13
-
14
- try {
15
- dirname = __dirname;
16
- } catch {
17
- // @ts-ignore
18
- dirname = import.meta.dirname;
19
- }
12
+ // @ts-ignore
13
+ const dirname = import.meta.dirname;
20
14
 
21
15
  const packageJsonPath = resolve(
22
16
  dirname,
23
- dirname.endsWith('src/bin') ? '../../package.json' : '../../../package.json',
17
+ dirname.endsWith('src/bin') ? '../../package.json' : '../../package.json',
24
18
  );
25
19
  const packageJson: { version: string } = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
26
20
  return packageJson.version;
@@ -38,10 +38,42 @@ export const generateCommand = buildCommand({
38
38
  optional: true,
39
39
  brief: 'Network to generate for (default: testnet)',
40
40
  },
41
+ importExtension: {
42
+ kind: 'enum',
43
+ values: ['.js', '.ts', 'none'],
44
+ optional: true,
45
+ brief: 'File extension for import statements (default: .js)',
46
+ },
47
+ modules: {
48
+ kind: 'parsed',
49
+ parse: String,
50
+ optional: true,
51
+ variadic: ',',
52
+ brief: 'Only generate from these modules (comma-separated)',
53
+ },
54
+ noTypes: {
55
+ kind: 'parsed',
56
+ parse: Boolean,
57
+ optional: true,
58
+ brief: 'Skip type generation',
59
+ },
60
+ noFunctions: {
61
+ kind: 'parsed',
62
+ parse: Boolean,
63
+ optional: true,
64
+ brief: 'Skip function generation',
65
+ },
66
+ private: {
67
+ kind: 'enum',
68
+ values: ['none', 'entry', 'all'],
69
+ optional: true,
70
+ brief: 'Which private functions to generate (default: entry)',
71
+ },
41
72
  },
42
73
  aliases: {
43
74
  o: 'outputDir',
44
75
  n: 'network',
76
+ m: 'modules',
45
77
  },
46
78
  },
47
79
  docs: {
@@ -3,16 +3,23 @@
3
3
 
4
4
  import type { LocalContext } from '../../context.js';
5
5
  import { generateFromPackageSummary } from '../../../index.js';
6
- import { loadConfig } from '../../../config.js';
6
+ import { loadConfig, type GenerateBase, type PackageGenerate } from '../../../config.js';
7
7
  import { isValidNamedPackage, isValidHaneulObjectId } from '@haneullabs/haneul/utils';
8
8
  import { execSync } from 'node:child_process';
9
- import { existsSync } from 'node:fs';
9
+ import { existsSync, mkdtempSync } from 'node:fs';
10
+ import { tmpdir } from 'node:os';
11
+ import { join } from 'node:path';
10
12
 
11
13
  export interface SubdirCommandFlags {
12
14
  outputDir?: string;
13
15
  noPrune?: boolean;
14
16
  noSummaries?: boolean;
15
17
  network?: 'mainnet' | 'testnet';
18
+ importExtension?: '.js' | '.ts' | 'none';
19
+ modules?: string[];
20
+ noTypes?: boolean;
21
+ noFunctions?: boolean;
22
+ private?: 'none' | 'entry' | 'all';
16
23
  }
17
24
 
18
25
  export default async function generate(
@@ -31,6 +38,7 @@ export default async function generate(
31
38
  network: flags.network ?? 'testnet',
32
39
  packageName: isValidHaneulObjectId(trimmed) ? trimmed : trimmed.split('/')[1],
33
40
  package: trimmed,
41
+ packageId: isValidHaneulObjectId(trimmed) ? trimmed : undefined,
34
42
  };
35
43
  } else {
36
44
  return {
@@ -45,8 +53,53 @@ export default async function generate(
45
53
  const generateSummaries =
46
54
  flags.noSummaries === undefined ? config.generateSummaries : !flags.noSummaries;
47
55
 
56
+ const cliPrivate =
57
+ flags.private !== undefined
58
+ ? flags.private === 'all'
59
+ ? true
60
+ : flags.private === 'none'
61
+ ? false
62
+ : 'entry'
63
+ : undefined;
64
+
65
+ const cliGenerate: PackageGenerate | undefined =
66
+ flags.modules !== undefined ||
67
+ flags.noTypes !== undefined ||
68
+ flags.noFunctions !== undefined ||
69
+ flags.private !== undefined
70
+ ? {
71
+ ...(flags.modules !== undefined && { modules: flags.modules }),
72
+ ...(flags.noTypes !== undefined && { types: !flags.noTypes as boolean }),
73
+ ...(flags.noFunctions !== undefined || flags.private !== undefined
74
+ ? {
75
+ functions: flags.noFunctions
76
+ ? false
77
+ : cliPrivate !== undefined
78
+ ? { private: cliPrivate }
79
+ : true,
80
+ }
81
+ : {}),
82
+ }
83
+ : undefined;
84
+
48
85
  for (const pkg of normalizedPackages) {
49
- if (generateSummaries && pkg.path) {
86
+ // Detect on-chain packages: they have 'network' field and no 'path'
87
+ const isOnChainPackage =
88
+ ('packageId' in pkg && pkg.packageId) || ('network' in pkg && !('path' in pkg));
89
+
90
+ // Generate summaries for on-chain packages using --package-id
91
+ if (isOnChainPackage) {
92
+ const packageId = 'packageId' in pkg ? pkg.packageId : pkg.package;
93
+ const tempDir = mkdtempSync(join(tmpdir(), 'haneul-codegen-'));
94
+ console.log(`Generating summary for on-chain package ${packageId} to ${tempDir}`);
95
+
96
+ execSync(`haneul move summary --package-id ${packageId} --output-directory ${tempDir}`, {
97
+ stdio: 'inherit',
98
+ });
99
+
100
+ // Set the path to use the generated summary directory
101
+ (pkg as { path?: string }).path = tempDir;
102
+ } else if (generateSummaries && pkg.path) {
50
103
  if (!existsSync(pkg.path)) {
51
104
  throw new Error(`Package path does not exist: ${pkg.path}`);
52
105
  }
@@ -56,11 +109,46 @@ export default async function generate(
56
109
  stdio: 'inherit',
57
110
  });
58
111
  }
112
+ const importExtension =
113
+ flags.importExtension === undefined
114
+ ? config.importExtension
115
+ : flags.importExtension === 'none'
116
+ ? ''
117
+ : flags.importExtension;
118
+
119
+ const pkgWithOverrides = cliGenerate
120
+ ? {
121
+ ...pkg,
122
+ generate: {
123
+ ...('generate' in pkg ? pkg.generate : {}),
124
+ ...cliGenerate,
125
+ },
126
+ }
127
+ : pkg;
128
+
129
+ // Fold deprecated privateMethods into globalGenerate
130
+ const globalGenerate: GenerateBase | undefined =
131
+ config.privateMethods && !config.generate?.functions
132
+ ? {
133
+ ...config.generate,
134
+ functions: {
135
+ private:
136
+ config.privateMethods === 'all'
137
+ ? true
138
+ : config.privateMethods === 'none'
139
+ ? false
140
+ : 'entry',
141
+ },
142
+ }
143
+ : config.generate;
144
+
59
145
  await generateFromPackageSummary({
60
- package: pkg,
146
+ package: pkgWithOverrides,
61
147
  prune: flags.noPrune === undefined ? config.prune : !flags.noPrune,
62
148
  outputDir: flags.outputDir ?? config.output,
63
- privateMethods: config.privateMethods,
149
+ globalGenerate,
150
+ importExtension,
151
+ includePhantomTypeParameters: config.includePhantomTypeParameters,
64
152
  });
65
153
  }
66
154
  }
package/src/config.ts CHANGED
@@ -5,6 +5,42 @@ import { isValidNamedPackage, isValidHaneulObjectId } from '@haneullabs/haneul/u
5
5
  import { cosmiconfig } from 'cosmiconfig';
6
6
  import * as z from 'zod/v4';
7
7
 
8
+ export const globalFunctionsOptionSchema = z.union([
9
+ z.boolean(),
10
+ z.object({
11
+ private: z.union([z.boolean(), z.literal('entry')]).optional(),
12
+ }),
13
+ ]);
14
+
15
+ export const functionsOptionSchema = z.union([
16
+ z.boolean(),
17
+ z.array(z.string()),
18
+ z.object({
19
+ private: z.union([z.boolean(), z.literal('entry')]).optional(),
20
+ }),
21
+ ]);
22
+
23
+ export const typesOptionSchema = z.union([z.boolean(), z.array(z.string())]);
24
+
25
+ export const globalGenerateSchema = z.object({
26
+ functions: globalFunctionsOptionSchema.optional(),
27
+ types: z.boolean().optional(),
28
+ });
29
+
30
+ export const moduleGenerateSchema = z.object({
31
+ functions: functionsOptionSchema.optional(),
32
+ types: typesOptionSchema.optional(),
33
+ });
34
+
35
+ export const packageGenerateSchema = globalGenerateSchema.extend({
36
+ modules: z
37
+ .union([
38
+ z.array(z.string()),
39
+ z.record(z.string(), z.union([z.literal(true), moduleGenerateSchema])),
40
+ ])
41
+ .optional(),
42
+ });
43
+
8
44
  export const onChainPackageSchema = z.object({
9
45
  package: z.string().refine((name) => isValidNamedPackage(name) || isValidHaneulObjectId(name), {
10
46
  message: 'Invalid package name or package ID',
@@ -12,25 +48,36 @@ export const onChainPackageSchema = z.object({
12
48
  packageName: z.string(),
13
49
  path: z.never().optional(),
14
50
  network: z.enum(['mainnet', 'testnet']),
51
+ generate: packageGenerateSchema.optional(),
15
52
  });
16
53
 
17
54
  export const localPackageSchema = z.object({
18
55
  path: z.string(),
19
56
  package: z.string(),
20
57
  packageName: z.string().optional(),
58
+ generate: packageGenerateSchema.optional(),
21
59
  });
22
60
 
23
61
  export const packageConfigSchema = z.union([onChainPackageSchema, localPackageSchema]);
24
62
 
63
+ export const importExtensionSchema = z.union([z.literal('.js'), z.literal('.ts'), z.literal('')]);
64
+ export type ImportExtension = z.infer<typeof importExtensionSchema>;
65
+
66
+ export type GenerateBase = z.infer<typeof globalGenerateSchema>;
67
+ export type PackageGenerate = z.infer<typeof packageGenerateSchema>;
68
+ export type FunctionsOption = z.infer<typeof functionsOptionSchema>;
69
+ export type TypesOption = z.infer<typeof typesOptionSchema>;
70
+
25
71
  export const configSchema = z.object({
26
72
  output: z.string(),
27
73
  prune: z.boolean().optional().default(true),
28
74
  generateSummaries: z.boolean().optional().default(true),
29
75
  packages: z.array(packageConfigSchema),
30
- privateMethods: z
31
- .union([z.literal('none'), z.literal('entry'), z.literal('all')])
32
- .optional()
33
- .default('entry'),
76
+ generate: globalGenerateSchema.optional(),
77
+ /** @deprecated Use `generate: { functions: { private: 'entry' } }` instead */
78
+ privateMethods: z.union([z.literal('none'), z.literal('entry'), z.literal('all')]).optional(),
79
+ importExtension: importExtensionSchema.optional().default('.js'),
80
+ includePhantomTypeParameters: z.boolean().optional().default(false),
34
81
  });
35
82
 
36
83
  export type PackageConfig = z.infer<typeof packageConfigSchema>;
@@ -46,7 +93,8 @@ export async function loadConfig(): Promise<ParsedHaneulCodegenConfig> {
46
93
  packages: [],
47
94
  prune: true,
48
95
  generateSummaries: true,
49
- privateMethods: 'entry',
96
+ importExtension: '.js',
97
+ includePhantomTypeParameters: false,
50
98
  };
51
99
  }
52
100
 
@@ -13,12 +13,25 @@ export class FileBuilder {
13
13
  starImports: Map<string, string> = new Map();
14
14
  protected reservedNames: Set<string> = new Set();
15
15
 
16
- addImport(module: string, name: string) {
16
+ addImport(module: string, name: string): string {
17
17
  if (!this.imports.has(module)) {
18
18
  this.imports.set(module, new Set());
19
19
  }
20
20
 
21
+ const isTypeImport = name.startsWith('type ');
22
+ const baseName = isTypeImport ? name.slice(5) : name;
23
+
24
+ if (this.reservedNames.has(baseName)) {
25
+ const alias = this.getUnusedName(baseName);
26
+ const aliasedImport = isTypeImport
27
+ ? `type ${baseName} as ${alias}`
28
+ : `${baseName} as ${alias}`;
29
+ this.imports.get(module)!.add(aliasedImport);
30
+ return alias;
31
+ }
32
+
21
33
  this.imports.get(module)!.add(name);
34
+ return baseName;
22
35
  }
23
36
 
24
37
  addStarImport(module: string, name: string) {
@@ -36,6 +49,7 @@ export class FileBuilder {
36
49
  i++;
37
50
  }
38
51
 
52
+ this.reservedNames.add(deConflictedName);
39
53
  return deConflictedName;
40
54
  }
41
55
 
@@ -2,16 +2,36 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export const utilsContent = /* ts */ `
5
- import { bcs, BcsType, TypeTag, TypeTagSerializer, BcsStruct, BcsEnum, BcsTuple } from '@haneullabs/haneul/bcs';
5
+ import {
6
+ bcs,
7
+ BcsType,
8
+ TypeTag,
9
+ TypeTagSerializer,
10
+ BcsStruct,
11
+ BcsEnum,
12
+ BcsTuple,
13
+ } from '@haneullabs/haneul/bcs';
6
14
  import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
7
15
  import { TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';
16
+ import { ClientWithCoreApi, HaneulClientTypes } from '@haneullabs/haneul/client';
8
17
 
9
18
  const MOVE_STDLIB_ADDRESS = normalizeHaneulAddress('0x1');
10
19
  const HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress('0x2');
11
- const HANEUL_SYSTEM_ADDRESS = normalizeHaneulAddress('0x3');
12
20
 
13
21
  export type RawTransactionArgument<T> = T | TransactionArgument;
14
22
 
23
+ export interface GetOptions<
24
+ Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},
25
+ > extends HaneulClientTypes.GetObjectOptions<Include> {
26
+ client: ClientWithCoreApi;
27
+ }
28
+
29
+ export interface GetManyOptions<
30
+ Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},
31
+ > extends HaneulClientTypes.GetObjectsOptions<Include> {
32
+ client: ClientWithCoreApi;
33
+ }
34
+
15
35
  export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {
16
36
  const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
17
37
 
@@ -36,7 +56,7 @@ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null
36
56
  return type ? bcs.vector(type) : null;
37
57
  } else if ('struct' in parsedTag) {
38
58
  const structTag = parsedTag.struct;
39
- const pkg = normalizeHaneulAddress(parsedTag.struct.address);
59
+ const pkg = normalizeHaneulAddress(structTag.address);
40
60
 
41
61
  if (pkg === MOVE_STDLIB_ADDRESS) {
42
62
  if (
@@ -47,12 +67,16 @@ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null
47
67
  }
48
68
 
49
69
  if (structTag.module === 'option' && structTag.name === 'Option') {
50
- const type = getPureBcsSchema(structTag.typeParams[0]!);
70
+ const type = getPureBcsSchema(structTag.typeParams[0]);
51
71
  return type ? bcs.option(type) : null;
52
72
  }
53
73
  }
54
74
 
55
- if (pkg === HANEUL_FRAMEWORK_ADDRESS && structTag.module === 'Object' && structTag.name === 'ID') {
75
+ if (
76
+ pkg === HANEUL_FRAMEWORK_ADDRESS &&
77
+ structTag.module === 'object' &&
78
+ (structTag.name === 'ID' || structTag.name === 'UID')
79
+ ) {
56
80
  return bcs.Address;
57
81
  }
58
82
  }
@@ -60,7 +84,11 @@ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null
60
84
  return null;
61
85
  }
62
86
 
63
- export function normalizeMoveArguments(args: unknown[] | object, argTypes: string[], parameterNames?: string[]) {
87
+ export function normalizeMoveArguments(
88
+ args: unknown[] | object,
89
+ argTypes: readonly (string | null)[],
90
+ parameterNames?: string[],
91
+ ) {
64
92
  const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
65
93
  if (parameterNames && argLen !== parameterNames.length) {
66
94
  throw new Error(
@@ -72,30 +100,32 @@ export function normalizeMoveArguments(args: unknown[] | object, argTypes: strin
72
100
 
73
101
  let index = 0;
74
102
  for (const [i, argType] of argTypes.entries()) {
75
- if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::deny_list::DenyList\`) {
76
- normalizedArgs.push((tx) => tx.object.denyList());
103
+ if (argType === '0x2::clock::Clock') {
104
+ normalizedArgs.push((tx) => tx.object.clock());
77
105
  continue;
78
106
  }
79
107
 
80
- if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::random::Random\`) {
108
+ if (argType === '0x2::random::Random') {
81
109
  normalizedArgs.push((tx) => tx.object.random());
82
110
  continue;
83
111
  }
84
112
 
85
- if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::clock::Clock\`) {
86
- normalizedArgs.push((tx) => tx.object.clock());
113
+ if (argType === '0x2::deny_list::DenyList') {
114
+ normalizedArgs.push((tx) => tx.object.denyList());
87
115
  continue;
88
116
  }
89
117
 
90
- if (argType === \`\${HANEUL_SYSTEM_ADDRESS}::haneul_system::HaneulSystemState\`) {
118
+ if (argType === '0x3::haneul_system::HaneulSystemState') {
91
119
  normalizedArgs.push((tx) => tx.object.system());
92
120
  continue;
93
121
  }
94
122
 
95
- let arg
123
+ let arg;
96
124
  if (Array.isArray(args)) {
97
125
  if (index >= args.length) {
98
- throw new Error(\`Invalid number of arguments, expected at least \${index + 1}, got \${args.length}\`);
126
+ throw new Error(
127
+ \`Invalid number of arguments, expected at least \${index + 1}, got \${args.length}\`,
128
+ );
99
129
  }
100
130
  arg = args[index];
101
131
  } else {
@@ -117,8 +147,8 @@ export function normalizeMoveArguments(args: unknown[] | object, argTypes: strin
117
147
  continue;
118
148
  }
119
149
 
120
- const type = argTypes[i]!;
121
- const bcsType = getPureBcsSchema(type);
150
+ const type = argTypes[i];
151
+ const bcsType = type === null ? null : getPureBcsSchema(type);
122
152
 
123
153
  if (bcsType) {
124
154
  const bytes = bcsType.serialize(arg as never);
@@ -138,7 +168,47 @@ export function normalizeMoveArguments(args: unknown[] | object, argTypes: strin
138
168
  export class MoveStruct<
139
169
  T extends Record<string, BcsType<any>>,
140
170
  const Name extends string = string,
141
- > extends BcsStruct<T, Name> {}
171
+ > extends BcsStruct<T, Name> {
172
+ async get<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
173
+ objectId,
174
+ ...options
175
+ }: GetOptions<Include>): Promise<
176
+ HaneulClientTypes.Object<Include & { content: true, json: true }> & { json: BcsStruct<T>['$inferType'] }
177
+ > {
178
+ const [res] = await this.getMany<Include>({
179
+ ...options,
180
+ objectIds: [objectId],
181
+ });
182
+
183
+ return res;
184
+ }
185
+
186
+ async getMany<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
187
+ client,
188
+ ...options
189
+ }: GetManyOptions<Include>): Promise<
190
+ Array<HaneulClientTypes.Object<Include & { content: true, json: true }> & { json: BcsStruct<T>['$inferType'] }>
191
+ > {
192
+ const response = (await client.core.getObjects({
193
+ ...options,
194
+ include: {
195
+ ...options.include,
196
+ content: true,
197
+ },
198
+ })) as HaneulClientTypes.GetObjectsResponse<Include & { content: true }>;
199
+
200
+ return response.objects.map((obj) => {
201
+ if (obj instanceof Error) {
202
+ throw obj;
203
+ }
204
+
205
+ return {
206
+ ...obj,
207
+ json: this.parse(obj.content),
208
+ };
209
+ });
210
+ }
211
+ }
142
212
 
143
213
  export class MoveEnum<
144
214
  T extends Record<string, BcsType<any> | null>,
@@ -146,7 +216,7 @@ export class MoveEnum<
146
216
  > extends BcsEnum<T, Name> {}
147
217
 
148
218
  export class MoveTuple<
149
- T extends readonly BcsType<any>[],
219
+ const T extends readonly BcsType<any>[],
150
220
  const Name extends string,
151
221
  > extends BcsTuple<T, Name> {}
152
222