@cosmwasm/ts-codegen 1.7.1 → 1.8.0

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 (61) hide show
  1. package/README.md +13 -28
  2. package/builder/builder.js +11 -16
  3. package/cli.d.ts +1 -1
  4. package/commands/create-boilerplate.d.ts +1 -1
  5. package/commands/generate.d.ts +1 -1
  6. package/commands/install.d.ts +1 -1
  7. package/esm/builder/builder.js +11 -16
  8. package/esm/{generators → helpers}/create-helpers.js +1 -9
  9. package/esm/index.js +0 -6
  10. package/esm/plugins/client.js +5 -6
  11. package/esm/plugins/index.js +6 -0
  12. package/esm/plugins/message-builder.js +2 -2
  13. package/esm/plugins/message-composer.js +3 -4
  14. package/esm/plugins/plugin-base.js +23 -6
  15. package/esm/plugins/provider-bundle.js +4 -2
  16. package/esm/plugins/provider.js +2 -2
  17. package/esm/plugins/react-query.js +2 -2
  18. package/esm/plugins/recoil.js +2 -2
  19. package/esm/plugins/types.js +3 -3
  20. package/esm/utils/contracts.js +5 -0
  21. package/{generators → helpers}/create-helpers.js +2 -10
  22. package/index.d.ts +0 -6
  23. package/index.js +0 -16
  24. package/package.json +6 -5
  25. package/plugins/client.d.ts +0 -1
  26. package/plugins/client.js +6 -7
  27. package/plugins/index.d.ts +6 -0
  28. package/plugins/index.js +6 -0
  29. package/plugins/message-builder.js +2 -2
  30. package/plugins/message-composer.d.ts +0 -1
  31. package/plugins/message-composer.js +4 -5
  32. package/plugins/plugin-base.d.ts +18 -4
  33. package/plugins/plugin-base.js +23 -6
  34. package/plugins/provider-bundle.d.ts +1 -1
  35. package/plugins/provider-bundle.js +4 -2
  36. package/plugins/provider.js +2 -2
  37. package/plugins/react-query.js +2 -2
  38. package/plugins/recoil.js +2 -2
  39. package/plugins/types.js +3 -3
  40. package/utils/contracts.d.ts +2 -0
  41. package/utils/contracts.js +9 -0
  42. package/utils/schemas.d.ts +1 -1
  43. package/esm/generators/client.js +0 -67
  44. package/esm/generators/message-builder.js +0 -58
  45. package/esm/generators/message-composer.js +0 -55
  46. package/esm/generators/react-query.js +0 -76
  47. package/esm/generators/recoil.js +0 -58
  48. package/esm/generators/types.js +0 -58
  49. package/generators/client.d.ts +0 -5
  50. package/generators/client.js +0 -95
  51. package/generators/message-builder.d.ts +0 -5
  52. package/generators/message-builder.js +0 -86
  53. package/generators/message-composer.d.ts +0 -5
  54. package/generators/message-composer.js +0 -83
  55. package/generators/react-query.d.ts +0 -4
  56. package/generators/react-query.js +0 -104
  57. package/generators/recoil.d.ts +0 -4
  58. package/generators/recoil.js +0 -86
  59. package/generators/types.d.ts +0 -4
  60. package/generators/types.js +0 -86
  61. /package/{generators → helpers}/create-helpers.d.ts +0 -0
package/README.md CHANGED
@@ -355,10 +355,10 @@ git clone https://github.com/cosmology-tech/launchpad.git
355
355
  cd launchpad/contracts/whitelists/whitelist
356
356
  ```
357
357
 
358
- Run `cosmwasm-ts-codegen` to generate your code.
358
+ Run `ts-codegen` or `cosmwasm-ts-codegen` to generate your code.
359
359
 
360
360
  ```sh
361
- cosmwasm-ts-codegen generate \
361
+ ts-codegen generate \
362
362
  --plugin client \
363
363
  --schema ./schema \
364
364
  --out ./ts \
@@ -387,7 +387,7 @@ In this example, you can press space bar to select a number of plugins you wish
387
387
  Additionally, it will also show you the name of the field (in this case `plugin`) so you can specify the parameter (for example when using CI/CD) on the comand line. Here is an exampl with `--plugin` set to `client` via CLI:
