@algorandfoundation/algokit-client-generator 3.0.6 → 4.0.0-alpha.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 (96) hide show
  1. package/README.md +4 -2
  2. package/cli.d.ts +6 -0
  3. package/cli.js +47 -16
  4. package/cli.js.map +1 -1
  5. package/cli.mjs +47 -17
  6. package/cli.mjs.map +1 -1
  7. package/client/{call-factory.d.ts → app-client.d.ts} +1 -1
  8. package/client/app-client.js +345 -0
  9. package/client/app-client.js.map +1 -0
  10. package/client/app-client.mjs +343 -0
  11. package/client/app-client.mjs.map +1 -0
  12. package/client/{call-client.d.ts → app-factory.d.ts} +1 -1
  13. package/client/app-factory.js +252 -0
  14. package/client/app-factory.js.map +1 -0
  15. package/client/app-factory.mjs +250 -0
  16. package/client/app-factory.mjs.map +1 -0
  17. package/client/app-types.js +206 -112
  18. package/client/app-types.js.map +1 -1
  19. package/client/app-types.mjs +210 -97
  20. package/client/app-types.mjs.map +1 -1
  21. package/client/call-composer-types.js +27 -57
  22. package/client/call-composer-types.js.map +1 -1
  23. package/client/call-composer-types.mjs +27 -38
  24. package/client/call-composer-types.mjs.map +1 -1
  25. package/client/call-composer.js +47 -59
  26. package/client/call-composer.js.map +1 -1
  27. package/client/call-composer.mjs +49 -42
  28. package/client/call-composer.mjs.map +1 -1
  29. package/client/deploy-types.d.ts +8 -4
  30. package/client/deploy-types.js +52 -34
  31. package/client/deploy-types.js.map +1 -1
  32. package/client/deploy-types.mjs +53 -36
  33. package/client/deploy-types.mjs.map +1 -1
  34. package/client/generate.d.ts +2 -2
  35. package/client/generate.js +18 -7
  36. package/client/generate.js.map +1 -1
  37. package/client/generate.mjs +18 -7
  38. package/client/generate.mjs.map +1 -1
  39. package/client/generator-context.d.ts +4 -4
  40. package/client/generator-context.js +5 -24
  41. package/client/generator-context.js.map +1 -1
  42. package/client/generator-context.mjs +5 -5
  43. package/client/generator-context.mjs.map +1 -1
  44. package/client/helpers/get-call-config-summary.d.ts +8 -3
  45. package/client/helpers/get-call-config-summary.js +22 -20
  46. package/client/helpers/get-call-config-summary.js.map +1 -1
  47. package/client/helpers/get-call-config-summary.mjs +22 -20
  48. package/client/helpers/get-call-config-summary.mjs.map +1 -1
  49. package/client/helpers/get-equivalent-type.d.ts +6 -1
  50. package/client/helpers/get-equivalent-type.js +20 -10
  51. package/client/helpers/get-equivalent-type.js.map +1 -1
  52. package/client/helpers/get-equivalent-type.mjs +20 -10
  53. package/client/helpers/get-equivalent-type.mjs.map +1 -1
  54. package/client/imports.js +21 -24
  55. package/client/imports.js.map +1 -1
  56. package/client/imports.mjs +21 -24
  57. package/client/imports.mjs.map +1 -1
  58. package/client/params-factory.d.ts +3 -0
  59. package/client/params-factory.js +126 -0
  60. package/client/params-factory.js.map +1 -0
  61. package/client/params-factory.mjs +124 -0
  62. package/client/params-factory.mjs.map +1 -0
  63. package/client/utility-types.d.ts +0 -7
  64. package/client/utility-types.js +37 -50
  65. package/client/utility-types.js.map +1 -1
  66. package/client/utility-types.mjs +38 -50
  67. package/client/utility-types.mjs.map +1 -1
  68. package/output/writer.d.ts +5 -5
  69. package/output/writer.js +26 -6
  70. package/output/writer.js.map +1 -1
  71. package/output/writer.mjs +26 -6
  72. package/output/writer.mjs.map +1 -1
  73. package/package.json +7 -5
  74. package/schema/application.schema.json.js +2 -2
  75. package/schema/application.schema.json.mjs +2 -2
  76. package/schema/arc56.schema.json.js +751 -0
  77. package/schema/arc56.schema.json.js.map +1 -0
  78. package/schema/arc56.schema.json.mjs +741 -0
  79. package/schema/arc56.schema.json.mjs.map +1 -0
  80. package/schema/load.d.ts +3 -3
  81. package/schema/load.js +28 -8
  82. package/schema/load.js.map +1 -1
  83. package/schema/load.mjs +29 -9
  84. package/schema/load.mjs.map +1 -1
  85. package/util/sanitization.js +13 -8
  86. package/util/sanitization.js.map +1 -1
  87. package/util/sanitization.mjs +13 -8
  88. package/util/sanitization.mjs.map +1 -1
  89. package/client/call-client.js +0 -341
  90. package/client/call-client.js.map +0 -1
  91. package/client/call-client.mjs +0 -320
  92. package/client/call-client.mjs.map +0 -1
  93. package/client/call-factory.js +0 -142
  94. package/client/call-factory.js.map +0 -1
  95. package/client/call-factory.mjs +0 -121
  96. package/client/call-factory.mjs.map +0 -1
@@ -1,139 +1,252 @@
1
- import { jsDoc, IncIndent, DecIndentAndCloseBlock, inline, DecIndent, NewLine } from '../output/writer.mjs';
2
- import * as algokit from '@algorandfoundation/algokit-utils';
1
+ import { jsDoc, IncIndent, DecIndentAndCloseBlock, inline, NewLine, DecIndent, indent } from '../output/writer.mjs';
3
2
  import { getEquivalentType } from './helpers/get-equivalent-type.mjs';
3
+ import algosdk, { ABIMethod } from 'algosdk';
4
4
 
