@algorandfoundation/algokit-client-generator 2.6.0 → 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.
Files changed (128) hide show
  1. package/bin/cli.mjs +4 -0
  2. package/cli.cjs +75 -0
  3. package/cli.d.ts +0 -1
  4. package/cli.mjs +54 -0
  5. package/client/app-types.cjs +152 -0
  6. package/client/app-types.d.ts +0 -1
  7. package/client/app-types.mjs +131 -0
  8. package/client/call-client.cjs +332 -0
  9. package/client/call-client.d.ts +0 -1
  10. package/client/{call-client.js → call-client.mjs} +107 -135
  11. package/client/call-composer-types.cjs +141 -0
  12. package/client/call-composer-types.d.ts +0 -1
  13. package/client/{call-composer-types.js → call-composer-types.mjs} +33 -58
  14. package/client/call-composer.cjs +145 -0
  15. package/client/call-composer.d.ts +0 -1
  16. package/client/call-composer.mjs +124 -0
  17. package/client/call-factory.cjs +138 -0
  18. package/client/call-factory.d.ts +0 -1
  19. package/client/{call-factory.js → call-factory.mjs} +31 -56
  20. package/client/deploy-types.cjs +94 -0
  21. package/client/deploy-types.d.ts +0 -1
  22. package/client/deploy-types.mjs +91 -0
  23. package/client/generate.cjs +37 -0
  24. package/client/generate.d.ts +0 -1
  25. package/client/generate.mjs +35 -0
  26. package/client/generator-context.cjs +37 -0
  27. package/client/generator-context.d.ts +0 -1
  28. package/client/generator-context.mjs +16 -0
  29. package/client/helpers/{get-call-config-summary.js → get-call-config-summary.cjs} +7 -25
  30. package/client/helpers/get-call-config-summary.d.ts +1 -2
  31. package/client/helpers/get-call-config-summary.mjs +54 -0
  32. package/client/helpers/{get-equivalent-type.js → get-equivalent-type.cjs} +20 -20
  33. package/client/helpers/get-equivalent-type.d.ts +0 -1
  34. package/client/helpers/get-equivalent-type.mjs +56 -0
  35. package/client/{imports.js → imports.cjs} +3 -4
  36. package/client/imports.d.ts +0 -1
  37. package/client/imports.mjs +27 -0
  38. package/client/{utility-types.js → utility-types.cjs} +26 -25
  39. package/client/utility-types.d.ts +0 -1
  40. package/client/utility-types.mjs +47 -0
  41. package/dev.d.ts +0 -1
  42. package/index.cjs +13 -0
  43. package/index.d.ts +0 -1
  44. package/index.mjs +3 -0
  45. package/output/{writer.js → writer.cjs} +44 -38
  46. package/output/writer.d.ts +0 -1
  47. package/output/writer.mjs +139 -0
  48. package/package.json +7 -4
  49. package/schema/application.schema.json.cjs +374 -0
  50. package/schema/application.schema.json.mjs +363 -0
  51. package/schema/contract.schema.json.cjs +159 -0
  52. package/schema/contract.schema.json.mjs +148 -0
  53. package/schema/load.cjs +25 -0
  54. package/schema/load.d.ts +0 -1
  55. package/schema/load.mjs +22 -0
  56. package/tests/approval-tests.spec.d.ts +0 -1
  57. package/tests/util.d.ts +1 -0
  58. package/util/boom.cjs +7 -0
  59. package/util/boom.d.ts +0 -1
  60. package/util/boom.mjs +5 -0
  61. package/util/color-console.cjs +18 -0
  62. package/util/color-console.d.ts +0 -1
  63. package/util/color-console.mjs +16 -0
  64. package/util/not-falsy.d.ts +0 -1
  65. package/util/sanitization.cjs +17 -0
  66. package/util/sanitization.d.ts +0 -1
  67. package/util/sanitization.mjs +11 -0
  68. package/bin/cli.js +0 -4
  69. package/cli.d.ts.map +0 -1
  70. package/cli.js +0 -79
  71. package/cli.js.map +0 -1
  72. package/client/app-types.d.ts.map +0 -1
  73. package/client/app-types.js +0 -161
  74. package/client/app-types.js.map +0 -1
  75. package/client/call-client.d.ts.map +0 -1
  76. package/client/call-client.js.map +0 -1
  77. package/client/call-composer-types.d.ts.map +0 -1
  78. package/client/call-composer-types.js.map +0 -1
  79. package/client/call-composer.d.ts.map +0 -1
  80. package/client/call-composer.js +0 -151
  81. package/client/call-composer.js.map +0 -1
  82. package/client/call-factory.d.ts.map +0 -1
  83. package/client/call-factory.js.map +0 -1
  84. package/client/deploy-types.d.ts.map +0 -1
  85. package/client/deploy-types.js +0 -95
  86. package/client/deploy-types.js.map +0 -1
  87. package/client/generate.d.ts.map +0 -1
  88. package/client/generate.js +0 -37
  89. package/client/generate.js.map +0 -1
  90. package/client/generator-context.d.ts.map +0 -1
  91. package/client/generator-context.js +0 -41
  92. package/client/generator-context.js.map +0 -1
  93. package/client/helpers/get-call-config-summary.d.ts.map +0 -1
  94. package/client/helpers/get-call-config-summary.js.map +0 -1
  95. package/client/helpers/get-equivalent-type.d.ts.map +0 -1
  96. package/client/helpers/get-equivalent-type.js.map +0 -1
  97. package/client/imports.d.ts.map +0 -1
  98. package/client/imports.js.map +0 -1
  99. package/client/utility-types.d.ts.map +0 -1
  100. package/client/utility-types.js.map +0 -1
  101. package/dev.d.ts.map +0 -1
  102. package/dev.js +0 -5
  103. package/dev.js.map +0 -1
  104. package/index.d.ts.map +0 -1
  105. package/index.js +0 -12
  106. package/index.js.map +0 -1
  107. package/output/writer.d.ts.map +0 -1
  108. package/output/writer.js.map +0 -1
  109. package/schema/application.schema.json +0 -354
  110. package/schema/contract.schema.json +0 -139
  111. package/schema/load.d.ts.map +0 -1
  112. package/schema/load.js +0 -51
  113. package/schema/load.js.map +0 -1
  114. package/tests/approval-tests.spec.d.ts.map +0 -1
  115. package/tests/approval-tests.spec.js +0 -24
  116. package/tests/approval-tests.spec.js.map +0 -1
  117. package/util/boom.d.ts.map +0 -1
  118. package/util/boom.js +0 -8
  119. package/util/boom.js.map +0 -1
  120. package/util/color-console.d.ts.map +0 -1
  121. package/util/color-console.js +0 -20
  122. package/util/color-console.js.map +0 -1
  123. package/util/not-falsy.d.ts.map +0 -1
  124. package/util/not-falsy.js +0 -6
  125. package/util/not-falsy.js.map +0 -1
  126. package/util/sanitization.d.ts.map +0 -1
  127. package/util/sanitization.js +0 -17
  128. package/util/sanitization.js.map +0 -1
