@algorandfoundation/algokit-client-generator 6.0.2-beta.1 → 7.0.0-alpha.2
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/client/app-client-context.d.ts +122 -0
- package/client/app-client-context.js +212 -0
- package/client/app-client-context.js.map +1 -0
- package/client/app-client-context.mjs +209 -0
- package/client/app-client-context.mjs.map +1 -0
- package/client/app-client.js +29 -51
- package/client/app-client.js.map +1 -1
- package/client/app-client.mjs +29 -51
- package/client/app-client.mjs.map +1 -1
- package/client/app-factory.js +23 -27
- package/client/app-factory.js.map +1 -1
- package/client/app-factory.mjs +23 -27
- package/client/app-factory.mjs.map +1 -1
- package/client/app-types.js +31 -60
- package/client/app-types.js.map +1 -1
- package/client/app-types.mjs +32 -61
- package/client/app-types.mjs.map +1 -1
- package/client/call-composer-types.js +31 -34
- package/client/call-composer-types.js.map +1 -1
- package/client/call-composer-types.mjs +31 -34
- package/client/call-composer-types.mjs.map +1 -1
- package/client/call-composer.js +24 -31
- package/client/call-composer.js.map +1 -1
- package/client/call-composer.mjs +24 -31
- package/client/call-composer.mjs.map +1 -1
- package/client/deploy-types.d.ts +1 -11
- package/client/deploy-types.js +28 -53
- package/client/deploy-types.js.map +1 -1
- package/client/deploy-types.mjs +29 -52
- package/client/deploy-types.mjs.map +1 -1
- package/client/generate.d.ts +1 -1
- package/client/generate.js +2 -2
- package/client/generate.js.map +1 -1
- package/client/generate.mjs +2 -2
- package/client/generate.mjs.map +1 -1
- package/client/generator-context.d.ts +3 -5
- package/client/generator-context.js +4 -10
- package/client/generator-context.js.map +1 -1
- package/client/generator-context.mjs +4 -10
- package/client/generator-context.mjs.map +1 -1
- package/client/helpers/contains-non-void-method.d.ts +2 -2
- package/client/helpers/contains-non-void-method.js +3 -2
- package/client/helpers/contains-non-void-method.js.map +1 -1
- package/client/helpers/contains-non-void-method.mjs +3 -2
- package/client/helpers/contains-non-void-method.mjs.map +1 -1
- package/client/helpers/get-equivalent-type.d.ts +3 -5
- package/client/helpers/get-equivalent-type.js +53 -54
- package/client/helpers/get-equivalent-type.js.map +1 -1
- package/client/helpers/get-equivalent-type.mjs +53 -55
- package/client/helpers/get-equivalent-type.mjs.map +1 -1
- package/client/imports.d.ts +1 -2
- package/client/imports.js +10 -19
- package/client/imports.js.map +1 -1
- package/client/imports.mjs +10 -19
- package/client/imports.mjs.map +1 -1
- package/client/params-factory.js +47 -50
- package/client/params-factory.js.map +1 -1
- package/client/params-factory.mjs +47 -50
- package/client/params-factory.mjs.map +1 -1
- package/package.json +2 -3
- package/schema/load.d.ts +1 -1
- package/schema/load.js.map +1 -1
- package/schema/load.mjs.map +1 -1
- package/client/helpers/get-call-config-summary.d.ts +0 -19
- package/client/helpers/get-call-config-summary.js +0 -60
- package/client/helpers/get-call-config-summary.js.map +0 -1
- package/client/helpers/get-call-config-summary.mjs +0 -57
- package/client/helpers/get-call-config-summary.mjs.map +0 -1
|
@@ -1,51 +1,50 @@
|
|
|
1
1
|
import { jsDoc, IncIndent, DecIndent, indent, DecIndentAndCloseBlock, NewLine } from '../output/writer.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import { getCreateOnCompleteOptions } from './deploy-types.mjs';
|
|
4
|
-
import { ABIMethod } from 'algosdk';
|
|
2
|
+
import { isAbiMethod } from './app-client-context.mjs';
|
|
5
3
|
|
|
6
4
|
function* paramsFactory(ctx) {
|
|
7
|
-
yield* jsDoc(`Exposes methods for constructing \`AppClient\` params objects for ABI calls to the ${ctx.name} smart contract`);
|
|
8
|
-
yield `export abstract class ${ctx.name}ParamsFactory {`;
|
|
5
|
+
yield* jsDoc(`Exposes methods for constructing \`AppClient\` params objects for ABI calls to the ${ctx.app.name.original} smart contract`);
|
|
6
|
+
yield `export abstract class ${ctx.app.name.makeSafeTypeIdentifier}ParamsFactory {`;
|
|
9
7
|
yield IncIndent;
|
|
10
8
|
yield* opMethods(ctx);
|
|
11
9
|
for (const method of ctx.app.methods) {
|
|
10
|
+
if (!method.callActions.noOp)
|
|
11
|
+
continue;
|
|
12
12
|
yield* callFactoryMethod(ctx, method);
|
|
13
13
|
}
|
|
14
14
|
yield DecIndent;
|
|
15
15
|
yield '}';
|
|
16
16
|
}
|
|
17
17
|
function* opMethods(ctx) {
|
|
18
|
-
const { app
|
|
18
|
+
const { app } = ctx;
|
|
19
19
|
if (ctx.mode === 'full') {
|
|
20
|
-
yield* operationMethod(ctx, `Constructs create ABI call params for the ${app.name} smart contract`,
|
|
21
|
-
yield* operationMethod(ctx, `Constructs update ABI call params for the ${app.name} smart contract`,
|
|
22
|
-
yield* operationMethod(ctx, `Constructs delete ABI call params for the ${app.name} smart contract`,
|
|
20
|
+
yield* operationMethod(ctx, `Constructs create ABI call params for the ${app.name} smart contract`, app.createMethods, 'create', true);
|
|
21
|
+
yield* operationMethod(ctx, `Constructs update ABI call params for the ${app.name} smart contract`, app.updateMethods, 'update', true);
|
|
22
|
+
yield* operationMethod(ctx, `Constructs delete ABI call params for the ${app.name} smart contract`, app.deleteMethods, 'delete');
|
|
23
23
|
}
|
|
24
|
-
yield* operationMethod(ctx, `Constructs opt-in ABI call params for the ${app.name} smart contract`,
|
|
25
|
-
yield* operationMethod(ctx, `Constructs close out ABI call params for the ${app.name} smart contract`,
|
|
24
|
+
yield* operationMethod(ctx, `Constructs opt-in ABI call params for the ${app.name} smart contract`, app.optInMethods, 'optIn');
|
|
25
|
+
yield* operationMethod(ctx, `Constructs close out ABI call params for the ${app.name} smart contract`, app.closeOutMethods, 'closeOut');
|
|
26
26
|
}
|
|
27
27
|
function* operationMethod(ctx, description, methods, verb, includeCompilation) {
|
|
28
|
-
const { app,
|
|
29
|
-
if (methods.
|
|
28
|
+
const { app, sanitizer, name } = ctx;
|
|
29
|
+
if (methods.some((m) => !m.isBare)) {
|
|
30
30
|
yield* jsDoc(`Gets available ${verb} ABI call param factories`);
|
|
31
31
|
yield `static get ${verb}() {`;
|
|
32
32
|
yield IncIndent;
|
|
33
33
|
yield `return {`;
|
|
34
34
|
yield IncIndent;
|
|
35
35
|
if (['create', 'update', 'delete'].includes(verb)) {
|
|
36
|
-
yield `_resolveByMethod<TParams extends ${
|
|
36
|
+
yield `_resolveByMethod<TParams extends ${app.name.makeSafeTypeIdentifier}${verb[0].toUpperCase()}${verb.substring(1)}CallParams & {method: string}>(params: TParams) {`;
|
|
37
37
|
yield IncIndent;
|
|
38
38
|
yield `switch(params.method) {`;
|
|
39
39
|
yield IncIndent;
|
|
40
|
-
for (const
|
|
41
|
-
if (
|
|
40
|
+
for (const method of methods) {
|
|
41
|
+
if (!isAbiMethod(method))
|
|
42
42
|
continue;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
yield `case '${sanitizer.makeSafeStringTypeLiteral(uniqueName)}':`;
|
|
43
|
+
if (method.baseNameIsUnique) {
|
|
44
|
+
yield `case '${method.name.makeSafeStringTypeLiteral}':`;
|
|
46
45
|
}
|
|
47
|
-
yield `case '${sanitizer.makeSafeStringTypeLiteral(
|
|
48
|
-
yield* indent(`return ${
|
|
46
|
+
yield `case '${sanitizer.makeSafeStringTypeLiteral(method.signature)}':`;
|
|
47
|
+
yield* indent(`return ${app.name.makeSafeTypeIdentifier}ParamsFactory.${verb}${sanitizer.getSafeMemberAccessor(sanitizer.makeSafeMethodIdentifier(method.uniqueName.original))}(params)`);
|
|
49
48
|
}
|
|
50
49
|
yield DecIndentAndCloseBlock;
|
|
51
50
|
// Ordinarily we'd pop in the params.method value, but we can't here since it knows at compile time the type of params.method is never
|
|
@@ -54,40 +53,38 @@ function* operationMethod(ctx, description, methods, verb, includeCompilation) {
|
|
|
54
53
|
yield '},';
|
|
55
54
|
yield NewLine;
|
|
56
55
|
}
|
|
57
|
-
for (const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
56
|
+
for (const method of methods) {
|
|
57
|
+
if (!isAbiMethod(method))
|
|
58
|
+
continue;
|
|
59
|
+
const onComplete = verb === 'create' ? method.createActions.inputType : undefined;
|
|
60
|
+
const uniqueName = method.uniqueName.original;
|
|
61
|
+
yield* jsDoc({
|
|
62
|
+
description: `${description} using the ${method.signature} ABI method`,
|
|
63
|
+
params: {
|
|
64
|
+
params: `Parameters for the call`,
|
|
65
|
+
},
|
|
66
|
+
returns: 'An `AppClientMethodCallParams` object for the call',
|
|
67
|
+
});
|
|
68
|
+
yield* factoryMethod({
|
|
69
|
+
isNested: true,
|
|
70
|
+
sanitizer,
|
|
71
|
+
name: sanitizer.makeSafeMethodIdentifier(uniqueName),
|
|
72
|
+
signature: method.signature,
|
|
73
|
+
args: method.args,
|
|
74
|
+
additionalParamTypes: `${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.typeLiteral ? ` & ${onComplete.typeLiteral}` : ''}`,
|
|
75
|
+
contractName: name,
|
|
76
|
+
});
|
|
79
77
|
}
|
|
80
78
|
yield DecIndentAndCloseBlock;
|
|
81
79
|
yield DecIndentAndCloseBlock;
|
|
82
80
|
yield NewLine;
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
|
-
function* callFactoryMethod({
|
|
86
|
-
|
|
87
|
-
if (!callConfig.callMethods.includes(methodSignature))
|
|
83
|
+
function* callFactoryMethod({ sanitizer, name }, method) {
|
|
84
|
+
if (!method.callActions.any || !isAbiMethod(method))
|
|
88
85
|
return;
|
|
89
86
|
yield* jsDoc({
|
|
90
|
-
description: `Constructs a no op call for the ${
|
|
87
|
+
description: `Constructs a no op call for the ${method.signature} ABI method`,
|
|
91
88
|
abiDescription: method.desc,
|
|
92
89
|
params: {
|
|
93
90
|
params: `Parameters for the call`,
|
|
@@ -97,8 +94,8 @@ function* callFactoryMethod({ methodSignatureToUniqueName, callConfig, sanitizer
|
|
|
97
94
|
yield* factoryMethod({
|
|
98
95
|
isNested: false,
|
|
99
96
|
sanitizer,
|
|
100
|
-
name:
|
|
101
|
-
signature:
|
|
97
|
+
name: method.uniqueName.makeSafeMethodIdentifier,
|
|
98
|
+
signature: method.signature,
|
|
102
99
|
args: method.args,
|
|
103
100
|
additionalParamTypes: ' & CallOnComplete',
|
|
104
101
|
contractName: name,
|
|
@@ -114,7 +111,7 @@ function* factoryMethod(m) {
|
|
|
114
111
|
yield '...params,';
|
|
115
112
|
yield `method: '${methodSigSafe}' as const,`;
|
|
116
113
|
yield `args: Array.isArray(params.args) ? params.args : [${args
|
|
117
|
-
.map((a, i) => `params.args${sanitizer.getSafeMemberAccessor(
|
|
114
|
+
.map((a, i) => `params.args${sanitizer.getSafeMemberAccessor(a.name?.makeSafePropertyIdentifier ?? `arg${i + 1}`)}`)
|
|
118
115
|
.join(', ')}],`;
|
|
119
116
|
yield DecIndent;
|
|
120
117
|
yield '}';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params-factory.mjs","sources":["../../src/client/params-factory.ts"],"sourcesContent":["import { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, indent, jsDoc, NewLine } from '../output/writer'\nimport { GeneratorContext } from './generator-context'\nimport { BARE_CALL, MethodList } from './helpers/get-call-config-summary'\nimport { getCreateOnCompleteOptions } from './deploy-types'\nimport { Sanitizer } from '../util/sanitization'\nimport { Method } from '@algorandfoundation/algokit-utils/types/app-arc56'\nimport { ABIMethod } from 'algosdk'\n\nexport function* paramsFactory(ctx: GeneratorContext): DocumentParts {\n yield* jsDoc(`Exposes methods for constructing \\`AppClient\\` params objects for ABI calls to the ${ctx.name} smart contract`)\n yield `export abstract class ${ctx.name}ParamsFactory {`\n yield IncIndent\n\n yield* opMethods(ctx)\n\n for (const method of ctx.app.methods) {\n yield* callFactoryMethod(ctx, method)\n }\n\n yield DecIndent\n\n yield '}'\n}\n\nfunction* opMethods(ctx: GeneratorContext): DocumentParts {\n const { app, callConfig } = ctx\n\n if (ctx.mode === 'full') {\n yield* operationMethod(\n ctx,\n `Constructs create ABI call params for the ${app.name} smart contract`,\n callConfig.createMethods,\n 'create',\n true,\n )\n yield* operationMethod(\n ctx,\n `Constructs update ABI call params for the ${app.name} smart contract`,\n callConfig.updateMethods,\n 'update',\n true,\n )\n yield* operationMethod(ctx, `Constructs delete ABI call params for the ${app.name} smart contract`, callConfig.deleteMethods, 'delete')\n }\n yield* operationMethod(ctx, `Constructs opt-in ABI call params for the ${app.name} smart contract`, callConfig.optInMethods, 'optIn')\n yield* operationMethod(\n ctx,\n `Constructs close out ABI call params for the ${app.name} smart contract`,\n callConfig.closeOutMethods,\n 'closeOut',\n )\n}\n\nfunction* operationMethod(\n ctx: GeneratorContext,\n description: string,\n methods: MethodList,\n verb: 'create' | 'update' | 'optIn' | 'closeOut' | 'delete',\n includeCompilation?: boolean,\n): DocumentParts {\n const { app, methodSignatureToUniqueName, sanitizer, name } = ctx\n if (methods.length > 0 && methods.some((m) => m !== BARE_CALL)) {\n yield* jsDoc(`Gets available ${verb} ABI call param factories`)\n yield `static get ${verb}() {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n\n if (['create', 'update', 'delete'].includes(verb)) {\n yield `_resolveByMethod<TParams extends ${ctx.name}${verb[0].toUpperCase()}${verb.substring(1)}CallParams & {method: string}>(params: TParams) {`\n yield IncIndent\n yield `switch(params.method) {`\n yield IncIndent\n\n for (const methodSig of methods) {\n if (methodSig === BARE_CALL) continue\n\n const uniqueName = methodSignatureToUniqueName[methodSig]\n if (uniqueName !== methodSig) {\n yield `case '${sanitizer.makeSafeStringTypeLiteral(uniqueName)}':`\n }\n yield `case '${sanitizer.makeSafeStringTypeLiteral(methodSig)}':`\n yield* indent(\n `return ${ctx.name}ParamsFactory.${verb}${sanitizer.getSafeMemberAccessor(sanitizer.makeSafeMethodIdentifier(uniqueName))}(params)`,\n )\n }\n yield DecIndentAndCloseBlock\n\n // Ordinarily we'd pop in the params.method value, but we can't here since it knows at compile time the type of params.method is never\n yield `throw new Error(\\`Unknown ' + verb + ' method\\`)`\n yield DecIndent\n yield '},'\n yield NewLine\n }\n\n for (const methodSig of methods) {\n const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined\n if (methodSig !== BARE_CALL) {\n const method = app.methods.find((m) => new ABIMethod(m).getSignature() === methodSig)!\n const uniqueName = methodSignatureToUniqueName[methodSig]\n yield* jsDoc({\n description: `${description} using the ${methodSig} ABI method`,\n params: {\n params: `Parameters for the call`,\n },\n returns: 'An `AppClientMethodCallParams` object for the call',\n })\n yield* factoryMethod({\n isNested: true,\n sanitizer,\n name: sanitizer.makeSafeMethodIdentifier(uniqueName),\n signature: methodSig,\n args: method.args,\n additionalParamTypes: `${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n onComplete?.type ? ` & ${onComplete.type}` : ''\n }`,\n contractName: name,\n })\n }\n }\n yield DecIndentAndCloseBlock\n yield DecIndentAndCloseBlock\n yield NewLine\n }\n}\n\nfunction* callFactoryMethod({ methodSignatureToUniqueName, callConfig, sanitizer, name }: GeneratorContext, method: Method) {\n const methodSignature = new ABIMethod(method).getSignature()\n if (!callConfig.callMethods.includes(methodSignature)) return\n\n yield* jsDoc({\n description: `Constructs a no op call for the ${methodSignature} ABI method`,\n abiDescription: method.desc,\n params: {\n params: `Parameters for the call`,\n },\n returns: 'An `AppClientMethodCallParams` object for the call',\n })\n yield* factoryMethod({\n isNested: false,\n sanitizer,\n name: sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]),\n signature: methodSignature,\n args: method.args,\n additionalParamTypes: ' & CallOnComplete',\n contractName: name,\n })\n}\n\nfunction* factoryMethod(m: {\n isNested: boolean\n name?: string\n signature: string\n args: Array<{ name?: string }>\n additionalParamTypes?: string\n sanitizer: Sanitizer\n contractName: string\n}) {\n const { isNested, name, signature, args, additionalParamTypes, sanitizer, contractName } = m\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(signature)\n yield `${isNested ? '' : 'static '}${name}(params: CallParams<${contractName}Args['obj']['${methodSigSafe}'] | ${contractName}Args['tuple']['${methodSigSafe}']>${additionalParamTypes}): AppClientMethodCallParams${additionalParamTypes} {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n yield '...params,'\n yield `method: '${methodSigSafe}' as const,`\n yield `args: Array.isArray(params.args) ? params.args : [${args\n .map((a, i) => `params.args${sanitizer.getSafeMemberAccessor(sanitizer.makeSafePropertyIdentifier(a.name ?? `arg${i + 1}`))}`)\n .join(', ')}],`\n yield DecIndent\n yield '}'\n yield DecIndent\n yield `}${isNested ? ',' : ''}`\n}\n"],"names":[],"mappings":";;;;;AAQM,UAAW,aAAa,CAAC,GAAqB,EAAA;IAClD,OAAO,KAAK,CAAC,CAAA,mFAAA,EAAsF,GAAG,CAAC,IAAI,CAAA,eAAA,CAAiB,CAAC;AAC7H,IAAA,MAAM,CAAA,sBAAA,EAAyB,GAAG,CAAC,IAAI,iBAAiB;AACxD,IAAA,MAAM,SAAS;AAEf,IAAA,OAAO,SAAS,CAAC,GAAG,CAAC;IAErB,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE;QACpC,OAAO,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC;IACvC;AAEA,IAAA,MAAM,SAAS;AAEf,IAAA,MAAM,GAAG;AACX;AAEA,UAAU,SAAS,CAAC,GAAqB,EAAA;AACvC,IAAA,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,GAAG;AAE/B,IAAA,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE;QACvB,OAAO,eAAe,CACpB,GAAG,EACH,CAAA,0CAAA,EAA6C,GAAG,CAAC,IAAI,iBAAiB,EACtE,UAAU,CAAC,aAAa,EACxB,QAAQ,EACR,IAAI,CACL;QACD,OAAO,eAAe,CACpB,GAAG,EACH,CAAA,0CAAA,EAA6C,GAAG,CAAC,IAAI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CAAA,EAAI,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAA,CAAE;AACjC;;;;"}
|
|
1
|
+
{"version":3,"file":"params-factory.mjs","sources":["../../src/client/params-factory.ts"],"sourcesContent":["import { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, indent, jsDoc, NewLine } from '../output/writer'\nimport { GeneratorContext } from './generator-context'\nimport { Sanitizer } from '../util/sanitization'\nimport { AppClientMethodContext, MethodArgClientContext, isAbiMethod } from './app-client-context'\n\nexport function* paramsFactory(ctx: GeneratorContext): DocumentParts {\n yield* jsDoc(`Exposes methods for constructing \\`AppClient\\` params objects for ABI calls to the ${ctx.app.name.original} smart contract`)\n yield `export abstract class ${ctx.app.name.makeSafeTypeIdentifier}ParamsFactory {`\n yield IncIndent\n\n yield* opMethods(ctx)\n\n for (const method of ctx.app.methods) {\n if (!method.callActions.noOp) continue\n yield* callFactoryMethod(ctx, method)\n }\n\n yield DecIndent\n\n yield '}'\n}\n\nfunction* opMethods(ctx: GeneratorContext): DocumentParts {\n const { app } = ctx\n\n if (ctx.mode === 'full') {\n yield* operationMethod(ctx, `Constructs create ABI call params for the ${app.name} smart contract`, app.createMethods, 'create', true)\n yield* operationMethod(ctx, `Constructs update ABI call params for the ${app.name} smart contract`, app.updateMethods, 'update', true)\n yield* operationMethod(ctx, `Constructs delete ABI call params for the ${app.name} smart contract`, app.deleteMethods, 'delete')\n }\n yield* operationMethod(ctx, `Constructs opt-in ABI call params for the ${app.name} smart contract`, app.optInMethods, 'optIn')\n yield* operationMethod(ctx, `Constructs close out ABI call params for the ${app.name} smart contract`, app.closeOutMethods, 'closeOut')\n}\n\nfunction* operationMethod(\n ctx: GeneratorContext,\n description: string,\n methods: AppClientMethodContext[],\n verb: 'create' | 'update' | 'optIn' | 'closeOut' | 'delete',\n includeCompilation?: boolean,\n): DocumentParts {\n const { app, sanitizer, name } = ctx\n if (methods.some((m) => !m.isBare)) {\n yield* jsDoc(`Gets available ${verb} ABI call param factories`)\n yield `static get ${verb}() {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n\n if (['create', 'update', 'delete'].includes(verb)) {\n yield `_resolveByMethod<TParams extends ${app.name.makeSafeTypeIdentifier}${verb[0].toUpperCase()}${verb.substring(1)}CallParams & {method: string}>(params: TParams) {`\n yield IncIndent\n yield `switch(params.method) {`\n yield IncIndent\n\n for (const method of methods) {\n if (!isAbiMethod(method)) continue\n if (method.baseNameIsUnique) {\n yield `case '${method.name.makeSafeStringTypeLiteral}':`\n }\n yield `case '${sanitizer.makeSafeStringTypeLiteral(method.signature)}':`\n yield* indent(\n `return ${app.name.makeSafeTypeIdentifier}ParamsFactory.${verb}${sanitizer.getSafeMemberAccessor(sanitizer.makeSafeMethodIdentifier(method.uniqueName.original))}(params)`,\n )\n }\n yield DecIndentAndCloseBlock\n\n // Ordinarily we'd pop in the params.method value, but we can't here since it knows at compile time the type of params.method is never\n yield `throw new Error(\\`Unknown ' + verb + ' method\\`)`\n yield DecIndent\n yield '},'\n yield NewLine\n }\n\n for (const method of methods) {\n if (!isAbiMethod(method)) continue\n const onComplete = verb === 'create' ? method.createActions.inputType : undefined\n\n const uniqueName = method.uniqueName.original\n yield* jsDoc({\n description: `${description} using the ${method.signature} ABI method`,\n params: {\n params: `Parameters for the call`,\n },\n returns: 'An `AppClientMethodCallParams` object for the call',\n })\n yield* factoryMethod({\n isNested: true,\n sanitizer,\n name: sanitizer.makeSafeMethodIdentifier(uniqueName),\n signature: method.signature,\n args: method.args,\n additionalParamTypes: `${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n onComplete?.typeLiteral ? ` & ${onComplete.typeLiteral}` : ''\n }`,\n contractName: name,\n })\n }\n yield DecIndentAndCloseBlock\n yield DecIndentAndCloseBlock\n yield NewLine\n }\n}\n\nfunction* callFactoryMethod({ sanitizer, name }: GeneratorContext, method: AppClientMethodContext) {\n if (!method.callActions.any || !isAbiMethod(method)) return\n\n yield* jsDoc({\n description: `Constructs a no op call for the ${method.signature} ABI method`,\n abiDescription: method.desc,\n params: {\n params: `Parameters for the call`,\n },\n returns: 'An `AppClientMethodCallParams` object for the call',\n })\n yield* factoryMethod({\n isNested: false,\n sanitizer,\n name: method.uniqueName.makeSafeMethodIdentifier,\n signature: method.signature,\n args: method.args,\n additionalParamTypes: ' & CallOnComplete',\n contractName: name,\n })\n}\n\nfunction* factoryMethod(m: {\n isNested: boolean\n name?: string\n signature: string\n args: MethodArgClientContext[]\n additionalParamTypes?: string\n sanitizer: Sanitizer\n contractName: string\n}) {\n const { isNested, name, signature, args, additionalParamTypes, sanitizer, contractName } = m\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(signature)\n yield `${isNested ? '' : 'static '}${name}(params: CallParams<${contractName}Args['obj']['${methodSigSafe}'] | ${contractName}Args['tuple']['${methodSigSafe}']>${additionalParamTypes}): AppClientMethodCallParams${additionalParamTypes} {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n yield '...params,'\n yield `method: '${methodSigSafe}' as const,`\n yield `args: Array.isArray(params.args) ? params.args : [${args\n .map((a, i) => `params.args${sanitizer.getSafeMemberAccessor(a.name?.makeSafePropertyIdentifier ?? `arg${i + 1}`)}`)\n .join(', ')}],`\n yield DecIndent\n yield '}'\n yield DecIndent\n yield `}${isNested ? ',' : ''}`\n}\n"],"names":[],"mappings":";;;AAKM,UAAW,aAAa,CAAC,GAAqB,EAAA;AAClD,IAAA,OAAO,KAAK,CAAC,sFAAsF,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAA,eAAA,CAAiB,CAAC;IAC1I,MAAM,CAAA,sBAAA,EAAyB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAA,eAAA,CAAiB;AACnF,IAAA,MAAM,SAAS;AAEf,IAAA,OAAO,SAAS,CAAC,GAAG,CAAC;IAErB,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE;AACpC,QAAA,IAAI,CAAC,MAAM,CAAC,WAAW,CAA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AAC,CAAC,CAAC,IAAI,EAAE,0BAA0B,IAAI,CAAA,GAAA,EAAM,CAAC,GAAG,CAAC,CAAA,CAAE,CAAC,CAAA,CAAE;AAClH,SAAA,IAAI,CAAC,IAAI,CAAC,CAAA,EAAA,CAAI;AACjB,IAAA,MAAM,SAAS;AACf,IAAA,MAAM,GAAG;AACT,IAAA,MAAM,SAAS;IACf,MAAM,CAAA,CAAA,EAAI,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAA,CAAE;AACjC;;;;"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"**"
|
|
7
7
|
],
|
|
8
8
|
"name": "@algorandfoundation/algokit-client-generator",
|
|
9
|
-
"version": "
|
|
9
|
+
"version": "7.0.0-alpha.2",
|
|
10
10
|
"description": "Generates a TypeScript client for interacting with, and deploying ARC-0032 smart contracts on the Algorand Blockchain.",
|
|
11
11
|
"module": "index.mjs",
|
|
12
12
|
"private": false,
|
|
@@ -27,8 +27,7 @@
|
|
|
27
27
|
"jsonschema": "^1.5.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@algorandfoundation/algokit-utils": "^
|
|
31
|
-
"algosdk": "^3.2.0"
|
|
30
|
+
"@algorandfoundation/algokit-utils": "^10.0.0-alpha.20"
|
|
32
31
|
},
|
|
33
32
|
"publishConfig": {
|
|
34
33
|
"access": "public"
|
package/schema/load.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Arc56Contract } from '@algorandfoundation/algokit-utils/
|
|
1
|
+
import { Arc56Contract } from '@algorandfoundation/algokit-utils/abi';
|
|
2
2
|
export declare function loadApplicationJson(appJsonPath: string): Promise<Arc56Contract>;
|
|
3
3
|
export declare function validateApplicationJson(json: unknown, appJsonPath: string): Arc56Contract;
|
package/schema/load.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","sources":["../../src/schema/load.ts"],"sourcesContent":["import { Schema, Validator } from 'jsonschema'\nimport { boom } from '../util/boom'\nimport arc32Schema from './application.schema.json' with { type: 'json' }\nimport arc56Schema from './arc56.schema.json' with { type: 'json' }\nimport contractSchema from './contract.schema.json' with { type: 'json' }\nimport { Arc56Contract } from '@algorandfoundation/algokit-utils/
|
|
1
|
+
{"version":3,"file":"load.js","sources":["../../src/schema/load.ts"],"sourcesContent":["import { Schema, Validator } from 'jsonschema'\nimport { boom } from '../util/boom'\nimport arc32Schema from './application.schema.json' with { type: 'json' }\nimport arc56Schema from './arc56.schema.json' with { type: 'json' }\nimport contractSchema from './contract.schema.json' with { type: 'json' }\nimport { Arc56Contract } from '@algorandfoundation/algokit-utils/abi'\nimport { AppSpec, arc32ToArc56 } from '@algorandfoundation/algokit-utils/types/app-spec'\n\nexport async function loadApplicationJson(appJsonPath: string): Promise<Arc56Contract> {\n const fs = await import('fs')\n if (!fs.existsSync(appJsonPath)) boom(`Could not find application.json file at ${appJsonPath}`)\n\n let jsonText = fs.readFileSync(appJsonPath, 'utf-8')\n let file = JSON.parse(jsonText)\n // Temporary to get backwards compatibility with TEALScript draft ARC-56\n if (!('contract' in file) /* ARC-56 */) {\n jsonText = jsonText.replace(/ype\":\\s*\"bytes\"/g, 'ype\":\"AVMBytes\"').replace(/import\\(.+?\\)\\./g, '')\n file = JSON.parse(jsonText)\n }\n\n return validateApplicationJson(file, appJsonPath)\n}\n\nexport function validateApplicationJson(json: unknown, appJsonPath: string): Arc56Contract {\n if (typeof json !== 'object') boom(`Could not parse ${appJsonPath} as JSON object`)\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n if ('contract' in (json as any)) {\n // ARC-32\n const arc32Validator = new Validator()\n arc32Validator.addSchema(contractSchema, '/contract.schema.json')\n const arc32Result = arc32Validator.validate(json, arc32Schema as unknown as Schema)\n if (!arc32Result.valid) boom(`Could not parse ${appJsonPath} as ARC-32.\\n${arc32Result}`)\n return arc32ToArc56(json as AppSpec)\n }\n // ARC-56\n const arc56Validator = new Validator()\n const arc56Result = arc56Validator.validate(json, arc56Schema as unknown as Schema)\n if (!arc56Result.valid) boom(`Could not parse ${appJsonPath} as ARC-56.\\n${arc56Result}`)\n return json as Arc56Contract\n}\n"],"names":["boom","Validator","contractSchema","arc32Schema","arc32ToArc56","arc56Schema"],"mappings":";;;;;;;;;AAQO,eAAe,mBAAmB,CAAC,WAAmB,EAAA;AAC3D,IAAA,MAAM,EAAE,GAAG,MAAM,OAAO,IAAI,CAAC;AAC7B,IAAA,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;AAAE,QAAAA,SAAI,CAAC,CAAA,wCAAA,EAA2C,WAAW,CAAA,CAAE,CAAC;IAE/F,IAAI,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC;IACpD,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;;IAE/B,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC,eAAe;AACtC,QAAA,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;AAClG,QAAA,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B;AAEA,IAAA,OAAO,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC;AACnD;AAEM,SAAU,uBAAuB,CAAC,IAAa,EAAE,WAAmB,EAAA;IACxE,IAAI,OAAO,IAAI,KAAK,QAAQ;AAAE,QAAAA,SAAI,CAAC,CAAA,gBAAA,EAAmB,WAAW,CAAA,eAAA,CAAiB,CAAC;;AAGnF,IAAA,IAAI,UAAU,IAAK,IAAY,EAAE;;AAE/B,QAAA,MAAM,cAAc,GAAG,IAAIC,oBAAS,EAAE;AACtC,QAAA,cAAc,CAAC,SAAS,CAACC,uBAAc,EAAE,uBAAuB,CAAC;QACjE,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAEC,0BAAgC,CAAC;QACnF,IAAI,CAAC,WAAW,CAAC,KAAK;AAAE,YAAAH,SAAI,CAAC,CAAA,gBAAA,EAAmB,WAAW,gBAAgB,WAAW,CAAA,CAAE,CAAC;AACzF,QAAA,OAAOI,oBAAY,CAAC,IAAe,CAAC;IACtC;;AAEA,IAAA,MAAM,cAAc,GAAG,IAAIH,oBAAS,EAAE;IACtC,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAEI,oBAAgC,CAAC;IACnF,IAAI,CAAC,WAAW,CAAC,KAAK;AAAE,QAAAL,SAAI,CAAC,CAAA,gBAAA,EAAmB,WAAW,gBAAgB,WAAW,CAAA,CAAE,CAAC;AACzF,IAAA,OAAO,IAAqB;AAC9B;;;;;"}
|
package/schema/load.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.mjs","sources":["../../src/schema/load.ts"],"sourcesContent":["import { Schema, Validator } from 'jsonschema'\nimport { boom } from '../util/boom'\nimport arc32Schema from './application.schema.json' with { type: 'json' }\nimport arc56Schema from './arc56.schema.json' with { type: 'json' }\nimport contractSchema from './contract.schema.json' with { type: 'json' }\nimport { Arc56Contract } from '@algorandfoundation/algokit-utils/
|
|
1
|
+
{"version":3,"file":"load.mjs","sources":["../../src/schema/load.ts"],"sourcesContent":["import { Schema, Validator } from 'jsonschema'\nimport { boom } from '../util/boom'\nimport arc32Schema from './application.schema.json' with { type: 'json' }\nimport arc56Schema from './arc56.schema.json' with { type: 'json' }\nimport contractSchema from './contract.schema.json' with { type: 'json' }\nimport { Arc56Contract } from '@algorandfoundation/algokit-utils/abi'\nimport { AppSpec, arc32ToArc56 } from '@algorandfoundation/algokit-utils/types/app-spec'\n\nexport async function loadApplicationJson(appJsonPath: string): Promise<Arc56Contract> {\n const fs = await import('fs')\n if (!fs.existsSync(appJsonPath)) boom(`Could not find application.json file at ${appJsonPath}`)\n\n let jsonText = fs.readFileSync(appJsonPath, 'utf-8')\n let file = JSON.parse(jsonText)\n // Temporary to get backwards compatibility with TEALScript draft ARC-56\n if (!('contract' in file) /* ARC-56 */) {\n jsonText = jsonText.replace(/ype\":\\s*\"bytes\"/g, 'ype\":\"AVMBytes\"').replace(/import\\(.+?\\)\\./g, '')\n file = JSON.parse(jsonText)\n }\n\n return validateApplicationJson(file, appJsonPath)\n}\n\nexport function validateApplicationJson(json: unknown, appJsonPath: string): Arc56Contract {\n if (typeof json !== 'object') boom(`Could not parse ${appJsonPath} as JSON object`)\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n if ('contract' in (json as any)) {\n // ARC-32\n const arc32Validator = new Validator()\n arc32Validator.addSchema(contractSchema, '/contract.schema.json')\n const arc32Result = arc32Validator.validate(json, arc32Schema as unknown as Schema)\n if (!arc32Result.valid) boom(`Could not parse ${appJsonPath} as ARC-32.\\n${arc32Result}`)\n return arc32ToArc56(json as AppSpec)\n }\n // ARC-56\n const arc56Validator = new Validator()\n const arc56Result = arc56Validator.validate(json, arc56Schema as unknown as Schema)\n if (!arc56Result.valid) boom(`Could not parse ${appJsonPath} as ARC-56.\\n${arc56Result}`)\n return json as Arc56Contract\n}\n"],"names":[],"mappings":";;;;;;;AAQO,eAAe,mBAAmB,CAAC,WAAmB,EAAA;AAC3D,IAAA,MAAM,EAAE,GAAG,MAAM,OAAO,IAAI,CAAC;AAC7B,IAAA,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;AAAE,QAAA,IAAI,CAAC,CAAA,wCAAA,EAA2C,WAAW,CAAA,CAAE,CAAC;IAE/F,IAAI,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC;IACpD,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;;IAE/B,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC,eAAe;AACtC,QAAA,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;AAClG,QAAA,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B;AAEA,IAAA,OAAO,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC;AACnD;AAEM,SAAU,uBAAuB,CAAC,IAAa,EAAE,WAAmB,EAAA;IACxE,IAAI,OAAO,IAAI,KAAK,QAAQ;AAAE,QAAA,IAAI,CAAC,CAAA,gBAAA,EAAmB,WAAW,CAAA,eAAA,CAAiB,CAAC;;AAGnF,IAAA,IAAI,UAAU,IAAK,IAAY,EAAE;;AAE/B,QAAA,MAAM,cAAc,GAAG,IAAI,SAAS,EAAE;AACtC,QAAA,cAAc,CAAC,SAAS,CAAC,cAAc,EAAE,uBAAuB,CAAC;QACjE,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAgC,CAAC;QACnF,IAAI,CAAC,WAAW,CAAC,KAAK;AAAE,YAAA,IAAI,CAAC,CAAA,gBAAA,EAAmB,WAAW,gBAAgB,WAAW,CAAA,CAAE,CAAC;AACzF,QAAA,OAAO,YAAY,CAAC,IAAe,CAAC;IACtC;;AAEA,IAAA,MAAM,cAAc,GAAG,IAAI,SAAS,EAAE;IACtC,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAgC,CAAC;IACnF,IAAI,CAAC,WAAW,CAAC,KAAK;AAAE,QAAA,IAAI,CAAC,CAAA,gBAAA,EAAmB,WAAW,gBAAgB,WAAW,CAAA,CAAE,CAAC;AACzF,IAAA,OAAO,IAAqB;AAC9B;;;;"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56';
|
|
2
|
-
export declare const BARE_CALL: unique symbol;
|
|
3
|
-
export type MethodIdentifier = string | typeof BARE_CALL;
|
|
4
|
-
export type MethodList = Array<MethodIdentifier>;
|
|
5
|
-
export type OnComplete = 'NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication';
|
|
6
|
-
export type Actions = {
|
|
7
|
-
create: ('NoOp' | 'OptIn' | 'DeleteApplication')[];
|
|
8
|
-
call: OnComplete[];
|
|
9
|
-
};
|
|
10
|
-
export type CallConfigSummary = {
|
|
11
|
-
createMethods: MethodList;
|
|
12
|
-
callMethods: MethodList;
|
|
13
|
-
deleteMethods: MethodList;
|
|
14
|
-
updateMethods: MethodList;
|
|
15
|
-
optInMethods: MethodList;
|
|
16
|
-
closeOutMethods: MethodList;
|
|
17
|
-
};
|
|
18
|
-
export declare const getCallConfigSummary: (app: Arc56Contract) => CallConfigSummary;
|
|
19
|
-
export declare const getCreateOnComplete: (app: Arc56Contract, method: MethodIdentifier) => string;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var algosdk = require('algosdk');
|
|
4
|
-
|
|
5
|
-
const BARE_CALL = Symbol('bare');
|
|
6
|
-
const getCallConfigSummary = (app) => {
|
|
7
|
-
const result = {
|
|
8
|
-
createMethods: [],
|
|
9
|
-
callMethods: [],
|
|
10
|
-
deleteMethods: [],
|
|
11
|
-
updateMethods: [],
|
|
12
|
-
optInMethods: [],
|
|
13
|
-
closeOutMethods: [],
|
|
14
|
-
};
|
|
15
|
-
if (app.bareActions) {
|
|
16
|
-
addToConfig(result, BARE_CALL, app.bareActions);
|
|
17
|
-
}
|
|
18
|
-
if (app.methods) {
|
|
19
|
-
for (const m of app.methods) {
|
|
20
|
-
if (m.actions) {
|
|
21
|
-
addToConfig(result, new algosdk.ABIMethod(m).getSignature(), m.actions);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
const addToConfig = (result, method, config) => {
|
|
28
|
-
if (hasCall(config, 'NoOp')) {
|
|
29
|
-
result.callMethods.push(method);
|
|
30
|
-
}
|
|
31
|
-
if (hasCreate(config, 'NoOp') ||
|
|
32
|
-
hasCreate(config, 'OptIn') ||
|
|
33
|
-
hasCreate(config, 'CloseOut') ||
|
|
34
|
-
hasCreate(config, 'UpdateApplication') ||
|
|
35
|
-
hasCreate(config, 'DeleteApplication')) {
|
|
36
|
-
result.createMethods.push(method);
|
|
37
|
-
}
|
|
38
|
-
if (hasCall(config, 'DeleteApplication')) {
|
|
39
|
-
result.deleteMethods.push(method);
|
|
40
|
-
}
|
|
41
|
-
if (hasCall(config, 'UpdateApplication')) {
|
|
42
|
-
result.updateMethods.push(method);
|
|
43
|
-
}
|
|
44
|
-
if (hasCall(config, 'OptIn')) {
|
|
45
|
-
result.optInMethods.push(method);
|
|
46
|
-
}
|
|
47
|
-
if (hasCall(config, 'CloseOut')) {
|
|
48
|
-
result.closeOutMethods.push(method);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const hasCall = (config, action) => {
|
|
52
|
-
return config?.call.includes(action);
|
|
53
|
-
};
|
|
54
|
-
const hasCreate = (config, action) => {
|
|
55
|
-
return (config?.create).includes(action);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
exports.BARE_CALL = BARE_CALL;
|
|
59
|
-
exports.getCallConfigSummary = getCallConfigSummary;
|
|
60
|
-
//# sourceMappingURL=get-call-config-summary.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-call-config-summary.js","sources":["../../../src/client/helpers/get-call-config-summary.ts"],"sourcesContent":["import { pascalCase } from 'change-case'\nimport { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56'\nimport { ABIMethod } from 'algosdk'\n\nexport const BARE_CALL = Symbol('bare')\n\nexport type MethodIdentifier = string | typeof BARE_CALL\n\nexport type MethodList = Array<MethodIdentifier>\n\nexport type OnComplete = 'NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication'\n\nexport type Actions = {\n create: ('NoOp' | 'OptIn' | 'DeleteApplication')[]\n call: OnComplete[]\n}\n\nexport type CallConfigSummary = {\n createMethods: MethodList\n callMethods: MethodList\n deleteMethods: MethodList\n updateMethods: MethodList\n optInMethods: MethodList\n closeOutMethods: MethodList\n}\nexport const getCallConfigSummary = (app: Arc56Contract) => {\n const result: CallConfigSummary = {\n createMethods: [],\n callMethods: [],\n deleteMethods: [],\n updateMethods: [],\n optInMethods: [],\n closeOutMethods: [],\n }\n if (app.bareActions) {\n addToConfig(result, BARE_CALL, app.bareActions)\n }\n if (app.methods) {\n for (const m of app.methods) {\n if (m.actions) {\n addToConfig(result, new ABIMethod(m).getSignature(), m.actions)\n }\n }\n }\n return result\n}\n\nexport const getCreateOnComplete = (app: Arc56Contract, method: MethodIdentifier) => {\n const actions = method === BARE_CALL ? app.bareActions : app.methods?.find((m) => m.name === method)?.actions\n if (!actions) {\n return ''\n }\n const hasNoOp = actions.create.includes('NoOp')\n return `{ onCompleteAction${hasNoOp ? '?' : ''}: ${getCreateOnCompleteTypes(actions)} }`\n}\n\nconst getCreateOnCompleteTypes = (config: Actions) => {\n return config.create.map((oc) => `'${oc}' | OnApplicationComplete.${pascalCase(oc)}OC`).join(' | ')\n}\n\nconst addToConfig = (result: CallConfigSummary, method: MethodIdentifier, config: Actions) => {\n if (hasCall(config, 'NoOp')) {\n result.callMethods.push(method)\n }\n if (\n hasCreate(config, 'NoOp') ||\n hasCreate(config, 'OptIn') ||\n hasCreate(config, 'CloseOut') ||\n hasCreate(config, 'UpdateApplication') ||\n hasCreate(config, 'DeleteApplication')\n ) {\n result.createMethods.push(method)\n }\n if (hasCall(config, 'DeleteApplication')) {\n result.deleteMethods.push(method)\n }\n if (hasCall(config, 'UpdateApplication')) {\n result.updateMethods.push(method)\n }\n if (hasCall(config, 'OptIn')) {\n result.optInMethods.push(method)\n }\n if (hasCall(config, 'CloseOut')) {\n result.closeOutMethods.push(method)\n }\n}\n\nconst hasCall = (config: Actions | undefined, action: OnComplete) => {\n return config?.call.includes(action)\n}\nconst hasCreate = (config: Actions | undefined, action: OnComplete) => {\n return (config?.create as OnComplete[]).includes(action)\n}\n"],"names":["ABIMethod"],"mappings":";;;;MAIa,SAAS,GAAG,MAAM,CAAC,MAAM;AAqB/B,MAAM,oBAAoB,GAAG,CAAC,GAAkB,KAAI;AACzD,IAAA,MAAM,MAAM,GAAsB;AAChC,QAAA,aAAa,EAAE,EAAE;AACjB,QAAA,WAAW,EAAE,EAAE;AACf,QAAA,aAAa,EAAE,EAAE;AACjB,QAAA,aAAa,EAAE,EAAE;AACjB,QAAA,YAAY,EAAE,EAAE;AAChB,QAAA,eAAe,EAAE,EAAE;KACpB;AACD,IAAA,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,WAAW,CAAC;IACjD;AACA,IAAA,IAAI,GAAG,CAAC,OAAO,EAAE;AACf,QAAA,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE;AAC3B,YAAA,IAAI,CAAC,CAAC,OAAO,EAAE;AACb,gBAAA,WAAW,CAAC,MAAM,EAAE,IAAIA,iBAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC;YACjE;QACF;IACF;AACA,IAAA,OAAO,MAAM;AACf;AAeA,MAAM,WAAW,GAAG,CAAC,MAAyB,EAAE,MAAwB,EAAE,MAAe,KAAI;AAC3F,IAAA,IAAI,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;AAC3B,QAAA,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;IACjC;AACA,IAAA,IACE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;AACzB,QAAA,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;AAC1B,QAAA,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;AAC7B,QAAA,SAAS,CAAC,MAAM,EAAE,mBAAmB,CAAC;AACtC,QAAA,SAAS,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACtC;AACA,QAAA,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;IACnC;AACA,IAAA,IAAI,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,EAAE;AACxC,QAAA,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;IACnC;AACA,IAAA,IAAI,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,EAAE;AACxC,QAAA,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;IACnC;AACA,IAAA,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;AAC5B,QAAA,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;IAClC;AACA,IAAA,IAAI,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE;AAC/B,QAAA,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;IACrC;AACF,CAAC;AAED,MAAM,OAAO,GAAG,CAAC,MAA2B,EAAE,MAAkB,KAAI;IAClE,OAAO,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AACtC,CAAC;AACD,MAAM,SAAS,GAAG,CAAC,MAA2B,EAAE,MAAkB,KAAI;IACpE,OAAO,CAAC,MAAM,EAAE,MAAuB,EAAC,QAAQ,CAAC,MAAM,CAAC;AAC1D,CAAC;;;;;"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ABIMethod } from 'algosdk';
|
|
2
|
-
|
|
3
|
-
const BARE_CALL = Symbol('bare');
|
|
4
|
-
const getCallConfigSummary = (app) => {
|
|
5
|
-
const result = {
|
|
6
|
-
createMethods: [],
|
|
7
|
-
callMethods: [],
|
|
8
|
-
deleteMethods: [],
|
|
9
|
-
updateMethods: [],
|
|
10
|
-
optInMethods: [],
|
|
11
|
-
closeOutMethods: [],
|
|
12
|
-
};
|
|
13
|
-
if (app.bareActions) {
|
|
14
|
-
addToConfig(result, BARE_CALL, app.bareActions);
|
|
15
|
-
}
|
|
16
|
-
if (app.methods) {
|
|
17
|
-
for (const m of app.methods) {
|
|
18
|
-
if (m.actions) {
|
|
19
|
-
addToConfig(result, new ABIMethod(m).getSignature(), m.actions);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
const addToConfig = (result, method, config) => {
|
|
26
|
-
if (hasCall(config, 'NoOp')) {
|
|
27
|
-
result.callMethods.push(method);
|
|
28
|
-
}
|
|
29
|
-
if (hasCreate(config, 'NoOp') ||
|
|
30
|
-
hasCreate(config, 'OptIn') ||
|
|
31
|
-
hasCreate(config, 'CloseOut') ||
|
|
32
|
-
hasCreate(config, 'UpdateApplication') ||
|
|
33
|
-
hasCreate(config, 'DeleteApplication')) {
|
|
34
|
-
result.createMethods.push(method);
|
|
35
|
-
}
|
|
36
|
-
if (hasCall(config, 'DeleteApplication')) {
|
|
37
|
-
result.deleteMethods.push(method);
|
|
38
|
-
}
|
|
39
|
-
if (hasCall(config, 'UpdateApplication')) {
|
|
40
|
-
result.updateMethods.push(method);
|
|
41
|
-
}
|
|
42
|
-
if (hasCall(config, 'OptIn')) {
|
|
43
|
-
result.optInMethods.push(method);
|
|
44
|
-
}
|
|
45
|
-
if (hasCall(config, 'CloseOut')) {
|
|
46
|
-
result.closeOutMethods.push(method);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const hasCall = (config, action) => {
|
|
50
|
-
return config?.call.includes(action);
|
|
51
|
-
};
|
|
52
|
-
const hasCreate = (config, action) => {
|
|
53
|
-
return (config?.create).includes(action);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export { BARE_CALL, getCallConfigSummary };
|
|
57
|
-
//# sourceMappingURL=get-call-config-summary.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-call-config-summary.mjs","sources":["../../../src/client/helpers/get-call-config-summary.ts"],"sourcesContent":["import { pascalCase } from 'change-case'\nimport { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56'\nimport { ABIMethod } from 'algosdk'\n\nexport const BARE_CALL = Symbol('bare')\n\nexport type MethodIdentifier = string | typeof BARE_CALL\n\nexport type MethodList = Array<MethodIdentifier>\n\nexport type OnComplete = 'NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication'\n\nexport type Actions = {\n create: ('NoOp' | 'OptIn' | 'DeleteApplication')[]\n call: OnComplete[]\n}\n\nexport type CallConfigSummary = {\n createMethods: MethodList\n callMethods: MethodList\n deleteMethods: MethodList\n updateMethods: MethodList\n optInMethods: MethodList\n closeOutMethods: MethodList\n}\nexport const getCallConfigSummary = (app: Arc56Contract) => {\n const result: CallConfigSummary = {\n createMethods: [],\n callMethods: [],\n deleteMethods: [],\n updateMethods: [],\n optInMethods: [],\n closeOutMethods: [],\n }\n if (app.bareActions) {\n addToConfig(result, BARE_CALL, app.bareActions)\n }\n if (app.methods) {\n for (const m of app.methods) {\n if (m.actions) {\n addToConfig(result, new ABIMethod(m).getSignature(), m.actions)\n }\n }\n }\n return result\n}\n\nexport const getCreateOnComplete = (app: Arc56Contract, method: MethodIdentifier) => {\n const actions = method === BARE_CALL ? app.bareActions : app.methods?.find((m) => m.name === method)?.actions\n if (!actions) {\n return ''\n }\n const hasNoOp = actions.create.includes('NoOp')\n return `{ onCompleteAction${hasNoOp ? '?' : ''}: ${getCreateOnCompleteTypes(actions)} }`\n}\n\nconst getCreateOnCompleteTypes = (config: Actions) => {\n return config.create.map((oc) => `'${oc}' | OnApplicationComplete.${pascalCase(oc)}OC`).join(' | ')\n}\n\nconst addToConfig = (result: CallConfigSummary, method: MethodIdentifier, config: Actions) => {\n if (hasCall(config, 'NoOp')) {\n result.callMethods.push(method)\n }\n if (\n hasCreate(config, 'NoOp') ||\n hasCreate(config, 'OptIn') ||\n hasCreate(config, 'CloseOut') ||\n hasCreate(config, 'UpdateApplication') ||\n hasCreate(config, 'DeleteApplication')\n ) {\n result.createMethods.push(method)\n }\n if (hasCall(config, 'DeleteApplication')) {\n result.deleteMethods.push(method)\n }\n if (hasCall(config, 'UpdateApplication')) {\n result.updateMethods.push(method)\n }\n if (hasCall(config, 'OptIn')) {\n result.optInMethods.push(method)\n }\n if (hasCall(config, 'CloseOut')) {\n result.closeOutMethods.push(method)\n }\n}\n\nconst hasCall = (config: Actions | undefined, action: OnComplete) => {\n return config?.call.includes(action)\n}\nconst hasCreate = (config: Actions | undefined, action: OnComplete) => {\n return (config?.create as OnComplete[]).includes(action)\n}\n"],"names":[],"mappings":";;MAIa,SAAS,GAAG,MAAM,CAAC,MAAM;AAqB/B,MAAM,oBAAoB,GAAG,CAAC,GAAkB,KAAI;AACzD,IAAA,MAAM,MAAM,GAAsB;AAChC,QAAA,aAAa,EAAE,EAAE;AACjB,QAAA,WAAW,EAAE,EAAE;AACf,QAAA,aAAa,EAAE,EAAE;AACjB,QAAA,aAAa,EAAE,EAAE;AACjB,QAAA,YAAY,EAAE,EAAE;AAChB,QAAA,eAAe,EAAE,EAAE;KACpB;AACD,IAAA,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,WAAW,CAAC;IACjD;AACA,IAAA,IAAI,GAAG,CAAC,OAAO,EAAE;AACf,QAAA,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE;AAC3B,YAAA,IAAI,CAAC,CAAC,OAAO,EAAE;AACb,gBAAA,WAAW,CAAC,MAAM,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC;YACjE;QACF;IACF;AACA,IAAA,OAAO,MAAM;AACf;AAeA,MAAM,WAAW,GAAG,CAAC,MAAyB,EAAE,MAAwB,EAAE,MAAe,KAAI;AAC3F,IAAA,IAAI,OAAO,CAAC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