@haneullabs/codegen 0.1.0 → 0.8.2

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 (145) hide show
  1. package/CHANGELOG.md +128 -33
  2. package/README.md +35 -33
  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 +106 -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 +65 -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/package.json +27 -28
  37. package/src/bin/bash-complete.ts +18 -7
  38. package/src/bin/cli.ts +3 -9
  39. package/src/cli/commands/generate/command.ts +32 -0
  40. package/src/cli/commands/generate/impl.ts +93 -5
  41. package/src/config.ts +55 -7
  42. package/src/file-builder.ts +14 -1
  43. package/src/generate-utils.ts +88 -18
  44. package/src/index.ts +89 -29
  45. package/src/move-module-builder.ts +181 -76
  46. package/src/render-types.ts +82 -29
  47. package/dist/cjs/bin/bash-complete.d.ts +0 -2
  48. package/dist/cjs/bin/bash-complete.js +0 -51
  49. package/dist/cjs/bin/bash-complete.js.map +0 -7
  50. package/dist/cjs/bin/cli.d.ts +0 -2
  51. package/dist/cjs/bin/cli.js +0 -34
  52. package/dist/cjs/bin/cli.js.map +0 -7
  53. package/dist/cjs/cli/cli.d.ts +0 -1
  54. package/dist/cjs/cli/cli.js +0 -49
  55. package/dist/cjs/cli/cli.js.map +0 -7
  56. package/dist/cjs/cli/commands/generate/command.d.ts +0 -1
  57. package/dist/cjs/cli/commands/generate/command.js +0 -80
  58. package/dist/cjs/cli/commands/generate/command.js.map +0 -7
  59. package/dist/cjs/cli/commands/generate/impl.d.ts +0 -8
  60. package/dist/cjs/cli/commands/generate/impl.js +0 -66
  61. package/dist/cjs/cli/commands/generate/impl.js.map +0 -7
  62. package/dist/cjs/cli/context.d.ts +0 -6
  63. package/dist/cjs/cli/context.js +0 -45
  64. package/dist/cjs/cli/context.js.map +0 -7
  65. package/dist/cjs/config.d.ts +0 -51
  66. package/dist/cjs/config.js +0 -75
  67. package/dist/cjs/config.js.map +0 -7
  68. package/dist/cjs/file-builder.d.ts +0 -13
  69. package/dist/cjs/file-builder.js +0 -83
  70. package/dist/cjs/file-builder.js.map +0 -7
  71. package/dist/cjs/generate-utils.d.ts +0 -1
  72. package/dist/cjs/generate-utils.js +0 -187
  73. package/dist/cjs/generate-utils.js.map +0 -7
  74. package/dist/cjs/index.d.ts +0 -8
  75. package/dist/cjs/index.js +0 -124
  76. package/dist/cjs/index.js.map +0 -7
  77. package/dist/cjs/move-module-builder.d.ts +0 -26
  78. package/dist/cjs/move-module-builder.js +0 -464
  79. package/dist/cjs/move-module-builder.js.map +0 -7
  80. package/dist/cjs/package.json +0 -5
  81. package/dist/cjs/render-types.d.ts +0 -19
  82. package/dist/cjs/render-types.js +0 -313
  83. package/dist/cjs/render-types.js.map +0 -7
  84. package/dist/cjs/summary.d.ts +0 -3
  85. package/dist/cjs/summary.js +0 -218
  86. package/dist/cjs/summary.js.map +0 -7
  87. package/dist/cjs/types/deserialized.d.ts +0 -89
  88. package/dist/cjs/types/deserialized.js +0 -17
  89. package/dist/cjs/types/deserialized.js.map +0 -7
  90. package/dist/cjs/types/summary.d.ts +0 -105
  91. package/dist/cjs/types/summary.js +0 -17
  92. package/dist/cjs/types/summary.js.map +0 -7
  93. package/dist/cjs/utils.d.ts +0 -22
  94. package/dist/cjs/utils.js +0 -164
  95. package/dist/cjs/utils.js.map +0 -7
  96. package/dist/esm/bin/bash-complete.d.ts +0 -2
  97. package/dist/esm/bin/bash-complete.js +0 -31
  98. package/dist/esm/bin/bash-complete.js.map +0 -7
  99. package/dist/esm/bin/cli.d.ts +0 -2
  100. package/dist/esm/bin/cli.js +0 -32
  101. package/dist/esm/bin/cli.js.map +0 -7
  102. package/dist/esm/cli/cli.d.ts +0 -1
  103. package/dist/esm/cli/cli.js +0 -29
  104. package/dist/esm/cli/cli.js.map +0 -7
  105. package/dist/esm/cli/commands/generate/command.d.ts +0 -1
  106. package/dist/esm/cli/commands/generate/command.js +0 -50
  107. package/dist/esm/cli/commands/generate/command.js.map +0 -7
  108. package/dist/esm/cli/commands/generate/impl.d.ts +0 -8
  109. package/dist/esm/cli/commands/generate/impl.js +0 -46
  110. package/dist/esm/cli/commands/generate/impl.js.map +0 -7
  111. package/dist/esm/cli/context.d.ts +0 -6
  112. package/dist/esm/cli/context.js +0 -15
  113. package/dist/esm/cli/context.js.map +0 -7
  114. package/dist/esm/config.d.ts +0 -51
  115. package/dist/esm/config.js +0 -45
  116. package/dist/esm/config.js.map +0 -7
  117. package/dist/esm/file-builder.d.ts +0 -13
  118. package/dist/esm/file-builder.js +0 -63
  119. package/dist/esm/file-builder.js.map +0 -7
  120. package/dist/esm/generate-utils.d.ts +0 -1
  121. package/dist/esm/generate-utils.js.map +0 -7
  122. package/dist/esm/index.d.ts +0 -8
  123. package/dist/esm/index.js +0 -104
  124. package/dist/esm/index.js.map +0 -7
  125. package/dist/esm/move-module-builder.d.ts +0 -26
  126. package/dist/esm/move-module-builder.js +0 -457
  127. package/dist/esm/move-module-builder.js.map +0 -7
  128. package/dist/esm/package.json +0 -5
  129. package/dist/esm/render-types.d.ts +0 -19
  130. package/dist/esm/render-types.js +0 -293
  131. package/dist/esm/render-types.js.map +0 -7
  132. package/dist/esm/summary.d.ts +0 -3
  133. package/dist/esm/summary.js +0 -198
  134. package/dist/esm/summary.js.map +0 -7
  135. package/dist/esm/types/deserialized.d.ts +0 -89
  136. package/dist/esm/types/deserialized.js +0 -1
  137. package/dist/esm/types/deserialized.js.map +0 -7
  138. package/dist/esm/types/summary.d.ts +0 -105
  139. package/dist/esm/types/summary.js +0 -1
  140. package/dist/esm/types/summary.js.map +0 -7
  141. package/dist/esm/utils.d.ts +0 -22
  142. package/dist/esm/utils.js +0 -134
  143. package/dist/esm/utils.js.map +0 -7
  144. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  145. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,72 @@
