@taqueria/plugin-contract-types 0.3.0 → 0.4.0-rc2

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.
@@ -1,210 +1,246 @@
1
1
  import { assertExhaustive, GenerateApiError, reduceFlatMap } from './common';
2
- import { TypedStorage, TypedMethod, TypedType, TypedVar } from './contract-parser';
2
+ import { TypedMethod, TypedStorage, TypedType, TypedVar } from './contract-parser';
3
3
 
4
4
  export type TypescriptCodeOutput = {
5
- typesFileContent: string;
6
- contractCodeFileContent: string;
7
- storage: string;
8
- methods: string;
9
- methodsObject: string;
5
+ typesFileContent: string;
6
+ contractCodeFileContent: string;
7
+ storage: string;
8
+ methods: string;
9
+ methodsObject: string;
10
10
  };
11
11
 
12
12
  export type TypeAliasData = {
13
- mode: 'local',
14
- fileContent?: string,
13
+ mode: 'local';
14
+ fileContent?: string;
15
15
  } | {
16
- mode: 'file' | 'library',
17
- importPath?: string,
16
+ mode: 'file' | 'library';
17
+ importPath?: string;
18
18
  } | {
19
- mode: 'simple',
19
+ mode: 'simple';
20
20
  };
21
21
  export type TypeUtilsData = {
22
- importPath: string,
22
+ importPath: string;
23
23
  };
24
24
 
