@algorandfoundation/algokit-client-generator 2.6.1-beta.1 → 3.0.0-beta.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/{cli.cjs → cli.js} +8 -6
- package/cli.js.map +1 -0
- package/cli.mjs +4 -2
- package/cli.mjs.map +1 -0
- package/client/{app-types.cjs → app-types.js} +20 -16
- package/client/app-types.js.map +1 -0
- package/client/app-types.mjs +18 -14
- package/client/app-types.mjs.map +1 -0
- package/client/{call-client.cjs → call-client.js} +30 -21
- package/client/call-client.js.map +1 -0
- package/client/call-client.mjs +26 -17
- package/client/call-client.mjs.map +1 -0
- package/client/{call-composer-types.cjs → call-composer-types.js} +11 -9
- package/client/call-composer-types.js.map +1 -0
- package/client/call-composer-types.mjs +8 -6
- package/client/call-composer-types.mjs.map +1 -0
- package/client/{call-composer.cjs → call-composer.js} +16 -12
- package/client/call-composer.js.map +1 -0
- package/client/call-composer.mjs +13 -9
- package/client/call-composer.mjs.map +1 -0
- package/client/{call-factory.cjs → call-factory.js} +16 -12
- package/client/call-factory.js.map +1 -0
- package/client/call-factory.mjs +13 -9
- package/client/call-factory.mjs.map +1 -0
- package/client/deploy-types.d.ts +1 -1
- package/client/{deploy-types.cjs → deploy-types.js} +12 -9
- package/client/deploy-types.js.map +1 -0
- package/client/deploy-types.mjs +9 -6
- package/client/deploy-types.mjs.map +1 -0
- package/client/generate.d.ts +2 -1
- package/client/{generate.cjs → generate.js} +12 -11
- package/client/generate.js.map +1 -0
- package/client/generate.mjs +3 -2
- package/client/generate.mjs.map +1 -0
- package/client/generator-context.d.ts +7 -1
- package/client/{generator-context.cjs → generator-context.js} +17 -12
- package/client/generator-context.js.map +1 -0
- package/client/generator-context.mjs +16 -11
- package/client/generator-context.mjs.map +1 -0
- package/client/helpers/{get-call-config-summary.cjs → get-call-config-summary.js} +1 -0
- package/client/helpers/get-call-config-summary.js.map +1 -0
- package/client/helpers/get-call-config-summary.mjs +1 -0
- package/client/helpers/get-call-config-summary.mjs.map +1 -0
- package/client/helpers/{get-equivalent-type.cjs → get-equivalent-type.js} +1 -0
- package/client/helpers/get-equivalent-type.js.map +1 -0
- package/client/helpers/get-equivalent-type.mjs +1 -0
- package/client/helpers/get-equivalent-type.mjs.map +1 -0
- package/client/{imports.cjs → imports.js} +1 -0
- package/client/imports.js.map +1 -0
- package/client/imports.mjs +1 -0
- package/client/imports.mjs.map +1 -0
- package/client/{utility-types.cjs → utility-types.js} +2 -1
- package/client/utility-types.js.map +1 -0
- package/client/utility-types.mjs +1 -0
- package/client/utility-types.mjs.map +1 -0
- package/{index.cjs → index.js} +4 -3
- package/index.js.map +1 -0
- package/index.mjs +1 -0
- package/index.mjs.map +1 -0
- package/output/{writer.cjs → writer.js} +1 -0
- package/output/writer.js.map +1 -0
- package/output/writer.mjs +1 -0
- package/output/writer.mjs.map +1 -0
- package/package.json +4 -2
- package/schema/{application.schema.json.cjs → application.schema.json.js} +1 -0
- package/schema/application.schema.json.js.map +1 -0
- package/schema/application.schema.json.mjs +1 -0
- package/schema/application.schema.json.mjs.map +1 -0
- package/schema/{contract.schema.json.cjs → contract.schema.json.js} +1 -0
- package/schema/contract.schema.json.js.map +1 -0
- package/schema/contract.schema.json.mjs +1 -0
- package/schema/contract.schema.json.mjs.map +1 -0
- package/schema/{load.cjs → load.js} +4 -3
- package/schema/load.js.map +1 -0
- package/schema/load.mjs +1 -0
- package/schema/load.mjs.map +1 -0
- package/util/{boom.cjs → boom.js} +1 -0
- package/util/boom.js.map +1 -0
- package/util/boom.mjs +1 -0
- package/util/boom.mjs.map +1 -0
- package/util/{color-console.cjs → color-console.js} +1 -0
- package/util/color-console.js.map +1 -0
- package/util/color-console.mjs +1 -0
- package/util/color-console.mjs.map +1 -0
- package/util/sanitization.d.ts +12 -5
- package/util/sanitization.js +56 -0
- package/util/sanitization.js.map +1 -0
- package/util/sanitization.mjs +50 -7
- package/util/sanitization.mjs.map +1 -0
- package/util/sanitization.cjs +0 -17
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var writer = require('../output/writer.
|
|
4
|
-
var sanitization = require('../util/sanitization.cjs');
|
|
3
|
+
var writer = require('../output/writer.js');
|
|
5
4
|
var algokit = require('@algorandfoundation/algokit-utils');
|
|
6
|
-
var getCallConfigSummary = require('./helpers/get-call-config-summary.
|
|
7
|
-
var deployTypes = require('./deploy-types.
|
|
5
|
+
var getCallConfigSummary = require('./helpers/get-call-config-summary.js');
|
|
6
|
+
var deployTypes = require('./deploy-types.js');
|
|
8
7
|
|
|
9
8
|
function _interopNamespaceDefault(e) {
|
|
10
9
|
var n = Object.create(null);
|
|
@@ -44,7 +43,7 @@ function* opMethods(ctx) {
|
|
|
44
43
|
yield* operationMethod(ctx, `Constructs an opt in call for the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn');
|
|
45
44
|
yield* operationMethod(ctx, `Constructs a close out call for the ${app.contract.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
|
|
46
45
|
}
|
|
47
|
-
function* operationMethod({ app, methodSignatureToUniqueName }, description, methods, verb, includeCompilation) {
|
|
46
|
+
function* operationMethod({ app, methodSignatureToUniqueName, sanitizer }, description, methods, verb, includeCompilation) {
|
|
48
47
|
if (methods.length) {
|
|
49
48
|
yield* writer.jsDoc(`Gets available ${verb} call factories`);
|
|
50
49
|
yield `static get ${verb}() {`;
|
|
@@ -64,6 +63,7 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
|
|
|
64
63
|
yield* factoryMethod({
|
|
65
64
|
isNested: true,
|
|
66
65
|
name: 'bare',
|
|
66
|
+
sanitizer,
|
|
67
67
|
paramTypes: `BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
|
|
68
68
|
});
|
|
69
69
|
}
|
|
@@ -80,7 +80,8 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
|
|
|
80
80
|
});
|
|
81
81
|
yield* factoryMethod({
|
|
82
82
|
isNested: true,
|
|
83
|
-
|
|
83
|
+
sanitizer,
|
|
84
|
+
name: sanitizer.makeSafeMethodIdentifier(uniqueName),
|
|
84
85
|
signature: methodSig,
|
|
85
86
|
args: method.args,
|
|
86
87
|
paramTypes: `AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
|
|
@@ -92,7 +93,7 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
|
|
|
92
93
|
yield writer.NewLine;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
|
-
function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method) {
|
|
96
|
+
function* callFactoryMethod({ methodSignatureToUniqueName, callConfig, sanitizer }, method) {
|
|
96
97
|
const methodSignature = algokit__namespace.getABIMethodSignature(method);
|
|
97
98
|
if (!callConfig.callMethods.includes(methodSignature))
|
|
98
99
|
return;
|
|
@@ -107,21 +108,23 @@ function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method)
|
|
|
107
108
|
});
|
|
108
109
|
yield* factoryMethod({
|
|
109
110
|
isNested: false,
|
|
110
|
-
|
|
111
|
+
sanitizer,
|
|
112
|
+
name: sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]),
|
|
111
113
|
signature: methodSignature,
|
|
112
114
|
args: method.args,
|
|
113
115
|
paramTypes: 'AppClientCallCoreParams & CoreAppCallArgs',
|
|
114
116
|
});
|
|
115
117
|
}
|
|
116
|
-
function* factoryMethod({ isNested, name, signature, args, paramTypes, }) {
|
|
117
|
-
|
|
118
|
+
function* factoryMethod({ isNested, name, signature, args, paramTypes, sanitizer, }) {
|
|
119
|
+
const signatureSafe = signature && sanitizer.makeSafeStringTypeLiteral(signature);
|
|
120
|
+
yield `${isNested ? '' : 'static '}${name}(${signature === undefined ? '' : `args: MethodArgs<'${signatureSafe}'>, `}params: ${paramTypes}) {`;
|
|
118
121
|
yield writer.IncIndent;
|
|
119
122
|
yield `return {`;
|
|
120
123
|
yield writer.IncIndent;
|
|
121
124
|
if (signature) {
|
|
122
|
-
yield `method: '${
|
|
125
|
+
yield `method: '${signatureSafe}' as const,`;
|
|
123
126
|
yield `methodArgs: Array.isArray(args) ? args : [${args
|
|
124
|
-
.map((a) =>
|
|
127
|
+
.map((a) => `args${sanitizer.getSafeMemberAccessor(sanitizer.makeSafePropertyIdentifier(a.name))}`)
|
|
125
128
|
.join(', ')}],`;
|
|
126
129
|
}
|
|
127
130
|
else {
|
|
@@ -136,3 +139,4 @@ function* factoryMethod({ isNested, name, signature, args, paramTypes, }) {
|
|
|
136
139
|
}
|
|
137
140
|
|
|
138
141
|
exports.callFactory = callFactory;
|
|
142
|
+
//# sourceMappingURL=call-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-factory.js","sources":["../../src/client/call-factory.ts"],"sourcesContent":["import { ContractMethod } from '../schema/application'\nimport { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, jsDoc, NewLine } from '../output/writer'\nimport * as algokit from '@algorandfoundation/algokit-utils'\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'\n\nexport function* callFactory(ctx: GeneratorContext): DocumentParts {\n yield* jsDoc('Exposes methods for constructing all available smart contract calls')\n yield `export abstract class ${ctx.name}CallFactory {`\n yield IncIndent\n\n yield* opMethods(ctx)\n\n for (const method of ctx.app.contract.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 yield* operationMethod(\n ctx,\n `Constructs a create call for the ${app.contract.name} smart contract`,\n callConfig.createMethods,\n 'create',\n true,\n )\n yield* operationMethod(\n ctx,\n `Constructs an update call for the ${app.contract.name} smart contract`,\n callConfig.updateMethods,\n 'update',\n true,\n )\n yield* operationMethod(ctx, `Constructs a delete call for the ${app.contract.name} smart contract`, callConfig.deleteMethods, 'delete')\n yield* operationMethod(ctx, `Constructs an opt in call for the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn')\n yield* operationMethod(\n ctx,\n `Constructs a close out call for the ${app.contract.name} smart contract`,\n callConfig.closeOutMethods,\n 'closeOut',\n )\n}\n\nfunction* operationMethod(\n { app, methodSignatureToUniqueName, sanitizer }: GeneratorContext,\n description: string,\n methods: MethodList,\n verb: 'create' | 'update' | 'optIn' | 'closeOut' | 'delete',\n includeCompilation?: boolean,\n): DocumentParts {\n if (methods.length) {\n yield* jsDoc(`Gets available ${verb} call factories`)\n yield `static get ${verb}() {`\n yield IncIndent\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* jsDoc({\n description: `${description} using a bare call`,\n params: {\n params: `Any parameters for the call`,\n },\n returns: `A TypedCallParams object for the call`,\n })\n yield* factoryMethod({\n isNested: true,\n name: 'bare',\n sanitizer,\n paramTypes: `BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs${\n includeCompilation ? ' & AppClientCompilationParams' : ''\n }${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,\n })\n } else {\n const method = app.contract.methods.find((m) => algokit.getABIMethodSignature(m) === methodSig)!\n const uniqueName = methodSignatureToUniqueName[methodSig]\n yield* jsDoc({\n description: `${description} using the ${methodSig} ABI method`,\n params: {\n args: `Any args for the contract call`,\n params: `Any additional parameters for the call`,\n },\n returns: `A TypedCallParams 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 paramTypes: `AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n onComplete?.type ? ` & ${onComplete.type}` : ''\n }${onComplete?.isOptional !== false ? ' = {}' : ''}`,\n })\n }\n }\n yield DecIndentAndCloseBlock\n yield DecIndentAndCloseBlock\n yield NewLine\n }\n}\n\nfunction* callFactoryMethod({ methodSignatureToUniqueName, callConfig, sanitizer }: GeneratorContext, method: ContractMethod) {\n const methodSignature = algokit.getABIMethodSignature(method)\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 args: `Any args for the contract call`,\n params: `Any additional parameters for the call`,\n },\n returns: `A TypedCallParams 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 paramTypes: 'AppClientCallCoreParams & CoreAppCallArgs',\n })\n}\n\nfunction* factoryMethod({\n isNested,\n name,\n signature,\n args,\n paramTypes,\n sanitizer,\n}:\n | {\n isNested: boolean\n name?: string\n signature?: undefined\n args?: undefined\n paramTypes: string\n sanitizer: Sanitizer\n }\n | {\n isNested: boolean\n name?: string\n signature: string\n args: Array<{ name: string }>\n paramTypes: string\n sanitizer: Sanitizer\n }) {\n const signatureSafe = signature && sanitizer.makeSafeStringTypeLiteral(signature)\n yield `${isNested ? '' : 'static '}${name}(${signature === undefined ? '' : `args: MethodArgs<'${signatureSafe}'>, `}params: ${paramTypes}) {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n if (signature) {\n yield `method: '${signatureSafe}' as const,`\n yield `methodArgs: Array.isArray(args) ? args : [${args\n .map((a) => `args${sanitizer.getSafeMemberAccessor(sanitizer.makeSafePropertyIdentifier(a.name))}`)\n .join(', ')}],`\n } else {\n yield `method: undefined,`\n yield `methodArgs: undefined,`\n }\n\n yield '...params,'\n yield DecIndent\n yield '}'\n yield DecIndent\n yield `}${isNested ? ',' : ''}`\n}\n"],"names":["jsDoc","IncIndent","DecIndent","getCreateOnCompleteOptions","BARE_CALL","algokit","DecIndentAndCloseBlock","NewLine"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQe,UAAE,WAAW,CAAC,GAAqB,EAAA;AAChD,IAAA,OAAOA,YAAK,CAAC,qEAAqE,CAAC,CAAA;AACnF,IAAA,MAAM,CAAyB,sBAAA,EAAA,GAAG,CAAC,IAAI,eAAe,CAAA;AACtD,IAAA,MAAMC,gBAAS,CAAA;AAEf,IAAA,OAAO,SAAS,CAAC,GAAG,CAAC,CAAA;IAErB,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC7C,OAAO,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;KACtC;AAED,IAAA,MAAMC,gBAAS,CAAA;AAEf,IAAA,MAAM,GAAG,CAAA;AACX,CAAC;AAED,UAAU,SAAS,CAAC,GAAqB,EAAA;AACvC,IAAA,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;IAE/B,OAAO,eAAe,CACpB,GAAG,EACH,CAAA,iCAAA,EAAoC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAiB,eAAA,CAAA,EACtE,UAAU,CAAC,aAAa,EACxB,QAAQ,EACR,IAAI,CACL,CAAA;IACD,OAAO,eAAe,CACpB,GAAG,EACH,CAAA,kCAAA,EAAqC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAiB,eAAA,CAAA,EACvE,UAAU,CAAC,aAAa,EACxB,QAAQ,EACR,IAAI,CACL,CAAA;IACD,OAAO,eAAe,CAAC,GAAG,EAAE,CAAA,iCAAA,EAAoC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAA,eAAA,CAAiB,EAAE,UA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AC,yBAAyB,CAAC,SAAS,CAAC,CAAA;AACjF,IAAA,MAAM,CAAG,EAAA,QAAQ,GAAG,EAAE,GAAG,SAAS,CAAG,EAAA,IAAI,CAAI,CAAA,EAAA,SAAS,KAAK,SAAS,GAAG,EAAE,GAAG,CAAA,kBAAA,EAAqB,aAAa,CAAA,IAAA,CAAM,CAAW,QAAA,EAAA,UAAU,KAAK,CAAA;AAC9I,IAAA,MAAMC,gBAAS,CAAA;AACf,IAAA,MAAM,UAAU,CAAA;AAChB,IAAA,MAAMA,gBAAS,CAAA;IACf,IAAI,SAAS,EAAE;QACb,MAAM,CAAA,SAAA,EAAY,aAAa,CAAA,WAAA,CAAa,CAAA;AAC5C,QAAA,MAAM,6CAA6C,IAAI;aACpD,GAAG,CAAC,CAAC,CAAC,KAAK,CAAA,IAAA,EAAO,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA,CAAE,CAAC;AAClG,aAAA,IAAI,CAAC,IAAI,CAAC,CAAA,EAAA,CAAI,CAAA;KAClB;SAAM;AACL,QAAA,MAAM,oBAAoB,CAAA;AAC1B,QAAA,MAAM,wBAAwB,CAAA;KAC/B;AAED,IAAA,MAAM,YAAY,CAAA;AAClB,IAAA,MAAMC,gBAAS,CAAA;AACf,IAAA,MAAM,GAAG,CAAA;AACT,IAAA,MAAMA,gBAAS,CAAA;IACf,MAAM,CAAA,CAAA,EAAI,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAA,CAAE,CAAA;AACjC;;;;"}
|
package/client/call-factory.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsDoc, IncIndent, DecIndent, DecIndentAndCloseBlock, NewLine } from '../output/writer.mjs';
|
|
2
|
-
import { makeSafeMethodIdentifier, isSafeVariableIdentifier, makeSafePropertyIdentifier } from '../util/sanitization.mjs';
|
|
3
2
|
import * as algokit from '@algorandfoundation/algokit-utils';
|
|
4
3
|
import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
|
|
5
4
|
import { getCreateOnCompleteOptions } from './deploy-types.mjs';
|
|
@@ -23,7 +22,7 @@ function* opMethods(ctx) {
|
|
|
23
22
|
yield* operationMethod(ctx, `Constructs an opt in call for the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn');
|
|
24
23
|
yield* operationMethod(ctx, `Constructs a close out call for the ${app.contract.name} smart contract`, callConfig.closeOutMethods, 'closeOut');
|
|
25
24
|
}
|
|
26
|
-
function* operationMethod({ app, methodSignatureToUniqueName }, description, methods, verb, includeCompilation) {
|
|
25
|
+
function* operationMethod({ app, methodSignatureToUniqueName, sanitizer }, description, methods, verb, includeCompilation) {
|
|
27
26
|
if (methods.length) {
|
|
28
27
|
yield* jsDoc(`Gets available ${verb} call factories`);
|
|
29
28
|
yield `static get ${verb}() {`;
|
|
@@ -43,6 +42,7 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
|
|
|
43
42
|
yield* factoryMethod({
|
|
44
43
|
isNested: true,
|
|
45
44
|
name: 'bare',
|
|
45
|
+
sanitizer,
|
|
46
46
|
paramTypes: `BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
@@ -59,7 +59,8 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
|
|
|
59
59
|
});
|
|
60
60
|
yield* factoryMethod({
|
|
61
61
|
isNested: true,
|
|
62
|
-
|
|
62
|
+
sanitizer,
|
|
63
|
+
name: sanitizer.makeSafeMethodIdentifier(uniqueName),
|
|
63
64
|
signature: methodSig,
|
|
64
65
|
args: method.args,
|
|
65
66
|
paramTypes: `AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
|
|
@@ -71,7 +72,7 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
|
|
|
71
72
|
yield NewLine;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method) {
|
|
75
|
+
function* callFactoryMethod({ methodSignatureToUniqueName, callConfig, sanitizer }, method) {
|
|
75
76
|
const methodSignature = algokit.getABIMethodSignature(method);
|
|
76
77
|
if (!callConfig.callMethods.includes(methodSignature))
|
|
77
78
|
return;
|
|
@@ -86,21 +87,23 @@ function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method)
|
|
|
86
87
|
});
|
|
87
88
|
yield* factoryMethod({
|
|
88
89
|
isNested: false,
|
|
89
|
-
|
|
90
|
+
sanitizer,
|
|
91
|
+
name: sanitizer.makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]),
|
|
90
92
|
signature: methodSignature,
|
|
91
93
|
args: method.args,
|
|
92
94
|
paramTypes: 'AppClientCallCoreParams & CoreAppCallArgs',
|
|
93
95
|
});
|
|
94
96
|
}
|
|
95
|
-
function* factoryMethod({ isNested, name, signature, args, paramTypes, }) {
|
|
96
|
-
|
|
97
|
+
function* factoryMethod({ isNested, name, signature, args, paramTypes, sanitizer, }) {
|
|
98
|
+
const signatureSafe = signature && sanitizer.makeSafeStringTypeLiteral(signature);
|
|
99
|
+
yield `${isNested ? '' : 'static '}${name}(${signature === undefined ? '' : `args: MethodArgs<'${signatureSafe}'>, `}params: ${paramTypes}) {`;
|
|
97
100
|
yield IncIndent;
|
|
98
101
|
yield `return {`;
|
|
99
102
|
yield IncIndent;
|
|
100
103
|
if (signature) {
|
|
101
|
-
yield `method: '${
|
|
104
|
+
yield `method: '${signatureSafe}' as const,`;
|
|
102
105
|
yield `methodArgs: Array.isArray(args) ? args : [${args
|
|
103
|
-
.map((a) =>
|
|
106
|
+
.map((a) => `args${sanitizer.getSafeMemberAccessor(sanitizer.makeSafePropertyIdentifier(a.name))}`)
|
|
104
107
|
.join(', ')}],`;
|
|
105
108
|
}
|
|
106
109
|
else {
|
|
@@ -115,3 +118,4 @@ function* factoryMethod({ isNested, name, signature, args, paramTypes, }) {
|
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
export { callFactory };
|
|
121
|
+
//# sourceMappingURL=call-factory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-factory.mjs","sources":["../../src/client/call-factory.ts"],"sourcesContent":["import { ContractMethod } from '../schema/application'\nimport { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, jsDoc, NewLine } from '../output/writer'\nimport * as algokit from '@algorandfoundation/algokit-utils'\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'\n\nexport function* callFactory(ctx: GeneratorContext): DocumentParts {\n yield* jsDoc('Exposes methods for constructing all available smart contract calls')\n yield `export abstract class ${ctx.name}CallFactory {`\n yield IncIndent\n\n yield* opMethods(ctx)\n\n for (const method of ctx.app.contract.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 yield* operationMethod(\n ctx,\n `Constructs a create call for the ${app.contract.name} smart contract`,\n callConfig.createMethods,\n 'create',\n true,\n )\n yield* operationMethod(\n ctx,\n `Constructs an update call for the ${app.contract.name} smart contract`,\n callConfig.updateMethods,\n 'update',\n true,\n )\n yield* operationMethod(ctx, `Constructs a delete call for the ${app.contract.name} smart contract`, callConfig.deleteMethods, 'delete')\n yield* operationMethod(ctx, `Constructs an opt in call for the ${app.contract.name} smart contract`, callConfig.optInMethods, 'optIn')\n yield* operationMethod(\n ctx,\n `Constructs a close out call for the ${app.contract.name} smart contract`,\n callConfig.closeOutMethods,\n 'closeOut',\n )\n}\n\nfunction* operationMethod(\n { app, methodSignatureToUniqueName, sanitizer }: GeneratorContext,\n description: string,\n methods: MethodList,\n verb: 'create' | 'update' | 'optIn' | 'closeOut' | 'delete',\n includeCompilation?: boolean,\n): DocumentParts {\n if (methods.length) {\n yield* jsDoc(`Gets available ${verb} call factories`)\n yield `static get ${verb}() {`\n yield IncIndent\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* jsDoc({\n description: `${description} using a bare call`,\n params: {\n params: `Any parameters for the call`,\n },\n returns: `A TypedCallParams object for the call`,\n })\n yield* factoryMethod({\n isNested: true,\n name: 'bare',\n sanitizer,\n paramTypes: `BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs${\n includeCompilation ? ' & AppClientCompilationParams' : ''\n }${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,\n })\n } else {\n const method = app.contract.methods.find((m) => algokit.getABIMethodSignature(m) === methodSig)!\n const uniqueName = methodSignatureToUniqueName[methodSig]\n yield* jsDoc({\n description: `${description} using the ${methodSig} ABI method`,\n params: {\n args: `Any args for the contract call`,\n params: `Any additional parameters for the call`,\n },\n returns: `A TypedCallParams 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 paramTypes: `AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n onComplete?.type ? ` & ${onComplete.type}` : ''\n }${onComplete?.isOptional !== false ? ' = {}' : ''}`,\n })\n }\n }\n yield DecIndentAndCloseBlock\n yield DecIndentAndCloseBlock\n yield NewLine\n }\n}\n\nfunction* callFactoryMethod({ methodSignatureToUniqueName, callConfig, sanitizer }: GeneratorContext, method: ContractMethod) {\n const methodSignature = algokit.getABIMethodSignature(method)\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 args: `Any args for the contract call`,\n params: `Any additional parameters for the call`,\n },\n returns: `A TypedCallParams 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 paramTypes: 'AppClientCallCoreParams & CoreAppCallArgs',\n })\n}\n\nfunction* factoryMethod({\n isNested,\n name,\n signature,\n args,\n paramTypes,\n sanitizer,\n}:\n | {\n isNested: boolean\n name?: string\n signature?: undefined\n args?: undefined\n paramTypes: string\n sanitizer: Sanitizer\n }\n | {\n isNested: boolean\n name?: string\n signature: string\n args: Array<{ name: string }>\n paramTypes: string\n sanitizer: Sanitizer\n }) {\n const signatureSafe = signature && sanitizer.makeSafeStringTypeLiteral(signature)\n yield `${isNested ? '' : 'static '}${name}(${signature === undefined ? '' : `args: MethodArgs<'${signatureSafe}'>, `}params: ${paramTypes}) {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n if (signature) {\n yield `method: '${signatureSafe}' as const,`\n yield `methodArgs: Array.isArray(args) ? args : [${args\n .map((a) => `args${sanitizer.getSafeMemberAccessor(sanitizer.makeSafePropertyIdentifier(a.name))}`)\n .join(', ')}],`\n } else {\n yield `method: undefined,`\n yield `methodArgs: undefined,`\n }\n\n yield '...params,'\n yield DecIndent\n yield '}'\n yield DecIndent\n yield `}${isNested ? ',' : ''}`\n}\n"],"names":[],"mappings":";;;;;AAQe,UAAE,WAAW,CAAC,GAAqB,EAAA;AAChD,IAAA,OAAO,KAAK,CAAC,qEAAqE,CAAC,CAAA;AACnF,IAAA,MAAM,CAAyB,sBAAA,EAAA,GAAG,CAAC,IAAI,eAAe,CAAA;AACtD,IAAA,MAAM,SAAS,CAAA;AAEf,IAAA,OAAO,SAAS,CAAC,GAAG,CAAC,CA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CAAA,IAAA,EAAO,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA,CAAE,CAAC;AAClG,aAAA,IAAI,CAAC,IAAI,CAAC,CAAA,EAAA,CAAI,CAAA;KAClB;SAAM;AACL,QAAA,MAAM,oBAAoB,CAAA;AAC1B,QAAA,MAAM,wBAAwB,CAAA;KAC/B;AAED,IAAA,MAAM,YAAY,CAAA;AAClB,IAAA,MAAM,SAAS,CAAA;AACf,IAAA,MAAM,GAAG,CAAA;AACT,IAAA,MAAM,SAAS,CAAA;IACf,MAAM,CAAA,CAAA,EAAI,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAA,CAAE,CAAA;AACjC;;;;"}
|
package/client/deploy-types.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare function getCreateOnCompleteOptions(method: MethodIdentifier, app
|
|
|
6
6
|
type: {};
|
|
7
7
|
isOptional: boolean;
|
|
8
8
|
};
|
|
9
|
-
export declare function deployTypes({ app, callConfig }: GeneratorContext): DocumentParts;
|
|
9
|
+
export declare function deployTypes({ app, callConfig, sanitizer }: GeneratorContext): DocumentParts;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var writer = require('../output/writer.
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var utilityTypes = require('./utility-types.cjs');
|
|
3
|
+
var writer = require('../output/writer.js');
|
|
4
|
+
var getCallConfigSummary = require('./helpers/get-call-config-summary.js');
|
|
5
|
+
var utilityTypes = require('./utility-types.js');
|
|
7
6
|
|
|
8
7
|
function getCreateOnCompleteOptions(method, app) {
|
|
9
8
|
const callConfig = method === getCallConfigSummary.BARE_CALL ? app.bare_call_config : app.hints?.[method]?.call_config;
|
|
@@ -19,8 +18,8 @@ function getCreateOnCompleteOptions(method, app) {
|
|
|
19
18
|
isOptional: hasNoOp,
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
|
-
function* deployTypes({ app, callConfig }) {
|
|
23
|
-
const name =
|
|
21
|
+
function* deployTypes({ app, callConfig, sanitizer }) {
|
|
22
|
+
const name = sanitizer.makeSafeTypeIdentifier(app.contract.name);
|
|
24
23
|
if (callConfig.createMethods.length > 0) {
|
|
25
24
|
yield* writer.jsDoc(`A factory for available 'create' calls`);
|
|
26
25
|
yield `export type ${name}CreateCalls = (typeof ${name}CallFactory)['create']`;
|
|
@@ -33,7 +32,8 @@ function* deployTypes({ app, callConfig }) {
|
|
|
33
32
|
yield `| (TypedCallParams<undefined> & ${onComplete.type})`;
|
|
34
33
|
}
|
|
35
34
|
else {
|
|
36
|
-
|
|
35
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
36
|
+
yield `| (TypedCallParams<'${methodSigSafe}'> & ${onComplete.type})`;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
yield writer.DecIndent;
|
|
@@ -49,7 +49,8 @@ function* deployTypes({ app, callConfig }) {
|
|
|
49
49
|
yield `| TypedCallParams<undefined>`;
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
|
-
|
|
52
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
53
|
+
yield `| TypedCallParams<'${methodSigSafe}'>`;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
yield writer.DecIndent;
|
|
@@ -65,7 +66,8 @@ function* deployTypes({ app, callConfig }) {
|
|
|
65
66
|
yield `| TypedCallParams<undefined>`;
|
|
66
67
|
}
|
|
67
68
|
else {
|
|
68
|
-
|
|
69
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
70
|
+
yield `| TypedCallParams<'${methodSigSafe}'>`;
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
yield writer.DecIndent;
|
|
@@ -92,3 +94,4 @@ function* deployTypes({ app, callConfig }) {
|
|
|
92
94
|
|
|
93
95
|
exports.deployTypes = deployTypes;
|
|
94
96
|
exports.getCreateOnCompleteOptions = getCreateOnCompleteOptions;
|
|
97
|
+
//# sourceMappingURL=deploy-types.js.map
|
|
@@ -0,0 +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":";;;;;;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ACD,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;;;;;"}
|
package/client/deploy-types.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsDoc, IncIndent, DecIndent, DecIndentAndCloseBlock, NewLine } from '../output/writer.mjs';
|
|
2
|
-
import { makeSafeTypeIdentifier } from '../util/sanitization.mjs';
|
|
3
2
|
import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
|
|
4
3
|
import { OnCompleteCodeMap } from './utility-types.mjs';
|
|
5
4
|
|
|
@@ -17,8 +16,8 @@ function getCreateOnCompleteOptions(method, app) {
|
|
|
17
16
|
isOptional: hasNoOp,
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
|
-
function* deployTypes({ app, callConfig }) {
|
|
21
|
-
const name = makeSafeTypeIdentifier(app.contract.name);
|
|
19
|
+
function* deployTypes({ app, callConfig, sanitizer }) {
|
|
20
|
+
const name = sanitizer.makeSafeTypeIdentifier(app.contract.name);
|
|
22
21
|
if (callConfig.createMethods.length > 0) {
|
|
23
22
|
yield* jsDoc(`A factory for available 'create' calls`);
|
|
24
23
|
yield `export type ${name}CreateCalls = (typeof ${name}CallFactory)['create']`;
|
|
@@ -31,7 +30,8 @@ function* deployTypes({ app, callConfig }) {
|
|
|
31
30
|
yield `| (TypedCallParams<undefined> & ${onComplete.type})`;
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
|
-
|
|
33
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
34
|
+
yield `| (TypedCallParams<'${methodSigSafe}'> & ${onComplete.type})`;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
yield DecIndent;
|
|
@@ -47,7 +47,8 @@ function* deployTypes({ app, callConfig }) {
|
|
|
47
47
|
yield `| TypedCallParams<undefined>`;
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
|
|
50
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
51
|
+
yield `| TypedCallParams<'${methodSigSafe}'>`;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
yield DecIndent;
|
|
@@ -63,7 +64,8 @@ function* deployTypes({ app, callConfig }) {
|
|
|
63
64
|
yield `| TypedCallParams<undefined>`;
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
|
-
|
|
67
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(method);
|
|
68
|
+
yield `| TypedCallParams<'${methodSigSafe}'>`;
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
yield DecIndent;
|
|
@@ -89,3 +91,4 @@ function* deployTypes({ app, callConfig }) {
|
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
export { deployTypes, getCreateOnCompleteOptions };
|
|
94
|
+
//# sourceMappingURL=deploy-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy-types.mjs","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":[],"mappings":";;;;AAOgB,SAAA,0BAA0B,CAAC,MAAwB,EAAE,GAAgB,EAAA;IACnF,MAAM,UAAU,GAAG,MAAM,KAAK,SAAS,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,KAAK,iBAAiB,CAAC,EAAsB,CAAC,CAAC;aACxD,IAAI,CAAC,KAAK,CAAC,CAAG,CAAA,CAAA;UACjB,EAAE,CA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AC,mDAAmD,CAAC,CAAA;IACjE,MAAM,CAAA,YAAA,EAAe,IAAI,CAAA,cAAA,CAAgB,CAAA;AACzC,IAAA,MAAM,SAAS,CAAA;AACf,IAAA,MAAM,uCAAuC,CAAA;AAC7C,IAAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,EAAE;AACnC,QAAA,OAAO,KAAK,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,OAAO,KAAK,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,OAAO,KAAK,CAAC,yGAAyG,CAAC,CAAA;AACvH,QAAA,MAAM,CAA8B,2BAAA,EAAA,IAAI,CAAmB,gBAAA,EAAA,IAAI,kBAAkB,CAAA;KAClF;AACD,IAAA,MAAM,sBAAsB,CAAA;AAC5B,IAAA,MAAM,OAAO,CAAA;AACf;;;;"}
|
package/client/generate.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { DocumentParts } from '../output/writer';
|
|
2
2
|
import { AlgoAppSpec } from '../schema/application';
|
|
3
|
-
|
|
3
|
+
import { GeneratorOptions } from './generator-context';
|
|
4
|
+
export declare function generate(app: AlgoAppSpec, options?: GeneratorOptions): DocumentParts;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var writer = require('../output/writer.
|
|
4
|
-
var callFactory = require('./call-factory.
|
|
5
|
-
var callClient = require('./call-client.
|
|
6
|
-
var deployTypes = require('./deploy-types.
|
|
7
|
-
var utilityTypes = require('./utility-types.
|
|
8
|
-
var imports = require('./imports.
|
|
9
|
-
var generatorContext = require('./generator-context.
|
|
10
|
-
var appTypes = require('./app-types.
|
|
11
|
-
var callComposerTypes = require('./call-composer-types.
|
|
3
|
+
var writer = require('../output/writer.js');
|
|
4
|
+
var callFactory = require('./call-factory.js');
|
|
5
|
+
var callClient = require('./call-client.js');
|
|
6
|
+
var deployTypes = require('./deploy-types.js');
|
|
7
|
+
var utilityTypes = require('./utility-types.js');
|
|
8
|
+
var imports = require('./imports.js');
|
|
9
|
+
var generatorContext = require('./generator-context.js');
|
|
10
|
+
var appTypes = require('./app-types.js');
|
|
11
|
+
var callComposerTypes = require('./call-composer-types.js');
|
|
12
12
|
|
|
13
|
-
function* generate(app) {
|
|
14
|
-
const ctx = generatorContext.createGeneratorContext(app);
|
|
13
|
+
function* generate(app, options = { preserveNames: false }) {
|
|
14
|
+
const ctx = generatorContext.createGeneratorContext(app, options);
|
|
15
15
|
yield `/* eslint-disable */`;
|
|
16
16
|
yield `/**`;
|
|
17
17
|
yield ` * This file was automatically generated by @algorandfoundation/algokit-client-generator.`;
|
|
@@ -35,3 +35,4 @@ function* generate(app) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
exports.generate = generate;
|
|
38
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sources":["../../src/client/generate.ts"],"sourcesContent":["import { DocumentParts, inline, NewLine } from '../output/writer'\nimport { AlgoAppSpec } from '../schema/application'\nimport { callFactory } from './call-factory'\nimport { callClient } from './call-client'\nimport { deployTypes } from './deploy-types'\nimport { utilityTypes } from './utility-types'\nimport { imports } from './imports'\nimport { createGeneratorContext, GeneratorOptions } from './generator-context'\nimport { appTypes } from './app-types'\nimport { callComposerType } from './call-composer-types'\n\nexport function* generate(app: AlgoAppSpec, options: GeneratorOptions = { preserveNames: false }): DocumentParts {\n const ctx = createGeneratorContext(app, options)\n yield `/* eslint-disable */`\n yield `/**`\n yield ` * This file was automatically generated by @algorandfoundation/algokit-client-generator.`\n yield ` * DO NOT MODIFY IT BY HAND.`\n yield ` * requires: @algorandfoundation/algokit-utils: ^2`\n yield ` */`\n\n yield* imports()\n yield* inline('export const APP_SPEC: AppSpec = ', JSON.stringify(app, undefined, 2))\n yield NewLine\n\n yield* utilityTypes()\n yield NewLine\n yield* appTypes(ctx)\n yield* deployTypes(ctx)\n yield NewLine\n\n // Write a call factory\n yield* callFactory(ctx)\n yield NewLine\n // Write a client\n yield* callClient(ctx)\n\n yield* callComposerType(ctx)\n}\n"],"names":["createGeneratorContext","imports","inline","NewLine","utilityTypes","appTypes","deployTypes","callFactory","callClient","callComposerType"],"mappings":";;;;;;;;;;;;AAWe,UAAE,QAAQ,CAAC,GAAgB,EAAE,OAAA,GAA4B,EAAE,aAAa,EAAE,KAAK,EAAE,EAAA;IAC9F,MAAM,GAAG,GAAGA,uCAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAChD,IAAA,MAAM,sBAAsB,CAAA;AAC5B,IAAA,MAAM,KAAK,CAAA;AACX,IAAA,MAAM,2FAA2F,CAAA;AACjG,IAAA,MAAM,8BAA8B,CAAA;AACpC,IAAA,MAAM,oDAAoD,CAAA;AAC1D,IAAA,MAAM,KAAK,CAAA;AAEX,IAAA,OAAOC,eAAO,EAAE,CAAA;AAChB,IAAA,OAAOC,aAAM,CAAC,mCAAmC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAA;AACrF,IAAA,MAAMC,cAAO,CAAA;AAEb,IAAA,OAAOC,yBAAY,EAAE,CAAA;AACrB,IAAA,MAAMD,cAAO,CAAA;AACb,IAAA,OAAOE,iBAAQ,CAAC,GAAG,CAAC,CAAA;AACpB,IAAA,OAAOC,uBAAW,CAAC,GAAG,CAAC,CAAA;AACvB,IAAA,MAAMH,cAAO,CAAA;;AAGb,IAAA,OAAOI,uBAAW,CAAC,GAAG,CAAC,CAAA;AACvB,IAAA,MAAMJ,cAAO,CAAA;;AAEb,IAAA,OAAOK,qBAAU,CAAC,GAAG,CAAC,CAAA;AAEtB,IAAA,OAAOC,kCAAgB,CAAC,GAAG,CAAC,CAAA;AAC9B;;;;"}
|
package/client/generate.mjs
CHANGED
|
@@ -8,8 +8,8 @@ import { createGeneratorContext } from './generator-context.mjs';
|
|
|
8
8
|
import { appTypes } from './app-types.mjs';
|
|
9
9
|
import { callComposerType } from './call-composer-types.mjs';
|
|
10
10
|
|
|
11
|
-
function* generate(app) {
|
|
12
|
-
const ctx = createGeneratorContext(app);
|
|
11
|
+
function* generate(app, options = { preserveNames: false }) {
|
|
12
|
+
const ctx = createGeneratorContext(app, options);
|
|
13
13
|
yield `/* eslint-disable */`;
|
|
14
14
|
yield `/**`;
|
|
15
15
|
yield ` * This file was automatically generated by @algorandfoundation/algokit-client-generator.`;
|
|
@@ -33,3 +33,4 @@ function* generate(app) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export { generate };
|
|
36
|
+
//# sourceMappingURL=generate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.mjs","sources":["../../src/client/generate.ts"],"sourcesContent":["import { DocumentParts, inline, NewLine } from '../output/writer'\nimport { AlgoAppSpec } from '../schema/application'\nimport { callFactory } from './call-factory'\nimport { callClient } from './call-client'\nimport { deployTypes } from './deploy-types'\nimport { utilityTypes } from './utility-types'\nimport { imports } from './imports'\nimport { createGeneratorContext, GeneratorOptions } from './generator-context'\nimport { appTypes } from './app-types'\nimport { callComposerType } from './call-composer-types'\n\nexport function* generate(app: AlgoAppSpec, options: GeneratorOptions = { preserveNames: false }): DocumentParts {\n const ctx = createGeneratorContext(app, options)\n yield `/* eslint-disable */`\n yield `/**`\n yield ` * This file was automatically generated by @algorandfoundation/algokit-client-generator.`\n yield ` * DO NOT MODIFY IT BY HAND.`\n yield ` * requires: @algorandfoundation/algokit-utils: ^2`\n yield ` */`\n\n yield* imports()\n yield* inline('export const APP_SPEC: AppSpec = ', JSON.stringify(app, undefined, 2))\n yield NewLine\n\n yield* utilityTypes()\n yield NewLine\n yield* appTypes(ctx)\n yield* deployTypes(ctx)\n yield NewLine\n\n // Write a call factory\n yield* callFactory(ctx)\n yield NewLine\n // Write a client\n yield* callClient(ctx)\n\n yield* callComposerType(ctx)\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWe,UAAE,QAAQ,CAAC,GAAgB,EAAE,OAAA,GAA4B,EAAE,aAAa,EAAE,KAAK,EAAE,EAAA;IAC9F,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAChD,IAAA,MAAM,sBAAsB,CAAA;AAC5B,IAAA,MAAM,KAAK,CAAA;AACX,IAAA,MAAM,2FAA2F,CAAA;AACjG,IAAA,MAAM,8BAA8B,CAAA;AACpC,IAAA,MAAM,oDAAoD,CAAA;AAC1D,IAAA,MAAM,KAAK,CAAA;AAEX,IAAA,OAAO,OAAO,EAAE,CAAA;AAChB,IAAA,OAAO,MAAM,CAAC,mCAAmC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAA;AACrF,IAAA,MAAM,OAAO,CAAA;AAEb,IAAA,OAAO,YAAY,EAAE,CAAA;AACrB,IAAA,MAAM,OAAO,CAAA;AACb,IAAA,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAA;AACpB,IAAA,OAAO,WAAW,CAAC,GAAG,CAAC,CAAA;AACvB,IAAA,MAAM,OAAO,CAAA;;AAGb,IAAA,OAAO,WAAW,CAAC,GAAG,CAAC,CAAA;AACvB,IAAA,MAAM,OAAO,CAAA;;AAEb,IAAA,OAAO,UAAU,CAAC,GAAG,CAAC,CAAA;AAEtB,IAAA,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAA;AAC9B;;;;"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { AlgoAppSpec } from '../schema/application';
|
|
2
2
|
import { CallConfigSummary } from './helpers/get-call-config-summary';
|
|
3
|
+
import { Sanitizer } from '../util/sanitization';
|
|
3
4
|
export type GeneratorContext = {
|
|
4
5
|
app: AlgoAppSpec;
|
|
5
6
|
name: string;
|
|
6
7
|
callConfig: CallConfigSummary;
|
|
7
8
|
methodSignatureToUniqueName: Record<string, string>;
|
|
9
|
+
sanitizer: Sanitizer;
|
|
8
10
|
};
|
|
9
|
-
export
|
|
11
|
+
export type GeneratorOptions = {
|
|
12
|
+
preserveNames: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const createGeneratorContext: (app: AlgoAppSpec, options: GeneratorOptions) => {
|
|
15
|
+
sanitizer: Sanitizer;
|
|
10
16
|
app: AlgoAppSpec;
|
|
11
17
|
name: string;
|
|
12
18
|
callConfig: CallConfigSummary;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var getCallConfigSummary = require('./helpers/get-call-config-summary.
|
|
4
|
-
var sanitization = require('../util/sanitization.
|
|
3
|
+
var getCallConfigSummary = require('./helpers/get-call-config-summary.js');
|
|
4
|
+
var sanitization = require('../util/sanitization.js');
|
|
5
5
|
var algokit = require('@algorandfoundation/algokit-utils');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
@@ -23,15 +23,20 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
|
|
24
24
|
var algokit__namespace = /*#__PURE__*/_interopNamespaceDefault(algokit);
|
|
25
25
|
|
|
26
|
-
const createGeneratorContext = (app) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
const createGeneratorContext = (app, options) => {
|
|
27
|
+
const sanitizer = sanitization.getSanitizer(options);
|
|
28
|
+
return {
|
|
29
|
+
sanitizer,
|
|
30
|
+
app,
|
|
31
|
+
name: sanitizer.makeSafeTypeIdentifier(app.contract.name),
|
|
32
|
+
callConfig: getCallConfigSummary.getCallConfigSummary(app),
|
|
33
|
+
methodSignatureToUniqueName: app.contract.methods.reduce((acc, cur) => {
|
|
34
|
+
const signature = algokit__namespace.getABIMethodSignature(cur);
|
|
35
|
+
acc[signature] = app.contract.methods.some((m) => m.name === cur.name && m !== cur) ? signature : cur.name;
|
|
36
|
+
return acc;
|
|
37
|
+
}, {}),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
36
40
|
|
|
37
41
|
exports.createGeneratorContext = createGeneratorContext;
|
|
42
|
+
//# sourceMappingURL=generator-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-context.js","sources":["../../src/client/generator-context.ts"],"sourcesContent":["import { AlgoAppSpec } from '../schema/application'\nimport { CallConfigSummary, getCallConfigSummary } from './helpers/get-call-config-summary'\nimport { getSanitizer, Sanitizer } from '../util/sanitization'\nimport * as algokit from '@algorandfoundation/algokit-utils'\n\nexport type GeneratorContext = {\n app: AlgoAppSpec\n name: string\n callConfig: CallConfigSummary\n methodSignatureToUniqueName: Record<string, string>\n sanitizer: Sanitizer\n}\n\nexport type GeneratorOptions = {\n preserveNames: boolean\n}\n\nexport const createGeneratorContext = (app: AlgoAppSpec, options: GeneratorOptions) => {\n const sanitizer = getSanitizer(options)\n return {\n sanitizer,\n app,\n name: sanitizer.makeSafeTypeIdentifier(app.contract.name),\n callConfig: getCallConfigSummary(app),\n methodSignatureToUniqueName: app.contract.methods.reduce(\n (acc, cur) => {\n const signature = algokit.getABIMethodSignature(cur)\n acc[signature] = app.contract.methods.some((m) => m.name === cur.name && m !== cur) ? signature : cur.name\n return acc\n },\n {} as Record<string, string>,\n ),\n }\n}\n"],"names":["getSanitizer","getCallConfigSummary","algokit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;MAiBa,sBAAsB,GAAG,CAAC,GAAgB,EAAE,OAAyB,KAAI;AACpF,IAAA,MAAM,SAAS,GAAGA,yBAAY,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO;QACL,SAAS;QACT,GAAG;QACH,IAAI,EAAE,SAAS,CAAC,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACzD,QAAA,UAAU,EAAEC,yCAAoB,CAAC,GAAG,CAAC;AACrC,QAAA,2BAA2B,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CACtD,CAAC,GAAG,EAAE,GAAG,KAAI;YACX,MAAM,SAAS,GAAGC,kBAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAA;AACpD,YAAA,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,SAAS,GAAG,GAAG,CAAC,IAAI,CAAA;AAC1G,YAAA,OAAO,GAAG,CAAA;SACX,EACD,EAA4B,CAC7B;KACF,CAAA;AACH;;;;"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { getCallConfigSummary } from './helpers/get-call-config-summary.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { getSanitizer } from '../util/sanitization.mjs';
|
|
3
3
|
import * as algokit from '@algorandfoundation/algokit-utils';
|
|
4
4
|
|
|
5
|
-
const createGeneratorContext = (app) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const createGeneratorContext = (app, options) => {
|
|
6
|
+
const sanitizer = getSanitizer(options);
|
|
7
|
+
return {
|
|
8
|
+
sanitizer,
|
|
9
|
+
app,
|
|
10
|
+
name: sanitizer.makeSafeTypeIdentifier(app.contract.name),
|
|
11
|
+
callConfig: getCallConfigSummary(app),
|
|
12
|
+
methodSignatureToUniqueName: app.contract.methods.reduce((acc, cur) => {
|
|
13
|
+
const signature = algokit.getABIMethodSignature(cur);
|
|
14
|
+
acc[signature] = app.contract.methods.some((m) => m.name === cur.name && m !== cur) ? signature : cur.name;
|
|
15
|
+
return acc;
|
|
16
|
+
}, {}),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
15
19
|
|
|
16
20
|
export { createGeneratorContext };
|
|
21
|
+
//# sourceMappingURL=generator-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-context.mjs","sources":["../../src/client/generator-context.ts"],"sourcesContent":["import { AlgoAppSpec } from '../schema/application'\nimport { CallConfigSummary, getCallConfigSummary } from './helpers/get-call-config-summary'\nimport { getSanitizer, Sanitizer } from '../util/sanitization'\nimport * as algokit from '@algorandfoundation/algokit-utils'\n\nexport type GeneratorContext = {\n app: AlgoAppSpec\n name: string\n callConfig: CallConfigSummary\n methodSignatureToUniqueName: Record<string, string>\n sanitizer: Sanitizer\n}\n\nexport type GeneratorOptions = {\n preserveNames: boolean\n}\n\nexport const createGeneratorContext = (app: AlgoAppSpec, options: GeneratorOptions) => {\n const sanitizer = getSanitizer(options)\n return {\n sanitizer,\n app,\n name: sanitizer.makeSafeTypeIdentifier(app.contract.name),\n callConfig: getCallConfigSummary(app),\n methodSignatureToUniqueName: app.contract.methods.reduce(\n (acc, cur) => {\n const signature = algokit.getABIMethodSignature(cur)\n acc[signature] = app.contract.methods.some((m) => m.name === cur.name && m !== cur) ? signature : cur.name\n return acc\n },\n {} as Record<string, string>,\n ),\n }\n}\n"],"names":[],"mappings":";;;;MAiBa,sBAAsB,GAAG,CAAC,GAAgB,EAAE,OAAyB,KAAI;AACpF,IAAA,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO;QACL,SAAS;QACT,GAAG;QACH,IAAI,EAAE,SAAS,CAAC,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACzD,QAAA,UAAU,EAAE,oBAAoB,CAAC,GAAG,CAAC;AACrC,QAAA,2BAA2B,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CACtD,CAAC,GAAG,EAAE,GAAG,KAAI;YACX,MAAM,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAA;AACpD,YAAA,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,SAAS,GAAG,GAAG,CAAC,IAAI,CAAA;AAC1G,YAAA,OAAO,GAAG,CAAA;SACX,EACD,EAA4B,CAC7B;KACF,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
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 { AlgoAppSpec, CallConfig, CallConfigValue } from '../../schema/application.js'\n\nexport const BARE_CALL = Symbol('bare')\n\nexport type MethodIdentifier = string | typeof BARE_CALL\n\nexport type MethodList = Array<MethodIdentifier>\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: AlgoAppSpec) => {\n const result: CallConfigSummary = {\n createMethods: [],\n callMethods: [],\n deleteMethods: [],\n updateMethods: [],\n optInMethods: [],\n closeOutMethods: [],\n }\n if (app.bare_call_config) {\n addToConfig(result, BARE_CALL, app.bare_call_config)\n }\n if (app.hints) {\n for (const [method, hints] of Object.entries(app.hints)) {\n if (hints.call_config) {\n addToConfig(result, method, hints.call_config)\n }\n }\n }\n return result\n}\n\nexport const getCreateOnComplete = (app: AlgoAppSpec, method: MethodIdentifier) => {\n const callConfig = method === BARE_CALL ? app.bare_call_config : app.hints?.[method]?.call_config\n if (!callConfig) {\n return ''\n }\n const hasNoOp = callConfig.no_op === 'ALL' || callConfig.no_op === 'CREATE'\n return `{ onCompleteAction${hasNoOp ? '?' : ''}: ${getCreateOnCompleteTypes(callConfig)} }`\n}\n\nconst getCreateOnCompleteTypes = (config: CallConfig) => {\n return Object.keys(config)\n .map((oc) => oc as keyof CallConfig)\n .filter((oc) => config[oc] === 'ALL' || config[oc] === 'CREATE')\n .map((oc) => `'${oc}' | OnApplicationComplete.${pascalCase(oc)}OC`)\n .join(' | ')\n}\n\nconst addToConfig = (result: CallConfigSummary, method: MethodIdentifier, config: CallConfig) => {\n if (hasCall(config.no_op)) {\n result.callMethods.push(method)\n }\n if (\n hasCreate(config.no_op) ||\n hasCreate(config.opt_in) ||\n hasCreate(config.close_out) ||\n hasCreate(config.update_application) ||\n hasCreate(config.delete_application)\n ) {\n result.createMethods.push(method)\n }\n if (hasCall(config.delete_application)) {\n result.deleteMethods.push(method)\n }\n if (hasCall(config.update_application)) {\n result.updateMethods.push(method)\n }\n if (hasCall(config.opt_in)) {\n result.optInMethods.push(method)\n }\n if (hasCall(config.close_out)) {\n result.closeOutMethods.push(method)\n }\n}\n\nconst hasCall = (config: CallConfigValue | undefined) => {\n return config === 'CALL' || config === 'ALL'\n}\nconst hasCreate = (config: CallConfigValue | undefined) => {\n return config === 'CREATE' || config === 'ALL'\n}\n"],"names":[],"mappings":";;MAGa,SAAS,GAAG,MAAM,CAAC,MAAM,EAAC;AAc1B,MAAA,oBAAoB,GAAG,CAAC,GAAgB,KAAI;AACvD,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,CAAA;AACD,IAAA,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KAClC;AACD,IAAA,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;AAC1B,QAAA,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;KACjC;AACD,IAAA,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;AAC7B,QAAA,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;KACpC;AACH,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,CAAC,MAAmC,KAAI;AACtD,IAAA,OAAO,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,KAAK,CAAA;AAC9C,CAAC,CAAA;AACD,MAAM,SAAS,GAAG,CAAC,MAAmC,KAAI;AACxD,IAAA,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,KAAK,CAAA;AAChD,CAAC;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
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 { AlgoAppSpec, CallConfig, CallConfigValue } from '../../schema/application.js'\n\nexport const BARE_CALL = Symbol('bare')\n\nexport type MethodIdentifier = string | typeof BARE_CALL\n\nexport type MethodList = Array<MethodIdentifier>\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: AlgoAppSpec) => {\n const result: CallConfigSummary = {\n createMethods: [],\n callMethods: [],\n deleteMethods: [],\n updateMethods: [],\n optInMethods: [],\n closeOutMethods: [],\n }\n if (app.bare_call_config) {\n addToConfig(result, BARE_CALL, app.bare_call_config)\n }\n if (app.hints) {\n for (const [method, hints] of Object.entries(app.hints)) {\n if (hints.call_config) {\n addToConfig(result, method, hints.call_config)\n }\n }\n }\n return result\n}\n\nexport const getCreateOnComplete = (app: AlgoAppSpec, method: MethodIdentifier) => {\n const callConfig = method === BARE_CALL ? app.bare_call_config : app.hints?.[method]?.call_config\n if (!callConfig) {\n return ''\n }\n const hasNoOp = callConfig.no_op === 'ALL' || callConfig.no_op === 'CREATE'\n return `{ onCompleteAction${hasNoOp ? '?' : ''}: ${getCreateOnCompleteTypes(callConfig)} }`\n}\n\nconst getCreateOnCompleteTypes = (config: CallConfig) => {\n return Object.keys(config)\n .map((oc) => oc as keyof CallConfig)\n .filter((oc) => config[oc] === 'ALL' || config[oc] === 'CREATE')\n .map((oc) => `'${oc}' | OnApplicationComplete.${pascalCase(oc)}OC`)\n .join(' | ')\n}\n\nconst addToConfig = (result: CallConfigSummary, method: MethodIdentifier, config: CallConfig) => {\n if (hasCall(config.no_op)) {\n result.callMethods.push(method)\n }\n if (\n hasCreate(config.no_op) ||\n hasCreate(config.opt_in) ||\n hasCreate(config.close_out) ||\n hasCreate(config.update_application) ||\n hasCreate(config.delete_application)\n ) {\n result.createMethods.push(method)\n }\n if (hasCall(config.delete_application)) {\n result.deleteMethods.push(method)\n }\n if (hasCall(config.update_application)) {\n result.updateMethods.push(method)\n }\n if (hasCall(config.opt_in)) {\n result.optInMethods.push(method)\n }\n if (hasCall(config.close_out)) {\n result.closeOutMethods.push(method)\n }\n}\n\nconst hasCall = (config: CallConfigValue | undefined) => {\n return config === 'CALL' || config === 'ALL'\n}\nconst hasCreate = (config: CallConfigValue | undefined) => {\n return config === 'CREATE' || config === 'ALL'\n}\n"],"names":[],"mappings":"MAGa,SAAS,GAAG,MAAM,CAAC,MAAM,EAAC;AAc1B,MAAA,oBAAoB,GAAG,CAAC,GAAgB,KAAI;AACvD,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,EAA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