1
+ import { generateFromPackageSummary } from "../../../index.mjs";
2
+ import { loadConfig } from "../../../config.mjs";
3
+ import { join } from "node:path";
4
+ import { isValidHaneulObjectId, isValidNamedPackage } from "@haneullabs/haneul/utils";
5
+ import { existsSync, mkdtempSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { execSync } from "node:child_process";
8
+
9
+ //#region src/cli/commands/generate/impl.ts
10
+ async function generate(flags, ...packages) {
11
+ const config = await loadConfig();
12
+ const normalizedPackages = packages.length > 0 ? packages.map((p) => {
13
+ const trimmed = p.trim();
14
+ if (isValidHaneulObjectId(trimmed) || isValidNamedPackage(trimmed)) return {
15
+ network: flags.network ?? "testnet",
16
+ packageName: isValidHaneulObjectId(trimmed) ? trimmed : trimmed.split("/")[1],
17
+ package: trimmed,
18
+ packageId: isValidHaneulObjectId(trimmed) ? trimmed : void 0
19
+ };
20
+ else return {
21
+ package: "@local-pkg/" + trimmed,
22
+ packageName: trimmed,
23
+ path: trimmed
24
+ };
25
+ }) : config.packages;
26
+ const generateSummaries = flags.noSummaries === void 0 ? config.generateSummaries : !flags.noSummaries;
27
+ const cliPrivate = flags.private !== void 0 ? flags.private === "all" ? true : flags.private === "none" ? false : "entry" : void 0;
28
+ const cliGenerate = flags.modules !== void 0 || flags.noTypes !== void 0 || flags.noFunctions !== void 0 || flags.private !== void 0 ? {
29
+ ...flags.modules !== void 0 && { modules: flags.modules },
30
+ ...flags.noTypes !== void 0 && { types: !flags.noTypes },
31
+ ...flags.noFunctions !== void 0 || flags.private !== void 0 ? { functions: flags.noFunctions ? false : cliPrivate !== void 0 ? { private: cliPrivate } : true } : {}
32
+ } : void 0;
33
+ for (const pkg of normalizedPackages) {
34
+ if ("packageId" in pkg && pkg.packageId || "network" in pkg && !("path" in pkg)) {
35
+ const packageId = "packageId" in pkg ? pkg.packageId : pkg.package;
36
+ const tempDir = mkdtempSync(join(tmpdir(), "haneul-codegen-"));
37
+ console.log(`Generating summary for on-chain package ${packageId} to ${tempDir}`);
38
+ execSync(`haneul move summary --package-id ${packageId} --output-directory ${tempDir}`, { stdio: "inherit" });
39
+ pkg.path = tempDir;
40
+ } else if (generateSummaries && pkg.path) {
41
+ if (!existsSync(pkg.path)) throw new Error(`Package path does not exist: ${pkg.path}`);
42
+ execSync("haneul move summary", {
43
+ cwd: pkg.path,
44
+ stdio: "inherit"
45
+ });
46
+ }
47
+ const importExtension = flags.importExtension === void 0 ? config.importExtension : flags.importExtension === "none" ? "" : flags.importExtension;
48
+ const pkgWithOverrides = cliGenerate ? {
49
+ ...pkg,
50
+ generate: {
51
+ ..."generate" in pkg ? pkg.generate : {},
52
+ ...cliGenerate
53
+ }
54
+ } : pkg;
55
+ const globalGenerate = config.privateMethods && !config.generate?.functions ? {
56
+ ...config.generate,
57
+ functions: { private: config.privateMethods === "all" ? true : config.privateMethods === "none" ? false : "entry" }
58
+ } : config.generate;
59
+ await generateFromPackageSummary({
60
+ package: pkgWithOverrides,
61
+ prune: flags.noPrune === void 0 ? config.prune : !flags.noPrune,
62
+ outputDir: flags.outputDir ?? config.output,
63
+ globalGenerate,
64
+ importExtension,
65
+ includePhantomTypeParameters: config.includePhantomTypeParameters
66
+ });
67
+ }
68
+ }
69
+
70
+ //#endregion
71
+ export { generate as default };
72
+ //# sourceMappingURL=impl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"impl.mjs","names":[],"sources":["../../../../src/cli/commands/generate/impl.ts"],"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, type GenerateBase, type PackageGenerate } from '../../../config.js';\nimport { isValidNamedPackage, isValidHaneulObjectId } from '@haneullabs/haneul/utils';\nimport { execSync } from 'node:child_process';\nimport { existsSync, mkdtempSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\n\nexport interface SubdirCommandFlags {\n\toutputDir?: string;\n\tnoPrune?: boolean;\n\tnoSummaries?: boolean;\n\tnetwork?: 'mainnet' | 'testnet';\n\timportExtension?: '.js' | '.ts' | 'none';\n\tmodules?: string[];\n\tnoTypes?: boolean;\n\tnoFunctions?: boolean;\n\tprivate?: 'none' | 'entry' | 'all';\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\tpackageId: isValidHaneulObjectId(trimmed) ? trimmed : undefined,\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\tconst cliPrivate =\n\t\tflags.private !== undefined\n\t\t\t? flags.private === 'all'\n\t\t\t\t? true\n\t\t\t\t: flags.private === 'none'\n\t\t\t\t\t? false\n\t\t\t\t\t: 'entry'\n\t\t\t: undefined;\n\n\tconst cliGenerate: PackageGenerate | undefined =\n\t\tflags.modules !== undefined ||\n\t\tflags.noTypes !== undefined ||\n\t\tflags.noFunctions !== undefined ||\n\t\tflags.private !== undefined\n\t\t\t? {\n\t\t\t\t\t...(flags.modules !== undefined && { modules: flags.modules }),\n\t\t\t\t\t...(flags.noTypes !== undefined && { types: !flags.noTypes as boolean }),\n\t\t\t\t\t...(flags.noFunctions !== undefined || flags.private !== undefined\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tfunctions: flags.noFunctions\n\t\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t\t: cliPrivate !== undefined\n\t\t\t\t\t\t\t\t\t\t? { private: cliPrivate }\n\t\t\t\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t}\n\t\t\t: undefined;\n\n\tfor (const pkg of normalizedPackages) {\n\t\t// Detect on-chain packages: they have 'network' field and no 'path'\n\t\tconst isOnChainPackage =\n\t\t\t('packageId' in pkg && pkg.packageId) || ('network' in pkg && !('path' in pkg));\n\n\t\t// Generate summaries for on-chain packages using --package-id\n\t\tif (isOnChainPackage) {\n\t\t\tconst packageId = 'packageId' in pkg ? pkg.packageId : pkg.package;\n\t\t\tconst tempDir = mkdtempSync(join(tmpdir(), 'haneul-codegen-'));\n\t\t\tconsole.log(`Generating summary for on-chain package ${packageId} to ${tempDir}`);\n\n\t\t\texecSync(`haneul move summary --package-id ${packageId} --output-directory ${tempDir}`, {\n\t\t\t\tstdio: 'inherit',\n\t\t\t});\n\n\t\t\t// Set the path to use the generated summary directory\n\t\t\t(pkg as { path?: string }).path = tempDir;\n\t\t} else if (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\tconst importExtension =\n\t\t\tflags.importExtension === undefined\n\t\t\t\t? config.importExtension\n\t\t\t\t: flags.importExtension === 'none'\n\t\t\t\t\t? ''\n\t\t\t\t\t: flags.importExtension;\n\n\t\tconst pkgWithOverrides = cliGenerate\n\t\t\t? {\n\t\t\t\t\t...pkg,\n\t\t\t\t\tgenerate: {\n\t\t\t\t\t\t...('generate' in pkg ? pkg.generate : {}),\n\t\t\t\t\t\t...cliGenerate,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: pkg;\n\n\t\t// Fold deprecated privateMethods into globalGenerate\n\t\tconst globalGenerate: GenerateBase | undefined =\n\t\t\tconfig.privateMethods && !config.generate?.functions\n\t\t\t\t? {\n\t\t\t\t\t\t...config.generate,\n\t\t\t\t\t\tfunctions: {\n\t\t\t\t\t\t\tprivate:\n\t\t\t\t\t\t\t\tconfig.privateMethods === 'all'\n\t\t\t\t\t\t\t\t\t? true\n\t\t\t\t\t\t\t\t\t: config.privateMethods === 'none'\n\t\t\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t\t\t: 'entry',\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: config.generate;\n\n\t\tawait generateFromPackageSummary({\n\t\t\tpackage: pkgWithOverrides,\n\t\t\tprune: flags.noPrune === undefined ? config.prune : !flags.noPrune,\n\t\t\toutputDir: flags.outputDir ?? config.output,\n\t\t\tglobalGenerate,\n\t\t\timportExtension,\n\t\t\tincludePhantomTypeParameters: config.includePhantomTypeParameters,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;AAwBA,eAA8B,SAE7B,OACA,GAAG,UACa;CAChB,MAAM,SAAS,MAAM,YAAY;CAEjC,MAAM,qBACL,SAAS,SAAS,IACf,SAAS,KAAK,MAAM;EACpB,MAAM,UAAU,EAAE,MAAM;AACxB,MAAI,sBAAsB,QAAQ,IAAI,oBAAoB,QAAQ,CACjE,QAAO;GACN,SAAS,MAAM,WAAW;GAC1B,aAAa,sBAAsB,QAAQ,GAAG,UAAU,QAAQ,MAAM,IAAI,CAAC;GAC3E,SAAS;GACT,WAAW,sBAAsB,QAAQ,GAAG,UAAU;GACtD;MAED,QAAO;GACN,SAAS,gBAAgB;GACzB,aAAa;GACb,MAAM;GACN;GAED,GACD,OAAO;CAEX,MAAM,oBACL,MAAM,gBAAgB,SAAY,OAAO,oBAAoB,CAAC,MAAM;CAErE,MAAM,aACL,MAAM,YAAY,SACf,MAAM,YAAY,QACjB,OACA,MAAM,YAAY,SACjB,QACA,UACF;CAEJ,MAAM,cACL,MAAM,YAAY,UAClB,MAAM,YAAY,UAClB,MAAM,gBAAgB,UACtB,MAAM,YAAY,SACf;EACA,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,SAAS;EAC7D,GAAI,MAAM,YAAY,UAAa,EAAE,OAAO,CAAC,MAAM,SAAoB;EACvE,GAAI,MAAM,gBAAgB,UAAa,MAAM,YAAY,SACtD,EACA,WAAW,MAAM,cACd,QACA,eAAe,SACd,EAAE,SAAS,YAAY,GACvB,MACJ,GACA,EAAE;EACL,GACA;AAEJ,MAAK,MAAM,OAAO,oBAAoB;AAMrC,MAHE,eAAe,OAAO,IAAI,aAAe,aAAa,OAAO,EAAE,UAAU,MAGrD;GACrB,MAAM,YAAY,eAAe,MAAM,IAAI,YAAY,IAAI;GAC3D,MAAM,UAAU,YAAY,KAAK,QAAQ,EAAE,kBAAkB,CAAC;AAC9D,WAAQ,IAAI,2CAA2C,UAAU,MAAM,UAAU;AAEjF,YAAS,oCAAoC,UAAU,sBAAsB,WAAW,EACvF,OAAO,WACP,CAAC;AAGF,GAAC,IAA0B,OAAO;aACxB,qBAAqB,IAAI,MAAM;AACzC,OAAI,CAAC,WAAW,IAAI,KAAK,CACxB,OAAM,IAAI,MAAM,gCAAgC,IAAI,OAAO;AAG5D,YAAS,uBAAuB;IAC/B,KAAK,IAAI;IACT,OAAO;IACP,CAAC;;EAEH,MAAM,kBACL,MAAM,oBAAoB,SACvB,OAAO,kBACP,MAAM,oBAAoB,SACzB,KACA,MAAM;EAEX,MAAM,mBAAmB,cACtB;GACA,GAAG;GACH,UAAU;IACT,GAAI,cAAc,MAAM,IAAI,WAAW,EAAE;IACzC,GAAG;IACH;GACD,GACA;EAGH,MAAM,iBACL,OAAO,kBAAkB,CAAC,OAAO,UAAU,YACxC;GACA,GAAG,OAAO;GACV,WAAW,EACV,SACC,OAAO,mBAAmB,QACvB,OACA,OAAO,mBAAmB,SACzB,QACA,SACL;GACD,GACA,OAAO;AAEX,QAAM,2BAA2B;GAChC,SAAS;GACT,OAAO,MAAM,YAAY,SAAY,OAAO,QAAQ,CAAC,MAAM;GAC3D,WAAW,MAAM,aAAa,OAAO;GACrC;GACA;GACA,8BAA8B,OAAO;GACrC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+
5
+ //#region src/cli/context.ts
6
+ function buildContext(process) {
7
+ return {
8
+ process,
9
+ os,
10
+ fs,
11
+ path
12
+ };
13
+ }
14
+
15
+ //#endregion
16
+ export { buildContext };
17
+ //# sourceMappingURL=context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.mjs","names":[],"sources":["../../src/cli/context.ts"],"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"],"mappings":";;;;;AAaA,SAAgB,aAAa,SAAuC;AACnE,QAAO;EACN;EACA;EACA;EACA;EACA"}
@@ -0,0 +1,106 @@
1
+ import * as z from "zod/v4";
2
+
3
+ //#region src/config.d.ts
4
+
5
+ declare const globalGenerateSchema: z.ZodObject<{
6
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
7
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
8
+ }, z.core.$strip>]>>;
9
+ types: z.ZodOptional<z.ZodBoolean>;
10
+ }, z.core.$strip>;
11
+ declare const packageConfigSchema: z.ZodUnion<readonly [z.ZodObject<{
12
+ package: z.ZodString;
13
+ packageName: z.ZodString;
14
+ path: z.ZodOptional<z.ZodNever>;
15
+ network: z.ZodEnum<{
16
+ mainnet: "mainnet";
17
+ testnet: "testnet";
18
+ }>;
19
+ generate: z.ZodOptional<z.ZodObject<{
20
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
21
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
22
+ }, z.core.$strip>]>>;
23
+ types: z.ZodOptional<z.ZodBoolean>;
24
+ modules: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
25
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodObject<{
26
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
27
+ }, z.core.$strip>]>>;
28
+ types: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
29
+ }, z.core.$strip>]>>]>>;
30
+ }, z.core.$strip>>;
31
+ }, z.core.$strip>, z.ZodObject<{
32
+ path: z.ZodString;
33
+ package: z.ZodString;
34
+ packageName: z.ZodOptional<z.ZodString>;
35
+ generate: z.ZodOptional<z.ZodObject<{
36
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
37
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
38
+ }, z.core.$strip>]>>;
39
+ types: z.ZodOptional<z.ZodBoolean>;
40
+ modules: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
41
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodObject<{
42
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
43
+ }, z.core.$strip>]>>;
44
+ types: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
45
+ }, z.core.$strip>]>>]>>;
46
+ }, z.core.$strip>>;
47
+ }, z.core.$strip>]>;
48
+ declare const importExtensionSchema: z.ZodUnion<readonly [z.ZodLiteral<".js">, z.ZodLiteral<".ts">, z.ZodLiteral<"">]>;
49
+ type ImportExtension = z.infer<typeof importExtensionSchema>;
50
+ type GenerateBase = z.infer<typeof globalGenerateSchema>;
51
+ declare const configSchema: z.ZodObject<{
52
+ output: z.ZodString;
53
+ prune: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
54
+ generateSummaries: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
55
+ packages: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
56
+ package: z.ZodString;
57
+ packageName: z.ZodString;
58
+ path: z.ZodOptional<z.ZodNever>;
59
+ network: z.ZodEnum<{
60
+ mainnet: "mainnet";
61
+ testnet: "testnet";
62
+ }>;
63
+ generate: z.ZodOptional<z.ZodObject<{
64
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
65
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
66
+ }, z.core.$strip>]>>;
67
+ types: z.ZodOptional<z.ZodBoolean>;
68
+ modules: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
69
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodObject<{
70
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
71
+ }, z.core.$strip>]>>;
72
+ types: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
73
+ }, z.core.$strip>]>>]>>;
74
+ }, z.core.$strip>>;
75
+ }, z.core.$strip>, z.ZodObject<{
76
+ path: z.ZodString;
77
+ package: z.ZodString;
78
+ packageName: z.ZodOptional<z.ZodString>;
79
+ generate: z.ZodOptional<z.ZodObject<{
80
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
81
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
82
+ }, z.core.$strip>]>>;
83
+ types: z.ZodOptional<z.ZodBoolean>;
84
+ modules: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
85
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodObject<{
86
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
87
+ }, z.core.$strip>]>>;
88
+ types: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
89
+ }, z.core.$strip>]>>]>>;
90
+ }, z.core.$strip>>;
91
+ }, z.core.$strip>]>>;
92
+ generate: z.ZodOptional<z.ZodObject<{
93
+ functions: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
94
+ private: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"entry">]>>;
95
+ }, z.core.$strip>]>>;
96
+ types: z.ZodOptional<z.ZodBoolean>;
97
+ }, z.core.$strip>>;
98
+ privateMethods: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"none">, z.ZodLiteral<"entry">, z.ZodLiteral<"all">]>>;
99
+ importExtension: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<".js">, z.ZodLiteral<".ts">, z.ZodLiteral<"">]>>>;
100
+ includePhantomTypeParameters: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
101
+ }, z.core.$strip>;
102
+ type PackageConfig = z.infer<typeof packageConfigSchema>;
103
+ type HaneulCodegenConfig = z.input<typeof configSchema>;
104
+ //#endregion
105
+ export { GenerateBase, HaneulCodegenConfig, ImportExtension, PackageConfig };
106
+ //# sourceMappingURL=config.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.mts","names":[],"sources":["../src/config.ts"],"sourcesContent":[],"mappings":";;;;cAwBa,sBAAoB,CAAA,CAAA;;;;;;cAoCpB,qBAAmB,CAAA,CAAA,mBAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEnB,uBAAqB,CAAA,CAAA,mBAAA,CAAA,CAAA,mBAAA,CAAA,CAAA,mBAAA,CAAA,CAAA;KACtB,eAAA,GAAkB,CAAA,CAAE,aAAa;KAEjC,YAAA,GAAe,CAAA,CAAE,aAAa;AALV,cAUnB,YAVmB,EAUP,CAAA,CAAA,SAVO,CAAA;EAEnB,MAAA,aAAA;EAAqB,KAAA,cAAA,cAAA,aAAA,CAAA,CAAA;EAAA,iBAAA,cAAA,cAAA,aAAA,CAAA,CAAA;EAAA,QAAA,YAAA,WAAA,CAAA,SAAA,YAAA,CAAA;IAAA,OAAA,aAAA;IAAA,WAAA,aAAA;IACtB,IAAA,eAAe,WAAkB,CAAA;IAEjC,OAAA,WAAY,CAAA;MAKX,OAUX,EAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAEU,aAAA,GAAgB,CAAA,CAAE,aAAa;KAC/B,mBAAA,GAAsB,CAAA,CAAE,aAAa"}
@@ -0,0 +1,70 @@
1
+ import { isValidHaneulObjectId, isValidNamedPackage } from "@haneullabs/haneul/utils";
2
+ import { cosmiconfig } from "cosmiconfig";
3
+ import * as z from "zod/v4";
4
+
5
+ //#region src/config.ts
6
+ const globalFunctionsOptionSchema = z.union([z.boolean(), z.object({ private: z.union([z.boolean(), z.literal("entry")]).optional() })]);
7
+ const functionsOptionSchema = z.union([
8
+ z.boolean(),
9
+ z.array(z.string()),
10
+ z.object({ private: z.union([z.boolean(), z.literal("entry")]).optional() })
11
+ ]);
12
+ const typesOptionSchema = z.union([z.boolean(), z.array(z.string())]);
13
+ const globalGenerateSchema = z.object({
14
+ functions: globalFunctionsOptionSchema.optional(),
15
+ types: z.boolean().optional()
16
+ });
17
+ const moduleGenerateSchema = z.object({
18
+ functions: functionsOptionSchema.optional(),
19
+ types: typesOptionSchema.optional()
20
+ });
21
+ const packageGenerateSchema = globalGenerateSchema.extend({ modules: z.union([z.array(z.string()), z.record(z.string(), z.union([z.literal(true), moduleGenerateSchema]))]).optional() });
22
+ const onChainPackageSchema = z.object({
23
+ package: z.string().refine((name) => isValidNamedPackage(name) || isValidHaneulObjectId(name), { message: "Invalid package name or package ID" }),
24
+ packageName: z.string(),
25
+ path: z.never().optional(),
26
+ network: z.enum(["mainnet", "testnet"]),
27
+ generate: packageGenerateSchema.optional()
28
+ });
29
+ const localPackageSchema = z.object({
30
+ path: z.string(),
31
+ package: z.string(),
32
+ packageName: z.string().optional(),
33
+ generate: packageGenerateSchema.optional()
34
+ });
35
+ const packageConfigSchema = z.union([onChainPackageSchema, localPackageSchema]);
36
+ const importExtensionSchema = z.union([
37
+ z.literal(".js"),
38
+ z.literal(".ts"),
39
+ z.literal("")
40
+ ]);
41
+ const configSchema = z.object({
42
+ output: z.string(),
43
+ prune: z.boolean().optional().default(true),
44
+ generateSummaries: z.boolean().optional().default(true),
45
+ packages: z.array(packageConfigSchema),
46
+ generate: globalGenerateSchema.optional(),
47
+ privateMethods: z.union([
48
+ z.literal("none"),
49
+ z.literal("entry"),
50
+ z.literal("all")
51
+ ]).optional(),
52
+ importExtension: importExtensionSchema.optional().default(".js"),
53
+ includePhantomTypeParameters: z.boolean().optional().default(false)
54
+ });
55
+ async function loadConfig() {
56
+ const config = await cosmiconfig("haneul-codegen").search();
57
+ if (!config) return {
58
+ output: "./generated",
59
+ packages: [],
60
+ prune: true,
61
+ generateSummaries: true,
62
+ importExtension: ".js",
63
+ includePhantomTypeParameters: false
64
+ };
65
+ return configSchema.parse(config.config);
66
+ }
67
+
68
+ //#endregion
69
+ export { loadConfig };
70
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"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 globalFunctionsOptionSchema = z.union([\n\tz.boolean(),\n\tz.object({\n\t\tprivate: z.union([z.boolean(), z.literal('entry')]).optional(),\n\t}),\n]);\n\nexport const functionsOptionSchema = z.union([\n\tz.boolean(),\n\tz.array(z.string()),\n\tz.object({\n\t\tprivate: z.union([z.boolean(), z.literal('entry')]).optional(),\n\t}),\n]);\n\nexport const typesOptionSchema = z.union([z.boolean(), z.array(z.string())]);\n\nexport const globalGenerateSchema = z.object({\n\tfunctions: globalFunctionsOptionSchema.optional(),\n\ttypes: z.boolean().optional(),\n});\n\nexport const moduleGenerateSchema = z.object({\n\tfunctions: functionsOptionSchema.optional(),\n\ttypes: typesOptionSchema.optional(),\n});\n\nexport const packageGenerateSchema = globalGenerateSchema.extend({\n\tmodules: z\n\t\t.union([\n\t\t\tz.array(z.string()),\n\t\t\tz.record(z.string(), z.union([z.literal(true), moduleGenerateSchema])),\n\t\t])\n\t\t.optional(),\n});\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\tgenerate: packageGenerateSchema.optional(),\n});\n\nexport const localPackageSchema = z.object({\n\tpath: z.string(),\n\tpackage: z.string(),\n\tpackageName: z.string().optional(),\n\tgenerate: packageGenerateSchema.optional(),\n});\n\nexport const packageConfigSchema = z.union([onChainPackageSchema, localPackageSchema]);\n\nexport const importExtensionSchema = z.union([z.literal('.js'), z.literal('.ts'), z.literal('')]);\nexport type ImportExtension = z.infer<typeof importExtensionSchema>;\n\nexport type GenerateBase = z.infer<typeof globalGenerateSchema>;\nexport type PackageGenerate = z.infer<typeof packageGenerateSchema>;\nexport type FunctionsOption = z.infer<typeof functionsOptionSchema>;\nexport type TypesOption = z.infer<typeof typesOptionSchema>;\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\tgenerate: globalGenerateSchema.optional(),\n\t/** @deprecated Use `generate: { functions: { private: 'entry' } }` instead */\n\tprivateMethods: z.union([z.literal('none'), z.literal('entry'), z.literal('all')]).optional(),\n\timportExtension: importExtensionSchema.optional().default('.js'),\n\tincludePhantomTypeParameters: z.boolean().optional().default(false),\n});\n\nexport type PackageConfig = z.infer<typeof packageConfigSchema>;\nexport type HaneulCodegenConfig = z.input<typeof configSchema>;\nexport type ParsedSuiCodegenConfig = z.infer<typeof configSchema>;\n\nexport async function loadConfig(): Promise<ParsedSuiCodegenConfig> {\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\timportExtension: '.js',\n\t\t\tincludePhantomTypeParameters: false,\n\t\t};\n\t}\n\n\treturn configSchema.parse(config.config);\n}\n"],"mappings":";;;;;AAOA,MAAa,8BAA8B,EAAE,MAAM,CAClD,EAAE,SAAS,EACX,EAAE,OAAO,EACR,SAAS,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,QAAQ,QAAQ,CAAC,CAAC,CAAC,UAAU,EAC9D,CAAC,CACF,CAAC;AAEF,MAAa,wBAAwB,EAAE,MAAM;CAC5C,EAAE,SAAS;CACX,EAAE,MAAM,EAAE,QAAQ,CAAC;CACnB,EAAE,OAAO,EACR,SAAS,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,QAAQ,QAAQ,CAAC,CAAC,CAAC,UAAU,EAC9D,CAAC;CACF,CAAC;AAEF,MAAa,oBAAoB,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE5E,MAAa,uBAAuB,EAAE,OAAO;CAC5C,WAAW,4BAA4B,UAAU;CACjD,OAAO,EAAE,SAAS,CAAC,UAAU;CAC7B,CAAC;AAEF,MAAa,uBAAuB,EAAE,OAAO;CAC5C,WAAW,sBAAsB,UAAU;CAC3C,OAAO,kBAAkB,UAAU;CACnC,CAAC;AAEF,MAAa,wBAAwB,qBAAqB,OAAO,EAChE,SAAS,EACP,MAAM,CACN,EAAE,MAAM,EAAE,QAAQ,CAAC,EACnB,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,EAAE,QAAQ,KAAK,EAAE,qBAAqB,CAAC,CAAC,CACtE,CAAC,CACD,UAAU,EACZ,CAAC;AAEF,MAAa,uBAAuB,EAAE,OAAO;CAC5C,SAAS,EAAE,QAAQ,CAAC,QAAQ,SAAS,oBAAoB,KAAK,IAAI,sBAAsB,KAAK,EAAE,EAC9F,SAAS,sCACT,CAAC;CACF,aAAa,EAAE,QAAQ;CACvB,MAAM,EAAE,OAAO,CAAC,UAAU;CAC1B,SAAS,EAAE,KAAK,CAAC,WAAW,UAAU,CAAC;CACvC,UAAU,sBAAsB,UAAU;CAC1C,CAAC;AAEF,MAAa,qBAAqB,EAAE,OAAO;CAC1C,MAAM,EAAE,QAAQ;CAChB,SAAS,EAAE,QAAQ;CACnB,aAAa,EAAE,QAAQ,CAAC,UAAU;CAClC,UAAU,sBAAsB,UAAU;CAC1C,CAAC;AAEF,MAAa,sBAAsB,EAAE,MAAM,CAAC,sBAAsB,mBAAmB,CAAC;AAEtF,MAAa,wBAAwB,EAAE,MAAM;CAAC,EAAE,QAAQ,MAAM;CAAE,EAAE,QAAQ,MAAM;CAAE,EAAE,QAAQ,GAAG;CAAC,CAAC;AAQjG,MAAa,eAAe,EAAE,OAAO;CACpC,QAAQ,EAAE,QAAQ;CAClB,OAAO,EAAE,SAAS,CAAC,UAAU,CAAC,QAAQ,KAAK;CAC3C,mBAAmB,EAAE,SAAS,CAAC,UAAU,CAAC,QAAQ,KAAK;CACvD,UAAU,EAAE,MAAM,oBAAoB;CACtC,UAAU,qBAAqB,UAAU;CAEzC,gBAAgB,EAAE,MAAM;EAAC,EAAE,QAAQ,OAAO;EAAE,EAAE,QAAQ,QAAQ;EAAE,EAAE,QAAQ,MAAM;EAAC,CAAC,CAAC,UAAU;CAC7F,iBAAiB,sBAAsB,UAAU,CAAC,QAAQ,MAAM;CAChE,8BAA8B,EAAE,SAAS,CAAC,UAAU,CAAC,QAAQ,MAAM;CACnE,CAAC;AAMF,eAAsB,aAA8C;CACnE,MAAM,SAAS,MAAM,YAAY,iBAAiB,CAAC,QAAQ;AAE3D,KAAI,CAAC,OACJ,QAAO;EACN,QAAQ;EACR,UAAU,EAAE;EACZ,OAAO;EACP,mBAAmB;EACnB,iBAAiB;EACjB,8BAA8B;EAC9B;AAGF,QAAO,aAAa,MAAM,OAAO,OAAO"}
@@ -0,0 +1,65 @@
1
+ import { getSafeName } from "./render-types.mjs";
2
+ import { parseTS, printNodes } from "./utils.mjs";
3
+ import { relative, resolve } from "path";
4
+
5
+ //#region src/file-builder.ts
6
+ var FileBuilder = class {
7
+ constructor() {
8
+ this.statements = [];
9
+ this.exports = [];
10
+ this.imports = /* @__PURE__ */ new Map();
11
+ this.starImports = /* @__PURE__ */ new Map();
12
+ this.reservedNames = /* @__PURE__ */ new Set();
13
+ }
14
+ addImport(module, name) {
15
+ if (!this.imports.has(module)) this.imports.set(module, /* @__PURE__ */ new Set());
16
+ const isTypeImport = name.startsWith("type ");
17
+ const baseName = isTypeImport ? name.slice(5) : name;
18
+ if (this.reservedNames.has(baseName)) {
19
+ const alias = this.getUnusedName(baseName);
20
+ const aliasedImport = isTypeImport ? `type ${baseName} as ${alias}` : `${baseName} as ${alias}`;
21
+ this.imports.get(module).add(aliasedImport);
22
+ return alias;
23
+ }
24
+ this.imports.get(module).add(name);
25
+ return baseName;
26
+ }
27
+ addStarImport(module, name) {
28
+ const importName = this.getUnusedName(name);
29
+ this.starImports.set(importName, module);
30
+ return importName;
31
+ }
32
+ getUnusedName(name) {
33
+ let deConflictedName = getSafeName(name);
34
+ let i = 1;
35
+ while (this.reservedNames.has(deConflictedName)) {
36
+ deConflictedName = `${name}_${i}`;
37
+ i++;
38
+ }
39
+ return deConflictedName;
40
+ }
41
+ async getHeader() {
42
+ return [
43
+ "/**************************************************************",
44
+ " * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *",
45
+ " **************************************************************/",
46
+ ""
47
+ ].join("\n");
48
+ }
49
+ async toString(modDir, filePath) {
50
+ const importStatements = [...this.imports.entries()].flatMap(([module, names]) => parseTS`import { ${[...names].join(", ")} } from '${modulePath(module)}'`);
51
+ const starImportStatements = [...this.starImports.entries()].flatMap(([name, module]) => parseTS`import * as ${name} from '${modulePath(module)}'`);
52
+ return `${await this.getHeader()}${printNodes(...importStatements, ...starImportStatements, ...this.statements)}`;
53
+ function modulePath(mod) {
54
+ if (!mod.startsWith("~root/")) return mod;
55
+ const sourcePath = resolve(modDir, filePath);
56
+ const destPath = resolve(modDir, mod.replace("~root/", "./"));
57
+ const relativePath = relative(sourcePath.split("/").slice(0, -1).join("/"), destPath);
58
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
59
+ }
60
+ }
61
+ };
62
+
63
+ //#endregion
64
+ export { FileBuilder };
65
+ //# sourceMappingURL=file-builder.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-builder.mjs","names":[],"sources":["../src/file-builder.ts"],"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): string {\n\t\tif (!this.imports.has(module)) {\n\t\t\tthis.imports.set(module, new Set());\n\t\t}\n\n\t\tconst isTypeImport = name.startsWith('type ');\n\t\tconst baseName = isTypeImport ? name.slice(5) : name;\n\n\t\tif (this.reservedNames.has(baseName)) {\n\t\t\tconst alias = this.getUnusedName(baseName);\n\t\t\tconst aliasedImport = isTypeImport\n\t\t\t\t? `type ${baseName} as ${alias}`\n\t\t\t\t: `${baseName} as ${alias}`;\n\t\t\tthis.imports.get(module)!.add(aliasedImport);\n\t\t\treturn alias;\n\t\t}\n\n\t\tthis.imports.get(module)!.add(name);\n\t\treturn baseName;\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"],"mappings":";;;;;AAQA,IAAa,cAAb,MAAyB;;oBACK,EAAE;iBACX,EAAE;iCACc,IAAI,KAAK;qCACV,IAAI,KAAK;uCACL,IAAI,KAAK;;CAEhD,UAAU,QAAgB,MAAsB;AAC/C,MAAI,CAAC,KAAK,QAAQ,IAAI,OAAO,CAC5B,MAAK,QAAQ,IAAI,wBAAQ,IAAI,KAAK,CAAC;EAGpC,MAAM,eAAe,KAAK,WAAW,QAAQ;EAC7C,MAAM,WAAW,eAAe,KAAK,MAAM,EAAE,GAAG;AAEhD,MAAI,KAAK,cAAc,IAAI,SAAS,EAAE;GACrC,MAAM,QAAQ,KAAK,cAAc,SAAS;GAC1C,MAAM,gBAAgB,eACnB,QAAQ,SAAS,MAAM,UACvB,GAAG,SAAS,MAAM;AACrB,QAAK,QAAQ,IAAI,OAAO,CAAE,IAAI,cAAc;AAC5C,UAAO;;AAGR,OAAK,QAAQ,IAAI,OAAO,CAAE,IAAI,KAAK;AACnC,SAAO;;CAGR,cAAc,QAAgB,MAAc;EAC3C,MAAM,aAAa,KAAK,cAAc,KAAK;AAC3C,OAAK,YAAY,IAAI,YAAY,OAAO;AACxC,SAAO;;CAGR,cAAc,MAAc;EAC3B,IAAI,mBAAmB,YAAY,KAAK;EAExC,IAAI,IAAI;AACR,SAAO,KAAK,cAAc,IAAI,iBAAiB,EAAE;AAChD,sBAAmB,GAAG,KAAK,GAAG;AAC9B;;AAGD,SAAO;;CAGR,MAAM,YAAY;AACjB,SAAO;GACN;GACA;GACA;GACA;GACA,CAAC,KAAK,KAAK;;CAGb,MAAM,SAAS,QAAgB,UAAkB;EAChD,MAAM,mBAAmB,CAAC,GAAG,KAAK,QAAQ,SAAS,CAAC,CAAC,SACnD,CAAC,QAAQ,WACT,OAAO,YAAY,CAAC,GAAG,MAAM,CAAC,KAAK,KAAK,CAAC,WAAW,WAAW,OAAO,CAAC,GACxE;EACD,MAAM,uBAAuB,CAAC,GAAG,KAAK,YAAY,SAAS,CAAC,CAAC,SAC3D,CAAC,MAAM,YAAY,OAAO,eAAe,KAAK,SAAS,WAAW,OAAO,CAAC,GAC3E;AAED,SAAO,GAAG,MAAM,KAAK,WAAW,GAAG,WAAW,GAAG,kBAAkB,GAAG,sBAAsB,GAAG,KAAK,WAAW;EAE/G,SAAS,WAAW,KAAa;AAChC,OAAI,CAAC,IAAI,WAAW,SAAS,CAC5B,QAAO;GAGR,MAAM,aAAa,QAAQ,QAAQ,SAAS;GAC5C,MAAM,WAAW,QAAQ,QAAQ,IAAI,QAAQ,UAAU,KAAK,CAAC;GAE7D,MAAM,eAAe,SADG,WAAW,MAAM,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,IAAI,EACrB,SAAS;AACxD,UAAO,aAAa,WAAW,IAAI,GAAG,eAAe,KAAK"}
@@ -1,16 +1,35 @@
1
- const utilsContent = (
2
- /* ts */
3
- `
4
- import { bcs, BcsType, TypeTag, TypeTagSerializer, BcsStruct, BcsEnum, BcsTuple } from '@haneullabs/haneul/bcs';
1
+ //#region src/generate-utils.ts
2
+ const utilsContent = `
3
+ import {
4
+ bcs,
5
+ BcsType,
6
+ TypeTag,
7
+ TypeTagSerializer,
8
+ BcsStruct,
9
+ BcsEnum,
10
+ BcsTuple,
11
+ } from '@haneullabs/haneul/bcs';
5
12
  import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
6
13
  import { TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';
14
+ import { ClientWithCoreApi, HaneulClientTypes } from '@haneullabs/haneul/client';
7
15
 
8
16
  const MOVE_STDLIB_ADDRESS = normalizeHaneulAddress('0x1');
9
17
  const HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress('0x2');
10
- const HANEUL_SYSTEM_ADDRESS = normalizeHaneulAddress('0x3');
11
18
 
12
19
  export type RawTransactionArgument<T> = T | TransactionArgument;
13
20
 
21
+ export interface GetOptions<
22
+ Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},
23
+ > extends HaneulClientTypes.GetObjectOptions<Include> {
24
+ client: ClientWithCoreApi;
25
+ }
26
+
27
+ export interface GetManyOptions<
28
+ Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},
29
+ > extends HaneulClientTypes.GetObjectsOptions<Include> {
30
+ client: ClientWithCoreApi;
31
+ }
32
+
14
33
  export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {
15
34
  const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
16
35
 
@@ -35,7 +54,7 @@ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null
35
54
  return type ? bcs.vector(type) : null;
36
55
  } else if ('struct' in parsedTag) {
37
56
  const structTag = parsedTag.struct;
38
- const pkg = normalizeHaneulAddress(parsedTag.struct.address);
57
+ const pkg = normalizeHaneulAddress(structTag.address);
39
58
 
40
59
  if (pkg === MOVE_STDLIB_ADDRESS) {
41
60
  if (
@@ -46,12 +65,16 @@ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null
46
65
  }
47
66
 
48
67
  if (structTag.module === 'option' && structTag.name === 'Option') {
49
- const type = getPureBcsSchema(structTag.typeParams[0]!);
68
+ const type = getPureBcsSchema(structTag.typeParams[0]);
50
69
  return type ? bcs.option(type) : null;
51
70
  }
52
71
  }
53
72
 
54
- if (pkg === HANEUL_FRAMEWORK_ADDRESS && structTag.module === 'Object' && structTag.name === 'ID') {
73
+ if (
74
+ pkg === HANEUL_FRAMEWORK_ADDRESS &&
75
+ structTag.module === 'object' &&
76
+ (structTag.name === 'ID' || structTag.name === 'UID')
77
+ ) {
55
78
  return bcs.Address;
56
79
  }
57
80
  }
@@ -59,7 +82,11 @@ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null
59
82
  return null;
60
83
  }
