wasm-ast-types 0.26.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. package/LICENSE-Apache +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +1 -1
  4. package/{types/client → client}/client.d.ts +2 -2
  5. package/client/client.js +275 -0
  6. package/client/index.js +17 -0
  7. package/{types/context → context}/context.d.ts +9 -22
  8. package/context/context.js +114 -0
  9. package/{types/context → context}/imports.d.ts +9 -8
  10. package/context/imports.js +166 -0
  11. package/context/index.js +18 -0
  12. package/esm/client/client.js +238 -0
  13. package/esm/client/index.js +1 -0
  14. package/esm/context/context.js +104 -0
  15. package/esm/context/imports.js +136 -0
  16. package/{module → esm}/context/index.js +1 -1
  17. package/{src/index.ts → esm/index.js} +0 -1
  18. package/esm/message-builder/message-builder.js +64 -0
  19. package/esm/message-composer/message-composer.js +105 -0
  20. package/esm/provider/provider.js +97 -0
  21. package/esm/react-query/react-query.js +458 -0
  22. package/esm/recoil/recoil.js +110 -0
  23. package/esm/utils/babel.js +231 -0
  24. package/esm/utils/constants.js +20 -0
  25. package/esm/utils/ref.js +4 -0
  26. package/esm/utils/types.js +343 -0
  27. package/{types/index.d.ts → index.d.ts} +0 -1
  28. package/index.js +24 -0
  29. package/message-builder/index.js +17 -0
  30. package/{types/message-builder → message-builder}/message-builder.d.ts +1 -1
  31. package/message-builder/message-builder.js +91 -0
  32. package/message-composer/index.d.ts +1 -0
  33. package/message-composer/index.js +17 -0
  34. package/{types/message-composer → message-composer}/message-composer.d.ts +1 -1
  35. package/message-composer/message-composer.js +133 -0
  36. package/package.json +19 -68
  37. package/provider/index.d.ts +1 -0
  38. package/provider/index.js +17 -0
  39. package/provider/provider.js +127 -0
  40. package/react-query/index.d.ts +1 -0
  41. package/react-query/index.js +17 -0
  42. package/{types/react-query → react-query}/react-query.d.ts +2 -3
  43. package/react-query/react-query.js +490 -0
  44. package/recoil/index.d.ts +1 -0
  45. package/recoil/index.js +17 -0
  46. package/{types/recoil → recoil}/recoil.d.ts +1 -1
  47. package/recoil/recoil.js +140 -0
  48. package/{types/utils → utils}/babel.d.ts +9 -8
  49. package/utils/babel.js +285 -0
  50. package/utils/constants.js +46 -0
  51. package/utils/index.js +26 -0
  52. package/{types/utils → utils}/ref.d.ts +1 -1
  53. package/utils/ref.js +8 -0
  54. package/{types/utils → utils}/types.d.ts +8 -8
  55. package/utils/types.js +379 -0
  56. package/main/client/client.js +0 -196
  57. package/main/client/index.js +0 -16
  58. package/main/client/test/ts-client.account-nfts.spec.js +0 -28
  59. package/main/client/test/ts-client.arrays-ref.spec.js +0 -19
  60. package/main/client/test/ts-client.arrays.spec.js +0 -26
  61. package/main/client/test/ts-client.cw-named-groups.test.js +0 -19
  62. package/main/client/test/ts-client.cw-proposal-single.test.js +0 -23
  63. package/main/client/test/ts-client.empty-enums.spec.js +0 -13
  64. package/main/client/test/ts-client.issue-101.spec.js +0 -23
  65. package/main/client/test/ts-client.issue-103.test.js +0 -44
  66. package/main/client/test/ts-client.issue-71.test.js +0 -81
  67. package/main/client/test/ts-client.issue-98.test.js +0 -28
  68. package/main/client/test/ts-client.issues.test.js +0 -81
  69. package/main/client/test/ts-client.overrides.spec.js +0 -33
  70. package/main/client/test/ts-client.sg721.spec.js +0 -19
  71. package/main/client/test/ts-client.spec.js +0 -87
  72. package/main/client/test/ts-client.vectis.spec.js +0 -46
  73. package/main/client/test/ts-client.wager.spec.js +0 -39
  74. package/main/context/context.js +0 -162
  75. package/main/context/imports.js +0 -159
  76. package/main/context/index.js +0 -27
  77. package/main/index.js +0 -104
  78. package/main/message-builder/index.js +0 -16
  79. package/main/message-builder/message-builder.js +0 -62
  80. package/main/message-builder/message-builder.spec.js +0 -20
  81. package/main/message-composer/index.js +0 -16
  82. package/main/message-composer/message-composer.js +0 -86
  83. package/main/message-composer/message-composer.spec.js +0 -23
  84. package/main/provider/index.js +0 -16
  85. package/main/provider/provider.js +0 -71
  86. package/main/provider/provider.spec.js +0 -60
  87. package/main/react-query/index.js +0 -16
  88. package/main/react-query/react-query.js +0 -413
  89. package/main/react-query/react-query.spec.js +0 -91
  90. package/main/recoil/index.js +0 -16
  91. package/main/recoil/recoil.js +0 -61
  92. package/main/recoil/recoil.spec.js +0 -20
  93. package/main/types.js +0 -4
  94. package/main/utils/babel.js +0 -282
  95. package/main/utils/babel.spec.js +0 -109
  96. package/main/utils/constants.js +0 -26
  97. package/main/utils/index.js +0 -65
  98. package/main/utils/ref.js +0 -12
  99. package/main/utils/types.js +0 -343
  100. package/module/client/client.js +0 -166
  101. package/module/client/index.js +0 -1
  102. package/module/client/test/ts-client.account-nfts.spec.js +0 -25
  103. package/module/client/test/ts-client.arrays-ref.spec.js +0 -16
  104. package/module/client/test/ts-client.arrays.spec.js +0 -23
  105. package/module/client/test/ts-client.cw-named-groups.test.js +0 -16
  106. package/module/client/test/ts-client.cw-proposal-single.test.js +0 -20
  107. package/module/client/test/ts-client.empty-enums.spec.js +0 -10
  108. package/module/client/test/ts-client.issue-101.spec.js +0 -22
  109. package/module/client/test/ts-client.issue-103.test.js +0 -41
  110. package/module/client/test/ts-client.issue-71.test.js +0 -21
  111. package/module/client/test/ts-client.issue-98.test.js +0 -25
  112. package/module/client/test/ts-client.issues.test.js +0 -21
  113. package/module/client/test/ts-client.overrides.spec.js +0 -30
  114. package/module/client/test/ts-client.sg721.spec.js +0 -16
  115. package/module/client/test/ts-client.spec.js +0 -84
  116. package/module/client/test/ts-client.vectis.spec.js +0 -43
  117. package/module/client/test/ts-client.wager.spec.js +0 -36
  118. package/module/context/context.js +0 -116
  119. package/module/context/imports.js +0 -127
  120. package/module/index.js +0 -9
  121. package/module/message-builder/index.js +0 -1
  122. package/module/message-builder/message-builder.js +0 -52
  123. package/module/message-builder/message-builder.spec.js +0 -17
  124. package/module/message-composer/index.js +0 -1
  125. package/module/message-composer/message-composer.js +0 -70
  126. package/module/message-composer/message-composer.spec.js +0 -20
  127. package/module/provider/index.js +0 -1
  128. package/module/provider/provider.js +0 -45
  129. package/module/provider/provider.spec.js +0 -58
  130. package/module/react-query/index.js +0 -1
  131. package/module/react-query/react-query.js +0 -403
  132. package/module/react-query/react-query.spec.js +0 -85
  133. package/module/recoil/index.js +0 -1
  134. package/module/recoil/recoil.js +0 -46
  135. package/module/recoil/recoil.spec.js +0 -14
  136. package/module/types.js +0 -3
  137. package/module/utils/babel.js +0 -203
  138. package/module/utils/babel.spec.js +0 -70
  139. package/module/utils/constants.js +0 -12
  140. package/module/utils/index.js +0 -6
  141. package/module/utils/ref.js +0 -4
  142. package/module/utils/types.js +0 -301
  143. package/src/client/client.ts +0 -584
  144. package/src/client/index.ts +0 -1
  145. package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +0 -497
  146. package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +0 -452
  147. package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +0 -101
  148. package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +0 -141
  149. package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +0 -341
  150. package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +0 -20
  151. package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +0 -47
  152. package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +0 -79
  153. package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +0 -432
  154. package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +0 -117
  155. package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +0 -984
  156. package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +0 -709
  157. package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +0 -350
  158. package/src/client/test/__snapshots__/ts-client.spec.ts.snap +0 -723
  159. package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +0 -337
  160. package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +0 -132
  161. package/src/client/test/ts-client.account-nfts.spec.ts +0 -55
  162. package/src/client/test/ts-client.arrays-ref.spec.ts +0 -48
  163. package/src/client/test/ts-client.arrays.spec.ts +0 -58
  164. package/src/client/test/ts-client.cw-named-groups.test.ts +0 -48
  165. package/src/client/test/ts-client.cw-proposal-single.test.ts +0 -50
  166. package/src/client/test/ts-client.empty-enums.spec.ts +0 -28
  167. package/src/client/test/ts-client.issue-101.spec.ts +0 -37
  168. package/src/client/test/ts-client.issue-103.test.ts +0 -106
  169. package/src/client/test/ts-client.issue-71.test.ts +0 -51
  170. package/src/client/test/ts-client.issue-98.test.ts +0 -55
  171. package/src/client/test/ts-client.issues.test.ts +0 -52
  172. package/src/client/test/ts-client.overrides.spec.ts +0 -74
  173. package/src/client/test/ts-client.sg721.spec.ts +0 -46
  174. package/src/client/test/ts-client.spec.ts +0 -166
  175. package/src/client/test/ts-client.vectis.spec.ts +0 -97
  176. package/src/client/test/ts-client.wager.spec.ts +0 -63
  177. package/src/context/context.ts +0 -229
  178. package/src/context/imports.ts +0 -195
  179. package/src/context/index.ts +0 -2
  180. package/src/message-builder/__snapshots__/message-builder.spec.ts.snap +0 -270
  181. package/src/message-builder/message-builder.spec.ts +0 -24
  182. package/src/message-builder/message-builder.ts +0 -119
  183. package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +0 -331
  184. package/src/message-composer/index.ts +0 -1
  185. package/src/message-composer/message-composer.spec.ts +0 -46
  186. package/src/message-composer/message-composer.ts +0 -262
  187. package/src/provider/__snapshots__/provider.spec.ts.snap +0 -49
  188. package/src/provider/index.ts +0 -1
  189. package/src/provider/provider.spec.ts +0 -81
  190. package/src/provider/provider.ts +0 -237
  191. package/src/react-query/__snapshots__/react-query.spec.ts.snap +0 -1359
  192. package/src/react-query/index.ts +0 -1
  193. package/src/react-query/react-query.spec.ts +0 -116
  194. package/src/react-query/react-query.ts +0 -1072
  195. package/src/recoil/__snapshots__/recoil.spec.ts.snap +0 -203
  196. package/src/recoil/index.ts +0 -1
  197. package/src/recoil/recoil.spec.ts +0 -38
  198. package/src/recoil/recoil.ts +0 -307
  199. package/src/types.ts +0 -44
  200. package/src/utils/__snapshots__/babel.spec.ts.snap +0 -75
  201. package/src/utils/babel.spec.ts +0 -511
  202. package/src/utils/babel.ts +0 -352
  203. package/src/utils/constants.ts +0 -37
  204. package/src/utils/ref.ts +0 -6
  205. package/src/utils/types.ts +0 -478
  206. package/types/types.d.ts +0 -41
  207. /package/{types/client → client}/index.d.ts +0 -0
  208. /package/{types/context → context}/index.d.ts +0 -0
  209. /package/{src/message-builder/index.ts → esm/message-builder/index.js} +0 -0
  210. /package/{types/message-composer/index.d.ts → esm/message-composer/index.js} +0 -0
  211. /package/{types/provider/index.d.ts → esm/provider/index.js} +0 -0
  212. /package/{types/react-query/index.d.ts → esm/react-query/index.js} +0 -0
  213. /package/{types/recoil/index.d.ts → esm/recoil/index.js} +0 -0
  214. /package/{src/utils/index.ts → esm/utils/index.js} +0 -0
  215. /package/{types/message-builder → message-builder}/index.d.ts +0 -0
  216. /package/{types/provider → provider}/provider.d.ts +0 -0
  217. /package/{types/utils → utils}/constants.d.ts +0 -0
  218. /package/{types/utils → utils}/index.d.ts +0 -0
