@typemove/aptos 1.0.0-rc.27 → 1.0.0-rc.28

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.
@@ -0,0 +1,14 @@
1
+ import { Event, MoveModuleBytecode, MoveResource } from '../move-types.js';
2
+ import { AbstractCodegen, InternalMoveFunction, InternalMoveModule } from '@typemove/move';
3
+ export declare function codegen(abisDir: string, outDir: string | undefined, endpoint: string, genExample?: boolean, builtin?: boolean): Promise<void>;
4
+ export declare class AptosCodegen extends AbstractCodegen<MoveModuleBytecode, Event | MoveResource> {
5
+ ADDRESS_TYPE: string;
6
+ PREFIX: string;
7
+ SYSTEM_PACKAGE: string;
8
+ constructor(endpoint: string);
9
+ generateImports(): string;
10
+ protected generateExtra(module: InternalMoveModule): string;
11
+ protected generateViewFunction(module: InternalMoveModule, func: InternalMoveFunction): string;
12
+ protected generateEntryForFunction(module: InternalMoveModule, func: InternalMoveFunction): string;
13
+ }
14
+ //# sourceMappingURL=codegen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../../src/codegen/codegen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAI1E,OAAO,EAAE,eAAe,EAAS,oBAAoB,EAAE,kBAAkB,EAAqB,MAAM,gBAAgB,CAAA;AAEpH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,MAAM,oBAAgC,EACtC,QAAQ,EAAE,MAAM,EAChB,UAAU,UAAQ,EAClB,OAAO,UAAQ,iBAQhB;AAED,qBAAa,YAAa,SAAQ,eAAe,CAAC,kBAAkB,EAAE,KAAK,GAAG,YAAY,CAAC;IACzF,YAAY,SAAY;IACxB,MAAM,SAAU;IAChB,cAAc,SAAoB;gBAEtB,QAAQ,EAAE,MAAM;IAI5B,eAAe,IAAI,MAAM;IAMzB,SAAS,CAAC,aAAa,CAAC,MAAM,EAAE,kBAAkB;IAelD,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,oBAAoB,GAAG,MAAM;IA2C9F,SAAS,CAAC,wBAAwB,CAAC,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,oBAAoB,GAAG,MAAM;CAmCnG"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AptosCodegen = exports.codegen = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const path_1 = require("path");
8
+ const aptos_chain_adapter_js_1 = require("../aptos-chain-adapter.js");
9
+ const move_1 = require("@typemove/move");
10
+ async function codegen(abisDir, outDir = (0, path_1.join)('src', 'types', 'aptos'), endpoint, genExample = false, builtin = false) {
11
+ if (!fs.existsSync(abisDir)) {
12
+ return;
13
+ }
14
+ const gen = new AptosCodegen(endpoint);
15
+ const numFiles = await gen.generate(abisDir, outDir, builtin);
16
+ console.log(chalk_1.default.green(`Generated ${numFiles} for Aptos`));
17
+ }
18
+ exports.codegen = codegen;
19
+ class AptosCodegen extends move_1.AbstractCodegen {
20
+ ADDRESS_TYPE = 'Address';
21
+ PREFIX = 'Aptos';
22
+ SYSTEM_PACKAGE = '@typemove/aptos';
23
+ constructor(endpoint) {
24
+ super(new aptos_chain_adapter_js_1.AptosChainAdapter(endpoint));
25
+ }
26
+ generateImports() {
27
+ return `
28
+ ${super.generateImports()}
29
+ import { AptosClient, AptosAccount, TransactionBuilderRemoteABI, Types, TxnBuilderTypes, OptionalTransactionArgs } from 'aptos'
30
+ `;
31
+ }
32
+ generateExtra(module) {
33
+ const funcs = module.exposedFunctions.map((f) => this.generateEntryForFunction(module, f));
34
+ const viewFuncs = module.exposedFunctions.map((f) => this.generateViewFunction(module, f));
35
+ return `
36
+ export namespace entry {
37
+ ${funcs.join('\n')}
38
+ }
39
+ export namespace view {
40
+ ${viewFuncs.join('\n')}
41
+ }
42
+ `;
43
+ }
44
+ generateViewFunction(module, func) {
45
+ if (!func.isView) {
46
+ return '';
47
+ }
48
+ const genericString = this.generateFunctionTypeParameters(func);
49
+ const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
50
+ return this.generateTypeForDescriptor(param, module.address);
51
+ });
52
+ const returns = func.return.map((param) => {
53
+ return this.generateTypeForDescriptor(param, module.address);
54
+ });
55
+ const typeParamArg = func.typeParams
56
+ .map((v, idx) => {
57
+ return `TypeDescriptor<T${idx}> | string`;
58
+ })
59
+ .join(',');
60
+ // const args = this.generateArgs(module, func)
61
+ const allEmpty = func.typeParams.length === 0 && func.params.length === 0;
62
+ const requestArg = allEmpty
63
+ ? ''
64
+ : `request: {
65
+ ${func.typeParams.length > 0 ? `type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}],` : ''}
66
+ ${func.params.length > 0 ? `arguments: [${fields.join(',')}]` : ''}},`;
67
+ return `export async function ${(0, move_1.camel)((0, move_1.normalizeToJSName)(func.name))}${genericString}(
68
+ client: AptosClient,
69
+ ${requestArg}
70
+ version?: bigint): Promise<[${returns.join(',')}]> {
71
+ const coder = defaultMoveCoder(client.nodeUrl)
72
+ const data = {
73
+ type_arguments: ${func.typeParams.length > 0 ? 'request.type_arguments' : '[]'},
74
+ arguments: ${func.params.length > 0 ? 'coder.encodeArray(request.arguments)' : '[]'},
75
+ function: "${module.address}::${module.name}::${func.name}"
76
+ }
77
+ const res = await client.view(data, version?.toString())
78
+ const type = await coder.getMoveFunction("${module.address}::${module.name}::${func.name}")
79
+ return await coder.decodeArray(res, type.return) as any
80
+ }`;
81
+ }
82
+ generateEntryForFunction(module, func) {
83
+ if (!func.isEntry) {
84
+ return '';
85
+ }
86
+ const genericString = this.generateFunctionTypeParameters(func);
87
+ const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
88
+ return this.generateTypeForDescriptor(param, module.address);
89
+ });
90
+ // const typeParamArg = func.typeParams
91
+ // .map((v, idx) => {
92
+ // return `TypeDescriptor<T${idx}> | string`
93
+ // })
94
+ // .join(',')
95
+ //
96
+ // const args = this.generateArgs(module, func)
97
+ return `export async function ${(0, move_1.camel)((0, move_1.normalizeToJSName)(func.name))}${genericString}(
98
+ client: AptosClient,
99
+ account: AptosAccount,
100
+ request: {
101
+ type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}],
102
+ arguments: [${fields.join(',')}]
103
+ },
104
+ extraArgs?: OptionalTransactionArgs
105
+ ): Promise<Types.PendingTransaction> {
106
+ const coder = defaultMoveCoder(client.nodeUrl)
107
+ const builder = new TransactionBuilderRemoteABI(client, { sender: account.address(), ...extraArgs });
108
+ const txn = await builder.build("${module.address}::${module.name}::${func.name}", request.type_arguments, coder.encodeArray(request.arguments))
109
+ const bcsTxn = AptosClient.generateBCSTransaction(account, txn)
110
+ return await client.submitSignedBCSTransaction(bcsTxn)
111
+ }`;
112
+ }
113
+ }
114
+ exports.AptosCodegen = AptosCodegen;
115
+ //# sourceMappingURL=codegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/codegen/codegen.ts"],"names":[],"mappings":";;;;AAAA,+CAAwB;AAExB,0DAAyB;AACzB,+BAA2B;AAC3B,sEAA6D;AAC7D,yCAAoH;AAE7G,KAAK,UAAU,OAAO,CAC3B,OAAe,EACf,MAAM,GAAG,IAAA,WAAI,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EACtC,QAAgB,EAChB,UAAU,GAAG,KAAK,EAClB,OAAO,GAAG,KAAK;IAEf,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAM;KACP;IACD,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAA;IACtC,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,OAAO,EA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CACF;AA5GD,oCA4GC"}
@@ -0,0 +1,2 @@
1
+ export * from './codegen.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./codegen.js"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.test.d.ts","sourceRoot":"","sources":["../../../src/codegen/types.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.test.js","sourceRoot":"","sources":["../../../src/codegen/types.test.ts"],"names":[],"mappings":";;AAAA,0CAA8C;AAC9C,+CAAgD;AAEhD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAA,sBAAY,EAAC,IAAA,2BAAgB,GAAE,CAAC,CAAA;IAChC,IAAI,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;QACzC,MAAM,OAAO,GAAG,IAAA,2BAAgB,GAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;QAC9D,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,MAAM,IAAI,GAAG;IACX,IAAI,EAAE,wBAAwB;IAC9B,cAAc,EAAE,EAAE;IAClB,SAAS,EAAE;QACT,oEAAoE;KACrE;IACD,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtB,QAAQ,EAAE,oCAAoC;CAC/C,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typemove/aptos",
3
- "version": "1.0.0-rc.27",
3
+ "version": "1.0.0-rc.28",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -12,9 +12,8 @@
12
12
  "import": "./dist/esm/builtin/index.js",
13
13
  "require": "./dist/cjs/builtin/index.js"
14
14
  },
15
- "./codgen": {
16
- "import": "./dist/esm/codgen/index.js",
17
- "require": "./dist/cjs/codgen/index.js"
15
+ "./codegen": {
16
+ "import": "./dist/esm/codegen/index.js"
18
17
  }
19
18
  },
20
19
  "main": "./dist/cjs/index.js",
@@ -33,7 +32,7 @@
33
32
  "aptos": "^1.16.0",
34
33
  "chalk": "^5.2.0",
35
34
  "radash": "^11.0.0",
36
- "@typemove/move": "1.0.0-rc.27"
35
+ "@typemove/move": "1.0.0-rc.28"
37
36
  },
38
37
  "url": "https://github.com/sentioxyz/typemove",
39
38
  "scripts": {