@typemove/move 1.13.3 → 1.13.4-rc.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 (56) hide show
  1. package/dist/esm/codegen/abstract-codegen.js +1 -1
  2. package/dist/esm/codegen/abstract-codegen.js.map +1 -1
  3. package/dist/esm/types.d.ts.map +1 -1
  4. package/dist/esm/types.js +10 -0
  5. package/dist/esm/types.js.map +1 -1
  6. package/dist/esm/utils.d.ts.map +1 -1
  7. package/dist/esm/utils.js +2 -1
  8. package/dist/esm/utils.js.map +1 -1
  9. package/package.json +4 -13
  10. package/src/codegen/abstract-codegen.ts +1 -1
  11. package/src/types.ts +11 -0
  12. package/src/utils.ts +2 -1
  13. package/codegen/package.json +0 -5
  14. package/dist/cjs/abstract-move-coder.d.ts +0 -30
  15. package/dist/cjs/abstract-move-coder.d.ts.map +0 -1
  16. package/dist/cjs/abstract-move-coder.js +0 -312
  17. package/dist/cjs/abstract-move-coder.js.map +0 -1
  18. package/dist/cjs/account.d.ts +0 -16
  19. package/dist/cjs/account.d.ts.map +0 -1
  20. package/dist/cjs/account.js +0 -76
  21. package/dist/cjs/account.js.map +0 -1
  22. package/dist/cjs/chain-adapter.d.ts +0 -13
  23. package/dist/cjs/chain-adapter.d.ts.map +0 -1
  24. package/dist/cjs/chain-adapter.js +0 -7
  25. package/dist/cjs/chain-adapter.js.map +0 -1
  26. package/dist/cjs/codegen/abstract-codegen.d.ts +0 -52
  27. package/dist/cjs/codegen/abstract-codegen.d.ts.map +0 -1
  28. package/dist/cjs/codegen/abstract-codegen.js +0 -466
  29. package/dist/cjs/codegen/abstract-codegen.js.map +0 -1
  30. package/dist/cjs/codegen/index.d.ts +0 -2
  31. package/dist/cjs/codegen/index.d.ts.map +0 -1
  32. package/dist/cjs/codegen/index.js +0 -5
  33. package/dist/cjs/codegen/index.js.map +0 -1
  34. package/dist/cjs/index.d.ts +0 -7
  35. package/dist/cjs/index.d.ts.map +0 -1
  36. package/dist/cjs/index.js +0 -10
  37. package/dist/cjs/index.js.map +0 -1
  38. package/dist/cjs/internal-models.d.ts +0 -46
  39. package/dist/cjs/internal-models.d.ts.map +0 -1
  40. package/dist/cjs/internal-models.js +0 -10
  41. package/dist/cjs/internal-models.js.map +0 -1
  42. package/dist/cjs/package.json +0 -3
  43. package/dist/cjs/ts-type.test.d.ts +0 -2
  44. package/dist/cjs/ts-type.test.d.ts.map +0 -1
  45. package/dist/cjs/ts-type.test.js.map +0 -1
  46. package/dist/cjs/types.d.ts +0 -52
  47. package/dist/cjs/types.d.ts.map +0 -1
  48. package/dist/cjs/types.js +0 -257
  49. package/dist/cjs/types.js.map +0 -1
  50. package/dist/cjs/utils.d.ts +0 -17
  51. package/dist/cjs/utils.d.ts.map +0 -1
  52. package/dist/cjs/utils.js +0 -139
  53. package/dist/cjs/utils.js.map +0 -1
  54. package/dist/cjs/utils.test.d.ts +0 -2
  55. package/dist/cjs/utils.test.d.ts.map +0 -1
  56. package/dist/cjs/utils.test.js.map +0 -1
