|
1 | 1 | import type {ABI} from '@wharfkit/antelope' |
2 | 2 | import * as ts from 'typescript' |
3 | 3 | import {formatClassName} from '../../utils' |
| 4 | +import {capitalize, extractDecorator, parseType, trim} from './contract-utils' |
4 | 5 | import {findAbiType, findAliasFromType, findCoreClass, findCoreType, findVariant} from './finders' |
5 | 6 | import type {TypeInterfaceDeclaration} from './interfaces' |
6 | 7 |
|
| 8 | +// Re-export utilities for backwards compatibility |
| 9 | +export {capitalize, extractDecorator, parseType, trim, cleanupType} from './contract-utils' |
| 10 | + |
7 | 11 | export function getCoreImports(abi: ABI.Def) { |
8 | 12 | const coreImports: string[] = [] |
9 | 13 | const coreTypes: string[] = [] |
@@ -211,55 +215,15 @@ export function formatInternalType( |
211 | 215 | return `${type}${decorator}` |
212 | 216 | } |
213 | 217 |
|
214 | | -const decorators = ['?', '[]'] |
215 | | -export function extractDecorator(type: string): {type: string; decorator?: string} { |
216 | | - for (const decorator of decorators) { |
217 | | - if (type.includes(decorator)) { |
218 | | - type = type.replace(decorator, '') |
219 | | - |
220 | | - return {type, decorator} |
221 | | - } |
222 | | - } |
223 | | - |
224 | | - return {type} |
225 | | -} |
226 | | - |
227 | | -export function cleanupType(type: string): string { |
228 | | - return extractDecorator(parseType(trim(type))).type |
229 | | -} |
230 | | - |
231 | | -export function parseType(type: string): string { |
232 | | - type = type.replace('$', '') |
233 | | - |
234 | | - if (type === 'String') { |
235 | | - return 'string' |
236 | | - } |
237 | | - |
238 | | - if (type === 'String[]') { |
239 | | - return 'string[]' |
240 | | - } |
241 | | - |
242 | | - if (type === 'Boolean') { |
243 | | - return 'boolean' |
244 | | - } |
245 | | - |
246 | | - if (type === 'Boolean[]') { |
247 | | - return 'boolean[]' |
248 | | - } |
249 | | - |
250 | | - return type |
251 | | -} |
252 | | - |
253 | | -export function trim(string: string) { |
254 | | - return string.replace(/\s/g, '') |
255 | | -} |
256 | | - |
257 | | -export function capitalize(string) { |
258 | | - if (typeof string !== 'string' || string.length === 0) { |
259 | | - return '' |
260 | | - } |
| 218 | +export function findInternalType( |
| 219 | + type: string, |
| 220 | + typeNamespace: string | undefined, |
| 221 | + abi: ABI.Def |
| 222 | +): string { |
| 223 | + const {type: typeString, decorator} = findAbiType(type, abi, typeNamespace) |
261 | 224 |
|
262 | | - return string.charAt(0).toUpperCase() + string.slice(1) |
| 225 | + // TODO: inside findAbiType, namespace is prefixed, but formatInternalType is doing the same |
| 226 | + return formatInternalType(typeString, typeNamespace, abi, decorator) |
263 | 227 | } |
264 | 228 |
|
265 | 229 | export function removeDuplicateInterfaces( |
|
0 commit comments