@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,45 +1,20 @@
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.callComposerType = void 0;
27
- const writer_1 = require("../output/writer");
28
- const algokit = __importStar(require("@algorandfoundation/algokit-utils"));
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");
1
+ import { IncIndent, jsDoc, DecIndentAndCloseBlock, NewLine } from '../output/writer.mjs';
2
+ import * as algokit from '@algorandfoundation/algokit-utils';
3
+ import { makeSafeMethodIdentifier } from '../util/sanitization.mjs';
4
+ import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
5
+ import { getCreateOnCompleteOptions } from './deploy-types.mjs';
6
+
32
7
  function* callComposerType(ctx) {
33
8
  const { name, callConfig, app } = ctx;
34
9
  yield `export type ${name}Composer<TReturns extends [...any[]] = []> = {`;
35
- yield writer_1.IncIndent;
10
+ yield IncIndent;
36
11
  yield* callComposerTypeNoops(ctx);
37
12
  yield* callComposerOperationMethodType(ctx, `Updates an existing instance of the ${app.contract.name} smart contract`, callConfig.updateMethods, 'update', true);
38
13
  yield* callComposerOperationMethodType(ctx, `Deletes an existing instance of the ${app.contract.name} smart contract`, callConfig.deleteMethods, 'delete');
39
14
  yield* callComposerOperationMethodType(ctx, `Opts the user into an existing instance of the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn');
40
15
  yield* callComposerOperationMethodType(ctx, `Makes a close out call to an existing instance of the ${app.contract.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
41
16
  yield* callComposerTypeClearState(ctx);
42
- yield* (0, writer_1.jsDoc)({
17
+ yield* jsDoc({
43
18
  description: 'Adds a transaction to the composer',
44
19
  params: {
45
20
  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)',
@@ -48,37 +23,36 @@ function* callComposerType(ctx) {
48
23
  },
49
24
  });
50
25
  yield `addTransaction(txn: TransactionWithSigner | TransactionToSign | Transaction | Promise<SendTransactionResult>, defaultSender?: SendTransactionFrom): ${name}Composer<TReturns>`;
51
- yield* (0, writer_1.jsDoc)({
26
+ yield* jsDoc({
52
27
  description: 'Returns the underlying AtomicTransactionComposer instance',
53
28
  });
54
29
  yield `atc(): Promise<AtomicTransactionComposer>`;
55
- yield* (0, writer_1.jsDoc)({
30
+ yield* jsDoc({
56
31
  description: 'Simulates the transaction group and returns the result',
57
32
  });
58
33
  yield `simulate(options?: SimulateOptions): Promise<${name}ComposerSimulateResult<TReturns>>`;
59
- yield* (0, writer_1.jsDoc)({
34
+ yield* jsDoc({
60
35
  description: 'Executes the transaction group and returns the results',
61
36
  });
62
37
  yield `execute(sendParams?: AppClientComposeExecuteParams): Promise<${name}ComposerResults<TReturns>>`;
63
- yield writer_1.DecIndentAndCloseBlock;
38
+ yield DecIndentAndCloseBlock;
64
39
  yield `export type SimulateOptions = Omit<ConstructorParameters<typeof modelsv2.SimulateRequest>[0], 'txnGroups'>`;
65
40
  yield `export type ${name}ComposerSimulateResult<TReturns extends [...any[]]> = {`;
66
- yield writer_1.IncIndent;
41
+ yield IncIndent;
67
42
  yield `returns: TReturns`;
68
43
  yield `methodResults: ABIResult[]`;
69
44
  yield `simulateResponse: modelsv2.SimulateResponse`;
70
- yield writer_1.DecIndentAndCloseBlock;
45
+ yield DecIndentAndCloseBlock;
71
46
  yield `export type ${name}ComposerResults<TReturns extends [...any[]]> = {`;
72
- yield writer_1.IncIndent;
47
+ yield IncIndent;
73
48
  yield `returns: TReturns`;
74
49
  yield `groupId: string`;
75
50
  yield `txIds: string[]`;
76
51
  yield `transactions: Transaction[]`;
77
- yield writer_1.DecIndentAndCloseBlock;
52
+ yield DecIndentAndCloseBlock;
78
53
  }
79
- exports.callComposerType = callComposerType;
80
54
  function* callComposerTypeClearState({ app, name }) {
81
- yield* (0, writer_1.jsDoc)({
55
+ yield* jsDoc({
82
56
  description: `Makes a clear_state call to an existing instance of the ${app.contract.name} smart contract.`,
83
57
  params: {
84
58
  args: `The arguments for the bare call`,
@@ -86,16 +60,16 @@ function* callComposerTypeClearState({ app, name }) {
86
60
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
87
61
  });
88
62
  yield `clearState(args?: BareCallArgs & AppClientComposeCallCoreParams & CoreAppCallArgs): ${name}Composer<[...TReturns, undefined]>`;
89
- yield writer_1.NewLine;
63
+ yield NewLine;
90
64
  }
91
65
  function* callComposerTypeNoops({ app, name, callConfig, methodSignatureToUniqueName }) {
92
66
  for (const method of app.contract.methods) {
93
67
  const methodSignature = algokit.getABIMethodSignature(method);
94
- const methodName = (0, sanitization_1.makeSafeMethodIdentifier)(methodSignatureToUniqueName[methodSignature]);
68
+ const methodName = makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]);
95
69
  // Skip methods which don't support a no_op call config
96
70
  if (!callConfig.callMethods.includes(methodSignature))
97
71
  continue;
98
- yield* (0, writer_1.jsDoc)({
72
+ yield* jsDoc({
99
73
  description: `Calls the ${algokit.getABIMethodSignature(method)} ABI method.`,
100
74
  abiDescription: method.desc,
101
75
  params: {
@@ -105,29 +79,29 @@ function* callComposerTypeNoops({ app, name, callConfig, methodSignatureToUnique
105
79
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
106
80
  });
107
81
  yield `${methodName}(args: MethodArgs<'${methodSignature}'>, params?: AppClientComposeCallCoreParams & CoreAppCallArgs): ${name}Composer<[...TReturns, MethodReturn<'${methodSignature}'>]>`;
108
- yield writer_1.NewLine;
82
+ yield NewLine;
109
83
  }
110
84
  }
111
85
  function* callComposerOperationMethodType({ app, methodSignatureToUniqueName, name }, description, methods, verb, includeCompilation) {
112
86
  if (methods.length) {
113
- yield* (0, writer_1.jsDoc)(`Gets available ${verb} methods`);
87
+ yield* jsDoc(`Gets available ${verb} methods`);
114
88
  yield `readonly ${verb}: {`;
115
- yield writer_1.IncIndent;
89
+ yield IncIndent;
116
90
  for (const methodSig of methods) {
117
- const onComplete = verb === 'create' ? (0, deploy_types_1.getCreateOnCompleteOptions)(methodSig, app) : undefined;
118
- if (methodSig === get_call_config_summary_1.BARE_CALL) {
119
- yield* (0, writer_1.jsDoc)({
91
+ const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined;
92
+ if (methodSig === BARE_CALL) {
93
+ yield* jsDoc({
120
94
  description: `${description} using a bare call.`,
121
95
  params: {
122
96
  args: `The arguments for the bare call`,
123
97
  },
124
98
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
125
99
  });
126
- yield `bare(args${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.isOptional) !== false ? '?' : ''}: BareCallArgs & AppClientComposeCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.type) ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, undefined]>`;
100
+ yield `bare(args${onComplete?.isOptional !== false ? '?' : ''}: BareCallArgs & AppClientComposeCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${onComplete?.type ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, undefined]>`;
127
101
  }
128
102
  else {
129
103
  const uniqueName = methodSignatureToUniqueName[methodSig];
130
- yield* (0, writer_1.jsDoc)({
104
+ yield* jsDoc({
131
105
  description: `${description} using the ${methodSig} ABI method.`,
132
106
  params: {
133
107
  args: `The arguments for the smart contract call`,
@@ -135,11 +109,12 @@ function* callComposerOperationMethodType({ app, methodSignatureToUniqueName, na
135
109
  },
136
110
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
137
111
  });
138
- yield `${(0, sanitization_1.makeSafeMethodIdentifier)(uniqueName)}(args: MethodArgs<'${methodSig}'>, params${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.isOptional) !== false ? '?' : ''}: AppClientComposeCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.type) ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, MethodReturn<'${methodSig}'>]>`;
112
+ yield `${makeSafeMethodIdentifier(uniqueName)}(args: MethodArgs<'${methodSig}'>, params${onComplete?.isOptional !== false ? '?' : ''}: AppClientComposeCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, MethodReturn<'${methodSig}'>]>`;
139
113
  }
140
114
  }
141
- yield writer_1.DecIndentAndCloseBlock;
142
- yield writer_1.NewLine;
115
+ yield DecIndentAndCloseBlock;
116
+ yield NewLine;
143
117
  }
144
118
  }
145
- //# sourceMappingURL=call-composer-types.js.map
119
+
120
+ export { callComposerType };
@@ -0,0 +1,145 @@
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* composeMethod(ctx) {
29
+ const { name, callConfig } = ctx;
30
+ yield `public compose(): ${name}Composer {`;
31
+ yield writer.IncIndent;
32
+ yield `const client = this`;
33
+ yield `const atc = new AtomicTransactionComposer()`;
34
+ yield `let promiseChain:Promise<unknown> = Promise.resolve()`;
35
+ yield `const resultMappers: Array<undefined | ((x: any) => any)> = []`;
36
+ yield `return {`;
37
+ yield writer.IncIndent;
38
+ yield* callComposerNoops(ctx);
39
+ yield* callComposerOperationMethods(ctx, callConfig.updateMethods, 'update', true);
40
+ yield* callComposerOperationMethods(ctx, callConfig.deleteMethods, 'delete');
41
+ yield* callComposerOperationMethods(ctx, callConfig.optInMethods, 'optIn');
42
+ yield* callComposerOperationMethods(ctx, callConfig.closeOutMethods, 'closeOut');
43
+ yield* callComposerClearState();
44
+ yield `addTransaction(txn: TransactionWithSigner | TransactionToSign | Transaction | Promise<SendTransactionResult>, defaultSender?: SendTransactionFrom) {`;
45
+ yield writer.IncIndent;
46
+ yield 'promiseChain = promiseChain.then(async () => atc.addTransaction(await algokit.getTransactionWithSigner(txn, defaultSender ??' +
47
+ ' client.sender)))';
48
+ yield 'return this';
49
+ yield writer.DecIndent;
50
+ yield '},';
51
+ yield `async atc() {`;
52
+ yield writer.IncIndent;
53
+ yield 'await promiseChain';
54
+ yield 'return atc';
55
+ yield writer.DecIndent;
56
+ yield '},';
57
+ yield `async simulate(options?: SimulateOptions) {`;
58
+ yield writer.IncIndent;
59
+ yield `await promiseChain`;
60
+ yield `const result = await atc.simulate(client.algod, new modelsv2.SimulateRequest({ txnGroups: [], ...options }))`;
61
+ yield `return {`;
62
+ yield writer.IncIndent;
63
+ yield `...result,`;
64
+ yield `returns: result.methodResults?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val.returnValue) : val.returnValue)`;
65
+ yield writer.DecIndentAndCloseBlock;
66
+ yield writer.DecIndent;
67
+ yield '},';
68
+ yield `async execute(sendParams?: AppClientComposeExecuteParams) {`;
69
+ yield writer.IncIndent;
70
+ yield `await promiseChain`;
71
+ yield `const result = await algokit.sendAtomicTransactionComposer({ atc, sendParams }, client.algod)`;
72
+ yield `return {`;
73
+ yield writer.IncIndent;
74
+ yield `...result,`;
75
+ yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val.returnValue) : val.returnValue)`;
76
+ yield writer.DecIndentAndCloseBlock;
77
+ yield writer.DecIndentAndCloseBlock;
78
+ yield writer.DecIndent;
79
+ yield `} as unknown as ${name}Composer`;
80
+ yield writer.DecIndentAndCloseBlock;
81
+ }
82
+ function* callComposerNoops({ app, callConfig, methodSignatureToUniqueName }) {
83
+ for (const method of app.contract.methods) {
84
+ const methodSignature = algokit__namespace.getABIMethodSignature(method);
85
+ const methodName = sanitization.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]);
86
+ // Skip methods which don't support a no_op call config
87
+ if (!callConfig.callMethods.includes(methodSignature))
88
+ continue;
89
+ yield `${methodName}(args: MethodArgs<'${methodSignature}'>, params?: AppClientComposeCallCoreParams & CoreAppCallArgs) {`;
90
+ yield writer.IncIndent;
91
+ yield `promiseChain = promiseChain.then(() => client.${methodName}(args, {...params, sendParams: {...params?.sendParams, skipSending: true, atc}}))`;
92
+ const outputTypeName = app.hints?.[methodSignature]?.structs?.output?.name;
93
+ yield `resultMappers.push(${outputTypeName ?? 'undefined'})`;
94
+ yield `return this`;
95
+ yield writer.DecIndent;
96
+ yield '},';
97
+ }
98
+ }
99
+ function* callComposerClearState() {
100
+ yield `clearState(args?: BareCallArgs & AppClientComposeCallCoreParams & CoreAppCallArgs) {`;
101
+ yield writer.IncIndent;
102
+ yield `promiseChain = promiseChain.then(() => client.clearState({...args, sendParams: {...args?.sendParams, skipSending: true, atc}}))`;
103
+ yield `resultMappers.push(undefined)`;
104
+ yield `return this`;
105
+ yield writer.DecIndent;
106
+ yield '},';
107
+ }
108
+ function* callComposerOperationMethods({ app, methodSignatureToUniqueName }, methods, verb, includeCompilation) {
109
+ if (methods.length) {
110
+ yield `get ${verb}() {`;
111
+ yield writer.IncIndent;
112
+ yield `const $this = this`;
113
+ yield `return {`;
114
+ yield writer.IncIndent;
115
+ for (const methodSig of methods) {
116
+ const onComplete = verb === 'create' ? deployTypes.getCreateOnCompleteOptions(methodSig, app) : undefined;
117
+ if (methodSig === getCallConfigSummary.BARE_CALL) {
118
+ yield `bare(args${onComplete?.isOptional !== false ? '?' : ''}: BareCallArgs & AppClientComposeCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${onComplete?.type ? ` & ${onComplete.type}` : ''}) {`;
119
+ yield writer.IncIndent;
120
+ yield `promiseChain = promiseChain.then(() => client.${verb}.bare({...args, sendParams: {...args?.sendParams, skipSending: true, atc}}))`;
121
+ yield `resultMappers.push(undefined)`;
122
+ yield `return $this`;
123
+ yield writer.DecIndent;
124
+ yield '},';
125
+ }
126
+ else {
127
+ const uniqueName = methodSignatureToUniqueName[methodSig];
128
+ const methodName = sanitization.makeSafeMethodIdentifier(uniqueName);
129
+ yield `${methodName}(args: MethodArgs<'${methodSig}'>, params${onComplete?.isOptional !== false ? '?' : ''}: AppClientComposeCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}) {`;
130
+ yield writer.IncIndent;
131
+ yield `promiseChain = promiseChain.then(() => client.${verb}.${methodName}(args, {...params, sendParams: {...params?.sendParams, skipSending: true, atc}}))`;
132
+ const outputTypeName = app.hints?.[methodSig]?.structs?.output?.name;
133
+ yield `resultMappers.push(${outputTypeName ?? 'undefined'})`;
134
+ yield `return $this`;
135
+ yield writer.DecIndent;
136
+ yield '},';
137
+ }
138
+ }
139
+ yield writer.DecIndentAndCloseBlock;
140
+ yield writer.DecIndent;
141
+ yield '},';
142
+ }
143
+ }
144
+
145
+ exports.composeMethod = composeMethod;
@@ -1,4 +1,3 @@
1
1
  import { DocumentParts } from '../output/writer';
2
2
  import { GeneratorContext } from './generator-context';
3
3
  export declare function composeMethod(ctx: GeneratorContext): DocumentParts;
4
- //# sourceMappingURL=call-composer.d.ts.map
@@ -0,0 +1,124 @@
1
+ import { IncIndent, DecIndent, DecIndentAndCloseBlock } from '../output/writer.mjs';
2
+ import * as algokit from '@algorandfoundation/algokit-utils';
3
+ import { makeSafeMethodIdentifier } from '../util/sanitization.mjs';
4
+ import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
5
+ import { getCreateOnCompleteOptions } from './deploy-types.mjs';
6
+
7
+ function* composeMethod(ctx) {
8
+ const { name, callConfig } = ctx;
9
+ yield `public compose(): ${name}Composer {`;
10
+ yield IncIndent;
11
+ yield `const client = this`;
12
+ yield `const atc = new AtomicTransactionComposer()`;
13
+ yield `let promiseChain:Promise<unknown> = Promise.resolve()`;
14
+ yield `const resultMappers: Array<undefined | ((x: any) => any)> = []`;
15
+ yield `return {`;
16
+ yield IncIndent;
17
+ yield* callComposerNoops(ctx);
18
+ yield* callComposerOperationMethods(ctx, callConfig.updateMethods, 'update', true);
19
+ yield* callComposerOperationMethods(ctx, callConfig.deleteMethods, 'delete');
20
+ yield* callComposerOperationMethods(ctx, callConfig.optInMethods, 'optIn');
21
+ yield* callComposerOperationMethods(ctx, callConfig.closeOutMethods, 'closeOut');
22
+ yield* callComposerClearState();
23
+ yield `addTransaction(txn: TransactionWithSigner | TransactionToSign | Transaction | Promise<SendTransactionResult>, defaultSender?: SendTransactionFrom) {`;
24
+ yield IncIndent;
25
+ yield 'promiseChain = promiseChain.then(async () => atc.addTransaction(await algokit.getTransactionWithSigner(txn, defaultSender ??' +
26
+ ' client.sender)))';
27
+ yield 'return this';
28
+ yield DecIndent;
29
+ yield '},';
30
+ yield `async atc() {`;
31
+ yield IncIndent;
32
+ yield 'await promiseChain';
33
+ yield 'return atc';
34
+ yield DecIndent;
35
+ yield '},';
36
+ yield `async simulate(options?: SimulateOptions) {`;
37
+ yield IncIndent;
38
+ yield `await promiseChain`;
39
+ yield `const result = await atc.simulate(client.algod, new modelsv2.SimulateRequest({ txnGroups: [], ...options }))`;
40
+ yield `return {`;
41
+ yield IncIndent;
42
+ yield `...result,`;
43
+ yield `returns: result.methodResults?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val.returnValue) : val.returnValue)`;
44
+ yield DecIndentAndCloseBlock;
45
+ yield DecIndent;
46
+ yield '},';
47
+ yield `async execute(sendParams?: AppClientComposeExecuteParams) {`;
48
+ yield IncIndent;
49
+ yield `await promiseChain`;
50
+ yield `const result = await algokit.sendAtomicTransactionComposer({ atc, sendParams }, client.algod)`;
51
+ yield `return {`;
52
+ yield IncIndent;
53
+ yield `...result,`;
54
+ yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val.returnValue) : val.returnValue)`;
55
+ yield DecIndentAndCloseBlock;
56
+ yield DecIndentAndCloseBlock;
57
+ yield DecIndent;
58
+ yield `} as unknown as ${name}Composer`;
59
+ yield DecIndentAndCloseBlock;
60
+ }
61
+ function* callComposerNoops({ app, callConfig, methodSignatureToUniqueName }) {
62
+ for (const method of app.contract.methods) {
63
+ const methodSignature = algokit.getABIMethodSignature(method);
64
+ const methodName = makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]);
65
+ // Skip methods which don't support a no_op call config
66
+ if (!callConfig.callMethods.includes(methodSignature))
67
+ continue;
68
+ yield `${methodName}(args: MethodArgs<'${methodSignature}'>, params?: AppClientComposeCallCoreParams & CoreAppCallArgs) {`;
69
+ yield IncIndent;
70
+ yield `promiseChain = promiseChain.then(() => client.${methodName}(args, {...params, sendParams: {...params?.sendParams, skipSending: true, atc}}))`;
71
+ const outputTypeName = app.hints?.[methodSignature]?.structs?.output?.name;
72
+ yield `resultMappers.push(${outputTypeName ?? 'undefined'})`;
73
+ yield `return this`;
74
+ yield DecIndent;
75
+ yield '},';
76
+ }
77
+ }
78
+ function* callComposerClearState() {
79
+ yield `clearState(args?: BareCallArgs & AppClientComposeCallCoreParams & CoreAppCallArgs) {`;
80
+ yield IncIndent;
81
+ yield `promiseChain = promiseChain.then(() => client.clearState({...args, sendParams: {...args?.sendParams, skipSending: true, atc}}))`;
82
+ yield `resultMappers.push(undefined)`;
83
+ yield `return this`;
84
+ yield DecIndent;
85
+ yield '},';
86
+ }
87
+ function* callComposerOperationMethods({ app, methodSignatureToUniqueName }, methods, verb, includeCompilation) {
88
+ if (methods.length) {
89
+ yield `get ${verb}() {`;
90
+ yield IncIndent;
91
+ yield `const $this = this`;
92
+ yield `return {`;
93
+ yield IncIndent;
94
+ for (const methodSig of methods) {
95
+ const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined;
96
+ if (methodSig === BARE_CALL) {
97
+ yield `bare(args${onComplete?.isOptional !== false ? '?' : ''}: BareCallArgs & AppClientComposeCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${onComplete?.type ? ` & ${onComplete.type}` : ''}) {`;
98
+ yield IncIndent;
99
+ yield `promiseChain = promiseChain.then(() => client.${verb}.bare({...args, sendParams: {...args?.sendParams, skipSending: true, atc}}))`;
100
+ yield `resultMappers.push(undefined)`;
101
+ yield `return $this`;
102
+ yield DecIndent;
103
+ yield '},';
104
+ }
105
+ else {
106
+ const uniqueName = methodSignatureToUniqueName[methodSig];
107
+ const methodName = makeSafeMethodIdentifier(uniqueName);
108
+ yield `${methodName}(args: MethodArgs<'${methodSig}'>, params${onComplete?.isOptional !== false ? '?' : ''}: AppClientComposeCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}) {`;
109
+ yield IncIndent;
110
+ yield `promiseChain = promiseChain.then(() => client.${verb}.${methodName}(args, {...params, sendParams: {...params?.sendParams, skipSending: true, atc}}))`;
111
+ const outputTypeName = app.hints?.[methodSig]?.structs?.output?.name;
112
+ yield `resultMappers.push(${outputTypeName ?? 'undefined'})`;
113
+ yield `return $this`;
114
+ yield DecIndent;
115
+ yield '},';
116
+ }
117
+ }
118
+ yield DecIndentAndCloseBlock;
119
+ yield DecIndent;
120
+ yield '},';
121
+ }
122
+ }
123
+
124
+ export { composeMethod };
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ var writer = require('../output/writer.cjs');
4
+ var sanitization = require('../util/sanitization.cjs');
5
+ var algokit = require('@algorandfoundation/algokit-utils');
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* callFactory(ctx) {
29
+ yield* writer.jsDoc('Exposes methods for constructing all available smart contract calls');
30
+ yield `export abstract class ${ctx.name}CallFactory {`;
31
+ yield writer.IncIndent;
32
+ yield* opMethods(ctx);
33
+ for (const method of ctx.app.contract.methods) {
34
+ yield* callFactoryMethod(ctx, method);
35
+ }
36
+ yield writer.DecIndent;
37
+ yield '}';
38
+ }
39
+ function* opMethods(ctx) {
40
+ const { app, callConfig } = ctx;
41
+ yield* operationMethod(ctx, `Constructs a create call for the ${app.contract.name} smart contract`, callConfig.createMethods, 'create', true);
42
+ yield* operationMethod(ctx, `Constructs an update call for the ${app.contract.name} smart contract`, callConfig.updateMethods, 'update', true);
43
+ yield* operationMethod(ctx, `Constructs a delete call for the ${app.contract.name} smart contract`, callConfig.deleteMethods, 'delete');
44
+ yield* operationMethod(ctx, `Constructs an opt in call for the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn');
45
+ yield* operationMethod(ctx, `Constructs a close out call for the ${app.contract.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
46
+ }
47
+ function* operationMethod({ app, methodSignatureToUniqueName }, description, methods, verb, includeCompilation) {
48
+ if (methods.length) {
49
+ yield* writer.jsDoc(`Gets available ${verb} call factories`);
50
+ yield `static get ${verb}() {`;
51
+ yield writer.IncIndent;
52
+ yield `return {`;
53
+ yield writer.IncIndent;
54
+ for (const methodSig of methods) {
55
+ const onComplete = verb === 'create' ? deployTypes.getCreateOnCompleteOptions(methodSig, app) : undefined;
56
+ if (methodSig === getCallConfigSummary.BARE_CALL) {
57
+ yield* writer.jsDoc({
58
+ description: `${description} using a bare call`,
59
+ params: {
60
+ params: `Any parameters for the call`,
61
+ },
62
+ returns: `A TypedCallParams object for the call`,
63
+ });
64
+ yield* factoryMethod({
65
+ isNested: true,
66
+ name: 'bare',
67
+ paramTypes: `BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
68
+ });
69
+ }
70
+ else {
71
+ const method = app.contract.methods.find((m) => algokit__namespace.getABIMethodSignature(m) === methodSig);
72
+ const uniqueName = methodSignatureToUniqueName[methodSig];
73
+ yield* writer.jsDoc({
74
+ description: `${description} using the ${methodSig} ABI method`,
75
+ params: {
76
+ args: `Any args for the contract call`,
77
+ params: `Any additional parameters for the call`,
78
+ },
79
+ returns: `A TypedCallParams object for the call`,
80
+ });
81
+ yield* factoryMethod({
82
+ isNested: true,
83
+ name: sanitization.makeSafeMethodIdentifier(uniqueName),
84
+ signature: methodSig,
85
+ args: method.args,
86
+ paramTypes: `AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
87
+ });
88
+ }
89
+ }
90
+ yield writer.DecIndentAndCloseBlock;
91
+ yield writer.DecIndentAndCloseBlock;
92
+ yield writer.NewLine;
93
+ }
94
+ }
95
+ function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method) {
96
+ const methodSignature = algokit__namespace.getABIMethodSignature(method);
97
+ if (!callConfig.callMethods.includes(methodSignature))
98
+ return;
99
+ yield* writer.jsDoc({
100
+ description: `Constructs a no op call for the ${methodSignature} ABI method`,
101
+ abiDescription: method.desc,
102
+ params: {
103
+ args: `Any args for the contract call`,
104
+ params: `Any additional parameters for the call`,
105
+ },
106
+ returns: `A TypedCallParams object for the call`,
107
+ });
108
+ yield* factoryMethod({
109
+ isNested: false,
110
+ name: sanitization.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]),
111
+ signature: methodSignature,
112
+ args: method.args,
113
+ paramTypes: 'AppClientCallCoreParams & CoreAppCallArgs',
114
+ });
115
+ }
116
+ function* factoryMethod({ isNested, name, signature, args, paramTypes, }) {
117
+ yield `${isNested ? '' : 'static '}${name}(${signature === undefined ? '' : `args: MethodArgs<'${signature}'>, `}params: ${paramTypes}) {`;
118
+ yield writer.IncIndent;
119
+ yield `return {`;
120
+ yield writer.IncIndent;
121
+ if (signature) {
122
+ yield `method: '${signature}' as const,`;
123
+ yield `methodArgs: Array.isArray(args) ? args : [${args
124
+ .map((a) => (sanitization.isSafeVariableIdentifier(a.name) ? `args.${a.name}` : `args['${sanitization.makeSafePropertyIdentifier(a.name)}']`))
125
+ .join(', ')}],`;
126
+ }
127
+ else {
128
+ yield `method: undefined,`;
129
+ yield `methodArgs: undefined,`;
130
+ }
131
+ yield '...params,';
132
+ yield writer.DecIndent;
133
+ yield '}';
134
+ yield writer.DecIndent;
135
+ yield `}${isNested ? ',' : ''}`;
136
+ }
137
+
138
+ exports.callFactory = callFactory;
@@ -1,4 +1,3 @@
1
1
  import { DocumentParts } from '../output/writer';
2
2
  import { GeneratorContext } from './generator-context';
3
3
  export declare function callFactory(ctx: GeneratorContext): DocumentParts;
4
- //# sourceMappingURL=call-factory.d.ts.map