388
388
 
389
389
  ```sh
390
- cosmwasm-ts-codegen generate \
390
+ ts-codegen generate \
391
391
  --plugin client
392
392
  --schema ./schema \
393
393
  --out ./ts \
@@ -397,7 +397,7 @@ cosmwasm-ts-codegen generate \
397
397
  You can specify multiple `--plugin` options using the `generate` command:
398
398
 
399
399
  ```sh
400
- cosmwasm-ts-codegen generate \
400
+ ts-codegen generate \
401
401
  --plugin client \
402
402
  --plugin recoil \
403
403
  --schema ./schema \
@@ -412,7 +412,7 @@ All options can be provided so you can bypass the prompt.
412
412
  For confirm options, you can pass `--no-<name>` to set the value to false. Here is an example without optional client, using v3 for `react-query`, without mutations:
413
413
 
414
414
  ```sh
415
- cosmwasm-ts-codegen generate \
415
+ ts-codegen generate \
416
416
  --plugin client \
417
417
  --plugin react-query \
418
418
  --schema ./schema \
@@ -426,7 +426,7 @@ cosmwasm-ts-codegen generate \
426
426
  Example with optional client, using v4, with mutations:
427
427
 
428
428
  ```sh
429
- cosmwasm-ts-codegen generate \
429
+ ts-codegen generate \
430
430
  --plugin react-query \
431
431
  --schema ./schema \
432
432
  --out ./ts \
@@ -441,7 +441,7 @@ cosmwasm-ts-codegen generate \
441
441
  If needed, you can generate only the types with the `typesOnly` option;
442
442
 
443
443
  ```sh
444
- cosmwasm-ts-codegen generate \
444
+ ts-codegen generate \
445
445
  --typesOnly \
446
446
  --schema ./schema \
447
447
  --out ./ts \
@@ -451,7 +451,7 @@ cosmwasm-ts-codegen generate \
451
451
  #### Client via CLI
452
452
 
453
453
  ```sh
454
- cosmwasm-ts-codegen generate \
454
+ ts-codegen generate \
455
455
  --plugin client
456
456
  --schema ./schema \
457
457
  --out ./ts \
@@ -464,7 +464,7 @@ cosmwasm-ts-codegen generate \
464
464
  Here is an example without optional client, using v3 for `react-query`, without mutations:
465
465
 
466
466
  ```sh
467
- cosmwasm-ts-codegen generate \
467
+ ts-codegen generate \
468
468
  --plugin client \
469
469
  --plugin react-query \
470
470
  --schema ./schema \
@@ -478,7 +478,7 @@ cosmwasm-ts-codegen generate \
478
478
  Example with optional client, using v4, with mutations:
479
479
 
480
480
  ```sh
481
- cosmwasm-ts-codegen generate \
481
+ ts-codegen generate \
482
482
  --plugin react-query \
483
483
  --schema ./schema \
484
484
  --out ./ts \
@@ -491,7 +491,7 @@ cosmwasm-ts-codegen generate \
491
491
  #### Recoil via CLI
492
492
 
493
493
  ```sh
494
- cosmwasm-ts-codegen generate \
494
+ ts-codegen generate \
495
495
  --plugin recoil \
496
496
  --schema ./schema \
497
497
  --out ./ts \
@@ -501,7 +501,7 @@ cosmwasm-ts-codegen generate \
501
501
  #### Message Composer via CLI
502
502
 
503
503
  ```sh
504
- cosmwasm-ts-codegen generate \
504
+ ts-codegen generate \
505
505
  --plugin message-composer \
506
506
  --schema ./schema \
507
507
  --out ./ts \
@@ -511,28 +511,13 @@ cosmwasm-ts-codegen generate \
511
511
  #### Message Builder via CLI
512
512
 
513
513
  ```sh
514
- cosmwasm-ts-codegen generate \
514
+ ts-codegen generate \
515
515
  --plugin message-builder \
516
516
  --schema ./schema \
517
517
  --out ./ts \
518
518
  --name MyContractName
519
519
  ```
520
520
 
