@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.
- package/README.md +4 -2
- package/cli.d.ts +6 -0
- package/cli.js +47 -16
- package/cli.js.map +1 -1
- package/cli.mjs +47 -17
- package/cli.mjs.map +1 -1
- package/client/{call-factory.d.ts → app-client.d.ts} +1 -1
- package/client/app-client.js +345 -0
- package/client/app-client.js.map +1 -0
- package/client/app-client.mjs +343 -0
- package/client/app-client.mjs.map +1 -0
- package/client/{call-client.d.ts → app-factory.d.ts} +1 -1
- package/client/app-factory.js +252 -0
- package/client/app-factory.js.map +1 -0
- package/client/app-factory.mjs +250 -0
- package/client/app-factory.mjs.map +1 -0
- package/client/app-types.js +206 -112
- package/client/app-types.js.map +1 -1
- package/client/app-types.mjs +210 -97
- package/client/app-types.mjs.map +1 -1
- package/client/call-composer-types.js +27 -57
- package/client/call-composer-types.js.map +1 -1
- package/client/call-composer-types.mjs +27 -38
- package/client/call-composer-types.mjs.map +1 -1
- package/client/call-composer.js +47 -59
- package/client/call-composer.js.map +1 -1
- package/client/call-composer.mjs +49 -42
- package/client/call-composer.mjs.map +1 -1
- package/client/deploy-types.d.ts +8 -4
- package/client/deploy-types.js +52 -34
- package/client/deploy-types.js.map +1 -1
- package/client/deploy-types.mjs +53 -36
- package/client/deploy-types.mjs.map +1 -1
- package/client/generate.d.ts +2 -2
- package/client/generate.js +18 -7
- package/client/generate.js.map +1 -1
- package/client/generate.mjs +18 -7
- package/client/generate.mjs.map +1 -1
- package/client/generator-context.d.ts +4 -4
- package/client/generator-context.js +5 -24
- package/client/generator-context.js.map +1 -1
- package/client/generator-context.mjs +5 -5
- package/client/generator-context.mjs.map +1 -1
- package/client/helpers/get-call-config-summary.d.ts +8 -3
- package/client/helpers/get-call-config-summary.js +22 -20
- package/client/helpers/get-call-config-summary.js.map +1 -1
- package/client/helpers/get-call-config-summary.mjs +22 -20
- package/client/helpers/get-call-config-summary.mjs.map +1 -1
- package/client/helpers/get-equivalent-type.d.ts +6 -1
- package/client/helpers/get-equivalent-type.js +20 -10
- package/client/helpers/get-equivalent-type.js.map +1 -1
- package/client/helpers/get-equivalent-type.mjs +20 -10
- package/client/helpers/get-equivalent-type.mjs.map +1 -1
- package/client/imports.js +21 -24
- package/client/imports.js.map +1 -1
- package/client/imports.mjs +21 -24
- package/client/imports.mjs.map +1 -1
- package/client/params-factory.d.ts +3 -0
- package/client/params-factory.js +126 -0
- package/client/params-factory.js.map +1 -0
- package/client/params-factory.mjs +124 -0
- package/client/params-factory.mjs.map +1 -0
- package/client/utility-types.d.ts +0 -7
- package/client/utility-types.js +37 -50
- package/client/utility-types.js.map +1 -1
- package/client/utility-types.mjs +38 -50
- package/client/utility-types.mjs.map +1 -1
- package/output/writer.d.ts +5 -5
- package/output/writer.js +26 -6
- package/output/writer.js.map +1 -1
- package/output/writer.mjs +26 -6
- package/output/writer.mjs.map +1 -1
- package/package.json +7 -5
- package/schema/application.schema.json.js +2 -2
- package/schema/application.schema.json.mjs +2 -2
- package/schema/arc56.schema.json.js +751 -0
- package/schema/arc56.schema.json.js.map +1 -0
- package/schema/arc56.schema.json.mjs +741 -0
- package/schema/arc56.schema.json.mjs.map +1 -0
- package/schema/load.d.ts +3 -3
- package/schema/load.js +28 -8
- package/schema/load.js.map +1 -1
- package/schema/load.mjs +29 -9
- package/schema/load.mjs.map +1 -1
- package/util/sanitization.js +13 -8
- package/util/sanitization.js.map +1 -1
- package/util/sanitization.mjs +13 -8
- package/util/sanitization.mjs.map +1 -1
- package/client/call-client.js +0 -341
- package/client/call-client.js.map +0 -1
- package/client/call-client.mjs +0 -320
- package/client/call-client.mjs.map +0 -1
- package/client/call-factory.js +0 -142
- package/client/call-factory.js.map +0 -1
- package/client/call-factory.mjs +0 -121
- package/client/call-factory.mjs.map +0 -1
package/client/call-composer.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { IncIndent, DecIndent, DecIndentAndCloseBlock } from '../output/writer.mjs';
|
|
2
|
-
import * as algokit from '@algorandfoundation/algokit-utils';
|
|
1
|
+
import { IncIndent, DecIndent, DecIndentAndCloseBlock, jsDoc } from '../output/writer.mjs';
|
|
3
2
|
import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
|
|
4
|
-
import {
|
|
3
|
+
import { getCallOnCompleteOptions } from './deploy-types.mjs';
|
|
4
|
+
import { ABIMethod } from 'algosdk';
|
|
5
5
|
|
|
6
6
|
function* composeMethod(ctx) {
|
|
7
7
|
const { name, callConfig } = ctx;
|
|
8
|
-
|
|
8
|
+
// todo: Patrick feedback - allow common params to be passed in here so they propagate to all params calls e.g. firstValid
|
|
9
|
+
yield `public newGroup(): ${name}Composer {`;
|
|
9
10
|
yield IncIndent;
|
|
10
11
|
yield `const client = this`;
|
|
11
|
-
yield `const
|
|
12
|
+
yield `const composer = this.algorand.newGroup()`;
|
|
12
13
|
yield `let promiseChain:Promise<unknown> = Promise.resolve()`;
|
|
13
|
-
yield `const resultMappers: Array<undefined | ((x:
|
|
14
|
+
yield `const resultMappers: Array<undefined | ((x: ABIReturn | undefined) => any)> = []`;
|
|
14
15
|
yield `return {`;
|
|
15
16
|
yield IncIndent;
|
|
16
17
|
yield* callComposerNoops(ctx);
|
|
@@ -18,88 +19,94 @@ function* composeMethod(ctx) {
|
|
|
18
19
|
yield* callComposerOperationMethods(ctx, callConfig.deleteMethods, 'delete');
|
|
19
20
|
yield* callComposerOperationMethods(ctx, callConfig.optInMethods, 'optIn');
|
|
20
21
|
yield* callComposerOperationMethods(ctx, callConfig.closeOutMethods, 'closeOut');
|
|
21
|
-
yield* callComposerClearState();
|
|
22
|
-
yield `addTransaction(txn:
|
|
22
|
+
yield* callComposerClearState(ctx);
|
|
23
|
+
yield `addTransaction(txn: Transaction, signer?: TransactionSigner) {`;
|
|
23
24
|
yield IncIndent;
|
|
24
|
-
yield 'promiseChain = promiseChain.then(
|
|
25
|
-
' client.sender)))';
|
|
25
|
+
yield 'promiseChain = promiseChain.then(() => composer.addTransaction(txn, signer))';
|
|
26
26
|
yield 'return this';
|
|
27
27
|
yield DecIndent;
|
|
28
28
|
yield '},';
|
|
29
|
-
yield `async
|
|
29
|
+
yield `async composer() {`;
|
|
30
30
|
yield IncIndent;
|
|
31
|
-
yield
|
|
32
|
-
yield 'return
|
|
31
|
+
yield `await promiseChain`;
|
|
32
|
+
yield 'return composer';
|
|
33
33
|
yield DecIndent;
|
|
34
34
|
yield '},';
|
|
35
35
|
yield `async simulate(options?: SimulateOptions) {`;
|
|
36
36
|
yield IncIndent;
|
|
37
37
|
yield `await promiseChain`;
|
|
38
|
-
yield `const result = await
|
|
38
|
+
yield `const result = await composer.simulate(options)`;
|
|
39
39
|
yield `return {`;
|
|
40
40
|
yield IncIndent;
|
|
41
41
|
yield `...result,`;
|
|
42
|
-
yield `returns: result.
|
|
42
|
+
yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val) : val.returnValue)`;
|
|
43
43
|
yield DecIndentAndCloseBlock;
|
|
44
44
|
yield DecIndent;
|
|
45
45
|
yield '},';
|
|
46
|
-
yield `async
|
|
46
|
+
yield `async send(params?: SendParams) {`;
|
|
47
47
|
yield IncIndent;
|
|
48
48
|
yield `await promiseChain`;
|
|
49
|
-
yield `const result = await
|
|
49
|
+
yield `const result = await composer.send(params)`;
|
|
50
50
|
yield `return {`;
|
|
51
51
|
yield IncIndent;
|
|
52
52
|
yield `...result,`;
|
|
53
|
-
yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val
|
|
53
|
+
yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val) : val.returnValue)`;
|
|
54
54
|
yield DecIndentAndCloseBlock;
|
|
55
55
|
yield DecIndentAndCloseBlock;
|
|
56
56
|
yield DecIndent;
|
|
57
57
|
yield `} as unknown as ${name}Composer`;
|
|
58
58
|
yield DecIndentAndCloseBlock;
|
|
59
59
|
}
|
|
60
|
-
function* callComposerNoops({ app, callConfig, methodSignatureToUniqueName, sanitizer }) {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
function* callComposerNoops({ app, name, callConfig, methodSignatureToUniqueName, sanitizer }) {
|
|
61
|
+
if (callConfig.callMethods.includes(BARE_CALL)) {
|
|
62
|
+
yield* jsDoc(`Add a bare method call to the ${app.name} contract`);
|
|
63
|
+
yield `bare(params: AppClientBareCallParams & ${getCallOnCompleteOptions(BARE_CALL, app).type}) {`;
|
|
64
|
+
yield IncIndent;
|
|
65
|
+
yield `promiseChain = promiseChain.then(() => composer.addAppCall(client.params.bare(params)))`;
|
|
66
|
+
yield `return this`;
|
|
67
|
+
yield DecIndent;
|
|
68
|
+
yield '},';
|
|
69
|
+
}
|
|
70
|
+
for (const methodSignature of callConfig.callMethods.filter((m) => m !== BARE_CALL).map((m) => m)) {
|
|
63
71
|
const methodName = sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]);
|
|
64
|
-
const
|
|
72
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSignature);
|
|
65
73
|
const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName);
|
|
66
74
|
// Skip methods which don't support a no_op call config
|
|
67
75
|
if (!callConfig.callMethods.includes(methodSignature))
|
|
68
76
|
continue;
|
|
69
|
-
yield
|
|
77
|
+
yield* jsDoc(`Add a ${methodSignature} method call against the ${app.name} contract`);
|
|
78
|
+
yield `${methodName}(params: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & ${getCallOnCompleteOptions(methodSignature, app).type}) {`;
|
|
70
79
|
yield IncIndent;
|
|
71
|
-
yield `promiseChain = promiseChain.then(() => client${methodNameAccessor}(
|
|
72
|
-
const outputTypeName = app.
|
|
73
|
-
yield `resultMappers.push(${outputTypeName
|
|
80
|
+
yield `promiseChain = promiseChain.then(async () => composer.addAppCallMethodCall(await client.params${methodNameAccessor}(params)))`;
|
|
81
|
+
const outputTypeName = app.methods.find((m) => new ABIMethod(m).getSignature() === methodSignature)?.returns.type;
|
|
82
|
+
yield `resultMappers.push(${outputTypeName && outputTypeName !== 'void' ? `(v) => client.decodeReturnValue('${methodSigSafe}', v)` : 'undefined'})`;
|
|
74
83
|
yield `return this`;
|
|
75
84
|
yield DecIndent;
|
|
76
85
|
yield '},';
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
|
-
function* callComposerClearState() {
|
|
80
|
-
yield `
|
|
88
|
+
function* callComposerClearState({ app }) {
|
|
89
|
+
yield* jsDoc(`Add a clear state call to the ${app.name} contract`);
|
|
90
|
+
yield `clearState(params: AppClientBareCallParams) {`;
|
|
81
91
|
yield IncIndent;
|
|
82
|
-
yield `promiseChain = promiseChain.then(() => client.clearState(
|
|
83
|
-
yield `resultMappers.push(undefined)`;
|
|
92
|
+
yield `promiseChain = promiseChain.then(() => composer.addAppCall(client.params.clearState(params)))`;
|
|
84
93
|
yield `return this`;
|
|
85
94
|
yield DecIndent;
|
|
86
95
|
yield '},';
|
|
87
96
|
}
|
|
88
|
-
function* callComposerOperationMethods({ app, methodSignatureToUniqueName, sanitizer }, methods, verb, includeCompilation) {
|
|
97
|
+
function* callComposerOperationMethods({ app, name, methodSignatureToUniqueName, sanitizer }, methods, verb, includeCompilation) {
|
|
98
|
+
const callType = verb === 'update' ? 'Update' : verb === 'delete' ? 'Delete' : 'Call';
|
|
89
99
|
if (methods.length) {
|
|
90
100
|
yield `get ${verb}() {`;
|
|
91
101
|
yield IncIndent;
|
|
92
|
-
yield `const $this = this`;
|
|
93
102
|
yield `return {`;
|
|
94
103
|
yield IncIndent;
|
|
95
104
|
for (const methodSig of methods) {
|
|
96
|
-
const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined;
|
|
97
105
|
if (methodSig === BARE_CALL) {
|
|
98
|
-
yield `bare
|
|
106
|
+
yield `bare: (params?: AppClientBareCallParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}) => {`;
|
|
99
107
|
yield IncIndent;
|
|
100
|
-
yield `promiseChain = promiseChain.then(() =>
|
|
101
|
-
yield `
|
|
102
|
-
yield `return $this`;
|
|
108
|
+
yield `promiseChain = promiseChain.then(${verb === 'update' ? 'async ' : ''}() => composer.addApp${callType}(${verb === 'update' ? 'await ' : ''}client.params.${verb}.bare(params)))`;
|
|
109
|
+
yield `return this`;
|
|
103
110
|
yield DecIndent;
|
|
104
111
|
yield '},';
|
|
105
112
|
}
|
|
@@ -108,12 +115,12 @@ function* callComposerOperationMethods({ app, methodSignatureToUniqueName, sanit
|
|
|
108
115
|
const methodName = sanitizer.makeSafeMethodIdentifier(uniqueName);
|
|
109
116
|
const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName);
|
|
110
117
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig);
|
|
111
|
-
yield `${methodName}(
|
|
118
|
+
yield `${methodName}: (params: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']>${includeCompilation ? ' & AppClientCompilationParams' : ''}) => {`;
|
|
112
119
|
yield IncIndent;
|
|
113
|
-
yield `promiseChain = promiseChain.then(() => client.${verb}${methodNameAccessor}(
|
|
114
|
-
const outputTypeName = app.
|
|
115
|
-
yield `resultMappers.push(${outputTypeName
|
|
116
|
-
yield `return
|
|
120
|
+
yield `promiseChain = promiseChain.then(async () => composer.addApp${callType}MethodCall(await client.params.${verb}${methodNameAccessor}(params)))`;
|
|
121
|
+
const outputTypeName = app.methods.find((m) => new ABIMethod(m).getSignature() === methodSig)?.returns.type;
|
|
122
|
+
yield `resultMappers.push(${outputTypeName && outputTypeName !== 'void' ? `(v) => client.decodeReturnValue('${methodSigSafe}', v)` : 'undefined'})`;
|
|
123
|
+
yield `return this`;
|
|
117
124
|
yield DecIndent;
|
|
118
125
|
yield '},';
|
|
119
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-composer.mjs","sources":["../../src/client/call-composer.ts"],"sourcesContent":["import { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent } from '../output/writer'\nimport { GeneratorContext } from './generator-context'\nimport * as algokit from '@algorandfoundation/algokit-utils'\nimport { BARE_CALL, MethodList } from './helpers/get-call-config-summary'\nimport { getCreateOnCompleteOptions } from './deploy-types'\n\nexport function* composeMethod(ctx: GeneratorContext): DocumentParts {\n const { name, callConfig } = ctx\n yield `public compose(): ${name}Composer {`\n yield IncIndent\n\n yield `const client = this`\n yield `const atc = new AtomicTransactionComposer()`\n yield `let promiseChain:Promise<unknown> = Promise.resolve()`\n yield `const resultMappers: Array<undefined | ((x: any) => any)> = []`\n yield `return {`\n yield IncIndent\n\n yield* callComposerNoops(ctx)\n yield* callComposerOperationMethods(ctx, callConfig.updateMethods, 'update', true)\n yield* callComposerOperationMethods(ctx, callConfig.deleteMethods, 'delete')\n yield* callComposerOperationMethods(ctx, callConfig.optInMethods, 'optIn')\n yield* callComposerOperationMethods(ctx, callConfig.closeOutMethods, 'closeOut')\n yield* callComposerClearState()\n\n yield `addTransaction(txn: TransactionWithSigner | TransactionToSign | Transaction | Promise<SendTransactionResult>, defaultSender?: SendTransactionFrom) {`\n yield IncIndent\n yield 'promiseChain = promiseChain.then(async () => atc.addTransaction(await algokit.getTransactionWithSigner(txn, defaultSender ??' +\n ' client.sender)))'\n yield 'return this'\n yield DecIndent\n yield '},'\n\n yield `async atc() {`\n yield IncIndent\n yield 'await promiseChain'\n yield 'return atc'\n yield DecIndent\n yield '},'\n\n yield `async simulate(options?: SimulateOptions) {`\n yield IncIndent\n yield `await promiseChain`\n yield `const result = await atc.simulate(client.algod, new modelsv2.SimulateRequest({ txnGroups: [], ...options }))`\n yield `return {`\n yield IncIndent\n yield `...result,`\n yield `returns: result.methodResults?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val.returnValue) : val.returnValue)`\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield '},'\n\n yield `async execute(sendParams?: AppClientComposeExecuteParams) {`\n yield IncIndent\n yield `await promiseChain`\n yield `const result = await algokit.sendAtomicTransactionComposer({ atc, sendParams }, client.algod)`\n yield `return {`\n yield IncIndent\n yield `...result,`\n yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val.returnValue) : val.returnValue)`\n yield DecIndentAndCloseBlock\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield `} as unknown as ${name}Composer`\n\n yield DecIndentAndCloseBlock\n}\n\nfunction* callComposerNoops({ app, callConfig, methodSignatureToUniqueName, sanitizer }: GeneratorContext): DocumentParts {\n for (const method of app.contract.methods) {\n const methodSignature = algokit.getABIMethodSignature(method)\n const methodName = sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature])\n const methodSignatureSafe = sanitizer.makeSafeStringTypeLiteral(methodSignature)\n const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName)\n // Skip methods which don't support a no_op call config\n if (!callConfig.callMethods.includes(methodSignature)) continue\n\n yield `${methodName}(args: MethodArgs<'${methodSignatureSafe}'>, params?: AppClientComposeCallCoreParams & CoreAppCallArgs) {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(() => client${methodNameAccessor}(args, {...params, sendParams: {...params?.sendParams, skipSending: true, atc}}))`\n const outputTypeName = app.hints?.[methodSignature]?.structs?.output?.name\n yield `resultMappers.push(${outputTypeName ?? 'undefined'})`\n yield `return this`\n yield DecIndent\n yield '},'\n }\n}\n\nfunction* callComposerClearState(): DocumentParts {\n yield `clearState(args?: BareCallArgs & AppClientComposeCallCoreParams & CoreAppCallArgs) {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(() => client.clearState({...args, sendParams: {...args?.sendParams, skipSending: true, atc}}))`\n yield `resultMappers.push(undefined)`\n yield `return this`\n yield DecIndent\n yield '},'\n}\n\nfunction* callComposerOperationMethods(\n { app, methodSignatureToUniqueName, sanitizer }: GeneratorContext,\n methods: MethodList,\n verb: 'create' | 'update' | 'optIn' | 'closeOut' | 'delete',\n includeCompilation?: boolean,\n): DocumentParts {\n if (methods.length) {\n yield `get ${verb}() {`\n yield IncIndent\n yield `const $this = this`\n yield `return {`\n yield IncIndent\n for (const methodSig of methods) {\n const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined\n if (methodSig === BARE_CALL) {\n yield `bare(args${onComplete?.isOptional !== false ? '?' : ''}: BareCallArgs & AppClientComposeCallCoreParams ${\n includeCompilation ? '& AppClientCompilationParams ' : ''\n }& CoreAppCallArgs${onComplete?.type ? ` & ${onComplete.type}` : ''}) {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(() => client.${verb}.bare({...args, sendParams: {...args?.sendParams, skipSending: true, atc}}))`\n yield `resultMappers.push(undefined)`\n yield `return $this`\n yield DecIndent\n yield '},'\n } else {\n const uniqueName = methodSignatureToUniqueName[methodSig]\n const methodName = sanitizer.makeSafeMethodIdentifier(uniqueName)\n const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName)\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig)\n yield `${methodName}(args: MethodArgs<'${methodSigSafe}'>, params${\n onComplete?.isOptional !== false ? '?' : ''\n }: AppClientComposeCallCoreParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n onComplete?.type ? ` & ${onComplete.type}` : ''\n }) {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(() => client.${verb}${methodNameAccessor}(args, {...params, sendParams: {...params?.sendParams, skipSending: true, atc}}))`\n const outputTypeName = app.hints?.[methodSig]?.structs?.output?.name\n yield `resultMappers.push(${outputTypeName ?? 'undefined'})`\n yield `return $this`\n yield DecIndent\n yield '},'\n }\n }\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield '},'\n }\n}\n"],"names":[],"mappings":";;;;;AAMe,UAAE,aAAa,CAAC,GAAqB,EAAA;AAClD,IAAA,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;IAChC,MAAM,C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AE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAA;AACpE,gBAAA,MAAM,CAAsB,mBAAA,EAAA,cAAc,IAAI,WAAW,GAAG,CAAA;AAC5D,gBAAA,MAAM,cAAc,CAAA;AACpB,gBAAA,MAAM,SAAS,CAAA;AACf,gBAAA,MAAM,IAAI,CAAA;aACX;SACF;AACD,QAAA,MAAM,sBAAsB,CAAA;AAC5B,QAAA,MAAM,SAAS,CAAA;AACf,QAAA,MAAM,IAAI,CAAA;KACX;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"call-composer.mjs","sources":["../../src/client/call-composer.ts"],"sourcesContent":["import { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, jsDoc } from '../output/writer'\nimport { GeneratorContext } from './generator-context'\nimport { BARE_CALL, MethodList } from './helpers/get-call-config-summary'\nimport { getCallOnCompleteOptions } from './deploy-types'\nimport { ABIMethod, ABIMethodParams } from 'algosdk'\n\nexport function* composeMethod(ctx: GeneratorContext): DocumentParts {\n const { name, callConfig } = ctx\n // todo: Patrick feedback - allow common params to be passed in here so they propagate to all params calls e.g. firstValid\n yield `public newGroup(): ${name}Composer {`\n yield IncIndent\n\n yield `const client = this`\n yield `const composer = this.algorand.newGroup()`\n yield `let promiseChain:Promise<unknown> = Promise.resolve()`\n yield `const resultMappers: Array<undefined | ((x: ABIReturn | undefined) => any)> = []`\n yield `return {`\n yield IncIndent\n\n yield* callComposerNoops(ctx)\n yield* callComposerOperationMethods(ctx, callConfig.updateMethods, 'update', true)\n yield* callComposerOperationMethods(ctx, callConfig.deleteMethods, 'delete')\n yield* callComposerOperationMethods(ctx, callConfig.optInMethods, 'optIn')\n yield* callComposerOperationMethods(ctx, callConfig.closeOutMethods, 'closeOut')\n yield* callComposerClearState(ctx)\n\n yield `addTransaction(txn: Transaction, signer?: TransactionSigner) {`\n yield IncIndent\n yield 'promiseChain = promiseChain.then(() => composer.addTransaction(txn, signer))'\n yield 'return this'\n yield DecIndent\n yield '},'\n\n yield `async composer() {`\n yield IncIndent\n yield `await promiseChain`\n yield 'return composer'\n yield DecIndent\n yield '},'\n\n yield `async simulate(options?: SimulateOptions) {`\n yield IncIndent\n yield `await promiseChain`\n yield `const result = await composer.simulate(options)`\n yield `return {`\n yield IncIndent\n yield `...result,`\n yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val) : val.returnValue)`\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield '},'\n\n yield `async send(params?: SendParams) {`\n yield IncIndent\n yield `await promiseChain`\n yield `const result = await composer.send(params)`\n yield `return {`\n yield IncIndent\n yield `...result,`\n yield `returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i]!(val) : val.returnValue)`\n yield DecIndentAndCloseBlock\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield `} as unknown as ${name}Composer`\n\n yield DecIndentAndCloseBlock\n}\n\nfunction* callComposerNoops({ app, name, callConfig, methodSignatureToUniqueName, sanitizer }: GeneratorContext): DocumentParts {\n if (callConfig.callMethods.includes(BARE_CALL)) {\n yield* jsDoc(`Add a bare method call to the ${app.name} contract`)\n yield `bare(params: AppClientBareCallParams & ${getCallOnCompleteOptions(BARE_CALL, app).type}) {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(() => composer.addAppCall(client.params.bare(params)))`\n yield `return this`\n yield DecIndent\n yield '},'\n }\n\n for (const methodSignature of callConfig.callMethods.filter((m) => m !== BARE_CALL).map((m) => m as string)) {\n const methodName = sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature])\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSignature)\n const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName)\n // Skip methods which don't support a no_op call config\n if (!callConfig.callMethods.includes(methodSignature)) continue\n yield* jsDoc(`Add a ${methodSignature} method call against the ${app.name} contract`)\n yield `${methodName}(params: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & ${getCallOnCompleteOptions(methodSignature, app).type}) {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(async () => composer.addAppCallMethodCall(await client.params${methodNameAccessor}(params)))`\n const outputTypeName = app.methods.find((m: ABIMethodParams) => new ABIMethod(m).getSignature() === methodSignature)?.returns.type\n yield `resultMappers.push(${outputTypeName && outputTypeName !== 'void' ? `(v) => client.decodeReturnValue('${methodSigSafe}', v)` : 'undefined'})`\n yield `return this`\n yield DecIndent\n yield '},'\n }\n}\n\nfunction* callComposerClearState({ app }: GeneratorContext): DocumentParts {\n yield* jsDoc(`Add a clear state call to the ${app.name} contract`)\n yield `clearState(params: AppClientBareCallParams) {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(() => composer.addAppCall(client.params.clearState(params)))`\n yield `return this`\n yield DecIndent\n yield '},'\n}\n\nfunction* callComposerOperationMethods(\n { app, name, methodSignatureToUniqueName, sanitizer }: GeneratorContext,\n methods: MethodList,\n verb: 'update' | 'optIn' | 'closeOut' | 'delete',\n includeCompilation?: boolean,\n): DocumentParts {\n const callType = verb === 'update' ? 'Update' : verb === 'delete' ? 'Delete' : 'Call'\n if (methods.length) {\n yield `get ${verb}() {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n for (const methodSig of methods) {\n if (methodSig === BARE_CALL) {\n yield `bare: (params?: AppClientBareCallParams ${includeCompilation ? '& AppClientCompilationParams ' : ''}) => {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(${verb === 'update' ? 'async ' : ''}() => composer.addApp${callType}(${verb === 'update' ? 'await ' : ''}client.params.${verb}.bare(params)))`\n yield `return this`\n yield DecIndent\n yield '},'\n } else {\n const uniqueName = methodSignatureToUniqueName[methodSig]\n const methodName = sanitizer.makeSafeMethodIdentifier(uniqueName)\n const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName)\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig)\n yield `${methodName}: (params: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']>${includeCompilation ? ' & AppClientCompilationParams' : ''}) => {`\n yield IncIndent\n yield `promiseChain = promiseChain.then(async () => composer.addApp${callType}MethodCall(await client.params.${verb}${methodNameAccessor}(params)))`\n const outputTypeName = app.methods.find((m: ABIMethodParams) => new ABIMethod(m).getSignature() === methodSig)?.returns.type\n yield `resultMappers.push(${outputTypeName && outputTypeName !== 'void' ? `(v) => client.decodeReturnValue('${methodSigSafe}', v)` : 'undefined'})`\n yield `return this`\n yield DecIndent\n yield '},'\n }\n }\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield '},'\n }\n}\n"],"names":[],"mappings":";;;;;AAMe,UAAE,aAAa,CAAC,GAAqB,EAAA;AAClD,IAAA,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;;IAEhC,MAAM,CAAA,mBAAA,EAAsB,IAAI,CAAA,UAAA,CAAY,CAAA;AAC5C,IAAA,MAAM,SAAS,CAAA;AAEf,IAAA,MAAM,qBAAqB,CAAA;AAC3B,IAAA,MAAM,2CAA2C,CAAA;AACjD,IAAA,MAAM,uDAAuD,CAAA;AAC7D,IAAA,MAAM,kFAAkF,CAAA;AACxF,IAAA,MAAM,UAAU,CAAA;AAChB,IAAA,MAAM,SAAS,CAAA;AAEf,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAA;AAC7B,IAAA,OAAO,4BAA4B,CAAC,GAAG,EAAE,UAAU,CAAC,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAClF,IAAA,OAAO,4BAA4B,CAAC,GAAG,EAAE,UAAU,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAA;AAC5E,IAAA,OAAO,4BAA4B,CAAC,GAAG,EAAE,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;AAC1E,IAAA,OAAO,4BAA4B,CAAC,GAAG,EAAE,UAAU,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;AAChF,IAAA,OAAO,sBAAsB,CAAC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gBAAA,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAkB,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,CAAA;AAC5H,gBAAA,MAAM,sBAAsB,cAAc,IAAI,cAAc,KAAK,MAAM,GAAG,CAAA,iCAAA,EAAoC,aAAa,CAAO,KAAA,CAAA,GAAG,WAAW,GAAG,CAAA;AACnJ,gBAAA,MAAM,aAAa,CAAA;AACnB,gBAAA,MAAM,SAAS,CAAA;AACf,gBAAA,MAAM,IAAI,CAAA;aACX;SACF;AACD,QAAA,MAAM,sBAAsB,CAAA;AAC5B,QAAA,MAAM,SAAS,CAAA;AACf,QAAA,MAAM,IAAI,CAAA;KACX;AACH;;;;"}
|
package/client/deploy-types.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { DocumentParts } from '../output/writer';
|
|
2
2
|
import { MethodIdentifier } from './helpers/get-call-config-summary';
|
|
3
3
|
import { GeneratorContext } from './generator-context';
|
|
4
|
-
import {
|
|
5
|
-
export declare function getCreateOnCompleteOptions(method: MethodIdentifier, app:
|
|
4
|
+
import { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56';
|
|
5
|
+
export declare function getCreateOnCompleteOptions(method: MethodIdentifier, app: Arc56Contract): {
|
|
6
6
|
type: {};
|
|
7
|
-
isOptional: boolean;
|
|
7
|
+
isOptional: boolean | undefined;
|
|
8
8
|
};
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function getCallOnCompleteOptions(method: MethodIdentifier, app: Arc56Contract): {
|
|
10
|
+
type: {};
|
|
11
|
+
isOptional: boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare function deployTypes({ app, callConfig, sanitizer, methodSignatureToUniqueName }: GeneratorContext): DocumentParts;
|
package/client/deploy-types.js
CHANGED
|
@@ -2,96 +2,114 @@
|
|
|
2
2
|
|
|
3
3
|
var writer = require('../output/writer.js');
|
|
4
4
|
var getCallConfigSummary = require('./helpers/get-call-config-summary.js');
|
|
5
|
-
var
|
|
5
|
+
var algosdk = require('algosdk');
|
|
6
6
|
|
|
7
7
|
function getCreateOnCompleteOptions(method, app) {
|
|
8
|
-
const
|
|
9
|
-
const hasNoOp =
|
|
10
|
-
const onCompleteType =
|
|
11
|
-
? `
|
|
12
|
-
.filter(([_, value]) => value === 'ALL' || value === 'CREATE')
|
|
13
|
-
.map(([oc]) => utilityTypes.OnCompleteCodeMap[oc])
|
|
14
|
-
.join(' | ')})`
|
|
8
|
+
const validCreateOnCompletes = method === getCallConfigSummary.BARE_CALL ? app.bareActions.create : app.methods.find((m) => new algosdk.ABIMethod(m).getSignature() === method)?.actions?.create;
|
|
9
|
+
const hasNoOp = validCreateOnCompletes?.includes('NoOp');
|
|
10
|
+
const onCompleteType = validCreateOnCompletes
|
|
11
|
+
? `{onComplete${hasNoOp ? '?' : ''}: ${validCreateOnCompletes.map((oc) => `OnApplicationComplete.${oc}OC`).join(' | ')}}`
|
|
15
12
|
: {};
|
|
16
13
|
return {
|
|
17
14
|
type: onCompleteType,
|
|
18
15
|
isOptional: hasNoOp,
|
|
19
16
|
};
|
|
20
17
|
}
|
|
21
|
-
function
|
|
22
|
-
const
|
|
18
|
+
function getCallOnCompleteOptions(method, app) {
|
|
19
|
+
const validCallOnCompletes = method === getCallConfigSummary.BARE_CALL ? app.bareActions.call : app.methods.find((m) => new algosdk.ABIMethod(m).getSignature() === method)?.actions?.call;
|
|
20
|
+
const hasNoOp = validCallOnCompletes?.includes('NoOp');
|
|
21
|
+
const onCompleteType = validCallOnCompletes
|
|
22
|
+
? `{onComplete${hasNoOp ? '?' : ''}: ${validCallOnCompletes.map((oc) => `OnApplicationComplete.${oc}OC`).join(' | ')}}`
|
|
23
|
+
: {};
|
|
24
|
+
return {
|
|
25
|
+
type: onCompleteType,
|
|
26
|
+
isOptional: hasNoOp,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function* deployTypes({ app, callConfig, sanitizer, methodSignatureToUniqueName }) {
|
|
30
|
+
const name = sanitizer.makeSafeTypeIdentifier(app.name);
|
|
23
31
|
if (callConfig.createMethods.length > 0) {
|
|
24
|
-
yield* writer.jsDoc(
|
|
25
|
-
yield `export type ${name}CreateCalls = (typeof ${name}CallFactory)['create']`;
|
|
26
|
-
yield* writer.jsDoc('Defines supported create methods for this smart contract');
|
|
32
|
+
yield* writer.jsDoc('Defines supported create method params for this smart contract');
|
|
27
33
|
yield `export type ${name}CreateCallParams =`;
|
|
28
34
|
yield writer.IncIndent;
|
|
29
35
|
for (const method of callConfig.createMethods) {
|
|
30
36
|
const onComplete = getCreateOnCompleteOptions(method, app);
|
|
31
37
|
if (method === getCallConfigSummary.BARE_CALL) {
|
|
32
|
-
yield `|
|
|
38
|
+
yield `| Expand<AppClientBareCallParams & {method?: undefined} & ${onComplete.type} & CreateSchema>`;
|
|
33
39
|
}
|
|
34
40
|
else {
|
|
35
41
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
36
|
-
|
|
42
|
+
const uniqueName = methodSignatureToUniqueName[method];
|
|
43
|
+
if (uniqueName !== method) {
|
|
44
|
+
const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName);
|
|
45
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'} & ${onComplete.type} & CreateSchema>`;
|
|
46
|
+
}
|
|
47
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'} & ${onComplete.type} & CreateSchema>`;
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
yield writer.DecIndent;
|
|
40
51
|
}
|
|
41
52
|
if (callConfig.updateMethods.length > 0) {
|
|
42
|
-
yield* writer.jsDoc(
|
|
43
|
-
yield `export type ${name}UpdateCalls = (typeof ${name}CallFactory)['update']`;
|
|
44
|
-
yield* writer.jsDoc('Defines supported update methods for this smart contract');
|
|
53
|
+
yield* writer.jsDoc('Defines supported update method params for this smart contract');
|
|
45
54
|
yield `export type ${name}UpdateCallParams =`;
|
|
46
55
|
yield writer.IncIndent;
|
|
47
56
|
for (const method of callConfig.updateMethods) {
|
|
48
57
|
if (method === getCallConfigSummary.BARE_CALL) {
|
|
49
|
-
yield `|
|
|
58
|
+
yield `| Expand<AppClientBareCallParams> & {method?: undefined}`;
|
|
50
59
|
}
|
|
51
60
|
else {
|
|
61
|
+
const uniqueName = methodSignatureToUniqueName[method];
|
|
52
62
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
53
|
-
|
|
63
|
+
if (uniqueName !== method) {
|
|
64
|
+
const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName);
|
|
65
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'}>`;
|
|
66
|
+
}
|
|
67
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'}>`;
|
|
54
68
|
}
|
|
55
69
|
}
|
|
56
70
|
yield writer.DecIndent;
|
|
57
71
|
}
|
|
58
72
|
if (callConfig.deleteMethods.length > 0) {
|
|
59
|
-
yield* writer.jsDoc(
|
|
60
|
-
yield `export type ${name}DeleteCalls = (typeof ${name}CallFactory)['delete']`;
|
|
61
|
-
yield* writer.jsDoc('Defines supported delete methods for this smart contract');
|
|
73
|
+
yield* writer.jsDoc('Defines supported delete method params for this smart contract');
|
|
62
74
|
yield `export type ${name}DeleteCallParams =`;
|
|
63
75
|
yield writer.IncIndent;
|
|
64
76
|
for (const method of callConfig.deleteMethods) {
|
|
65
77
|
if (method === getCallConfigSummary.BARE_CALL) {
|
|
66
|
-
yield `|
|
|
78
|
+
yield `| Expand<AppClientBareCallParams> & {method?: undefined}`;
|
|
67
79
|
}
|
|
68
80
|
else {
|
|
81
|
+
const uniqueName = methodSignatureToUniqueName[method];
|
|
69
82
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
70
|
-
|
|
83
|
+
if (uniqueName !== method) {
|
|
84
|
+
const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName);
|
|
85
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'}>`;
|
|
86
|
+
}
|
|
87
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'}>`;
|
|
71
88
|
}
|
|
72
89
|
}
|
|
73
90
|
yield writer.DecIndent;
|
|
74
91
|
}
|
|
75
92
|
yield* writer.jsDoc('Defines arguments required for the deploy method.');
|
|
76
|
-
yield `export type ${name}
|
|
93
|
+
yield `export type ${name}DeployParams = Expand<Omit<AppFactoryDeployParams, 'createParams' | 'updateParams' | 'deleteParams'> & {`;
|
|
77
94
|
yield writer.IncIndent;
|
|
78
|
-
yield `deployTimeParams?: TealTemplateParams`;
|
|
79
95
|
if (callConfig.createMethods.length) {
|
|
80
|
-
yield* writer.jsDoc('
|
|
81
|
-
yield `
|
|
96
|
+
yield* writer.jsDoc('Create transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)');
|
|
97
|
+
yield `createParams?: ${name}CreateCallParams`;
|
|
82
98
|
}
|
|
83
99
|
if (callConfig.updateMethods.length) {
|
|
84
|
-
yield* writer.jsDoc('
|
|
85
|
-
yield `
|
|
100
|
+
yield* writer.jsDoc('Update transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)');
|
|
101
|
+
yield `updateParams?: ${name}UpdateCallParams`;
|
|
86
102
|
}
|
|
87
103
|
if (callConfig.deleteMethods.length) {
|
|
88
|
-
yield* writer.jsDoc('
|
|
89
|
-
yield `
|
|
104
|
+
yield* writer.jsDoc('Delete transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)');
|
|
105
|
+
yield `deleteParams?: ${name}DeleteCallParams`;
|
|
90
106
|
}
|
|
91
|
-
yield writer.
|
|
107
|
+
yield writer.DecIndent;
|
|
108
|
+
yield `}>`;
|
|
92
109
|
yield writer.NewLine;
|
|
93
110
|
}
|
|
94
111
|
|
|
95
112
|
exports.deployTypes = deployTypes;
|
|
113
|
+
exports.getCallOnCompleteOptions = getCallOnCompleteOptions;
|
|
96
114
|
exports.getCreateOnCompleteOptions = getCreateOnCompleteOptions;
|
|
97
115
|
//# sourceMappingURL=deploy-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy-types.js","sources":["../../src/client/deploy-types.ts"],"sourcesContent":["import { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, jsDoc, NewLine } from '../output/writer'\n\nimport { BARE_CALL, MethodIdentifier } from './helpers/get-call-config-summary'\nimport { GeneratorContext } from './generator-context'\nimport { AlgoAppSpec, CallConfig } from '../schema/application'\nimport { OnCompleteCodeMap } from './utility-types'\n\nexport function getCreateOnCompleteOptions(method: MethodIdentifier, app: AlgoAppSpec) {\n const callConfig = method === BARE_CALL ? app.bare_call_config : app.hints?.[method]?.call_config\n const hasNoOp = callConfig?.no_op === 'ALL' || callConfig?.no_op === 'CREATE'\n const onCompleteType = callConfig\n ? `(${Object.entries(callConfig)\n .filter(([_, value]) => value === 'ALL' || value === 'CREATE')\n .map(([oc]) => OnCompleteCodeMap[oc as keyof CallConfig])\n .join(' | ')})`\n : {}\n return {\n type: onCompleteType,\n isOptional: hasNoOp,\n }\n}\n\nexport function* deployTypes({ app, callConfig, sanitizer }: GeneratorContext): DocumentParts {\n const name = sanitizer.makeSafeTypeIdentifier(app.contract.name)\n\n if (callConfig.createMethods.length > 0) {\n yield* jsDoc(`A factory for available 'create' calls`)\n yield `export type ${name}CreateCalls = (typeof ${name}CallFactory)['create']`\n yield* jsDoc('Defines supported create methods for this smart contract')\n yield `export type ${name}CreateCallParams =`\n yield IncIndent\n for (const method of callConfig.createMethods) {\n const onComplete = getCreateOnCompleteOptions(method, app)\n if (method === BARE_CALL) {\n yield `| (TypedCallParams<undefined> & ${onComplete.type})`\n } else {\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method)\n yield `| (TypedCallParams<'${methodSigSafe}'> & ${onComplete.type})`\n }\n }\n yield DecIndent\n }\n if (callConfig.updateMethods.length > 0) {\n yield* jsDoc(`A factory for available 'update' calls`)\n\n yield `export type ${name}UpdateCalls = (typeof ${name}CallFactory)['update']`\n yield* jsDoc('Defines supported update methods for this smart contract')\n yield `export type ${name}UpdateCallParams =`\n yield IncIndent\n for (const method of callConfig.updateMethods) {\n if (method === BARE_CALL) {\n yield `| TypedCallParams<undefined>`\n } else {\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method)\n\n yield `| TypedCallParams<'${methodSigSafe}'>`\n }\n }\n yield DecIndent\n }\n\n if (callConfig.deleteMethods.length > 0) {\n yield* jsDoc(`A factory for available 'delete' calls`)\n\n yield `export type ${name}DeleteCalls = (typeof ${name}CallFactory)['delete']`\n\n yield* jsDoc('Defines supported delete methods for this smart contract')\n yield `export type ${name}DeleteCallParams =`\n yield IncIndent\n for (const method of callConfig.deleteMethods) {\n if (method === BARE_CALL) {\n yield `| TypedCallParams<undefined>`\n } else {\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method)\n\n yield `| TypedCallParams<'${methodSigSafe}'>`\n }\n }\n yield DecIndent\n }\n\n yield* jsDoc('Defines arguments required for the deploy method.')\n yield `export type ${name}DeployArgs = {`\n yield IncIndent\n yield `deployTimeParams?: TealTemplateParams`\n if (callConfig.createMethods.length) {\n yield* jsDoc('A delegate which takes a create call factory and returns the create call params for this smart contract')\n yield `createCall?: (callFactory: ${name}CreateCalls) => ${name}CreateCallParams`\n }\n if (callConfig.updateMethods.length) {\n yield* jsDoc('A delegate which takes a update call factory and returns the update call params for this smart contract')\n yield `updateCall?: (callFactory: ${name}UpdateCalls) => ${name}UpdateCallParams`\n }\n if (callConfig.deleteMethods.length) {\n yield* jsDoc('A delegate which takes a delete call factory and returns the delete call params for this smart contract')\n yield `deleteCall?: (callFactory: ${name}DeleteCalls) => ${name}DeleteCallParams`\n }\n yield DecIndentAndCloseBlock\n yield NewLine\n}\n"],"names":["BARE_CALL","OnCompleteCodeMap","jsDoc","IncIndent","DecIndent","DecIndentAndCloseBlock","NewLine"],"mappings":";;;;;;AAOgB,SAAA,0BAA0B,CAAC,MAAwB,EAAE,GAAgB,EAAA;IACnF,MAAM,UAAU,GAAG,MAAM,KAAKA,8BAAS,GAAG,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,EAAE,WAAW,CAAA;AACjG,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE,KAAK,KAAK,KAAK,IAAI,UAAU,EAAE,KAAK,KAAK,QAAQ,CAAA;IAC7E,MAAM,cAAc,GAAG,UAAU;AAC/B,UAAE,CAAI,CAAA,EAAA,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;AAC3B,aAAA,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,QAAQ,CAAC;AAC7D,aAAA,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAKC,8BAAiB,CAAC,EAAsB,CAAC,CAAC;aACxD,IAAI,CAAC,KAAK,CAAC,CAAG,CAAA,CAAA;UACjB,EAAE,CAAA;IACN,OAAO;AACL,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,UAAU,EAAE,OAAO;KACpB,CAAA;AACH,CAAC;AAEK,UAAW,WAAW,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAoB,EAAA;AAC3E,IAAA,MAAM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AAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,EAAE;AACnC,QAAA,OAAOD,YAAK,CAAC,yGAAyG,CAAC,CAAA;AACvH,QAAA,MAAM,CAA8B,2BAAA,EAAA,IAAI,CAAmB,gBAAA,EAAA,IAAI,kBAAkB,CAAA;KAClF;AACD,IAAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,EAAE;AACnC,QAAA,OAAOA,YAAK,CAAC,yGAAyG,CAAC,CAAA;AACvH,QAAA,MAAM,CAA8B,2BAAA,EAAA,IAAI,CAAmB,gBAAA,EAAA,IAAI,kBAAkB,CAAA;KAClF;AACD,IAAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,EAAE;AACnC,QAAA,OAAOA,YAAK,CAAC,yGAAyG,CAAC,CAAA;AACvH,QAAA,MAAM,CAA8B,2BAAA,EAAA,IAAI,CAAmB,gBAAA,EAAA,IAAI,kBAAkB,CAAA;KAClF;AACD,IAAA,MAAMG,6BAAsB,CAAA;AAC5B,IAAA,MAAMC,cAAO,CAAA;AACf;;;;;"}
|
|
1
|
+
{"version":3,"file":"deploy-types.js","sources":["../../src/client/deploy-types.ts"],"sourcesContent":["import { DecIndent, DocumentParts, IncIndent, jsDoc, NewLine } from '../output/writer'\nimport { BARE_CALL, MethodIdentifier } from './helpers/get-call-config-summary'\nimport { GeneratorContext } from './generator-context'\nimport { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56'\nimport { ABIMethod } from 'algosdk'\n\nexport function getCreateOnCompleteOptions(method: MethodIdentifier, app: Arc56Contract) {\n const validCreateOnCompletes =\n method === BARE_CALL ? app.bareActions.create : app.methods.find((m) => new ABIMethod(m).getSignature() === method)?.actions?.create\n const hasNoOp = validCreateOnCompletes?.includes('NoOp')\n const onCompleteType = validCreateOnCompletes\n ? `{onComplete${hasNoOp ? '?' : ''}: ${validCreateOnCompletes.map((oc) => `OnApplicationComplete.${oc}OC`).join(' | ')}}`\n : {}\n return {\n type: onCompleteType,\n isOptional: hasNoOp,\n }\n}\n\nexport function getCallOnCompleteOptions(method: MethodIdentifier, app: Arc56Contract) {\n const validCallOnCompletes =\n method === BARE_CALL ? app.bareActions.call : app.methods.find((m) => new ABIMethod(m).getSignature() === method)?.actions?.call\n const hasNoOp = validCallOnCompletes?.includes('NoOp')\n const onCompleteType = validCallOnCompletes\n ? `{onComplete${hasNoOp ? '?' : ''}: ${validCallOnCompletes.map((oc) => `OnApplicationComplete.${oc}OC`).join(' | ')}}`\n : {}\n return {\n type: onCompleteType,\n isOptional: hasNoOp,\n }\n}\n\nexport function* deployTypes({ app, callConfig, sanitizer, methodSignatureToUniqueName }: GeneratorContext): DocumentParts {\n const name = sanitizer.makeSafeTypeIdentifier(app.name)\n\n if (callConfig.createMethods.length > 0) {\n yield* jsDoc('Defines supported create method params for this smart contract')\n yield `export type ${name}CreateCallParams =`\n yield IncIndent\n for (const method of callConfig.createMethods) {\n const onComplete = getCreateOnCompleteOptions(method, app)\n if (method === BARE_CALL) {\n yield `| Expand<AppClientBareCallParams & {method?: undefined} & ${onComplete.type} & CreateSchema>`\n } else {\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method)\n const uniqueName = methodSignatureToUniqueName[method]\n if (uniqueName !== method) {\n const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName)\n yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'} & ${onComplete.type} & CreateSchema>`\n }\n yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'} & ${onComplete.type} & CreateSchema>`\n }\n }\n yield DecIndent\n }\n if (callConfig.updateMethods.length > 0) {\n yield* jsDoc('Defines supported update method params for this smart contract')\n yield `export type ${name}UpdateCallParams =`\n yield IncIndent\n for (const method of callConfig.updateMethods) {\n if (method === BARE_CALL) {\n yield `| Expand<AppClientBareCallParams> & {method?: undefined}`\n } else {\n const uniqueName = methodSignatureToUniqueName[method]\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method)\n if (uniqueName !== method) {\n const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName)\n yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'}>`\n }\n yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'}>`\n }\n }\n yield DecIndent\n }\n\n if (callConfig.deleteMethods.length > 0) {\n yield* jsDoc('Defines supported delete method params for this smart contract')\n yield `export type ${name}DeleteCallParams =`\n yield IncIndent\n for (const method of callConfig.deleteMethods) {\n if (method === BARE_CALL) {\n yield `| Expand<AppClientBareCallParams> & {method?: undefined}`\n } else {\n const uniqueName = methodSignatureToUniqueName[method]\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method)\n if (uniqueName !== method) {\n const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName)\n yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'}>`\n }\n yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'}>`\n }\n }\n yield DecIndent\n }\n\n yield* jsDoc('Defines arguments required for the deploy method.')\n yield `export type ${name}DeployParams = Expand<Omit<AppFactoryDeployParams, 'createParams' | 'updateParams' | 'deleteParams'> & {`\n yield IncIndent\n if (callConfig.createMethods.length) {\n yield* jsDoc(\n 'Create transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)',\n )\n yield `createParams?: ${name}CreateCallParams`\n }\n if (callConfig.updateMethods.length) {\n yield* jsDoc(\n 'Update transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)',\n )\n yield `updateParams?: ${name}UpdateCallParams`\n }\n if (callConfig.deleteMethods.length) {\n yield* jsDoc(\n 'Delete transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)',\n )\n yield `deleteParams?: ${name}DeleteCallParams`\n }\n yield DecIndent\n yield `}>`\n yield NewLine\n}\n"],"names":["BARE_CALL","ABIMethod","jsDoc","IncIndent","DecIndent","NewLine"],"mappings":";;;;;;AAMgB,SAAA,0BAA0B,CAAC,MAAwB,EAAE,GAAkB,EAAA;AACrF,IAAA,MAAM,sBAAsB,GAC1B,MAAM,KAAKA,8BAAS,GAAG,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAIC,iBAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAA;IACtI,MAAM,OAAO,GAAG,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxD,MAAM,cAAc,GAAG,sBAAsB;AAC3C,UAAE,CAAA,WAAA,EAAc,OAAO,GAAG,GAAG,GAAG,EAAE,CAAA,EAAA,EAAK,sBAAsB,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAyB,sBAAA,EAAA,EAAE,CAAI,EAAA,CAAA,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAG,CAAA,CAAA;UACvH,EAAE,CAAA;IACN,OAAO;AACL,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,UAAU,EAAE,OAAO;KACpB,CAAA;AACH,CAAC;AAEe,SAAA,wBAAwB,CAAC,MAAwB,EAAE,GAAkB,EAAA;AACnF,IAAA,MAAM,oBAAoB,GACxB,MAAM,KAAKD,8BAAS,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAIC,iBAAS,CAAC,C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AA,EAAkB,aAAa,CAAA,gBAAA,EAAmB,aAAa,CAAA,GAAA,CAAK,CAAA;aAC/I;SACF;AACD,QAAA,MAAMI,gBAAS,CAAA;KAChB;AAED,IAAA,OAAOF,YAAK,CAAC,mDAAmD,CAAC,CAAA;IACjE,MAAM,CAAA,YAAA,EAAe,IAAI,CAAA,wGAAA,CAA0G,CAAA;AACnI,IAAA,MAAMC,gBAAS,CAAA;AACf,IAAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,EAAE;AACnC,QAAA,OAAOD,YAAK,CACV,uLAAuL,CACxL,CAAA;QACD,MAAM,CAAA,eAAA,EAAkB,IAAI,CAAA,gBAAA,CAAkB,CAAA;KAC/C;AACD,IAAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,EAAE;AACnC,QAAA,OAAOA,YAAK,CACV,uLAAuL,CACxL,CAAA;QACD,MAAM,CAAA,eAAA,EAAkB,IAAI,CAAA,gBAAA,CAAkB,CAAA;KAC/C;AACD,IAAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,EAAE;AACnC,QAAA,OAAOA,YAAK,CACV,uLAAuL,CACxL,CAAA;QACD,MAAM,CAAA,eAAA,EAAkB,IAAI,CAAA,gBAAA,CAAkB,CAAA;KAC/C;AACD,IAAA,MAAME,gBAAS,CAAA;AACf,IAAA,MAAM,IAAI,CAAA;AACV,IAAA,MAAMC,cAAO,CAAA;AACf;;;;;;"}
|
package/client/deploy-types.mjs
CHANGED
|
@@ -1,94 +1,111 @@
|
|
|
1
|
-
import { jsDoc, IncIndent, DecIndent,
|
|
1
|
+
import { jsDoc, IncIndent, DecIndent, NewLine } from '../output/writer.mjs';
|
|
2
2
|
import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { ABIMethod } from 'algosdk';
|
|
4
4
|
|
|
5
5
|
function getCreateOnCompleteOptions(method, app) {
|
|
6
|
-
const
|
|
7
|
-
const hasNoOp =
|
|
8
|
-
const onCompleteType =
|
|
9
|
-
? `
|
|
10
|
-
.filter(([_, value]) => value === 'ALL' || value === 'CREATE')
|
|
11
|
-
.map(([oc]) => OnCompleteCodeMap[oc])
|
|
12
|
-
.join(' | ')})`
|
|
6
|
+
const validCreateOnCompletes = method === BARE_CALL ? app.bareActions.create : app.methods.find((m) => new ABIMethod(m).getSignature() === method)?.actions?.create;
|
|
7
|
+
const hasNoOp = validCreateOnCompletes?.includes('NoOp');
|
|
8
|
+
const onCompleteType = validCreateOnCompletes
|
|
9
|
+
? `{onComplete${hasNoOp ? '?' : ''}: ${validCreateOnCompletes.map((oc) => `OnApplicationComplete.${oc}OC`).join(' | ')}}`
|
|
13
10
|
: {};
|
|
14
11
|
return {
|
|
15
12
|
type: onCompleteType,
|
|
16
13
|
isOptional: hasNoOp,
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
16
|
+
function getCallOnCompleteOptions(method, app) {
|
|
17
|
+
const validCallOnCompletes = method === BARE_CALL ? app.bareActions.call : app.methods.find((m) => new ABIMethod(m).getSignature() === method)?.actions?.call;
|
|
18
|
+
const hasNoOp = validCallOnCompletes?.includes('NoOp');
|
|
19
|
+
const onCompleteType = validCallOnCompletes
|
|
20
|
+
? `{onComplete${hasNoOp ? '?' : ''}: ${validCallOnCompletes.map((oc) => `OnApplicationComplete.${oc}OC`).join(' | ')}}`
|
|
21
|
+
: {};
|
|
22
|
+
return {
|
|
23
|
+
type: onCompleteType,
|
|
24
|
+
isOptional: hasNoOp,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function* deployTypes({ app, callConfig, sanitizer, methodSignatureToUniqueName }) {
|
|
28
|
+
const name = sanitizer.makeSafeTypeIdentifier(app.name);
|
|
21
29
|
if (callConfig.createMethods.length > 0) {
|
|
22
|
-
yield* jsDoc(
|
|
23
|
-
yield `export type ${name}CreateCalls = (typeof ${name}CallFactory)['create']`;
|
|
24
|
-
yield* jsDoc('Defines supported create methods for this smart contract');
|
|
30
|
+
yield* jsDoc('Defines supported create method params for this smart contract');
|
|
25
31
|
yield `export type ${name}CreateCallParams =`;
|
|
26
32
|
yield IncIndent;
|
|
27
33
|
for (const method of callConfig.createMethods) {
|
|
28
34
|
const onComplete = getCreateOnCompleteOptions(method, app);
|
|
29
35
|
if (method === BARE_CALL) {
|
|
30
|
-
yield `|
|
|
36
|
+
yield `| Expand<AppClientBareCallParams & {method?: undefined} & ${onComplete.type} & CreateSchema>`;
|
|
31
37
|
}
|
|
32
38
|
else {
|
|
33
39
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
34
|
-
|
|
40
|
+
const uniqueName = methodSignatureToUniqueName[method];
|
|
41
|
+
if (uniqueName !== method) {
|
|
42
|
+
const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName);
|
|
43
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'} & ${onComplete.type} & CreateSchema>`;
|
|
44
|
+
}
|
|
45
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'} & ${onComplete.type} & CreateSchema>`;
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
48
|
yield DecIndent;
|
|
38
49
|
}
|
|
39
50
|
if (callConfig.updateMethods.length > 0) {
|
|
40
|
-
yield* jsDoc(
|
|
41
|
-
yield `export type ${name}UpdateCalls = (typeof ${name}CallFactory)['update']`;
|
|
42
|
-
yield* jsDoc('Defines supported update methods for this smart contract');
|
|
51
|
+
yield* jsDoc('Defines supported update method params for this smart contract');
|
|
43
52
|
yield `export type ${name}UpdateCallParams =`;
|
|
44
53
|
yield IncIndent;
|
|
45
54
|
for (const method of callConfig.updateMethods) {
|
|
46
55
|
if (method === BARE_CALL) {
|
|
47
|
-
yield `|
|
|
56
|
+
yield `| Expand<AppClientBareCallParams> & {method?: undefined}`;
|
|
48
57
|
}
|
|
49
58
|
else {
|
|
59
|
+
const uniqueName = methodSignatureToUniqueName[method];
|
|
50
60
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
51
|
-
|
|
61
|
+
if (uniqueName !== method) {
|
|
62
|
+
const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName);
|
|
63
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'}>`;
|
|
64
|
+
}
|
|
65
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'}>`;
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
yield DecIndent;
|
|
55
69
|
}
|
|
56
70
|
if (callConfig.deleteMethods.length > 0) {
|
|
57
|
-
yield* jsDoc(
|
|
58
|
-
yield `export type ${name}DeleteCalls = (typeof ${name}CallFactory)['delete']`;
|
|
59
|
-
yield* jsDoc('Defines supported delete methods for this smart contract');
|
|
71
|
+
yield* jsDoc('Defines supported delete method params for this smart contract');
|
|
60
72
|
yield `export type ${name}DeleteCallParams =`;
|
|
61
73
|
yield IncIndent;
|
|
62
74
|
for (const method of callConfig.deleteMethods) {
|
|
63
75
|
if (method === BARE_CALL) {
|
|
64
|
-
yield `|
|
|
76
|
+
yield `| Expand<AppClientBareCallParams> & {method?: undefined}`;
|
|
65
77
|
}
|
|
66
78
|
else {
|
|
79
|
+
const uniqueName = methodSignatureToUniqueName[method];
|
|
67
80
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
68
|
-
|
|
81
|
+
if (uniqueName !== method) {
|
|
82
|
+
const methodName = sanitizer.makeSafeStringTypeLiteral(uniqueName);
|
|
83
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodName}'}>`;
|
|
84
|
+
}
|
|
85
|
+
yield `| Expand<CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']> & {method: '${methodSigSafe}'}>`;
|
|
69
86
|
}
|
|
70
87
|
}
|
|
71
88
|
yield DecIndent;
|
|
72
89
|
}
|
|
73
90
|
yield* jsDoc('Defines arguments required for the deploy method.');
|
|
74
|
-
yield `export type ${name}
|
|
91
|
+
yield `export type ${name}DeployParams = Expand<Omit<AppFactoryDeployParams, 'createParams' | 'updateParams' | 'deleteParams'> & {`;
|
|
75
92
|
yield IncIndent;
|
|
76
|
-
yield `deployTimeParams?: TealTemplateParams`;
|
|
77
93
|
if (callConfig.createMethods.length) {
|
|
78
|
-
yield* jsDoc('
|
|
79
|
-
yield `
|
|
94
|
+
yield* jsDoc('Create transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)');
|
|
95
|
+
yield `createParams?: ${name}CreateCallParams`;
|
|
80
96
|
}
|
|
81
97
|
if (callConfig.updateMethods.length) {
|
|
82
|
-
yield* jsDoc('
|
|
83
|
-
yield `
|
|
98
|
+
yield* jsDoc('Update transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)');
|
|
99
|
+
yield `updateParams?: ${name}UpdateCallParams`;
|
|
84
100
|
}
|
|
85
101
|
if (callConfig.deleteMethods.length) {
|
|
86
|
-
yield* jsDoc('
|
|
87
|
-
yield `
|
|
102
|
+
yield* jsDoc('Delete transaction parameters to use if a create needs to be issued as part of deployment; use `method` to define ABI call (if available) or leave out for a bare call (if available)');
|
|
103
|
+
yield `deleteParams?: ${name}DeleteCallParams`;
|
|
88
104
|
}
|
|
89
|
-
yield
|
|
105
|
+
yield DecIndent;
|
|
106
|
+
yield `}>`;
|
|
90
107
|
yield NewLine;
|
|
91
108
|
}
|
|
92
109
|
|
|
93
|
-
export { deployTypes, getCreateOnCompleteOptions };
|
|
110
|
+
export { deployTypes, getCallOnCompleteOptions, getCreateOnCompleteOptions };
|
|
94
111
|
//# sourceMappingURL=deploy-types.mjs.map
|