5
+ function getMethodMetadata(method, ctx) {
6
+ const { methodSignatureToUniqueName } = ctx;
7
+ const methodSig = new ABIMethod(method).getSignature();
8
+ const uniqueName = methodSignatureToUniqueName[methodSig];
9
+ let hasAppCallArgToTheRight = false;
10
+ const argsMeta = new Array();
11
+ for (let i = (method.args ?? []).length - 1; i >= 0; i--) {
12
+ const arg = method.args[i];
13
+ argsMeta.push({
14
+ ...arg,
15
+ name: arg.name ?? `arg${i + 1}`,
16
+ isOptional: !!arg.defaultValue || (hasAppCallArgToTheRight && algosdk.abiTypeIsTransaction(arg.type)),
17
+ tsType: getEquivalentType(arg.struct ?? arg.type, 'input', ctx),
18
+ });
19
+ if (!hasAppCallArgToTheRight &&
20
+ algosdk.abiTypeIsTransaction(arg.type) &&
21
+ [algosdk.ABITransactionType.appl, algosdk.ABITransactionType.any].includes(arg.type)) {
22
+ hasAppCallArgToTheRight = true;
23
+ }
24
+ }
25
+ argsMeta.reverse();
26
+ return { methodSig, uniqueName, argsMeta };
27
+ }
5
28
  function* appTypes(ctx) {
6
- const { app, methodSignatureToUniqueName, name } = ctx;
29
+ yield* structTypes(ctx);
30
+ yield* templateVariableTypes(ctx);
31
+ const { app, name } = ctx;
32
+ yield* jsDoc(`The argument types for the ${name} contract`);
33
+ yield `export type ${name}Args = {`;
34
+ yield IncIndent;
35
+ yield* jsDoc('The object representation of the arguments for each method');
36
+ yield 'obj: {';
37
+ yield IncIndent;
38
+ for (const method of app.methods) {
39
+ const { methodSig, argsMeta } = getMethodMetadata(method, ctx);
40
+ if (argsMeta.length) {
41
+ yield `'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': {`;
42
+ yield IncIndent;
43
+ for (const arg of argsMeta) {
44
+ if (arg.desc)
45
+ yield* jsDoc(arg.desc);
46
+ yield `${ctx.sanitizer.makeSafePropertyIdentifier(arg.name)}${arg.isOptional ? '?' : ''}: ${arg.tsType}`;
47
+ }
48
+ yield DecIndentAndCloseBlock;
49
+ }
50
+ else {
51
+ yield `'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': Record<string, never>`;
52
+ }
53
+ }
54
+ yield DecIndentAndCloseBlock;
55
+ yield* jsDoc('The tuple representation of the arguments for each method');
56
+ yield 'tuple: {';
57
+ yield IncIndent;
58
+ for (const method of app.methods) {
59
+ const { methodSig, argsMeta } = getMethodMetadata(method, ctx);
60
+ yield* inline(`'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': [`, argsMeta
61
+ .map((arg) => `${ctx.sanitizer.makeSafeVariableIdentifier(arg.name)}: ${arg.tsType}${arg.isOptional ? ' | undefined' : ''}`)
62
+ .join(', '), ']');
63
+ }
64
+ yield DecIndentAndCloseBlock;
65
+ yield DecIndentAndCloseBlock;
66
+ yield NewLine;
67
+ yield* jsDoc('The return type for each method');
68
+ yield `export type ${name}Returns = {`;
69
+ yield IncIndent;
70
+ for (const method of app.methods) {
71
+ const { methodSig } = getMethodMetadata(method, ctx);
72
+ yield* inline(`'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': ${getEquivalentType(method.returns.struct ?? method.returns.type ?? 'void', 'output', ctx)}`);
73
+ }
74
+ yield DecIndentAndCloseBlock;
75
+ yield NewLine;
7
76
  yield* jsDoc(`Defines the types of available calls and state of the ${name} smart contract.`);
8
- yield `export type ${name} = {`;
77
+ yield `export type ${name}Types = {`;
9
78
  yield IncIndent;
10
79
  yield* jsDoc('Maps method signatures / names to their argument and return types.');
11
- if (app.contract.methods.length == 0) {
80
+ if (app.methods.length == 0) {
12
81
  yield 'methods: {}';
13
82
  }
14
83
  else {
15
84
  yield 'methods:';
16
85
  }
17
86
  yield IncIndent;
18
- for (const method of app.contract.methods) {
19
- const methodSig = algokit.getABIMethodSignature(method);
20
- const methodSigSafe = ctx.sanitizer.makeSafeStringTypeLiteral(methodSig);
21
- const uniqueName = methodSignatureToUniqueName[methodSig];
22
- const uniqueNameSafe = ctx.sanitizer.makeSafeStringTypeLiteral(uniqueName);
23
- yield `& Record<'${methodSigSafe}'${methodSig !== uniqueName ? ` | '${uniqueNameSafe}'` : ''}, {`;
87
+ for (const method of app.methods) {
88
+ const { methodSig, uniqueName } = getMethodMetadata(method, ctx);
89
+ yield `& Record<'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}'${methodSig !== uniqueName ? ` | '${ctx.sanitizer.makeSafeStringTypeLiteral(uniqueName)}'` : ''}, {`;
24
90
  yield IncIndent;
25
- yield `argsObj: {`;
26
- yield IncIndent;
27
- const argsMeta = method.args.map((arg) => ({
28
- ...arg,
29
- hasDefault: app.hints?.[methodSig]?.default_arguments?.[arg.name],
30
- tsType: getEquivalentType(arg.type, 'input'),
31
- }));
32
- for (const arg of argsMeta) {
33
- if (arg.desc)
34
- yield* jsDoc(arg.desc);
35
- yield `${ctx.sanitizer.makeSafePropertyIdentifier(arg.name)}${arg.hasDefault ? '?' : ''}: ${arg.tsType}`;
36
- }
37
- yield DecIndentAndCloseBlock;
38
- yield* inline(`argsTuple: [`, argsMeta
39
- .map((arg) => `${ctx.sanitizer.makeSafeVariableIdentifier(arg.name)}: ${getEquivalentType(arg.type, 'input')}${arg.hasDefault ? ' | undefined' : ''}`)
40
- .join(', '), ']');
41
- const outputStruct = ctx.app.hints?.[methodSig]?.structs?.output;
91
+ yield `argsObj: ${name}Args['obj']['${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}']`;
92
+ yield `argsTuple: ${name}Args['tuple']['${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}']`;
42
93
  if (method.returns.desc)
43
94
  yield* jsDoc(method.returns.desc);
44
- if (outputStruct) {
45
- yield `returns: ${ctx.sanitizer.makeSafeTypeIdentifier(outputStruct.name)}`;
46
- }
47
- else {
48
- yield `returns: ${getEquivalentType(method.returns.type ?? 'void', 'output')}`;
49
- }
95
+ yield `returns: ${name}Returns['${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}']`;
50
96
  yield DecIndent;
51
97
  yield '}>';
52
98
  }
53
99
  yield DecIndent;
54
- yield* appState(ctx);
100
+ const hasLocal = (app.state.keys.local && Object.keys(app.state.keys.local).length > 0) ||
101
+ (app.state.maps.local && Object.keys(app.state.maps.local).length > 0);
102
+ const hasGlobal = (app.state.keys.global && Object.keys(app.state.keys.global).length > 0) ||
103
+ (app.state.maps.global && Object.keys(app.state.maps.global).length > 0);
104
+ const hasBox = (app.state.keys.box && Object.keys(app.state.keys.box).length > 0) || (app.state.maps.box && Object.keys(app.state.maps.box).length > 0);
105
+ yield* appState(ctx, { hasBox, hasGlobal, hasLocal });
55
106
  yield DecIndentAndCloseBlock;
56
- yield* jsDoc('Defines the possible abi call signatures');
57
- yield `export type ${name}Sig = keyof ${name}['methods']`;
58
- yield* jsDoc('Defines an object containing all relevant parameters for a single call to the contract. Where TSignature is undefined, a' +
59
- ' bare call is made');
60
- yield `export type TypedCallParams<TSignature extends ${name}Sig | undefined> = {`;
61
- yield IncIndent;
62
- yield 'method: TSignature';
63
- yield 'methodArgs: TSignature extends undefined ? undefined : Array<ABIAppCallArg | undefined>';
64
- yield DecIndent;
65
- yield '} & AppClientCallCoreParams & CoreAppCallArgs';
66
- yield* jsDoc('Defines the arguments required for a bare call');
67
- yield `export type BareCallArgs = Omit<RawAppCallArgs, keyof CoreAppCallArgs>`;
68
- yield* structs(ctx);
69
- yield* jsDoc(`Maps a method signature from the ${name} smart contract to the method's arguments in either tuple of struct form`);
70
- yield `export type MethodArgs<TSignature extends ${name}Sig> = ${name}['methods'][TSignature]['argsObj' | 'argsTuple']`;
71
- yield* jsDoc(`Maps a method signature from the ${name} smart contract to the method's return type`);
72
- yield `export type MethodReturn<TSignature extends ${name}Sig> = ${name}['methods'][TSignature]['returns']`;
73
107
  yield NewLine;
108
+ yield `
109
+ /**
110
+ * Defines the possible abi call signatures.
111
+ */
112
+ export type ${name}Signatures = keyof ${name}Types['methods']
113
+ /**
114
+ * Defines the possible abi call signatures for methods that return a non-void value.
115
+ */
116
+ export type ${name}NonVoidMethodSignatures = keyof ${name}Types['methods'] extends infer T ? T extends keyof ${name}Types['methods'] ? MethodReturn<T> extends void ? never : T : never : never
117
+ /**
118
+ * Defines an object containing all relevant parameters for a single call to the contract.
119
+ */
120
+ export type CallParams<TArgs> = Expand<
121
+ Omit<AppClientMethodCallParams, 'method' | 'args' | 'onComplete'> &
122
+ {
123
+ /** The args for the ABI method call, either as an ordered array or an object */
124
+ args: Expand<TArgs>
125
+ }
126
+ >
127
+ /**
128
+ * Maps a method signature from the ${name} smart contract to the method's arguments in either tuple or struct form
129
+ */
130
+ export type MethodArgs<TSignature extends ${name}Signatures> = ${name}Types['methods'][TSignature]['argsObj' | 'argsTuple']
131
+ /**
132
+ * Maps a method signature from the ${name} smart contract to the method's return type
133
+ */
134
+ export type MethodReturn<TSignature extends ${name}Signatures> = ${name}Types['methods'][TSignature]['returns']
135
+ `;
136
+ if (hasGlobal) {
137
+ yield `
138
+ /**
139
+ * Defines the shape of the keyed global state of the application.
140
+ */
141
+ export type GlobalKeysState = ${name}Types['state']['global']['keys']
142
+ `;
143
+ }
144
+ if (hasLocal) {
145
+ yield `
146
+ /**
147
+ * Defines the shape of the keyed local state of the application.
148
+ */
149
+ export type LocalKeysState = ${name}Types['state']['local']['keys']
150
+ `;
151
+ }
152
+ if (hasBox) {
153
+ yield `
154
+ /**
155
+ * Defines the shape of the keyed box state of the application.
156
+ */
157
+ export type BoxKeysState = ${name}Types['state']['box']['keys']
158
+ `;
159
+ }
160
+ yield NewLine;
161
+ }
162
+ /* eslint-disable @typescript-eslint/no-explicit-any */
163
+ function getStructAsObject(struct, ctx) {
164
+ return Object.fromEntries(struct.map((s) => [s.name, typeof s.type === 'string' ? getEquivalentType(s.type, 'output', ctx) : getStructAsObject(s.type, ctx)]));
74
165
  }
75
- function* structs({ app, sanitizer }) {
76
- if (app.hints === undefined)
166
+ function getStructAsTupleTypes(struct, ctx) {
167
+ return `[${struct.map((s) => (Array.isArray(s.type) ? getStructAsTupleTypes(s.type, ctx) : getEquivalentType(s.type, 'output', ctx))).join(', ')}]`;
168
+ }
169
+ function* structTypes(ctx) {
170
+ const { app, sanitizer } = ctx;
171
+ if (Object.keys(app.structs).length === 0)
77
172
  return;
78
- const definedStructs = new Set();
79
- for (const methodHint of Object.values(app.hints)) {
80
- if (methodHint.structs === undefined)
81
- continue;
82
- for (const struct of Object.values(methodHint.structs)) {
83
- if (definedStructs.has(struct.name))
84
- continue;
85
- definedStructs.add(struct.name);
86
- yield* jsDoc(`Represents a ${struct.name} result as a struct`);
87
- yield `export type ${sanitizer.makeSafeTypeIdentifier(struct.name)} = {`;
88
- yield IncIndent;
89
- for (const [key, type] of struct.elements) {
90
- yield `${sanitizer.makeSafePropertyIdentifier(key)}: ${getEquivalentType(type, 'output')}`;
173
+ yield '// Type definitions for ARC-56 structs';
174
+ yield NewLine;
175
+ for (const structName of Object.keys(app.structs)) {
176
+ // Emit the struct type
177
+ yield `export type ${sanitizer.makeSafeTypeIdentifier(structName)} = ${JSON.stringify(getStructAsObject(app.structs[structName], ctx), null, 2).replace(/"/g, '')}`;
178
+ yield NewLine;
179
+ // Emit method that converts ABI tuple to the struct object
180
+ yield* jsDoc(`Converts the ABI tuple representation of a ${structName} to the struct representation`);
181
+ yield* inline(`export function ${sanitizer.makeSafeTypeIdentifier(structName)}FromTuple(`, `abiTuple: ${getStructAsTupleTypes(app.structs[structName], ctx)}`, `) {`);
182
+ yield* indent(`return getABIStructFromABITuple(abiTuple, APP_SPEC.structs${sanitizer.getSafeMemberAccessor(structName)}, APP_SPEC.structs) as ${sanitizer.makeSafeTypeIdentifier(structName)}`);
183
+ yield '}';
184
+ yield NewLine;
185
+ }
186
+ }
187
+ function* templateVariableTypes(ctx) {
188
+ if (Object.keys(ctx.app.templateVariables ?? {}).length === 0) {
189
+ return;
190
+ }
191
+ yield* jsDoc('Deploy-time template variables');
192
+ yield 'export type TemplateVariables = {';
193
+ yield IncIndent;
194
+ for (const name of Object.keys(ctx.app.templateVariables ?? {})) {
195
+ yield `${name}: ${getEquivalentType(ctx.app.templateVariables[name].type, 'output', ctx)},`;
196
+ }
197
+ yield DecIndentAndCloseBlock;
198
+ yield NewLine;
199
+ }
200
+ function* keysAndMaps(app, sanitizer, keys, maps) {
201
+ if (keys && Object.keys(keys).length) {
202
+ yield 'keys: {';
203
+ yield IncIndent;
204
+ for (const name of Object.keys(keys)) {
205
+ const prop = keys[name];
206
+ if (prop.desc) {
207
+ yield* jsDoc(prop.desc);
91
208
  }
92
- yield DecIndentAndCloseBlock;
93
- yield* jsDoc(`Converts the tuple representation of a ${struct.name} to the struct representation`);
94
- yield* inline(`export function ${sanitizer.makeSafeTypeIdentifier(struct.name)}(`, `[${struct.elements.map(([key]) => sanitizer.makeSafeVariableIdentifier(key)).join(', ')}]: `, `[${struct.elements.map(([_, type]) => getEquivalentType(type, 'output')).join(', ')}] ) {`);
95
- yield IncIndent;
96
- yield `return {`;
97
- yield IncIndent;
98
- for (const [key] of struct.elements) {
99
- const prop = sanitizer.makeSafePropertyIdentifier(key);
100
- const param = sanitizer.makeSafeVariableIdentifier(key);
101
- yield `${prop}${prop !== param ? `: ${param}` : ''},`;
209
+ const keySafe = sanitizer.makeSafePropertyIdentifier(name);
210
+ yield `${keySafe}: ${prop.valueType === 'AVMBytes' ? 'BinaryState' : getEquivalentType(prop.valueType, 'output', { app, sanitizer })}`;
211
+ }
212
+ yield DecIndentAndCloseBlock;
213
+ }
214
+ if (maps && Object.keys(maps).length) {
215
+ yield 'maps: {';
216
+ yield IncIndent;
217
+ for (const name of Object.keys(maps)) {
218
+ const prop = maps[name];
219
+ if (prop.desc) {
220
+ yield* jsDoc(prop.desc);
102
221
  }
103
- yield DecIndentAndCloseBlock;
104
- yield DecIndentAndCloseBlock;
222
+ const keySafe = sanitizer.makeSafePropertyIdentifier(name);
223
+ yield `${keySafe}: Map<${getEquivalentType(prop.keyType, 'input', { app, sanitizer })}, ${getEquivalentType(prop.valueType, 'output', { app, sanitizer })}>`;
105
224
  }
225
+ yield DecIndentAndCloseBlock;
106
226
  }
107
227
  }
108
- function* appState({ app, sanitizer }) {
109
- const hasLocal = app.schema.local?.declared && Object.keys(app.schema.local.declared).length;
110
- const hasGlobal = app.schema.global?.declared && Object.keys(app.schema.global.declared).length;
228
+ function* appState({ app, sanitizer }, stateFlags) {
229
+ const { hasBox, hasGlobal, hasLocal } = stateFlags;
111
230
  if (hasLocal || hasGlobal) {
112
- yield* jsDoc('Defines the shape of the global and local state of the application.');
231
+ yield* jsDoc('Defines the shape of the state of the application.');
113
232
  yield 'state: {';
114
233
  yield IncIndent;
115
234
  if (hasGlobal) {
116
235
  yield 'global: {';
117
236
  yield IncIndent;
118
- for (const prop of Object.values(app.schema.global.declared)) {
119
- if (prop.descr) {
120
- yield* jsDoc(prop.descr);
121
- }
122
- const keySafe = sanitizer.makeSafePropertyIdentifier(prop.key);
123
- yield `${keySafe}?: ${prop.type === 'uint64' ? 'IntegerState' : 'BinaryState'}`;
124
- }
237
+ yield* keysAndMaps(app, sanitizer, app.state.keys.global, app.state.maps.global);
125
238
  yield DecIndentAndCloseBlock;
126
239
  }
127
240
  if (hasLocal) {
128
241
  yield 'local: {';
129
242
  yield IncIndent;
130
- for (const prop of Object.values(app.schema.local.declared)) {
131
- if (prop.descr) {
132
- yield* jsDoc(prop.descr);
133
- }
134
- const keySafe = sanitizer.makeSafePropertyIdentifier(prop.key);
135
- yield `${keySafe}?: ${prop.type === 'uint64' ? 'IntegerState' : 'BinaryState'}`;
136
- }
243
+ yield* keysAndMaps(app, sanitizer, app.state.keys.local, app.state.maps.local);
244
+ yield DecIndentAndCloseBlock;
245
+ }
246
+ if (hasBox) {
247
+ yield 'box: {';
248
+ yield IncIndent;
249
+ yield* keysAndMaps(app, sanitizer, app.state.keys.box, app.state.maps.box);
137
250
  yield DecIndentAndCloseBlock;
138
251
  }
139
252
  yield DecIndentAndCloseBlock;
@@ -1 +1 @@
1
- {"version":3,"file":"app-types.mjs","sources":["../../src/client/app-types.ts"],"sourcesContent":["import { GeneratorContext } from './generator-context'\nimport { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, inline, jsDoc, NewLine } from '../output/writer'\nimport * as algokit from '@algorandfoundation/algokit-utils'\nimport { getEquivalentType } from './helpers/get-equivalent-type'\n\nexport function* appTypes(ctx: GeneratorContext): DocumentParts {\n const { app, methodSignatureToUniqueName, name } = ctx\n yield* jsDoc(`Defines the types of available calls and state of the ${name} smart contract.`)\n yield `export type ${name} = {`\n yield IncIndent\n yield* jsDoc('Maps method signatures / names to their argument and return types.')\n if (app.contract.methods.length == 0) {\n yield 'methods: {}'\n } else {\n yield 'methods:'\n }\n yield IncIndent\n for (const method of app.contract.methods) {\n const methodSig = algokit.getABIMethodSignature(method)\n const methodSigSafe = ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)\n const uniqueName = methodSignatureToUniqueName[methodSig]\n const uniqueNameSafe = ctx.sanitizer.makeSafeStringTypeLiteral(uniqueName)\n yield `& Record<'${methodSigSafe}'${methodSig !== uniqueName ? ` | '${uniqueNameSafe}'` : ''}, {`\n yield IncIndent\n yield `argsObj: {`\n yield IncIndent\n\n const argsMeta = method.args.map((arg) => ({\n ...arg,\n hasDefault: app.hints?.[methodSig]?.default_arguments?.[arg.name],\n tsType: getEquivalentType(arg.type, 'input'),\n }))\n\n for (const arg of argsMeta) {\n if (arg.desc) yield* jsDoc(arg.desc)\n yield `${ctx.sanitizer.makeSafePropertyIdentifier(arg.name)}${arg.hasDefault ? '?' : ''}: ${arg.tsType}`\n }\n yield DecIndentAndCloseBlock\n yield* inline(\n `argsTuple: [`,\n argsMeta\n .map(\n (arg) =>\n `${ctx.sanitizer.makeSafeVariableIdentifier(arg.name)}: ${getEquivalentType(arg.type, 'input')}${arg.hasDefault ? ' | undefined' : ''}`,\n )\n .join(', '),\n ']',\n )\n const outputStruct = ctx.app.hints?.[methodSig]?.structs?.output\n if (method.returns.desc) yield* jsDoc(method.returns.desc)\n if (outputStruct) {\n yield `returns: ${ctx.sanitizer.makeSafeTypeIdentifier(outputStruct.name)}`\n } else {\n yield `returns: ${getEquivalentType(method.returns.type ?? 'void', 'output')}`\n }\n\n yield DecIndent\n yield '}>'\n }\n yield DecIndent\n yield* appState(ctx)\n yield DecIndentAndCloseBlock\n\n yield* jsDoc('Defines the possible abi call signatures')\n yield `export type ${name}Sig = keyof ${name}['methods']`\n yield* jsDoc(\n 'Defines an object containing all relevant parameters for a single call to the contract. Where TSignature is undefined, a' +\n ' bare call is made',\n )\n yield `export type TypedCallParams<TSignature extends ${name}Sig | undefined> = {`\n yield IncIndent\n yield 'method: TSignature'\n yield 'methodArgs: TSignature extends undefined ? undefined : Array<ABIAppCallArg | undefined>'\n yield DecIndent\n yield '} & AppClientCallCoreParams & CoreAppCallArgs'\n yield* jsDoc('Defines the arguments required for a bare call')\n yield `export type BareCallArgs = Omit<RawAppCallArgs, keyof CoreAppCallArgs>`\n\n yield* structs(ctx)\n yield* jsDoc(`Maps a method signature from the ${name} smart contract to the method's arguments in either tuple of struct form`)\n yield `export type MethodArgs<TSignature extends ${name}Sig> = ${name}['methods'][TSignature]['argsObj' | 'argsTuple']`\n yield* jsDoc(`Maps a method signature from the ${name} smart contract to the method's return type`)\n yield `export type MethodReturn<TSignature extends ${name}Sig> = ${name}['methods'][TSignature]['returns']`\n yield NewLine\n}\n\nfunction* structs({ app, sanitizer }: GeneratorContext): DocumentParts {\n if (app.hints === undefined) return\n const definedStructs = new Set()\n\n for (const methodHint of Object.values(app.hints)) {\n if (methodHint.structs === undefined) continue\n for (const struct of Object.values(methodHint.structs)) {\n if (definedStructs.has(struct.name)) continue\n definedStructs.add(struct.name)\n\n yield* jsDoc(`Represents a ${struct.name} result as a struct`)\n yield `export type ${sanitizer.makeSafeTypeIdentifier(struct.name)} = {`\n yield IncIndent\n for (const [key, type] of struct.elements) {\n yield `${sanitizer.makeSafePropertyIdentifier(key)}: ${getEquivalentType(type, 'output')}`\n }\n yield DecIndentAndCloseBlock\n yield* jsDoc(`Converts the tuple representation of a ${struct.name} to the struct representation`)\n yield* inline(\n `export function ${sanitizer.makeSafeTypeIdentifier(struct.name)}(`,\n `[${struct.elements.map(([key]) => sanitizer.makeSafeVariableIdentifier(key)).join(', ')}]: `,\n `[${struct.elements.map(([_, type]) => getEquivalentType(type, 'output')).join(', ')}] ) {`,\n )\n yield IncIndent\n yield `return {`\n yield IncIndent\n for (const [key] of struct.elements) {\n const prop = sanitizer.makeSafePropertyIdentifier(key)\n const param = sanitizer.makeSafeVariableIdentifier(key)\n yield `${prop}${prop !== param ? `: ${param}` : ''},`\n }\n yield DecIndentAndCloseBlock\n yield DecIndentAndCloseBlock\n }\n }\n}\n\nfunction* appState({ app, sanitizer }: GeneratorContext): DocumentParts {\n const hasLocal = app.schema.local?.declared && Object.keys(app.schema.local.declared).length\n const hasGlobal = app.schema.global?.declared && Object.keys(app.schema.global.declared).length\n if (hasLocal || hasGlobal) {\n yield* jsDoc('Defines the shape of the global and local state of the application.')\n yield 'state: {'\n yield IncIndent\n if (hasGlobal) {\n yield 'global: {'\n yield IncIndent\n for (const prop of Object.values(app.schema.global!.declared!)) {\n if (prop.descr) {\n yield* jsDoc(prop.descr)\n }\n const keySafe = sanitizer.makeSafePropertyIdentifier(prop.key)\n\n yield `${keySafe}?: ${prop.type === 'uint64' ? 'IntegerState' : 'BinaryState'}`\n }\n yield DecIndentAndCloseBlock\n }\n if (hasLocal) {\n yield 'local: {'\n yield IncIndent\n for (const prop of Object.values(app.schema.local!.declared!)) {\n if (prop.descr) {\n yield* jsDoc(prop.descr)\n }\n const keySafe = sanitizer.makeSafePropertyIdentifier(prop.key)\n\n yield `${keySafe}?: ${prop.type === 'uint64' ? 'IntegerState' : 'BinaryState'}`\n }\n yield DecIndentAndCloseBlock\n }\n\n yield DecIndentAndCloseBlock\n }\n}\n"],"names":[],"mappings":";;;;AAKe,UAAE,QAAQ,CAAC,GAAqB,EAAA;IAC7C,MAAM,EAAE,GAAG,EAAE,2BAA2B,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;IACtD,OAAO,KAAK,CAAC,yDAAyD,IAAI,CAAA,gBAAA,CAAkB,CAAC,CAAA;IAC7F,MAAM,CAAA,YAAA,EAAe,IAAI,CAAA,IAAA,CAAM,CAAA;AAC/B,IAAA,MAAM,SAAS,CAAA;AACf,IAAA,OAAO,KAAK,CAAC,oEAAoE,CAAC,CAAA;IAClF,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE;AACpC,QAAA,MAAM,aAAa,CAAA;KACpB;SAAM;AACL,QAAA,MAAM,UAAU,CAAA;KACjB;AACD,IAAA,MAAM,SAAS,CAAA;IACf,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE;QACzC,MAAM,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;QACvD,MAAM,aAAa,GAAG,GAAG,CAAC,SAAS,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAA;AACxE,QAAA,MAAM,UAAU,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAA;QACzD,MAAM,cAAc,GAAG,GAAG,CAAC,SAAS,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAA;AAC1E,QAAA,MAAM,aAAa,aAAa,CAAA,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SAAS,CAAA;AACf,YAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAM,CAAC,QAAS,CAAC,EAAE;AAC7D,gBAAA,IAAI,IAAI,CAAC,KAAK,EAAE;oBACd,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;iBACzB;gBACD,MAAM,OAAO,GAAG,SAAS,CAAC,0BAA0B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9D,gBAAA,MAAM,GAAG,OAAO,CAAA,GAAA,EAAM,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG,cAAc,GAAG,aAAa,EAAE,CAAA;aAChF;AACD,YAAA,MAAM,sBAAsB,CAAA;SAC7B;AAED,QAAA,MAAM,sBAAsB,CAAA;KAC7B;AACH;;;;"}
1
+ {"version":3,"file":"app-types.mjs","sources":["../../src/client/app-types.ts"],"sourcesContent":["import { GeneratorContext } from './generator-context'\nimport { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, indent, inline, jsDoc, NewLine } from '../output/writer'\nimport { getEquivalentType } from './helpers/get-equivalent-type'\nimport algosdk, { ABIMethod } from 'algosdk'\nimport { Arc56Contract, Method, StorageKey, StorageMap, StructField } from '@algorandfoundation/algokit-utils/types/app-arc56'\nimport { Sanitizer } from '../util/sanitization'\nimport { Expand } from '@algorandfoundation/algokit-utils/types/expand'\n\nfunction getMethodMetadata(method: Method, ctx: GeneratorContext) {\n const { methodSignatureToUniqueName } = ctx\n const methodSig = new ABIMethod(method).getSignature()\n const uniqueName = methodSignatureToUniqueName[methodSig]\n\n let hasAppCallArgToTheRight = false\n const argsMeta = new Array<Expand<Omit<(typeof method.args)[0], 'name'> & { name: string; isOptional: boolean; tsType: string }>>()\n\n for (let i = (method.args ?? []).length - 1; i >= 0; i--) {\n const arg = method.args[i]\n\n argsMeta.push({\n ...arg,\n name: arg.name ?? `arg${i + 1}`,\n isOptional: !!arg.defaultValue || (hasAppCallArgToTheRight && algosdk.abiTypeIsTransaction(arg.type)),\n tsType: getEquivalentType(arg.struct ?? arg.type, 'input', ctx),\n })\n\n if (\n !hasAppCallArgToTheRight &&\n algosdk.abiTypeIsTransaction(arg.type) &&\n [algosdk.ABITransactionType.appl, algosdk.ABITransactionType.any].includes(arg.type)\n ) {\n hasAppCallArgToTheRight = true\n }\n }\n argsMeta.reverse()\n\n return { methodSig, uniqueName, argsMeta }\n}\n\nexport function* appTypes(ctx: GeneratorContext): DocumentParts {\n yield* structTypes(ctx)\n yield* templateVariableTypes(ctx)\n\n const { app, name } = ctx\n\n yield* jsDoc(`The argument types for the ${name} contract`)\n yield `export type ${name}Args = {`\n yield IncIndent\n yield* jsDoc('The object representation of the arguments for each method')\n yield 'obj: {'\n yield IncIndent\n for (const method of app.methods) {\n const { methodSig, argsMeta } = getMethodMetadata(method, ctx)\n if (argsMeta.length) {\n yield `'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': {`\n yield IncIndent\n for (const arg of argsMeta) {\n if (arg.desc) yield* jsDoc(arg.desc)\n yield `${ctx.sanitizer.makeSafePropertyIdentifier(arg.name)}${arg.isOptional ? '?' : ''}: ${arg.tsType}`\n }\n yield DecIndentAndCloseBlock\n } else {\n yield `'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': Record<string, never>`\n }\n }\n yield DecIndentAndCloseBlock\n\n yield* jsDoc('The tuple representation of the arguments for each method')\n yield 'tuple: {'\n yield IncIndent\n for (const method of app.methods) {\n const { methodSig, argsMeta } = getMethodMetadata(method, ctx)\n yield* inline(\n `'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': [`,\n argsMeta\n .map((arg) => `${ctx.sanitizer.makeSafeVariableIdentifier(arg.name)}: ${arg.tsType}${arg.isOptional ? ' | undefined' : ''}`)\n .join(', '),\n ']',\n )\n }\n yield DecIndentAndCloseBlock\n\n yield DecIndentAndCloseBlock\n yield NewLine\n\n yield* jsDoc('The return type for each method')\n yield `export type ${name}Returns = {`\n yield IncIndent\n for (const method of app.methods) {\n const { methodSig } = getMethodMetadata(method, ctx)\n yield* inline(\n `'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}': ${getEquivalentType(method.returns.struct ?? method.returns.type ?? 'void', 'output', ctx)}`,\n )\n }\n yield DecIndentAndCloseBlock\n yield NewLine\n\n yield* jsDoc(`Defines the types of available calls and state of the ${name} smart contract.`)\n yield `export type ${name}Types = {`\n yield IncIndent\n yield* jsDoc('Maps method signatures / names to their argument and return types.')\n if (app.methods.length == 0) {\n yield 'methods: {}'\n } else {\n yield 'methods:'\n }\n yield IncIndent\n for (const method of app.methods) {\n const { methodSig, uniqueName } = getMethodMetadata(method, ctx)\n yield `& Record<'${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}'${methodSig !== uniqueName ? ` | '${ctx.sanitizer.makeSafeStringTypeLiteral(uniqueName)}'` : ''}, {`\n yield IncIndent\n yield `argsObj: ${name}Args['obj']['${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}']`\n yield `argsTuple: ${name}Args['tuple']['${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}']`\n\n if (method.returns.desc) yield* jsDoc(method.returns.desc)\n yield `returns: ${name}Returns['${ctx.sanitizer.makeSafeStringTypeLiteral(methodSig)}']`\n\n yield DecIndent\n yield '}>'\n }\n yield DecIndent\n\n const hasLocal =\n (app.state.keys.local && Object.keys(app.state.keys.local).length > 0) ||\n (app.state.maps.local && Object.keys(app.state.maps.local).length > 0)\n const hasGlobal =\n (app.state.keys.global && Object.keys(app.state.keys.global).length > 0) ||\n (app.state.maps.global && Object.keys(app.state.maps.global).length > 0)\n const hasBox =\n (app.state.keys.box && Object.keys(app.state.keys.box).length > 0) || (app.state.maps.box && Object.keys(app.state.maps.box).length > 0)\n yield* appState(ctx, { hasBox, hasGlobal, hasLocal })\n\n yield DecIndentAndCloseBlock\n yield NewLine\n\n yield `\n /**\n * Defines the possible abi call signatures.\n */\n export type ${name}Signatures = keyof ${name}Types['methods']\n /**\n * Defines the possible abi call signatures for methods that return a non-void value.\n */\n export type ${name}NonVoidMethodSignatures = keyof ${name}Types['methods'] extends infer T ? T extends keyof ${name}Types['methods'] ? MethodReturn<T> extends void ? never : T : never : never\n /**\n * Defines an object containing all relevant parameters for a single call to the contract.\n */\n export type CallParams<TArgs> = Expand<\n Omit<AppClientMethodCallParams, 'method' | 'args' | 'onComplete'> &\n {\n /** The args for the ABI method call, either as an ordered array or an object */\n args: Expand<TArgs>\n }\n >\n /**\n * Maps a method signature from the ${name} smart contract to the method's arguments in either tuple or struct form\n */\n export type MethodArgs<TSignature extends ${name}Signatures> = ${name}Types['methods'][TSignature]['argsObj' | 'argsTuple']\n /**\n * Maps a method signature from the ${name} smart contract to the method's return type\n */\n export type MethodReturn<TSignature extends ${name}Signatures> = ${name}Types['methods'][TSignature]['returns']\n `\n\n if (hasGlobal) {\n yield `\n /**\n * Defines the shape of the keyed global state of the application.\n */\n export type GlobalKeysState = ${name}Types['state']['global']['keys']\n `\n }\n\n if (hasLocal) {\n yield `\n /**\n * Defines the shape of the keyed local state of the application.\n */\n export type LocalKeysState = ${name}Types['state']['local']['keys']\n `\n }\n\n if (hasBox) {\n yield `\n /**\n * Defines the shape of the keyed box state of the application.\n */\n export type BoxKeysState = ${name}Types['state']['box']['keys']\n `\n }\n\n yield NewLine\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nfunction getStructAsObject(struct: StructField[], ctx: GeneratorContext): Record<string, any> {\n return Object.fromEntries(\n struct.map((s) => [s.name, typeof s.type === 'string' ? getEquivalentType(s.type, 'output', ctx) : getStructAsObject(s.type, ctx)]),\n )\n}\n\nfunction getStructAsTupleTypes(struct: StructField[], ctx: GeneratorContext): string {\n return `[${struct.map((s) => (Array.isArray(s.type) ? getStructAsTupleTypes(s.type, ctx) : getEquivalentType(s.type, 'output', ctx))).join(', ')}]`\n}\n\nfunction* structTypes(ctx: GeneratorContext): DocumentParts {\n const { app, sanitizer } = ctx\n if (Object.keys(app.structs).length === 0) return\n\n yield '// Type definitions for ARC-56 structs'\n yield NewLine\n\n for (const structName of Object.keys(app.structs)) {\n // Emit the struct type\n\n yield `export type ${sanitizer.makeSafeTypeIdentifier(structName)} = ${JSON.stringify(getStructAsObject(app.structs[structName], ctx), null, 2).replace(/\"/g, '')}`\n yield NewLine\n\n // Emit method that converts ABI tuple to the struct object\n yield* jsDoc(`Converts the ABI tuple representation of a ${structName} to the struct representation`)\n yield* inline(\n `export function ${sanitizer.makeSafeTypeIdentifier(structName)}FromTuple(`,\n `abiTuple: ${getStructAsTupleTypes(app.structs[structName], ctx)}`,\n `) {`,\n )\n yield* indent(\n `return getABIStructFromABITuple(abiTuple, APP_SPEC.structs${sanitizer.getSafeMemberAccessor(structName)}, APP_SPEC.structs) as ${sanitizer.makeSafeTypeIdentifier(structName)}`,\n )\n yield '}'\n yield NewLine\n }\n}\n\nfunction* templateVariableTypes(ctx: GeneratorContext): DocumentParts {\n if (Object.keys(ctx.app.templateVariables ?? {}).length === 0) {\n return\n }\n\n yield* jsDoc('Deploy-time template variables')\n yield 'export type TemplateVariables = {'\n yield IncIndent\n\n for (const name of Object.keys(ctx.app.templateVariables ?? {})) {\n yield `${name}: ${getEquivalentType(ctx.app.templateVariables![name].type, 'output', ctx)},`\n }\n\n yield DecIndentAndCloseBlock\n yield NewLine\n}\n\nfunction* keysAndMaps(\n app: Arc56Contract,\n sanitizer: Sanitizer,\n keys: {\n [name: string]: StorageKey\n },\n maps: {\n [name: string]: StorageMap\n },\n): DocumentParts {\n if (keys && Object.keys(keys).length) {\n yield 'keys: {'\n yield IncIndent\n for (const name of Object.keys(keys)) {\n const prop = keys[name]\n if (prop.desc) {\n yield* jsDoc(prop.desc)\n }\n const keySafe = sanitizer.makeSafePropertyIdentifier(name)\n\n yield `${keySafe}: ${prop.valueType === 'AVMBytes' ? 'BinaryState' : getEquivalentType(prop.valueType, 'output', { app, sanitizer })}`\n }\n yield DecIndentAndCloseBlock\n }\n\n if (maps && Object.keys(maps).length) {\n yield 'maps: {'\n yield IncIndent\n for (const name of Object.keys(maps)) {\n const prop = maps[name]\n if (prop.desc) {\n yield* jsDoc(prop.desc)\n }\n const keySafe = sanitizer.makeSafePropertyIdentifier(name)\n\n yield `${keySafe}: Map<${getEquivalentType(prop.keyType, 'input', { app, sanitizer })}, ${getEquivalentType(prop.valueType, 'output', { app, sanitizer })}>`\n }\n yield DecIndentAndCloseBlock\n }\n}\n\nfunction* appState(\n { app, sanitizer }: GeneratorContext,\n stateFlags: { hasLocal: boolean; hasGlobal: boolean; hasBox: boolean },\n): DocumentParts {\n const { hasBox, hasGlobal, hasLocal } = stateFlags\n\n if (hasLocal || hasGlobal) {\n yield* jsDoc('Defines the shape of the state of the application.')\n yield 'state: {'\n yield IncIndent\n if (hasGlobal) {\n yield 'global: {'\n yield IncIndent\n yield* keysAndMaps(app, sanitizer, app.state.keys.global, app.state.maps.global)\n yield DecIndentAndCloseBlock\n }\n if (hasLocal) {\n yield 'local: {'\n yield IncIndent\n yield* keysAndMaps(app, sanitizer, app.state.keys.local, app.state.maps.local)\n yield DecIndentAndCloseBlock\n }\n if (hasBox) {\n yield 'box: {'\n yield IncIndent\n yield* keysAndMaps(app, sanitizer, app.state.keys.box, app.state.maps.box)\n yield DecIndentAndCloseBlock\n }\n yield DecIndentAndCloseBlock\n }\n}\n"],"names":[],"mappings":";;;;AAQA,SAAS,iBAAiB,CAAC,MAAc,EAAE,GAAqB,EAAA;AAC9D,IAAA,MAAM,EAAE,2BAA2B,EAAE,GAAG,GAAG,CAAA;IAC3C,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,CAAA;AACtD,IAAA,MAAM,UAAU,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAA;IAEzD,IAAI,uBAAuB,GAAG,KAAK,CAAA;AACnC,IAAA,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAyG,CAAA;IAEnI,KAAK,IAAI,CA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E,EAAA;IAEtE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAA;AAElD,IAAA,IAAI,QAAQ,IAAI,SAAS,EAAE;AACzB,QAAA,OAAO,KAAK,CAAC,oDAAoD,CAAC,CAAA;AAClE,QAAA,MAAM,UAAU,CAAA;AAChB,QAAA,MAAM,SAAS,CAAA;QACf,IAAI,SAAS,EAAE;AACb,YAAA,MAAM,WAAW,CAAA;AACjB,YAAA,MAAM,SAAS,CAAA;YACf,OAAO,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAChF,YAAA,MAAM,sBAAsB,CAAA;SAC7B;QACD,IAAI,QAAQ,EAAE;AACZ,YAAA,MAAM,UAAU,CAAA;AAChB,YAAA,MAAM,SAAS,CAAA;YACf,OAAO,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC9E,YAAA,MAAM,sBAAsB,CAAA;SAC7B;QACD,IAAI,MAAM,EAAE;AACV,YAAA,MAAM,QAAQ,CAAA;AACd,YAAA,MAAM,SAAS,CAAA;YACf,OAAO,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC1E,YAAA,MAAM,sBAAsB,CAAA;SAC7B;AACD,QAAA,MAAM,sBAAsB,CAAA;KAC7B;AACH;;;;"}
@@ -1,97 +1,67 @@
1
1
  'use strict';
2
2
 
3
3
  var writer = require('../output/writer.js');
4
- var algokit = require('@algorandfoundation/algokit-utils');
5
4
  var getCallConfigSummary = require('./helpers/get-call-config-summary.js');
6
5
  var deployTypes = require('./deploy-types.js');
7
-
8
- function _interopNamespaceDefault(e) {
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n.default = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var algokit__namespace = /*#__PURE__*/_interopNamespaceDefault(algokit);
6
+ var algosdk = require('algosdk');
26
7
 
27
8
  function* callComposerType(ctx) {
28
9
  const { name, callConfig, app } = ctx;
29
10
  yield `export type ${name}Composer<TReturns extends [...any[]] = []> = {`;
30
11
  yield writer.IncIndent;
31
12
  yield* callComposerTypeNoops(ctx);
32
- yield* callComposerOperationMethodType(ctx, `Updates an existing instance of the ${app.contract.name} smart contract`, callConfig.updateMethods, 'update', true);
33
- yield* callComposerOperationMethodType(ctx, `Deletes an existing instance of the ${app.contract.name} smart contract`, callConfig.deleteMethods, 'delete');
34
- yield* callComposerOperationMethodType(ctx, `Opts the user into an existing instance of the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn');
35
- yield* callComposerOperationMethodType(ctx, `Makes a close out call to an existing instance of the ${app.contract.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
13
+ yield* callComposerOperationMethodType(ctx, `Deletes an existing instance of the ${app.name} smart contract`, callConfig.deleteMethods, 'delete');
14
+ yield* callComposerOperationMethodType(ctx, `Opts the user into an existing instance of the ${app.name} smart contract`, callConfig.optInMethods, 'optIn');
15
+ yield* callComposerOperationMethodType(ctx, `Makes a close out call to an existing instance of the ${app.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
36
16
  yield* callComposerTypeClearState(ctx);
37
17
  yield* writer.jsDoc({
38
18
  description: 'Adds a transaction to the composer',
39
19
  params: {
40
- 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)',
41
- defaultSender: 'The default sender to be used to obtain a signer where the object provided to the transaction parameter does not' +
42
- ' include a signer.',
20
+ txn: 'A transaction to add to the transaction group',
21
+ signer: 'The optional signer to use when signing this transaction.',
43
22
  },
44
23
  });
45
- yield `addTransaction(txn: TransactionWithSigner | TransactionToSign | Transaction | Promise<SendTransactionResult>, defaultSender?: SendTransactionFrom): ${name}Composer<TReturns>`;
24
+ yield `addTransaction(txn: Transaction, signer?: TransactionSigner): ${name}Composer<TReturns>`;
46
25
  yield* writer.jsDoc({
47
26
  description: 'Returns the underlying AtomicTransactionComposer instance',
48
27
  });
49
- yield `atc(): Promise<AtomicTransactionComposer>`;
28
+ yield `composer(): TransactionComposer`;
50
29
  yield* writer.jsDoc({
51
30
  description: 'Simulates the transaction group and returns the result',
52
31
  });
53
- yield `simulate(options?: SimulateOptions): Promise<${name}ComposerSimulateResult<TReturns>>`;
32
+ yield `simulate(options?: SimulateOptions): Promise<${name}ComposerResults<TReturns> & { simulateResponse: SimulateResponse }>`;
54
33
  yield* writer.jsDoc({
55
- description: 'Executes the transaction group and returns the results',
34
+ description: 'Sends the transaction group to the network and returns the results',
56
35
  });
57
- yield `execute(sendParams?: AppClientComposeExecuteParams): Promise<${name}ComposerResults<TReturns>>`;
58
- yield writer.DecIndentAndCloseBlock;
59
- yield `export type SimulateOptions = Omit<ConstructorParameters<typeof modelsv2.SimulateRequest>[0], 'txnGroups'>`;
60
- yield `export type ${name}ComposerSimulateResult<TReturns extends [...any[]]> = {`;
61
- yield writer.IncIndent;
62
- yield `returns: TReturns`;
63
- yield `methodResults: ABIResult[]`;
64
- yield `simulateResponse: modelsv2.SimulateResponse`;
65
- yield writer.DecIndentAndCloseBlock;
66
- yield `export type ${name}ComposerResults<TReturns extends [...any[]]> = {`;
67
- yield writer.IncIndent;
68
- yield `returns: TReturns`;
69
- yield `groupId: string`;
70
- yield `txIds: string[]`;
71
- yield `transactions: Transaction[]`;
36
+ yield `send(params?: SendParams): Promise<${name}ComposerResults<TReturns>>`;
72
37
  yield writer.DecIndentAndCloseBlock;
38
+ yield `
39
+ export type ${name}ComposerResults<TReturns extends [...any[]]> = Expand<SendAtomicTransactionComposerResults & {
40
+ returns: TReturns
41
+ }>
42
+ `;
73
43
  }
74
44
  function* callComposerTypeClearState({ app, name }) {
75
45
  yield* writer.jsDoc({
76
- description: `Makes a clear_state call to an existing instance of the ${app.contract.name} smart contract.`,
46
+ description: `Makes a clear_state call to an existing instance of the ${app.name} smart contract.`,
77
47
  params: {
78
48
  args: `The arguments for the bare call`,
79
49
  },
80
50
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
81
51
  });
82
- yield `clearState(args?: BareCallArgs & AppClientComposeCallCoreParams & CoreAppCallArgs): ${name}Composer<[...TReturns, undefined]>`;
52
+ yield `clearState(params?: AppClientBareCallParams): ${name}Composer<[...TReturns, undefined]>`;
83
53
  yield writer.NewLine;
84
54
  }
85
55
  function* callComposerTypeNoops({ app, name, callConfig, methodSignatureToUniqueName, sanitizer }) {
86
- for (const method of app.contract.methods) {
87
- const methodSignature = algokit__namespace.getABIMethodSignature(method);
88
- const methodSignatureSafe = sanitizer.makeSafeStringTypeLiteral(methodSignature);
89
- const methodName = sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]);
56
+ for (const method of app.methods) {
57
+ const methodSig = new algosdk.ABIMethod(method).getSignature();
58
+ const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig);
59
+ const methodName = sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSig]);
90
60
  // Skip methods which don't support a no_op call config
91
- if (!callConfig.callMethods.includes(methodSignature))
61
+ if (!callConfig.callMethods.includes(methodSig))
92
62
  continue;
93
63
  yield* writer.jsDoc({
94
- description: `Calls the ${algokit__namespace.getABIMethodSignature(method)} ABI method.`,
64
+ description: `Calls the ${new algosdk.ABIMethod(method).getSignature()} ABI method.`,
95
65
  abiDescription: method.desc,
96
66
  params: {
97
67
  args: `The arguments for the contract call`,
@@ -99,7 +69,7 @@ function* callComposerTypeNoops({ app, name, callConfig, methodSignatureToUnique
99
69
  },
100
70
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
101
71
  });
102
- yield `${methodName}(args: MethodArgs<'${methodSignatureSafe}'>, params?: AppClientComposeCallCoreParams & CoreAppCallArgs): ${name}Composer<[...TReturns, MethodReturn<'${methodSignatureSafe}'>]>`;
72
+ yield `${methodName}(params?: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']>): ${name}Composer<[...TReturns, ${name}Returns['${methodSigSafe}'] | undefined]>`;
103
73
  yield writer.NewLine;
104
74
  }
105
75
  }
@@ -118,7 +88,7 @@ function* callComposerOperationMethodType({ app, methodSignatureToUniqueName, na
118
88
  },
119
89
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
120
90
  });
121
- yield `bare(args${onComplete?.isOptional !== false ? '?' : ''}: BareCallArgs & AppClientComposeCallCoreParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}& CoreAppCallArgs${onComplete?.type ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, undefined]>`;
91
+ yield `bare(params${onComplete?.isOptional !== false ? '?' : ''}: AppClientBareCallParams ${''}): ${name}Composer<[...TReturns, undefined]>`;
122
92
  }
123
93
  else {
124
94
  const uniqueName = methodSignatureToUniqueName[methodSig];
@@ -131,7 +101,7 @@ function* callComposerOperationMethodType({ app, methodSignatureToUniqueName, na
131
101
  returns: `The typed transaction composer so you can fluently chain multiple calls or call execute to execute all queued up transactions`,
132
102
  });
133
103
  const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig);
134
- yield `${sanitizer.makeSafeMethodIdentifier(uniqueName)}(args: MethodArgs<'${methodSigSafe}'>, params${onComplete?.isOptional !== false ? '?' : ''}: AppClientComposeCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, MethodReturn<'${methodSigSafe}'>]>`;
104
+ yield `${sanitizer.makeSafeMethodIdentifier(uniqueName)}(params${onComplete?.isOptional !== false ? '?' : ''}: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']>${''}${onComplete?.type ? ` & ${onComplete.type}` : ''}): ${name}Composer<[...TReturns, ${name}Returns['${methodSigSafe}'] | undefined]>`;
135
105
  }
136
106
  }
137
107
  yield writer.DecIndentAndCloseBlock;