@taqueria/plugin-contract-types 0.8.3 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunk-GC2KSB5D.js +226 -0
- package/chunk-GC2KSB5D.js.map +1 -0
- package/chunk-T4SGVAIL.js +604 -0
- package/chunk-T4SGVAIL.js.map +1 -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/type-aliases.ts +4 -0
- package/index.cjs +920 -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 +27 -12
- package/src/cli-process.cjs +848 -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/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/taqueria-plugin-contract-types-0.12.0.tgz +0 -0
- package/tsconfig.json +4 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateContractTypesFromMichelsonCode,
|
|
3
|
+
normalizeContractName
|
|
4
|
+
} from "./chunk-T4SGVAIL.js";
|
|
5
|
+
|
|
6
|
+
// src/cli-process.ts
|
|
7
|
+
import fsRaw from "fs";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { promisify } from "util";
|
|
10
|
+
|
|
11
|
+
// src/type-aliases-file-content.ts
|
|
12
|
+
var typeAliasesFileContent = `
|
|
13
|
+
import { BigNumber } from 'bignumber.js';
|
|
14
|
+
import { MichelsonMap } from '@taquito/taquito';
|
|
15
|
+
|
|
16
|
+
export type unit = (true | undefined) & { __type: 'unit' };
|
|
17
|
+
|
|
18
|
+
export type address = string & { __type: 'address' };
|
|
19
|
+
export type bytes = string & { __type: 'bytes' };
|
|
20
|
+
export type contract = string & { __type: 'contract' };
|
|
21
|
+
export type operation = string & { __type: 'operation' };
|
|
22
|
+
export type key = string & { __type: 'key' };
|
|
23
|
+
export type key_hash = string & { __type: 'key_hash' };
|
|
24
|
+
export type signature = string & { __type: 'signature' };
|
|
25
|
+
export type ticket = string & { __type: 'ticket' };
|
|
26
|
+
|
|
27
|
+
export type timestamp = string & { __type: 'timestamp' };
|
|
28
|
+
|
|
29
|
+
export type int = BigNumber & { __type: 'int' };
|
|
30
|
+
export type nat = BigNumber & { __type: 'nat' };
|
|
31
|
+
|
|
32
|
+
export type mutez = BigNumber & { __type: 'mutez' };
|
|
33
|
+
export type tez = BigNumber & { __type: 'tez' };
|
|
34
|
+
|
|
35
|
+
type MapKey = Array<any> | object | string | boolean | number;
|
|
36
|
+
export type MMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => V };
|
|
37
|
+
export type BigMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => Promise<V> };
|
|
38
|
+
|
|
39
|
+
export type chest = string & { __type: 'chest' };
|
|
40
|
+
export type chest_key = string & { __type: 'chest_key' };
|
|
41
|
+
|
|
42
|
+
const createStringTypeTas = <T extends string>() => {
|
|
43
|
+
return (value: string): T => value as T;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const createBigNumberTypeTas = <T extends BigNumber>() => {
|
|
47
|
+
return (value: number | BigNumber | string): T => new BigNumber(value) as T;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type asMapParamOf<K, V> = K extends string ? { [key: string]: V } | Array<{ key: K, value: V }>
|
|
51
|
+
: K extends number ? { [key: number]: V } | Array<{ key: K, value: V }>
|
|
52
|
+
: Array<{ key: K, value: V }>;
|
|
53
|
+
|
|
54
|
+
function asMap<K extends MapKey, V>(value: asMapParamOf<K, V>): MMap<K, V> {
|
|
55
|
+
const m = new MichelsonMap<K, V>();
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
const vArray = value as Array<{ key: K, value: V }>;
|
|
58
|
+
vArray.forEach(x => m.set(x.key, x.value));
|
|
59
|
+
} else {
|
|
60
|
+
const vObject = value as { [key: string]: V };
|
|
61
|
+
Object.keys(vObject).forEach(key => m.set(key as unknown as K, vObject[key]));
|
|
62
|
+
}
|
|
63
|
+
return m as MMap<K, V>;
|
|
64
|
+
}
|
|
65
|
+
const asBigMap = <K extends MapKey, V>(value: asMapParamOf<K, V>) => asMap(value) as unknown as BigMap<K, V>;
|
|
66
|
+
|
|
67
|
+
function add<T extends BigNumber>(a: T, b: T): T {
|
|
68
|
+
return a.plus(b) as T;
|
|
69
|
+
}
|
|
70
|
+
function subtract<T extends BigNumber>(a: T, b: T): T {
|
|
71
|
+
return a.minus(b) as T;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** tas: Tezos 'as' casting for strict types */
|
|
75
|
+
export const tas = {
|
|
76
|
+
address: createStringTypeTas<address>(),
|
|
77
|
+
bytes: createStringTypeTas<bytes>(),
|
|
78
|
+
contract: createStringTypeTas<contract>(),
|
|
79
|
+
chest: createStringTypeTas<chest>(),
|
|
80
|
+
chest_key: createStringTypeTas<chest_key>(),
|
|
81
|
+
timestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp,
|
|
82
|
+
|
|
83
|
+
int: createBigNumberTypeTas<int>(),
|
|
84
|
+
nat: createBigNumberTypeTas<nat>(),
|
|
85
|
+
mutez: createBigNumberTypeTas<mutez>(),
|
|
86
|
+
tez: createBigNumberTypeTas<tez>(),
|
|
87
|
+
|
|
88
|
+
map: asMap,
|
|
89
|
+
bigMap: asBigMap,
|
|
90
|
+
|
|
91
|
+
// Operations
|
|
92
|
+
add,
|
|
93
|
+
subtract,
|
|
94
|
+
|
|
95
|
+
// To number
|
|
96
|
+
number: (value: string | BigNumber) => Number(value + ''),
|
|
97
|
+
};
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
// src/type-utils-file-content.ts
|
|
101
|
+
var typeUtilsFileContent = `
|
|
102
|
+
import { ContractAbstraction, ContractMethod, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';
|
|
103
|
+
|
|
104
|
+
type BaseContractType = { methods: unknown, methodsObject: unknown, storage: unknown };
|
|
105
|
+
|
|
106
|
+
type ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
|
|
107
|
+
[M in keyof TContract['methods']]:
|
|
108
|
+
TContract['methods'][M] extends (...args: infer A) => unknown
|
|
109
|
+
? (...args: A) => ContractMethod<T>
|
|
110
|
+
: never
|
|
111
|
+
};
|
|
112
|
+
type ContractMethodsObjectsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
|
|
113
|
+
[M in keyof TContract['methodsObject']]:
|
|
114
|
+
TContract['methodsObject'][M] extends (...args: infer A) => unknown
|
|
115
|
+
? (...args: A) => ContractMethodObject<T>
|
|
116
|
+
: never
|
|
117
|
+
};
|
|
118
|
+
type ContractStorageOf<TContract extends BaseContractType> = TContract['storage'];
|
|
119
|
+
|
|
120
|
+
export type ContractAbstractionFromContractType<TContract extends BaseContractType> =
|
|
121
|
+
ContractAbstraction<ContractProvider,
|
|
122
|
+
ContractMethodsOf<ContractProvider, TContract>,
|
|
123
|
+
ContractMethodsObjectsOf<ContractProvider, TContract>,
|
|
124
|
+
{},
|
|
125
|
+
{},
|
|
126
|
+
ContractStorageOf<TContract>
|
|
127
|
+
>;
|
|
128
|
+
|
|
129
|
+
export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> =
|
|
130
|
+
ContractAbstraction<Wallet,
|
|
131
|
+
ContractMethodsOf<Wallet, TContract>,
|
|
132
|
+
ContractMethodsObjectsOf<Wallet, TContract>,
|
|
133
|
+
{},
|
|
134
|
+
{},
|
|
135
|
+
ContractStorageOf<TContract>
|
|
136
|
+
>;
|
|
137
|
+
`;
|
|
138
|
+
|
|
139
|
+
// src/cli-process.ts
|
|
140
|
+
var fs = {
|
|
141
|
+
mkdir: promisify(fsRaw.mkdir),
|
|
142
|
+
copyFile: promisify(fsRaw.copyFile),
|
|
143
|
+
readdir: promisify(fsRaw.readdir),
|
|
144
|
+
readFile: promisify(fsRaw.readFile),
|
|
145
|
+
writeFile: promisify(fsRaw.writeFile),
|
|
146
|
+
stat: promisify(fsRaw.stat),
|
|
147
|
+
exists: fsRaw.existsSync
|
|
148
|
+
};
|
|
149
|
+
var getAllFiles = async (rootPath, filter) => {
|
|
150
|
+
const allFiles = [];
|
|
151
|
+
const getAllFilesRecursive = async (dirPath) => {
|
|
152
|
+
let files = await fs.readdir(dirPath, { withFileTypes: true });
|
|
153
|
+
for (const f of files) {
|
|
154
|
+
const subPath = path.resolve(dirPath, f.name);
|
|
155
|
+
if (f.isDirectory()) {
|
|
156
|
+
await getAllFilesRecursive(subPath);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (!filter(subPath)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
allFiles.push(subPath);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
await getAllFilesRecursive(rootPath);
|
|
166
|
+
return allFiles;
|
|
167
|
+
};
|
|
168
|
+
var generateContractTypesProcessContractFiles = async ({
|
|
169
|
+
inputTzContractDirectory,
|
|
170
|
+
inputFiles,
|
|
171
|
+
outputTypescriptDirectory,
|
|
172
|
+
format,
|
|
173
|
+
typeAliasMode
|
|
174
|
+
}) => {
|
|
175
|
+
console.log(
|
|
176
|
+
`Generating Types: ${path.resolve(inputTzContractDirectory)} => ${path.resolve(outputTypescriptDirectory)}`
|
|
177
|
+
);
|
|
178
|
+
const ext = "." + format;
|
|
179
|
+
const filesAll = await getAllFiles(inputTzContractDirectory, (x) => x.endsWith(ext));
|
|
180
|
+
const files = inputFiles ? filesAll.filter((f) => inputFiles.some((inputFile) => f.endsWith(inputFile))) : filesAll;
|
|
181
|
+
console.log(`Contracts Found: ${[``, ...files].join(`
|
|
182
|
+
- `)}`);
|
|
183
|
+
const typeAliasImportPath = `@taquito/contract-type-generator`;
|
|
184
|
+
const typeAliasData = typeAliasMode === "local" ? { mode: typeAliasMode, fileContent: typeAliasesFileContent } : typeAliasMode === "file" ? { mode: typeAliasMode, importPath: `./type-aliases` } : typeAliasMode === "library" ? { mode: typeAliasMode, importPath: typeAliasImportPath } : { mode: "simple" };
|
|
185
|
+
if (typeAliasMode === "file") {
|
|
186
|
+
await fs.mkdir(outputTypescriptDirectory, { recursive: true });
|
|
187
|
+
await fs.writeFile(path.join(outputTypescriptDirectory, "./type-aliases.ts"), typeAliasesFileContent);
|
|
188
|
+
}
|
|
189
|
+
const typeUtilsData = { importPath: `./type-utils` };
|
|
190
|
+
await fs.mkdir(outputTypescriptDirectory, { recursive: true });
|
|
191
|
+
await fs.writeFile(path.join(outputTypescriptDirectory, "./type-utils.ts"), typeUtilsFileContent);
|
|
192
|
+
for (const fullPath of files) {
|
|
193
|
+
const fileRelativePath = fullPath.replace(path.resolve(inputTzContractDirectory), "");
|
|
194
|
+
const fileName = fileRelativePath.replace(ext, "");
|
|
195
|
+
const inputFilePath = path.join(inputTzContractDirectory, fileRelativePath);
|
|
196
|
+
const typesOutputFilePath = path.join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.types.ts`));
|
|
197
|
+
const codeContentOutputFilePath = path.join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.code.ts`));
|
|
198
|
+
const schemaContentOutputFilePath = path.join(
|
|
199
|
+
outputTypescriptDirectory,
|
|
200
|
+
fileRelativePath.replace(ext, `.schema.json`)
|
|
201
|
+
);
|
|
202
|
+
console.log(`Processing ${fileRelativePath}...`);
|
|
203
|
+
try {
|
|
204
|
+
const contractTypeName = normalizeContractName(fileName);
|
|
205
|
+
const michelsonCode = await fs.readFile(inputFilePath, { encoding: `utf8` });
|
|
206
|
+
const {
|
|
207
|
+
schemaOutput,
|
|
208
|
+
typescriptCodeOutput: { typesFileContent, contractCodeFileContent }
|
|
209
|
+
} = generateContractTypesFromMichelsonCode(michelsonCode, contractTypeName, format, typeAliasData, typeUtilsData);
|
|
210
|
+
await fs.mkdir(path.dirname(typesOutputFilePath), { recursive: true });
|
|
211
|
+
await fs.writeFile(typesOutputFilePath, typesFileContent);
|
|
212
|
+
await fs.writeFile(codeContentOutputFilePath, contractCodeFileContent);
|
|
213
|
+
const debugSchema = false;
|
|
214
|
+
if (debugSchema) {
|
|
215
|
+
await fs.writeFile(schemaContentOutputFilePath, JSON.stringify(schemaOutput, null, 2));
|
|
216
|
+
}
|
|
217
|
+
} catch (err) {
|
|
218
|
+
console.error(`\u274C Could not process ${fileRelativePath}`, { err });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export {
|
|
224
|
+
generateContractTypesProcessContractFiles
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=chunk-GC2KSB5D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["src/cli-process.ts","src/type-aliases-file-content.ts","src/type-utils-file-content.ts"],"sourcesContent":["import fsRaw from 'fs';\nimport path from 'path';\nimport { promisify } from 'util';\nimport { normalizeContractName } from './generator/contract-name';\nimport { generateContractTypesFromMichelsonCode } from './generator/process';\nimport { TypeAliasData, TypeUtilsData } from './generator/typescript-output';\nimport { typeAliasesFileContent } from './type-aliases-file-content';\nimport { typeUtilsFileContent } from './type-utils-file-content';\n\nconst fs = {\n\tmkdir: promisify(fsRaw.mkdir),\n\tcopyFile: promisify(fsRaw.copyFile),\n\treaddir: promisify(fsRaw.readdir),\n\treadFile: promisify(fsRaw.readFile),\n\twriteFile: promisify(fsRaw.writeFile),\n\tstat: promisify(fsRaw.stat),\n\texists: fsRaw.existsSync,\n};\n\nconst getAllFiles = async (rootPath: string, filter: (fullPath: string) => boolean): Promise<string[]> => {\n\tconst allFiles = [] as string[];\n\n\tconst getAllFilesRecursive = async (dirPath: string) => {\n\t\tlet files = await fs.readdir(dirPath, { withFileTypes: true });\n\n\t\tfor (const f of files) {\n\t\t\tconst subPath = path.resolve(dirPath, f.name);\n\n\t\t\tif (f.isDirectory()) {\n\t\t\t\tawait getAllFilesRecursive(subPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!filter(subPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tallFiles.push(subPath);\n\t\t}\n\t};\n\n\tawait getAllFilesRecursive(rootPath);\n\treturn allFiles;\n};\n\nexport const generateContractTypesProcessContractFiles = async ({\n\tinputTzContractDirectory,\n\tinputFiles,\n\toutputTypescriptDirectory,\n\tformat,\n\ttypeAliasMode,\n}: {\n\tinputTzContractDirectory: string;\n\tinputFiles?: string[];\n\toutputTypescriptDirectory: string;\n\tformat: 'tz' | 'json';\n\ttypeAliasMode: 'local' | 'file' | 'library' | 'simple';\n}): Promise<void> => {\n\tconsole.log(\n\t\t`Generating Types: ${path.resolve(inputTzContractDirectory)} => ${path.resolve(outputTypescriptDirectory)}`,\n\t);\n\n\tconst ext = '.' + format;\n\tconst filesAll = await getAllFiles(inputTzContractDirectory, x => x.endsWith(ext));\n\tconst files = inputFiles ? filesAll.filter(f => inputFiles.some(inputFile => f.endsWith(inputFile))) : filesAll;\n\n\tconsole.log(`Contracts Found: ${[``, ...files].join(`\\n\\t- `)}`);\n\n\tconst typeAliasImportPath = `@taquito/contract-type-generator`;\n\n\tconst typeAliasData: TypeAliasData = typeAliasMode === 'local'\n\t\t? { mode: typeAliasMode, fileContent: typeAliasesFileContent }\n\t\t: typeAliasMode === 'file'\n\t\t? { mode: typeAliasMode, importPath: `./type-aliases` }\n\t\t: typeAliasMode === 'library'\n\t\t? { mode: typeAliasMode, importPath: typeAliasImportPath }\n\t\t: { mode: 'simple' };\n\n\tif (typeAliasMode === 'file') {\n\t\t// Copy the type alias file\n\t\tawait fs.mkdir(outputTypescriptDirectory, { recursive: true });\n\t\tawait fs.writeFile(path.join(outputTypescriptDirectory, './type-aliases.ts'), typeAliasesFileContent);\n\t}\n\n\t// Copy the type utils file\n\tconst typeUtilsData: TypeUtilsData = { importPath: `./type-utils` };\n\tawait fs.mkdir(outputTypescriptDirectory, { recursive: true });\n\tawait fs.writeFile(path.join(outputTypescriptDirectory, './type-utils.ts'), typeUtilsFileContent);\n\n\tfor (const fullPath of files) {\n\t\tconst fileRelativePath = fullPath.replace(path.resolve(inputTzContractDirectory), '');\n\t\tconst fileName = fileRelativePath.replace(ext, '');\n\t\tconst inputFilePath = path.join(inputTzContractDirectory, fileRelativePath);\n\t\tconst typesOutputFilePath = path.join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.types.ts`));\n\t\tconst codeContentOutputFilePath = path.join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.code.ts`));\n\t\tconst schemaContentOutputFilePath = path.join(\n\t\t\toutputTypescriptDirectory,\n\t\t\tfileRelativePath.replace(ext, `.schema.json`),\n\t\t);\n\t\tconsole.log(`Processing ${fileRelativePath}...`);\n\n\t\ttry {\n\t\t\tconst contractTypeName = normalizeContractName(fileName);\n\n\t\t\tconst michelsonCode = await fs.readFile(inputFilePath, { encoding: `utf8` });\n\n\t\t\tconst {\n\t\t\t\tschemaOutput,\n\t\t\t\ttypescriptCodeOutput: { typesFileContent, contractCodeFileContent },\n\t\t\t} = generateContractTypesFromMichelsonCode(michelsonCode, contractTypeName, format, typeAliasData, typeUtilsData);\n\n\t\t\t// Write output (ensure dir exists)\n\t\t\tawait fs.mkdir(path.dirname(typesOutputFilePath), { recursive: true });\n\t\t\tawait fs.writeFile(typesOutputFilePath, typesFileContent);\n\t\t\tawait fs.writeFile(codeContentOutputFilePath, contractCodeFileContent);\n\n\t\t\tconst debugSchema = false;\n\t\t\tif (debugSchema) {\n\t\t\t\tawait fs.writeFile(schemaContentOutputFilePath, JSON.stringify(schemaOutput, null, 2));\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconsole.error(`❌ Could not process ${fileRelativePath}`, { err });\n\t\t}\n\t}\n};\n","// This is required for copying the type aliases to a local file\nexport const typeAliasesFileContent = `\nimport { BigNumber } from 'bignumber.js';\nimport { MichelsonMap } from '@taquito/taquito';\n\nexport type unit = (true | undefined) & { __type: 'unit' };\n\nexport type address = string & { __type: 'address' };\nexport type bytes = string & { __type: 'bytes' };\nexport type contract = string & { __type: 'contract' };\nexport type operation = string & { __type: 'operation' };\nexport type key = string & { __type: 'key' };\nexport type key_hash = string & { __type: 'key_hash' };\nexport type signature = string & { __type: 'signature' };\nexport type ticket = string & { __type: 'ticket' };\n\nexport type timestamp = string & { __type: 'timestamp' };\n\nexport type int = BigNumber & { __type: 'int' };\nexport type nat = BigNumber & { __type: 'nat' };\n\nexport type mutez = BigNumber & { __type: 'mutez' };\nexport type tez = BigNumber & { __type: 'tez' };\n\ntype MapKey = Array<any> | object | string | boolean | number;\nexport type MMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => V };\nexport type BigMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => Promise<V> };\n\nexport type chest = string & { __type: 'chest' };\nexport type chest_key = string & { __type: 'chest_key' };\n\nconst createStringTypeTas = <T extends string>() => {\n return (value: string): T => value as T;\n};\n\nconst createBigNumberTypeTas = <T extends BigNumber>() => {\n return (value: number | BigNumber | string): T => new BigNumber(value) as T;\n};\n\ntype asMapParamOf<K, V> = K extends string ? { [key: string]: V } | Array<{ key: K, value: V }>\n : K extends number ? { [key: number]: V } | Array<{ key: K, value: V }>\n : Array<{ key: K, value: V }>;\n\nfunction asMap<K extends MapKey, V>(value: asMapParamOf<K, V>): MMap<K, V> {\n const m = new MichelsonMap<K, V>();\n if (Array.isArray(value)) {\n const vArray = value as Array<{ key: K, value: V }>;\n vArray.forEach(x => m.set(x.key, x.value));\n } else {\n const vObject = value as { [key: string]: V };\n Object.keys(vObject).forEach(key => m.set(key as unknown as K, vObject[key]));\n }\n return m as MMap<K, V>;\n}\nconst asBigMap = <K extends MapKey, V>(value: asMapParamOf<K, V>) => asMap(value) as unknown as BigMap<K, V>;\n\nfunction add<T extends BigNumber>(a: T, b: T): T {\n return a.plus(b) as T;\n}\nfunction subtract<T extends BigNumber>(a: T, b: T): T {\n return a.minus(b) as T;\n}\n\n/** tas: Tezos 'as' casting for strict types */\nexport const tas = {\n address: createStringTypeTas<address>(),\n bytes: createStringTypeTas<bytes>(),\n contract: createStringTypeTas<contract>(),\n chest: createStringTypeTas<chest>(),\n chest_key: createStringTypeTas<chest_key>(),\n timestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp,\n\n int: createBigNumberTypeTas<int>(),\n nat: createBigNumberTypeTas<nat>(),\n mutez: createBigNumberTypeTas<mutez>(),\n tez: createBigNumberTypeTas<tez>(),\n\n map: asMap,\n bigMap: asBigMap,\n\n // Operations\n add,\n subtract,\n\n // To number\n number: (value: string | BigNumber) => Number(value + ''),\n};\n`;\n","// This is required for copying the type utils to a local file\nexport const typeUtilsFileContent = `\nimport { ContractAbstraction, ContractMethod, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';\n\ntype BaseContractType = { methods: unknown, methodsObject: unknown, storage: unknown };\n\ntype ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {\n[M in keyof TContract['methods']]:\nTContract['methods'][M] extends (...args: infer A) => unknown\n? (...args: A) => ContractMethod<T>\n: never\n};\ntype ContractMethodsObjectsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {\n[M in keyof TContract['methodsObject']]:\nTContract['methodsObject'][M] extends (...args: infer A) => unknown\n? (...args: A) => ContractMethodObject<T>\n: never\n};\ntype ContractStorageOf<TContract extends BaseContractType> = TContract['storage'];\n\nexport type ContractAbstractionFromContractType<TContract extends BaseContractType> = \n ContractAbstraction<ContractProvider, \n ContractMethodsOf<ContractProvider, TContract>,\n ContractMethodsObjectsOf<ContractProvider, TContract>,\n {},\n {},\n ContractStorageOf<TContract>\n >;\n\nexport type WalletContractAbstractionFromContractType<TContract extends BaseContractType> = \n ContractAbstraction<Wallet, \n ContractMethodsOf<Wallet, TContract>,\n ContractMethodsObjectsOf<Wallet, TContract>,\n {},\n {},\n ContractStorageOf<TContract>\n >;\n`;\n"],"mappings":";;;;;;AAAA,OAAO,WAAW;AAClB,OAAO,UAAU;AACjB,SAAS,iBAAiB;;;ACDnB,IAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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