@@ -1,16 +0,0 @@
1
- import { InternalMoveModule } from './internal-models.js';
2
- export declare class AccountModulesImportInfo {
3
- imports: Map<string, Set<string>>;
4
- account: string;
5
- moduleName: string;
6
- constructor(account: string, tsModuleName: string);
7
- addImport(account: string, module: string): void;
8
- }
9
- export declare class AccountRegister {
10
- accountImports: Map<string, AccountModulesImportInfo>;
11
- pendingAccounts: Set<string>;
12
- register(module: InternalMoveModule, tsModuleName: string): AccountModulesImportInfo;
13
- private registerFunctions;
14
- private registerStruct;
15
- }
16
- //# sourceMappingURL=account.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,qBAAa,wBAAwB;IAEnC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;gBAEN,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAMjD,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAW1C;AAED,qBAAa,eAAe;IAC1B,cAAc,wCAA8C;IAC5D,eAAe,cAAoB;IAEnC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,wBAAwB;IAkBpF,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,cAAc;CAavB"}
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountRegister = exports.AccountModulesImportInfo = void 0;
4
- const utils_js_1 = require("./utils.js");
5
- class AccountModulesImportInfo {
6
- // account to module
7
- imports;
8
- account;
9
- moduleName;
10
- constructor(account, tsModuleName) {
11
- this.account = account;
12
- this.moduleName = tsModuleName;
13
- this.imports = new Map();
14
- }
15
- addImport(account, module) {
16
- if (account === this.account) {
17
- return;
18
- }
19
- let accountModules = this.imports.get(account);
20
- if (!accountModules) {
21
- accountModules = new Set();
22
- this.imports.set(account, accountModules);
23
- }
24
- accountModules.add(module);
25
- }
26
- }
27
- exports.AccountModulesImportInfo = AccountModulesImportInfo;
28
- class AccountRegister {
29
- accountImports = new Map();
30
- pendingAccounts = new Set();
31
- register(module, tsModuleName) {
32
- const currentModuleFqn = (0, utils_js_1.moduleQname)(module);
33
- let accountModuleImports = this.accountImports.get(module.address);
34
- if (!accountModuleImports) {
35
- accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName);
36
- this.accountImports.set(module.address, accountModuleImports);
37
- // the account has already be processed, delete pending task
38
- this.pendingAccounts.delete(module.address);
39
- }
40
- this.registerStruct(module, accountModuleImports);
41
- this.registerFunctions(module, accountModuleImports);
42
- this.accountImports.set(currentModuleFqn, accountModuleImports);
43
- return accountModuleImports;
44
- }
45
- registerFunctions(module, accountModuleImports) {
46
- for (const func of module.exposedFunctions) {
47
- // if (!func.isEntry) {
48
- // continue
49
- // }
50
- for (const param of func.params.concat(func.return)) {
51
- for (const type of param.dependedTypes()) {
52
- const [account, module] = (0, utils_js_1.moduleQnameForType)(type);
53
- accountModuleImports.addImport(account, module);
54
- if (!this.accountImports.has(account)) {
55
- this.pendingAccounts.add(account);
56
- }
57
- }
58
- }
59
- }
60
- }
61
- registerStruct(module, accountModuleImports) {
62
- for (const struct of module.structs) {
63
- for (const field of struct.fields) {
64
- for (const type of field.type.dependedTypes()) {
65
- const [account, module] = (0, utils_js_1.moduleQnameForType)(type);
66
- accountModuleImports.addImport(account, module);
67
- if (!this.accountImports.has(account)) {
68
- this.pendingAccounts.add(account);
69
- }
70
- }
71
- }
72
- }
73
- }
74
- }
75
- exports.AccountRegister = AccountRegister;
76
- //# sourceMappingURL=account.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/account.ts"],"names":[],"mappings":";;;AAAA,yCAA4D;AAG5D,MAAa,wBAAwB;IACnC,oBAAoB;IACpB,OAAO,CAA0B;IACjC,OAAO,CAAQ;IACf,UAAU,CAAQ;IAElB,YAAY,OAAe,EAAE,YAAoB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,YAAY,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC/C,CAAC;IAED,SAAS,CAAC,OAAe,EAAE,MAAc;QACvC,IAAI,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7B,OAAM;QACR,CAAC;QACD,IAAI,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC9C,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG,IAAI,GAAG,EAAU,CAAA;YAClC,IAAI,CAAC,OAAO,CAAC,GAAG,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AC;gBACpD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,aAAa,EAAE,EAAE,CAAC;oBACzC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAA,6BAAkB,EAAC,IAAI,CAAC,CAAA;oBAClD,oBAAoB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;oBAC/C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;wBACtC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;oBACnC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,MAA0B,EAAE,oBAA8C;QAC/F,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;oBAC9C,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAA,6BAAkB,EAAC,IAAI,CAAC,CAAA;oBAClD,oBAAoB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;oBAC/C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;wBACtC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;oBACnC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AApDD,0CAoDC"}
@@ -1,13 +0,0 @@
1
- import { InternalMoveModule, InternalMoveStruct } from './internal-models.js';
2
- import { TypeDescriptor } from './types.js';
3
- export declare abstract class ChainAdapter<ModuleType, StructType> {
4
- abstract getChainId(): Promise<string>;
5
- abstract fetchModule(account: string, module: string): Promise<ModuleType>;
6
- abstract fetchModules(account: string): Promise<ModuleType[]>;
7
- abstract toInternalModules(modules: ModuleType[]): InternalMoveModule[];
8
- abstract getAllEventStructs(module: InternalMoveModule[]): Map<string, InternalMoveStruct>;
9
- abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
10
- abstract getType(base: StructType): string;
11
- abstract getData<T>(base: StructType): any;
12
- }
13
- //# sourceMappingURL=chain-adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chain-adapter.d.ts","sourceRoot":"","sources":["../../src/chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,8BAAsB,YAAY,CAAC,UAAU,EAAE,UAAU;IAMvD,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAEtC,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAE1E,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAC7D,QAAQ,CAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,kBAAkB,EAAE;IAGvE,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAI1F,QAAQ,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE;IAEhF,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAC1C,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,GAAG;CAC3C"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChainAdapter = void 0;
4
- class ChainAdapter {
5
- }
6
- exports.ChainAdapter = ChainAdapter;
7
- //# sourceMappingURL=chain-adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chain-adapter.js","sourceRoot":"","sources":["../../src/chain-adapter.ts"],"names":[],"mappings":";;;AAGA,MAAsB,YAAY;CAsBjC;AAtBD,oCAsBC"}
@@ -1,52 +0,0 @@
1
- import { InternalMoveEnum, InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from '../internal-models.js';
2
- import { AccountRegister } from '../account.js';
3
- import { TypeDescriptor } from '../types.js';
4
- import { ChainAdapter } from '../chain-adapter.js';
5
- interface OutputFile {
6
- fileName: string;
7
- fileContent: string;
8
- }
9
- interface Config {
10
- fileName: string;
11
- outputDir: string;
12
- }
13
- export declare abstract class AbstractCodegen<ModuleTypes, StructType> {
14
- ADDRESS_TYPE: string;
15
- SYSTEM_PACKAGE: string;
16
- PREFIX: string;
17
- STRUCT_FIELD_NAME: string;
18
- PAYLOAD_OPTIONAL: boolean;
19
- SYSTEM_MODULES: Set<string>;
20
- ESM: boolean;
21
- chainAdapter: ChainAdapter<ModuleTypes, StructType>;
22
- protected constructor(chainAdapter: ChainAdapter<ModuleTypes, StructType>);
23
- maybeEsmPrefix(): "" | ".js";
24
- readModulesFile(fullPath: string): any;
25
- protected defaultCoderPackage(): string;
26
- generateLoadAll(isSystem: boolean): string;
27
- generate(srcDir: string, outputDir: string, builtin?: boolean): Promise<number>;
28
- protected generateExtra(address: string | undefined, module: InternalMoveModule): string;
29
- generateModule(module: InternalMoveModule, allEventStructs: Map<string, InternalMoveStruct>, addressOverride?: string): string;
30
- generateEnum(module: InternalMoveModule, enumType: InternalMoveEnum): string;
31
- generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>, typeOnly?: boolean): string;
32
- generateFunctionTypeParameters(func: InternalMoveFunction): string;
33
- generateFunctionReturnTypeParameters(func: InternalMoveFunction, currentAddress: string): string;
34
- generateStructTypeParameters(struct: InternalMoveStruct | InternalMoveEnum, useAny?: boolean): string;
35
- generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction): string;
36
- generateForEvents(module: InternalMoveModule, struct: InternalMoveStruct): string;
37
- generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string;
38
- generateSimpleType(type: string, currentAddress: string): string;
39
- generateImports(): string;
40
- }
41
- export declare class AccountCodegen<ModuleType, StructType> {
42
- modules: InternalMoveModule[];
43
- config: Config;
44
- abi: ModuleType[];
45
- loader: AccountRegister;
46
- moduleGen: AbstractCodegen<ModuleType, StructType>;
47
- address?: string;
48
- constructor(moduleGen: AbstractCodegen<ModuleType, StructType>, loader: AccountRegister, abi: ModuleType[], modules: InternalMoveModule[], config: Config, address: string | undefined);
49
- generate(): OutputFile[];
50
- }
51
- export {};
52
- //# sourceMappingURL=abstract-codegen.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract-codegen.d.ts","sourceRoot":"","sources":["../../../src/codegen/abstract-codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGtH,OAAO,EAA4B,eAAe,EAAE,MAAM,eAAe,CAAA;AAGzE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,UAAU,UAAU;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,UAAU,MAAM;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAElB;AAGD,8BAAsB,eAAe,CAAC,WAAW,EAAE,UAAU;IAC3D,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,MAAM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AAG,MAAM;IAgE/E,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM;IAgBhE,eAAe;CAgBhB;AAED,qBAAa,cAAc,CAAC,UAAU,EAAE,UAAU;IAChD,OAAO,EAAE,kBAAkB,EAAE,CAAA;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,UAAU,EAAE,CAAA;IACjB,MAAM,EAAE,eAAe,CAAA;IACvB,SAAS,EAAE,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IAElD,OAAO,CAAC,EAAE,MAAM,CAAA;gBAGd,SAAS,EAAE,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,EAClD,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,UAAU,EAAE,EACjB,OAAO,EAAE,kBAAkB,EAAE,EAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS;IAW7B,QAAQ,IAAI,UAAU,EAAE;CAwEzB"}
@@ -1,466 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountCodegen = exports.AbstractCodegen = void 0;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const fs_1 = tslib_1.__importDefault(require("fs"));
7
- const account_js_1 = require("../account.js");
8
- const prettier_1 = require("prettier");
9
- const utils_js_1 = require("../utils.js");
10
- // TODO be able to generate cjs
11
- class AbstractCodegen {
12
- ADDRESS_TYPE;
13
- SYSTEM_PACKAGE;
14
- PREFIX;
15
- STRUCT_FIELD_NAME = 'data';
16
- PAYLOAD_OPTIONAL = false;
17
- SYSTEM_MODULES = new Set(['0x1', '0x2', '0x3', '0x4']);
18
- ESM = true;
19
- chainAdapter;
20
- constructor(chainAdapter) {
21
- this.chainAdapter = chainAdapter;
22
- }
23
- maybeEsmPrefix() {
24
- return this.ESM ? '.js' : '';
25
- }
26
- readModulesFile(fullPath) {
27
- return JSON.parse(fs_1.default.readFileSync(fullPath, 'utf-8'));
28
- }
29
- defaultCoderPackage() {
30
- return this.SYSTEM_PACKAGE;
31
- }
32
- generateLoadAll(isSystem) {
33
- return 'loadAllTypes(defaultMoveCoder())';
34
- }
35
- async generate(srcDir, outputDir,
36
- // network: NetworkType,
37
- builtin = false) {
38
- if (!fs_1.default.existsSync(srcDir)) {
39
- return 0;
40
- }
41
- const files = fs_1.default.readdirSync(srcDir);
42
- outputDir = path_1.default.resolve(outputDir);
43
- const outputs = [];
44
- fs_1.default.mkdirSync(outputDir, { recursive: true });
45
- const loader = new account_js_1.AccountRegister();
46
- // when generating user code, don't need to generate framework account
47
- for (const sysModule of this.SYSTEM_MODULES) {
48
- loader.accountImports.set(sysModule, new account_js_1.AccountModulesImportInfo(sysModule, sysModule));
49
- }
50
- // const client = getRpcClient(network)
51
- for (const file of files) {
52
- if (!file.endsWith('.json')) {
53
- continue;
54
- }
55
- const fullPath = path_1.default.resolve(srcDir, file);
56
- const abi = this.readModulesFile(fullPath);
57
- const modules = this.chainAdapter.toInternalModules(abi);
58
- for (const module of modules) {
59
- loader.register(module, path_1.default.basename(file, '.json'));
60
- }
61
- const fileName = path_1.default.basename(file, '.json');
62
- // TODO more reliable way to check if this is sui address
63
- const address = fileName.startsWith('0x') ? fileName : undefined;
64
- const codeGen = new AccountCodegen(this, loader, abi, modules, {
65
- fileName,
66
- outputDir: outputDir
67
- // network,
68
- }, address);
69
- outputs.push(...codeGen.generate());
70
- }
71
- while (loader.pendingAccounts.size > 0) {
72
- for (const account of loader.pendingAccounts) {
73
- const id = await this.chainAdapter.getChainId();
74
- console.log(`download dependent module for account ${account}, chain ID: ${id}`);
75
- try {
76
- const rawModules = await this.chainAdapter.fetchModules(account
77
- // network
78
- );
79
- const modules = this.chainAdapter.toInternalModules(rawModules);
80
- fs_1.default.writeFileSync(path_1.default.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\t'));
81
- for (const module of modules) {
82
- loader.register(module, account);
83
- }
84
- const codeGen = new AccountCodegen(this, loader, rawModules, modules, {
85
- fileName: account,
86
- outputDir: outputDir
87
- // network,
88
- }, account);
89
- outputs.push(...codeGen.generate());
90
- }
91
- catch (e) {
92
- console.error('Error downloading account module, check if you choose the right network,or download account modules manually into your director');
93
- console.error(e);
94
- process.exit(1);
95
- }
96
- }
97
- }
98
- for (const output of outputs) {
99
- let content = output.fileContent;
100
- content = await (0, prettier_1.format)(output.fileContent, { parser: 'typescript' });
101
- fs_1.default.writeFileSync(path_1.default.join(outputDir, output.fileName), content);
102
- }
103
- const rootFile = path_1.default.join(outputDir, 'index.ts');
104
- let rootFileContent = `/* Autogenerated file. Do not edit manually. */
105
- /* tslint:disable */
106
- /* eslint-disable */
107
- `;
108
- for (const output of outputs) {
109
- const parsed = path_1.default.parse(output.fileName);
110
- rootFileContent += `export * as _${parsed.name.replaceAll('-', '_')} from './${parsed.name}${this.maybeEsmPrefix()}'\n`;
111
- }
112
- fs_1.default.writeFileSync(rootFile, rootFileContent);
113
- return outputs.length;
114
- }
115
- generateExtra(address, module) {
116
- return '';
117
- }
118
- generateModule(module, allEventStructs, addressOverride
119
- // network: NetworkType
120
- ) {
121
- const qname = (0, utils_js_1.moduleQname)(module);
122
- const eventStructs = new Map();
123
- for (const [type, struct] of allEventStructs.entries()) {
124
- if (type.startsWith(qname + utils_js_1.SPLITTER)) {
125
- eventStructs.set(type, struct);
126
- }
127
- }
128
- const eventTypes = new Set(eventStructs.keys());
129
- const events = Array.from(eventStructs.values())
130
- .map((e) => this.generateForEvents(module, e))
131
- .filter((s) => s !== '');
132
- const enums = module.enums.map((e) => this.generateEnum(module, e));
133
- const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes));
134
- const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f));
135
- const moduleName = (0, utils_js_1.normalizeToJSName)(module.name);
136
- return `
137
-
138
- export namespace ${moduleName} {
139
- ${enums.join('\n')}
140
-
141
- ${structs.join('\n')}
142
-
143
- ${this.generateExtra(addressOverride, module)}
144
-
145
- ${events.join('\n')}
146
-
147
- ${callArgs.join('\n')}
148
- }
149
- `;
150
- }
151
- generateEnum(module, enumType) {
152
- const enumName = (0, utils_js_1.normalizeToJSName)(enumType.name);
153
- const enumValues = Object.keys(enumType.variants)
154
- .map((v) => `'${v}'`)
155
- .join(' | ');
156
- const typeParams = enumType.typeParams || [];
157
- const genericString = this.generateStructTypeParameters(enumType);
158
- const genericStringAny = this.generateStructTypeParameters(enumType, true);
159
- const typeParamApplyArg = typeParams
160
- .map((v, idx) => {
161
- return `arg${idx}: TypeDescriptor<T${idx}> = ANY_TYPE`;
162
- })
163
- .join(',');
164
- const typeParamApply = typeParams
165
- .map((v, idx) => {
166
- return `arg${idx}`;
167
- })
168
- .join(',');
169
- const typeDescriptor = `
170
- export namespace ${enumName}{
171
- export const TYPE_QNAME = '${module.address}::${module.name}::${enumType.name}'
172
-
173
- const TYPE = new TypeDescriptor<${enumName}${genericStringAny}>(${enumName}.TYPE_QNAME)
174
-
175
- export function type${genericString}(${typeParamApplyArg}): TypeDescriptor<${enumName}${genericString}> {
176
- return TYPE.apply(${typeParamApply})
177
- }
178
- }
179
- `;
180
- // TODO support fields
181
- return `
182
- export interface ${enumName} {
183
- fields: {}
184
- variant: ${enumValues}
185
- }
186
-
187
- ${typeDescriptor}
188
- `;
189
- }
190
- generateStructs(module, struct, events, typeOnly = false) {
191
- const typeParams = struct.typeParams || [];
192
- const genericString = this.generateStructTypeParameters(struct);
193
- const genericStringAny = this.generateStructTypeParameters(struct, true);
194
- const structName = (0, utils_js_1.normalizeToJSName)(struct.name);
195
- const fields = struct.fields.map((field) => {
196
- const type = this.generateTypeForDescriptor(field.type, module.address);
197
- return `${field.name}: ${type}`;
198
- });
199
- const typeParamApplyArg = typeParams
200
- .map((v, idx) => {
201
- return `arg${idx}: TypeDescriptor<T${idx}> = ANY_TYPE`;
202
- })
203
- .join(',');
204
- const typeParamApply = typeParams
205
- .map((v, idx) => {
206
- return `arg${idx}`;
207
- })
208
- .join(',');
209
- const typeDescriptor = `
210
- export namespace ${structName}{
211
- export const TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'
212
-
213
- const TYPE = new TypeDescriptor<${structName}${genericStringAny}>(${structName}.TYPE_QNAME)
214
-
215
- export function type${genericString}(${typeParamApplyArg}): TypeDescriptor<${structName}${genericString}> {
216
- return TYPE.apply(${typeParamApply})
217
- }
218
- }
219
- `;
220
- if (typeOnly) {
221
- return typeDescriptor;
222
- }
223
- let eventPayload = '';
224
- if (events.has((0, utils_js_1.moduleQname)(module) + utils_js_1.SPLITTER + struct.name)) {
225
- eventPayload = `
226
- export type ${structName}Instance = TypedEventInstance<${structName}${genericStringAny}> & {
227
- ${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}
228
- type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]
229
- }
230
- `;
231
- }
232
- return `
233
- export interface ${structName}${genericString} {
234
- ${fields.join('\n')}
235
- }
236
-
237
- ${typeDescriptor}
238
-
239
- ${eventPayload}
240
- `;
241
- }
242
- generateFunctionTypeParameters(func) {
243
- let genericString = '';
244
- if (func.typeParams && func.typeParams.length > 0) {
245
- const params = func.typeParams
246
- .map((v, idx) => {
247
- return `T${idx}=any`;
248
- })
249
- .join(',');
250
- genericString = `<${params}>`;
251
- }
252
- return genericString;
253
- }
254
- generateFunctionReturnTypeParameters(func, currentAddress) {
255
- let returnType = '';
256
- if (func.return && func.return.length > 0) {
257
- returnType = func.return
258
- .map((v, idx) => {
259
- return this.generateTypeForDescriptor(v, currentAddress);
260
- })
261
- .join(',');
262
- }
263
- return '[' + returnType + ']';
264
- }
265
- generateStructTypeParameters(struct, useAny = false) {
266
- let genericString = '';
267
- if (struct.typeParams && struct.typeParams.length > 0) {
268
- const params = struct.typeParams
269
- .map((v, idx) => {
270
- return useAny ? 'any' : 'T' + idx;
271
- })
272
- .join(',');
273
- genericString = `<${params}>`;
274
- }
275
- return genericString;
276
- }
277
- // generateTypeParameters(struct: TypeDescriptor, useAny = false) {
278
- // let genericString = ''
279
- //
280
- // if (struct.typeArgs && struct.typeArgs.length > 0) {
281
- // const params = struct.typeArgs
282
- // .map((_, idx) => {
283
- // return useAny ? 'any' : 'T' + idx
284
- // })
285
- // .join(',')
286
- // genericString = `<${params}>`
287
- // }
288
- // return genericString
289
- // }
290
- generateCallArgsStructs(module, func) {
291
- return '';
292
- }
293
- generateForEvents(module, struct) {
294
- return '';
295
- }
296
- generateTypeForDescriptor(type, currentAddress) {
297
- if (type.reference) {
298
- return this.ADDRESS_TYPE;
299
- }
300
- switch (type.qname) {
301
- case 'signer': // TODO check this
302
- case 'address':
303
- case 'Address':
304
- return this.ADDRESS_TYPE;
305
- case '0x1::string::String':
306
- return 'string';
307
- case 'bool':
308
- case 'Bool':
309
- return 'boolean';
310
- case 'u8':
311
- case 'U8':
312
- case 'u16':
313
- case 'U16':
314
- case 'u32':
315
- case 'U32':
316
- return 'number';
317
- case 'u64':
318
- case 'U64':
319
- case 'u128':
320
- case 'U128':
321
- case 'u256':
322
- case 'U256':
323
- return 'bigint';
324
- }
325
- if (type.qname.toLowerCase() === utils_js_1.VECTOR_STR) {
326
- // vector<u8> as hex string
327
- const elementTypeQname = type.typeArgs[0].qname;
328
- if (elementTypeQname === 'u8') {
329
- // only for aptos
330
- return 'string';
331
- }
332
- // if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {
333
- // return `${elementTypeQname} extends string ? string : ${elementTypeQname}[]`
334
- // }
335
- // TODO there might be an error here, find the case and get it fixed
336
- if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(utils_js_1.SPLITTER)) {
337
- return `${elementTypeQname}[]`;
338
- }
339
- return this.generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]';
340
- }
341
- const simpleName = this.generateSimpleType(type.qname, currentAddress);
342
- if (simpleName.length === 0) {
343
- console.error('unexpected error');
344
- }
345
- if (simpleName.toLowerCase() === utils_js_1.VECTOR_STR || simpleName.toLowerCase().startsWith(utils_js_1.VECTOR_STR + utils_js_1.SPLITTER)) {
346
- console.error('unexpected vector type error');
347
- }
348
- if (type.typeArgs.length > 0) {
349
- // return simpleName
350
- return (simpleName + '<' + type.typeArgs.map((t) => this.generateTypeForDescriptor(t, currentAddress)).join(',') + '>');
351
- }
352
- return simpleName;
353
- }
354
- generateSimpleType(type, currentAddress) {
355
- const parts = type.split(utils_js_1.SPLITTER);
356
- for (let i = 0; i < parts.length; i++) {
357
- parts[i] = (0, utils_js_1.normalizeToJSName)(parts[i]);
358
- }
359
- if (parts.length < 2) {
360
- return parts[0];
361
- }
362
- if (parts[0] === currentAddress) {
363
- return parts.slice(1).join('.');
364
- }
365
- return '_' + parts.join('.');
366
- }
367
- generateImports() {
368
- // let refImports = `import { ${this.ADDRESS_TYPE} } from "${this.SYSTEM_PACKAGE}"`
369
- // if (this.ADDRESS_TYPE === 'string') {
370
- // refImports = ''
371
- // }
372
- const imports = `
373
- import { TypeDescriptor, ANY_TYPE } from "@typemove/move"
374
- import {
375
- MoveCoder, TypedEventInstance } from "@typemove/${this.PREFIX.toLowerCase()}"
376
-
377
- import { defaultMoveCoder } from "${this.defaultCoderPackage()}"
378
-
379
- `;
380
- return imports;
381
- }
382
- }
383
- exports.AbstractCodegen = AbstractCodegen;
384
- class AccountCodegen {
385
- modules;
386
- config;
387
- abi;
388
- loader;
389
- moduleGen;
390
- // Usually it's same as module.address, but in upgraded package, this might be the new address
391
- address;
392
- constructor(moduleGen, loader, abi, modules, config, address) {
393
- // const json = fs.readFileSync(config.srcFile, 'utf-8')
394
- this.moduleGen = moduleGen;
395
- this.abi = abi;
396
- this.modules = modules;
397
- this.config = config;
398
- this.loader = loader;
399
- this.address = address;
400
- }
401
- generate() {
402
- if (!this.modules) {
403
- return [];
404
- }
405
- // const baseName = path.basename(this.config.fileName, '.json')
406
- let address;
407
- for (const module of this.modules) {
408
- address = module.address;
409
- }
410
- if (!address) {
411
- return [];
412
- }
413
- const dependedAccounts = [];
414
- const moduleImports = [];
415
- const info = this.loader.accountImports.get(address);
416
- if (info) {
417
- for (const [account] of info.imports.entries()) {
418
- // Remap to user's filename if possible, TODO codepath not well tested
419
- const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account);
420
- if ((0, utils_js_1.isFrameworkAccount)(account) && !(0, utils_js_1.isFrameworkAccount)(address)) {
421
- // Decide where to find builtin library
422
- moduleImports.push(`import * as _${account} from "${this.moduleGen.SYSTEM_PACKAGE}/builtin/${account}"`
423
- // `import _${account} = builtin._${account} `
424
- );
425
- }
426
- else {
427
- moduleImports.push(`import * as _${account} from "${tsAccountModule}${this.moduleGen.maybeEsmPrefix()}"`);
428
- }
429
- dependedAccounts.push(account);
430
- }
431
- }
432
- const eventsMap = this.moduleGen.chainAdapter.getAllEventStructs(this.modules);
433
- const source = `
434
- /* Autogenerated file. Do not edit manually. */
435
- /* tslint:disable */
436
- /* eslint-disable */
437
-
438
- /* Generated types for ${this.address || address}, original address ${address} */
439
-
440
- ${this.moduleGen.generateImports()}
441
-
442
- ${moduleImports.join('\n')}
443
-
444
- ${this.modules.map((m) => this.moduleGen.generateModule(m, eventsMap, this.address)).join('\n')}
445
-
446
- const MODULES = JSON.parse('${JSON.stringify(this.abi)}')
447
-
448
- export function loadAllTypes(coder: MoveCoder) {
449
- ${dependedAccounts.map((a) => `_${a}.loadAllTypes(coder)`).join('\n')}
450
- for (const m of Object.values(MODULES)) {
451
- coder.load(m as any, '${address}')
452
- }
453
- }
454
-
455
- ${this.moduleGen.generateLoadAll(this.moduleGen.SYSTEM_MODULES.has(address))}
456
- `; // source
457
- return [
458
- {
459
- fileName: this.config.fileName + '.ts',
460
- fileContent: source
461
- }
462
- ];
463
- }
464
- }
465
- exports.AccountCodegen = AccountCodegen;
466
- //# sourceMappingURL=abstract-codegen.js.map