25
- export const toTypescriptCode = (storage: TypedStorage, methods: TypedMethod[], contractName: string, parsedContract: unknown, protocol: { name: string, key: string }, typeAliasData: TypeAliasData, typeUtilsData: TypeUtilsData): TypescriptCodeOutput => {
26
- type TypeAlias = { aliasType: string, simpleTypeDefinition: string, simpleTypeImports?: { name: string, isDefault?: boolean, from: string }[] };
27
- const usedStrictTypes = [] as TypeAlias[];
28
- const addTypeAlias = (strictType: TypeAlias) => {
29
- if (!usedStrictTypes.some(x => x.aliasType === strictType.aliasType)) {
30
- usedStrictTypes.push(strictType);
31
- }
32
- };
33
-
34
- // Not really tabs :)
35
- const tabs = (indent: number) => Array(indent).fill(` `).join(``);
36
- const toIndentedItems = (indent: number, delimeters: { afterItem?: string, beforeItem?: string }, items: string[]) => {
37
- return `
38
- ${tabs(indent + 1)}${items.join(`${delimeters.afterItem ?? ``}
39
- ${tabs(indent + 1)}${delimeters.beforeItem ?? ``}`)}
25
+ export const toTypescriptCode = (
26
+ storage: TypedStorage,
27
+ methods: TypedMethod[],
28
+ contractName: string,
29
+ parsedContract: unknown,
30
+ protocol: { name: string; key: string },
31
+ typeAliasData: TypeAliasData,
32
+ typeUtilsData: TypeUtilsData,
33
+ ): TypescriptCodeOutput => {
34
+ type TypeAlias = {
35
+ aliasType: string;
36
+ simpleTypeDefinition: string;
37
+ simpleTypeImports?: { name: string; isDefault?: boolean; from: string }[];
38
+ };
39
+ const usedStrictTypes = [] as TypeAlias[];
40
+ const addTypeAlias = (strictType: TypeAlias) => {
41
+ if (!usedStrictTypes.some(x => x.aliasType === strictType.aliasType)) {
42
+ usedStrictTypes.push(strictType);
43
+ }
44
+ };
45
+
46
+ // Not really tabs :)
47
+ const tabs = (indent: number) => Array(indent).fill(` `).join(``);
48
+ const toIndentedItems = (
49
+ indent: number,
50
+ delimeters: { afterItem?: string; beforeItem?: string },
51
+ items: string[],
52
+ ) => {
53
+ return `
54
+ ${tabs(indent + 1)}${
55
+ items.join(`${delimeters.afterItem ?? ``}
56
+ ${tabs(indent + 1)}${delimeters.beforeItem ?? ``}`)
57
+ }
40
58
  ${tabs(indent)}`;
41
- };
42
-
43
- const typeToCode = (t: TypedType, indent: number): string => {
44
- if (t.kind === `value`) {
45
- // return `${t.typescriptType}`;
46
-
47
- const prim = `prim` in t.raw ? t.raw.prim : `unknown`;
48
-
49
- // Strict mode
50
- if (t.typescriptType === `boolean`
51
- || t.typescriptType === `string` && prim === `string`
52
- ) {
53
- return `${t.typescriptType}`;
54
- }
55
-
56
- if (t.typescriptType === 'number') {
57
- const simpleBaseType = `string | BigNumber | number`;
58
- const typeAlias: TypeAlias = { aliasType: prim, simpleTypeDefinition: `type ${prim} = ${simpleBaseType};`, simpleTypeImports: [{ name: 'BigNumber', isDefault: true, from: 'bignumber.js' }] };
59
- addTypeAlias(typeAlias);
60
-
61
- return typeAlias.aliasType;
62
- }
63
-
64
- const simpleBaseType = t.typescriptType === 'Date' ? 'Date | string' : t.typescriptType;
65
- const typeAlias: TypeAlias = { aliasType: prim, simpleTypeDefinition: `type ${prim} = ${simpleBaseType};` };
66
- addTypeAlias(typeAlias);
67
-
68
- return typeAlias.aliasType;
69
- }
70
- if (t.kind === `array`) {
71
- return `Array<${typeToCode(t.array.item, indent)}>`;
72
- }
73
- if (t.kind === `map`) {
74
-
75
- const typeAlias: TypeAlias = t.map.isBigMap
76
- ? { aliasType: `BigMap`, simpleTypeDefinition: 'type BigMap<K, T> = MichelsonMap<K, T>;', simpleTypeImports: [{ name: 'MichelsonMap', from: '@taquito/taquito' }] }
77
- : { aliasType: `MMap`, simpleTypeDefinition: 'type MMap<K, T> = MichelsonMap<K, T>;', simpleTypeImports: [{ name: 'MichelsonMap', from: '@taquito/taquito' }] };
78
- addTypeAlias(typeAlias);
79
-
80
- return `${typeAlias.aliasType}<${typeToCode(t.map.key, indent)}, ${typeToCode(t.map.value, indent)}>`;
81
- }
82
- if (t.kind === `object`) {
83
- return `{${toIndentedItems(indent, {},
84
- t.fields.map((a, i) => varToCode(a, i, indent + 1) + `;`),
85
- )}}`;
86
- }
87
- if (t.kind === `union`) {
88
-
89
- const getUnionItem = (a: TypedVar, i: number) => {
90
- const itemCode = `${varToCode(a, i, indent + 1)}`;
91
-
92
- // Keep on single line if already on single line
93
- if (!itemCode.includes(`\n`)) {
94
- return `{ ${itemCode} }`;
95
- }
96
-
97
- // Indent if multi-line (and remake with extra indent)
98
- return `{${toIndentedItems(indent + 1, {}, [`${varToCode(a, i, indent + 2)}`])}}`;
99
- };
100
-
101
- return `(${toIndentedItems(indent, { beforeItem: `| ` },
102
- t.union.map(getUnionItem),
103
- )})`;
104
- }
105
- if (t.kind === `unit`) {
106
- const typeAlias: TypeAlias = { aliasType: `unit`, simpleTypeDefinition: `type unit = (true | undefined);`, };
107
- addTypeAlias(typeAlias);
108
- return typeAlias.aliasType;
109
- }
110
- if (t.kind === `never`) {
111
- return `never`;
112
- }
113
- if (t.kind === `unknown`) {
114
- return `unknown`;
115
- }
116
-
117
- assertExhaustive(t, `Unknown type`);
118
- throw new GenerateApiError(`Unknown type node`, { t });
119
- };
120
-
121
- const varToCode = (t: TypedVar, i: number, indent: number, numberVarNamePrefix = ''): string => {
122
- return `${t.name ?? `${numberVarNamePrefix}${i}`}${t.type.optional ? `?` : ``}: ${typeToCode(t.type, indent)}`;
123
- };
124
-
125
- const argsToCode = (args: TypedVar[], indent: number, asObject: boolean): string => {
126
- if (args.length === 1) {
127
- if (args[0].type.kind === `unit`) { return ``; }
128
- return `${args[0].name ?? `param`}: ${typeToCode(args[0].type, indent + 1)}`;
129
- }
130
-
131
- const result = `${toIndentedItems(indent, {},
132
- args.filter(x => x.name || x.type.kind !== `unit`).map((a, i) => varToCode(a, i, indent + 1, asObject ? '' : '_') + `,`),
133
- )}`;
134
-
135
- if(asObject){
136
- return `params: {${result}}`;
137
- }
138
-
139
- return result;
140
- };
141
-
142
- const methodsToCode = (indent: number) => {
143
- const methodFields = methods.map(x => {
144
- const methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, false)}) => Promise<void>;`;
145
- return methodCode;
146
- });
147
-
148
- const methodsTypeCode = `type Methods = {${toIndentedItems(indent, {}, methodFields)}};`;
149
- return methodsTypeCode;
150
- };
151
- const methodsObjectToCode = (indent: number) => {
152
- const methodFields = methods.map(x => {
153
- const methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, true)}) => Promise<void>;`;
154
- return methodCode;
155
- });
156
-
157
- const methodsTypeCode = `type MethodsObject = {${toIndentedItems(indent, {}, methodFields)}};`;
158
- return methodsTypeCode;
159
- };
160
-
161
- const storageToCode = (indent: number) => {
162
- const storageTypeCode = `type Storage = ${typeToCode(storage.storage, indent)};`;
163
- return storageTypeCode;
164
- };
165
-
166
- const methodsCode = methodsToCode(0);
167
- const methodsObjectCode = methodsObjectToCode(0);
168
- const storageCode = storageToCode(0);
169
-
170
- // Simple type aliases
171
- const simpleTypeMappingImportsAll = new Map(usedStrictTypes.map(x => x.simpleTypeImports ?? []).reduce(reduceFlatMap, []).map(x => [`${x?.from}:${x?.name}:${x?.isDefault}`, x]));
172
- const simpleTypeMappingImportsFrom = [...simpleTypeMappingImportsAll.values()].reduce((out, x) => {
173
- const entry = out[x.from] ?? (out[x.from] = { names: [] });
174
- if (x.isDefault) {
175
- entry.default = x.name;
176
- } else {
177
- entry.names.push(x.name);
178
- }
179
- entry.names.sort((a, b) => a.localeCompare(b));
180
- return out;
181
- }, {} as { [from: string]: { names: string[], default?: string } });
182
-
183
- const simpleTypeMappingImportsText = Object.keys(simpleTypeMappingImportsFrom)
184
- .map(k => {
185
- const entry = simpleTypeMappingImportsFrom[k];
186
- const items = [entry.default, entry.names.length ? `{ ${entry.names.join(', ')} }` : ''].filter(x => x);
187
- return `import ${items.join(', ')} from '${k}';\n`;
188
- })
189
- .join('');
190
-
191
- const simpleTypeMapping = usedStrictTypes
192
- .sort((a, b) => a.aliasType.localeCompare(b.aliasType))
193
- .map(x => x.simpleTypeDefinition).join(`\n`);
194
-
195
- const typeUtilsDefinitions =
196
- `import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from '${typeUtilsData.importPath}';`;
197
-
198
- const typeAliasesDefinitions =
199
- typeAliasData.mode === 'simple' ? `${simpleTypeMappingImportsText}${simpleTypeMapping}`
200
- : typeAliasData.mode === 'local' ? typeAliasData.fileContent
201
- : `import { ${usedStrictTypes.map(x => x.aliasType).join(`, `)} } from '${typeAliasData.importPath}';`;
202
-
203
- const contractTypeName = `${contractName}ContractType`;
204
- const walletTypeName = `${contractName}WalletType`;
205
- const codeName = `${contractName}Code`;
206
-
207
- const typesFileContent = `
59
+ };
60
+
61
+ const typeToCode = (t: TypedType, indent: number): string => {
62
+ if (t.kind === `value`) {
63
+ // return `${t.typescriptType}`;
64
+
65
+ const prim = `prim` in t.raw ? t.raw.prim : `unknown`;
66
+
67
+ // Strict mode
68
+ if (
69
+ t.typescriptType === `boolean`
70
+ || t.typescriptType === `string` && prim === `string`
71
+ ) {
72
+ return `${t.typescriptType}`;
73
+ }
74
+
75
+ if (t.typescriptType === 'number') {
76
+ const simpleBaseType = `string | BigNumber | number`;
77
+ const typeAlias: TypeAlias = {
78
+ aliasType: prim,
79
+ simpleTypeDefinition: `type ${prim} = ${simpleBaseType};`,
80
+ simpleTypeImports: [{ name: 'BigNumber', isDefault: true, from: 'bignumber.js' }],
81
+ };
82
+ addTypeAlias(typeAlias);
83
+
84
+ return typeAlias.aliasType;
85
+ }
86
+
87
+ const simpleBaseType = t.typescriptType === 'Date' ? 'Date | string' : t.typescriptType;
88
+ const typeAlias: TypeAlias = { aliasType: prim, simpleTypeDefinition: `type ${prim} = ${simpleBaseType};` };
89
+ addTypeAlias(typeAlias);
90
+
91
+ return typeAlias.aliasType;
92
+ }
93
+ if (t.kind === `array`) {
94
+ return `Array<${typeToCode(t.array.item, indent)}>`;
95
+ }
96
+ if (t.kind === `map`) {
97
+ const typeAlias: TypeAlias = t.map.isBigMap
98
+ ? {
99
+ aliasType: `BigMap`,
100
+ simpleTypeDefinition: 'type BigMap<K, T> = MichelsonMap<K, T>;',
101
+ simpleTypeImports: [{ name: 'MichelsonMap', from: '@taquito/taquito' }],
102
+ }
103
+ : {
104
+ aliasType: `MMap`,
105
+ simpleTypeDefinition: 'type MMap<K, T> = MichelsonMap<K, T>;',
106
+ simpleTypeImports: [{ name: 'MichelsonMap', from: '@taquito/taquito' }],
107
+ };
108
+ addTypeAlias(typeAlias);
109
+
110
+ return `${typeAlias.aliasType}<${typeToCode(t.map.key, indent)}, ${typeToCode(t.map.value, indent)}>`;
111
+ }
112
+ if (t.kind === `object`) {
113
+ return `{${toIndentedItems(indent, {}, t.fields.map((a, i) => varToCode(a, i, indent + 1) + `;`))}}`;
114
+ }
115
+ if (t.kind === `union`) {
116
+ const getUnionItem = (a: TypedVar, i: number) => {
117
+ const itemCode = `${varToCode(a, i, indent + 1)}`;
118
+
119
+ // Keep on single line if already on single line
120
+ if (!itemCode.includes(`\n`)) {
121
+ return `{ ${itemCode} }`;
122
+ }
123
+
124
+ // Indent if multi-line (and remake with extra indent)
125
+ return `{${toIndentedItems(indent + 1, {}, [`${varToCode(a, i, indent + 2)}`])}}`;
126
+ };
127
+
128
+ return `(${toIndentedItems(indent, { beforeItem: `| ` }, t.union.map(getUnionItem))})`;
129
+ }
130
+ if (t.kind === `unit`) {
131
+ const typeAlias: TypeAlias = { aliasType: `unit`, simpleTypeDefinition: `type unit = (true | undefined);` };
132
+ addTypeAlias(typeAlias);
133
+ return typeAlias.aliasType;
134
+ }
135
+ if (t.kind === `never`) {
136
+ return `never`;
137
+ }
138
+ if (t.kind === `unknown`) {
139
+ return `unknown`;
140
+ }
141
+
142
+ assertExhaustive(t, `Unknown type`);
143
+ throw new GenerateApiError(`Unknown type node`, { t });
144
+ };
145
+
146
+ const varToCode = (t: TypedVar, i: number, indent: number, numberVarNamePrefix = ''): string => {
147
+ return `${t.name ?? `${numberVarNamePrefix}${i}`}${t.type.optional ? `?` : ``}: ${typeToCode(t.type, indent)}`;
148
+ };
149
+
150
+ const argsToCode = (args: TypedVar[], indent: number, asObject: boolean): string => {
151
+ if (args.length === 1) {
152
+ if (args[0].type.kind === `unit`) return ``;
153
+ return `${args[0].name ?? `param`}: ${typeToCode(args[0].type, indent + 1)}`;
154
+ }
155
+
156
+ const result = `${
157
+ toIndentedItems(
158
+ indent,
159
+ {},
160
+ args.filter(x => x.name || x.type.kind !== `unit`).map((a, i) =>
161
+ varToCode(a, i, indent + 1, asObject ? '' : '_') + `,`
162
+ ),
163
+ )
164
+ }`;
165
+
166
+ if (asObject) {
167
+ return `params: {${result}}`;
168
+ }
169
+
170
+ return result;
171
+ };
172
+
173
+ const methodsToCode = (indent: number) => {
174
+ const methodFields = methods.map(x => {
175
+ const methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, false)}) => Promise<void>;`;
176
+ return methodCode;
177
+ });
178
+
179
+ const methodsTypeCode = `type Methods = {${toIndentedItems(indent, {}, methodFields)}};`;
180
+ return methodsTypeCode;
181
+ };
182
+ const methodsObjectToCode = (indent: number) => {
183
+ const methodFields = methods.map(x => {
184
+ const methodCode = `${x.name}: (${argsToCode(x.args, indent + 1, true)}) => Promise<void>;`;
185
+ return methodCode;
186
+ });
187
+
188
+ const methodsTypeCode = `type MethodsObject = {${toIndentedItems(indent, {}, methodFields)}};`;
189
+ return methodsTypeCode;
190
+ };
191
+
192
+ const storageToCode = (indent: number) => {
193
+ const storageTypeCode = `type Storage = ${typeToCode(storage.storage, indent)};`;
194
+ return storageTypeCode;
195
+ };
196
+
197
+ const methodsCode = methodsToCode(0);
198
+ const methodsObjectCode = methodsObjectToCode(0);
199
+ const storageCode = storageToCode(0);
200
+
201
+ // Simple type aliases
202
+ const simpleTypeMappingImportsAll = new Map(
203
+ usedStrictTypes.map(x => x.simpleTypeImports ?? []).reduce(reduceFlatMap, []).map(
204
+ x => [`${x?.from}:${x?.name}:${x?.isDefault}`, x],
205
+ ),
206
+ );
207
+ const simpleTypeMappingImportsFrom = [...simpleTypeMappingImportsAll.values()].reduce((out, x) => {
208
+ const entry = out[x.from] ?? (out[x.from] = { names: [] });
209
+ if (x.isDefault) {
210
+ entry.default = x.name;
211
+ } else {
212
+ entry.names.push(x.name);
213
+ }
214
+ entry.names.sort((a, b) => a.localeCompare(b));
215
+ return out;
216
+ }, {} as { [from: string]: { names: string[]; default?: string } });
217
+
218
+ const simpleTypeMappingImportsText = Object.keys(simpleTypeMappingImportsFrom)
219
+ .map(k => {
220
+ const entry = simpleTypeMappingImportsFrom[k];
221
+ const items = [entry.default, entry.names.length ? `{ ${entry.names.join(', ')} }` : ''].filter(x => x);
222
+ return `import ${items.join(', ')} from '${k}';\n`;
223
+ })
224
+ .join('');
225
+
226
+ const simpleTypeMapping = usedStrictTypes
227
+ .sort((a, b) => a.aliasType.localeCompare(b.aliasType))
228
+ .map(x => x.simpleTypeDefinition).join(`\n`);
229
+
230
+ const typeUtilsDefinitions =
231
+ `import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from '${typeUtilsData.importPath}';`;
232
+
233
+ const typeAliasesDefinitions = typeAliasData.mode === 'simple'
234
+ ? `${simpleTypeMappingImportsText}${simpleTypeMapping}`
235
+ : typeAliasData.mode === 'local'
236
+ ? typeAliasData.fileContent
237
+ : `import { ${usedStrictTypes.map(x => x.aliasType).join(`, `)} } from '${typeAliasData.importPath}';`;
238
+
239
+ const contractTypeName = `${contractName}ContractType`;
240
+ const walletTypeName = `${contractName}WalletType`;
241
+ const codeName = `${contractName}Code`;
242
+
243
+ const typesFileContent = `
208
244
  ${typeUtilsDefinitions}
