@algorandfoundation/algokit-client-generator 2.6.0-beta.1 → 2.6.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.mjs +4 -0
- package/cli.cjs +75 -0
- package/cli.d.ts +0 -1
- package/cli.mjs +54 -0
- package/client/app-types.cjs +152 -0
- package/client/app-types.d.ts +0 -1
- package/client/app-types.mjs +131 -0
- package/client/call-client.cjs +332 -0
- package/client/call-client.d.ts +0 -1
- package/client/{call-client.js → call-client.mjs} +107 -135
- package/client/call-composer-types.cjs +141 -0
- package/client/call-composer-types.d.ts +0 -1
- package/client/{call-composer-types.js → call-composer-types.mjs} +33 -58
- package/client/call-composer.cjs +145 -0
- package/client/call-composer.d.ts +0 -1
- package/client/call-composer.mjs +124 -0
- package/client/call-factory.cjs +138 -0
- package/client/call-factory.d.ts +0 -1
- package/client/{call-factory.js → call-factory.mjs} +31 -56
- package/client/deploy-types.cjs +94 -0
- package/client/deploy-types.d.ts +0 -1
- package/client/deploy-types.mjs +91 -0
- package/client/generate.cjs +37 -0
- package/client/generate.d.ts +0 -1
- package/client/generate.mjs +35 -0
- package/client/generator-context.cjs +37 -0
- package/client/generator-context.d.ts +0 -1
- package/client/generator-context.mjs +16 -0
- package/client/helpers/{get-call-config-summary.js → get-call-config-summary.cjs} +7 -25
- package/client/helpers/get-call-config-summary.d.ts +1 -2
- package/client/helpers/get-call-config-summary.mjs +54 -0
- package/client/helpers/{get-equivalent-type.js → get-equivalent-type.cjs} +20 -20
- package/client/helpers/get-equivalent-type.d.ts +0 -1
- package/client/helpers/get-equivalent-type.mjs +56 -0
- package/client/{imports.js → imports.cjs} +3 -4
- package/client/imports.d.ts +0 -1
- package/client/imports.mjs +27 -0
- package/client/{utility-types.js → utility-types.cjs} +26 -25
- package/client/utility-types.d.ts +0 -1
- package/client/utility-types.mjs +47 -0
- package/dev.d.ts +0 -1
- package/index.cjs +13 -0
- package/index.d.ts +0 -1
- package/index.mjs +3 -0
- package/output/{writer.js → writer.cjs} +44 -38
- package/output/writer.d.ts +0 -1
- package/output/writer.mjs +139 -0
- package/package.json +7 -4
- package/schema/application.schema.json.cjs +374 -0
- package/schema/application.schema.json.mjs +363 -0
- package/schema/contract.schema.json.cjs +159 -0
- package/schema/contract.schema.json.mjs +148 -0
- package/schema/load.cjs +25 -0
- package/schema/load.d.ts +0 -1
- package/schema/load.mjs +22 -0
- package/tests/approval-tests.spec.d.ts +0 -1
- package/tests/util.d.ts +1 -0
- package/util/boom.cjs +7 -0
- package/util/boom.d.ts +0 -1
- package/util/boom.mjs +5 -0
- package/util/color-console.cjs +18 -0
- package/util/color-console.d.ts +0 -1
- package/util/color-console.mjs +16 -0
- package/util/not-falsy.d.ts +0 -1
- package/util/sanitization.cjs +17 -0
- package/util/sanitization.d.ts +0 -1
- package/util/sanitization.mjs +11 -0
- package/bin/cli.js +0 -4
- package/cli.d.ts.map +0 -1
- package/cli.js +0 -79
- package/cli.js.map +0 -1
- package/client/app-types.d.ts.map +0 -1
- package/client/app-types.js +0 -161
- package/client/app-types.js.map +0 -1
- package/client/call-client.d.ts.map +0 -1
- package/client/call-client.js.map +0 -1
- package/client/call-composer-types.d.ts.map +0 -1
- package/client/call-composer-types.js.map +0 -1
- package/client/call-composer.d.ts.map +0 -1
- package/client/call-composer.js +0 -151
- package/client/call-composer.js.map +0 -1
- package/client/call-factory.d.ts.map +0 -1
- package/client/call-factory.js.map +0 -1
- package/client/deploy-types.d.ts.map +0 -1
- package/client/deploy-types.js +0 -95
- package/client/deploy-types.js.map +0 -1
- package/client/generate.d.ts.map +0 -1
- package/client/generate.js +0 -37
- package/client/generate.js.map +0 -1
- package/client/generator-context.d.ts.map +0 -1
- package/client/generator-context.js +0 -41
- package/client/generator-context.js.map +0 -1
- package/client/helpers/get-call-config-summary.d.ts.map +0 -1
- package/client/helpers/get-call-config-summary.js.map +0 -1
- package/client/helpers/get-equivalent-type.d.ts.map +0 -1
- package/client/helpers/get-equivalent-type.js.map +0 -1
- package/client/imports.d.ts.map +0 -1
- package/client/imports.js.map +0 -1
- package/client/utility-types.d.ts.map +0 -1
- package/client/utility-types.js.map +0 -1
- package/dev.d.ts.map +0 -1
- package/dev.js +0 -5
- package/dev.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js +0 -12
- package/index.js.map +0 -1
- package/output/writer.d.ts.map +0 -1
- package/output/writer.js.map +0 -1
- package/schema/application.schema.json +0 -354
- package/schema/contract.schema.json +0 -139
- package/schema/load.d.ts.map +0 -1
- package/schema/load.js +0 -51
- package/schema/load.js.map +0 -1
- package/tests/approval-tests.spec.d.ts.map +0 -1
- package/tests/approval-tests.spec.js +0 -24
- package/tests/approval-tests.spec.js.map +0 -1
- package/util/boom.d.ts.map +0 -1
- package/util/boom.js +0 -8
- package/util/boom.js.map +0 -1
- package/util/color-console.d.ts.map +0 -1
- package/util/color-console.js +0 -20
- package/util/color-console.js.map +0 -1
- package/util/not-falsy.d.ts.map +0 -1
- package/util/not-falsy.js +0 -6
- package/util/not-falsy.js.map +0 -1
- package/util/sanitization.d.ts.map +0 -1
- package/util/sanitization.js +0 -17
- package/util/sanitization.js.map +0 -1
|
@@ -1,62 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.callClient = void 0;
|
|
27
|
-
const algokit = __importStar(require("@algorandfoundation/algokit-utils"));
|
|
28
|
-
const writer_1 = require("../output/writer");
|
|
29
|
-
const sanitization_1 = require("../util/sanitization");
|
|
30
|
-
const get_call_config_summary_1 = require("./helpers/get-call-config-summary");
|
|
31
|
-
const deploy_types_1 = require("./deploy-types");
|
|
32
|
-
const call_composer_1 = require("./call-composer");
|
|
1
|
+
import * as algokit from '@algorandfoundation/algokit-utils';
|
|
2
|
+
import { jsDoc, IncIndent, NewLine, indent, DecIndent, inline, DecIndentAndCloseBlock } from '../output/writer.mjs';
|
|
3
|
+
import { makeSafeTypeIdentifier, makeSafeMethodIdentifier } from '../util/sanitization.mjs';
|
|
4
|
+
import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
|
|
5
|
+
import { getCreateOnCompleteOptions } from './deploy-types.mjs';
|
|
6
|
+
import { composeMethod } from './call-composer.mjs';
|
|
7
|
+
|
|
33
8
|
function* callClient(ctx) {
|
|
34
9
|
const { app, name } = ctx;
|
|
35
|
-
yield*
|
|
36
|
-
yield `export class ${
|
|
37
|
-
yield
|
|
38
|
-
yield*
|
|
10
|
+
yield* jsDoc(`A client to make calls to the ${app.contract.name} smart contract`);
|
|
11
|
+
yield `export class ${makeSafeTypeIdentifier(app.contract.name)}Client {`;
|
|
12
|
+
yield IncIndent;
|
|
13
|
+
yield* jsDoc(`The underlying \`ApplicationClient\` for when you want to have more flexibility`);
|
|
39
14
|
yield 'public readonly appClient: ApplicationClient';
|
|
40
|
-
yield
|
|
15
|
+
yield NewLine;
|
|
41
16
|
yield `private readonly sender: SendTransactionFrom | undefined`;
|
|
42
|
-
yield
|
|
43
|
-
yield*
|
|
44
|
-
description: `Creates a new instance of \`${
|
|
17
|
+
yield NewLine;
|
|
18
|
+
yield* jsDoc({
|
|
19
|
+
description: `Creates a new instance of \`${makeSafeTypeIdentifier(app.contract.name)}Client\``,
|
|
45
20
|
params: {
|
|
46
21
|
appDetails: 'appDetails The details to identify the app to deploy',
|
|
47
22
|
algod: 'An algod client instance',
|
|
48
23
|
},
|
|
49
24
|
});
|
|
50
25
|
yield `constructor(appDetails: AppDetails, private algod: Algodv2) {`;
|
|
51
|
-
yield
|
|
26
|
+
yield IncIndent;
|
|
52
27
|
yield `this.sender = appDetails.sender`;
|
|
53
28
|
yield 'this.appClient = algokit.getAppClient({';
|
|
54
|
-
yield*
|
|
29
|
+
yield* indent('...appDetails,', 'app: APP_SPEC');
|
|
55
30
|
yield '}, algod)';
|
|
56
|
-
yield
|
|
31
|
+
yield DecIndent;
|
|
57
32
|
yield '}';
|
|
58
|
-
yield
|
|
59
|
-
yield*
|
|
33
|
+
yield NewLine;
|
|
34
|
+
yield* jsDoc({
|
|
60
35
|
description: 'Checks for decode errors on the AppCallTransactionResult and maps the return value to the specified generic type',
|
|
61
36
|
params: {
|
|
62
37
|
result: 'The AppCallTransactionResult to be mapped',
|
|
@@ -64,20 +39,20 @@ function* callClient(ctx) {
|
|
|
64
39
|
},
|
|
65
40
|
returns: 'The smart contract response with an updated return value',
|
|
66
41
|
});
|
|
67
|
-
yield*
|
|
68
|
-
yield
|
|
42
|
+
yield* inline(`protected mapReturnValue<TReturn, TResult extends AppCallTransactionResult = AppCallTransactionResult>`, `(result: AppCallTransactionResult, returnValueFormatter?: (value: any) => TReturn): `, `AppCallTransactionResultOfType<TReturn> & TResult {`);
|
|
43
|
+
yield IncIndent;
|
|
69
44
|
yield `if(result.return?.decodeError) {`;
|
|
70
|
-
yield*
|
|
45
|
+
yield* indent(`throw result.return.decodeError`);
|
|
71
46
|
yield `}`;
|
|
72
47
|
yield `const returnValue = result.return?.returnValue !== undefined && returnValueFormatter !== undefined`;
|
|
73
|
-
yield
|
|
48
|
+
yield IncIndent;
|
|
74
49
|
yield `? returnValueFormatter(result.return.returnValue)`;
|
|
75
50
|
yield `: result.return?.returnValue as TReturn | undefined`;
|
|
76
51
|
yield `return { ...result, return: returnValue } as AppCallTransactionResultOfType<TReturn> & TResult`;
|
|
77
|
-
yield
|
|
78
|
-
yield
|
|
79
|
-
yield
|
|
80
|
-
yield*
|
|
52
|
+
yield DecIndent;
|
|
53
|
+
yield DecIndentAndCloseBlock;
|
|
54
|
+
yield NewLine;
|
|
55
|
+
yield* jsDoc({
|
|
81
56
|
description: 'Calls the ABI method with the matching signature using an onCompletion code of NO_OP',
|
|
82
57
|
params: {
|
|
83
58
|
typedCallParams: 'An object containing the method signature, args, and any other relevant parameters',
|
|
@@ -86,21 +61,20 @@ function* callClient(ctx) {
|
|
|
86
61
|
returns: 'The result of the smart contract call',
|
|
87
62
|
});
|
|
88
63
|
yield `public async call<TSignature extends keyof ${name}['methods']>(typedCallParams: TypedCallParams<TSignature>, returnValueFormatter?: (value: any) => MethodReturn<TSignature>) {`;
|
|
89
|
-
yield
|
|
64
|
+
yield IncIndent;
|
|
90
65
|
yield `return this.mapReturnValue<MethodReturn<TSignature>>(await this.appClient.call(typedCallParams), returnValueFormatter)`;
|
|
91
|
-
yield
|
|
92
|
-
yield
|
|
66
|
+
yield DecIndentAndCloseBlock;
|
|
67
|
+
yield NewLine;
|
|
93
68
|
yield* opMethods(ctx);
|
|
94
69
|
yield* clearState(ctx);
|
|
95
70
|
yield* noopMethods(ctx);
|
|
96
71
|
yield* getStateMethods(ctx);
|
|
97
|
-
yield*
|
|
98
|
-
yield
|
|
72
|
+
yield* composeMethod(ctx);
|
|
73
|
+
yield DecIndentAndCloseBlock;
|
|
99
74
|
}
|
|
100
|
-
exports.callClient = callClient;
|
|
101
75
|
function* opMethods(ctx) {
|
|
102
76
|
const { app, callConfig, name } = ctx;
|
|
103
|
-
yield*
|
|
77
|
+
yield* jsDoc({
|
|
104
78
|
description: `Idempotently deploys the ${app.contract.name} smart contract.`,
|
|
105
79
|
params: {
|
|
106
80
|
params: 'The arguments for the contract calls and any additional parameters for the call',
|
|
@@ -108,7 +82,7 @@ function* opMethods(ctx) {
|
|
|
108
82
|
returns: 'The deployment result',
|
|
109
83
|
});
|
|
110
84
|
yield `public deploy(params: ${name}DeployArgs & AppClientDeployCoreParams = {}): ReturnType<ApplicationClient['deploy']> {`;
|
|
111
|
-
yield
|
|
85
|
+
yield IncIndent;
|
|
112
86
|
if (callConfig.createMethods.length)
|
|
113
87
|
yield `const createArgs = params.createCall?.(${name}CallFactory.create)`;
|
|
114
88
|
if (callConfig.updateMethods.length)
|
|
@@ -116,7 +90,7 @@ function* opMethods(ctx) {
|
|
|
116
90
|
if (callConfig.deleteMethods.length)
|
|
117
91
|
yield `const deleteArgs = params.deleteCall?.(${name}CallFactory.delete)`;
|
|
118
92
|
yield `return this.appClient.deploy({`;
|
|
119
|
-
yield
|
|
93
|
+
yield IncIndent;
|
|
120
94
|
yield `...params,`;
|
|
121
95
|
if (callConfig.updateMethods.length)
|
|
122
96
|
yield 'updateArgs,';
|
|
@@ -126,10 +100,10 @@ function* opMethods(ctx) {
|
|
|
126
100
|
yield 'createArgs,';
|
|
127
101
|
yield `createOnCompleteAction: createArgs?.onCompleteAction,`;
|
|
128
102
|
}
|
|
129
|
-
yield
|
|
103
|
+
yield DecIndent;
|
|
130
104
|
yield `})`;
|
|
131
|
-
yield
|
|
132
|
-
yield
|
|
105
|
+
yield DecIndentAndCloseBlock;
|
|
106
|
+
yield NewLine;
|
|
133
107
|
yield* operationMethod(ctx, `Creates a new instance of the ${app.contract.name} smart contract`, callConfig.createMethods, 'create', true);
|
|
134
108
|
yield* operationMethod(ctx, `Updates an existing instance of the ${app.contract.name} smart contract`, callConfig.updateMethods, 'update', true);
|
|
135
109
|
yield* operationMethod(ctx, `Deletes an existing instance of the ${app.contract.name} smart contract`, callConfig.deleteMethods, 'delete');
|
|
@@ -137,7 +111,6 @@ function* opMethods(ctx) {
|
|
|
137
111
|
yield* operationMethod(ctx, `Makes a close out call to an existing instance of the ${app.contract.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
|
|
138
112
|
}
|
|
139
113
|
function* operationMethod({ app, methodSignatureToUniqueName, name }, description, methods, verb, includeCompilation) {
|
|
140
|
-
var _a;
|
|
141
114
|
let responseTypeGenericParam;
|
|
142
115
|
switch (verb) {
|
|
143
116
|
case 'create':
|
|
@@ -151,49 +124,49 @@ function* operationMethod({ app, methodSignatureToUniqueName, name }, descriptio
|
|
|
151
124
|
break;
|
|
152
125
|
}
|
|
153
126
|
if (methods.length) {
|
|
154
|
-
yield*
|
|
127
|
+
yield* jsDoc(`Gets available ${verb} methods`);
|
|
155
128
|
yield `public get ${verb}() {`;
|
|
156
|
-
yield
|
|
129
|
+
yield IncIndent;
|
|
157
130
|
yield `const $this = this`;
|
|
158
131
|
yield `return {`;
|
|
159
|
-
yield
|
|
132
|
+
yield IncIndent;
|
|
160
133
|
for (const methodSig of methods) {
|
|
161
|
-
const onComplete = verb === 'create' ?
|
|
162
|
-
if (methodSig ===
|
|
163
|
-
yield*
|
|
134
|
+
const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined;
|
|
135
|
+
if (methodSig === BARE_CALL) {
|
|
136
|
+
yield* jsDoc({
|
|
164
137
|
description: `${description} using a bare call.`,
|
|
165
138
|
params: {
|
|
166
139
|
args: `The arguments for the bare call`,
|
|
167
140
|
},
|
|
168
141
|
returns: `The ${verb} result`,
|
|
169
142
|
});
|
|
170
|
-
yield `async bare(args: BareCallArgs & AppClientCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${
|
|
171
|
-
yield*
|
|
143
|
+
yield `async bare(args: BareCallArgs & AppClientCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}) {`;
|
|
144
|
+
yield* indent(`return $this.mapReturnValue<undefined${responseTypeGenericParam}>(await $this.appClient.${verb}(args))`);
|
|
172
145
|
yield '},';
|
|
173
146
|
}
|
|
174
147
|
else {
|
|
175
148
|
const uniqueName = methodSignatureToUniqueName[methodSig];
|
|
176
149
|
const method = app.contract.methods.find((m) => algokit.getABIMethodSignature(m) === methodSig);
|
|
177
|
-
yield*
|
|
150
|
+
yield* jsDoc({
|
|
178
151
|
description: `${description} using the ${methodSig} ABI method.`,
|
|
179
152
|
params: {
|
|
180
153
|
args: `The arguments for the smart contract call`,
|
|
181
154
|
params: `Any additional parameters for the call`,
|
|
182
155
|
},
|
|
183
|
-
returns: `The ${verb} result${
|
|
156
|
+
returns: `The ${verb} result${method?.returns?.desc ? `: ${method.returns.desc}` : ''}`,
|
|
184
157
|
});
|
|
185
|
-
yield `async ${
|
|
186
|
-
yield*
|
|
158
|
+
yield `async ${makeSafeMethodIdentifier(uniqueName)}(args: MethodArgs<'${methodSig}'>, params: AppClientCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}) {`;
|
|
159
|
+
yield* indent(`return $this.mapReturnValue<MethodReturn<'${methodSig}'>${responseTypeGenericParam}>(await $this.appClient.${verb}(${name}CallFactory.${verb}.${makeSafeMethodIdentifier(uniqueName)}(args, params)))`);
|
|
187
160
|
yield '},';
|
|
188
161
|
}
|
|
189
162
|
}
|
|
190
|
-
yield
|
|
191
|
-
yield
|
|
192
|
-
yield
|
|
163
|
+
yield DecIndentAndCloseBlock;
|
|
164
|
+
yield DecIndentAndCloseBlock;
|
|
165
|
+
yield NewLine;
|
|
193
166
|
}
|
|
194
167
|
}
|
|
195
168
|
function* clearState({ app }) {
|
|
196
|
-
yield*
|
|
169
|
+
yield* jsDoc({
|
|
197
170
|
description: `Makes a clear_state call to an existing instance of the ${app.contract.name} smart contract.`,
|
|
198
171
|
params: {
|
|
199
172
|
args: `The arguments for the bare call`,
|
|
@@ -201,43 +174,41 @@ function* clearState({ app }) {
|
|
|
201
174
|
returns: `The clear_state result`,
|
|
202
175
|
});
|
|
203
176
|
yield `public clearState(args: BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs = {}) {`;
|
|
204
|
-
yield
|
|
177
|
+
yield IncIndent;
|
|
205
178
|
yield `return this.appClient.clearState(args)`;
|
|
206
|
-
yield
|
|
207
|
-
yield
|
|
179
|
+
yield DecIndentAndCloseBlock;
|
|
180
|
+
yield NewLine;
|
|
208
181
|
}
|
|
209
182
|
function* noopMethods({ app, name, callConfig, methodSignatureToUniqueName }) {
|
|
210
|
-
var _a, _b, _c, _d, _e;
|
|
211
183
|
for (const method of app.contract.methods) {
|
|
212
184
|
const methodSignature = algokit.getABIMethodSignature(method);
|
|
213
|
-
const methodName =
|
|
185
|
+
const methodName = makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]);
|
|
214
186
|
// Skip methods which don't support a no_op call config
|
|
215
187
|
if (!callConfig.callMethods.includes(methodSignature))
|
|
216
188
|
continue;
|
|
217
|
-
yield*
|
|
189
|
+
yield* jsDoc({
|
|
218
190
|
description: `Calls the ${algokit.getABIMethodSignature(method)} ABI method.`,
|
|
219
191
|
abiDescription: method.desc,
|
|
220
192
|
params: {
|
|
221
193
|
args: `The arguments for the contract call`,
|
|
222
194
|
params: `Any additional parameters for the call`,
|
|
223
195
|
},
|
|
224
|
-
returns: `The result of the call${
|
|
196
|
+
returns: `The result of the call${method?.returns?.desc ? `: ${method.returns.desc}` : ''}`,
|
|
225
197
|
});
|
|
226
198
|
yield `public ${methodName}(args: MethodArgs<'${methodSignature}'>, params: AppClientCallCoreParams & CoreAppCallArgs = {}) {`;
|
|
227
|
-
yield
|
|
228
|
-
const outputTypeName =
|
|
229
|
-
yield `return this.call(${name}CallFactory.${methodName}(args, params)${outputTypeName === undefined ? '' : `, ${
|
|
230
|
-
yield
|
|
199
|
+
yield IncIndent;
|
|
200
|
+
const outputTypeName = app.hints?.[methodSignature]?.structs?.output?.name;
|
|
201
|
+
yield `return this.call(${name}CallFactory.${methodName}(args, params)${outputTypeName === undefined ? '' : `, ${makeSafeTypeIdentifier(outputTypeName)}`})`;
|
|
202
|
+
yield DecIndent;
|
|
231
203
|
yield '}';
|
|
232
|
-
yield
|
|
204
|
+
yield NewLine;
|
|
233
205
|
}
|
|
234
206
|
}
|
|
235
207
|
function* getStateMethods({ app, name }) {
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
yield* (0, writer_1.jsDoc)({
|
|
208
|
+
const globalStateValues = app.schema.global?.declared && Object.values(app.schema.global?.declared);
|
|
209
|
+
const localStateValues = app.schema.local?.declared && Object.values(app.schema.local?.declared);
|
|
210
|
+
if (globalStateValues?.length || localStateValues?.length) {
|
|
211
|
+
yield* jsDoc({
|
|
241
212
|
description: 'Extracts a binary state value out of an AppState dictionary',
|
|
242
213
|
params: {
|
|
243
214
|
state: 'The state dictionary containing the state value',
|
|
@@ -246,23 +217,23 @@ function* getStateMethods({ app, name }) {
|
|
|
246
217
|
returns: 'A BinaryState instance containing the state value, or undefined if the key was not found',
|
|
247
218
|
});
|
|
248
219
|
yield `private static getBinaryState(state: AppState, key: string): BinaryState | undefined {`;
|
|
249
|
-
yield
|
|
220
|
+
yield IncIndent;
|
|
250
221
|
yield `const value = state[key]`;
|
|
251
222
|
yield `if (!value) return undefined`;
|
|
252
223
|
yield `if (!('valueRaw' in value))`;
|
|
253
|
-
yield*
|
|
224
|
+
yield* indent(`throw new Error(\`Failed to parse state value for \${key}; received an int when expected a byte array\`)`);
|
|
254
225
|
yield `return {`;
|
|
255
|
-
yield
|
|
226
|
+
yield IncIndent;
|
|
256
227
|
yield `asString(): string {`;
|
|
257
|
-
yield*
|
|
228
|
+
yield* indent(`return value.value`);
|
|
258
229
|
yield `},`;
|
|
259
230
|
yield `asByteArray(): Uint8Array {`;
|
|
260
|
-
yield*
|
|
231
|
+
yield* indent(`return value.valueRaw`);
|
|
261
232
|
yield `}`;
|
|
262
|
-
yield
|
|
263
|
-
yield
|
|
264
|
-
yield
|
|
265
|
-
yield*
|
|
233
|
+
yield DecIndentAndCloseBlock;
|
|
234
|
+
yield DecIndentAndCloseBlock;
|
|
235
|
+
yield NewLine;
|
|
236
|
+
yield* jsDoc({
|
|
266
237
|
description: 'Extracts a integer state value out of an AppState dictionary',
|
|
267
238
|
params: {
|
|
268
239
|
state: 'The state dictionary containing the state value',
|
|
@@ -271,69 +242,70 @@ function* getStateMethods({ app, name }) {
|
|
|
271
242
|
returns: 'An IntegerState instance containing the state value, or undefined if the key was not found',
|
|
272
243
|
});
|
|
273
244
|
yield `private static getIntegerState(state: AppState, key: string): IntegerState | undefined {`;
|
|
274
|
-
yield
|
|
245
|
+
yield IncIndent;
|
|
275
246
|
yield `const value = state[key]`;
|
|
276
247
|
yield `if (!value) return undefined`;
|
|
277
248
|
yield `if ('valueRaw' in value)`;
|
|
278
|
-
yield*
|
|
249
|
+
yield* indent(`throw new Error(\`Failed to parse state value for \${key}; received a byte array when expected a number\`)`);
|
|
279
250
|
yield `return {`;
|
|
280
|
-
yield
|
|
251
|
+
yield IncIndent;
|
|
281
252
|
yield `asBigInt() {`;
|
|
282
|
-
yield*
|
|
253
|
+
yield* indent(`return typeof value.value === 'bigint' ? value.value : BigInt(value.value)`);
|
|
283
254
|
yield `},`;
|
|
284
255
|
yield `asNumber(): number {`;
|
|
285
|
-
yield*
|
|
256
|
+
yield* indent(`return typeof value.value === 'bigint' ? Number(value.value) : value.value`);
|
|
286
257
|
yield `},`;
|
|
287
|
-
yield
|
|
288
|
-
yield
|
|
289
|
-
yield
|
|
258
|
+
yield DecIndentAndCloseBlock;
|
|
259
|
+
yield DecIndentAndCloseBlock;
|
|
260
|
+
yield NewLine;
|
|
290
261
|
}
|
|
291
|
-
if (globalStateValues
|
|
292
|
-
yield*
|
|
262
|
+
if (globalStateValues?.length) {
|
|
263
|
+
yield* jsDoc(`Returns the smart contract's global state wrapped in a strongly typed accessor with options to format the stored value`);
|
|
293
264
|
yield `public async getGlobalState(): Promise<${name}['state']['global']> {`;
|
|
294
|
-
yield
|
|
265
|
+
yield IncIndent;
|
|
295
266
|
yield `const state = await this.appClient.getGlobalState()`;
|
|
296
267
|
yield `return {`;
|
|
297
|
-
yield
|
|
268
|
+
yield IncIndent;
|
|
298
269
|
for (const stateValue of globalStateValues) {
|
|
299
270
|
yield `get ${stateValue.key}() {`;
|
|
300
271
|
if (stateValue.type === 'uint64') {
|
|
301
|
-
yield*
|
|
272
|
+
yield* indent(`return ${name}Client.getIntegerState(state, '${stateValue.key}')`);
|
|
302
273
|
}
|
|
303
274
|
else {
|
|
304
|
-
yield*
|
|
275
|
+
yield* indent(`return ${name}Client.getBinaryState(state, '${stateValue.key}')`);
|
|
305
276
|
}
|
|
306
277
|
yield '},';
|
|
307
278
|
}
|
|
308
|
-
yield
|
|
309
|
-
yield
|
|
310
|
-
yield
|
|
279
|
+
yield DecIndentAndCloseBlock;
|
|
280
|
+
yield DecIndentAndCloseBlock;
|
|
281
|
+
yield NewLine;
|
|
311
282
|
}
|
|
312
|
-
if (localStateValues
|
|
313
|
-
yield*
|
|
283
|
+
if (localStateValues?.length) {
|
|
284
|
+
yield* jsDoc({
|
|
314
285
|
description: `Returns the smart contract's local state wrapped in a strongly typed accessor with options to format the stored value`,
|
|
315
286
|
params: {
|
|
316
287
|
account: `The address of the account for which to read local state from`,
|
|
317
288
|
},
|
|
318
289
|
});
|
|
319
290
|
yield `public async getLocalState(account: string | SendTransactionFrom): Promise<${name}['state']['local']> {`;
|
|
320
|
-
yield
|
|
291
|
+
yield IncIndent;
|
|
321
292
|
yield `const state = await this.appClient.getLocalState(account)`;
|
|
322
293
|
yield `return {`;
|
|
323
|
-
yield
|
|
294
|
+
yield IncIndent;
|
|
324
295
|
for (const stateValue of localStateValues) {
|
|
325
296
|
yield `get ${stateValue.key}() {`;
|
|
326
297
|
if (stateValue.type === 'uint64') {
|
|
327
|
-
yield*
|
|
298
|
+
yield* indent(`return ${name}Client.getIntegerState(state, '${stateValue.key}')`);
|
|
328
299
|
}
|
|
329
300
|
else {
|
|
330
|
-
yield*
|
|
301
|
+
yield* indent(`return ${name}Client.getBinaryState(state, '${stateValue.key}')`);
|
|
331
302
|
}
|
|
332
303
|
yield '},';
|
|
333
304
|
}
|
|
334
|
-
yield
|
|
335
|
-
yield
|
|
336
|
-
yield
|
|
305
|
+
yield DecIndentAndCloseBlock;
|
|
306
|
+
yield DecIndentAndCloseBlock;
|
|
307
|
+
yield NewLine;
|
|
337
308
|
}
|
|
338
309
|
}
|
|
339
|
-
|
|
310
|
+
|
|
311
|
+
export { callClient };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var writer = require('../output/writer.cjs');
|
|
4
|
+
var algokit = require('@algorandfoundation/algokit-utils');
|
|
5
|
+
var sanitization = require('../util/sanitization.cjs');
|
|
6
|
+
var getCallConfigSummary = require('./helpers/get-call-config-summary.cjs');
|
|
7
|
+
var deployTypes = require('./deploy-types.cjs');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var algokit__namespace = /*#__PURE__*/_interopNamespaceDefault(algokit);
|
|
27
|
+
|
|
28
|
+
function* callComposerType(ctx) {
|
|
29
|
+
const { name, callConfig, app } = ctx;
|
|
30
|
+
yield `export type ${name}Composer<TReturns extends [...any[]] = []> = {`;
|
|
31
|
+
yield writer.IncIndent;
|
|
32
|
+
yield* callComposerTypeNoops(ctx);
|
|
33
|
+
yield* callComposerOperationMethodType(ctx, `Updates an existing instance of the ${app.contract.name} smart contract`, callConfig.updateMethods, 'update', true);
|
|
34
|
+
yield* callComposerOperationMethodType(ctx, `Deletes an existing instance of the ${app.contract.name} smart contract`, callConfig.deleteMethods, 'delete');
|
|
35
|
+
yield* callComposerOperationMethodType(ctx, `Opts the user into an existing instance of the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn');
|
|
36
|
+
yield* callComposerOperationMethodType(ctx, `Makes a close out call to an existing instance of the ${app.contract.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
|
|
37
|
+
yield* callComposerTypeClearState(ctx);
|
|
38
|
+
yield* writer.jsDoc({
|
|
39
|
+
description: 'Adds a transaction to the composer',
|
|
40
|
+
params: {
|
|
41
|
+
txn: 'One of: A TransactionWithSigner object (returned as is), a TransactionToSign object (signer is obtained from the signer property), a Transaction object (signer is extracted from the defaultSender parameter), an async SendTransactionResult returned by one of algokit utils helpers (signer is obtained from the defaultSender parameter)',
|
|
42
|
+
defaultSender: 'The default sender to be used to obtain a signer where the object provided to the transaction parameter does not' +
|
|
43
|
+
' include a signer.',
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
yield `addTransaction(txn: TransactionWithSigner | TransactionToSign | Transaction | Promise<SendTransactionResult>, defaultSender?: SendTransactionFrom): ${name}Composer<TReturns>`;
|
|
47
|
+
yield* writer.jsDoc({
|
|
48
|
+
description: 'Returns the underlying AtomicTransactionComposer instance',
|
|
49
|
+
});
|
|
50
|
+
yield `atc(): Promise<AtomicTransactionComposer>`;
|
|
51
|
+
yield* writer.jsDoc({
|
|
52
|
+
description: 'Simulates the transaction group and returns the result',
|
|
53
|
+
});
|
|
54
|
+
yield `simulate(options?: SimulateOptions): Promise<${name}ComposerSimulateResult<TReturns>>`;
|
|
55
|
+
yield* writer.jsDoc({
|
|
56
|
+
description: 'Executes the transaction group and returns the results',
|
|
57
|
+
});
|
|
58
|
+
yield `execute(sendParams?: AppClientComposeExecuteParams): Promise<${name}ComposerResults<TReturns>>`;
|
|
59
|
+
yield writer.DecIndentAndCloseBlock;
|
|
60
|
+
yield `export type SimulateOptions = Omit<ConstructorParameters<typeof modelsv2.SimulateRequest>[0], 'txnGroups'>`;
|
|
61
|
+
yield `export type ${name}ComposerSimulateResult<TReturns extends [...any[]]> = {`;
|
|
62
|
+
yield writer.IncIndent;
|
|
63
|
+
yield `returns: TReturns`;
|
|
64
|
+
yield `methodResults: ABIResult[]`;
|
|
65
|
+
yield `simulateResponse: modelsv2.SimulateResponse`;
|
|
66
|
+
yield writer.DecIndentAndCloseBlock;
|
|
67
|
+
yield `export type ${name}ComposerResults<TReturns extends [...any[]]> = {`;
|
|
68
|
+
yield writer.IncIndent;
|
|
69
|
+
yield `returns: TReturns`;
|
|
70
|
+
yield `groupId: string`;
|
|
71
|
+
yield `txIds: string[]`;
|
|
72
|
+
yield `transactions: Transaction[]`;
|
|
73
|
+
yield writer.DecIndentAndCloseBlock;
|
|
74
|
+
}
|
|
75
|
+
function* callComposerTypeClearState({ app, name }) {
|
|
76
|
+
yield* writer.jsDoc({
|
|
77
|
+
description: `Makes a clear_state call to an existing instance of the ${app.contract.name} smart contract.`,
|
|
78
|
+
params: {
|
|
79
|
+
args: `The arguments for the bare call`,
|
|
80
|
+
},
|
|
81
|
+
returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
|
|
82
|
+
});
|
|
83
|
+
yield `clearState(args?: BareCallArgs & AppClientComposeCallCoreParams & CoreAppCallArgs): ${name}Composer<[...TReturns, undefined]>`;
|
|
84
|
+
yield writer.NewLine;
|
|
85
|
+
}
|
|
86
|
+
function* callComposerTypeNoops({ app, name, callConfig, methodSignatureToUniqueName }) {
|
|
87
|
+
for (const method of app.contract.methods) {
|
|
88
|
+
const methodSignature = algokit__namespace.getABIMethodSignature(method);
|
|
89
|
+
const methodName = sanitization.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]);
|
|
90
|
+
// Skip methods which don't support a no_op call config
|
|
91
|
+
if (!callConfig.callMethods.includes(methodSignature))
|
|
92
|
+
continue;
|
|
93
|
+
yield* writer.jsDoc({
|
|
94
|
+
description: `Calls the ${algokit__namespace.getABIMethodSignature(method)} ABI method.`,
|
|
95
|
+
abiDescription: method.desc,
|
|
96
|
+
params: {
|
|
97
|
+
args: `The arguments for the contract call`,
|
|
98
|
+
params: `Any additional parameters for the call`,
|
|
99
|
+
},
|
|
100
|
+
returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
|
|
101
|
+
});
|
|
102
|
+
yield `${methodName}(args: MethodArgs<'${methodSignature}'>, params?: AppClientComposeCallCoreParams & CoreAppCallArgs): ${name}Composer<[...TReturns, MethodReturn<'${methodSignature}'>]>`;
|
|
103
|
+
yield writer.NewLine;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function* callComposerOperationMethodType({ app, methodSignatureToUniqueName, name }, description, methods, verb, includeCompilation) {
|
|
107
|
+
if (methods.length) {
|
|
108
|
+
yield* writer.jsDoc(`Gets available ${verb} methods`);
|
|
109
|
+
yield `readonly ${verb}: {`;
|
|
110
|
+
yield writer.IncIndent;
|
|
111
|
+
for (const methodSig of methods) {
|
|
112
|
+
const onComplete = verb === 'create' ? deployTypes.getCreateOnCompleteOptions(methodSig, app) : undefined;
|
|
113
|
+
if (methodSig === getCallConfigSummary.BARE_CALL) {
|
|
114
|
+
yield* writer.jsDoc({
|
|
115
|
+
description: `${description} using a bare call.`,
|
|
116
|
+
params: {
|
|
117
|
+
args: `The arguments for the bare call`,
|
|
118
|
+
},
|
|
119
|
+
returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
|
|
120
|
+
});
|
|
121
|
+
yield `bare(args${onComplete?.isOptional !== false ? '?' : ''}: BareCallArgs & AppClientComposeCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${onComplete?.type ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, undefined]>`;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const uniqueName = methodSignatureToUniqueName[methodSig];
|
|
125
|
+
yield* writer.jsDoc({
|
|
126
|
+
description: `${description} using the ${methodSig} ABI method.`,
|
|
127
|
+
params: {
|
|
128
|
+
args: `The arguments for the smart contract call`,
|
|
129
|
+
params: `Any additional parameters for the call`,
|
|
130
|
+
},
|
|
131
|
+
returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
|
|
132
|
+
});
|
|
133
|
+
yield `${sanitization.makeSafeMethodIdentifier(uniqueName)}(args: MethodArgs<'${methodSig}'>, params${onComplete?.isOptional !== false ? '?' : ''}: AppClientComposeCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, MethodReturn<'${methodSig}'>]>`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
yield writer.DecIndentAndCloseBlock;
|
|
137
|
+
yield writer.NewLine;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
exports.callComposerType = callComposerType;
|