@taqueria/plugin-contract-types 0.28.6 → 0.28.18

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -66,7 +66,7 @@ The `generate types` command will accept the following optional parameters:
66
66
  The generated TS types can be used in a Taquito project which provides an improved developing experience, and simplifies the way types are provided to Taquito method calls. Some examples of how these changes are put into use are detailed below
67
67
 
68
68
  > ### :page_with_curl: Note
69
- > You can view the full example in the `example-usage.ts` file on Github: [example-usage.ts](https://github.com/ecadlabs/taqueria/blob/main/taqueria-plugin-contract-types/example/example-usage.ts)
69
+ > You can view the full example in the `example-usage.ts` file on Github: [example-usage.ts](https://github.com/pinnacle-labs/taqueria/blob/main/taqueria-plugin-contract-types/example/example-usage.ts)
70
70
 
71
71
  ### Calling the `.at` Method of a Contract
72
72
 
package/_readme.eta CHANGED
@@ -68,7 +68,7 @@ The `generate types` command will accept the following optional parameters:
68
68
  The generated TS types can be used in a Taquito project which provides an improved developing experience, and simplifies the way types are provided to Taquito method calls. Some examples of how these changes are put into use are detailed below
69
69
 
70
70
  <%~ it.noteOpenAdmonition %>
71
- You can view the full example in the `example-usage.ts` file on Github: [example-usage.ts](https://github.com/ecadlabs/taqueria/blob/main/taqueria-plugin-contract-types/example/example-usage.ts)
71
+ You can view the full example in the `example-usage.ts` file on Github: [example-usage.ts](https://github.com/pinnacle-labs/taqueria/blob/main/taqueria-plugin-contract-types/example/example-usage.ts)
72
72
  <%= it.closeAdmonition %>
73
73
 
74
74
  ### Calling the `.at` Method of a Contract
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generateContractTypesFromMichelsonCode,
3
3
  normalizeContractName
4
- } from "./chunk-B5MX5VNS.js";
4
+ } from "./chunk-RD5ZALXH.js";
5
5
 
6
6
  // src/cli-process.ts
7
7
  import fsRaw from "fs";
@@ -239,4 +239,4 @@ var generateContractTypesProcessContractFiles = async ({
239
239
  export {
240
240
  generateContractTypesProcessContractFiles
241
241
  };
242
- //# sourceMappingURL=chunk-E6YGOZCV.js.map
242
+ //# sourceMappingURL=chunk-FJB62W6D.js.map
@@ -190,18 +190,25 @@ ${tabs(indent)}}])`;
190
190
  return `${t.name ?? `${numberVarNamePrefix}${i}`}${t.type.optional && (options == null ? void 0 : options.mode) !== "defaultValue" ? `?` : ``}: ${typeToCode(t.type, indent)}`;
191
191
  };
192
192
  const argsToCode = (args, indent, asObject) => {
193
- if (args.length === 1) {
194
- if (args[0].type.kind === `unit`)
193
+ const sortedArgs = args.sort((a, b) => {
194
+ if (a.type.optional && !b.type.optional)
195
+ return 1;
196
+ if (!a.type.optional && b.type.optional)
197
+ return -1;
198
+ return 0;
199
+ });
200
+ if (sortedArgs.length === 1) {
201
+ if (sortedArgs[0].type.kind === `unit`)
195
202
  return ``;
196
203
  if ((options == null ? void 0 : options.mode) === "defaultValue") {
197
- return typeToCode(args[0].type, indent + 1);
204
+ return typeToCode(sortedArgs[0].type, indent + 1);
198
205
  }
199
- return `${args[0].name ?? `param`}: ${typeToCode(args[0].type, indent + 1)}`;
206
+ return `${sortedArgs[0].name ?? `param`}: ${typeToCode(sortedArgs[0].type, indent + 1)}`;
200
207
  }
201
208
  const result = `${toIndentedItems(
202
209
  indent,
203
210
  {},
204
- args.filter((x) => x.name || x.type.kind !== `unit`).map((a, i) => {
211
+ sortedArgs.filter((x) => x.name || x.type.kind !== `unit`).map((a, i) => {
205
212
  if (!asObject && (options == null ? void 0 : options.mode) === "defaultValue") {
206
213
  return typeToCode(a.type, indent + 1) + `,`;
207
214
  }
@@ -345,7 +352,7 @@ var visitContractParameterEndpoint = (node) => {
345
352
  return node.args.map((x) => visitContractParameterEndpoint(x)).reduce(reduceFlatMap, []);
346
353
  }
347
354
  const nameRaw = (_b = node.annots) == null ? void 0 : _b[0];
348
- const name = (nameRaw == null ? void 0 : nameRaw.startsWith("%")) ? nameRaw.substr(1) : null;
355
+ const name = (nameRaw == null ? void 0 : nameRaw.startsWith("%")) ? nameRaw.substr(1) : "default";
349
356
  if (!name) {
350
357
  console.warn(`Unknown method: ${node.prim}`, { node, args: node.args });
351
358
  return [];
@@ -631,4 +638,4 @@ export {
631
638
  parseContractInterface,
632
639
  generateContractTypesFromMichelsonCode
633
640
  };
634
- //# sourceMappingURL=chunk-B5MX5VNS.js.map
641
+ //# sourceMappingURL=chunk-RD5ZALXH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["src/generator/contract-name.ts","src/generator/common.ts","src/generator/typescript-output.ts","src/generator/process.ts","src/generator/contract-parser.ts","src/generator/schema-output.ts"],"sourcesContent":["export const normalizeContractName = (text: string) =>\n\ttext\n\t\t.replace(/[^A-Za-z0-9]/g, '_')\n\t\t.split('_')\n\t\t.filter(x => x)\n\t\t.map(x => x[0].toUpperCase() + x.substring(1))\n\t\t.join('');\n","export class GenerateApiError implements Error {\n\tname = `GenerateApiError`;\n\tconstructor(public message: string, readonly data: unknown) {\n\t\tconsole.error(`❌ GenerateApiError: ${message}`, data);\n\t}\n}\n\nexport const assertExhaustive = (value: never, message: string): void => {\n\tconsole.error(message, { value });\n};\n\nexport const reduceFlatMap = <T>(out: T[], x: T[]): T[] => {\n\tout.push(...x);\n\treturn out;\n};\n\n// const reduceFlatMapTest = () => {\n// const items = [['a'], ['b']];\n// const itemsFlat = items.reduce(reduceFlatMap);\n// };\n","import { assertExhaustive, GenerateApiError, reduceFlatMap } from './common';\nimport { TypedMethod, TypedStorage, TypedType, TypedVar } from './contract-parser';\n\nexport type TypescriptCodeOutput = {\n\ttypesFileContent: string;\n\tcontractCodeFileContent: string;\n\tstorage: string;\n\tmethods: string;\n\tmethodsObject: string;\n};\n\nexport type TypeAliasData = {\n\tmode: 'local';\n\tfileContent?: string;\n} | {\n\tmode: 'file' | 'library';\n\timportPath?: string;\n} | {\n\tmode: 'simple';\n};\n\nexport type TypeUtilsData = {\n\timportPath: string;\n};\n\nexport const createTypescriptCodeGenerator = (options?: { mode?: 'types' | 'defaultValue' }) => {\n\ttype TypeAlias = {\n\t\taliasType: string;\n\t\tsimpleTypeDefinition: string;\n\t\tsimpleTypeImports?: { name: string; isDefault?: boolean; from: string }[];\n\t};\n\tconst usedStrictTypes = [] as TypeAlias[];\n\tconst addTypeAlias = (strictType: TypeAlias) => {\n\t\tif (!usedStrictTypes.some(x => x.aliasType === strictType.aliasType)) {\n\t\t\tusedStrictTypes.push(strictType);\n\t\t}\n\t};\n\n\t// Not really tabs :)\n\tconst tabs = (indent: number) => Array(indent).fill(` `).join(``);\n\tconst toIndentedItems = (\n\t\tindent: number,\n\t\tdelimiters: { afterItem?: string; beforeItem?: string },\n\t\titems: string[],\n\t) => {\n\t\treturn `\n${tabs(indent + 1)}${\n\t\t\titems.join(`${delimiters.afterItem ?? ``}\n${tabs(indent + 1)}${delimiters.beforeItem ?? ``}`)\n\t\t}\n${tabs(indent)}`;\n\t};\n\n\tconst typeToCode = (t: TypedType, indent: number): string => {\n\t\tif (options?.mode === 'defaultValue') {\n\t\t\treturn typeToCode_defaultValue(t, indent);\n\t\t}\n\n\t\tif (t.kind === `value`) {\n\t\t\t// return `${t.typescriptType}`;\n\n\t\t\tconst prim = `prim` in t.raw ? t.raw.prim : `unknown`;\n\n\t\t\t// Strict mode\n\t\t\tif (\n\t\t\t\tt.typescriptType === `boolean`\n\t\t\t\t|| t.typescriptType === `string` && prim === `string`\n\t\t\t) {\n\t\t\t\treturn `${t.typescriptType}`;\n\t\t\t}\n\n\t\t\tif (t.typescriptType === 'number') {\n\t\t\t\tconst simpleBaseType = `string | BigNumber | number`;\n\t\t\t\tconst typeAlias: TypeAlias = {\n\t\t\t\t\taliasType: prim,\n\t\t\t\t\tsimpleTypeDefinition: `type ${prim} = ${simpleBaseType};`,\n\t\t\t\t\tsimpleTypeImports: [{ name: 'BigNumber', isDefault: true, from: 'bignumber.js' }],\n\t\t\t\t};\n\t\t\t\taddTypeAlias(typeAlias);\n\n\t\t\t\treturn typeAlias.aliasType;\n\t\t\t}\n\n\t\t\tconst simpleBaseType = t.typescriptType === 'Date' ? 'Date | string' : t.typescriptType;\n\t\t\tconst typeAlias: TypeAlias = { aliasType: prim, simpleTypeDefinition: `type ${prim} = ${simpleBaseType};` };\n\t\t\taddTypeAlias(typeAlias);\n\n\t\t\treturn typeAlias.aliasType;\n\t\t}\n\t\tif (t.kind === `array`) {\n\t\t\treturn `Array<${typeToCode(t.array.item, indent)}>`;\n\t\t}\n\t\tif (t.kind === `map`) {\n\t\t\tconst typeAlias: TypeAlias = t.map.isBigMap\n\t\t\t\t? {\n\t\t\t\t\taliasType: `BigMap`,\n\t\t\t\t\tsimpleTypeDefinition: 'type BigMap<K, T> = MichelsonMap<K, T>;',\n\t\t\t\t\tsimpleTypeImports: [{ name: 'MichelsonMap', from: '@taquito/taquito' }],\n\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\taliasType: `MMap`,\n\t\t\t\t\tsimpleTypeDefinition: 'type MMap<K, T> = MichelsonMap<K, T>;',\n\t\t\t\t\tsimpleTypeImports: [{ name: 'MichelsonMap', from: '@taquito/taquito' }],\n\t\t\t\t};\n\t\t\taddTypeAlias(typeAlias);\n\n\t\t\treturn `${typeAlias.aliasType}<${typeToCode(t.map.key, indent)}, ${typeToCode(t.map.value, indent)}>`;\n\t\t}\n\t\tif (t.kind === `lambda`) {\n\t\t\tconst typeAlias: TypeAlias = {\n\t\t\t\taliasType: 'Instruction',\n\t\t\t\tsimpleTypeDefinition: `type Instruction = MichelsonInstruction;`,\n\t\t\t\tsimpleTypeImports: [{ name: 'MichelsonInstruction', isDefault: false, from: '@taquito/michel-codec' }],\n\t\t\t};\n\t\t\taddTypeAlias(typeAlias);\n\t\t\treturn `Instruction[]`;\n\t\t}\n\t\tif (t.kind === `object`) {\n\t\t\treturn `{${toIndentedItems(indent, {}, t.fields.map((a, i) => varToCode(a, i, indent + 1) + `;`))}}`;\n\t\t}\n\t\tif (t.kind === `union`) {\n\t\t\tconst getUnionItem = (a: TypedVar, i: number) => {\n\t\t\t\tconst itemCode = `${varToCode(a, i, indent + 1)}`;\n\n\t\t\t\t// Keep on single line if already on single line\n\t\t\t\tif (!itemCode.includes(`\\n`)) {\n\t\t\t\t\treturn `{ ${itemCode} }`;\n\t\t\t\t}\n\n\t\t\t\t// Indent if multi-line (and remake with extra indent)\n\t\t\t\treturn `{${toIndentedItems(indent + 1, {}, [`${varToCode(a, i, indent + 2)}`])}}`;\n\t\t\t};\n\n\t\t\treturn `(${toIndentedItems(indent, { beforeItem: `| ` }, t.union.map(getUnionItem))})`;\n\t\t}\n\t\tif (t.kind === `unit`) {\n\t\t\tconst typeAlias: TypeAlias = {\n\t\t\t\taliasType: `unit`,\n\t\t\t\tsimpleTypeDefinition: `type unit = (true | undefined);`,\n\t\t\t};\n\t\t\taddTypeAlias(typeAlias);\n\t\t\treturn typeAlias.aliasType;\n\t\t}\n\t\tif (t.kind === `never`) {\n\t\t\treturn `never`;\n\t\t}\n\t\tif (t.kind === `unknown`) {\n\t\t\treturn `unknown`;\n\t\t}\n\n\t\tassertExhaustive(t, `Unknown type`);\n\t\tthrow new GenerateApiError(`Unknown type node`, { t });\n\t};\n\n\tconst typeToCode_defaultValue = (t: TypedType, indent: number): string => {\n\t\tif (t.kind === `value`) {\n\t\t\t// return `${t.typescriptType}`;\n\n\t\t\tconst prim = `prim` in t.raw ? t.raw.prim : `unknown`;\n\n\t\t\t// Strict mode\n\t\t\tif (t.typescriptType === 'boolean') {\n\t\t\t\treturn `true`;\n\t\t\t}\n\t\t\tif (t.typescriptType === `string` && prim === `string`) {\n\t\t\t\treturn `'VALUE'`;\n\t\t\t}\n\t\t\tif (t.typescriptType === 'number') {\n\t\t\t\treturn `tas.${prim}('42')`;\n\t\t\t}\n\t\t\tif (t.typescriptType === 'Date') {\n\t\t\t\treturn `tas.timestamp(new Date())`;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tprim === 'address'\n\t\t\t\t|| prim === 'contract'\n\t\t\t) {\n\t\t\t\treturn `tas.${prim}('tz1ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456')`;\n\t\t\t}\n\t\t\tif (prim === 'bytes') {\n\t\t\t\treturn `tas.${prim}(char2Bytes('DATA'))`;\n\t\t\t}\n\t\t\tif (t.typescriptType === 'string') {\n\t\t\t\treturn `tas.${prim}('VALUE')`;\n\t\t\t}\n\t\t\tassertExhaustive(t.typescriptType, `Unknown value type`);\n\n\t\t\treturn prim;\n\t\t}\n\t\tif (t.kind === `array`) {\n\t\t\treturn `[${typeToCode(t.array.item, indent)}]`;\n\t\t}\n\t\tif (t.kind === `map`) {\n\t\t\tconst keyPrim = `prim` in t.map.key.raw ? t.map.key.raw.prim : `unknown`;\n\t\t\tconst isStringBasedKey = t.map.key.kind === 'value' && keyPrim === 'string';\n\t\t\tif (isStringBasedKey) {\n\t\t\t\treturn `tas.${t.map.isBigMap ? 'bigMap' : 'map'}({ \n${tabs(indent + 1)}${typeToCode(t.map.key, indent)}: ${typeToCode(t.map.value, indent)},\n${tabs(indent)}})`;\n\t\t\t}\n\n\t\t\treturn `tas.${t.map.isBigMap ? 'bigMap' : 'map'}([{ \n${tabs(indent + 1)}key: ${typeToCode(t.map.key, indent)}, \n${tabs(indent + 1)}value: ${typeToCode(t.map.value, indent)},\n${tabs(indent)}}])`;\n\t\t}\n\t\tif (t.kind === `object`) {\n\t\t\tconst delimiter = options?.mode === 'defaultValue' ? ',' : `;`;\n\t\t\treturn `{${toIndentedItems(indent, {}, t.fields.map((a, i) => varToCode(a, i, indent + 1) + delimiter))}}`;\n\t\t}\n\t\tif (t.kind === `union`) {\n\t\t\tconst getUnionItem = (a: TypedVar, i: number) => {\n\t\t\t\tconst itemCode = `${varToCode(a, i, indent + 1)}`;\n\n\t\t\t\t// Keep on single line if already on single line\n\t\t\t\tif (!itemCode.includes(`\\n`)) {\n\t\t\t\t\treturn `{ ${itemCode} }`;\n\t\t\t\t}\n\n\t\t\t\t// Indent if multi-line (and remake with extra indent)\n\t\t\t\treturn `{${toIndentedItems(indent + 1, {}, [`${varToCode(a, i, indent + 2)}`])}}`;\n\t\t\t};\n\n\t\t\treturn `(${toIndentedItems(indent, { beforeItem: `| ` }, t.union.map(getUnionItem))})`;\n\t\t}\n\t\tif (t.kind === `unit`) {\n\t\t\treturn `tas.unit()`;\n\t\t}\n\t\tif (t.kind === `never`) {\n\t\t\treturn `never`;\n\t\t}\n\t\tif (t.kind === `unknown`) {\n\t\t\treturn `unknown`;\n\t\t}\n\t\tif (t.kind === 'lambda') {\n\t\t\treturn `tas.lambda([])`;\n\t\t}\n\n\t\tassertExhaustive(t, `Unknown type`);\n\t\tthrow new GenerateApiError(`Unknown type node`, { t });\n\t};\n\n\tconst varToCode = (t: TypedVar, i: number, indent: number, numberVarNamePrefix = ''): string => {\n\t\treturn `${t.name ?? `${numberVarNamePrefix}${i}`}${\n\t\t\tt.type.optional && options?.mode !== 'defaultValue' ? `?` : ``\n\t\t}: ${typeToCode(t.type, indent)}`;\n\t};\n\n\tconst argsToCode = (args: TypedVar[], indent: number, asObject: boolean): string => {\n\t\t// Sort arguments so that optional args at the end\n\t\t// See https://github.com/pinnacle-labs/taqueria/issues/1861\n\t\tconst sortedArgs = args.sort((a, b) => {\n\t\t\tif (a.type.optional && !b.type.optional) return 1;\n\t\t\tif (!a.type.optional && b.type.optional) return -1;\n\t\t\treturn 0;\n\t\t});\n\n\t\tif (sortedArgs.length === 1) {\n\t\t\tif (sortedArgs[0].type.kind === `unit`) return ``;\n\n\t\t\tif (options?.mode === 'defaultValue') {\n\t\t\t\treturn typeToCode(sortedArgs[0].type, indent + 1);\n\t\t\t}\n\t\t\treturn `${sortedArgs[0].name ?? `param`}: ${typeToCode(sortedArgs[0].type, indent + 1)}`;\n\t\t}\n\n\t\tconst result = `${\n\t\t\ttoIndentedItems(\n\t\t\t\tindent,\n\t\t\t\t{},\n\t\t\t\tsortedArgs.filter(x => x.name || x.type.kind !== `unit`).map((a, i) => {\n\t\t\t\t\tif (!asObject && options?.mode === 'defaultValue') {\n\t\t\t\t\t\treturn typeToCode(a.type, indent + 1) + `,`;\n\t\t\t\t\t}\n\t\t\t\t\treturn varToCode(a, i, indent + 1, asObject ? '' : '_') + `,`;\n\t\t\t\t}),\n\t\t\t)\n\t\t}`;\n\n\t\tif (asObject) {\n\t\t\tif (options?.mode === 'defaultValue') {\n\t\t\t\treturn `{${result}}`;\n\t\t\t}\n\t\t\treturn `params: {${result}}`;\n\t\t}\n\n\t\treturn result;\n\t};\n\n\treturn {\n\t\tusedStrictTypes,\n\t\ttabs,\n\t\ttoIndentedItems,\n\t\ttypeToCode,\n\t\targsToCode,\n\t};\n};\n\nexport const toTypescriptCode = (\n\tstorage: TypedStorage,\n\tmethods: TypedMethod[],\n\tcontractName: string,\n\tparsedContract: unknown,\n\tprotocol: { name: string; key: string },\n\ttypeAliasData: TypeAliasData,\n\ttypeUtilsData: TypeUtilsData,\n): TypescriptCodeOutput => {\n\tconst {\n\t\tusedStrictTypes,\n\t\ttoIndentedItems,\n\t\ttypeToCode,\n\t\targsToCode,\n\t} = createTypescriptCodeGenerator();\n\n\tconst methodsToCode = (indent: number) => {\n\t\tconst methodFields = methods.map(x => {\n\t\t\tconst methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, false)}) => Promise<void>;`;\n\t\t\treturn methodCode;\n\t\t});\n\n\t\tconst methodsTypeCode = `type Methods = {${toIndentedItems(indent, {}, methodFields)}};`;\n\t\treturn methodsTypeCode;\n\t};\n\tconst methodsObjectToCode = (indent: number) => {\n\t\tconst methodFields = methods.map(x => {\n\t\t\tconst methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, true)}) => Promise<void>;`;\n\t\t\treturn methodCode;\n\t\t});\n\n\t\tconst methodsTypeCode = `type MethodsObject = {${toIndentedItems(indent, {}, methodFields)}};`;\n\t\treturn methodsTypeCode;\n\t};\n\n\tconst storageToCode = (indent: number) => {\n\t\tconst storageTypeCode = `export type Storage = ${typeToCode(storage.storage, indent)};`;\n\t\treturn storageTypeCode;\n\t};\n\n\tconst methodsCode = methodsToCode(0);\n\tconst methodsObjectCode = methodsObjectToCode(0);\n\tconst storageCode = storageToCode(0);\n\n\t// Simple type aliases\n\tconst simpleTypeMappingImportsAll = new Map(\n\t\tusedStrictTypes.map(x => x.simpleTypeImports ?? []).reduce(reduceFlatMap, []).map(\n\t\t\tx => [`${x?.from}:${x?.name}:${x?.isDefault}`, x],\n\t\t),\n\t);\n\tconst simpleTypeMappingImportsFrom = [...simpleTypeMappingImportsAll.values()].reduce((out, x) => {\n\t\tconst entry = out[x.from] ?? (out[x.from] = { names: [] });\n\t\tif (x.isDefault) {\n\t\t\tentry.default = x.name;\n\t\t} else {\n\t\t\tentry.names.push(x.name);\n\t\t}\n\t\tentry.names.sort((a, b) => a.localeCompare(b));\n\t\treturn out;\n\t}, {} as { [from: string]: { names: string[]; default?: string } });\n\n\tconst simpleTypeMappingImportsText = Object.keys(simpleTypeMappingImportsFrom)\n\t\t.map(k => {\n\t\t\tconst entry = simpleTypeMappingImportsFrom[k];\n\t\t\tconst items = [entry.default, entry.names.length ? `{ ${entry.names.join(', ')} }` : ''].filter(x => x);\n\t\t\treturn `import ${items.join(', ')} from '${k}';\\n`;\n\t\t})\n\t\t.join('');\n\n\tconst simpleTypeMapping = usedStrictTypes\n\t\t.sort((a, b) => a.aliasType.localeCompare(b.aliasType))\n\t\t.map(x => x.simpleTypeDefinition).join(`\\n`);\n\n\tconst typeUtilsDefinitions =\n\t\t`import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from '${typeUtilsData.importPath}';`;\n\n\tconst typeAliasesDefinitions = typeAliasData.mode === 'simple'\n\t\t? `${simpleTypeMappingImportsText}${simpleTypeMapping}`\n\t\t: typeAliasData.mode === 'local'\n\t\t? typeAliasData.fileContent\n\t\t: `import { ${usedStrictTypes.map(x => x.aliasType).join(`, `)} } from '${typeAliasData.importPath}';`;\n\n\tconst contractTypeName = `${contractName}ContractType`;\n\tconst walletTypeName = `${contractName}WalletType`;\n\tconst codeName = `${contractName}Code`;\n\n\tconst typesFileContent = `\n${typeUtilsDefinitions}\n${typeAliasesDefinitions}\n\n${storageCode}\n\n${methodsCode}\n\n${methodsObjectCode}\n\ntype contractTypes = { methods: Methods, methodsObject: MethodsObject, storage: Storage, code: { __type: '${codeName}', protocol: string, code: object[] } };\nexport type ${contractTypeName} = ContractAbstractionFromContractType<contractTypes>;\nexport type ${walletTypeName} = WalletContractAbstractionFromContractType<contractTypes>;\n`;\n\n\tconst contractCodeFileContent = `\nexport const ${codeName}: { __type: '${codeName}', protocol: string, code: object[] } = {\n __type: '${codeName}',\n protocol: '${protocol.key}',\n code: JSON.parse(\\`${JSON.stringify(parsedContract)}\\`)\n};\n`;\n\treturn {\n\t\ttypesFileContent,\n\t\tcontractCodeFileContent,\n\t\tstorage: storageCode,\n\t\tmethods: methodsCode,\n\t\tmethodsObject: methodsObjectCode,\n\t};\n};\n","import * as M from '@taquito/michel-codec';\nimport { GenerateApiError } from './common';\nimport { parseContractParameter, parseContractStorage } from './contract-parser';\nimport { SchemaOutput, toSchema } from './schema-output';\nimport { toTypescriptCode, TypeAliasData, TypescriptCodeOutput, TypeUtilsData } from './typescript-output';\n\nconst parseContractWithMinimalProtocolLevel = (\n\tcontractScript: string,\n\tformat: 'tz' | 'json',\n\tcontractLevelIndex: number,\n): { contract: M.MichelsonContract; protocol: { name: string; key: string } } => {\n\tconst contractLevels = [\n\t\t{ name: 'PsDELPH1', key: M.Protocol.PsDELPH1 },\n\t\t{ name: 'PtEdo2Zk', key: M.Protocol.PtEdo2Zk },\n\t\t{ name: 'PsFLorena', key: M.Protocol.PsFLorena },\n\t];\n\n\tconst protocol = contractLevels[contractLevelIndex];\n\tif (!protocol) {\n\t\tthrow new GenerateApiError(`Could not parse contract script`, contractScript);\n\t}\n\n\tconst p = new M.Parser({ protocol: protocol.key });\n\n\ttry {\n\t\tconst contract = (\n\t\t\tformat === 'tz'\n\t\t\t\t? p.parseScript(contractScript)\n\t\t\t\t: p.parseJSON(JSON.parse(contractScript))\n\t\t) as M.MichelsonContract;\n\t\tif (contract) {\n\t\t\treturn {\n\t\t\t\tcontract,\n\t\t\t\tprotocol,\n\t\t\t};\n\t\t}\n\t} catch {\n\t\t// Ignore parse errors\n\t}\n\n\t// Try again with next level\n\treturn parseContractWithMinimalProtocolLevel(contractScript, format, contractLevelIndex + 1);\n};\n\nexport const parseContractInterface = (\n\tcontractScript: string,\n\tformat: 'tz' | 'json',\n) => {\n\tconst p = new M.Parser({ protocol: M.Protocol.PsFLorena });\n\n\tconst { contract, protocol } = parseContractWithMinimalProtocolLevel(contractScript, format, 0);\n\n\tconst contractStorage = contract.find(x => x.prim === `storage`) as undefined | M.MichelsonContractStorage;\n\tconst contractParameter = contract.find(x => x.prim === `parameter`) as undefined | M.MichelsonContractParameter;\n\n\tconst storageResult = contractStorage && parseContractStorage(contractStorage);\n\tconst storage = storageResult\n\t\t?? { storage: { kind: `object`, raw: { prim: `never` } as M.MichelsonType, fields: [] } };\n\n\tconst parameterResult = contractParameter && parseContractParameter(contractParameter);\n\tconst methods = parameterResult?.methods ?? [];\n\n\treturn {\n\t\tstorage,\n\t\tmethods,\n\t\tcontract,\n\t\tprotocol,\n\t};\n};\n\nexport const generateContractTypesFromMichelsonCode = (\n\tcontractScript: string,\n\tcontractName: string,\n\tformat: 'tz' | 'json',\n\ttypeAliasData: TypeAliasData,\n\ttypeUtilsData: TypeUtilsData,\n): {\n\tschemaOutput: SchemaOutput;\n\ttypescriptCodeOutput: TypescriptCodeOutput;\n\tparsedContract: M.MichelsonContract;\n\tminimalProtocol: string;\n} => {\n\tconst {\n\t\tstorage,\n\t\tmethods,\n\t\tcontract,\n\t\tprotocol,\n\t} = parseContractInterface(\n\t\tcontractScript,\n\t\tformat,\n\t);\n\n\t// If there's only one entrypoint, then we call it \"default\"\n\tif (methods.length === 1) methods[0].name = `default`;\n\n\tconst schemaOutput = toSchema(methods, storage);\n\n\tconst typescriptCode = toTypescriptCode(\n\t\tstorage,\n\t\tmethods,\n\t\tcontractName,\n\t\tcontract,\n\t\tprotocol,\n\t\ttypeAliasData,\n\t\ttypeUtilsData,\n\t);\n\n\treturn {\n\t\tschemaOutput,\n\t\ttypescriptCodeOutput: typescriptCode,\n\t\tparsedContract: contract,\n\t\tminimalProtocol: protocol.key,\n\t};\n};\n","import * as M from '@taquito/michel-codec';\nimport { assertExhaustive, GenerateApiError, reduceFlatMap } from './common';\n\nexport type TypedStorage = {\n\tstorage: TypedType;\n};\nexport type TypedParameter = {\n\tmethods: TypedMethod[];\n};\nexport type TypedMethod = {\n\tname: string;\n\targs: TypedVar[];\n};\nexport type TypedVar = {\n\tname?: string;\n\ttype: TypedType;\n};\nexport type TypedType =\n\t& {\n\t\traw: M.MichelsonType;\n\t\toptional?: boolean;\n\t}\n\t& (\n\t\t{\n\t\t\tkind: 'unit';\n\t\t} | {\n\t\t\tkind: 'never';\n\t\t} | {\n\t\t\tkind: 'unknown';\n\t\t} | {\n\t\t\tkind: 'value';\n\t\t\tvalue: string;\n\t\t\ttypescriptType: 'string' | 'boolean' | 'number' | 'Date';\n\t\t} | {\n\t\t\tkind: 'union';\n\t\t\tunion: TypedVar[];\n\t\t} | {\n\t\t\tkind: 'object';\n\t\t\tfields: TypedVar[];\n\t\t} | {\n\t\t\tkind: 'array';\n\t\t\tarray: { item: TypedType };\n\t\t} | {\n\t\t\tkind: 'map';\n\t\t\tmap: { key: TypedType; value: TypedType; isBigMap: boolean };\n\t\t} | {\n\t\t\tkind: 'lambda';\n\t\t\tlambda: { arg: TypedType; ret: TypedType };\n\t\t}\n\t);\n\nconst toDebugSource = (node: M.MichelsonType) => {\n\treturn JSON.stringify(node);\n};\n\nexport const parseContractStorage = (storage: M.MichelsonContractStorage): TypedStorage => {\n\tconst fields = storage.args\n\t\t.map(x => visitVar(x))\n\t\t.reduce(reduceFlatMap, []);\n\n\tif (fields.length === 1 && !fields[0].name) {\n\t\treturn {\n\t\t\tstorage: fields[0].type,\n\t\t};\n\t}\n\n\treturn {\n\t\tstorage: {\n\t\t\tkind: `object` as const,\n\t\t\traw: storage as unknown as M.MichelsonType,\n\t\t\tfields,\n\t\t},\n\t};\n};\n\nexport const parseContractParameter = (parameter: M.MichelsonContractParameter): TypedParameter => {\n\treturn {\n\t\tmethods: parameter.args\n\t\t\t.map(x => visitContractParameterEndpoint(x as MMethod))\n\t\t\t.reduce(reduceFlatMap, []),\n\t};\n};\n\ntype MMethod = M.MichelsonTypeOr<[M.MichelsonType, M.MichelsonType]>;\nconst visitContractParameterEndpoint = (node: MMethod): TypedMethod[] => {\n\t// console.log('visitContractParameterEndpoint', { node });\n\n\t// Sub endpoints (i.e. admin endpoints that are imported)\n\tif (node.prim === `or`) {\n\t\treturn node.args.map(x => visitContractParameterEndpoint(x as MMethod)).reduce(reduceFlatMap, []);\n\t}\n\n\t// Sub endpoints as a list with a single or (i.e. admin endpoints that are imported)\n\tif (node.prim === `list` && node.args.length as number === 1 && (node.args[0] as MMethod)?.prim === `or`) {\n\t\treturn node.args.map(x => visitContractParameterEndpoint(x as MMethod)).reduce(reduceFlatMap, []);\n\t}\n\n\tconst nameRaw = node.annots?.[0];\n\n\t// If the name is missing, then we assume its the main / default entrypoint\n\tconst name = nameRaw?.startsWith('%') ? nameRaw.substr(1) : 'default';\n\n\tif (!name) {\n\t\tconsole.warn(`Unknown method: ${node.prim as string}`, { node, args: node.args });\n\t\treturn [];\n\t}\n\n\tconst nodeType = visitType(node, { ignorePairName: node.prim === 'pair' });\n\n\t// Method args are usually objects\n\tif (nodeType.kind === 'object') {\n\t\treturn [{ name, args: nodeType.fields }];\n\t}\n\n\t// Simple methods can have a single unnamed argument\n\treturn [{\n\t\tname,\n\t\targs: [{ type: nodeType }],\n\t}];\n};\n\n// type PrimOf<T extends M.MichelsonType> = T extends { prim: infer U } ? U : never;\n// type WithPrim<T extends M.MichelsonType, P extends PrimOf<T>> = T extends { prim: P } ? T : never;\n// const isPrimType = <TPrim extends PrimOf<M.MichelsonType>>(node: undefined | null | M.MichelsonType, prim: TPrim): node is WithPrim<M.MichelsonType, TPrim> => {\n// return (node && 'prim' in node && node.prim === prim) || false;\n// };\n\ntype MVarArgs = M.MichelsonType;\nconst visitVar = (node: MVarArgs): TypedVar[] => {\n\tconst name = `annots` in node && node.annots?.length === 1 ? node.annots[0].substr(1) : undefined;\n\tconst type = visitType(node);\n\n\treturn [{\n\t\tname,\n\t\ttype,\n\t}];\n};\n\ntype MType = M.MichelsonType;\nconst visitType = (node: MType, options?: { ignorePairName?: boolean }): TypedType => {\n\t// console.log('visitType', { node });\n\t// const debug_source = toDebugSource(node);\n\n\t// if (typeof node === `string`) {\n\t// return { kind: `value`, raw: node, value: node, typescriptType: `string` };\n\t// }\n\n\tif (!(`prim` in node)) {\n\t\t// Unknown\n\t\tconsole.error(`visitType no prim`, { node });\n\t\treturn { kind: `unknown`, raw: node };\n\t}\n\n\t// Union\n\tif (node.prim === `or`) {\n\t\tconst unionVars = node.args.map(x => visitVar(x)).reduce(reduceFlatMap, []).map(x => x);\n\n\t\t// Flatten with child unions\n\t\tconst union = unionVars.map(x => !x.name && x.type.kind === 'union' ? x.type.union : [x]).reduce(reduceFlatMap, []);\n\t\t// const union = unionVars.map(x=>x.type);\n\n\t\t// const union = unionVars.map(x => x.type);\n\n\t\t// Flatten with child unions\n\n\t\t// const rightSide = union[1];\n\t\t// if (rightSide.kind === `union`) {\n\t\t// union.pop();\n\t\t// union.push(...rightSide.union);\n\t\t// }\n\n\t\tif (union.some(x => !x)) {\n\t\t\tthrow new GenerateApiError(`or: Some fields are null`, { node });\n\t\t}\n\t\treturn {\n\t\t\tkind: `union`,\n\t\t\traw: node,\n\t\t\tunion,\n\t\t};\n\t}\n\n\t// Intersect\n\tif (node.prim === `pair`) {\n\t\tconst fields = node.args.map(x => visitVar(x)).reduce(reduceFlatMap, []);\n\t\tif (fields.some(x => !x)) {\n\t\t\tthrow new GenerateApiError(`pair: Some fields are null`, { node, args: node.args, fields });\n\t\t}\n\t\t// Disabled Check: Apparently pairs can have more than 2 items\n\t\t// if (fields.length !== 2) {\n\t\t// throw new GenerateApiError(`pair: Expected 2 items`, { node, length: fields.length, fields });\n\t\t// }\n\n\t\t// Flatten with unnamed child pairs\n\t\tconst fieldsFlat = fields.map(x =>\n\t\t\t(!x.name || options?.ignorePairName) && x.type.kind === 'object' ? x.type.fields : [x]\n\t\t).reduce(reduceFlatMap, []);\n\n\t\treturn {\n\t\t\tkind: `object`,\n\t\t\traw: node,\n\t\t\tfields: fieldsFlat,\n\t\t};\n\t}\n\n\t// list\n\tif (\n\t\tnode.prim === `list`\n\t\t|| node.prim === `set`\n\t) {\n\t\tif (node.args.length !== 1) {\n\t\t\tthrow new GenerateApiError(`list does not have 1 arg`, { node, args: node.args });\n\t\t}\n\n\t\tconst arrayItem = visitType(node.args[0]);\n\t\tif (!arrayItem) {\n\t\t\tthrow new GenerateApiError(`arrayItem are null`, { node, args: node.args, arrayItem });\n\t\t}\n\t\treturn {\n\t\t\tkind: `array`,\n\t\t\traw: node,\n\t\t\tarray: { item: arrayItem },\n\t\t};\n\t}\n\n\t// map\n\tif (\n\t\tnode.prim === `map`\n\t\t|| node.prim === `big_map`\n\t) {\n\t\tif (node.args.length !== 2) {\n\t\t\tthrow new GenerateApiError(`map does not have 2 args`, { node, args: node.args });\n\t\t}\n\n\t\tconst mapKey = visitType(node.args[0]);\n\t\tconst mapValue = visitType(node.args[1]);\n\t\tif (!mapKey || !mapValue) {\n\t\t\tthrow new GenerateApiError(`map is missing key or value`, { node, args: node.args, mapKey, mapValue });\n\t\t}\n\t\treturn {\n\t\t\tkind: `map`,\n\t\t\traw: node,\n\t\t\tmap: {\n\t\t\t\tkey: mapKey,\n\t\t\t\tvalue: mapValue,\n\t\t\t\tisBigMap: node.prim === `big_map`,\n\t\t\t},\n\t\t};\n\t}\n\n\t// option\n\tif (node.prim === `option`) {\n\t\treturn {\n\t\t\t...visitType(node.args[0]),\n\t\t\toptional: true,\n\t\t};\n\t}\n\n\t// boolean\n\tif (node.prim === `bool`) {\n\t\treturn {\n\t\t\tkind: `value`,\n\t\t\traw: node,\n\t\t\tvalue: node.prim,\n\t\t\ttypescriptType: `boolean`,\n\t\t};\n\t}\n\n\t// numbers\n\tif (\n\t\tnode.prim === `nat`\n\t\t|| node.prim === `int`\n\t\t|| node.prim === `mutez`\n\t) {\n\t\treturn {\n\t\t\tkind: `value`,\n\t\t\traw: node,\n\t\t\tvalue: node.prim,\n\t\t\ttypescriptType: `number`,\n\t\t};\n\t}\n\n\t// Date\n\tif (node.prim === `timestamp`) {\n\t\treturn {\n\t\t\tkind: `value`,\n\t\t\traw: node,\n\t\t\tvalue: node.prim,\n\t\t\ttypescriptType: `Date`,\n\t\t};\n\t}\n\n\t// strings\n\tif (\n\t\tnode.prim === `address`\n\t\t|| node.prim === `key`\n\t\t|| node.prim === `key_hash`\n\t\t|| node.prim === `chain_id`\n\t\t|| node.prim === `string`\n\t\t|| node.prim === `signature`\n\t\t|| node.prim === `ticket`\n\t\t|| node.prim === `bls12_381_fr`\n\t\t|| node.prim === `bls12_381_g1`\n\t\t|| node.prim === `bls12_381_g2`\n\t\t|| node.prim === `sapling_state`\n\t\t|| node.prim === `sapling_transaction`\n\t\t|| node.prim === `contract`\n\t) {\n\t\treturn {\n\t\t\tkind: `value`,\n\t\t\traw: node,\n\t\t\tvalue: node.prim,\n\t\t\ttypescriptType: `string`,\n\t\t};\n\t}\n\n\t// void\n\tif (node.prim === `unit`) {\n\t\treturn {\n\t\t\tkind: `unit`,\n\t\t\traw: node,\n\t\t};\n\t}\n\n\t// bytes?\n\tif (node.prim === `bytes`) {\n\t\treturn {\n\t\t\tkind: `value`,\n\t\t\traw: node,\n\t\t\tvalue: node.prim,\n\t\t\ttypescriptType: `string`,\n\t\t};\n\t}\n\n\tif (node.prim === `lambda`) {\n\t\tif (node.args.length !== 2) {\n\t\t\tthrow new GenerateApiError(`lambda does not have 2 args`, { node, args: node.args });\n\t\t}\n\n\t\tconst argType = visitType(node.args[0]);\n\t\tconst retType = visitType(node.args[1]);\n\t\tif (!argType || !retType) {\n\t\t\tthrow new GenerateApiError(`lambda is missing arg or return`, { node, args: node.args, argType, retType });\n\t\t}\n\n\t\treturn {\n\t\t\tkind: `lambda`,\n\t\t\traw: node,\n\t\t\tlambda: {\n\t\t\t\targ: argType,\n\t\t\t\tret: retType,\n\t\t\t},\n\t\t};\n\t}\n\n\t// misc?\n\tif (node.prim === `operation`) {\n\t\treturn {\n\t\t\tkind: `value`,\n\t\t\traw: node,\n\t\t\tvalue: node.prim,\n\t\t\ttypescriptType: `string`,\n\t\t};\n\t}\n\n\t// chest\n\tif (node.prim === 'chest' || node.prim === 'chest_key') {\n\t\treturn {\n\t\t\tkind: `value`,\n\t\t\traw: node,\n\t\t\tvalue: node.prim,\n\t\t\ttypescriptType: `string`,\n\t\t};\n\t}\n\n\t// never\n\tif (node.prim === `never`) {\n\t\treturn {\n\t\t\tkind: `never`,\n\t\t\traw: node,\n\t\t};\n\t}\n\n\t// Unknown\n\tassertExhaustive(node, `Unknown type`);\n\tthrow new GenerateApiError(`Unknown type`, { node });\n};\n","import { GenerateApiError } from './common';\nimport { TypedMethod, TypedStorage, TypedType, TypedVar } from './contract-parser';\n\ntype SchemaObjectType = { [name: string]: SchemaType };\ntype SchemaType = string | SchemaType[] | SchemaObjectType;\ntype SchemaMethods = {\n\t[name: string]: {\n\t\tparams: SchemaType;\n\t};\n};\nexport type SchemaOutput = {\n\tmethods: SchemaMethods;\n\tstorage: SchemaType;\n};\n\nexport const toSchema = (methods: TypedMethod[], storage: TypedStorage): SchemaOutput => {\n\tconst getSchemaObjectType = (vars: TypedVar[]) => {\n\t\t// console.log('getSchemaObjectType', { vars });\n\n\t\tif (vars.some(x => !x)) {\n\t\t\tthrow new GenerateApiError(`getSchemaObjectType has null vars`, { vars });\n\t\t}\n\n\t\treturn vars.reduce((out, x, i) => {\n\t\t\tout[x.name ?? i] = getSchemaType(x.type);\n\t\t\treturn out;\n\t\t}, {} as SchemaObjectType);\n\t};\n\n\tconst getSchemaType = (t: TypedType): SchemaType => {\n\t\t// console.log('getSchemaType', { t });\n\n\t\treturn (t.kind === `value` && t.value ? t.value : null)\n\t\t\t?? (t.kind === `array` && t.array ? [getSchemaType(t.array.item)] : null)\n\t\t\t?? (t.kind === `map` && t.map ? [`map`, getSchemaType(t.map.key), getSchemaType(t.map.value)] : null)\n\t\t\t?? (t.kind === `object` && t.fields ? getSchemaObjectType(t.fields) : null)\n\t\t\t?? (t.kind === `unit` ? `unit` : null)\n\t\t\t?? (t.kind === `never` ? `never` : null)\n\t\t\t?? (t.kind === 'lambda' ? ['lambda', getSchemaType(t.lambda.arg), getSchemaType(t.lambda.ret)] : null)\n\t\t\t?? `${t.raw as unknown as string}`;\n\t};\n\n\tconst schemaMethods = methods.reduce((out, x) => {\n\t\t// console.log('schemaMethods', { x });\n\n\t\tout[x.name] = {\n\t\t\tparams: x.args.length === 1 && !x.args[0].name\n\t\t\t\t? getSchemaType(x.args[0].type)\n\t\t\t\t: getSchemaObjectType(x.args ?? []),\n\t\t};\n\t\treturn out;\n\t}, {} as SchemaMethods);\n\n\tconst schemaStorage = getSchemaType(storage.storage);\n\n\treturn {\n\t\tmethods: schemaMethods,\n\t\tstorage: schemaStorage,\n\t};\n};\n"],"mappings":";AAAO,IAAM,wBAAwB,CAAC,SACrC,KACE,QAAQ,iBAAiB,GAAG,EAC5B,MAAM,GAAG,EACT,OAAO,OAAK,CAAC,EACb,IAAI,OAAK,EAAE,GAAG,YAAY,IAAI,EAAE,UAAU,CAAC,CAAC,EAC5C,KAAK,EAAE;;;ACNH,IAAM,mBAAN,MAAwC;AAAA,EAE9C,YAAmB,SAA0B,MAAe;AAAzC;AAA0B;AAD7C,gBAAO;AAEN,YAAQ,MAAM,4BAAuB,WAAW,IAAI;AAAA,EACrD;AACD;AAEO,IAAM,mBAAmB,CAAC,OAAc,YAA0B;AACxE,UAAQ,MAAM,SAAS,E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AAM,UAAU,KAAK,EAAE,MAAM,QAAQ,GAAsB,QAAQ,CAAC,EAAE,EAAE;AAEzF,QAAM,kBAAkB,qBAAqB,uBAAuB,iBAAiB;AACrF,QAAM,WAAU,mDAAiB,YAAW,CAAC;AAE7C,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,IAAM,yCAAyC,CACrD,gBACA,cACA,QACA,eACA,kBAMI;AACJ,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI;AAAA,IACH;AAAA,IACA;AAAA,EACD;AAGA,MAAI,QAAQ,WAAW;AAAG,YAAQ,GAAG,OAAO;AAE5C,QAAM,eAAe,SAAS,SAAS,OAAO;AAE9C,QAAM,iBAAiB;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,SAAO;AAAA,IACN;AAAA,IACA,sBAAsB;AAAA,IACtB,gBAAgB;AAAA,IAChB,iBAAiB,SAAS;AAAA,EAC3B;AACD;","names":["simpleBaseType","typeAlias"]}
@@ -0,0 +1,10 @@
1
+ { parameter (or (or (int %decrement) (pair %increment (option int) int)) (unit %reset)) ;
2
+ storage int ;
3
+ code { UNPAIR ;
4
+ IF_LEFT
5
+ { IF_LEFT
6
+ { SWAP ; SUB }
7
+ { CAR ; IF_NONE { PUSH int 1 ; ADD } { ADD } } }
8
+ { DROP 2 ; PUSH int 0 } ;
9
+ NIL operation ;
10
+ PAIR } }
package/index.cjs CHANGED
@@ -18,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
21
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
22
  mod
27
23
  ));
@@ -98,7 +94,7 @@ var visitContractParameterEndpoint = (node) => {
98
94
  return node.args.map((x) => visitContractParameterEndpoint(x)).reduce(reduceFlatMap, []);
99
95
  }
100
96
  const nameRaw = (_b = node.annots) == null ? void 0 : _b[0];
101
- const name = (nameRaw == null ? void 0 : nameRaw.startsWith("%")) ? nameRaw.substr(1) : null;
97
+ const name = (nameRaw == null ? void 0 : nameRaw.startsWith("%")) ? nameRaw.substr(1) : "default";
102
98
  if (!name) {
103
99
  console.warn(`Unknown method: ${node.prim}`, { node, args: node.args });
104
100
  return [];
@@ -480,18 +476,25 @@ ${tabs(indent)}}])`;
480
476
  return `${t.name ?? `${numberVarNamePrefix}${i}`}${t.type.optional && (options == null ? void 0 : options.mode) !== "defaultValue" ? `?` : ``}: ${typeToCode(t.type, indent)}`;
481
477
  };
482
478
  const argsToCode = (args, indent, asObject) => {
483
- if (args.length === 1) {
484
- if (args[0].type.kind === `unit`)
479
+ const sortedArgs = args.sort((a, b) => {
480
+ if (a.type.optional && !b.type.optional)
481
+ return 1;
482
+ if (!a.type.optional && b.type.optional)
483
+ return -1;
484
+ return 0;
485
+ });
486
+ if (sortedArgs.length === 1) {
487
+ if (sortedArgs[0].type.kind === `unit`)
485
488
  return ``;
486
489
  if ((options == null ? void 0 : options.mode) === "defaultValue") {
487
- return typeToCode(args[0].type, indent + 1);
490
+ return typeToCode(sortedArgs[0].type, indent + 1);
488
491
  }
489
- return `${args[0].name ?? `param`}: ${typeToCode(args[0].type, indent + 1)}`;
492
+ return `${sortedArgs[0].name ?? `param`}: ${typeToCode(sortedArgs[0].type, indent + 1)}`;
490
493
  }
491
494
  const result = `${toIndentedItems(
492
495
  indent,
493
496
  {},
494
- args.filter((x) => x.name || x.type.kind !== `unit`).map((a, i) => {
497
+ sortedArgs.filter((x) => x.name || x.type.kind !== `unit`).map((a, i) => {
495
498
  if (!asObject && (options == null ? void 0 : options.mode) === "defaultValue") {
496
499
  return typeToCode(a.type, indent + 1) + `,`;
497
500
  }