@@ -1,97 +0,0 @@
1
- import cosmos_msg_for__empty from '../../../../../__fixtures__/vectis/govec/cosmos_msg_for__empty.json';
2
- import execute_msg_for__empty from '../../../../../__fixtures__/vectis/govec/execute_msg_for__empty.json';
3
- import can_execute_relay_response from '../../../../../__fixtures__/vectis/govec/can_execute_relay_response.json';
4
- import info_response from '../../../../../__fixtures__/vectis/govec/info_response.json';
5
- import relay_transaction from '../../../../../__fixtures__/vectis/govec/relay_transaction.json';
6
-
7
- import {
8
- createQueryClass,
9
- createExecuteClass,
10
- createExecuteInterface,
11
- createTypeInterface
12
- } from '../client';
13
-
14
- import { RenderContext } from '../../context';
15
- import { expectCode, makeContext } from '../../../test-utils';
16
-
17
- it('cosmos_msg_for__empty', () => {
18
- const ctx = makeContext(cosmos_msg_for__empty);
19
- expectCode(createTypeInterface(
20
- ctx,
21
- cosmos_msg_for__empty
22
- ))
23
- });
24
-
25
- it('execute_msg_for__empty', () => {
26
- const ctx = makeContext(execute_msg_for__empty);
27
- expectCode(createTypeInterface(
28
- ctx,
29
- execute_msg_for__empty
30
- ))
31
- })
32
-
33
- it('can_execute_relay_response', () => {
34
- const ctx = makeContext(can_execute_relay_response);
35
- expectCode(createTypeInterface(
36
- ctx,
37
- can_execute_relay_response
38
- ))
39
- })
40
-
41
- it('info_response', () => {
42
- const ctx = makeContext(info_response);
43
- expectCode(createTypeInterface(
44
- ctx,
45
- info_response
46
- ))
47
- })
48
-
49
- it('relay_transaction', () => {
50
- const ctx = makeContext(relay_transaction);
51
- expectCode(createTypeInterface(
52
- ctx,
53
- relay_transaction
54
- ))
55
- })
56
-
57
-
58
- it('query classes', () => {
59
- const ctx = makeContext(cosmos_msg_for__empty);
60
- expectCode(createQueryClass(
61
- ctx,
62
- 'SG721QueryClient',
63
- 'SG721ReadOnlyInstance',
64
- cosmos_msg_for__empty
65
- ))
66
- });
67
-
68
- it('query classes', () => {
69
- const ctx = makeContext(execute_msg_for__empty);
70
- expectCode(createQueryClass(
71
- ctx,
72
- 'SG721QueryClient',
73
- 'SG721ReadOnlyInstance',
74
- execute_msg_for__empty
75
- ))
76
- });
77
-
78
- it('execute classes array types', () => {
79
- const ctx = makeContext(execute_msg_for__empty);
80
- expectCode(createExecuteClass(
81
- ctx,
82
- 'SG721Client',
83
- 'SG721Instance',
84
- null,
85
- execute_msg_for__empty
86
- ))
87
- });
88
-
89
- it('execute interfaces no extends', () => {
90
- const ctx = makeContext(execute_msg_for__empty);
91
- expectCode(createExecuteInterface(
92
- ctx,
93
- 'SG721Instance',
94
- null,
95
- execute_msg_for__empty
96
- ))
97
- });
@@ -1,63 +0,0 @@
1
- import wagerJson from '../../../../../__fixtures__/wager/cw-wager.json';
2
- import {
3
- createQueryClass,
4
- createExecuteClass,
5
- createExecuteInterface,
6
- createTypeInterface
7
- } from '../client'
8
- import { expectCode, makeContext } from '../../../test-utils';
9
-
10
- const queryCtx = makeContext(wagerJson.query);
11
- const executeCtx = makeContext(wagerJson.execute);
12
-
13
- it('query', () => {
14
- expectCode(createTypeInterface(
15
- queryCtx,
16
- wagerJson.query
17
- ))
18
- })
19
-
20
- it('execute', () => {
21
- expectCode(createTypeInterface(
22
- executeCtx,
23
- wagerJson.execute
24
- ))
25
- })
26
-
27
- it('query classes', () => {
28
- expectCode(createQueryClass(
29
- queryCtx,
30
- 'WagerQueryClient',
31
- 'WagerReadOnlyInstance',
32
- wagerJson.query
33
- ))
34
- });
35
-
36
- it('execute classes', () => {
37
- expectCode(createExecuteClass(
38
- executeCtx,
39
- 'WagerClient',
40
- 'WagerInstance',
41
- null,
42
- wagerJson.execute
43
- ))
44
- });
45
-
46
- // it('execute classes array types', () => {
47
- // expectCode(createExecuteClass(
48
- // ctx,
49
- // 'SG721Client',
50
- // 'SG721Instance',
51
- // null,
52
- // wagerJson
53
- // ))
54
- // });
55
-
56
- // it('execute interfaces no extends', () => {
57
- // expectCode(createExecuteInterface(
58
- // ctx,
59
- // 'SG721Instance',
60
- // null,
61
- // wagerJson
62
- // ))
63
- // });
@@ -1,229 +0,0 @@
1
- import { JSONSchema } from "../types";
2
- import { refLookup } from "../utils";
3
- import { convertUtilsToImportList, getImportStatements, UtilMapping } from "./imports";
4
- import deepmerge from "deepmerge";
5
- import { basename, extname } from 'path'
6
-
7
- /// Plugin Types
8
- export interface ReactQueryOptions {
9
- enabled?: boolean;
10
- optionalClient?: boolean;
11
- version?: 'v3' | 'v4';
12
- mutations?: boolean;
13
- camelize?: boolean;
14
- queryKeys?: boolean
15
- queryFactory?: boolean
16
- }
17
-
18
- export interface TSClientOptions {
19
- enabled?: boolean;
20
- execExtendsQuery?: boolean;
21
- noImplicitOverride?: boolean;
22
- }
23
- export interface MessageComposerOptions {
24
- enabled?: boolean;
25
- }
26
- export interface MessageBuilderOptions {
27
- enabled?: boolean;
28
- }
29
- export interface RecoilOptions {
30
- enabled?: boolean;
31
- }
32
- export interface TSTypesOptions {
33
- enabled?: boolean;
34
- // deprecated
35
- aliasExecuteMsg?: boolean;
36
- aliasEntryPoints?: boolean;
37
- }
38
-
39
- /// END Plugin Types
40
-
41
- interface KeyedSchema {
42
- [key: string]: JSONSchema;
43
- }
44
- export interface IDLObject {
45
- contract_name: string;
46
- contract_version: string;
47
- idl_version: string;
48
- instantiate: JSONSchema;
49
- execute: JSONSchema;
50
- query: JSONSchema;
51
- migrate: JSONSchema;
52
- sudo: JSONSchema;
53
- responses: KeyedSchema;
54
- }
55
-
56
- export interface ContractInfo {
57
- schemas: JSONSchema[];
58
- responses?: Record<string, JSONSchema>;
59
- idlObject?: IDLObject;
60
- };
61
- export interface RenderOptions {
62
- enabled?: boolean;
63
- types?: TSTypesOptions;
64
- recoil?: RecoilOptions;
65
- messageComposer?: MessageComposerOptions;
66
- messageBuilder?: MessageBuilderOptions;
67
- client?: TSClientOptions;
68
- reactQuery?: ReactQueryOptions;
69
- }
70
-
71
- export interface ProviderInfo {
72
- classname: string,
73
- filename: string,
74
- basename: string,
75
- }
76
-
77
- export interface IContext {
78
- refLookup($ref: string);
79
- addUtil(util: string);
80
- getImports(registeredUtils?: UtilMapping, filepath?: string);
81
- }
82
-
83
- export interface IRenderContext<TOpt = RenderOptions> extends IContext {
84
- contract: ContractInfo;
85
- options: TOpt;
86
-
87
- addProviderInfo(contractName: string, type: string, classname: string, filename: string): void;
88
- getProviderInfos(): {
89
- [key: string]: {
90
- [key: string]: ProviderInfo;
91
- };
92
- };
93
- }
94
-
95
- export const defaultOptions: RenderOptions = {
96
- enabled: true,
97
- types: {
98
- enabled: true,
99
- aliasExecuteMsg: false
100
- },
101
- client: {
102
- enabled: true,
103
- execExtendsQuery: true,
104
- noImplicitOverride: false,
105
- },
106
- recoil: {
107
- enabled: false
108
- },
109
- messageComposer: {
110
- enabled: false
111
- },
112
- messageBuilder: {
113
- enabled: false,
114
- },
115
- reactQuery: {
116
- enabled: false,
117
- optionalClient: false,
118
- version: 'v4',
119
- mutations: false,
120
- camelize: true,
121
- queryKeys: false
122
- }
123
- };
124
-
125
- export const getDefinitionSchema = (schemas: JSONSchema[]): JSONSchema => {
126
- const aggregateSchema = {
127
- definitions: {
128
- //
129
- }
130
- };
131
-
132
- schemas.forEach(schema => {
133
- schema.definitions = schema.definitions || {};
134
- aggregateSchema.definitions = {
135
- ...aggregateSchema.definitions,
136
- ...schema.definitions
137
- };
138
- });
139
-
140
- return aggregateSchema;
141
- };
142
-
143
- export class BuilderContext {
144
- providers: {
145
- [key: string]: {
146
- [key: string]: ProviderInfo;
147
- };
148
- } = {};
149
-
150
- addProviderInfo(contractName: string, type: string, classname: string, filename: string): void {
151
- if (!this.providers[contractName]) {
152
- this.providers[contractName] = {}
153
- }
154
-
155
- this.providers[contractName][type] = {
156
- classname,
157
- filename,
158
- basename: basename(filename, extname(filename))
159
- };
160
- }
161
- getProviderInfos(): {
162
- [key: string]: {
163
- [key: string]: ProviderInfo;
164
- };
165
- } {
166
- return this.providers;
167
- }
168
- }
169
-
170
- /**
171
- * context object for generating code.
172
- * only mergeDefaultOpt needs to implementing for combine options and default options.
173
- * @param TOpt option type
174
- */
175
- export abstract class RenderContextBase<TOpt = RenderOptions> implements IRenderContext<TOpt> {
176
- builderContext: BuilderContext;
177
- contract: ContractInfo;
178
- utils: string[] = [];
179
- schema: JSONSchema;
180
- options: TOpt;
181
-
182
- constructor(
183
- contract: ContractInfo,
184
- options?: TOpt,
185
- builderContext?: BuilderContext
186
- ) {
187
- this.contract = contract;
188
- this.schema = getDefinitionSchema(contract.schemas);
189
- this.options = this.mergeDefaultOpt(options);
190
- this.builderContext = builderContext;
191
- }
192
- /**
193
- * merge options and default options
194
- * @param options
195
- */
196
- abstract mergeDefaultOpt(options: TOpt): TOpt;
197
- refLookup($ref: string) {
198
- return refLookup($ref, this.schema)
199
- }
200
- addUtil(util: string) {
201
- this.utils[util] = true;
202
- }
203
- addProviderInfo(contractName: string, type: string, classname: string, filename: string): void {
204
- this.builderContext.addProviderInfo(contractName, type, classname, filename);
205
- }
206
- getProviderInfos(): {
207
- [key: string]: {
208
- [key: string]: ProviderInfo;
209
- };
210
- } {
211
- return this.builderContext.providers;
212
- }
213
- getImports(registeredUtils?: UtilMapping, filepath?: string) {
214
- return getImportStatements(
215
- convertUtilsToImportList(
216
- this,
217
- Object.keys(this.utils),
218
- registeredUtils,
219
- ),
220
- filepath
221
- );
222
- }
223
- }
224
-
225
- export class RenderContext extends RenderContextBase {
226
- mergeDefaultOpt(options: RenderOptions): RenderOptions {
227
- return deepmerge(defaultOptions, options ?? {});
228
- }
229
- }
@@ -1,195 +0,0 @@
1
- import * as t from '@babel/types';
2
- import { importAs, importStmt } from "../utils";
3
- import { RenderContext } from './context';
4
- import { relative, dirname, extname } from 'path';
5
-
6
-
7
- export interface ImportObj {
8
- type: 'import' | 'default' | 'namespace';
9
- name: string;
10
- path: string;
11
- importAs?: string;
12
- }
13
-
14
- export type GetUtilFn = (<TContext = RenderContext>(...args: any[]) => (context: TContext) => ImportObj);
15
- export type UtilMapping = {
16
- [key: string]:
17
- | ImportObj
18
- | string
19
- | GetUtilFn
20
- };
21
-
22
- const makeReactQuerySwitch = (varName) => {
23
- return (context: RenderContext) => {
24
- switch (context.options.reactQuery.version) {
25
- case 'v4':
26
- return {
27
- type: 'import',
28
- path: '@tanstack/react-query',
29
- name: varName
30
- }
31
- case 'v3':
32
- default:
33
- return {
34
- type: 'import',
35
- path: 'react-query',
36
- name: varName
37
- }
38
- }
39
- };
40
- }
41
-
42
- export const UTILS = {
43
- selectorFamily: 'recoil',
44
- MsgExecuteContract: 'cosmjs-types/cosmwasm/wasm/v1/tx',
45
- MsgExecuteContractEncodeObject: '@cosmjs/cosmwasm-stargate',
46
- Coin: '@cosmjs/amino',
47
- toUtf8: '@cosmjs/encoding',
48
- StdFee: '@cosmjs/amino',
49
- CosmWasmClient: '@cosmjs/cosmwasm-stargate',
50
- ExecuteResult: '@cosmjs/cosmwasm-stargate',
51
- SigningCosmWasmClient: '@cosmjs/cosmwasm-stargate',
52
-
53
- // react-query
54
- useQuery: makeReactQuerySwitch('useQuery'),
55
- UseQueryOptions: makeReactQuerySwitch('UseQueryOptions'),
56
- useMutation: makeReactQuerySwitch('useMutation'),
57
- UseMutationOptions: makeReactQuerySwitch('UseMutationOptions')
58
-
59
- };
60
-
61
- export const UTIL_HELPERS = [
62
- '__contractContextBase__',
63
- ];
64
-
65
- export const convertUtilsToImportList = (
66
- context: RenderContext,
67
- utils: string[],
68
- registeredUtils?: UtilMapping
69
- ): ImportObj[] => {
70
- return utils.map((util) => {
71
- let result = null;
72
-
73
- if(registeredUtils){
74
- result = convertUtil(context, util, registeredUtils);
75
-
76
- if (result) {
77
- return result;
78
- }
79
- }
80
-
81
- result = convertUtil(context, util, UTILS);
82
-
83
- if (result) {
84
- return result;
85
- }
86
-
87
- throw new Error(`missing Util! ::[${util}]`);
88
- });
89
- };
90
-
91
- export const convertUtil = (
92
- context: RenderContext,
93
- util: string,
94
- registeredUtils: object
95
- ): ImportObj => {
96
- if (!registeredUtils.hasOwnProperty(util)) return null;
97
- if (typeof registeredUtils[util] === 'string') {
98
- return {
99
- type: 'import',
100
- path: registeredUtils[util],
101
- name: util
102
- };
103
- } else if (typeof registeredUtils[util] === 'function') {
104
- return registeredUtils[util](context);
105
- } else {
106
- return registeredUtils[util];
107
- }
108
- };
109
-
110
-
111
- // __helpers__
112
- export const getImportStatements = (
113
- list: ImportObj[],
114
- filepath?: string
115
- ) => {
116
-
117
- // swap helpers with helpers file...
118
- const modifiedImports = list.map(imp => {
119
- if (filepath && UTIL_HELPERS.includes(imp.path)) {
120
- const name = imp.path.replace(/__/g, '');
121
- return {
122
- ...imp,
123
- path: getRelativePath(filepath, `./${name}`)
124
- }
125
- }
126
- return imp;
127
- });
128
-
129
- const imports = modifiedImports.reduce((m, obj) => {
130
- m[obj.path] = m[obj.path] || [];
131
- const exists = m[obj.path].find(el =>
132
- el.type === obj.type && el.path === obj.path && el.name === obj.name);
133
-
134
- // MARKED AS NOT DRY [google.protobuf names]
135
- // TODO some have google.protobuf.Any shows up... figure out the better way to handle this
136
- if (/\./.test(obj.name)) {
137
- obj.name = obj.name.split('.')[obj.name.split('.').length - 1];
138
- }
139
-
140
- if (!exists) {
141
- m[obj.path].push(obj);
142
- }
143
- return m;
144
- }, {})
145
-
146
-
147
- return Object.entries(imports)
148
- .reduce((m, [importPath, imports]: [string, ImportObj[]]) => {
149
- const defaultImports = imports.filter(a => a.type === 'default');
150
- if (defaultImports.length) {
151
- if (defaultImports.length > 1) throw new Error('more than one default name NOT allowed.')
152
- m.push(
153
- t.importDeclaration(
154
- [
155
- t.importDefaultSpecifier(
156
- t.identifier(defaultImports[0].name)
157
- )
158
- ],
159
- t.stringLiteral(defaultImports[0].path)
160
- )
161
- )
162
- }
163
- const namedImports = imports.filter(a => a.type === 'import' && (!a.importAs || (a.name === a.importAs)));
164
- if (namedImports.length) {
165
- m.push(importStmt(namedImports.map(i => i.name), namedImports[0].path));
166
- }
167
- const aliasNamedImports = imports.filter(a => a.type === 'import' && (a.importAs && (a.name !== a.importAs)));
168
- aliasNamedImports.forEach(imp => {
169
- m.push(importAs(imp.name, imp.importAs, imp.path));
170
- });
171
-
172
- const namespaced = imports.filter(a => a.type === 'namespace');
173
- if (namespaced.length) {
174
- if (namespaced.length > 1) throw new Error('more than one namespaced name NOT allowed.')
175
- m.push(
176
- t.importDeclaration(
177
- [
178
- t.importNamespaceSpecifier(
179
- t.identifier(namespaced[0].name)
180
- )
181
- ],
182
- t.stringLiteral(namespaced[0].path)
183
- )
184
- )
185
- }
186
- return m;
187
- }, [])
188
- };
189
-
190
- export const getRelativePath = (f1: string, f2: string) => {
191
- const rel = relative(dirname(f1), f2);
192
- let importPath = rel.replace(extname(rel), '');
193
- if (!/^\./.test(importPath)) importPath = `./${importPath}`;
194
- return importPath;
195
- }
@@ -1,2 +0,0 @@
1
- export * from './context';
2
- export * from './imports';