@algorandfoundation/algokit-client-generator 4.0.0-beta.1 → 4.0.0-beta.10
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.d.ts +6 -0
- package/cli.js +47 -16
- package/cli.js.map +1 -1
- package/cli.mjs +47 -17
- package/cli.mjs.map +1 -1
- package/client/app-client.js +115 -49
- package/client/app-client.js.map +1 -1
- package/client/app-client.mjs +115 -49
- package/client/app-client.mjs.map +1 -1
- package/client/app-factory.js +49 -35
- package/client/app-factory.js.map +1 -1
- package/client/app-factory.mjs +49 -35
- package/client/app-factory.mjs.map +1 -1
- package/client/app-types.js +98 -102
- package/client/app-types.js.map +1 -1
- package/client/app-types.mjs +100 -104
- package/client/app-types.mjs.map +1 -1
- package/client/call-composer-types.js +9 -9
- package/client/call-composer-types.js.map +1 -1
- package/client/call-composer-types.mjs +9 -9
- package/client/call-composer-types.mjs.map +1 -1
- package/client/call-composer.js +25 -23
- package/client/call-composer.js.map +1 -1
- package/client/call-composer.mjs +25 -23
- package/client/call-composer.mjs.map +1 -1
- package/client/deploy-types.js +9 -9
- package/client/deploy-types.js.map +1 -1
- package/client/deploy-types.mjs +9 -9
- package/client/deploy-types.mjs.map +1 -1
- package/client/generate.js +6 -7
- package/client/generate.js.map +1 -1
- package/client/generate.mjs +6 -7
- package/client/generate.mjs.map +1 -1
- package/client/helpers/get-equivalent-type.js +9 -3
- package/client/helpers/get-equivalent-type.js.map +1 -1
- package/client/helpers/get-equivalent-type.mjs +9 -3
- package/client/helpers/get-equivalent-type.mjs.map +1 -1
- package/client/imports.js +8 -5
- package/client/imports.js.map +1 -1
- package/client/imports.mjs +8 -5
- package/client/imports.mjs.map +1 -1
- package/client/params-factory.js +12 -12
- package/client/params-factory.js.map +1 -1
- package/client/params-factory.mjs +12 -12
- package/client/params-factory.mjs.map +1 -1
- package/output/writer.d.ts +5 -5
- package/output/writer.js +9 -3
- package/output/writer.js.map +1 -1
- package/output/writer.mjs +9 -3
- package/output/writer.mjs.map +1 -1
- package/package.json +9 -5
- package/schema/arc56.schema.json.js +465 -501
- package/schema/arc56.schema.json.js.map +1 -1
- package/schema/arc56.schema.json.mjs +462 -501
- package/schema/arc56.schema.json.mjs.map +1 -1
- package/schema/load.js +7 -1
- package/schema/load.js.map +1 -1
- package/schema/load.mjs +7 -1
- package/schema/load.mjs.map +1 -1
- package/util/sanitization.js +13 -8
- package/util/sanitization.js.map +1 -1
- package/util/sanitization.mjs +13 -8
- package/util/sanitization.mjs.map +1 -1
package/cli.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export declare function cli(workingDirectory: string, args: string[]): void;
|
|
2
|
+
export declare function generateClientCommand({ application, output, preserveNames, workingDirectory, }: {
|
|
3
|
+
application: string;
|
|
4
|
+
output: string;
|
|
5
|
+
preserveNames: boolean;
|
|
6
|
+
workingDirectory: string;
|
|
7
|
+
}): Promise<void>;
|
package/cli.js
CHANGED
|
@@ -35,23 +35,12 @@ function cli(workingDirectory, args) {
|
|
|
35
35
|
.requiredOption('-o --output <path>', 'Specifies the output file path')
|
|
36
36
|
.option('-pn --preserve-names', 'Preserve names from application.json spec instead of sanitizing them')
|
|
37
37
|
.action(async ({ application, output, preserveNames }) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const spec = await load.loadApplicationJson(resolvedAppJsonPath);
|
|
44
|
-
colorConsole.colorConsole.info `Generating TS client for ${spec.name}`;
|
|
45
|
-
const parts = generate.generate(spec, { preserveNames: Boolean(preserveNames) });
|
|
46
|
-
if (!fs.existsSync(resolvedOutDir)) {
|
|
47
|
-
colorConsole.colorConsole.warn `Output directory ${resolvedOutDir} does not exist and will be created.`;
|
|
48
|
-
fs.mkdirSync(resolvedOutDir, { recursive: true });
|
|
49
|
-
}
|
|
50
|
-
colorConsole.colorConsole.info `Writing TS client to ${resolvedOutPath}`;
|
|
51
|
-
const file = fs.createWriteStream(resolvedOutPath, {
|
|
52
|
-
flags: 'w',
|
|
38
|
+
await generateClientCommand({
|
|
39
|
+
application,
|
|
40
|
+
output,
|
|
41
|
+
preserveNames: Boolean(preserveNames),
|
|
42
|
+
workingDirectory,
|
|
53
43
|
});
|
|
54
|
-
writer.writeDocumentPartsToStream(parts, file);
|
|
55
44
|
colorConsole.colorConsole.success `Operation completed successfully`;
|
|
56
45
|
})
|
|
57
46
|
.configureOutput({
|
|
@@ -72,6 +61,48 @@ function cli(workingDirectory, args) {
|
|
|
72
61
|
process.exit(-1);
|
|
73
62
|
}
|
|
74
63
|
}
|
|
64
|
+
async function generateClientCommand({ application, output, preserveNames, workingDirectory, }) {
|
|
65
|
+
const fs = await import('fs');
|
|
66
|
+
const resolvedAppJsonPath = path__namespace.resolve(workingDirectory, application);
|
|
67
|
+
const resolvedOutPath = path__namespace.resolve(workingDirectory, output);
|
|
68
|
+
const resolvedOutDir = path__namespace.dirname(resolvedOutPath);
|
|
69
|
+
colorConsole.colorConsole.info `Reading application.json file from path ${resolvedAppJsonPath}`;
|
|
70
|
+
const spec = await load.loadApplicationJson(resolvedAppJsonPath);
|
|
71
|
+
colorConsole.colorConsole.info `Generating TS client for ${spec.name}`;
|
|
72
|
+
const parts = generate.generate(spec, { preserveNames });
|
|
73
|
+
if (!fs.existsSync(resolvedOutDir)) {
|
|
74
|
+
colorConsole.colorConsole.warn `Output directory ${resolvedOutDir} does not exist and will be created.`;
|
|
75
|
+
fs.mkdirSync(resolvedOutDir, { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
colorConsole.colorConsole.info `Writing TS client to ${resolvedOutPath}`;
|
|
78
|
+
const file = await createAwaitableWriteStream(resolvedOutPath);
|
|
79
|
+
writer.writeDocumentPartsToStream(parts, file);
|
|
80
|
+
await file.finish();
|
|
81
|
+
}
|
|
82
|
+
async function createAwaitableWriteStream(path) {
|
|
83
|
+
const fs = await import('fs');
|
|
84
|
+
const stream = fs.createWriteStream(path, {
|
|
85
|
+
flags: 'w',
|
|
86
|
+
});
|
|
87
|
+
const finish = new Promise((resolve, reject) => {
|
|
88
|
+
stream.on('error', (err) => {
|
|
89
|
+
reject(err);
|
|
90
|
+
});
|
|
91
|
+
stream.on('finish', () => {
|
|
92
|
+
resolve();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
write(chunk) {
|
|
97
|
+
stream.write(chunk);
|
|
98
|
+
},
|
|
99
|
+
finish() {
|
|
100
|
+
stream.end();
|
|
101
|
+
return finish;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
75
105
|
|
|
76
106
|
exports.cli = cli;
|
|
107
|
+
exports.generateClientCommand = generateClientCommand;
|
|
77
108
|
//# sourceMappingURL=cli.js.map
|
package/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["import { Command } from 'commander'\nimport { loadApplicationJson } from './schema/load'\nimport * as path from 'path'\nimport { generate } from './client/generate'\nimport { writeDocumentPartsToStream } from './output/writer'\nimport { colorConsole } from './util/color-console'\n\nexport function cli(workingDirectory: string, args: string[]) {\n const program = new Command()\n program\n .command('generate')\n .description('Generates a TypeScript client for the given application.json file')\n .requiredOption('-a --application <path>', 'Specifies the application.json file')\n .requiredOption('-o --output <path>', 'Specifies the output file path')\n .option('-pn --preserve-names', 'Preserve names from application.json spec instead of sanitizing them')\n .action(\n async ({ application, output, preserveNames }: { application: string; output: string; preserveNames?: boolean }): Promise<void> => {\n const fs = await import('fs')\n
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["import { Command } from 'commander'\nimport { loadApplicationJson } from './schema/load'\nimport * as path from 'path'\nimport { generate } from './client/generate'\nimport { writeDocumentPartsToStream } from './output/writer'\nimport { colorConsole } from './util/color-console'\n\nexport function cli(workingDirectory: string, args: string[]) {\n const program = new Command()\n program\n .command('generate')\n .description('Generates a TypeScript client for the given application.json file')\n .requiredOption('-a --application <path>', 'Specifies the application.json file')\n .requiredOption('-o --output <path>', 'Specifies the output file path')\n .option('-pn --preserve-names', 'Preserve names from application.json spec instead of sanitizing them')\n .action(\n async ({ application, output, preserveNames }: { application: string; output: string; preserveNames?: boolean }): Promise<void> => {\n await generateClientCommand({\n application,\n output,\n preserveNames: Boolean(preserveNames),\n workingDirectory,\n })\n colorConsole.success`Operation completed successfully`\n },\n )\n .configureOutput({\n writeErr(str: string) {\n colorConsole.error`${str}`\n },\n })\n try {\n program.parse(args)\n } catch (err) {\n if (err instanceof Error) {\n colorConsole.error`Unhandled error: \\n\\n${err.stack}`\n } else {\n colorConsole.error`Unhandled error: \\n\\n${err}`\n }\n process.exit(-1)\n }\n}\n\nexport async function generateClientCommand({\n application,\n output,\n preserveNames,\n workingDirectory,\n}: {\n application: string\n output: string\n preserveNames: boolean\n workingDirectory: string\n}) {\n const fs = await import('fs')\n\n const resolvedAppJsonPath = path.resolve(workingDirectory, application)\n const resolvedOutPath = path.resolve(workingDirectory, output)\n const resolvedOutDir = path.dirname(resolvedOutPath)\n colorConsole.info`Reading application.json file from path ${resolvedAppJsonPath}`\n const spec = await loadApplicationJson(resolvedAppJsonPath)\n colorConsole.info`Generating TS client for ${spec.name}`\n const parts = generate(spec, { preserveNames })\n if (!fs.existsSync(resolvedOutDir)) {\n colorConsole.warn`Output directory ${resolvedOutDir} does not exist and will be created.`\n fs.mkdirSync(resolvedOutDir, { recursive: true })\n }\n colorConsole.info`Writing TS client to ${resolvedOutPath}`\n const file = await createAwaitableWriteStream(resolvedOutPath)\n writeDocumentPartsToStream(parts, file)\n await file.finish()\n}\n\nasync function createAwaitableWriteStream(path: string) {\n const fs = await import('fs')\n const stream = fs.createWriteStream(path, {\n flags: 'w',\n })\n const finish = new Promise<void>((resolve, reject) => {\n stream.on('error', (err) => {\n reject(err)\n })\n stream.on('finish', () => {\n resolve()\n })\n })\n return {\n write(chunk: string): void {\n stream.write(chunk)\n },\n finish() {\n stream.end()\n return finish\n },\n }\n}\n"],"names":["Command","colorConsole","path","loadApplicationJson","generate","writeDocumentPartsToStream"],"mappings":"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"}
|
package/cli.mjs
CHANGED
|
@@ -14,23 +14,12 @@ function cli(workingDirectory, args) {
|
|
|
14
14
|
.requiredOption('-o --output <path>', 'Specifies the output file path')
|
|
15
15
|
.option('-pn --preserve-names', 'Preserve names from application.json spec instead of sanitizing them')
|
|
16
16
|
.action(async ({ application, output, preserveNames }) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const spec = await loadApplicationJson(resolvedAppJsonPath);
|
|
23
|
-
colorConsole.info `Generating TS client for ${spec.name}`;
|
|
24
|
-
const parts = generate(spec, { preserveNames: Boolean(preserveNames) });
|
|
25
|
-
if (!fs.existsSync(resolvedOutDir)) {
|
|
26
|
-
colorConsole.warn `Output directory ${resolvedOutDir} does not exist and will be created.`;
|
|
27
|
-
fs.mkdirSync(resolvedOutDir, { recursive: true });
|
|
28
|
-
}
|
|
29
|
-
colorConsole.info `Writing TS client to ${resolvedOutPath}`;
|
|
30
|
-
const file = fs.createWriteStream(resolvedOutPath, {
|
|
31
|
-
flags: 'w',
|
|
17
|
+
await generateClientCommand({
|
|
18
|
+
application,
|
|
19
|
+
output,
|
|
20
|
+
preserveNames: Boolean(preserveNames),
|
|
21
|
+
workingDirectory,
|
|
32
22
|
});
|
|
33
|
-
writeDocumentPartsToStream(parts, file);
|
|
34
23
|
colorConsole.success `Operation completed successfully`;
|
|
35
24
|
})
|
|
36
25
|
.configureOutput({
|
|
@@ -51,6 +40,47 @@ function cli(workingDirectory, args) {
|
|
|
51
40
|
process.exit(-1);
|
|
52
41
|
}
|
|
53
42
|
}
|
|
43
|
+
async function generateClientCommand({ application, output, preserveNames, workingDirectory, }) {
|
|
44
|
+
const fs = await import('fs');
|
|
45
|
+
const resolvedAppJsonPath = path.resolve(workingDirectory, application);
|
|
46
|
+
const resolvedOutPath = path.resolve(workingDirectory, output);
|
|
47
|
+
const resolvedOutDir = path.dirname(resolvedOutPath);
|
|
48
|
+
colorConsole.info `Reading application.json file from path ${resolvedAppJsonPath}`;
|
|
49
|
+
const spec = await loadApplicationJson(resolvedAppJsonPath);
|
|
50
|
+
colorConsole.info `Generating TS client for ${spec.name}`;
|
|
51
|
+
const parts = generate(spec, { preserveNames });
|
|
52
|
+
if (!fs.existsSync(resolvedOutDir)) {
|
|
53
|
+
colorConsole.warn `Output directory ${resolvedOutDir} does not exist and will be created.`;
|
|
54
|
+
fs.mkdirSync(resolvedOutDir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
colorConsole.info `Writing TS client to ${resolvedOutPath}`;
|
|
57
|
+
const file = await createAwaitableWriteStream(resolvedOutPath);
|
|
58
|
+
writeDocumentPartsToStream(parts, file);
|
|
59
|
+
await file.finish();
|
|
60
|
+
}
|
|
61
|
+
async function createAwaitableWriteStream(path) {
|
|
62
|
+
const fs = await import('fs');
|
|
63
|
+
const stream = fs.createWriteStream(path, {
|
|
64
|
+
flags: 'w',
|
|
65
|
+
});
|
|
66
|
+
const finish = new Promise((resolve, reject) => {
|
|
67
|
+
stream.on('error', (err) => {
|
|
68
|
+
reject(err);
|
|
69
|
+
});
|
|
70
|
+
stream.on('finish', () => {
|
|
71
|
+
resolve();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
write(chunk) {
|
|
76
|
+
stream.write(chunk);
|
|
77
|
+
},
|
|
78
|
+
finish() {
|
|
79
|
+
stream.end();
|
|
80
|
+
return finish;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
54
84
|
|
|
55
|
-
export { cli };
|
|
85
|
+
export { cli, generateClientCommand };
|
|
56
86
|
//# sourceMappingURL=cli.mjs.map
|
package/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","sources":["../src/cli.ts"],"sourcesContent":["import { Command } from 'commander'\nimport { loadApplicationJson } from './schema/load'\nimport * as path from 'path'\nimport { generate } from './client/generate'\nimport { writeDocumentPartsToStream } from './output/writer'\nimport { colorConsole } from './util/color-console'\n\nexport function cli(workingDirectory: string, args: string[]) {\n const program = new Command()\n program\n .command('generate')\n .description('Generates a TypeScript client for the given application.json file')\n .requiredOption('-a --application <path>', 'Specifies the application.json file')\n .requiredOption('-o --output <path>', 'Specifies the output file path')\n .option('-pn --preserve-names', 'Preserve names from application.json spec instead of sanitizing them')\n .action(\n async ({ application, output, preserveNames }: { application: string; output: string; preserveNames?: boolean }): Promise<void> => {\n const fs = await import('fs')\n
|
|
1
|
+
{"version":3,"file":"cli.mjs","sources":["../src/cli.ts"],"sourcesContent":["import { Command } from 'commander'\nimport { loadApplicationJson } from './schema/load'\nimport * as path from 'path'\nimport { generate } from './client/generate'\nimport { writeDocumentPartsToStream } from './output/writer'\nimport { colorConsole } from './util/color-console'\n\nexport function cli(workingDirectory: string, args: string[]) {\n const program = new Command()\n program\n .command('generate')\n .description('Generates a TypeScript client for the given application.json file')\n .requiredOption('-a --application <path>', 'Specifies the application.json file')\n .requiredOption('-o --output <path>', 'Specifies the output file path')\n .option('-pn --preserve-names', 'Preserve names from application.json spec instead of sanitizing them')\n .action(\n async ({ application, output, preserveNames }: { application: string; output: string; preserveNames?: boolean }): Promise<void> => {\n await generateClientCommand({\n application,\n output,\n preserveNames: Boolean(preserveNames),\n workingDirectory,\n })\n colorConsole.success`Operation completed successfully`\n },\n )\n .configureOutput({\n writeErr(str: string) {\n colorConsole.error`${str}`\n },\n })\n try {\n program.parse(args)\n } catch (err) {\n if (err instanceof Error) {\n colorConsole.error`Unhandled error: \\n\\n${err.stack}`\n } else {\n colorConsole.error`Unhandled error: \\n\\n${err}`\n }\n process.exit(-1)\n }\n}\n\nexport async function generateClientCommand({\n application,\n output,\n preserveNames,\n workingDirectory,\n}: {\n application: string\n output: string\n preserveNames: boolean\n workingDirectory: string\n}) {\n const fs = await import('fs')\n\n const resolvedAppJsonPath = path.resolve(workingDirectory, application)\n const resolvedOutPath = path.resolve(workingDirectory, output)\n const resolvedOutDir = path.dirname(resolvedOutPath)\n colorConsole.info`Reading application.json file from path ${resolvedAppJsonPath}`\n const spec = await loadApplicationJson(resolvedAppJsonPath)\n colorConsole.info`Generating TS client for ${spec.name}`\n const parts = generate(spec, { preserveNames })\n if (!fs.existsSync(resolvedOutDir)) {\n colorConsole.warn`Output directory ${resolvedOutDir} does not exist and will be created.`\n fs.mkdirSync(resolvedOutDir, { recursive: true })\n }\n colorConsole.info`Writing TS client to ${resolvedOutPath}`\n const file = await createAwaitableWriteStream(resolvedOutPath)\n writeDocumentPartsToStream(parts, file)\n await file.finish()\n}\n\nasync function createAwaitableWriteStream(path: string) {\n const fs = await import('fs')\n const stream = fs.createWriteStream(path, {\n flags: 'w',\n })\n const finish = new Promise<void>((resolve, reject) => {\n stream.on('error', (err) => {\n reject(err)\n })\n stream.on('finish', () => {\n resolve()\n })\n })\n return {\n write(chunk: string): void {\n stream.write(chunk)\n },\n finish() {\n stream.end()\n return finish\n },\n }\n}\n"],"names":[],"mappings":"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"}
|
package/client/app-client.js
CHANGED
|
@@ -27,8 +27,8 @@ function* appClient(ctx) {
|
|
|
27
27
|
*
|
|
28
28
|
* @param params The parameters to initialise the app client with
|
|
29
29
|
*/
|
|
30
|
-
constructor(params:
|
|
31
|
-
constructor(appClientOrParams: AppClient |
|
|
30
|
+
constructor(params: Omit<AppClientParams, 'appSpec'>)
|
|
31
|
+
constructor(appClientOrParams: AppClient | Omit<AppClientParams, 'appSpec'>) {
|
|
32
32
|
this.appClient = appClientOrParams instanceof AppClient ? appClientOrParams : new AppClient({
|
|
33
33
|
...appClientOrParams,
|
|
34
34
|
appSpec: APP_SPEC,
|
|
@@ -48,7 +48,7 @@ function* appClient(ctx) {
|
|
|
48
48
|
* using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
|
|
49
49
|
* @param params The parameters to create the app client
|
|
50
50
|
*/
|
|
51
|
-
public static async fromCreatorAndName(params:
|
|
51
|
+
public static async fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<${name}Client> {
|
|
52
52
|
return new ${name}Client(await AppClient.fromCreatorAndName({...params, appSpec: APP_SPEC}))
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -60,62 +60,77 @@ function* appClient(ctx) {
|
|
|
60
60
|
* @param params The parameters to create the app client
|
|
61
61
|
*/
|
|
62
62
|
static async fromNetwork(
|
|
63
|
-
params:
|
|
63
|
+
params: Omit<ResolveAppClientByNetwork, 'appSpec'>
|
|
64
64
|
): Promise<${name}Client> {
|
|
65
65
|
return new ${name}Client(await AppClient.fromNetwork({...params, appSpec: APP_SPEC}))
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/** The ID of the app instance this client is linked to. */
|
|
69
|
+
public get appId() {
|
|
70
|
+
return this.appClient.appId
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The app address of the app instance this client is linked to. */
|
|
74
|
+
public get appAddress() {
|
|
75
|
+
return this.appClient.appAddress
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The name of the app. */
|
|
79
|
+
public get appName() {
|
|
80
|
+
return this.appClient.appName
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The ARC-56 app spec being used */
|
|
84
|
+
public get appSpec() {
|
|
85
|
+
return this.appClient.appSpec
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A reference to the underlying \`AlgorandClient\` this app client is using. */
|
|
89
|
+
public get algorand(): AlgorandClientInterface {
|
|
90
|
+
return this.appClient.algorand
|
|
91
|
+
}
|
|
92
|
+
|
|
68
93
|
`;
|
|
69
94
|
yield* params(ctx);
|
|
70
|
-
yield*
|
|
95
|
+
yield* createTransaction(ctx);
|
|
71
96
|
yield* send(ctx);
|
|
97
|
+
yield* cloneMethod(ctx);
|
|
98
|
+
yield* readonlyMethods(ctx);
|
|
72
99
|
yield* getStateMethods(ctx);
|
|
73
100
|
yield* callComposer.composeMethod(ctx);
|
|
74
101
|
yield writer.DecIndentAndCloseBlock;
|
|
75
102
|
}
|
|
76
103
|
function* params(ctx) {
|
|
77
|
-
yield* writer.jsDoc(`Get parameters to
|
|
78
|
-
yield `readonly params =
|
|
79
|
-
yield writer.IncIndent;
|
|
80
|
-
yield `return {`;
|
|
104
|
+
yield* writer.jsDoc(`Get parameters to create transactions for the current app. A good mental model for this is that these parameters represent a deferred transaction creation.`);
|
|
105
|
+
yield `readonly params = {`;
|
|
81
106
|
yield writer.IncIndent;
|
|
82
107
|
yield* opMethods(ctx, 'params');
|
|
83
108
|
yield* clearState(ctx, 'params');
|
|
84
109
|
yield* call(ctx, 'params');
|
|
85
110
|
yield* noopMethods(ctx, 'params');
|
|
86
111
|
yield writer.DecIndentAndCloseBlock;
|
|
87
|
-
yield writer.DecIndent;
|
|
88
|
-
yield `})(this)`;
|
|
89
112
|
yield writer.NewLine;
|
|
90
113
|
}
|
|
91
|
-
function*
|
|
92
|
-
yield* writer.jsDoc(`
|
|
93
|
-
yield `readonly
|
|
114
|
+
function* createTransaction(ctx) {
|
|
115
|
+
yield* writer.jsDoc(`Create transactions for the current app`);
|
|
116
|
+
yield `readonly createTransaction = {`;
|
|
94
117
|
yield writer.IncIndent;
|
|
95
|
-
yield
|
|
96
|
-
yield
|
|
97
|
-
yield*
|
|
98
|
-
yield*
|
|
99
|
-
yield* call(ctx, 'transactions');
|
|
100
|
-
yield* noopMethods(ctx, 'transactions');
|
|
118
|
+
yield* opMethods(ctx, 'createTransaction');
|
|
119
|
+
yield* clearState(ctx, 'createTransaction');
|
|
120
|
+
yield* call(ctx, 'createTransaction');
|
|
121
|
+
yield* noopMethods(ctx, 'createTransaction');
|
|
101
122
|
yield writer.DecIndentAndCloseBlock;
|
|
102
|
-
yield writer.DecIndent;
|
|
103
|
-
yield `})(this)`;
|
|
104
123
|
yield writer.NewLine;
|
|
105
124
|
}
|
|
106
125
|
function* send(ctx) {
|
|
107
126
|
yield* writer.jsDoc(`Send calls to the current app`);
|
|
108
|
-
yield `readonly send =
|
|
109
|
-
yield writer.IncIndent;
|
|
110
|
-
yield `return {`;
|
|
127
|
+
yield `readonly send = {`;
|
|
111
128
|
yield writer.IncIndent;
|
|
112
129
|
yield* opMethods(ctx, 'send');
|
|
113
130
|
yield* clearState(ctx, 'send');
|
|
114
131
|
yield* call(ctx, 'send');
|
|
115
132
|
yield* noopMethods(ctx, 'send');
|
|
116
133
|
yield writer.DecIndentAndCloseBlock;
|
|
117
|
-
yield writer.DecIndent;
|
|
118
|
-
yield `})(this)`;
|
|
119
134
|
yield writer.NewLine;
|
|
120
135
|
}
|
|
121
136
|
function* opMethods(ctx, type) {
|
|
@@ -130,44 +145,55 @@ function* bareMethodCall({ generator: { app }, name, description, verb, type, in
|
|
|
130
145
|
yield* writer.jsDoc({
|
|
131
146
|
description: `${description}.`,
|
|
132
147
|
params: {
|
|
133
|
-
params: `The params for the bare (
|
|
148
|
+
params: `The params for the bare (raw) call`,
|
|
134
149
|
},
|
|
135
150
|
returns: `The ${verb} result`,
|
|
136
151
|
});
|
|
137
|
-
yield `${name}(params?: Expand<AppClientBareCallParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${verb === 'create' ? ' & CreateSchema' : ''}${type === 'send' ? ' &
|
|
138
|
-
yield* writer.indent(`return
|
|
152
|
+
yield `${name}: (params?: Expand<AppClientBareCallParams${includeCompilation ? ' & AppClientCompilationParams' : ''}${verb === 'create' ? ' & CreateSchema' : ''}${type === 'send' ? ' & SendParams' : ''}${onComplete?.type ? ` & ${onComplete.type}` : ''}>) => {`;
|
|
153
|
+
yield* writer.indent(`return this.appClient.${type}.bare.${verb}(params)`);
|
|
139
154
|
yield '},';
|
|
140
155
|
}
|
|
141
|
-
function* abiMethodCall({ generator: { app, methodSignatureToUniqueName, name, sanitizer }, method, description, verb, type, includeCompilation, }) {
|
|
156
|
+
function* abiMethodCall({ generator: { app, methodSignatureToUniqueName, name, sanitizer }, method, description, verb, type, includeCompilation, readonly, }) {
|
|
142
157
|
const methodSig = new algosdk.ABIMethod(method).getSignature();
|
|
143
158
|
const uniqueName = methodSignatureToUniqueName[methodSig];
|
|
144
|
-
const onComplete = verb === 'create'
|
|
159
|
+
const onComplete = verb === 'create'
|
|
160
|
+
? deployTypes.getCreateOnCompleteOptions(methodSig, app)
|
|
161
|
+
: verb === 'call' && !readonly
|
|
162
|
+
? deployTypes.getCallOnCompleteOptions(methodSig, app)
|
|
163
|
+
: undefined;
|
|
145
164
|
yield* writer.jsDoc({
|
|
146
|
-
description:
|
|
165
|
+
description: verb === 'call' && method.readonly
|
|
166
|
+
? [
|
|
167
|
+
`${description} using the \`${methodSig}\` ABI method.`,
|
|
168
|
+
'',
|
|
169
|
+
'This method is a readonly method; calling it with onComplete of NoOp will result in a simulated transaction rather than a real transaction.',
|
|
170
|
+
]
|
|
171
|
+
: `${description} using the \`${methodSig}\` ABI method.`,
|
|
147
172
|
abiDescription: method?.desc,
|
|
148
173
|
params: {
|
|
149
174
|
params: `The params for the smart contract call`,
|
|
150
175
|
},
|
|
151
|
-
returns: `The ${verb} ${type === 'params' ? 'params' : type === '
|
|
176
|
+
returns: `The ${verb} ${type === 'params' ? 'params' : type === 'createTransaction' ? 'transaction' : 'result'}${method?.returns?.desc ? `: ${method.returns.desc}` : ''}`,
|
|
152
177
|
});
|
|
153
178
|
const methodName = sanitizer.makeSafeMethodIdentifier(uniqueName);
|
|
154
179
|
const methodNameAccessor = sanitizer.getSafeMemberAccessor(methodName);
|
|
155
180
|
const methodSigSafe = sanitizer.makeSafeStringTypeLiteral(methodSig);
|
|
156
|
-
yield `${type === 'send' ? 'async ' : ''}${methodName}(params:
|
|
181
|
+
yield `${!readonly ? `${methodName}: ` : ''}${type === 'send' ? 'async ' : ''}${readonly ? `${methodName}` : ''}(params: CallParams<${name}Args['obj']['${methodSigSafe}'] | ${name}Args['tuple']['${methodSigSafe}']>${includeCompilation ? ' &' + ' AppClientCompilationParams' : ''}${verb === 'create' ? ' & CreateSchema' : ''}${type === 'send' && !readonly ? ' & SendParams' : ''}${onComplete?.type && !readonly ? ` & ${onComplete.type}` : ''}${onComplete?.isOptional !== false && (method.args.length === 0 || !method.args.some((a) => !a.defaultValue)) ? ` = {args: [${method.args.map((_) => 'undefined').join(', ')}]}` : ''})${!readonly ? ' =>' : ''} {`;
|
|
157
182
|
if (type === 'send') {
|
|
158
|
-
yield* writer.indent(`const result = await
|
|
183
|
+
yield* writer.indent(`const result = await this.appClient.${type}.${verb}(${name}ParamsFactory${verb !== 'call' ? `.${verb}` : ''}${methodNameAccessor}(params))`, readonly
|
|
184
|
+
? `return result.return as ${name}Returns['${methodSigSafe}']`
|
|
185
|
+
: `return {...result, return: result.return as undefined | ${name}Returns['${methodSigSafe}']}`);
|
|
159
186
|
}
|
|
160
187
|
else {
|
|
161
|
-
yield* writer.indent(`return
|
|
188
|
+
yield* writer.indent(`return this.appClient.${type}.${verb}(${name}ParamsFactory${verb !== 'call' ? `.${verb}` : ''}${methodNameAccessor}(params))`);
|
|
162
189
|
}
|
|
163
|
-
yield '
|
|
190
|
+
yield `}${!readonly ? ',' : ''}`;
|
|
191
|
+
yield writer.NewLine;
|
|
164
192
|
}
|
|
165
193
|
function* operationMethods(generator, description, methods, verb, type, includeCompilation) {
|
|
166
194
|
if (methods.length) {
|
|
167
195
|
yield* writer.jsDoc(`Gets available ${verb} methods`);
|
|
168
|
-
yield
|
|
169
|
-
yield writer.IncIndent;
|
|
170
|
-
yield `return {`;
|
|
196
|
+
yield `${verb}: {`;
|
|
171
197
|
yield writer.IncIndent;
|
|
172
198
|
for (const methodSig of methods) {
|
|
173
199
|
if (methodSig === getCallConfigSummary.BARE_CALL) {
|
|
@@ -192,7 +218,6 @@ function* operationMethods(generator, description, methods, verb, type, includeC
|
|
|
192
218
|
});
|
|
193
219
|
}
|
|
194
220
|
}
|
|
195
|
-
yield writer.DecIndentAndCloseBlock;
|
|
196
221
|
yield writer.DecIndent;
|
|
197
222
|
yield '},';
|
|
198
223
|
yield writer.NewLine;
|
|
@@ -220,6 +245,24 @@ function* call(generator, type) {
|
|
|
220
245
|
yield writer.NewLine;
|
|
221
246
|
}
|
|
222
247
|
}
|
|
248
|
+
function* readonlyMethods(generator) {
|
|
249
|
+
const { app, callConfig } = generator;
|
|
250
|
+
for (const method of app.methods) {
|
|
251
|
+
const methodSignature = new algosdk.ABIMethod(method).getSignature();
|
|
252
|
+
// Skip non readonly methods
|
|
253
|
+
if (!callConfig.callMethods.includes(methodSignature) || !method.readonly)
|
|
254
|
+
continue;
|
|
255
|
+
yield* abiMethodCall({
|
|
256
|
+
generator,
|
|
257
|
+
description: `Makes a readonly (simulated) call to the ${generator.app.name} smart contract`,
|
|
258
|
+
method,
|
|
259
|
+
verb: 'call',
|
|
260
|
+
type: 'send',
|
|
261
|
+
includeCompilation: false,
|
|
262
|
+
readonly: true,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
223
266
|
function* noopMethods(generator, type) {
|
|
224
267
|
const { app, callConfig } = generator;
|
|
225
268
|
for (const method of app.methods) {
|
|
@@ -250,19 +293,24 @@ function* getStateMethods({ app, sanitizer }) {
|
|
|
250
293
|
if (!hasKeys && !hasMaps)
|
|
251
294
|
continue;
|
|
252
295
|
yield* writer.jsDoc(`Methods to access ${storageType} state for the current ${app.name} app`);
|
|
253
|
-
yield `${storageType}${storageType === 'local' ? ': (address: string) =>
|
|
296
|
+
yield `${storageType}${storageType === 'local' ? ': (address: string | Address) => {' : ': {'}`;
|
|
254
297
|
yield writer.IncIndent;
|
|
298
|
+
if (storageType === 'local') {
|
|
299
|
+
yield "const encodedAddress = typeof address === 'string' ? address : encodeAddress(address.publicKey)";
|
|
300
|
+
yield 'return {';
|
|
301
|
+
yield writer.IncIndent;
|
|
302
|
+
}
|
|
255
303
|
yield* writer.jsDoc(`Get all current keyed values from ${storageType} state`);
|
|
256
304
|
yield `getAll: async (): Promise<Partial<Expand<${storageType[0].toUpperCase()}${storageType.substring(1)}KeysState>>> => {`;
|
|
257
|
-
yield* writer.indent(`const result = await this.appClient.state.${storageType}${storageType === 'local' ? '(
|
|
258
|
-
return ` ${sanitizer.makeSafePropertyIdentifier(n)}: ${app.state.keys[storageType][n].valueType === '
|
|
305
|
+
yield* writer.indent(`const result = await this.appClient.state.${storageType}${storageType === 'local' ? '(encodedAddress)' : ''}.getAll()`, `return {`, ...Object.keys(app.state.keys[storageType]).map((n) => {
|
|
306
|
+
return ` ${sanitizer.makeSafePropertyIdentifier(n)}: ${app.state.keys[storageType][n].valueType === 'AVMBytes' ? `new BinaryStateValue(result${sanitizer.getSafeMemberAccessor(n)})` : `result${sanitizer.getSafeMemberAccessor(n)}`},`;
|
|
259
307
|
}), `}`);
|
|
260
308
|
yield `},`;
|
|
261
309
|
for (const n of Object.keys(app.state.keys[storageType])) {
|
|
262
310
|
const name = sanitizer.makeSafePropertyIdentifier(n);
|
|
263
311
|
const k = app.state.keys[storageType][n];
|
|
264
312
|
yield* writer.jsDoc(`Get the current value of the ${n} key in ${storageType} state`);
|
|
265
|
-
yield `${name}: async (): Promise<${k.valueType === '
|
|
313
|
+
yield `${name}: async (): Promise<${k.valueType === 'AVMBytes' ? 'BinaryState' : `${getEquivalentType.getEquivalentType(k.valueType, 'output', { app, sanitizer })} | undefined`}> => { return ${k.valueType === 'AVMBytes' ? 'new BinaryStateValue(' : ''}(await this.appClient.state.${storageType}${storageType === 'local' ? '(encodedAddress)' : ''}.getValue("${name}"))${k.valueType === 'AVMBytes' ? ' as Uint8Array | undefined)' : ` as ${getEquivalentType.getEquivalentType(k.valueType, 'output', { app, sanitizer })} | undefined`} },`;
|
|
266
314
|
}
|
|
267
315
|
for (const n of Object.keys(app.state.maps[storageType])) {
|
|
268
316
|
const name = sanitizer.makeSafePropertyIdentifier(app.state.keys[storageType][n] ? `${n}Map` : n);
|
|
@@ -271,18 +319,36 @@ function* getStateMethods({ app, sanitizer }) {
|
|
|
271
319
|
yield `${name}: {`;
|
|
272
320
|
yield writer.IncIndent;
|
|
273
321
|
yield* writer.jsDoc(`Get all current values of the ${n} map in ${storageType} state`);
|
|
274
|
-
yield `getMap: async (): Promise<Map<${getEquivalentType.getEquivalentType(m.keyType, 'output', { app, sanitizer })}, ${getEquivalentType.getEquivalentType(m.valueType, 'output', { app, sanitizer })}>> => { return (await this.appClient.state.${storageType}${storageType === 'local' ? '(
|
|
322
|
+
yield `getMap: async (): Promise<Map<${getEquivalentType.getEquivalentType(m.keyType, 'output', { app, sanitizer })}, ${getEquivalentType.getEquivalentType(m.valueType, 'output', { app, sanitizer })}>> => { return (await this.appClient.state.${storageType}${storageType === 'local' ? '(encodedAddress)' : ''}.getMap("${sanitizer.makeSafeStringTypeLiteral(n)}")) as Map<${getEquivalentType.getEquivalentType(m.keyType, 'output', { app, sanitizer })}, ${getEquivalentType.getEquivalentType(m.valueType, 'output', { app, sanitizer })}> },`;
|
|
275
323
|
yield* writer.jsDoc(`Get a current value of the ${n} map by key from ${storageType} state`);
|
|
276
|
-
yield `value: async (key: ${getEquivalentType.getEquivalentType(m.keyType, 'input', { app, sanitizer })}): Promise<${getEquivalentType.getEquivalentType(m.valueType, 'output', { app, sanitizer })} | undefined> => { return await this.appClient.state.${storageType}${storageType === 'local' ? '(
|
|
324
|
+
yield `value: async (key: ${getEquivalentType.getEquivalentType(m.keyType, 'input', { app, sanitizer })}): Promise<${getEquivalentType.getEquivalentType(m.valueType, 'output', { app, sanitizer })} | undefined> => { return await this.appClient.state.${storageType}${storageType === 'local' ? '(encodedAddress)' : ''}.getMapValue("${sanitizer.makeSafeStringTypeLiteral(n)}", key) as ${getEquivalentType.getEquivalentType(m.valueType, 'output', { app, sanitizer })} | undefined },`;
|
|
277
325
|
yield writer.DecIndent;
|
|
278
326
|
yield `},`;
|
|
279
327
|
}
|
|
280
328
|
yield writer.DecIndent;
|
|
281
|
-
|
|
329
|
+
if (storageType === 'local') {
|
|
330
|
+
yield '}';
|
|
331
|
+
yield writer.DecIndent;
|
|
332
|
+
}
|
|
333
|
+
yield '},';
|
|
282
334
|
}
|
|
283
335
|
yield writer.DecIndentAndCloseBlock;
|
|
284
336
|
yield writer.NewLine;
|
|
285
337
|
}
|
|
338
|
+
function* cloneMethod({ name }) {
|
|
339
|
+
yield* writer.jsDoc({
|
|
340
|
+
description: 'Clone this app client with different params',
|
|
341
|
+
params: {
|
|
342
|
+
params: 'The params to use for the the cloned app client. Omit a param to keep the original value. Set a param to override the original value. Setting to undefined will clear the original value.',
|
|
343
|
+
},
|
|
344
|
+
returns: 'A new app client with the altered params',
|
|
345
|
+
});
|
|
346
|
+
yield `public clone(params: CloneAppClientParams) {`;
|
|
347
|
+
yield writer.IncIndent;
|
|
348
|
+
yield `return new ${name}Client(this.appClient.clone(params))`;
|
|
349
|
+
yield writer.DecIndentAndCloseBlock;
|
|
350
|
+
yield writer.NewLine;
|
|
351
|
+
}
|
|
286
352
|
|
|
287
353
|
exports.appClient = appClient;
|
|
288
354
|
//# sourceMappingURL=app-client.js.map
|