61
84
 
62
- export function normalizeMoveArguments(args: unknown[] | object, argTypes: string[], parameterNames?: string[]) {
85
+ export function normalizeMoveArguments(
86
+ args: unknown[] | object,
87
+ argTypes: readonly (string | null)[],
88
+ parameterNames?: string[],
89
+ ) {
63
90
  const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
64
91
  if (parameterNames && argLen !== parameterNames.length) {
65
92
  throw new Error(
@@ -71,30 +98,32 @@ export function normalizeMoveArguments(args: unknown[] | object, argTypes: strin
71
98
 
72
99
  let index = 0;
73
100
  for (const [i, argType] of argTypes.entries()) {
74
- if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::deny_list::DenyList\`) {
75
- normalizedArgs.push((tx) => tx.object.denyList());
101
+ if (argType === '0x2::clock::Clock') {
102
+ normalizedArgs.push((tx) => tx.object.clock());
76
103
  continue;
77
104
  }
78
105
 
79
- if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::random::Random\`) {
106
+ if (argType === '0x2::random::Random') {
80
107
  normalizedArgs.push((tx) => tx.object.random());
81
108
  continue;
82
109
  }
83
110
 
84
- if (argType === \`\${HANEUL_FRAMEWORK_ADDRESS}::clock::Clock\`) {
85
- normalizedArgs.push((tx) => tx.object.clock());
111
+ if (argType === '0x2::deny_list::DenyList') {
112
+ normalizedArgs.push((tx) => tx.object.denyList());
86
113
  continue;
87
114
  }
88
115
 
89
- if (argType === \`\${HANEUL_SYSTEM_ADDRESS}::haneul_system::HaneulSystemState\`) {
116
+ if (argType === '0x3::haneul_system::HaneulSystemState') {
90
117
  normalizedArgs.push((tx) => tx.object.system());
91
118
  continue;
92
119
  }
93
120
 
94
- let arg
121
+ let arg;
95
122
  if (Array.isArray(args)) {
96
123
  if (index >= args.length) {
97
- throw new Error(\`Invalid number of arguments, expected at least \${index + 1}, got \${args.length}\`);
124
+ throw new Error(
125
+ \`Invalid number of arguments, expected at least \${index + 1}, got \${args.length}\`,
126
+ );
98
127
  }
99
128
  arg = args[index];
100
129
  } else {
@@ -116,8 +145,8 @@ export function normalizeMoveArguments(args: unknown[] | object, argTypes: strin
116
145
  continue;
117
146
  }
118
147
 
119
- const type = argTypes[i]!;
120
- const bcsType = getPureBcsSchema(type);
148
+ const type = argTypes[i];
149
+ const bcsType = type === null ? null : getPureBcsSchema(type);
121
150
 
122
151
  if (bcsType) {
123
152
  const bytes = bcsType.serialize(arg as never);
@@ -137,7 +166,47 @@ export function normalizeMoveArguments(args: unknown[] | object, argTypes: strin
137
166
  export class MoveStruct<
138
167
  T extends Record<string, BcsType<any>>,
139
168
  const Name extends string = string,
140
- > extends BcsStruct<T, Name> {}
169
+ > extends BcsStruct<T, Name> {
170
+ async get<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
171
+ objectId,
172
+ ...options
173
+ }: GetOptions<Include>): Promise<
174
+ HaneulClientTypes.Object<Include & { content: true, json: true }> & { json: BcsStruct<T>['$inferType'] }
175
+ > {
176
+ const [res] = await this.getMany<Include>({
177
+ ...options,
178
+ objectIds: [objectId],
179
+ });
180
+
181
+ return res;
182
+ }
183
+
184
+ async getMany<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
185
+ client,
186
+ ...options
187
+ }: GetManyOptions<Include>): Promise<
188
+ Array<HaneulClientTypes.Object<Include & { content: true, json: true }> & { json: BcsStruct<T>['$inferType'] }>
189
+ > {
190
+ const response = (await client.core.getObjects({
191
+ ...options,
192
+ include: {
193
+ ...options.include,
194
+ content: true,
195
+ },
196
+ })) as HaneulClientTypes.GetObjectsResponse<Include & { content: true }>;
197
+
198
+ return response.objects.map((obj) => {
199
+ if (obj instanceof Error) {
200
+ throw obj;
201
+ }
202
+
203
+ return {
204
+ ...obj,
205
+ json: this.parse(obj.content),
206
+ };
207
+ });
208
+ }
209
+ }
141
210
 
142
211
  export class MoveEnum<
143
212
  T extends Record<string, BcsType<any> | null>,
@@ -145,7 +214,7 @@ export class MoveEnum<
145
214
  > extends BcsEnum<T, Name> {}
146
215
 
147
216
  export class MoveTuple<
148
- T extends readonly BcsType<any>[],
217
+ const T extends readonly BcsType<any>[],
149
218
  const Name extends string,
150
219
  > extends BcsTuple<T, Name> {}
151
220
 
@@ -159,9 +228,8 @@ function stringify(val: unknown) {
159
228
 
160
229
  return val;
161
230
  }
162
- `
163
- );
164
- export {
165
- utilsContent
166
- };
167
- //# sourceMappingURL=generate-utils.js.map
231
+ `;
232
+
233
+ //#endregion
234
+ export { utilsContent };
235
+ //# sourceMappingURL=generate-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-utils.mjs","names":[],"sources":["../src/generate-utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport const utilsContent = /* ts */ `\nimport {\n\tbcs,\n\tBcsType,\n\tTypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@haneullabs/haneul/bcs';\nimport { normalizeHaneulAddress } from '@haneullabs/haneul/utils';\nimport { TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';\nimport { ClientWithCoreApi, HaneulClientTypes } from '@haneullabs/haneul/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeHaneulAddress('0x1');\nconst HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport interface GetOptions<\n\tInclude extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},\n> extends HaneulClientTypes.GetObjectOptions<Include> {\n\tclient: ClientWithCoreApi;\n}\n\nexport interface GetManyOptions<\n\tInclude extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {},\n> extends HaneulClientTypes.GetObjectsOptions<Include> {\n\tclient: ClientWithCoreApi;\n}\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(structTag.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 (\n\t\t\tpkg === HANEUL_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\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 === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::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(\n\t\t\t\t\t\\`Invalid number of arguments, expected at least \\${index + 1}, got \\${args.length}\\`,\n\t\t\t\t);\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 = type === null ? null : 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\tasync get<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tHaneulClientTypes.Object<Include & { content: true, json: true }> & { json: BcsStruct<T>['$inferType'] }\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tasync getMany<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<HaneulClientTypes.Object<Include & { content: true, json: true }> & { json: BcsStruct<T>['$inferType'] }>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as HaneulClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\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\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (val: unknown) => val);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n`;\n"],"mappings":";AAGA,MAAa,eAAwB"}
@@ -0,0 +1,21 @@
1
+ import { GenerateBase, HaneulCodegenConfig, ImportExtension, PackageConfig } from "./config.mjs";
2
+
3
+ //#region src/index.d.ts
4
+ declare function generateFromPackageSummary({
5
+ package: pkg,
6
+ prune,
7
+ outputDir,
8
+ globalGenerate,
9
+ importExtension,
10
+ includePhantomTypeParameters
11
+ }: {
12
+ package: PackageConfig;
13
+ prune: boolean;
14
+ outputDir: string;
15
+ globalGenerate?: GenerateBase;
16
+ importExtension?: ImportExtension;
17
+ includePhantomTypeParameters?: boolean;
18
+ }): Promise<void>;
19
+ //#endregion
20
+ export { type HaneulCodegenConfig, generateFromPackageSummary };
21
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;iBAmBsB,0BAAA;WACZ;;;;;;;EADY,OAAA,EAQZ,aARY;EACZ,KAAA,EAAA,OAAA;EACT,SAAA,EAAA,MAAA;EACA,cAAA,CAAA,EAQiB,YARjB;EACA,eAAA,CAAA,EAQkB,eARlB;EACA,4BAAA,CAAA,EAAA,OAAA;CACA,CAAA,EAQA,OARA,CAAA,IAAA,CAAA"}