521
-
522
- ### Advanced Usage
523
-
524
- for lower-level access, you can import the various plugins directly:
525
-
526
- ```ts
527
- import {
528
- generateTypes,
529
- generateClient,
530
- generateReactQuery,
531
- generateRecoil,
532
- generateMessageComposer
533
- } from '@cosmwasm/ts-codegen';
534
- ```
535
-
536
521
  ### JSON Schema
537
522
 
538
523
  We generate code from the [JSON Schema](https://json-schema.org/) exported from CosmWasm smart contracts.
@@ -46,8 +46,9 @@ const message_composer_1 = require("../plugins/message-composer");
46
46
  const client_1 = require("../plugins/client");
47
47
  const types_1 = require("../plugins/types");
48
48
  const provider_1 = require("../plugins/provider");
49
- const create_helpers_1 = require("../generators/create-helpers");
49
+ const create_helpers_1 = require("../helpers/create-helpers");
50
50
  const provider_bundle_1 = require("../plugins/provider-bundle");
51
+ const contracts_1 = require("../utils/contracts");
51
52
  const defaultOpts = {
52
53
  bundle: {
53
54
  enabled: true,
@@ -81,7 +82,7 @@ class TSBuilder {
81
82
  builderContext = new wasm_ast_types_1.BuilderContext();
82
83
  files = [];
83
84
  loadDefaultPlugins() {
84
- this.plugins.push(new types_1.TypesPlugin(this.options), new client_1.ClientPlugin(this.options), new message_composer_1.MessageComposerPlugin(this.options), new react_query_1.ReactQueryPlugin(this.options), new recoil_1.RecoilPlugin(this.options), new message_builder_1.MessageBuilderPlugin(this.options), new provider_1.ContractsContextProviderPlugin(this.options));
85
+ this.plugins.push(new types_1.TypesPlugin(this.options), new client_1.ClientPlugin(this.options), new message_composer_1.MessageComposerPlugin(this.options), new react_query_1.ReactQueryPlugin(this.options), new recoil_1.RecoilPlugin(this.options), new message_builder_1.MessageBuilderPlugin(this.options), new provider_1.ContractsContextProviderPlugin(this.options), new provider_bundle_1.ContractsProviderBundlePlugin(this.options));
85
86
  }
86
87
  constructor({ contracts, outPath, options, plugins }) {
87
88
  this.contracts = contracts;
@@ -106,28 +107,22 @@ class TSBuilder {
106
107
  schemaDir: contract.dir
107
108
  });
108
109
  //lifecycle and plugins.
109
- await this.render(contract.name, contractInfo);
110
+ await this.render('main', contract.name, contractInfo);
110
111
  }
111
112
  }
112
- async render(name, contractInfo) {
113
- for (const plugin of this.plugins) {
114
- let files = await plugin.render(name, contractInfo, this.outPath);
113
+ async render(lifecycle, name, contractInfo) {
114
+ const plugins = lifecycle
115
+ ? this.plugins.filter((p) => p.lifecycle === lifecycle)
116
+ : this.plugins;
117
+ for (const plugin of plugins) {
118
+ let files = await plugin.render(this.outPath, name, contractInfo ?? (0, contracts_1.createDefaultContractInfo)());
115
119
  if (files && files.length) {
116
120
  this.files.push(...files);
117
121
  }
118
122
  }
119
123
  }
120
124
  async after() {
121
- //create useContracts bundle file
122
- const contractsProviderBundlePlugin = new provider_bundle_1.ContractsProviderBundlePlugin(this.options);
123
- contractsProviderBundlePlugin.setBuilder(this);
124
- //contractContextProviders.ts
125
- const files = await contractsProviderBundlePlugin.render("contractContextProviders", {
126
- schemas: [],
127
- }, this.outPath);
128
- if (files && files.length) {
129
- this.files.push(...files);
130
- }
125
+ await this.render('after');
131
126
  const helpers = (0, create_helpers_1.createHelpers)({
132
127
  outPath: this.outPath,
133
128
  contracts: this.contracts,
package/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { MinimistArgs } from '@cosmology/ts-codegen-types';
1
+ import { MinimistArgs } from '@cosmwasm/ts-codegen-types';
2
2
  export declare const cli: (argv: MinimistArgs) => Promise<void>;
@@ -1,3 +1,3 @@
1
- import { MinimistArgs } from '@cosmology/ts-codegen-types';
1
+ import { MinimistArgs } from '@cosmwasm/ts-codegen-types';
2
2
  declare const _default: (argv: MinimistArgs) => Promise<never>;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import { MinimistArgs } from '@cosmology/ts-codegen-types';
1
+ import { MinimistArgs } from '@cosmwasm/ts-codegen-types';
2
2
  declare const _default: (argv: MinimistArgs) => Promise<void>;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import { MinimistArgs } from '@cosmology/ts-codegen-types';
1
+ import { MinimistArgs } from '@cosmwasm/ts-codegen-types';
2
2
  declare const _default: (argv: MinimistArgs) => Promise<void>;
3
3
  export default _default;
@@ -17,8 +17,9 @@ import { MessageComposerPlugin } from "../plugins/message-composer";
17
17
  import { ClientPlugin } from "../plugins/client";
18
18
  import { TypesPlugin } from "../plugins/types";
19
19
  import { ContractsContextProviderPlugin } from "../plugins/provider";
20
- import { createHelpers } from "../generators/create-helpers";
20
+ import { createHelpers } from "../helpers/create-helpers";
21
21
  import { ContractsProviderBundlePlugin } from "../plugins/provider-bundle";
22
+ import { createDefaultContractInfo } from "../utils/contracts";
22
23
  const defaultOpts = {
23
24
  bundle: {
24
25
  enabled: true,
@@ -52,7 +53,7 @@ export class TSBuilder {
52
53
  builderContext = new BuilderContext();
53
54
  files = [];
54
55
  loadDefaultPlugins() {
55
- this.plugins.push(new TypesPlugin(this.options), new ClientPlugin(this.options), new MessageComposerPlugin(this.options), new ReactQueryPlugin(this.options), new RecoilPlugin(this.options), new MessageBuilderPlugin(this.options), new ContractsContextProviderPlugin(this.options));
56
+ this.plugins.push(new TypesPlugin(this.options), new ClientPlugin(this.options), new MessageComposerPlugin(this.options), new ReactQueryPlugin(this.options), new RecoilPlugin(this.options), new MessageBuilderPlugin(this.options), new ContractsContextProviderPlugin(this.options), new ContractsProviderBundlePlugin(this.options));
56
57
  }
57
58
  constructor({ contracts, outPath, options, plugins }) {
58
59
  this.contracts = contracts;
@@ -77,28 +78,22 @@ export class TSBuilder {
77
78
  schemaDir: contract.dir
78
79
  });
79
80
  //lifecycle and plugins.
80
- await this.render(contract.name, contractInfo);
81
+ await this.render('main', contract.name, contractInfo);
81
82
  }
82
83
  }
83
- async render(name, contractInfo) {
84
- for (const plugin of this.plugins) {
85
- let files = await plugin.render(name, contractInfo, this.outPath);
84
+ async render(lifecycle, name, contractInfo) {
85
+ const plugins = lifecycle
86
+ ? this.plugins.filter((p) => p.lifecycle === lifecycle)
87
+ : this.plugins;
88
+ for (const plugin of plugins) {
89
+ let files = await plugin.render(this.outPath, name, contractInfo ?? createDefaultContractInfo());
86
90
  if (files && files.length) {
87
91
  this.files.push(...files);
88
92
  }
89
93
  }
90
94
  }
91
95
  async after() {
92
- //create useContracts bundle file
93
- const contractsProviderBundlePlugin = new ContractsProviderBundlePlugin(this.options);
94
- contractsProviderBundlePlugin.setBuilder(this);
95
- //contractContextProviders.ts
96
- const files = await contractsProviderBundlePlugin.render("contractContextProviders", {
97
- schemas: [],
98
- }, this.outPath);
99
- if (files && files.length) {
100
- this.files.push(...files);
101
- }
96
+ await this.render('after');
102
97
  const helpers = createHelpers({
103
98
  outPath: this.outPath,
104
99
  contracts: this.contracts,
@@ -1,16 +1,8 @@
1
1
  import { join, dirname, basename, extname } from "path";
2
2
  import { sync as mkdirp } from "mkdirp";
3
3
  import { writeContentToFile } from "../utils/files";
4
- import { readAndParsePackageJson } from "../utils/package";
5
4
  import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, } from "../helpers";
6
- const pkg = readAndParsePackageJson();
7
- const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
8
- const header = `/**
9
- * This file and any referenced files were automatically generated by ${pkg.name}@${version}
10
- * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
11
- * and run the transpile command or yarn proto command to regenerate this bundle.
12
- */
13
- \n`;
5
+ import { header } from "../utils/header";
14
6
  const write = (outPath, file, content, varname) => {
15
7
  const outFile = join(outPath, file);
16
8
  mkdirp(dirname(outFile));
package/esm/index.js CHANGED
@@ -1,10 +1,4 @@
1
1
  import { TSBuilder } from './builder';
2
- export { default as generateTypes } from './generators/types';
3
- export { default as generateClient } from './generators/client';
4
- export { default as generateMessageComposer } from './generators/message-composer';
5
- export { default as generateMessageBuilder } from './generators/message-builder';
6
- export { default as generateReactQuery } from './generators/react-query';
7
- export { default as generateRecoil } from './generators/recoil';
8
2
  export * from './utils';
9
3
  export * from './builder';
10
4
  export * from './bundler';
@@ -3,13 +3,12 @@ import * as w from "wasm-ast-types";
3
3
  import { findExecuteMsg, findAndParseTypes, findQueryMsg } from "../utils";
4
4
  import { RenderContext, getMessageProperties, } from "wasm-ast-types";
5
5
  import { BuilderPluginBase } from "./plugin-base";
6
- export const TYPE = "client";
7
6
  export class ClientPlugin extends BuilderPluginBase {
8
7
  initContext(contract, options) {
9
- return new RenderContext(contract, options, this.builder.builderContext);
8
+ return new RenderContext(contract, options, this.builder?.builderContext);
10
9
  }
11
10
  async doRender(name, context) {
12
- const { enabled } = this.option.client;
11
+ const { enabled } = this.options.client;
13
12
  if (!enabled) {
14
13
  return;
15
14
  }
@@ -39,8 +38,8 @@ export class ClientPlugin extends BuilderPluginBase {
39
38
  if (children.length > 0) {
40
39
  Client = pascal(`${name}Client`);
41
40
  Instance = pascal(`${name}Interface`);
42
- body.push(w.createExecuteInterface(context, Instance, this.option.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
43
- body.push(w.createExecuteClass(context, Client, Instance, this.option.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
41
+ body.push(w.createExecuteInterface(context, Instance, this.options.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
42
+ body.push(w.createExecuteClass(context, Client, Instance, this.options.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
44
43
  context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
45
44
  }
46
45
  }
@@ -50,7 +49,7 @@ export class ClientPlugin extends BuilderPluginBase {
50
49
  }
51
50
  return [
52
51
  {
53
- type: TYPE,
52
+ type: "client",
54
53
  localname,
55
54
  body,
56
55
  },
@@ -1 +1,7 @@
1
1
  export * from "./plugin-base";
2
+ export * from "./client";
3
+ export * from "./react-query";
4
+ export * from "./recoil";
5
+ export * from "./message-builder";
6
+ export * from "./message-composer";
7
+ export * from "./types";
@@ -5,10 +5,10 @@ import { getMessageProperties, RenderContext } from 'wasm-ast-types';
5
5
  import { BuilderPluginBase } from './plugin-base';
6
6
  export class MessageBuilderPlugin extends BuilderPluginBase {
7
7
  initContext(contract, options) {
8
- return new RenderContext(contract, options, this.builder.builderContext);
8
+ return new RenderContext(contract, options, this.builder?.builderContext);
9
9
  }
10
10
  async doRender(name, context) {
11
- const { enabled } = this.option.messageBuilder;
11
+ const { enabled } = this.options.messageBuilder;
12
12
  if (!enabled) {
13
13
  return;
14
14
  }
@@ -3,13 +3,12 @@ import * as w from "wasm-ast-types";
3
3
  import { findAndParseTypes, findExecuteMsg } from "../utils";
4
4
  import { getMessageProperties, RenderContext, } from "wasm-ast-types";
5
5
  import { BuilderPluginBase } from "./plugin-base";
6
- export const TYPE = "message-composer";
7
6
  export class MessageComposerPlugin extends BuilderPluginBase {
8
7
  initContext(contract, options) {
9
- return new RenderContext(contract, options, this.builder.builderContext);
8
+ return new RenderContext(contract, options, this.builder?.builderContext);
10
9
  }
11
10
  async doRender(name, context) {
12
- const { enabled } = this.option.messageComposer;
11
+ const { enabled } = this.options.messageComposer;
13
12
  if (!enabled) {
14
13
  return;
15
14
  }
@@ -37,7 +36,7 @@ export class MessageComposerPlugin extends BuilderPluginBase {
37
36
  }
38
37
  return [
39
38
  {
40
- type: TYPE,
39
+ type: "message-composer",
41
40
  localname,
42
41
  body,
43
42
  },
@@ -2,28 +2,39 @@ import { sync as mkdirp } from "mkdirp";
2
2
  import { join } from "path";
3
3
  import { writeFileSync } from "fs";
4
4
  import { header } from "../utils/header";
5
+ import { defaultOptions } from "wasm-ast-types";
5
6
  import generate from "@babel/generator";
6
7
  import * as t from "@babel/types";
8
+ import deepmerge from "deepmerge";
7
9
  /**
8
10
  * BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
9
11
  */
10
12
  export class BuilderPluginBase {
11
13
  builder;
12
- option;
14
+ options;
13
15
  utils;
14
- constructor(opt, builder) {
15
- this.option = opt;
16
+ /**
17
+ * prop to indicate to execute the render function in the lifecycle of main process or after
18
+ */
19
+ lifecycle;
20
+ defaultContractName;
21
+ constructor(opts, builder) {
22
+ this.options = opts;
16
23
  this.builder = builder;
24
+ this.lifecycle = "main";
17
25
  }
18
26
  setBuilder(builder) {
19
27
  this.builder = builder;
20
28
  }
21
- async render(name, contractInfo, outPath) {
22
- const { enabled } = this.option;
29
+ async render(outPath, name, contractInfo) {
30
+ if (!this.options) {
31
+ this.options = this.getDefaultOptions(this.options);
32
+ }
33
+ const { enabled } = this.options;
23
34
  if (!enabled) {
24
35
  return;
25
36
  }
26
- const context = this.initContext(contractInfo, this.option);
37
+ const context = this.initContext(contractInfo, this.options);
27
38
  const results = await this.doRender(name, context);
28
39
  if (!results || !results.length) {
29
40
  return [];
@@ -44,4 +55,10 @@ export class BuilderPluginBase {
44
55
  };
45
56
  });
46
57
  }
58
+ /**
59
+ * get default options
60
+ */
61
+ getDefaultOptions(opts) {
62
+ return deepmerge(defaultOptions, opts ?? {});
63
+ }
47
64
  }
@@ -6,6 +6,8 @@ import { GetLocalBaseNameByContractName } from "./provider";
6
6
  export class ContractsProviderBundlePlugin extends BuilderPluginBase {
7
7
  constructor(opt) {
8
8
  super(opt);
9
+ this.lifecycle = "after";
10
+ this.defaultContractName = "contractContextProviders";
9
11
  this.utils = {
10
12
  CosmWasmClient: "@cosmjs/cosmwasm-stargate",
11
13
  SigningCosmWasmClient: "@cosmjs/cosmwasm-stargate",
@@ -15,10 +17,10 @@ export class ContractsProviderBundlePlugin extends BuilderPluginBase {
15
17
  };
16
18
  }
17
19
  initContext(contract, options) {
18
- return new RenderContext(contract, options, this.builder.builderContext);
20
+ return new RenderContext(contract, options, this.builder?.builderContext);
19
21
  }
20
22
  async doRender(name, context) {
21
- if (!this.option?.useContractsHook?.enabled) {
23
+ if (!this.options?.useContractsHook?.enabled) {
22
24
  return;
23
25
  }
24
26
  const providerInfos = context.getProviderInfos();
@@ -14,10 +14,10 @@ export class ContractsContextProviderPlugin extends BuilderPluginBase {
14
14
  };
15
15
  }
16
16
  initContext(contract, options) {
17
- return new RenderContext(contract, options, this.builder.builderContext);
17
+ return new RenderContext(contract, options, this.builder?.builderContext);
18
18
  }
19
19
  async doRender(name, context) {
20
- if (!this.option?.useContractsHook?.enabled) {
20
+ if (!this.options?.useContractsHook?.enabled) {
21
21
  return;
22
22
  }
23
23
  const providerInfo = context.getProviderInfos()[name];
@@ -5,10 +5,10 @@ import { getMessageProperties, RenderContext } from 'wasm-ast-types';
5
5
  import { BuilderPluginBase } from './plugin-base';
6
6
  export class ReactQueryPlugin extends BuilderPluginBase {
7
7
  initContext(contract, options) {
8
- return new RenderContext(contract, options, this.builder.builderContext);
8
+ return new RenderContext(contract, options, this.builder?.builderContext);
9
9
  }
10
10
  async doRender(name, context) {
11
- const options = this.option.reactQuery;
11
+ const options = this.options.reactQuery;
12
12
  const { enabled } = options;
13
13
  if (!enabled) {
14
14
  return;
@@ -8,10 +8,10 @@ export class RecoilPlugin extends BuilderPluginBase {
8
8
  selectorFamily: 'recoil',
9
9
  };
10
10
  initContext(contract, options) {
11
- return new RenderContext(contract, options, this.builder.builderContext);
11
+ return new RenderContext(contract, options, this.builder?.builderContext);
12
12
  }
13
13
  async doRender(name, context) {
14
- const { enabled } = this.option.recoil;
14
+ const { enabled } = this.options.recoil;
15
15
  if (!enabled) {
16
16
  return;
17
17
  }
@@ -6,15 +6,15 @@ import { RenderContext } from 'wasm-ast-types';
6
6
  import { BuilderPluginBase } from './plugin-base';
7
7
  export class TypesPlugin extends BuilderPluginBase {
8
8
  initContext(contract, options) {
9
- return new RenderContext(contract, options, this.builder.builderContext);
9
+ return new RenderContext(contract, options, this.builder?.builderContext);
10
10
  }
11
11
  async doRender(name, context) {
12
- const { enabled } = this.option.types;
12
+ const { enabled } = this.options.types;
13
13
  if (!enabled) {
14
14
  return;
15
15
  }
16
16
  const { schemas } = context.contract;
17
- const options = this.option.types;
17
+ const options = this.options.types;
18
18
  const localname = pascal(name) + '.types.ts';
19
19
  const ExecuteMsg = findExecuteMsg(schemas);
20
20
  const typeHash = await findAndParseTypes(schemas);
@@ -0,0 +1,5 @@
1
+ export const createDefaultContractInfo = () => {
2
+ return {
3
+ schemas: [],
4
+ };
5
+ };
@@ -4,20 +4,12 @@ exports.createHelpers = void 0;
4
4
  const path_1 = require("path");
5
5
  const mkdirp_1 = require("mkdirp");
6
6
  const files_1 = require("../utils/files");
7
- const package_1 = require("../utils/package");
8
7
  const helpers_1 = require("../helpers");
9
- const pkg = (0, package_1.readAndParsePackageJson)();
10
- const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
11
- const header = `/**
12
- * This file and any referenced files were automatically generated by ${pkg.name}@${version}
13
- * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
14
- * and run the transpile command or yarn proto command to regenerate this bundle.
15
- */
16
- \n`;
8
+ const header_1 = require("../utils/header");
17
9
  const write = (outPath, file, content, varname) => {
18
10
  const outFile = (0, path_1.join)(outPath, file);
19
11
  (0, mkdirp_1.sync)((0, path_1.dirname)(outFile));
20
- (0, files_1.writeContentToFile)(outPath, header + content, outFile);
12
+ (0, files_1.writeContentToFile)(outPath, header_1.header + content, outFile);
21
13
  return {
22
14
  type: "plugin",
23
15
  pluginType: "helper",
package/index.d.ts CHANGED
@@ -1,10 +1,4 @@
1
1
  import { TSBuilderInput } from './builder';
2
- export { default as generateTypes } from './generators/types';
3
- export { default as generateClient } from './generators/client';
4
- export { default as generateMessageComposer } from './generators/message-composer';
5
- export { default as generateMessageBuilder } from './generators/message-builder';
6
- export { default as generateReactQuery } from './generators/react-query';
7
- export { default as generateRecoil } from './generators/recoil';
8
2
  export * from './utils';
9
3
  export * from './builder';
10
4
  export * from './bundler';
package/index.js CHANGED
@@ -13,24 +13,8 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.generateRecoil = exports.generateReactQuery = exports.generateMessageBuilder = exports.generateMessageComposer = exports.generateClient = exports.generateTypes = void 0;
21
17
  const builder_1 = require("./builder");
22
- var types_1 = require("./generators/types");
23
- Object.defineProperty(exports, "generateTypes", { enumerable: true, get: function () { return __importDefault(types_1).default; } });
24
- var client_1 = require("./generators/client");
25
- Object.defineProperty(exports, "generateClient", { enumerable: true, get: function () { return __importDefault(client_1).default; } });
26
- var message_composer_1 = require("./generators/message-composer");
27
- Object.defineProperty(exports, "generateMessageComposer", { enumerable: true, get: function () { return __importDefault(message_composer_1).default; } });
28
- var message_builder_1 = require("./generators/message-builder");
29
- Object.defineProperty(exports, "generateMessageBuilder", { enumerable: true, get: function () { return __importDefault(message_builder_1).default; } });
30
- var react_query_1 = require("./generators/react-query");
31
- Object.defineProperty(exports, "generateReactQuery", { enumerable: true, get: function () { return __importDefault(react_query_1).default; } });
32
- var recoil_1 = require("./generators/recoil");
33
- Object.defineProperty(exports, "generateRecoil", { enumerable: true, get: function () { return __importDefault(recoil_1).default; } });
34
18
  __exportStar(require("./utils"), exports);
35
19
  __exportStar(require("./builder"), exports);
36
20
  __exportStar(require("./bundler"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmwasm/ts-codegen",
@@ -13,7 +13,8 @@
13
13
  "directory": "dist"
14
14
  },
15
15
  "bin": {
16
- "cosmwasm-ts-codegen": "ts-codegen.js"
16
+ "cosmwasm-ts-codegen": "ts-codegen.js",
17
+ "ts-codegen": "ts-codegen.js"
17
18
  },
18
19
  "scripts": {
19
20
  "copy": "copyfiles -f LICENSE-Apache LICENSE-MIT README.md package.json dist",
@@ -41,7 +42,7 @@
41
42
  "@babel/generator": "7.24.4",
42
43
  "@babel/traverse": "7.24.1",
43
44
  "@babel/types": "7.24.0",
44
- "@cosmology/ts-codegen-types": "^1.1.0",
45
+ "@cosmwasm/ts-codegen-types": "^1.2.0",
45
46
  "@pyramation/json-schema-to-typescript": " 11.0.4",
46
47
  "@types/rimraf": "3.0.2",
47
48
  "@types/shelljs": "0.8.15",
@@ -57,7 +58,7 @@
57
58
  "parse-package-name": "1.0.0",
58
59
  "rimraf": "3.0.2",
59
60
  "shelljs": "0.8.5",
60
- "wasm-ast-types": "^1.4.0"
61
+ "wasm-ast-types": "^1.5.0"
61
62
  },
62
63
  "keywords": [
63
64
  "cosmwasm",
@@ -65,5 +66,5 @@
65
66
  "smart contracts",
66
67
  "codegen"
67
68
  ],
68
- "gitHead": "2c659f60a394582089a11bd4f3711f623c64a908"
69
+ "gitHead": "d63f67e0ee4e6494545751a2579e4d17a755bb66"
69
70
  }
@@ -1,7 +1,6 @@
1
1
  import { RenderContext, ContractInfo, RenderContextBase, RenderOptions } from "wasm-ast-types";
2
2
  import { BuilderFileType } from "../builder";
3
3
  import { BuilderPluginBase } from "./plugin-base";
4
- export declare const TYPE = "client";
5
4
  export declare class ClientPlugin extends BuilderPluginBase<RenderOptions> {
6
5
  initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
7
6
  doRender(name: string, context: RenderContext): Promise<{