@taqueria/plugin-contract-types 0.8.4 → 0.13.16
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/chunk-QSIV2OJS.js +231 -0
- package/chunk-QSIV2OJS.js.map +1 -0
- package/chunk-T4SGVAIL.js +604 -0
- package/chunk-T4SGVAIL.js.map +1 -0
- package/example/contracts/subdir/example-contract-0.tz +7 -0
- package/example/contracts/subdir/subsubdir/example-contract-0.tz +7 -0
- package/example/test-generation/example-contract-0.jest-demo.ts +78 -0
- package/example/test-generation/example-contract-1.jest-demo.ts +196 -0
- package/example/test-generation/example-contract-10.jest-demo.ts +47 -0
- package/example/test-generation/example-contract-11.jest-demo.ts +48 -0
- package/example/test-generation/example-contract-2.jest-demo.ts +277 -0
- package/example/test-generation/example-contract-4.jest-demo.ts +203 -0
- package/example/test-generation/example-contract-5.jest-demo.ts +235 -0
- package/example/test-generation/example-contract-6.jest-demo.ts +277 -0
- package/example/test-generation/example-contract-7.jest-demo.ts +170 -0
- package/example/test-generation/example-contract-8.jest-demo.ts +227 -0
- package/example/test-generation/example-contract-9.jest-demo.ts +42 -0
- package/example/types-file/example-contract-10.types.ts +2 -2
- package/example/types-file/example-contract-11.types.ts +2 -2
- package/example/types-file/subdir/example-contract-0.code.ts +6 -0
- package/example/types-file/subdir/example-contract-0.types.ts +21 -0
- package/example/types-file/subdir/subsubdir/example-contract-0.code.ts +6 -0
- package/example/types-file/subdir/subsubdir/example-contract-0.types.ts +21 -0
- package/example/types-file/type-aliases.ts +4 -0
- package/index.cjs +925 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +78 -882
- package/index.js.map +1 -1
- package/index.ts +1 -0
- package/package.json +68 -53
- package/src/cli-process.cjs +853 -0
- package/src/cli-process.cjs.map +1 -0
- package/src/cli-process.d.ts +9 -0
- package/src/cli-process.js +8 -0
- package/src/cli-process.js.map +1 -0
- package/src/cli-process.ts +10 -1
- package/src/generator/process.ts +37 -13
- package/src/generator/testing-code-generator-jest-demo.ts +75 -0
- package/src/generator/testing-code-generator.cjs +613 -0
- package/src/generator/testing-code-generator.cjs.map +1 -0
- package/src/generator/testing-code-generator.d.ts +79 -0
- package/src/generator/testing-code-generator.js +131 -0
- package/src/generator/testing-code-generator.js.map +1 -0
- package/src/generator/testing-code-generator.ts +282 -0
- package/src/generator/typescript-output.ts +136 -14
- package/src/type-aliases.ts +1 -0
- package/test/generator.spec.ts +6 -0
- package/tsconfig.json +4 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
package/index.js
CHANGED
|
@@ -1,882 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
const nodeType = $b95e97a0bb3bf047$var$visitType(node, {
|
|
81
|
-
ignorePairName: node.prim === "pair"
|
|
82
|
-
});
|
|
83
|
-
// Method args are usually objects
|
|
84
|
-
if (nodeType.kind === "object") return [
|
|
85
|
-
{
|
|
86
|
-
name: name,
|
|
87
|
-
args: nodeType.fields
|
|
88
|
-
}
|
|
89
|
-
];
|
|
90
|
-
// Simple methods can have a single unnamed argument
|
|
91
|
-
return [
|
|
92
|
-
{
|
|
93
|
-
name: name,
|
|
94
|
-
args: [
|
|
95
|
-
{
|
|
96
|
-
type: nodeType
|
|
97
|
-
}
|
|
98
|
-
]
|
|
99
|
-
}
|
|
100
|
-
];
|
|
101
|
-
};
|
|
102
|
-
const $b95e97a0bb3bf047$var$visitVar = (node)=>{
|
|
103
|
-
const name = `annots` in node && node.annots?.length === 1 ? node.annots[0].substr(1) : undefined;
|
|
104
|
-
const type = $b95e97a0bb3bf047$var$visitType(node);
|
|
105
|
-
return [
|
|
106
|
-
{
|
|
107
|
-
name: name,
|
|
108
|
-
type: type
|
|
109
|
-
}
|
|
110
|
-
];
|
|
111
|
-
};
|
|
112
|
-
const $b95e97a0bb3bf047$var$visitType = (node, options)=>{
|
|
113
|
-
// console.log('visitType', { node });
|
|
114
|
-
// const debug_source = toDebugSource(node);
|
|
115
|
-
// if (typeof node === `string`) {
|
|
116
|
-
// return { kind: `value`, raw: node, value: node, typescriptType: `string` };
|
|
117
|
-
// }
|
|
118
|
-
if (!(`prim` in node)) {
|
|
119
|
-
// Unknown
|
|
120
|
-
console.error(`visitType no prim`, {
|
|
121
|
-
node: node
|
|
122
|
-
});
|
|
123
|
-
return {
|
|
124
|
-
kind: `unknown`,
|
|
125
|
-
raw: node
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
// Union
|
|
129
|
-
if (node.prim === `or`) {
|
|
130
|
-
const unionVars = node.args.map((x)=>$b95e97a0bb3bf047$var$visitVar(x)).reduce((0, $901f5cf476ef87a5$export$37679993c4e6bc41), []).map((x)=>x);
|
|
131
|
-
// Flatten with child unions
|
|
132
|
-
const union = unionVars.map((x)=>!x.name && x.type.kind === "union" ? x.type.union : [
|
|
133
|
-
x
|
|
134
|
-
]).reduce((0, $901f5cf476ef87a5$export$37679993c4e6bc41), []);
|
|
135
|
-
// const union = unionVars.map(x=>x.type);
|
|
136
|
-
// const union = unionVars.map(x => x.type);
|
|
137
|
-
// Flatten with child unions
|
|
138
|
-
// const rightSide = union[1];
|
|
139
|
-
// if (rightSide.kind === `union`) {
|
|
140
|
-
// union.pop();
|
|
141
|
-
// union.push(...rightSide.union);
|
|
142
|
-
// }
|
|
143
|
-
if (union.some((x)=>!x)) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`or: Some fields are null`, {
|
|
144
|
-
node: node
|
|
145
|
-
});
|
|
146
|
-
return {
|
|
147
|
-
kind: `union`,
|
|
148
|
-
raw: node,
|
|
149
|
-
union: union
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
// Intersect
|
|
153
|
-
if (node.prim === `pair`) {
|
|
154
|
-
const fields = node.args.map((x)=>$b95e97a0bb3bf047$var$visitVar(x)).reduce((0, $901f5cf476ef87a5$export$37679993c4e6bc41), []);
|
|
155
|
-
if (fields.some((x)=>!x)) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`pair: Some fields are null`, {
|
|
156
|
-
node: node,
|
|
157
|
-
args: node.args,
|
|
158
|
-
fields: fields
|
|
159
|
-
});
|
|
160
|
-
// Disabled Check: Apparently pairs can have more than 2 items
|
|
161
|
-
// if (fields.length !== 2) {
|
|
162
|
-
// throw new GenerateApiError(`pair: Expected 2 items`, { node, length: fields.length, fields });
|
|
163
|
-
// }
|
|
164
|
-
// Flatten with unnamed child pairs
|
|
165
|
-
const fieldsFlat = fields.map((x)=>(!x.name || options?.ignorePairName) && x.type.kind === "object" ? x.type.fields : [
|
|
166
|
-
x
|
|
167
|
-
]).reduce((0, $901f5cf476ef87a5$export$37679993c4e6bc41), []);
|
|
168
|
-
return {
|
|
169
|
-
kind: `object`,
|
|
170
|
-
raw: node,
|
|
171
|
-
fields: fieldsFlat
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
// list
|
|
175
|
-
if (node.prim === `list` || node.prim === `set`) {
|
|
176
|
-
if (node.args.length !== 1) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`list does not have 1 arg`, {
|
|
177
|
-
node: node,
|
|
178
|
-
args: node.args
|
|
179
|
-
});
|
|
180
|
-
const arrayItem = $b95e97a0bb3bf047$var$visitType(node.args[0]);
|
|
181
|
-
if (!arrayItem) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`arrayItem are null`, {
|
|
182
|
-
node: node,
|
|
183
|
-
args: node.args,
|
|
184
|
-
arrayItem: arrayItem
|
|
185
|
-
});
|
|
186
|
-
return {
|
|
187
|
-
kind: `array`,
|
|
188
|
-
raw: node,
|
|
189
|
-
array: {
|
|
190
|
-
item: arrayItem
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
// map
|
|
195
|
-
if (node.prim === `map` || node.prim === `big_map`) {
|
|
196
|
-
if (node.args.length !== 2) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`map does not have 2 args`, {
|
|
197
|
-
node: node,
|
|
198
|
-
args: node.args
|
|
199
|
-
});
|
|
200
|
-
const mapKey = $b95e97a0bb3bf047$var$visitType(node.args[0]);
|
|
201
|
-
const mapValue = $b95e97a0bb3bf047$var$visitType(node.args[1]);
|
|
202
|
-
if (!mapKey || !mapValue) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`map is missing key or value`, {
|
|
203
|
-
node: node,
|
|
204
|
-
args: node.args,
|
|
205
|
-
mapKey: mapKey,
|
|
206
|
-
mapValue: mapValue
|
|
207
|
-
});
|
|
208
|
-
return {
|
|
209
|
-
kind: `map`,
|
|
210
|
-
raw: node,
|
|
211
|
-
map: {
|
|
212
|
-
key: mapKey,
|
|
213
|
-
value: mapValue,
|
|
214
|
-
isBigMap: node.prim === `big_map`
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
// option
|
|
219
|
-
if (node.prim === `option`) return {
|
|
220
|
-
...$b95e97a0bb3bf047$var$visitType(node.args[0]),
|
|
221
|
-
optional: true
|
|
222
|
-
};
|
|
223
|
-
// boolean
|
|
224
|
-
if (node.prim === `bool`) return {
|
|
225
|
-
kind: `value`,
|
|
226
|
-
raw: node,
|
|
227
|
-
value: node.prim,
|
|
228
|
-
typescriptType: `boolean`
|
|
229
|
-
};
|
|
230
|
-
// numbers
|
|
231
|
-
if (node.prim === `nat` || node.prim === `int` || node.prim === `mutez`) return {
|
|
232
|
-
kind: `value`,
|
|
233
|
-
raw: node,
|
|
234
|
-
value: node.prim,
|
|
235
|
-
typescriptType: `number`
|
|
236
|
-
};
|
|
237
|
-
// Date
|
|
238
|
-
if (node.prim === `timestamp`) return {
|
|
239
|
-
kind: `value`,
|
|
240
|
-
raw: node,
|
|
241
|
-
value: node.prim,
|
|
242
|
-
typescriptType: `Date`
|
|
243
|
-
};
|
|
244
|
-
// strings
|
|
245
|
-
if (node.prim === `address` || node.prim === `key` || node.prim === `key_hash` || node.prim === `chain_id` || node.prim === `string` || node.prim === `signature` || node.prim === `ticket` || node.prim === `bls12_381_fr` || node.prim === `bls12_381_g1` || node.prim === `bls12_381_g2` || node.prim === `sapling_state` || node.prim === `sapling_transaction` || node.prim === `contract`) return {
|
|
246
|
-
kind: `value`,
|
|
247
|
-
raw: node,
|
|
248
|
-
value: node.prim,
|
|
249
|
-
typescriptType: `string`
|
|
250
|
-
};
|
|
251
|
-
// void
|
|
252
|
-
if (node.prim === `unit`) return {
|
|
253
|
-
kind: `unit`,
|
|
254
|
-
raw: node
|
|
255
|
-
};
|
|
256
|
-
// bytes?
|
|
257
|
-
if (node.prim === `bytes`) return {
|
|
258
|
-
kind: `value`,
|
|
259
|
-
raw: node,
|
|
260
|
-
value: node.prim,
|
|
261
|
-
typescriptType: `string`
|
|
262
|
-
};
|
|
263
|
-
// misc?
|
|
264
|
-
if (node.prim === `lambda` || node.prim === `operation`) return {
|
|
265
|
-
kind: `value`,
|
|
266
|
-
raw: node,
|
|
267
|
-
value: node.prim,
|
|
268
|
-
typescriptType: `string`
|
|
269
|
-
};
|
|
270
|
-
// chest
|
|
271
|
-
if (node.prim === "chest" || node.prim === "chest_key") return {
|
|
272
|
-
kind: `value`,
|
|
273
|
-
raw: node,
|
|
274
|
-
value: node.prim,
|
|
275
|
-
typescriptType: `string`
|
|
276
|
-
};
|
|
277
|
-
// never
|
|
278
|
-
if (node.prim === `never`) return {
|
|
279
|
-
kind: `never`,
|
|
280
|
-
raw: node
|
|
281
|
-
};
|
|
282
|
-
// Unknown
|
|
283
|
-
(0, $901f5cf476ef87a5$export$16bf6fe03653420f)(node, `Unknown type`);
|
|
284
|
-
throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`Unknown type`, {
|
|
285
|
-
node: node
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const $4e7cd4eb63db9934$export$eb0413f5ee90780 = (methods, storage)=>{
|
|
292
|
-
const getSchemaObjectType = (vars)=>{
|
|
293
|
-
// console.log('getSchemaObjectType', { vars });
|
|
294
|
-
if (vars.some((x)=>!x)) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`getSchemaObjectType has null vars`, {
|
|
295
|
-
vars: vars
|
|
296
|
-
});
|
|
297
|
-
return vars.reduce((out, x, i)=>{
|
|
298
|
-
out[x.name ?? i] = getSchemaType(x.type);
|
|
299
|
-
return out;
|
|
300
|
-
}, {});
|
|
301
|
-
};
|
|
302
|
-
const getSchemaType = (t)=>{
|
|
303
|
-
// console.log('getSchemaType', { t });
|
|
304
|
-
return ((((((t.kind === `value` && t.value ? t.value : null) ?? (t.kind === `array` && t.array ? [
|
|
305
|
-
getSchemaType(t.array.item)
|
|
306
|
-
] : null)) ?? (t.kind === `map` && t.map ? [
|
|
307
|
-
`map`,
|
|
308
|
-
getSchemaType(t.map.key),
|
|
309
|
-
getSchemaType(t.map.value)
|
|
310
|
-
] : null)) ?? (t.kind === `object` && t.fields ? getSchemaObjectType(t.fields) : null)) ?? (t.kind === `unit` ? `unit` : null)) ?? (t.kind === `never` ? `never` : null)) ?? `${t.raw}`;
|
|
311
|
-
};
|
|
312
|
-
const schemaMethods = methods.reduce((out, x)=>{
|
|
313
|
-
// console.log('schemaMethods', { x });
|
|
314
|
-
out[x.name] = {
|
|
315
|
-
params: x.args.length === 1 && !x.args[0].name ? getSchemaType(x.args[0].type) : getSchemaObjectType(x.args ?? [])
|
|
316
|
-
};
|
|
317
|
-
return out;
|
|
318
|
-
}, {});
|
|
319
|
-
const schemaStorage = getSchemaType(storage.storage);
|
|
320
|
-
return {
|
|
321
|
-
methods: schemaMethods,
|
|
322
|
-
storage: schemaStorage
|
|
323
|
-
};
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const $8fdd19ff0013f28e$export$d355209543d39bc0 = (storage, methods, contractName, parsedContract, protocol, typeAliasData, typeUtilsData)=>{
|
|
329
|
-
const usedStrictTypes = [];
|
|
330
|
-
const addTypeAlias = (strictType)=>{
|
|
331
|
-
if (!usedStrictTypes.some((x)=>x.aliasType === strictType.aliasType)) usedStrictTypes.push(strictType);
|
|
332
|
-
};
|
|
333
|
-
// Not really tabs :)
|
|
334
|
-
const tabs = (indent)=>Array(indent).fill(` `).join(``);
|
|
335
|
-
const toIndentedItems = (indent, delimeters, items)=>{
|
|
336
|
-
return `
|
|
337
|
-
${tabs(indent + 1)}${items.join(`${delimeters.afterItem ?? ``}
|
|
338
|
-
${tabs(indent + 1)}${delimeters.beforeItem ?? ``}`)}
|
|
339
|
-
${tabs(indent)}`;
|
|
340
|
-
};
|
|
341
|
-
const typeToCode = (t, indent)=>{
|
|
342
|
-
if (t.kind === `value`) {
|
|
343
|
-
// return `${t.typescriptType}`;
|
|
344
|
-
const prim = `prim` in t.raw ? t.raw.prim : `unknown`;
|
|
345
|
-
// Strict mode
|
|
346
|
-
if (t.typescriptType === `boolean` || t.typescriptType === `string` && prim === `string`) return `${t.typescriptType}`;
|
|
347
|
-
if (t.typescriptType === "number") {
|
|
348
|
-
const simpleBaseType = `string | BigNumber | number`;
|
|
349
|
-
const typeAlias = {
|
|
350
|
-
aliasType: prim,
|
|
351
|
-
simpleTypeDefinition: `type ${prim} = ${simpleBaseType};`,
|
|
352
|
-
simpleTypeImports: [
|
|
353
|
-
{
|
|
354
|
-
name: "BigNumber",
|
|
355
|
-
isDefault: true,
|
|
356
|
-
from: "bignumber.js"
|
|
357
|
-
}
|
|
358
|
-
]
|
|
359
|
-
};
|
|
360
|
-
addTypeAlias(typeAlias);
|
|
361
|
-
return typeAlias.aliasType;
|
|
362
|
-
}
|
|
363
|
-
const simpleBaseType = t.typescriptType === "Date" ? "Date | string" : t.typescriptType;
|
|
364
|
-
const typeAlias = {
|
|
365
|
-
aliasType: prim,
|
|
366
|
-
simpleTypeDefinition: `type ${prim} = ${simpleBaseType};`
|
|
367
|
-
};
|
|
368
|
-
addTypeAlias(typeAlias);
|
|
369
|
-
return typeAlias.aliasType;
|
|
370
|
-
}
|
|
371
|
-
if (t.kind === `array`) return `Array<${typeToCode(t.array.item, indent)}>`;
|
|
372
|
-
if (t.kind === `map`) {
|
|
373
|
-
const typeAlias = t.map.isBigMap ? {
|
|
374
|
-
aliasType: `BigMap`,
|
|
375
|
-
simpleTypeDefinition: "type BigMap<K, T> = MichelsonMap<K, T>;",
|
|
376
|
-
simpleTypeImports: [
|
|
377
|
-
{
|
|
378
|
-
name: "MichelsonMap",
|
|
379
|
-
from: "@taquito/taquito"
|
|
380
|
-
}
|
|
381
|
-
]
|
|
382
|
-
} : {
|
|
383
|
-
aliasType: `MMap`,
|
|
384
|
-
simpleTypeDefinition: "type MMap<K, T> = MichelsonMap<K, T>;",
|
|
385
|
-
simpleTypeImports: [
|
|
386
|
-
{
|
|
387
|
-
name: "MichelsonMap",
|
|
388
|
-
from: "@taquito/taquito"
|
|
389
|
-
}
|
|
390
|
-
]
|
|
391
|
-
};
|
|
392
|
-
addTypeAlias(typeAlias);
|
|
393
|
-
return `${typeAlias.aliasType}<${typeToCode(t.map.key, indent)}, ${typeToCode(t.map.value, indent)}>`;
|
|
394
|
-
}
|
|
395
|
-
if (t.kind === `object`) return `{${toIndentedItems(indent, {}, t.fields.map((a, i)=>varToCode(a, i, indent + 1) + `;`))}}`;
|
|
396
|
-
if (t.kind === `union`) {
|
|
397
|
-
const getUnionItem = (a, i)=>{
|
|
398
|
-
const itemCode = `${varToCode(a, i, indent + 1)}`;
|
|
399
|
-
// Keep on single line if already on single line
|
|
400
|
-
if (!itemCode.includes(`\n`)) return `{ ${itemCode} }`;
|
|
401
|
-
// Indent if multi-line (and remake with extra indent)
|
|
402
|
-
return `{${toIndentedItems(indent + 1, {}, [
|
|
403
|
-
`${varToCode(a, i, indent + 2)}`
|
|
404
|
-
])}}`;
|
|
405
|
-
};
|
|
406
|
-
return `(${toIndentedItems(indent, {
|
|
407
|
-
beforeItem: `| `
|
|
408
|
-
}, t.union.map(getUnionItem))})`;
|
|
409
|
-
}
|
|
410
|
-
if (t.kind === `unit`) {
|
|
411
|
-
const typeAlias = {
|
|
412
|
-
aliasType: `unit`,
|
|
413
|
-
simpleTypeDefinition: `type unit = (true | undefined);`
|
|
414
|
-
};
|
|
415
|
-
addTypeAlias(typeAlias);
|
|
416
|
-
return typeAlias.aliasType;
|
|
417
|
-
}
|
|
418
|
-
if (t.kind === `never`) return `never`;
|
|
419
|
-
if (t.kind === `unknown`) return `unknown`;
|
|
420
|
-
(0, $901f5cf476ef87a5$export$16bf6fe03653420f)(t, `Unknown type`);
|
|
421
|
-
throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`Unknown type node`, {
|
|
422
|
-
t: t
|
|
423
|
-
});
|
|
424
|
-
};
|
|
425
|
-
const varToCode = (t, i, indent, numberVarNamePrefix = "")=>{
|
|
426
|
-
return `${t.name ?? `${numberVarNamePrefix}${i}`}${t.type.optional ? `?` : ``}: ${typeToCode(t.type, indent)}`;
|
|
427
|
-
};
|
|
428
|
-
const argsToCode = (args, indent, asObject)=>{
|
|
429
|
-
if (args.length === 1) {
|
|
430
|
-
if (args[0].type.kind === `unit`) return ``;
|
|
431
|
-
return `${args[0].name ?? `param`}: ${typeToCode(args[0].type, indent + 1)}`;
|
|
432
|
-
}
|
|
433
|
-
const result = `${toIndentedItems(indent, {}, args.filter((x)=>x.name || x.type.kind !== `unit`).map((a, i)=>varToCode(a, i, indent + 1, asObject ? "" : "_") + `,`))}`;
|
|
434
|
-
if (asObject) return `params: {${result}}`;
|
|
435
|
-
return result;
|
|
436
|
-
};
|
|
437
|
-
const methodsToCode = (indent)=>{
|
|
438
|
-
const methodFields = methods.map((x)=>{
|
|
439
|
-
const methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, false)}) => Promise<void>;`;
|
|
440
|
-
return methodCode;
|
|
441
|
-
});
|
|
442
|
-
const methodsTypeCode = `type Methods = {${toIndentedItems(indent, {}, methodFields)}};`;
|
|
443
|
-
return methodsTypeCode;
|
|
444
|
-
};
|
|
445
|
-
const methodsObjectToCode = (indent)=>{
|
|
446
|
-
const methodFields = methods.map((x)=>{
|
|
447
|
-
const methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, true)}) => Promise<void>;`;
|
|
448
|
-
return methodCode;
|
|
449
|
-
});
|
|
450
|
-
const methodsTypeCode = `type MethodsObject = {${toIndentedItems(indent, {}, methodFields)}};`;
|
|
451
|
-
return methodsTypeCode;
|
|
452
|
-
};
|
|
453
|
-
const storageToCode = (indent)=>{
|
|
454
|
-
const storageTypeCode = `type Storage = ${typeToCode(storage.storage, indent)};`;
|
|
455
|
-
return storageTypeCode;
|
|
456
|
-
};
|
|
457
|
-
const methodsCode = methodsToCode(0);
|
|
458
|
-
const methodsObjectCode = methodsObjectToCode(0);
|
|
459
|
-
const storageCode = storageToCode(0);
|
|
460
|
-
// Simple type aliases
|
|
461
|
-
const simpleTypeMappingImportsAll = new Map(usedStrictTypes.map((x)=>x.simpleTypeImports ?? []).reduce((0, $901f5cf476ef87a5$export$37679993c4e6bc41), []).map((x)=>[
|
|
462
|
-
`${x?.from}:${x?.name}:${x?.isDefault}`,
|
|
463
|
-
x
|
|
464
|
-
]));
|
|
465
|
-
const simpleTypeMappingImportsFrom = [
|
|
466
|
-
...simpleTypeMappingImportsAll.values()
|
|
467
|
-
].reduce((out, x)=>{
|
|
468
|
-
const entry = out[x.from] ?? (out[x.from] = {
|
|
469
|
-
names: []
|
|
470
|
-
});
|
|
471
|
-
if (x.isDefault) entry.default = x.name;
|
|
472
|
-
else entry.names.push(x.name);
|
|
473
|
-
entry.names.sort((a, b)=>a.localeCompare(b));
|
|
474
|
-
return out;
|
|
475
|
-
}, {});
|
|
476
|
-
const simpleTypeMappingImportsText = Object.keys(simpleTypeMappingImportsFrom).map((k)=>{
|
|
477
|
-
const entry = simpleTypeMappingImportsFrom[k];
|
|
478
|
-
const items = [
|
|
479
|
-
entry.default,
|
|
480
|
-
entry.names.length ? `{ ${entry.names.join(", ")} }` : ""
|
|
481
|
-
].filter((x)=>x);
|
|
482
|
-
return `import ${items.join(", ")} from '${k}';\n`;
|
|
483
|
-
}).join("");
|
|
484
|
-
const simpleTypeMapping = usedStrictTypes.sort((a, b)=>a.aliasType.localeCompare(b.aliasType)).map((x)=>x.simpleTypeDefinition).join(`\n`);
|
|
485
|
-
const typeUtilsDefinitions = `import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from '${typeUtilsData.importPath}';`;
|
|
486
|
-
const typeAliasesDefinitions = typeAliasData.mode === "simple" ? `${simpleTypeMappingImportsText}${simpleTypeMapping}` : typeAliasData.mode === "local" ? typeAliasData.fileContent : `import { ${usedStrictTypes.map((x)=>x.aliasType).join(`, `)} } from '${typeAliasData.importPath}';`;
|
|
487
|
-
const contractTypeName = `${contractName}ContractType`;
|
|
488
|
-
const walletTypeName = `${contractName}WalletType`;
|
|
489
|
-
const codeName = `${contractName}Code`;
|
|
490
|
-
const typesFileContent = `
|
|
491
|
-
${typeUtilsDefinitions}
|
|
492
|
-
${typeAliasesDefinitions}
|
|
493
|
-
|
|
494
|
-
${storageCode}
|
|
495
|
-
|
|
496
|
-
${methodsCode}
|
|
497
|
-
|
|
498
|
-
${methodsObjectCode}
|
|
499
|
-
|
|
500
|
-
type contractTypes = { methods: Methods, methodsObject: MethodsObject, storage: Storage, code: { __type: '${codeName}', protocol: string, code: object[] } };
|
|
501
|
-
export type ${contractTypeName} = ContractAbstractionFromContractType<contractTypes>;
|
|
502
|
-
export type ${walletTypeName} = WalletContractAbstractionFromContractType<contractTypes>;
|
|
503
|
-
`;
|
|
504
|
-
const contractCodeFileContent = `
|
|
505
|
-
export const ${codeName}: { __type: '${codeName}', protocol: string, code: object[] } = {
|
|
506
|
-
__type: '${codeName}',
|
|
507
|
-
protocol: '${protocol.key}',
|
|
508
|
-
code: JSON.parse(\`${JSON.stringify(parsedContract)}\`)
|
|
509
|
-
};
|
|
510
|
-
`;
|
|
511
|
-
return {
|
|
512
|
-
typesFileContent: typesFileContent,
|
|
513
|
-
contractCodeFileContent: contractCodeFileContent,
|
|
514
|
-
storage: storageCode,
|
|
515
|
-
methods: methodsCode,
|
|
516
|
-
methodsObject: methodsObjectCode
|
|
517
|
-
};
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
const $38088c948e5b4cf5$var$parseContractWithMinimalProtocolLevel = (contractScript, format, contractLevelIndex)=>{
|
|
522
|
-
const contractLevels = [
|
|
523
|
-
{
|
|
524
|
-
name: "PsDELPH1",
|
|
525
|
-
key: $3ymtt$taquitomichelcodec.Protocol.PsDELPH1
|
|
526
|
-
},
|
|
527
|
-
{
|
|
528
|
-
name: "PtEdo2Zk",
|
|
529
|
-
key: $3ymtt$taquitomichelcodec.Protocol.PtEdo2Zk
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
name: "PsFLorena",
|
|
533
|
-
key: $3ymtt$taquitomichelcodec.Protocol.PsFLorena
|
|
534
|
-
},
|
|
535
|
-
];
|
|
536
|
-
const protocol = contractLevels[contractLevelIndex];
|
|
537
|
-
if (!protocol) throw new (0, $901f5cf476ef87a5$export$d214d56e7a53a664)(`Could not parse contract script`, contractScript);
|
|
538
|
-
const p = new $3ymtt$taquitomichelcodec.Parser({
|
|
539
|
-
protocol: protocol.key
|
|
540
|
-
});
|
|
541
|
-
try {
|
|
542
|
-
const contract = format === "tz" ? p.parseScript(contractScript) : p.parseJSON(JSON.parse(contractScript));
|
|
543
|
-
if (contract) return {
|
|
544
|
-
contract: contract,
|
|
545
|
-
protocol: protocol
|
|
546
|
-
};
|
|
547
|
-
} catch {
|
|
548
|
-
// Ignore parse errors
|
|
549
|
-
}
|
|
550
|
-
// Try again with next level
|
|
551
|
-
return $38088c948e5b4cf5$var$parseContractWithMinimalProtocolLevel(contractScript, format, contractLevelIndex + 1);
|
|
552
|
-
};
|
|
553
|
-
const $38088c948e5b4cf5$export$adc4e820bbd3332 = (contractScript, contractName, format, typeAliasData, typeUtilsData)=>{
|
|
554
|
-
const p = new $3ymtt$taquitomichelcodec.Parser({
|
|
555
|
-
protocol: $3ymtt$taquitomichelcodec.Protocol.PsFLorena
|
|
556
|
-
});
|
|
557
|
-
const { contract: contract , protocol: protocol } = $38088c948e5b4cf5$var$parseContractWithMinimalProtocolLevel(contractScript, format, 0);
|
|
558
|
-
const contractStorage = contract.find((x)=>x.prim === `storage`);
|
|
559
|
-
const contractParameter = contract.find((x)=>x.prim === `parameter`);
|
|
560
|
-
const storageResult = contractStorage && (0, $b95e97a0bb3bf047$export$cc65da7b09dcddd7)(contractStorage);
|
|
561
|
-
const storage = storageResult ?? {
|
|
562
|
-
storage: {
|
|
563
|
-
kind: `object`,
|
|
564
|
-
raw: {
|
|
565
|
-
prim: `never`
|
|
566
|
-
},
|
|
567
|
-
fields: []
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
const parameterResult = contractParameter && (0, $b95e97a0bb3bf047$export$5c00959a6ba200c1)(contractParameter);
|
|
571
|
-
const methods = parameterResult?.methods ?? [];
|
|
572
|
-
// If there's only one entrypoint, then we call it "default"
|
|
573
|
-
if (methods.length === 1) methods[0].name = `default`;
|
|
574
|
-
const schemaOutput = (0, $4e7cd4eb63db9934$export$eb0413f5ee90780)(methods, storage);
|
|
575
|
-
const typescriptCode = (0, $8fdd19ff0013f28e$export$d355209543d39bc0)(storage, methods, contractName, contract, protocol, typeAliasData, typeUtilsData);
|
|
576
|
-
return {
|
|
577
|
-
schemaOutput: schemaOutput,
|
|
578
|
-
typescriptCodeOutput: typescriptCode,
|
|
579
|
-
parsedContract: contract,
|
|
580
|
-
minimalProtocol: protocol.key
|
|
581
|
-
};
|
|
582
|
-
};
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
const $7d27ec5ea3b0470e$export$4bf5db15180664ad = `
|
|
586
|
-
import { BigNumber } from 'bignumber.js';
|
|
587
|
-
import { MichelsonMap } from '@taquito/taquito';
|
|
588
|
-
|
|
589
|
-
export type unit = (true | undefined) & { __type: 'unit' };
|
|
590
|
-
|
|
591
|
-
export type address = string & { __type: 'address' };
|
|
592
|
-
export type bytes = string & { __type: 'bytes' };
|
|
593
|
-
export type contract = string & { __type: 'contract' };
|
|
594
|
-
export type operation = string & { __type: 'operation' };
|
|
595
|
-
export type key = string & { __type: 'key' };
|
|
596
|
-
export type key_hash = string & { __type: 'key_hash' };
|
|
597
|
-
export type signature = string & { __type: 'signature' };
|
|
598
|
-
export type ticket = string & { __type: 'ticket' };
|
|
599
|
-
|
|
600
|
-
export type timestamp = string & { __type: 'timestamp' };
|
|
601
|
-
|
|
602
|
-
export type int = BigNumber & { __type: 'int' };
|
|
603
|
-
export type nat = BigNumber & { __type: 'nat' };
|
|
604
|
-
|
|
605
|
-
export type mutez = BigNumber & { __type: 'mutez' };
|
|
606
|
-
export type tez = BigNumber & { __type: 'tez' };
|
|
607
|
-
|
|
608
|
-
type MapKey = Array<any> | object | string | boolean | number;
|
|
609
|
-
export type MMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => V };
|
|
610
|
-
export type BigMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => Promise<V> };
|
|
611
|
-
|
|
612
|
-
export type chest = string & { __type: 'chest' };
|
|
613
|
-
export type chest_key = string & { __type: 'chest_key' };
|
|
614
|
-
|
|
615
|
-
const createStringTypeTas = <T extends string>() => {
|
|
616
|
-
return (value: string): T => value as T;
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
const createBigNumberTypeTas = <T extends BigNumber>() => {
|
|
620
|
-
return (value: number | BigNumber | string): T => new BigNumber(value) as T;
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
type asMapParamOf<K, V> = K extends string ? { [key: string]: V } | Array<{ key: K, value: V }>
|
|
624
|
-
: K extends number ? { [key: number]: V } | Array<{ key: K, value: V }>
|
|
625
|
-
: Array<{ key: K, value: V }>;
|
|
626
|
-
|
|
627
|
-
function asMap<K extends MapKey, V>(value: asMapParamOf<K, V>): MMap<K, V> {
|
|
628
|
-
const m = new MichelsonMap<K, V>();
|
|
629
|
-
if (Array.isArray(value)) {
|
|
630
|
-
const vArray = value as Array<{ key: K, value: V }>;
|
|
631
|
-
vArray.forEach(x => m.set(x.key, x.value));
|
|
632
|
-
} else {
|
|
633
|
-
const vObject = value as { [key: string]: V };
|
|
634
|
-
Object.keys(vObject).forEach(key => m.set(key as unknown as K, vObject[key]));
|
|
635
|
-
}
|
|
636
|
-
return m as MMap<K, V>;
|
|
637
|
-
}
|
|
638
|
-
const asBigMap = <K extends MapKey, V>(value: asMapParamOf<K, V>) => asMap(value) as unknown as BigMap<K, V>;
|
|
639
|
-
|
|
640
|
-
function add<T extends BigNumber>(a: T, b: T): T {
|
|
641
|
-
return a.plus(b) as T;
|
|
642
|
-
}
|
|
643
|
-
function subtract<T extends BigNumber>(a: T, b: T): T {
|
|
644
|
-
return a.minus(b) as T;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
/** tas: Tezos 'as' casting for strict types */
|
|
648
|
-
export const tas = {
|
|
649
|
-
address: createStringTypeTas<address>(),
|
|
650
|
-
bytes: createStringTypeTas<bytes>(),
|
|
651
|
-
contract: createStringTypeTas<contract>(),
|
|
652
|
-
chest: createStringTypeTas<chest>(),
|
|
653
|
-
chest_key: createStringTypeTas<chest_key>(),
|
|
654
|
-
timestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp,
|
|
655
|
-
|
|
656
|
-
int: createBigNumberTypeTas<int>(),
|
|
657
|
-
nat: createBigNumberTypeTas<nat>(),
|
|
658
|
-
mutez: createBigNumberTypeTas<mutez>(),
|
|
659
|
-
tez: createBigNumberTypeTas<tez>(),
|
|
660
|
-
|
|
661
|
-
map: asMap,
|
|
662
|
-
bigMap: asBigMap,
|
|
663
|
-
|
|
664
|
-
// Operations
|
|
665
|
-
add,
|
|
666
|
-
subtract,
|
|
667
|
-
|
|
668
|
-
// To number
|
|
669
|
-
number: (value: string | BigNumber) => Number(value + ''),
|
|
670
|
-
};
|
|
671
|
-
`;
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const $d6317276dd27d471$export$e9cf70f604100ab7 = `
|
|
675
|
-
import { ContractAbstraction, ContractMethod, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';
|
|
676
|
-
|
|
677
|
-
type BaseContractType = { methods: unknown, methodsObject: unknown, storage: unknown };
|
|
678
|
-
|
|
679
|
-
type ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
|
|
680
|
-
[M in keyof TContract['methods']]:
|
|
681
|
-
TContract['methods'][M] extends (...args: infer A) => unknown
|
|
682
|
-
? (...args: A) => ContractMethod<T>
|
|
683
|
-
: never
|
|
684
|
-
};
|
|
685
|
-
type ContractMethodsObjectsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
|
|
686
|
-
[M in keyof TContract['methodsObject']]:
|
|
687
|
-
TContract['methodsObject'][M] extends (...args: infer A) => unknown
|
|
688
|
-
? (...args: A) => ContractMethodObject<T>
|
|
689
|
-
: never
|
|
690
|
-
};
|
|
691
|
-
type ContractStorageOf<TContract extends BaseContractType> = TContract['storage'];
|
|
692
|
-
|
|
693
|
-
export type ContractAbstractionFromContractType<TContract extends BaseContractType> =
|
|
694
|
-
ContractAbstraction<ContractProvider,
|
|
695
|
-
ContractMethodsOf<ContractProvider, TContract>,
|
|
696
|
-
ContractMethodsObjectsOf<ContractProvider, TContract>,
|
|
697
|
-
{},
|
|
698
|
-
{},
|
|
699
|
-
ContractStorageOf<TContract>
|
|
700
|
-
>;
|
|
701
|
-
|
|
702
|
-
export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> =
|
|
703
|
-
ContractAbstraction<Wallet,
|
|
704
|
-
ContractMethodsOf<Wallet, TContract>,
|
|
705
|
-
ContractMethodsObjectsOf<Wallet, TContract>,
|
|
706
|
-
{},
|
|
707
|
-
{},
|
|
708
|
-
ContractStorageOf<TContract>
|
|
709
|
-
>;
|
|
710
|
-
`;
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
const $ce33c3ba360b60b0$var$fs = {
|
|
714
|
-
mkdir: (0, $3ymtt$util.promisify)((0, ($parcel$interopDefault($3ymtt$fs))).mkdir),
|
|
715
|
-
copyFile: (0, $3ymtt$util.promisify)((0, ($parcel$interopDefault($3ymtt$fs))).copyFile),
|
|
716
|
-
readdir: (0, $3ymtt$util.promisify)((0, ($parcel$interopDefault($3ymtt$fs))).readdir),
|
|
717
|
-
readFile: (0, $3ymtt$util.promisify)((0, ($parcel$interopDefault($3ymtt$fs))).readFile),
|
|
718
|
-
writeFile: (0, $3ymtt$util.promisify)((0, ($parcel$interopDefault($3ymtt$fs))).writeFile),
|
|
719
|
-
stat: (0, $3ymtt$util.promisify)((0, ($parcel$interopDefault($3ymtt$fs))).stat),
|
|
720
|
-
exists: (0, ($parcel$interopDefault($3ymtt$fs))).existsSync
|
|
721
|
-
};
|
|
722
|
-
const $ce33c3ba360b60b0$var$getAllFiles = async (rootPath, filter)=>{
|
|
723
|
-
const allFiles = [];
|
|
724
|
-
const getAllFilesRecursive = async (dirPath)=>{
|
|
725
|
-
let files = await $ce33c3ba360b60b0$var$fs.readdir(dirPath, {
|
|
726
|
-
withFileTypes: true
|
|
727
|
-
});
|
|
728
|
-
for (const f of files){
|
|
729
|
-
const subPath = (0, ($parcel$interopDefault($3ymtt$path))).resolve(dirPath, f.name);
|
|
730
|
-
if (f.isDirectory()) {
|
|
731
|
-
await getAllFilesRecursive(subPath);
|
|
732
|
-
continue;
|
|
733
|
-
}
|
|
734
|
-
if (!filter(subPath)) continue;
|
|
735
|
-
allFiles.push(subPath);
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
await getAllFilesRecursive(rootPath);
|
|
739
|
-
return allFiles;
|
|
740
|
-
};
|
|
741
|
-
const $ce33c3ba360b60b0$export$2ab4539ae1119673 = async ({ inputTzContractDirectory: inputTzContractDirectory , inputFiles: inputFiles , outputTypescriptDirectory: outputTypescriptDirectory , format: format , typeAliasMode: typeAliasMode })=>{
|
|
742
|
-
console.log(`Generating Types: ${(0, ($parcel$interopDefault($3ymtt$path))).resolve(inputTzContractDirectory)} => ${(0, ($parcel$interopDefault($3ymtt$path))).resolve(outputTypescriptDirectory)}`);
|
|
743
|
-
const ext = "." + format;
|
|
744
|
-
const filesAll = await $ce33c3ba360b60b0$var$getAllFiles(inputTzContractDirectory, (x)=>x.endsWith(ext));
|
|
745
|
-
const files = inputFiles ? filesAll.filter((f)=>inputFiles.some((inputFile)=>f.endsWith(inputFile))) : filesAll;
|
|
746
|
-
console.log(`Contracts Found: ${[
|
|
747
|
-
``,
|
|
748
|
-
...files
|
|
749
|
-
].join(`\n\t- `)}`);
|
|
750
|
-
const typeAliasImportPath = `@taquito/contract-type-generator`;
|
|
751
|
-
const typeAliasData = typeAliasMode === "local" ? {
|
|
752
|
-
mode: typeAliasMode,
|
|
753
|
-
fileContent: (0, $7d27ec5ea3b0470e$export$4bf5db15180664ad)
|
|
754
|
-
} : typeAliasMode === "file" ? {
|
|
755
|
-
mode: typeAliasMode,
|
|
756
|
-
importPath: `./type-aliases`
|
|
757
|
-
} : typeAliasMode === "library" ? {
|
|
758
|
-
mode: typeAliasMode,
|
|
759
|
-
importPath: typeAliasImportPath
|
|
760
|
-
} : {
|
|
761
|
-
mode: "simple"
|
|
762
|
-
};
|
|
763
|
-
if (typeAliasMode === "file") {
|
|
764
|
-
// Copy the type alias file
|
|
765
|
-
await $ce33c3ba360b60b0$var$fs.mkdir(outputTypescriptDirectory, {
|
|
766
|
-
recursive: true
|
|
767
|
-
});
|
|
768
|
-
await $ce33c3ba360b60b0$var$fs.writeFile((0, ($parcel$interopDefault($3ymtt$path))).join(outputTypescriptDirectory, "./type-aliases.ts"), (0, $7d27ec5ea3b0470e$export$4bf5db15180664ad));
|
|
769
|
-
}
|
|
770
|
-
// Copy the type utils file
|
|
771
|
-
const typeUtilsData = {
|
|
772
|
-
importPath: `./type-utils`
|
|
773
|
-
};
|
|
774
|
-
await $ce33c3ba360b60b0$var$fs.mkdir(outputTypescriptDirectory, {
|
|
775
|
-
recursive: true
|
|
776
|
-
});
|
|
777
|
-
await $ce33c3ba360b60b0$var$fs.writeFile((0, ($parcel$interopDefault($3ymtt$path))).join(outputTypescriptDirectory, "./type-utils.ts"), (0, $d6317276dd27d471$export$e9cf70f604100ab7));
|
|
778
|
-
for (const fullPath of files){
|
|
779
|
-
const fileRelativePath = fullPath.replace((0, ($parcel$interopDefault($3ymtt$path))).resolve(inputTzContractDirectory), "");
|
|
780
|
-
const fileName = fileRelativePath.replace(ext, "");
|
|
781
|
-
const inputFilePath = (0, ($parcel$interopDefault($3ymtt$path))).join(inputTzContractDirectory, fileRelativePath);
|
|
782
|
-
const typesOutputFilePath = (0, ($parcel$interopDefault($3ymtt$path))).join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.types.ts`));
|
|
783
|
-
const codeContentOutputFilePath = (0, ($parcel$interopDefault($3ymtt$path))).join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.code.ts`));
|
|
784
|
-
const schemaContentOutputFilePath = (0, ($parcel$interopDefault($3ymtt$path))).join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.schema.json`));
|
|
785
|
-
console.log(`Processing ${fileRelativePath}...`);
|
|
786
|
-
try {
|
|
787
|
-
const contractTypeName = (0, $3f5c875567479895$export$bd8d1d28710832a7)(fileName);
|
|
788
|
-
const michelsonCode = await $ce33c3ba360b60b0$var$fs.readFile(inputFilePath, {
|
|
789
|
-
encoding: `utf8`
|
|
790
|
-
});
|
|
791
|
-
const { schemaOutput: schemaOutput , typescriptCodeOutput: { typesFileContent: typesFileContent , contractCodeFileContent: contractCodeFileContent } , } = (0, $38088c948e5b4cf5$export$adc4e820bbd3332)(michelsonCode, contractTypeName, format, typeAliasData, typeUtilsData);
|
|
792
|
-
// Write output (ensure dir exists)
|
|
793
|
-
await $ce33c3ba360b60b0$var$fs.mkdir((0, ($parcel$interopDefault($3ymtt$path))).dirname(typesOutputFilePath), {
|
|
794
|
-
recursive: true
|
|
795
|
-
});
|
|
796
|
-
await $ce33c3ba360b60b0$var$fs.writeFile(typesOutputFilePath, typesFileContent);
|
|
797
|
-
await $ce33c3ba360b60b0$var$fs.writeFile(codeContentOutputFilePath, contractCodeFileContent);
|
|
798
|
-
const debugSchema = false;
|
|
799
|
-
if (debugSchema) await $ce33c3ba360b60b0$var$fs.writeFile(schemaContentOutputFilePath, JSON.stringify(schemaOutput, null, 2));
|
|
800
|
-
} catch (err) {
|
|
801
|
-
console.error(`❌ Could not process ${fileRelativePath}`, {
|
|
802
|
-
err: err
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
};
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
const $3beaa6d78a95a243$var$getContractAbspath = (contractFilename, parsedArgs)=>(0, $3ymtt$path.join)(parsedArgs.config.artifactsDir, /\.tz$/.test(contractFilename) ? contractFilename : `${contractFilename}.tz`);
|
|
810
|
-
const $3beaa6d78a95a243$var$generateContractTypes = (parsedArgs)=>async (contractFilename)=>{
|
|
811
|
-
const contractAbspath = $3beaa6d78a95a243$var$getContractAbspath(contractFilename, parsedArgs);
|
|
812
|
-
await (0, $ce33c3ba360b60b0$export$2ab4539ae1119673)({
|
|
813
|
-
inputTzContractDirectory: parsedArgs.config.artifactsDir,
|
|
814
|
-
inputFiles: [
|
|
815
|
-
contractAbspath
|
|
816
|
-
],
|
|
817
|
-
outputTypescriptDirectory: parsedArgs.typescriptDir || "types",
|
|
818
|
-
format: "tz",
|
|
819
|
-
typeAliasMode: parsedArgs.typeAliasMode ?? "file"
|
|
820
|
-
});
|
|
821
|
-
return `${contractFilename}: Types generated`;
|
|
822
|
-
};
|
|
823
|
-
const $3beaa6d78a95a243$var$generateContractTypesAll = async (parsedArgs)=>{
|
|
824
|
-
const files = await (0, ($parcel$interopDefault($3ymtt$fastglob)))("**/*.tz", {
|
|
825
|
-
cwd: parsedArgs.config.artifactsDir
|
|
826
|
-
});
|
|
827
|
-
return await Promise.all(files.map($3beaa6d78a95a243$var$generateContractTypes(parsedArgs)));
|
|
828
|
-
};
|
|
829
|
-
const $3beaa6d78a95a243$export$3350b7b754d5c00c = (parsedArgs)=>{
|
|
830
|
-
parsedArgs.typescriptDir = parsedArgs.typescriptDir || "types";
|
|
831
|
-
console.log("generateTypes", {
|
|
832
|
-
typescriptDir: parsedArgs.typescriptDir
|
|
833
|
-
});
|
|
834
|
-
const p = parsedArgs.contract ? $3beaa6d78a95a243$var$generateContractTypes(parsedArgs)(parsedArgs.contract) : $3beaa6d78a95a243$var$generateContractTypesAll(parsedArgs);
|
|
835
|
-
return p.then((data)=>{
|
|
836
|
-
console.log(Array.isArray(data) ? data.join("\n") : data);
|
|
837
|
-
});
|
|
838
|
-
};
|
|
839
|
-
const $3beaa6d78a95a243$export$7191f9b9098a3ea4 = {
|
|
840
|
-
generateTypes: $3beaa6d78a95a243$export$3350b7b754d5c00c
|
|
841
|
-
};
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
(0, $3ymtt$taquerianodesdk.Plugin).create((i18n)=>({
|
|
845
|
-
alias: "contract-types",
|
|
846
|
-
schema: "1.0",
|
|
847
|
-
version: "0.1",
|
|
848
|
-
tasks: [
|
|
849
|
-
(0, $3ymtt$taquerianodesdk.Task).create({
|
|
850
|
-
task: "generate types",
|
|
851
|
-
command: "generate types [typescriptDir]",
|
|
852
|
-
description: "Generate types for a contract to be used with taquito",
|
|
853
|
-
positionals: [
|
|
854
|
-
(0, $3ymtt$taquerianodesdk.PositionalArg).create({
|
|
855
|
-
placeholder: "typescriptDir",
|
|
856
|
-
description: "The output directory for the generated type files",
|
|
857
|
-
defaultValue: "types"
|
|
858
|
-
}),
|
|
859
|
-
],
|
|
860
|
-
options: [
|
|
861
|
-
(0, $3ymtt$taquerianodesdk.Option).create({
|
|
862
|
-
shortFlag: "t",
|
|
863
|
-
flag: "typeAliasMode",
|
|
864
|
-
choices: [
|
|
865
|
-
"file",
|
|
866
|
-
"simple"
|
|
867
|
-
],
|
|
868
|
-
description: "The type aliases used in the generated types"
|
|
869
|
-
}),
|
|
870
|
-
],
|
|
871
|
-
aliases: [
|
|
872
|
-
"gen types",
|
|
873
|
-
"gentypes"
|
|
874
|
-
],
|
|
875
|
-
handler: "proxy"
|
|
876
|
-
}),
|
|
877
|
-
],
|
|
878
|
-
proxy: (0, $3beaa6d78a95a243$export$7191f9b9098a3ea4).generateTypes
|
|
879
|
-
}), process.argv);
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import {
|
|
2
|
+
generateContractTypesProcessContractFiles
|
|
3
|
+
} from "./chunk-QSIV2OJS.js";
|
|
4
|
+
import "./chunk-T4SGVAIL.js";
|
|
5
|
+
|
|
6
|
+
// index.ts
|
|
7
|
+
import { Option, Plugin, PositionalArg, Task } from "@taqueria/node-sdk";
|
|
8
|
+
|
|
9
|
+
// tasks.ts
|
|
10
|
+
import glob from "fast-glob";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
var getContractAbspath = (contractFilename, parsedArgs) => join(parsedArgs.config.artifactsDir, /\.tz$/.test(contractFilename) ? contractFilename : `${contractFilename}.tz`);
|
|
13
|
+
var generateContractTypes = (parsedArgs) => async (contractFilename) => {
|
|
14
|
+
const contractAbspath = getContractAbspath(contractFilename, parsedArgs);
|
|
15
|
+
await generateContractTypesProcessContractFiles({
|
|
16
|
+
inputTzContractDirectory: parsedArgs.config.artifactsDir,
|
|
17
|
+
inputFiles: [contractAbspath],
|
|
18
|
+
outputTypescriptDirectory: parsedArgs.typescriptDir || "types",
|
|
19
|
+
format: "tz",
|
|
20
|
+
typeAliasMode: parsedArgs.typeAliasMode ?? "file"
|
|
21
|
+
});
|
|
22
|
+
return `${contractFilename}: Types generated`;
|
|
23
|
+
};
|
|
24
|
+
var generateContractTypesAll = async (parsedArgs) => {
|
|
25
|
+
const files = await glob("**/*.tz", { cwd: parsedArgs.config.artifactsDir });
|
|
26
|
+
return await Promise.all(files.map(generateContractTypes(parsedArgs)));
|
|
27
|
+
};
|
|
28
|
+
var generateTypes = (parsedArgs) => {
|
|
29
|
+
parsedArgs.typescriptDir = parsedArgs.typescriptDir || "types";
|
|
30
|
+
console.log("generateTypes", {
|
|
31
|
+
typescriptDir: parsedArgs.typescriptDir
|
|
32
|
+
});
|
|
33
|
+
const p = parsedArgs.contract ? generateContractTypes(parsedArgs)(parsedArgs.contract) : generateContractTypesAll(parsedArgs);
|
|
34
|
+
return p.then((data) => {
|
|
35
|
+
console.log(
|
|
36
|
+
Array.isArray(data) ? data.join("\n") : data
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var tasks = {
|
|
41
|
+
generateTypes
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// index.ts
|
|
45
|
+
Plugin.create((i18n) => ({
|
|
46
|
+
alias: "contract-types",
|
|
47
|
+
schema: "1.0",
|
|
48
|
+
version: "0.1",
|
|
49
|
+
tasks: [
|
|
50
|
+
Task.create({
|
|
51
|
+
task: "generate types",
|
|
52
|
+
command: "generate types [typescriptDir]",
|
|
53
|
+
description: "Generate types for a contract to be used with taquito",
|
|
54
|
+
positionals: [
|
|
55
|
+
PositionalArg.create({
|
|
56
|
+
placeholder: "typescriptDir",
|
|
57
|
+
description: "The output directory for the generated type files",
|
|
58
|
+
defaultValue: "types"
|
|
59
|
+
})
|
|
60
|
+
],
|
|
61
|
+
options: [
|
|
62
|
+
Option.create({
|
|
63
|
+
shortFlag: "t",
|
|
64
|
+
flag: "typeAliasMode",
|
|
65
|
+
choices: ["file", "simple"],
|
|
66
|
+
description: "The type aliases used in the generated types"
|
|
67
|
+
})
|
|
68
|
+
],
|
|
69
|
+
aliases: ["gen types", "gentypes"],
|
|
70
|
+
handler: "proxy"
|
|
71
|
+
})
|
|
72
|
+
],
|
|
73
|
+
proxy: tasks.generateTypes
|
|
74
|
+
}), process.argv);
|
|
75
|
+
export {
|
|
76
|
+
generateContractTypesProcessContractFiles
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=index.js.map
|