209
245
  ${typeAliasesDefinitions}
210
246
 
@@ -219,21 +255,18 @@ export type ${contractTypeName} = ContractAbstractionFromContractType<contractTy
219
255
  export type ${walletTypeName} = WalletContractAbstractionFromContractType<contractTypes>;
220
256
  `;
221
257
 
222
- const contractCodeFileContent = `
258
+ const contractCodeFileContent = `
223
259
  export const ${codeName}: { __type: '${codeName}', protocol: string, code: object[] } = {
224
260
  __type: '${codeName}',
225
261
  protocol: '${protocol.key}',
226
262
  code: JSON.parse(\`${JSON.stringify(parsedContract)}\`)
227
263
  };
228
264
  `;
229
- return {
230
- typesFileContent,
231
- contractCodeFileContent,
232
- storage: storageCode,
233
- methods: methodsCode,
234
- methodsObject: methodsObjectCode,
235
- };
236
-
265
+ return {
266
+ typesFileContent,
267
+ contractCodeFileContent,
268
+ storage: storageCode,
269
+ methods: methodsCode,
270
+ methodsObject: methodsObjectCode,
271
+ };
237
272
  };
238
-
239
-
@@ -1,4 +1,4 @@
1
- export { generateContractTypesFromMichelsonCode } from './generator/process';
2
- export { generateContractTypesProcessContractFiles as generateContractTypesProcessTzContractFiles } from './cli-process';
3
1
  export { run } from './cli';
