@algorandfoundation/algokit-client-generator 3.0.6 → 4.0.0-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.
- package/README.md +4 -2
- package/cli.js +1 -1
- package/cli.js.map +1 -1
- package/cli.mjs +1 -1
- package/cli.mjs.map +1 -1
- package/client/{call-factory.d.ts → app-client.d.ts} +1 -1
- package/client/app-client.js +288 -0
- package/client/app-client.js.map +1 -0
- package/client/app-client.mjs +286 -0
- package/client/app-client.mjs.map +1 -0
- package/client/{call-client.d.ts → app-factory.d.ts} +1 -1
- package/client/app-factory.js +238 -0
- package/client/app-factory.js.map +1 -0
- package/client/app-factory.mjs +236 -0
- package/client/app-factory.mjs.map +1 -0
- package/client/app-types.js +196 -98
- package/client/app-types.js.map +1 -1
- package/client/app-types.mjs +196 -79
- package/client/app-types.mjs.map +1 -1
- package/client/call-composer-types.js +23 -53
- package/client/call-composer-types.js.map +1 -1
- package/client/call-composer-types.mjs +23 -34
- package/client/call-composer-types.mjs.map +1 -1
- package/client/call-composer.js +43 -57
- package/client/call-composer.js.map +1 -1
- package/client/call-composer.mjs +45 -40
- package/client/call-composer.mjs.map +1 -1
- package/client/deploy-types.d.ts +8 -4
- package/client/deploy-types.js +52 -34
- package/client/deploy-types.js.map +1 -1
- package/client/deploy-types.mjs +53 -36
- package/client/deploy-types.mjs.map +1 -1
- package/client/generate.d.ts +2 -2
- package/client/generate.js +18 -6
- package/client/generate.js.map +1 -1
- package/client/generate.mjs +18 -6
- package/client/generate.mjs.map +1 -1
- package/client/generator-context.d.ts +4 -4
- package/client/generator-context.js +5 -24
- package/client/generator-context.js.map +1 -1
- package/client/generator-context.mjs +5 -5
- package/client/generator-context.mjs.map +1 -1
- package/client/helpers/get-call-config-summary.d.ts +8 -3
- package/client/helpers/get-call-config-summary.js +22 -20
- package/client/helpers/get-call-config-summary.js.map +1 -1
- package/client/helpers/get-call-config-summary.mjs +22 -20
- package/client/helpers/get-call-config-summary.mjs.map +1 -1
- package/client/helpers/get-equivalent-type.d.ts +6 -1
- package/client/helpers/get-equivalent-type.js +10 -6
- package/client/helpers/get-equivalent-type.js.map +1 -1
- package/client/helpers/get-equivalent-type.mjs +10 -6
- package/client/helpers/get-equivalent-type.mjs.map +1 -1
- package/client/imports.js +18 -24
- package/client/imports.js.map +1 -1
- package/client/imports.mjs +18 -24
- package/client/imports.mjs.map +1 -1
- package/client/params-factory.d.ts +3 -0
- package/client/params-factory.js +126 -0
- package/client/params-factory.js.map +1 -0
- package/client/params-factory.mjs +124 -0
- package/client/params-factory.mjs.map +1 -0
- package/client/utility-types.d.ts +0 -7
- package/client/utility-types.js +37 -50
- package/client/utility-types.js.map +1 -1
- package/client/utility-types.mjs +38 -50
- package/client/utility-types.mjs.map +1 -1
- package/output/writer.js +17 -3
- package/output/writer.js.map +1 -1
- package/output/writer.mjs +17 -3
- package/output/writer.mjs.map +1 -1
- package/package.json +4 -3
- package/schema/application.schema.json.js +2 -2
- package/schema/application.schema.json.mjs +2 -2
- package/schema/arc56.schema.json.js +787 -0
- package/schema/arc56.schema.json.js.map +1 -0
- package/schema/arc56.schema.json.mjs +780 -0
- package/schema/arc56.schema.json.mjs.map +1 -0
- package/schema/load.d.ts +3 -3
- package/schema/load.js +21 -7
- package/schema/load.js.map +1 -1
- package/schema/load.mjs +22 -8
- package/schema/load.mjs.map +1 -1
- package/client/call-client.js +0 -341
- package/client/call-client.js.map +0 -1
- package/client/call-client.mjs +0 -320
- package/client/call-client.mjs.map +0 -1
- package/client/call-factory.js +0 -142
- package/client/call-factory.js.map +0 -1
- package/client/call-factory.mjs +0 -121
- package/client/call-factory.mjs.map +0 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { jsDoc, IncIndent, NewLine, DecIndentAndCloseBlock, DecIndent, indent } from '../output/writer.mjs';
|
|
2
|
+
import { BARE_CALL } from './helpers/get-call-config-summary.mjs';
|
|
3
|
+
import { getCreateOnCompleteOptions } from './deploy-types.mjs';
|
|
4
|
+
import { ABIMethod } from 'algosdk';
|
|
5
|
+
|
|
6
|
+
function* appFactory(ctx) {
|
|
7
|
+
const { app, name } = ctx;
|
|
8
|
+
yield* jsDoc(`A factory to create and deploy one or more instance of the ${app.name} smart contract and to create one or more app clients to interact with those (or other) app instances`);
|
|
9
|
+
yield `export class ${name}Factory {`;
|
|
10
|
+
yield IncIndent;
|
|
11
|
+
yield* jsDoc(`The underlying \`AppFactory\` for when you want to have more flexibility`);
|
|
12
|
+
yield 'public readonly appFactory: AppFactory';
|
|
13
|
+
yield NewLine;
|
|
14
|
+
yield* jsDoc({
|
|
15
|
+
description: `Creates a new instance of \`${name}Factory\``,
|
|
16
|
+
params: {
|
|
17
|
+
params: 'The parameters to initialise the app factory with',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
yield `
|
|
21
|
+
constructor(params: Expand<Omit<AppFactoryParams, 'appSpec'>>) {
|
|
22
|
+
this.appFactory = new AppFactory({
|
|
23
|
+
...params,
|
|
24
|
+
appSpec: APP_SPEC,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns a new \`AppClient\` client for an app instance of the given ID.
|
|
30
|
+
*
|
|
31
|
+
* Automatically populates appName, defaultSender and source maps from the factory
|
|
32
|
+
* if not specified in the params.
|
|
33
|
+
* @param params The parameters to create the app client
|
|
34
|
+
* @returns The \`AppClient\`
|
|
35
|
+
*/
|
|
36
|
+
public getAppClientById(params: Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>) {
|
|
37
|
+
return new ${name}Client(this.appFactory.getAppClientById(params))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns a new \`AppClient\` client, resolving the app by creator address and name
|
|
42
|
+
* using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
|
|
43
|
+
*
|
|
44
|
+
* Automatically populates appName, defaultSender and source maps from the factory
|
|
45
|
+
* if not specified in the params.
|
|
46
|
+
* @param params The parameters to create the app client
|
|
47
|
+
* @returns The \`AppClient\`
|
|
48
|
+
*/
|
|
49
|
+
public async getAppClientByCreatorAddressAndName(
|
|
50
|
+
params: Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'> & ResolveAppClientByCreatorAndName>,
|
|
51
|
+
) {
|
|
52
|
+
return new ${name}Client(await this.appFactory.getAppClientByCreatorAddressAndName(params))
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
yield* deployMethod(ctx);
|
|
56
|
+
yield* params(ctx);
|
|
57
|
+
yield* send(ctx);
|
|
58
|
+
yield DecIndentAndCloseBlock;
|
|
59
|
+
}
|
|
60
|
+
function* params(ctx) {
|
|
61
|
+
yield* jsDoc(`Get parameters to define transactions to the current app`);
|
|
62
|
+
yield `readonly params = (($this) => {`;
|
|
63
|
+
yield IncIndent;
|
|
64
|
+
yield `return {`;
|
|
65
|
+
yield IncIndent;
|
|
66
|
+
yield* paramMethods(ctx);
|
|
67
|
+
yield DecIndentAndCloseBlock;
|
|
68
|
+
yield DecIndent;
|
|
69
|
+
yield `})(this)`;
|
|
70
|
+
yield NewLine;
|
|
71
|
+
}
|
|
72
|
+
function* send(ctx) {
|
|
73
|
+
yield* jsDoc(`Send calls to the current app`);
|
|
74
|
+
yield `readonly send = (($this) => {`;
|
|
75
|
+
yield IncIndent;
|
|
76
|
+
yield `return {`;
|
|
77
|
+
yield IncIndent;
|
|
78
|
+
yield* createMethods(ctx);
|
|
79
|
+
yield DecIndentAndCloseBlock;
|
|
80
|
+
yield DecIndent;
|
|
81
|
+
yield `})(this)`;
|
|
82
|
+
yield NewLine;
|
|
83
|
+
}
|
|
84
|
+
function* createMethods(generator) {
|
|
85
|
+
const { app } = generator;
|
|
86
|
+
if (generator.callConfig.createMethods.length) {
|
|
87
|
+
yield* jsDoc(`Gets available create methods`);
|
|
88
|
+
yield `get create() {`;
|
|
89
|
+
yield IncIndent;
|
|
90
|
+
yield `return {`;
|
|
91
|
+
yield IncIndent;
|
|
92
|
+
for (const methodSig of generator.callConfig.createMethods) {
|
|
93
|
+
if (methodSig === BARE_CALL) {
|
|
94
|
+
yield* bareMethodCallParams({
|
|
95
|
+
generator,
|
|
96
|
+
name: 'bare',
|
|
97
|
+
description: `Creates a new instance of the ${app.name} smart contract using a bare call`,
|
|
98
|
+
verb: 'create',
|
|
99
|
+
type: 'send',
|
|
100
|
+
includeCompilation: true,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const method = generator.app.methods.find((m) => new ABIMethod(m).getSignature() === methodSig);
|
|
105
|
+
yield* abiMethodCallParams({
|
|
106
|
+
generator,
|
|
107
|
+
method,
|
|
108
|
+
description: `Creates a new instance of the ${app.name} smart contract using an ABI method call`,
|
|
109
|
+
verb: 'create',
|
|
110
|
+
type: 'send',
|
|
111
|
+
includeCompilation: true,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
yield DecIndentAndCloseBlock;
|
|
116
|
+
yield DecIndent;
|
|
117
|
+
yield '},';
|
|
118
|
+
yield NewLine;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function* paramMethods(ctx) {
|
|
122
|
+
const { app, callConfig } = ctx;
|
|
123
|
+
yield* operationMethods(ctx, `Creates a new instance of the ${app.name} smart contract`, callConfig.createMethods, 'create', true);
|
|
124
|
+
yield* operationMethods(ctx, `Updates an existing instance of the ${app.name} smart contract`, callConfig.updateMethods, 'deployUpdate', true);
|
|
125
|
+
yield* operationMethods(ctx, `Deletes an existing instance of the ${app.name} smart contract`, callConfig.deleteMethods, 'deployDelete');
|
|
126
|
+
}
|
|
127
|
+
function* bareMethodCallParams({ generator: { app, name: clientName }, name, description, verb, type, includeCompilation, }) {
|
|
128
|
+
const onComplete = verb === 'create' ? getCreateOnCompleteOptions(BARE_CALL, app) : undefined;
|
|
129
|
+
yield* jsDoc({
|
|
130
|
+
description: `${description}.`,
|
|
131
|
+
params: {
|
|
132
|
+
params: `The params for the bare (non-ABI) call`,
|
|
133
|
+
},
|
|
134
|
+
returns: type === 'params' ? `The params for a ${verb} call` : `The ${verb} result`,
|
|
135
|
+
});
|
|
136
|
+
yield `${type === 'send' ? 'async ' : ''}${name}(params?: Expand<AppClientBareCallParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${verb === 'create' ? ' & CreateSchema' : ''}${type === 'send' ? ' & ExecuteParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}>) {`;
|
|
137
|
+
if (type === 'params') {
|
|
138
|
+
yield* indent(`return $this.appFactory.params.bare.${verb}(params)`);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
yield* indent(`const result = await $this.appFactory.create(params)`, `return { result: result.result, app: new ${clientName}Client(result.app) }`);
|
|
142
|
+
}
|
|
143
|
+
yield '},';
|
|
144
|
+
}
|
|
145
|
+
function* abiMethodCallParams({ generator: { app, methodSignatureToUniqueName, name, sanitizer }, method, description, verb, type, includeCompilation, }) {
|
|
146
|
+
const methodSig = new ABIMethod(method).getSignature();
|
|
147
|
+
const uniqueName = methodSignatureToUniqueName[methodSig];
|
|
148
|
+
const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined;
|
|
149
|
+
yield* jsDoc({
|
|
150
|
+
description: `${description} using the ${methodSig} ABI method.`,
|
|
151
|
+
abiDescription: method?.desc,
|
|
152
|
+
params: {
|
|
153
|
+
params: `The params for the smart contract call`,
|
|
154
|
+
},
|
|
155
|
+
returns: `The ${verb} ${type === 'params' ? 'params' : 'result'}${method?.returns?.desc ? `: ${method.returns.desc}` : ''}`,
|
|
156
|
+
});
|
|
157
|
+
const methodName = sanitizer.makeSafeMethodIdentifier(uniqueName);
|
|
158
|
+
const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName);
|
|
159
|
+
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig);
|
|
160
|
+
yield `${type === 'send' ? 'async ' : ''}${methodName}(params: Expand<CallParams<'${methodSigSafe}'>${includeCompilation ? ' & AppClientCompilationParams' : ''}${verb === 'create' ? ' & CreateSchema' : ''}${type === 'send' ? ' & ExecuteParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}>${onComplete?.isOptional !== false && (method.args.length === 0 || !method.args.some((a) => !a.defaultValue)) ? ` = {args: [${method.args.map((_) => 'undefined').join(', ')}]}` : ''}) {`;
|
|
161
|
+
if (type === 'params') {
|
|
162
|
+
yield* indent(`return $this.appFactory.params.${verb}(${name}ParamsFactory.${verb == 'deployDelete' ? 'delete' : verb === 'deployUpdate' ? 'update' : verb}${methodNameAccessor}(params))`);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
yield* indent(`const result = await $this.appFactory.create(${name}ParamsFactory.${verb}${methodNameAccessor}(params))`, `return { result: { ...result.result, return: result.result.return as undefined | MethodReturn<'${methodSigSafe}'> }, app: new ${name}Client(result.app) }`);
|
|
166
|
+
}
|
|
167
|
+
yield '},';
|
|
168
|
+
}
|
|
169
|
+
function* operationMethods(generator, description, methods, verb, includeCompilation) {
|
|
170
|
+
if (methods.length) {
|
|
171
|
+
yield* jsDoc(`Gets available ${verb} methods`);
|
|
172
|
+
yield `get ${verb}() {`;
|
|
173
|
+
yield IncIndent;
|
|
174
|
+
yield `return {`;
|
|
175
|
+
yield IncIndent;
|
|
176
|
+
for (const methodSig of methods) {
|
|
177
|
+
if (methodSig === BARE_CALL) {
|
|
178
|
+
yield* bareMethodCallParams({
|
|
179
|
+
generator,
|
|
180
|
+
name: 'bare',
|
|
181
|
+
description: `${description} using a bare call`,
|
|
182
|
+
verb,
|
|
183
|
+
type: 'params',
|
|
184
|
+
includeCompilation,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const method = generator.app.methods.find((m) => new ABIMethod(m).getSignature() === methodSig);
|
|
189
|
+
yield* abiMethodCallParams({
|
|
190
|
+
generator,
|
|
191
|
+
method,
|
|
192
|
+
description,
|
|
193
|
+
verb,
|
|
194
|
+
type: 'params',
|
|
195
|
+
includeCompilation,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
yield DecIndentAndCloseBlock;
|
|
200
|
+
yield DecIndent;
|
|
201
|
+
yield '},';
|
|
202
|
+
yield NewLine;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function* deployMethod(ctx) {
|
|
206
|
+
const { app, callConfig, name } = ctx;
|
|
207
|
+
yield* jsDoc({
|
|
208
|
+
description: `Idempotently deploys the ${app.name} smart contract.`,
|
|
209
|
+
params: {
|
|
210
|
+
params: 'The arguments for the contract calls and any additional parameters for the call',
|
|
211
|
+
},
|
|
212
|
+
returns: 'The deployment result',
|
|
213
|
+
});
|
|
214
|
+
yield `public async deploy(params: ${name}DeployParams = {}) {`;
|
|
215
|
+
yield IncIndent;
|
|
216
|
+
yield `const result = await this.appFactory.deploy({`;
|
|
217
|
+
yield IncIndent;
|
|
218
|
+
yield `...params,`;
|
|
219
|
+
if (callConfig.createMethods.filter((m) => m !== BARE_CALL).length) {
|
|
220
|
+
yield `createParams: params.createParams?.method ? ${name}ParamsFactory.create._resolveByMethod(params.createParams) : params.createParams,`;
|
|
221
|
+
}
|
|
222
|
+
if (callConfig.updateMethods.filter((m) => m !== BARE_CALL).length) {
|
|
223
|
+
yield `updateParams: params.updateParams?.method ? ${name}ParamsFactory.update._resolveByMethod(params.updateParams) : params.updateParams,`;
|
|
224
|
+
}
|
|
225
|
+
if (callConfig.deleteMethods.filter((m) => m !== BARE_CALL).length) {
|
|
226
|
+
yield `deleteParams: params.deleteParams?.method ? ${name}ParamsFactory.delete._resolveByMethod(params.deleteParams) : params.deleteParams,`;
|
|
227
|
+
}
|
|
228
|
+
yield DecIndent;
|
|
229
|
+
yield `})`;
|
|
230
|
+
yield `return { result: result.result, app: new ${name}Client(result.app) }`;
|
|
231
|
+
yield DecIndentAndCloseBlock;
|
|
232
|
+
yield NewLine;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { appFactory };
|
|
236
|
+
//# sourceMappingURL=app-factory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-factory.mjs","sources":["../../src/client/app-factory.ts"],"sourcesContent":["import { DecIndent, DecIndentAndCloseBlock, DocumentParts, IncIndent, indent, jsDoc, NewLine } from '../output/writer'\nimport { BARE_CALL, MethodList } from './helpers/get-call-config-summary'\nimport { GeneratorContext } from './generator-context'\nimport { getCreateOnCompleteOptions } from './deploy-types'\nimport { ABIMethod } from 'algosdk'\nimport { Method } from '@algorandfoundation/algokit-utils/types/app-arc56'\n\nexport function* appFactory(ctx: GeneratorContext): DocumentParts {\n const { app, name } = ctx\n\n yield* jsDoc(\n `A factory to create and deploy one or more instance of the ${app.name} smart contract and to create one or more app clients to interact with those (or other) app instances`,\n )\n yield `export class ${name}Factory {`\n yield IncIndent\n yield* jsDoc(`The underlying \\`AppFactory\\` for when you want to have more flexibility`)\n yield 'public readonly appFactory: AppFactory'\n yield NewLine\n\n yield* jsDoc({\n description: `Creates a new instance of \\`${name}Factory\\``,\n params: {\n params: 'The parameters to initialise the app factory with',\n },\n })\n\n yield `\n constructor(params: Expand<Omit<AppFactoryParams, 'appSpec'>>) {\n this.appFactory = new AppFactory({\n ...params,\n appSpec: APP_SPEC,\n })\n }\n\n /**\n * Returns a new \\`AppClient\\` client for an app instance of the given ID.\n *\n * Automatically populates appName, defaultSender and source maps from the factory\n * if not specified in the params.\n * @param params The parameters to create the app client\n * @returns The \\`AppClient\\`\n */\n public getAppClientById(params: Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>) {\n return new ${name}Client(this.appFactory.getAppClientById(params))\n }\n\n /**\n * Returns a new \\`AppClient\\` client, resolving the app by creator address and name\n * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n *\n * Automatically populates appName, defaultSender and source maps from the factory\n * if not specified in the params.\n * @param params The parameters to create the app client\n * @returns The \\`AppClient\\`\n */\n public async getAppClientByCreatorAddressAndName(\n params: Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'> & ResolveAppClientByCreatorAndName>,\n ) {\n return new ${name}Client(await this.appFactory.getAppClientByCreatorAddressAndName(params))\n }\n `\n\n yield* deployMethod(ctx)\n yield* params(ctx)\n yield* send(ctx)\n yield DecIndentAndCloseBlock\n}\n\nfunction* params(ctx: GeneratorContext): DocumentParts {\n yield* jsDoc(`Get parameters to define transactions to the current app`)\n yield `readonly params = (($this) => {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n yield* paramMethods(ctx)\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield `})(this)`\n yield NewLine\n}\n\nfunction* send(ctx: GeneratorContext): DocumentParts {\n yield* jsDoc(`Send calls to the current app`)\n yield `readonly send = (($this) => {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n yield* createMethods(ctx)\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield `})(this)`\n yield NewLine\n}\n\nfunction* createMethods(generator: GeneratorContext): DocumentParts {\n const { app } = generator\n if (generator.callConfig.createMethods.length) {\n yield* jsDoc(`Gets available create methods`)\n yield `get create() {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n for (const methodSig of generator.callConfig.createMethods) {\n if (methodSig === BARE_CALL) {\n yield* bareMethodCallParams({\n generator,\n name: 'bare',\n description: `Creates a new instance of the ${app.name} smart contract using a bare call`,\n verb: 'create',\n type: 'send',\n includeCompilation: true,\n })\n } else {\n const method = generator.app.methods.find((m) => new ABIMethod(m).getSignature() === methodSig)!\n yield* abiMethodCallParams({\n generator,\n method,\n description: `Creates a new instance of the ${app.name} smart contract using an ABI method call`,\n verb: 'create',\n type: 'send',\n includeCompilation: true,\n })\n }\n }\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield '},'\n yield NewLine\n }\n}\n\nfunction* paramMethods(ctx: GeneratorContext): DocumentParts {\n const { app, callConfig } = ctx\n\n yield* operationMethods(ctx, `Creates a new instance of the ${app.name} smart contract`, callConfig.createMethods, 'create', true)\n\n yield* operationMethods(\n ctx,\n `Updates an existing instance of the ${app.name} smart contract`,\n callConfig.updateMethods,\n 'deployUpdate',\n true,\n )\n yield* operationMethods(ctx, `Deletes an existing instance of the ${app.name} smart contract`, callConfig.deleteMethods, 'deployDelete')\n}\n\nfunction* bareMethodCallParams({\n generator: { app, name: clientName },\n name,\n description,\n verb,\n type,\n includeCompilation,\n}: {\n generator: GeneratorContext\n name: string\n description: string\n verb: 'create' | 'deployUpdate' | 'deployDelete'\n type: 'params' | 'send'\n includeCompilation?: boolean\n}): DocumentParts {\n const onComplete = verb === 'create' ? getCreateOnCompleteOptions(BARE_CALL, app) : undefined\n yield* jsDoc({\n description: `${description}.`,\n params: {\n params: `The params for the bare (non-ABI) call`,\n },\n returns: type === 'params' ? `The params for a ${verb} call` : `The ${verb} result`,\n })\n yield `${type === 'send' ? 'async ' : ''}${name}(params?: Expand<AppClientBareCallParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n verb === 'create' ? ' & CreateSchema' : ''\n }${type === 'send' ? ' & ExecuteParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}>) {`\n if (type === 'params') {\n yield* indent(`return $this.appFactory.params.bare.${verb}(params)`)\n } else {\n yield* indent(\n `const result = await $this.appFactory.create(params)`,\n `return { result: result.result, app: new ${clientName}Client(result.app) }`,\n )\n }\n yield '},'\n}\n\nfunction* abiMethodCallParams({\n generator: { app, methodSignatureToUniqueName, name, sanitizer },\n method,\n description,\n verb,\n type,\n includeCompilation,\n}: {\n generator: GeneratorContext\n method: Method\n description: string\n verb: 'create' | 'deployUpdate' | 'deployDelete'\n type: 'params' | 'send'\n includeCompilation?: boolean\n}) {\n const methodSig = new ABIMethod(method).getSignature()\n const uniqueName = methodSignatureToUniqueName[methodSig]\n const onComplete = verb === 'create' ? getCreateOnCompleteOptions(methodSig, app) : undefined\n yield* jsDoc({\n description: `${description} using the ${methodSig} ABI method.`,\n abiDescription: method?.desc,\n params: {\n params: `The params for the smart contract call`,\n },\n returns: `The ${verb} ${type === 'params' ? 'params' : 'result'}${method?.returns?.desc ? `: ${method.returns.desc}` : ''}`,\n })\n const methodName = sanitizer.makeSafeMethodIdentifier(uniqueName)\n const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName)\n const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig)\n yield `${type === 'send' ? 'async ' : ''}${methodName}(params: Expand<CallParams<'${methodSigSafe}'>${includeCompilation ? ' & AppClientCompilationParams' : ''}${\n verb === 'create' ? ' & CreateSchema' : ''\n }${type === 'send' ? ' & ExecuteParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}>${onComplete?.isOptional !== false && (method.args.length === 0 || !method.args.some((a) => !a.defaultValue)) ? ` = {args: [${method.args.map((_) => 'undefined').join(', ')}]}` : ''}) {`\n if (type === 'params') {\n yield* indent(\n `return $this.appFactory.params.${verb}(${name}ParamsFactory.${verb == 'deployDelete' ? 'delete' : verb === 'deployUpdate' ? 'update' : verb}${methodNameAccessor}(params))`,\n )\n } else {\n yield* indent(\n `const result = await $this.appFactory.create(${name}ParamsFactory.${verb}${methodNameAccessor}(params))`,\n `return { result: { ...result.result, return: result.result.return as undefined | MethodReturn<'${methodSigSafe}'> }, app: new ${name}Client(result.app) }`,\n )\n }\n yield '},'\n}\n\nfunction* operationMethods(\n generator: GeneratorContext,\n description: string,\n methods: MethodList,\n verb: 'create' | 'deployUpdate' | 'deployDelete',\n includeCompilation?: boolean,\n): DocumentParts {\n if (methods.length) {\n yield* jsDoc(`Gets available ${verb} methods`)\n yield `get ${verb}() {`\n yield IncIndent\n yield `return {`\n yield IncIndent\n for (const methodSig of methods) {\n if (methodSig === BARE_CALL) {\n yield* bareMethodCallParams({\n generator,\n name: 'bare',\n description: `${description} using a bare call`,\n verb,\n type: 'params',\n includeCompilation,\n })\n } else {\n const method = generator.app.methods.find((m) => new ABIMethod(m).getSignature() === methodSig)!\n yield* abiMethodCallParams({\n generator,\n method,\n description,\n verb,\n type: 'params',\n includeCompilation,\n })\n }\n }\n yield DecIndentAndCloseBlock\n yield DecIndent\n yield '},'\n yield NewLine\n }\n}\n\nfunction* deployMethod(ctx: GeneratorContext): DocumentParts {\n const { app, callConfig, name } = ctx\n yield* jsDoc({\n description: `Idempotently deploys the ${app.name} smart contract.`,\n params: {\n params: 'The arguments for the contract calls and any additional parameters for the call',\n },\n returns: 'The deployment result',\n })\n yield `public async deploy(params: ${name}DeployParams = {}) {`\n yield IncIndent\n\n yield `const result = await this.appFactory.deploy({`\n yield IncIndent\n yield `...params,`\n if (callConfig.createMethods.filter((m) => m !== BARE_CALL).length) {\n yield `createParams: params.createParams?.method ? ${name}ParamsFactory.create._resolveByMethod(params.createParams) : params.createParams,`\n }\n if (callConfig.updateMethods.filter((m) => m !== BARE_CALL).length) {\n yield `updateParams: params.updateParams?.method ? ${name}ParamsFactory.update._resolveByMethod(params.updateParams) : params.updateParams,`\n }\n if (callConfig.deleteMethods.filter((m) => m !== BARE_CALL).length) {\n yield `deleteParams: params.deleteParams?.method ? ${name}ParamsFactory.delete._resolveByMethod(params.deleteParams) : params.deleteParams,`\n }\n yield DecIndent\n yield `})`\n yield `return { result: result.result, app: new ${name}Client(result.app) }`\n yield DecIndentAndCloseBlock\n yield NewLine\n}\n"],"names":[],"mappings":";;;;;AAOe,UAAE,UAAU,CAAC,GAAqB,EAAA;AAC/C,IAAA,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;IAEzB,OAAO,KAAK,CACV,CAAA,2DAAA,EAA8D,GAAG,CAAC,IAAI,CAAuG,qGAAA,CAAA,CAC9K,CAAA;IACD,MAAM,CAAA,aAAA,EAAgB,IAAI,CAAA,SAAA,CAAW,CAAA;AACrC,IAAA,MAAM,SAAS,CAAA;AACf,IAAA,OAAO,KAAK,CAAC,CAAA,wEAAA,CAA0E,CAAC,CAAA;AACxF,IAAA,MAAM,wCAAwC,CAAA;AAC9C,IAAA,MAAM,OAAO,CAAA;IAEb,O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S,CAAC,CAAC,MAAM,EAAE;QAClE,MAAM,CAAA,4CAAA,EAA+C,IAAI,CAAA,iFAAA,CAAmF,CAAA;KAC7I;AACD,IAAA,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,CAAC,MAAM,EAAE;QAClE,MAAM,CAAA,4CAAA,EAA+C,IAAI,CAAA,iFAAA,CAAmF,CAAA;KAC7I;AACD,IAAA,MAAM,SAAS,CAAA;AACf,IAAA,MAAM,IAAI,CAAA;IACV,MAAM,CAAA,yCAAA,EAA4C,IAAI,CAAA,oBAAA,CAAsB,CAAA;AAC5E,IAAA,MAAM,sBAAsB,CAAA;AAC5B,IAAA,MAAM,OAAO,CAAA;AACf;;;;"}
|
package/client/app-types.js
CHANGED
|
@@ -1,43 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var writer = require('../output/writer.js');
|
|
4
|
-
var algokit = require('@algorandfoundation/algokit-utils');
|
|
5
4
|
var getEquivalentType = require('./helpers/get-equivalent-type.js');
|
|
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);
|
|
5
|
+
var algosdk = require('algosdk');
|
|
25
6
|
|
|
26
7
|
function* appTypes(ctx) {
|
|
8
|
+
yield* abiTypes(ctx);
|
|
9
|
+
yield* structTypes(ctx);
|
|
10
|
+
yield* templateVariableTypes(ctx);
|
|
27
11
|
const { app, methodSignatureToUniqueName, name } = ctx;
|
|
28
12
|
yield* writer.jsDoc(`Defines the types of available calls and state of the ${name} smart contract.`);
|
|
29
|
-
yield `export type ${name} = {`;
|
|
13
|
+
yield `export type ${name}Types = {`;
|
|
30
14
|
yield writer.IncIndent;
|
|
31
15
|
yield* writer.jsDoc('Maps method signatures / names to their argument and return types.');
|
|
32
|
-
if (app.
|
|
16
|
+
if (app.methods.length == 0) {
|
|
33
17
|
yield 'methods: {}';
|
|
34
18
|
}
|
|
35
19
|
else {
|
|
36
20
|
yield 'methods:';
|
|
37
21
|
}
|
|
38
22
|
yield writer.IncIndent;
|
|
39
|
-
for (const method of app.
|
|
40
|
-
const methodSig =
|
|
23
|
+
for (const method of app.methods) {
|
|
24
|
+
const methodSig = new algosdk.ABIMethod(method).getSignature();
|
|
41
25
|
const methodSigSafe = ctx.sanitizer.makeSafeStringTypeLiteral(methodSig);
|
|
42
26
|
const uniqueName = methodSignatureToUniqueName[methodSig];
|
|
43
27
|
const uniqueNameSafe = ctx.sanitizer.makeSafeStringTypeLiteral(uniqueName);
|
|
@@ -45,10 +29,11 @@ function* appTypes(ctx) {
|
|
|
45
29
|
yield writer.IncIndent;
|
|
46
30
|
yield `argsObj: {`;
|
|
47
31
|
yield writer.IncIndent;
|
|
48
|
-
const argsMeta = method.args.map((arg) => ({
|
|
32
|
+
const argsMeta = method.args.map((arg, i) => ({
|
|
49
33
|
...arg,
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
name: arg.name ?? `arg${i + 1}`,
|
|
35
|
+
hasDefault: !!arg.defaultValue,
|
|
36
|
+
tsType: getEquivalentType.getEquivalentType(arg.struct ?? arg.type, 'input', ctx),
|
|
52
37
|
}));
|
|
53
38
|
for (const arg of argsMeta) {
|
|
54
39
|
if (arg.desc)
|
|
@@ -57,104 +42,217 @@ function* appTypes(ctx) {
|
|
|
57
42
|
}
|
|
58
43
|
yield writer.DecIndentAndCloseBlock;
|
|
59
44
|
yield* writer.inline(`argsTuple: [`, argsMeta
|
|
60
|
-
.map((arg) => `${ctx.sanitizer.makeSafeVariableIdentifier(arg.name)}: ${
|
|
45
|
+
.map((arg) => `${ctx.sanitizer.makeSafeVariableIdentifier(arg.name)}: ${arg.tsType}${arg.hasDefault ? ' | undefined' : ''}`)
|
|
61
46
|
.join(', '), ']');
|
|
62
|
-
const outputStruct = ctx.app.hints?.[methodSig]?.structs?.output;
|
|
63
47
|
if (method.returns.desc)
|
|
64
48
|
yield* writer.jsDoc(method.returns.desc);
|
|
65
|
-
|
|
66
|
-
yield `returns: ${ctx.sanitizer.makeSafeTypeIdentifier(outputStruct.name)}`;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
yield `returns: ${getEquivalentType.getEquivalentType(method.returns.type ?? 'void', 'output')}`;
|
|
70
|
-
}
|
|
49
|
+
yield `returns: ${getEquivalentType.getEquivalentType(method.returns.struct ?? method.returns.type ?? 'void', 'output', ctx)}`;
|
|
71
50
|
yield writer.DecIndent;
|
|
72
51
|
yield '}>';
|
|
73
52
|
}
|
|
74
53
|
yield writer.DecIndent;
|
|
75
|
-
|
|
54
|
+
const hasLocal = (app.state.keys.local && Object.keys(app.state.keys.local).length > 0) ||
|
|
55
|
+
(app.state.maps.local && Object.keys(app.state.maps.local).length > 0);
|
|
56
|
+
const hasGlobal = (app.state.keys.global && Object.keys(app.state.keys.global).length > 0) ||
|
|
57
|
+
(app.state.maps.global && Object.keys(app.state.maps.global).length > 0);
|
|
58
|
+
const hasBox = (app.state.keys.box && Object.keys(app.state.keys.box).length > 0) || (app.state.maps.box && Object.keys(app.state.maps.box).length > 0);
|
|
59
|
+
yield* appState(ctx, { hasBox, hasGlobal, hasLocal });
|
|
76
60
|
yield writer.DecIndentAndCloseBlock;
|
|
77
|
-
yield
|
|
78
|
-
yield `
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
61
|
+
yield writer.NewLine;
|
|
62
|
+
yield `
|
|
63
|
+
/**
|
|
64
|
+
* Defines the possible abi call signatures.
|
|
65
|
+
*/
|
|
66
|
+
export type ${name}Signatures = keyof ${name}Types['methods']
|
|
67
|
+
/**
|
|
68
|
+
* Defines the possible abi call signatures for methods that return a non-void value.
|
|
69
|
+
*/
|
|
70
|
+
export type ${name}NonVoidMethodSignatures = keyof ${name}Types['methods'] extends infer T ? T extends keyof ${name}Types['methods'] ? MethodReturn<T> extends void ? never : T : never : never
|
|
71
|
+
/**
|
|
72
|
+
* Defines an object containing all relevant parameters for a single call to the contract.
|
|
73
|
+
*/
|
|
74
|
+
export type CallParams<TSignature extends ${name}Signatures> = Expand<
|
|
75
|
+
Omit<AppClientMethodCallParams, 'method' | 'args' | 'onComplete'> &
|
|
76
|
+
{
|
|
77
|
+
/** The args for the ABI method call, either as an ordered array or an object */
|
|
78
|
+
args: Expand<MethodArgs<TSignature>>
|
|
79
|
+
}
|
|
80
|
+
>
|
|
81
|
+
/**
|
|
82
|
+
* Maps a method signature from the ${name} smart contract to the method's arguments in either tuple or struct form
|
|
83
|
+
*/
|
|
84
|
+
export type MethodArgs<TSignature extends ${name}Signatures> = ${name}Types['methods'][TSignature]['argsObj' | 'argsTuple']
|
|
85
|
+
/**
|
|
86
|
+
* Maps a method signature from the ${name} smart contract to the method's return type
|
|
87
|
+
*/
|
|
88
|
+
export type MethodReturn<TSignature extends ${name}Signatures> = ${name}Types['methods'][TSignature]['returns']
|
|
89
|
+
`;
|
|
90
|
+
if (hasGlobal) {
|
|
91
|
+
yield `
|
|
92
|
+
/**
|
|
93
|
+
* Defines the shape of the keyed global state of the application.
|
|
94
|
+
*/
|
|
95
|
+
export type GlobalKeysState = ${name}Types['state']['global']['keys']
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
if (hasLocal) {
|
|
99
|
+
yield `
|
|
100
|
+
/**
|
|
101
|
+
* Defines the shape of the keyed local state of the application.
|
|
102
|
+
*/
|
|
103
|
+
export type LocalKeysState = ${name}Types['state']['local']['keys']
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
if (hasBox) {
|
|
107
|
+
yield `
|
|
108
|
+
/**
|
|
109
|
+
* Defines the shape of the keyed box state of the application.
|
|
110
|
+
*/
|
|
111
|
+
export type BoxKeysState = ${name}Types['state']['box']['keys']
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
94
114
|
yield writer.NewLine;
|
|
95
115
|
}
|
|
96
|
-
function*
|
|
97
|
-
|
|
116
|
+
function* abiTypes(ctx) {
|
|
117
|
+
const { app } = ctx;
|
|
118
|
+
const abiTypes = [];
|
|
119
|
+
const pushType = (type) => {
|
|
120
|
+
// If we already have this type, skip
|
|
121
|
+
if (abiTypes.includes(type))
|
|
122
|
+
return;
|
|
123
|
+
// void and string are the same types in TS
|
|
124
|
+
if (['void', 'string'].includes(type))
|
|
125
|
+
return;
|
|
126
|
+
// Skip structs
|
|
127
|
+
if (app.structs[type])
|
|
128
|
+
return;
|
|
129
|
+
// If this is an array type, push the base type
|
|
130
|
+
if (type.match(/\[\d*\]$/)) {
|
|
131
|
+
pushType(type.replace(/\[\d*\]$/, ''));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (type.startsWith('(')) {
|
|
135
|
+
const tupleType = algosdk.ABITupleType.from(type);
|
|
136
|
+
tupleType.childTypes.forEach((t) => {
|
|
137
|
+
pushType(t.toString());
|
|
138
|
+
});
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
abiTypes.push(type);
|
|
142
|
+
};
|
|
143
|
+
Object.values(app.templateVariables ?? {}).forEach((t) => {
|
|
144
|
+
pushType(t.type);
|
|
145
|
+
});
|
|
146
|
+
app.methods.forEach((m) => {
|
|
147
|
+
m.args.forEach((a) => {
|
|
148
|
+
pushType(a.type);
|
|
149
|
+
});
|
|
150
|
+
pushType(m.returns.type);
|
|
151
|
+
});
|
|
152
|
+
['global', 'local', 'box'].forEach((storageType) => {
|
|
153
|
+
Object.values(app.state.keys[storageType]).forEach((k) => {
|
|
154
|
+
pushType(k.keyType);
|
|
155
|
+
pushType(k.valueType);
|
|
156
|
+
});
|
|
157
|
+
Object.values(app.state.maps[storageType]).forEach((m) => {
|
|
158
|
+
pushType(m.keyType);
|
|
159
|
+
pushType(m.valueType);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
const pushStructFields = (fields) => {
|
|
163
|
+
Object.values(fields).forEach((sf) => {
|
|
164
|
+
if (typeof sf === 'string')
|
|
165
|
+
pushType(sf);
|
|
166
|
+
else
|
|
167
|
+
pushStructFields(sf);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
Object.values(app.structs).forEach((sf) => {
|
|
171
|
+
pushStructFields(sf);
|
|
172
|
+
});
|
|
173
|
+
yield '// Aliases for non-encoded ABI values';
|
|
174
|
+
yield writer.NewLine;
|
|
175
|
+
for (const t of abiTypes) {
|
|
176
|
+
yield `type ${t} = ${getEquivalentType.getEquivalentType(t, 'output', ctx)};`;
|
|
177
|
+
}
|
|
178
|
+
yield writer.NewLine;
|
|
179
|
+
}
|
|
180
|
+
function* structTypes({ app, sanitizer }) {
|
|
181
|
+
if (Object.keys(app.structs).length === 0)
|
|
98
182
|
return;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
183
|
+
yield '// Type definitions for ARC-56 structs';
|
|
184
|
+
yield writer.NewLine;
|
|
185
|
+
for (const structName of Object.keys(app.structs)) {
|
|
186
|
+
yield `export type ${sanitizer.makeSafeTypeIdentifier(structName)} = ${JSON.stringify(app.structs[structName], null, 2)
|
|
187
|
+
.replace(/"/g, '')
|
|
188
|
+
.replaceAll('(', '[')
|
|
189
|
+
.replaceAll(')', ']')
|
|
190
|
+
.replace(/\[\d+\]/g, '[]')}`;
|
|
191
|
+
}
|
|
192
|
+
yield writer.NewLine;
|
|
193
|
+
}
|
|
194
|
+
function* templateVariableTypes({ app }) {
|
|
195
|
+
if (Object.keys(app.templateVariables ?? {}).length === 0) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
yield* writer.jsDoc('Deploy-time template variables');
|
|
199
|
+
yield 'export type TemplateVariables = {';
|
|
200
|
+
yield writer.IncIndent;
|
|
201
|
+
for (const name of Object.keys(app.templateVariables ?? {})) {
|
|
202
|
+
yield `${name}: ${app.templateVariables[name].type},`;
|
|
203
|
+
}
|
|
204
|
+
yield writer.DecIndentAndCloseBlock;
|
|
205
|
+
}
|
|
206
|
+
function* keysAndMaps(app, sanitizer, keys, maps) {
|
|
207
|
+
if (keys && Object.keys(keys).length) {
|
|
208
|
+
yield 'keys: {';
|
|
209
|
+
yield writer.IncIndent;
|
|
210
|
+
for (const name of Object.keys(keys)) {
|
|
211
|
+
const prop = keys[name];
|
|
212
|
+
if (prop.desc) {
|
|
213
|
+
yield* writer.jsDoc(prop.desc);
|
|
112
214
|
}
|
|
113
|
-
|
|
114
|
-
yield
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
215
|
+
const keySafe = sanitizer.makeSafePropertyIdentifier(name);
|
|
216
|
+
yield `${keySafe}: ${prop.valueType === 'bytes' ? 'BinaryState' : getEquivalentType.getEquivalentType(prop.valueType, 'output', { app, sanitizer })}`;
|
|
217
|
+
}
|
|
218
|
+
yield writer.DecIndentAndCloseBlock;
|
|
219
|
+
}
|
|
220
|
+
if (maps && Object.keys(maps).length) {
|
|
221
|
+
yield 'maps: {';
|
|
222
|
+
yield writer.IncIndent;
|
|
223
|
+
for (const name of Object.keys(maps)) {
|
|
224
|
+
const prop = maps[name];
|
|
225
|
+
if (prop.desc) {
|
|
226
|
+
yield* writer.jsDoc(prop.desc);
|
|
123
227
|
}
|
|
124
|
-
|
|
125
|
-
yield
|
|
228
|
+
const keySafe = sanitizer.makeSafePropertyIdentifier(name);
|
|
229
|
+
yield `${keySafe}: Map<${getEquivalentType.getEquivalentType(prop.keyType, 'input', { app, sanitizer })}, ${getEquivalentType.getEquivalentType(prop.valueType, 'output', { app, sanitizer })}>`;
|
|
126
230
|
}
|
|
231
|
+
yield writer.DecIndentAndCloseBlock;
|
|
127
232
|
}
|
|
128
233
|
}
|
|
129
|
-
function* appState({ app, sanitizer }) {
|
|
130
|
-
const hasLocal =
|
|
131
|
-
const hasGlobal = app.schema.global?.declared && Object.keys(app.schema.global.declared).length;
|
|
234
|
+
function* appState({ app, sanitizer }, stateFlags) {
|
|
235
|
+
const { hasBox, hasGlobal, hasLocal } = stateFlags;
|
|
132
236
|
if (hasLocal || hasGlobal) {
|
|
133
|
-
yield* writer.jsDoc('Defines the shape of the
|
|
237
|
+
yield* writer.jsDoc('Defines the shape of the state of the application.');
|
|
134
238
|
yield 'state: {';
|
|
135
239
|
yield writer.IncIndent;
|
|
136
240
|
if (hasGlobal) {
|
|
137
241
|
yield 'global: {';
|
|
138
242
|
yield writer.IncIndent;
|
|
139
|
-
|
|
140
|
-
if (prop.descr) {
|
|
141
|
-
yield* writer.jsDoc(prop.descr);
|
|
142
|
-
}
|
|
143
|
-
const keySafe = sanitizer.makeSafePropertyIdentifier(prop.key);
|
|
144
|
-
yield `${keySafe}?: ${prop.type === 'uint64' ? 'IntegerState' : 'BinaryState'}`;
|
|
145
|
-
}
|
|
243
|
+
yield* keysAndMaps(app, sanitizer, app.state.keys.global, app.state.maps.global);
|
|
146
244
|
yield writer.DecIndentAndCloseBlock;
|
|
147
245
|
}
|
|
148
246
|
if (hasLocal) {
|
|
149
247
|
yield 'local: {';
|
|
150
248
|
yield writer.IncIndent;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
249
|
+
yield* keysAndMaps(app, sanitizer, app.state.keys.local, app.state.maps.local);
|
|
250
|
+
yield writer.DecIndentAndCloseBlock;
|
|
251
|
+
}
|
|
252
|
+
if (hasBox) {
|
|
253
|
+
yield 'box: {';
|
|
254
|
+
yield writer.IncIndent;
|
|
255
|
+
yield* keysAndMaps(app, sanitizer, app.state.keys.box, app.state.maps.box);
|
|
158
256
|
yield writer.DecIndentAndCloseBlock;
|
|
159
257
|
}
|
|
160
258
|
yield writer.DecIndentAndCloseBlock;
|