@algorandfoundation/algokit-client-generator 2.6.0-beta.1 → 2.6.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/bin/cli.mjs +4 -0
  2. package/cli.cjs +75 -0
  3. package/cli.d.ts +0 -1
  4. package/cli.mjs +54 -0
  5. package/client/app-types.cjs +152 -0
  6. package/client/app-types.d.ts +0 -1
  7. package/client/app-types.mjs +131 -0
  8. package/client/call-client.cjs +332 -0
  9. package/client/call-client.d.ts +0 -1
  10. package/client/{call-client.js → call-client.mjs} +107 -135
  11. package/client/call-composer-types.cjs +141 -0
  12. package/client/call-composer-types.d.ts +0 -1
  13. package/client/{call-composer-types.js → call-composer-types.mjs} +33 -58
  14. package/client/call-composer.cjs +145 -0
  15. package/client/call-composer.d.ts +0 -1
  16. package/client/call-composer.mjs +124 -0
  17. package/client/call-factory.cjs +138 -0
  18. package/client/call-factory.d.ts +0 -1
  19. package/client/{call-factory.js → call-factory.mjs} +31 -56
  20. package/client/deploy-types.cjs +94 -0
  21. package/client/deploy-types.d.ts +0 -1
  22. package/client/deploy-types.mjs +91 -0
  23. package/client/generate.cjs +37 -0
  24. package/client/generate.d.ts +0 -1
  25. package/client/generate.mjs +35 -0
  26. package/client/generator-context.cjs +37 -0
  27. package/client/generator-context.d.ts +0 -1
  28. package/client/generator-context.mjs +16 -0
  29. package/client/helpers/{get-call-config-summary.js → get-call-config-summary.cjs} +7 -25
  30. package/client/helpers/get-call-config-summary.d.ts +1 -2
  31. package/client/helpers/get-call-config-summary.mjs +54 -0
  32. package/client/helpers/{get-equivalent-type.js → get-equivalent-type.cjs} +20 -20
  33. package/client/helpers/get-equivalent-type.d.ts +0 -1
  34. package/client/helpers/get-equivalent-type.mjs +56 -0
  35. package/client/{imports.js → imports.cjs} +3 -4
  36. package/client/imports.d.ts +0 -1
  37. package/client/imports.mjs +27 -0
  38. package/client/{utility-types.js → utility-types.cjs} +26 -25
  39. package/client/utility-types.d.ts +0 -1
  40. package/client/utility-types.mjs +47 -0
  41. package/dev.d.ts +0 -1
  42. package/index.cjs +13 -0
  43. package/index.d.ts +0 -1
  44. package/index.mjs +3 -0
  45. package/output/{writer.js → writer.cjs} +44 -38
  46. package/output/writer.d.ts +0 -1
  47. package/output/writer.mjs +139 -0
  48. package/package.json +7 -4
  49. package/schema/application.schema.json.cjs +374 -0
  50. package/schema/application.schema.json.mjs +363 -0
  51. package/schema/contract.schema.json.cjs +159 -0
  52. package/schema/contract.schema.json.mjs +148 -0
  53. package/schema/load.cjs +25 -0
  54. package/schema/load.d.ts +0 -1
  55. package/schema/load.mjs +22 -0
  56. package/tests/approval-tests.spec.d.ts +0 -1
  57. package/tests/util.d.ts +1 -0
  58. package/util/boom.cjs +7 -0
  59. package/util/boom.d.ts +0 -1
  60. package/util/boom.mjs +5 -0
  61. package/util/color-console.cjs +18 -0
  62. package/util/color-console.d.ts +0 -1
  63. package/util/color-console.mjs +16 -0
  64. package/util/not-falsy.d.ts +0 -1
  65. package/util/sanitization.cjs +17 -0
  66. package/util/sanitization.d.ts +0 -1
  67. package/util/sanitization.mjs +11 -0
  68. package/bin/cli.js +0 -4
  69. package/cli.d.ts.map +0 -1
  70. package/cli.js +0 -79
  71. package/cli.js.map +0 -1
  72. package/client/app-types.d.ts.map +0 -1
  73. package/client/app-types.js +0 -161
  74. package/client/app-types.js.map +0 -1
  75. package/client/call-client.d.ts.map +0 -1
  76. package/client/call-client.js.map +0 -1
  77. package/client/call-composer-types.d.ts.map +0 -1
  78. package/client/call-composer-types.js.map +0 -1
  79. package/client/call-composer.d.ts.map +0 -1
  80. package/client/call-composer.js +0 -151
  81. package/client/call-composer.js.map +0 -1
  82. package/client/call-factory.d.ts.map +0 -1
  83. package/client/call-factory.js.map +0 -1
  84. package/client/deploy-types.d.ts.map +0 -1
  85. package/client/deploy-types.js +0 -95
  86. package/client/deploy-types.js.map +0 -1
  87. package/client/generate.d.ts.map +0 -1
  88. package/client/generate.js +0 -37
  89. package/client/generate.js.map +0 -1
  90. package/client/generator-context.d.ts.map +0 -1
  91. package/client/generator-context.js +0 -41
  92. package/client/generator-context.js.map +0 -1
  93. package/client/helpers/get-call-config-summary.d.ts.map +0 -1
  94. package/client/helpers/get-call-config-summary.js.map +0 -1
  95. package/client/helpers/get-equivalent-type.d.ts.map +0 -1
  96. package/client/helpers/get-equivalent-type.js.map +0 -1
  97. package/client/imports.d.ts.map +0 -1
  98. package/client/imports.js.map +0 -1
  99. package/client/utility-types.d.ts.map +0 -1
  100. package/client/utility-types.js.map +0 -1
  101. package/dev.d.ts.map +0 -1
  102. package/dev.js +0 -5
  103. package/dev.js.map +0 -1
  104. package/index.d.ts.map +0 -1
  105. package/index.js +0 -12
  106. package/index.js.map +0 -1
  107. package/output/writer.d.ts.map +0 -1
  108. package/output/writer.js.map +0 -1
  109. package/schema/application.schema.json +0 -354
  110. package/schema/contract.schema.json +0 -139
  111. package/schema/load.d.ts.map +0 -1
  112. package/schema/load.js +0 -51
  113. package/schema/load.js.map +0 -1
  114. package/tests/approval-tests.spec.d.ts.map +0 -1
  115. package/tests/approval-tests.spec.js +0 -24
  116. package/tests/approval-tests.spec.js.map +0 -1
  117. package/util/boom.d.ts.map +0 -1
  118. package/util/boom.js +0 -8
  119. package/util/boom.js.map +0 -1
  120. package/util/color-console.d.ts.map +0 -1
  121. package/util/color-console.js +0 -20
  122. package/util/color-console.js.map +0 -1
  123. package/util/not-falsy.d.ts.map +0 -1
  124. package/util/not-falsy.js +0 -6
  125. package/util/not-falsy.js.map +0 -1
  126. package/util/sanitization.d.ts.map +0 -1
  127. package/util/sanitization.js +0 -17
  128. package/util/sanitization.js.map +0 -1