4
- export * from './type-aliases';
2
+ export { generateContractTypesProcessContractFiles as generateContractTypesProcessTzContractFiles } from './cli-process';
3
+ export { generateContractTypesFromMichelsonCode } from './generator/process';
4
+ export * from './type-aliases';
@@ -26,6 +26,8 @@ type MapKey = Array<any> | object | string | boolean | number;
26
26
  export type MMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => V };
27
27
  export type BigMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => Promise<V> };
28
28
 
29
+ export type chest = string & { __type: 'chest' };
30
+ export type chest_key = string & { __type: 'chest_key' };
29
31
 
30
32
  const createStringTypeTas = <T extends string>() => {
31
33
  return (value: string): T => value as T;
@@ -64,6 +66,8 @@ export const tas = {
64
66
  address: createStringTypeTas<address>(),
65
67
  bytes: createStringTypeTas<bytes>(),
66
68
  contract: createStringTypeTas<contract>(),
69
+ chest: createStringTypeTas<chest>(),
70
+ chest_key: createStringTypeTas<chest_key>(),
67
71
  timestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp,
68
72
 
69
73
  int: createBigNumberTypeTas<int>(),
@@ -81,4 +85,4 @@ export const tas = {
81
85
  // To number
82
86
  number: (value: string | BigNumber) => Number(value + ''),
83
87
  };
84
- `;
88
+ `;
@@ -1,5 +1,5 @@
1
- import { BigNumber } from 'bignumber.js';
2
1
  import { MichelsonMap } from '@taquito/taquito';
2
+ import { BigNumber } from 'bignumber.js';
3
3
 
4
4
  export type unit = (true | undefined) & { __type: 'unit' };
5
5
 
@@ -24,58 +24,62 @@ type MapKey = Array<any> | object | string | boolean | number;
24
24
  export type MMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => V };
25
25
  export type BigMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => Promise<V> };