@@ -1,62 +1,37 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
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* (0, writer_1.jsDoc)(`A client to make calls to the ${app.contract.name} smart contract`);
36
- yield `export class ${(0, sanitization_1.makeSafeTypeIdentifier)(app.contract.name)}Client {`;
37
- yield writer_1.IncIndent;
38
- yield* (0, writer_1.jsDoc)(`The underlying \`ApplicationClient\` for when you want to have more flexibility`);
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 writer_1.NewLine;
15
+ yield NewLine;
41
16
  yield `private readonly sender: SendTransactionFrom | undefined`;
42
- yield writer_1.NewLine;
43
- yield* (0, writer_1.jsDoc)({
44
- description: `Creates a new instance of \`${(0, sanitization_1.makeSafeTypeIdentifier)(app.contract.name)}Client\``,
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 writer_1.IncIndent;
26
+ yield IncIndent;
52
27
  yield `this.sender = appDetails.sender`;
53
28
  yield 'this.appClient = algokit.getAppClient({';
54
- yield* (0, writer_1.indent)('...appDetails,', 'app: APP_SPEC');
29
+ yield* indent('...appDetails,', 'app: APP_SPEC');
55
30
  yield '}, algod)';
56
- yield writer_1.DecIndent;
31
+ yield DecIndent;
57
32
  yield '}';
58
- yield writer_1.NewLine;
59
- yield* (0, writer_1.jsDoc)({
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* (0, writer_1.inline)(`protected mapReturnValue<TReturn, TResult extends AppCallTransactionResult = AppCallTransactionResult>`, `(result: AppCallTransactionResult, returnValueFormatter?: (value: any) => TReturn): `, `AppCallTransactionResultOfType<TReturn> & TResult {`);
68
- yield writer_1.IncIndent;
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* (0, writer_1.indent)(`throw result.return.decodeError`);
45
+ yield* indent(`throw result.return.decodeError`);
71
46
  yield `}`;
72
47
  yield `const returnValue = result.return?.returnValue !== undefined && returnValueFormatter !== undefined`;
73
- yield writer_1.IncIndent;
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 writer_1.DecIndent;
78
- yield writer_1.DecIndentAndCloseBlock;
79
- yield writer_1.NewLine;
80
- yield* (0, writer_1.jsDoc)({
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 writer_1.IncIndent;
64
+ yield IncIndent;
90
65
  yield `return this.mapReturnValue<MethodReturn<TSignature>>(await this.appClient.call(typedCallParams), returnValueFormatter)`;
91
- yield writer_1.DecIndentAndCloseBlock;
92
- yield writer_1.NewLine;
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* (0, call_composer_1.composeMethod)(ctx);
98
- yield writer_1.DecIndentAndCloseBlock;
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* (0, writer_1.jsDoc)({
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 writer_1.IncIndent;
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 writer_1.IncIndent;
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 writer_1.DecIndent;
103
+ yield DecIndent;
130
104
  yield `})`;
131
- yield writer_1.DecIndentAndCloseBlock;
132
- yield writer_1.NewLine;
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* (0, writer_1.jsDoc)(`Gets available ${verb} methods`);
127
+ yield* jsDoc(`Gets available ${verb} methods`);
155
128
  yield `public get ${verb}() {`;
156
- yield writer_1.IncIndent;
129
+ yield IncIndent;
157
130
  yield `const $this = this`;
158
131
  yield `return {`;
159
- yield writer_1.IncIndent;
132
+ yield IncIndent;
160
133
  for (const methodSig of methods) {
161
- const onComplete = verb === 'create' ? (0, deploy_types_1.getCreateOnCompleteOptions)(methodSig, app) : undefined;
162
- if (methodSig === get_call_config_summary_1.BARE_CALL) {
163
- yield* (0, writer_1.jsDoc)({
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${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.type) ? ` & ${onComplete.type}` : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.isOptional) !== false ? ' = {}' : ''}) {`;
171
- yield* (0, writer_1.indent)(`return $this.mapReturnValue<undefined${responseTypeGenericParam}>(await $this.appClient.${verb}(args))`);
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* (0, writer_1.jsDoc)({
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${((_a = method === null || method === void 0 ? void 0 : method.returns) === null || _a === void 0 ? void 0 : _a.desc) ? `: ${method.returns.desc}` : ''}`,
156
+ returns: `The ${verb} result${method?.returns?.desc ? `: ${method.returns.desc}` : ''}`,
184
157
  });
185
- yield `async ${(0, sanitization_1.makeSafeMethodIdentifier)(uniqueName)}(args: MethodArgs<'${methodSig}'>, params: AppClientCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.type) ? ` & ${onComplete.type}` : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.isOptional) !== false ? ' = {}' : ''}) {`;
186
- yield* (0, writer_1.indent)(`return $this.mapReturnValue<MethodReturn<'${methodSig}'>${responseTypeGenericParam}>(await $this.appClient.${verb}(${name}CallFactory.${verb}.${(0, sanitization_1.makeSafeMethodIdentifier)(uniqueName)}(args, params)))`);
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 writer_1.DecIndentAndCloseBlock;
191
- yield writer_1.DecIndentAndCloseBlock;
192
- yield writer_1.NewLine;
163
+ yield DecIndentAndCloseBlock;
164
+ yield DecIndentAndCloseBlock;
165
+ yield NewLine;
193
166
  }
194
167
  }
195
168
  function* clearState({ app }) {
196
- yield* (0, writer_1.jsDoc)({
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 writer_1.IncIndent;
177
+ yield IncIndent;
205
178
  yield `return this.appClient.clearState(args)`;
206
- yield writer_1.DecIndentAndCloseBlock;
207
- yield writer_1.NewLine;
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 = (0, sanitization_1.makeSafeMethodIdentifier)(methodSignatureToUniqueName[methodSignature]);
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* (0, writer_1.jsDoc)({
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${((_a = method === null || method === void 0 ? void 0 : method.returns) === null || _a === void 0 ? void 0 : _a.desc) ? `: ${method.returns.desc}` : ''}`,
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 writer_1.IncIndent;
228
- const outputTypeName = (_e = (_d = (_c = (_b = app.hints) === null || _b === void 0 ? void 0 : _b[methodSignature]) === null || _c === void 0 ? void 0 : _c.structs) === null || _d === void 0 ? void 0 : _d.output) === null || _e === void 0 ? void 0 : _e.name;
229
- yield `return this.call(${name}CallFactory.${methodName}(args, params)${outputTypeName === undefined ? '' : `, ${(0, sanitization_1.makeSafeTypeIdentifier)(outputTypeName)}`})`;
230
- yield writer_1.DecIndent;
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 writer_1.NewLine;
204
+ yield NewLine;
233
205
  }
234
206
  }
235
207
  function* getStateMethods({ app, name }) {
236
- var _a, _b, _c, _d;
237
- const globalStateValues = ((_a = app.schema.global) === null || _a === void 0 ? void 0 : _a.declared) && Object.values((_b = app.schema.global) === null || _b === void 0 ? void 0 : _b.declared);
238
- const localStateValues = ((_c = app.schema.local) === null || _c === void 0 ? void 0 : _c.declared) && Object.values((_d = app.schema.local) === null || _d === void 0 ? void 0 : _d.declared);
239
- if ((globalStateValues === null || globalStateValues === void 0 ? void 0 : globalStateValues.length) || (localStateValues === null || localStateValues === void 0 ? void 0 : localStateValues.length)) {
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 writer_1.IncIndent;
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* (0, writer_1.indent)(`throw new Error(\`Failed to parse state value for \${key}; received an int when expected a byte array\`)`);
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 writer_1.IncIndent;
226
+ yield IncIndent;
256
227
  yield `asString(): string {`;
257
- yield* (0, writer_1.indent)(`return value.value`);
228
+ yield* indent(`return value.value`);
258
229
  yield `},`;
259
230
  yield `asByteArray(): Uint8Array {`;
260
- yield* (0, writer_1.indent)(`return value.valueRaw`);
231
+ yield* indent(`return value.valueRaw`);
261
232
  yield `}`;
262
- yield writer_1.DecIndentAndCloseBlock;
263
- yield writer_1.DecIndentAndCloseBlock;
264
- yield writer_1.NewLine;
265
- yield* (0, writer_1.jsDoc)({
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 writer_1.IncIndent;
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* (0, writer_1.indent)(`throw new Error(\`Failed to parse state value for \${key}; received a byte array when expected a number\`)`);
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 writer_1.IncIndent;
251
+ yield IncIndent;
281
252
  yield `asBigInt() {`;
282
- yield* (0, writer_1.indent)(`return typeof value.value === 'bigint' ? value.value : BigInt(value.value)`);
253
+ yield* indent(`return typeof value.value === 'bigint' ? value.value : BigInt(value.value)`);
283
254
  yield `},`;
284
255
  yield `asNumber(): number {`;
285
- yield* (0, writer_1.indent)(`return typeof value.value === 'bigint' ? Number(value.value) : value.value`);
256
+ yield* indent(`return typeof value.value === 'bigint' ? Number(value.value) : value.value`);
286
257
  yield `},`;
287
- yield writer_1.DecIndentAndCloseBlock;
288
- yield writer_1.DecIndentAndCloseBlock;
289
- yield writer_1.NewLine;
258
+ yield DecIndentAndCloseBlock;
259
+ yield DecIndentAndCloseBlock;
260
+ yield NewLine;
290
261
  }
291
- if (globalStateValues === null || globalStateValues === void 0 ? void 0 : globalStateValues.length) {
292
- yield* (0, writer_1.jsDoc)(`Returns the smart contract's global state wrapped in a strongly typed accessor with options to format the stored value`);
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 writer_1.IncIndent;
265
+ yield IncIndent;
295
266
  yield `const state = await this.appClient.getGlobalState()`;
296
267
  yield `return {`;
297
- yield writer_1.IncIndent;
268
+ yield IncIndent;
298
269
  for (const stateValue of globalStateValues) {
299
270
  yield `get ${stateValue.key}() {`;
300
271
  if (stateValue.type === 'uint64') {
301
- yield* (0, writer_1.indent)(`return ${name}Client.getIntegerState(state, '${stateValue.key}')`);
272
+ yield* indent(`return ${name}Client.getIntegerState(state, '${stateValue.key}')`);
302
273
  }
303
274
  else {
304
- yield* (0, writer_1.indent)(`return ${name}Client.getBinaryState(state, '${stateValue.key}')`);
275
+ yield* indent(`return ${name}Client.getBinaryState(state, '${stateValue.key}')`);
305
276
  }
306
277
  yield '},';
307
278
  }
308
- yield writer_1.DecIndentAndCloseBlock;
309
- yield writer_1.DecIndentAndCloseBlock;
310
- yield writer_1.NewLine;
279
+ yield DecIndentAndCloseBlock;
280
+ yield DecIndentAndCloseBlock;
281
+ yield NewLine;
311
282
  }
312
- if (localStateValues === null || localStateValues === void 0 ? void 0 : localStateValues.length) {
313
- yield* (0, writer_1.jsDoc)({
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 writer_1.IncIndent;
291
+ yield IncIndent;
321
292
  yield `const state = await this.appClient.getLocalState(account)`;
322
293
  yield `return {`;
323
- yield writer_1.IncIndent;
294
+ yield IncIndent;
324
295
  for (const stateValue of localStateValues) {
325
296
  yield `get ${stateValue.key}() {`;
326
297
  if (stateValue.type === 'uint64') {
327
- yield* (0, writer_1.indent)(`return ${name}Client.getIntegerState(state, '${stateValue.key}')`);
298
+ yield* indent(`return ${name}Client.getIntegerState(state, '${stateValue.key}')`);
328
299
  }
329
300
  else {
330
- yield* (0, writer_1.indent)(`return ${name}Client.getBinaryState(state, '${stateValue.key}')`);
301
+ yield* indent(`return ${name}Client.getBinaryState(state, '${stateValue.key}')`);
331
302
  }
332
303
  yield '},';
333
304
  }
334
- yield writer_1.DecIndentAndCloseBlock;
335
- yield writer_1.DecIndentAndCloseBlock;
336
- yield writer_1.NewLine;
305
+ yield DecIndentAndCloseBlock;
306
+ yield DecIndentAndCloseBlock;
307
+ yield NewLine;
337
308
  }
338
309
  }
339
- //# sourceMappingURL=call-client.js.map
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;
@@ -1,4 +1,3 @@
1
1
  import { DocumentParts } from '../output/writer';
2
2
  import { GeneratorContext } from './generator-context';
3
3
  export declare function callComposerType(ctx: GeneratorContext): DocumentParts;
4
- //# sourceMappingURL=call-composer-types.d.ts.map