@@ -1,46 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.callFactory = void 0;
27
- const writer_1 = require("../output/writer");
28
- const sanitization_1 = require("../util/sanitization");
29
- const algokit = __importStar(require("@algorandfoundation/algokit-utils"));
30
- const get_call_config_summary_1 = require("./helpers/get-call-config-summary");
31
- const deploy_types_1 = require("./deploy-types");
1
+ import { jsDoc, IncIndent, DecIndent, DecIndentAndCloseBlock, NewLine } from '../output/writer.mjs';
2
+ import { makeSafeMethodIdentifier, isSafeVariableIdentifier, makeSafePropertyIdentifier } from '../util/sanitization.mjs';
3
+ import * as algokit from '@algorandfoundation/algokit-utils';
4
+ import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
5
+ import { getCreateOnCompleteOptions } from './deploy-types.mjs';
6
+
32
7
  function* callFactory(ctx) {
33
- yield* (0, writer_1.jsDoc)('Exposes methods for constructing all available smart contract calls');
8
+ yield* jsDoc('Exposes methods for constructing all available smart contract calls');
34
9
  yield `export abstract class ${ctx.name}CallFactory {`;
35
- yield writer_1.IncIndent;
10
+ yield IncIndent;
36
11
  yield* opMethods(ctx);
37
12
  for (const method of ctx.app.contract.methods) {
38
13
  yield* callFactoryMethod(ctx, method);
39
14
  }
40
- yield writer_1.DecIndent;
15
+ yield DecIndent;
41
16
  yield '}';
42
17
  }