26
26
 
27
+ export type chest = string & { __type: 'chest' };
28
+ export type chest_key = string & { __type: 'chest_key' };
27
29
 
28
30
  const createStringTypeTas = <T extends string>() => {
29
- return (value: string): T => value as T;
31
+ return (value: string): T => value as T;
30
32
  };
31
33
 
32
34
  const createBigNumberTypeTas = <T extends BigNumber>() => {
33
- return (value: number | BigNumber | string): T => new BigNumber(value) as T;
35
+ return (value: number | BigNumber | string): T => new BigNumber(value) as T;
34
36
  };
35
37
 
36
- type asMapParamOf<K, V> = K extends string ? { [key: string]: V } | Array<{ key: K, value: V }>
37
- : K extends number ? { [key: number]: V } | Array<{ key: K, value: V }>
38
- : Array<{ key: K, value: V }>;
38
+ type asMapParamOf<K, V> = K extends string ? { [key: string]: V } | Array<{ key: K; value: V }>
39
+ : K extends number ? { [key: number]: V } | Array<{ key: K; value: V }>
40
+ : Array<{ key: K; value: V }>;
39
41
 
40
42
  function asMap<K extends MapKey, V>(value: asMapParamOf<K, V>): MMap<K, V> {
41
- const m = new MichelsonMap<K, V>();
42
- if (Array.isArray(value)) {
43
- const vArray = value as Array<{ key: K, value: V }>;
44
- vArray.forEach(x => m.set(x.key, x.value));
45
- } else {
46
- const vObject = value as { [key: string]: V };
47
- Object.keys(vObject).forEach(key => m.set(key as unknown as K, vObject[key]));
48
- }
49
- return m as MMap<K, V>;
43
+ const m = new MichelsonMap<K, V>();
44
+ if (Array.isArray(value)) {
45
+ const vArray = value as Array<{ key: K; value: V }>;
46
+ vArray.forEach(x => m.set(x.key, x.value));
47
+ } else {
48
+ const vObject = value as { [key: string]: V };
49
+ Object.keys(vObject).forEach(key => m.set(key as unknown as K, vObject[key]));
50
+ }
51
+ return m as MMap<K, V>;
50
52
  }