43
- exports.callFactory = callFactory;
44
18
  function* opMethods(ctx) {
45
19
  const { app, callConfig } = ctx;
46
20
  yield* operationMethod(ctx, `Constructs a create call for the ${app.contract.name} smart contract`, callConfig.createMethods, 'create', true);
@@ -51,15 +25,15 @@ function* opMethods(ctx) {
51
25
  }
52
26
  function* operationMethod({ app, methodSignatureToUniqueName }, description, methods, verb, includeCompilation) {
53
27
  if (methods.length) {
54
- yield* (0, writer_1.jsDoc)(`Gets available ${verb} call factories`);
28
+ yield* jsDoc(`Gets available ${verb} call factories`);
55
29
  yield `static get ${verb}() {`;
56
- yield writer_1.IncIndent;
30
+ yield IncIndent;
57
31
  yield `return {`;
58
- yield writer_1.IncIndent;
32
+ yield IncIndent;
59
33
  for (const methodSig of methods) {
60
- const onComplete = verb === 'create' ? (0, deploy_types_1.getCreateOnCompleteOptions)(methodSig, app) : undefined;
61
- if (methodSig === get_call_config_summary_1.BARE_CALL) {
62
- yield* (0, writer_1.jsDoc)({
34
+ const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined;
35
+ if (methodSig === BARE_CALL) {
36
+ yield* jsDoc({
63
37
  description: `${description} using a bare call`,
64
38
  params: {
65
39
  params: `Any parameters for the call`,
@@ -69,13 +43,13 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
69
43
  yield* factoryMethod({
70
44
  isNested: true,
71
45
  name: 'bare',
72
- paramTypes: `BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.type) ? ` & ${onComplete.type}` : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.isOptional) !== false ? ' = {}' : ''}`,
46
+ paramTypes: `BareCallArgs & AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
73
47
  });
74
48
  }
75
49
  else {
76
50
  const method = app.contract.methods.find((m) => algokit.getABIMethodSignature(m) === methodSig);
77
51
  const uniqueName = methodSignatureToUniqueName[methodSig];
78
- yield* (0, writer_1.jsDoc)({
52
+ yield* jsDoc({
79
53
  description: `${description} using the ${methodSig} ABI method`,
80
54
  params: {
81
55
  args: `Any args for the contract call`,
@@ -85,23 +59,23 @@ function* operationMethod({ app, methodSignatureToUniqueName }, description, met
85
59
  });
86
60
  yield* factoryMethod({
87
61
  isNested: true,
88
- name: (0, sanitization_1.makeSafeMethodIdentifier)(uniqueName),
62
+ name: makeSafeMethodIdentifier(uniqueName),
89
63
  signature: methodSig,
90
64
  args: method.args,
91
- paramTypes: `AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.type) ? ` & ${onComplete.type}` : ''}${(onComplete === null || onComplete === void 0 ? void 0 : onComplete.isOptional) !== false ? ' = {}' : ''}`,
65
+ paramTypes: `AppClientCallCoreParams & CoreAppCallArgs${includeCompilation ? ' & AppClientCompilationParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false ? ' = {}' : ''}`,
92
66
  });
93
67
  }
94
68
  }
95
- yield writer_1.DecIndentAndCloseBlock;
96
- yield writer_1.DecIndentAndCloseBlock;
97
- yield writer_1.NewLine;
69
+ yield DecIndentAndCloseBlock;
70
+ yield DecIndentAndCloseBlock;
71
+ yield NewLine;
98
72
  }
99
73
  }
100
74
  function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method) {
101
75
  const methodSignature = algokit.getABIMethodSignature(method);
102
76
  if (!callConfig.callMethods.includes(methodSignature))
103
77
  return;
104
- yield* (0, writer_1.jsDoc)({
78
+ yield* jsDoc({
105
79
  description: `Constructs a no op call for the ${methodSignature} ABI method`,
106
80
  abiDescription: method.desc,
107
81
  params: {
@@ -112,7 +86,7 @@ function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method)
112
86
  });
113
87
  yield* factoryMethod({
114
88
  isNested: false,
115
- name: (0, sanitization_1.makeSafeMethodIdentifier)(methodSignatureToUniqueName[methodSignature]),
89
+ name: makeSafeMethodIdentifier(methodSignatureToUniqueName[methodSignature]),
116
90
  signature: methodSignature,
117
91
  args: method.args,
118
92
  paramTypes: 'AppClientCallCoreParams & CoreAppCallArgs',
@@ -120,13 +94,13 @@ function* callFactoryMethod({ methodSignatureToUniqueName, callConfig }, method)
120
94
  }
121
95
  function* factoryMethod({ isNested, name, signature, args, paramTypes, }) {
122
96
  yield `${isNested ? '' : 'static '}${name}(${signature === undefined ? '' : `args: MethodArgs<'${signature}'>, `}params: ${paramTypes}) {`;
123
- yield writer_1.IncIndent;
97
+ yield IncIndent;
124
98
  yield `return {`;
125
- yield writer_1.IncIndent;
99
+ yield IncIndent;
126
100
  if (signature) {
127
101
  yield `method: '${signature}' as const,`;
128
102
  yield `methodArgs: Array.isArray(args) ? args : [${args
129
- .map((a) => ((0, sanitization_1.isSafeVariableIdentifier)(a.name) ? `args.${a.name}` : `args['${(0, sanitization_1.makeSafePropertyIdentifier)(a.name)}']`))
103
+ .map((a) => (isSafeVariableIdentifier(a.name) ? `args.${a.name}` : `args['${makeSafePropertyIdentifier(a.name)}']`))
130
104
  .join(', ')}],`;
131
105
  }
132
106
  else {
@@ -134,9 +108,10 @@ function* factoryMethod({ isNested, name, signature, args, paramTypes, }) {
134
108
  yield `methodArgs: undefined,`;
135
109
  }
136
110
  yield '...params,';
137
- yield writer_1.DecIndent;
111
+ yield DecIndent;
138
112
  yield '}';
139
- yield writer_1.DecIndent;
113
+ yield DecIndent;
140
114
  yield `}${isNested ? ',' : ''}`;
141
115
  }
142
- //# sourceMappingURL=call-factory.js.map
116
+
117
+ export { callFactory };
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ var writer = require('../output/writer.cjs');
4
+ var sanitization = require('../util/sanitization.cjs');
5
+ var getCallConfigSummary = require('./helpers/get-call-config-summary.cjs');
6
+ var utilityTypes = require('./utility-types.cjs');
7
+
8
+ function getCreateOnCompleteOptions(method, app) {
9
+ const callConfig = method === getCallConfigSummary.BARE_CALL ? app.bare_call_config : app.hints?.[method]?.call_config;
10
+ const hasNoOp = callConfig?.no_op === 'ALL' || callConfig?.no_op === 'CREATE';
11
+ const onCompleteType = callConfig
12
+ ? `(${Object.entries(callConfig)
13
+ .filter(([_, value]) => value === 'ALL' || value === 'CREATE')
14
+ .map(([oc]) => utilityTypes.OnCompleteCodeMap[oc])
15
+ .join(' | ')})`
16
+ : {};
17
+ return {
18
+ type: onCompleteType,
19
+ isOptional: hasNoOp,
20
+ };
21
+ }
22
+ function* deployTypes({ app, callConfig }) {
23
+ const name = sanitization.makeSafeTypeIdentifier(app.contract.name);
24
+ if (callConfig.createMethods.length > 0) {
25
+ yield* writer.jsDoc(`A factory for available 'create' calls`);
26
+ yield `export type ${name}CreateCalls = (typeof ${name}CallFactory)['create']`;
27
+ yield* writer.jsDoc('Defines supported create methods for this smart contract');
28
+ yield `export type ${name}CreateCallParams =`;
29
+ yield writer.IncIndent;
30
+ for (const method of callConfig.createMethods) {
31
+ const onComplete = getCreateOnCompleteOptions(method, app);
32
+ if (method === getCallConfigSummary.BARE_CALL) {
33
+ yield `| (TypedCallParams<undefined> & ${onComplete.type})`;
34
+ }
35
+ else {
36
+ yield `| (TypedCallParams<'${method}'> & ${onComplete.type})`;
37
+ }
38
+ }
39
+ yield writer.DecIndent;
40
+ }
41
+ if (callConfig.updateMethods.length > 0) {
42
+ yield* writer.jsDoc(`A factory for available 'update' calls`);
43
+ yield `export type ${name}UpdateCalls = (typeof ${name}CallFactory)['update']`;
44
+ yield* writer.jsDoc('Defines supported update methods for this smart contract');
45
+ yield `export type ${name}UpdateCallParams =`;
46
+ yield writer.IncIndent;
47
+ for (const method of callConfig.updateMethods) {
48
+ if (method === getCallConfigSummary.BARE_CALL) {
49
+ yield `| TypedCallParams<undefined>`;
50
+ }
51
+ else {
52
+ yield `| TypedCallParams<'${method}'>`;
53
+ }
54
+ }
55
+ yield writer.DecIndent;
56
+ }
57
+ if (callConfig.deleteMethods.length > 0) {
58
+ yield* writer.jsDoc(`A factory for available 'delete' calls`);
59
+ yield `export type ${name}DeleteCalls = (typeof ${name}CallFactory)['delete']`;
60
+ yield* writer.jsDoc('Defines supported delete methods for this smart contract');
61
+ yield `export type ${name}DeleteCallParams =`;
62
+ yield writer.IncIndent;
63
+ for (const method of callConfig.deleteMethods) {
64
+ if (method === getCallConfigSummary.BARE_CALL) {
65
+ yield `| TypedCallParams<undefined>`;
66
+ }
67
+ else {
68
+ yield `| TypedCallParams<'${method}'>`;
69
+ }
70
+ }
71
+ yield writer.DecIndent;
72
+ }
73
+ yield* writer.jsDoc('Defines arguments required for the deploy method.');
74
+ yield `export type ${name}DeployArgs = {`;
75
+ yield writer.IncIndent;
76
+ yield `deployTimeParams?: TealTemplateParams`;
77
+ if (callConfig.createMethods.length) {
78
+ yield* writer.jsDoc('A delegate which takes a create call factory and returns the create call params for this smart contract');
79
+ yield `createCall?: (callFactory: ${name}CreateCalls) => ${name}CreateCallParams`;
80
+ }
81
+ if (callConfig.updateMethods.length) {
82
+ yield* writer.jsDoc('A delegate which takes a update call factory and returns the update call params for this smart contract');
83
+ yield `updateCall?: (callFactory: ${name}UpdateCalls) => ${name}UpdateCallParams`;
84
+ }
85
+ if (callConfig.deleteMethods.length) {
86
+ yield* writer.jsDoc('A delegate which takes a delete call factory and returns the delete call params for this smart contract');
87
+ yield `deleteCall?: (callFactory: ${name}DeleteCalls) => ${name}DeleteCallParams`;
88
+ }
89
+ yield writer.DecIndentAndCloseBlock;
90
+ yield writer.NewLine;
91
+ }
92
+
93
+ exports.deployTypes = deployTypes;
94
+ exports.getCreateOnCompleteOptions = getCreateOnCompleteOptions;
@@ -7,4 +7,3 @@ export declare function getCreateOnCompleteOptions(method: MethodIdentifier, app
7
7
  isOptional: boolean;
8
8
  };
9
9
  export declare function deployTypes({ app, callConfig }: GeneratorContext): DocumentParts;
10
- //# sourceMappingURL=deploy-types.d.ts.map
@@ -0,0 +1,91 @@
1
+ import { jsDoc, IncIndent, DecIndent, DecIndentAndCloseBlock, NewLine } from '../output/writer.mjs';
2
+ import { makeSafeTypeIdentifier } from '../util/sanitization.mjs';
3
+ import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
4
+ import { OnCompleteCodeMap } from './utility-types.mjs';
5
+
6
+ function getCreateOnCompleteOptions(method, app) {
7
+ const callConfig = method === BARE_CALL ? app.bare_call_config : app.hints?.[method]?.call_config;
8
+ const hasNoOp = callConfig?.no_op === 'ALL' || callConfig?.no_op === 'CREATE';
9
+ const onCompleteType = callConfig
10
+ ? `(${Object.entries(callConfig)
11
+ .filter(([_, value]) => value === 'ALL' || value === 'CREATE')
12
+ .map(([oc]) => OnCompleteCodeMap[oc])
13
+ .join(' | ')})`
14
+ : {};
15
+ return {
16
+ type: onCompleteType,
17
+ isOptional: hasNoOp,
18
+ };
19
+ }
20
+ function* deployTypes({ app, callConfig }) {
21
+ const name = makeSafeTypeIdentifier(app.contract.name);
22
+ if (callConfig.createMethods.length > 0) {
23
+ yield* jsDoc(`A factory for available 'create' calls`);
24
+ yield `export type ${name}CreateCalls = (typeof ${name}CallFactory)['create']`;
25
+ yield* jsDoc('Defines supported create methods for this smart contract');
26
+ yield `export type ${name}CreateCallParams =`;
27
+ yield IncIndent;
28
+ for (const method of callConfig.createMethods) {
29
+ const onComplete = getCreateOnCompleteOptions(method, app);
30
+ if (method === BARE_CALL) {
31
+ yield `| (TypedCallParams<undefined> & ${onComplete.type})`;
32
+ }
33
+ else {
34
+ yield `| (TypedCallParams<'${method}'> & ${onComplete.type})`;
35
+ }
36
+ }
37
+ yield DecIndent;
38
+ }
39
+ if (callConfig.updateMethods.length > 0) {
40
+ yield* jsDoc(`A factory for available 'update' calls`);
41
+ yield `export type ${name}UpdateCalls = (typeof ${name}CallFactory)['update']`;
42
+ yield* jsDoc('Defines supported update methods for this smart contract');
43
+ yield `export type ${name}UpdateCallParams =`;
44
+ yield IncIndent;
45
+ for (const method of callConfig.updateMethods) {
46
+ if (method === BARE_CALL) {
47
+ yield `| TypedCallParams<undefined>`;
48
+ }
49
+ else {
50
+ yield `| TypedCallParams<'${method}'>`;
51
+ }
52
+ }
53
+ yield DecIndent;
54
+ }
55
+ if (callConfig.deleteMethods.length > 0) {
56
+ yield* jsDoc(`A factory for available 'delete' calls`);
57
+ yield `export type ${name}DeleteCalls = (typeof ${name}CallFactory)['delete']`;
58
+ yield* jsDoc('Defines supported delete methods for this smart contract');
59
+ yield `export type ${name}DeleteCallParams =`;
60
+ yield IncIndent;
61
+ for (const method of callConfig.deleteMethods) {
62
+ if (method === BARE_CALL) {
63
+ yield `| TypedCallParams<undefined>`;
64
+ }
65
+ else {
66
+ yield `| TypedCallParams<'${method}'>`;
67
+ }
68
+ }
69
+ yield DecIndent;
70
+ }
71
+ yield* jsDoc('Defines arguments required for the deploy method.');
72
+ yield `export type ${name}DeployArgs = {`;
73
+ yield IncIndent;
74
+ yield `deployTimeParams?: TealTemplateParams`;
75
+ if (callConfig.createMethods.length) {
76
+ yield* jsDoc('A delegate which takes a create call factory and returns the create call params for this smart contract');
77
+ yield `createCall?: (callFactory: ${name}CreateCalls) => ${name}CreateCallParams`;
78
+ }
79
+ if (callConfig.updateMethods.length) {
80
+ yield* jsDoc('A delegate which takes a update call factory and returns the update call params for this smart contract');
81
+ yield `updateCall?: (callFactory: ${name}UpdateCalls) => ${name}UpdateCallParams`;
82
+ }
83
+ if (callConfig.deleteMethods.length) {
84
+ yield* jsDoc('A delegate which takes a delete call factory and returns the delete call params for this smart contract');
85
+ yield `deleteCall?: (callFactory: ${name}DeleteCalls) => ${name}DeleteCallParams`;
86
+ }
87
+ yield DecIndentAndCloseBlock;
88
+ yield NewLine;
89
+ }
90
+
91
+ export { deployTypes, getCreateOnCompleteOptions };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var writer = require('../output/writer.cjs');
4
+ var callFactory = require('./call-factory.cjs');
5
+ var callClient = require('./call-client.cjs');
6
+ var deployTypes = require('./deploy-types.cjs');
7
+ var utilityTypes = require('./utility-types.cjs');
8
+ var imports = require('./imports.cjs');
9
+ var generatorContext = require('./generator-context.cjs');
10
+ var appTypes = require('./app-types.cjs');
11
+ var callComposerTypes = require('./call-composer-types.cjs');
12
+
13
+ function* generate(app) {
14
+ const ctx = generatorContext.createGeneratorContext(app);
15
+ yield `/* eslint-disable */`;
16
+ yield `/**`;
17
+ yield ` * This file was automatically generated by @algorandfoundation/algokit-client-generator.`;
18
+ yield ` * DO NOT MODIFY IT BY HAND.`;
19
+ yield ` * requires: @algorandfoundation/algokit-utils: ^2`;
20
+ yield ` */`;
21
+ yield* imports.imports();
22
+ yield* writer.inline('export const APP_SPEC: AppSpec = ', JSON.stringify(app, undefined, 2));
23
+ yield writer.NewLine;
24
+ yield* utilityTypes.utilityTypes();
25
+ yield writer.NewLine;
26
+ yield* appTypes.appTypes(ctx);
27
+ yield* deployTypes.deployTypes(ctx);
28
+ yield writer.NewLine;
29
+ // Write a call factory
30
+ yield* callFactory.callFactory(ctx);
31
+ yield writer.NewLine;
32
+ // Write a client
33
+ yield* callClient.callClient(ctx);
34
+ yield* callComposerTypes.callComposerType(ctx);
35
+ }
36
+
37
+ exports.generate = generate;
@@ -1,4 +1,3 @@
1
1
  import { DocumentParts } from '../output/writer';
2
2
  import { AlgoAppSpec } from '../schema/application';
3
3
  export declare function generate(app: AlgoAppSpec): DocumentParts;
4
- //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { inline, NewLine } from '../output/writer.mjs';
2
+ import { callFactory } from './call-factory.mjs';
3
+ import { callClient } from './call-client.mjs';
4
+ import { deployTypes } from './deploy-types.mjs';
5
+ import { utilityTypes } from './utility-types.mjs';
6
+ import { imports } from './imports.mjs';
7
+ import { createGeneratorContext } from './generator-context.mjs';
8
+ import { appTypes } from './app-types.mjs';
9
+ import { callComposerType } from './call-composer-types.mjs';
10
+
11
+ function* generate(app) {
12
+ const ctx = createGeneratorContext(app);
13
+ yield `/* eslint-disable */`;
14
+ yield `/**`;
15
+ yield ` * This file was automatically generated by @algorandfoundation/algokit-client-generator.`;
16
+ yield ` * DO NOT MODIFY IT BY HAND.`;
17
+ yield ` * requires: @algorandfoundation/algokit-utils: ^2`;
18
+ yield ` */`;
19
+ yield* imports();
20
+ yield* inline('export const APP_SPEC: AppSpec = ', JSON.stringify(app, undefined, 2));
21
+ yield NewLine;
22
+ yield* utilityTypes();
23
+ yield NewLine;
24
+ yield* appTypes(ctx);
25
+ yield* deployTypes(ctx);
26
+ yield NewLine;
27
+ // Write a call factory
28
+ yield* callFactory(ctx);
29
+ yield NewLine;
30
+ // Write a client
31
+ yield* callClient(ctx);
32
+ yield* callComposerType(ctx);
33
+ }
34
+
35
+ export { generate };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var getCallConfigSummary = require('./helpers/get-call-config-summary.cjs');
4
+ var sanitization = require('../util/sanitization.cjs');
5
+ var algokit = require('@algorandfoundation/algokit-utils');
6
+
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var algokit__namespace = /*#__PURE__*/_interopNamespaceDefault(algokit);
25
+
26
+ const createGeneratorContext = (app) => ({
27
+ app,
28
+ name: sanitization.makeSafeTypeIdentifier(app.contract.name),
29
+ callConfig: getCallConfigSummary.getCallConfigSummary(app),
30
+ methodSignatureToUniqueName: app.contract.methods.reduce((acc, cur) => {
31
+ const signature = algokit__namespace.getABIMethodSignature(cur);
32
+ acc[signature] = app.contract.methods.some((m) => m.name === cur.name && m !== cur) ? signature : cur.name;
33
+ return acc;
34
+ }, {}),
35
+ });
36
+
37
+ exports.createGeneratorContext = createGeneratorContext;
@@ -12,4 +12,3 @@ export declare const createGeneratorContext: (app: AlgoAppSpec) => {
12
12
  callConfig: CallConfigSummary;
13
13
  methodSignatureToUniqueName: Record<string, string>;
14
14
  };
15
- //# sourceMappingURL=generator-context.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { getCallConfigSummary } from './helpers/get-call-config-summary.mjs';
2
+ import { makeSafeTypeIdentifier } from '../util/sanitization.mjs';
3
+ import * as algokit from '@algorandfoundation/algokit-utils';
4
+
5
+ const createGeneratorContext = (app) => ({
6
+ app,
7
+ name: makeSafeTypeIdentifier(app.contract.name),
8
+ callConfig: getCallConfigSummary(app),
9
+ methodSignatureToUniqueName: app.contract.methods.reduce((acc, cur) => {
10
+ const signature = algokit.getABIMethodSignature(cur);
11
+ acc[signature] = app.contract.methods.some((m) => m.name === cur.name && m !== cur) ? signature : cur.name;
12
+ return acc;
13
+ }, {}),
14
+ });
15
+
16
+ export { createGeneratorContext };
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCreateOnComplete = exports.getCallConfigSummary = exports.BARE_CALL = void 0;
4
- const change_case_1 = require("change-case");
5
- exports.BARE_CALL = Symbol('bare');
1
+ 'use strict';
2
+
3
+ const BARE_CALL = Symbol('bare');
6
4
  const getCallConfigSummary = (app) => {
7
5
  const result = {
8
6
  createMethods: [],
@@ -13,7 +11,7 @@ const getCallConfigSummary = (app) => {
13
11
  closeOutMethods: [],
14
12
  };
15
13
  if (app.bare_call_config) {
16
- addToConfig(result, exports.BARE_CALL, app.bare_call_config);
14
+ addToConfig(result, BARE_CALL, app.bare_call_config);
17
15
  }
18
16
  if (app.hints) {
19
17
  for (const [method, hints] of Object.entries(app.hints)) {
@@ -24,24 +22,6 @@ const getCallConfigSummary = (app) => {
24
22
  }
25
23
  return result;
26
24
  };
27
- exports.getCallConfigSummary = getCallConfigSummary;
28
- const getCreateOnComplete = (app, method) => {
29
- var _a, _b;
30
- const callConfig = method === exports.BARE_CALL ? app.bare_call_config : (_b = (_a = app.hints) === null || _a === void 0 ? void 0 : _a[method]) === null || _b === void 0 ? void 0 : _b.call_config;
31
- if (!callConfig) {
32
- return '';
33
- }
34
- const hasNoOp = callConfig.no_op === 'ALL' || callConfig.no_op === 'CREATE';
35
- return `{ onCompleteAction${hasNoOp ? '?' : ''}: ${getCreateOnCompleteTypes(callConfig)} }`;
36
- };
37
- exports.getCreateOnComplete = getCreateOnComplete;
38
- const getCreateOnCompleteTypes = (config) => {
39
- return Object.keys(config)
40
- .map((oc) => oc)
41
- .filter((oc) => config[oc] === 'ALL' || config[oc] === 'CREATE')
42
- .map((oc) => `'${oc}' | OnApplicationComplete.${(0, change_case_1.pascalCase)(oc)}OC`)
43
- .join(' | ');
44
- };
45
25
  const addToConfig = (result, method, config) => {
46
26
  if (hasCall(config.no_op)) {
47
27
  result.callMethods.push(method);
@@ -72,4 +52,6 @@ const hasCall = (config) => {
72
52
  const hasCreate = (config) => {
73
53
  return config === 'CREATE' || config === 'ALL';
74
54
  };
75
- //# sourceMappingURL=get-call-config-summary.js.map
55
+
56
+ exports.BARE_CALL = BARE_CALL;
57
+ exports.getCallConfigSummary = getCallConfigSummary;
@@ -1,4 +1,4 @@
1
- import { AlgoAppSpec } from '../../schema/application';
1
+ import { AlgoAppSpec } from '../../schema/application.js';
2
2
  export declare const BARE_CALL: unique symbol;
3
3
  export type MethodIdentifier = string | typeof BARE_CALL;
4
4
  export type MethodList = Array<MethodIdentifier>;
@@ -12,4 +12,3 @@ export type CallConfigSummary = {
12
12
  };
13
13
  export declare const getCallConfigSummary: (app: AlgoAppSpec) => CallConfigSummary;
14
14
  export declare const getCreateOnComplete: (app: AlgoAppSpec, method: MethodIdentifier) => string;
15
- //# sourceMappingURL=get-call-config-summary.d.ts.map
@@ -0,0 +1,54 @@
1
+ const BARE_CALL = Symbol('bare');
2
+ const getCallConfigSummary = (app) => {
3
+ const result = {
4
+ createMethods: [],
5
+ callMethods: [],
6
+ deleteMethods: [],
7
+ updateMethods: [],
8
+ optInMethods: [],
9
+ closeOutMethods: [],
10
+ };
11
+ if (app.bare_call_config) {
12
+ addToConfig(result, BARE_CALL, app.bare_call_config);
13
+ }
14
+ if (app.hints) {
15
+ for (const [method, hints] of Object.entries(app.hints)) {
16
+ if (hints.call_config) {
17
+ addToConfig(result, method, hints.call_config);
18
+ }
19
+ }
20
+ }
21
+ return result;
22
+ };
23
+ const addToConfig = (result, method, config) => {
24
+ if (hasCall(config.no_op)) {
25
+ result.callMethods.push(method);
26
+ }
27
+ if (hasCreate(config.no_op) ||
28
+ hasCreate(config.opt_in) ||
29
+ hasCreate(config.close_out) ||
30
+ hasCreate(config.update_application) ||
31
+ hasCreate(config.delete_application)) {
32
+ result.createMethods.push(method);
33
+ }
34
+ if (hasCall(config.delete_application)) {
35
+ result.deleteMethods.push(method);
36
+ }
37
+ if (hasCall(config.update_application)) {
38
+ result.updateMethods.push(method);
39
+ }
40
+ if (hasCall(config.opt_in)) {
41
+ result.optInMethods.push(method);
42
+ }
43
+ if (hasCall(config.close_out)) {
44
+ result.closeOutMethods.push(method);
45
+ }
46
+ };
47
+ const hasCall = (config) => {
48
+ return config === 'CALL' || config === 'ALL';
49
+ };
50
+ const hasCreate = (config) => {
51
+ return config === 'CREATE' || config === 'ALL';
52
+ };
53
+
54
+ export { BARE_CALL, getCallConfigSummary };