51
53
  const asBigMap = <K extends MapKey, V>(value: asMapParamOf<K, V>) => asMap(value) as unknown as BigMap<K, V>;
52
54
 
53
55
  function add<T extends BigNumber>(a: T, b: T): T {
54
- return a.plus(b) as T;
56
+ return a.plus(b) as T;
55
57
  }
56
58
  function subtract<T extends BigNumber>(a: T, b: T): T {
57
- return a.minus(b) as T;
59
+ return a.minus(b) as T;
58
60
  }
59
61
 
60
62
  /** tas: Tezos 'as' casting for strict types */
61
63
  export const tas = {
62
- address: createStringTypeTas<address>(),
63
- bytes: createStringTypeTas<bytes>(),
64
- contract: createStringTypeTas<contract>(),
65
- timestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp,
66
-
67
- int: createBigNumberTypeTas<int>(),
68
- nat: createBigNumberTypeTas<nat>(),
69
- mutez: createBigNumberTypeTas<mutez>(),
70
- tez: createBigNumberTypeTas<tez>(),
71
-
72
- map: asMap,
73
- bigMap: asBigMap,
74
-
75
- // Operations
76
- add,
77
- subtract,
78
-
79
- // To number
80
- number: (value: string | BigNumber) => Number(value + ''),
64
+ address: createStringTypeTas<address>(),
65
+ bytes: createStringTypeTas<bytes>(),
66
+ contract: createStringTypeTas<contract>(),
67
+ chest: createStringTypeTas<chest>(),
68
+ chest_key: createStringTypeTas<chest_key>(),
69
+ timestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp,
70
+
71
+ int: createBigNumberTypeTas<int>(),
72
+ nat: createBigNumberTypeTas<nat>(),
73
+ mutez: createBigNumberTypeTas<mutez>(),
74
+ tez: createBigNumberTypeTas<tez>(),
75
+
76
+ map: asMap,
77
+ bigMap: asBigMap,
78
+
79
+ // Operations
80
+ add,
81
+ subtract,
82
+
83
+ // To number
84
+ number: (value: string | BigNumber) => Number(value + ''),
81
85
  };
@@ -35,4 +35,4 @@ export type WalletContractAbstractionFromContractType<TContract extends BaseCont
35
35
  {},
36
36
  ContractStorageOf<TContract>
37
37
  >;
38
- `;
38
+ `;