2023-11-29 20:31:18 +03:00
|
|
|
import * as schema_ from '@mtcute/tl/api-schema.json' assert { type: 'json' }
|
2024-08-13 04:53:07 +03:00
|
|
|
import type { TlEntry } from '@mtcute/tl-utils'
|
2023-11-29 20:31:18 +03:00
|
|
|
|
|
|
|
const schema = ('default' in schema_ ? schema_.default : schema_) as { e: TlEntry[] }
|
2023-11-08 17:28:45 +03:00
|
|
|
|
|
|
|
let _cachedEntriesMap: Map<string, TlEntry> | null = null
|
|
|
|
let _cachedUnionsMap: Map<string, TlEntry[]> | null = null
|
|
|
|
|
|
|
|
/** @internal */
|
2024-08-18 09:31:23 +03:00
|
|
|
export function getEntriesMap(): {
|
|
|
|
entries: Map<string, TlEntry>
|
|
|
|
unions: Map<string, TlEntry[]>
|
|
|
|
} {
|
2023-11-08 17:28:45 +03:00
|
|
|
if (_cachedEntriesMap) {
|
|
|
|
return {
|
|
|
|
entries: _cachedEntriesMap,
|
|
|
|
unions: _cachedUnionsMap!,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_cachedEntriesMap = new Map()
|
|
|
|
_cachedUnionsMap = new Map()
|
|
|
|
|
|
|
|
let entry: TlEntry
|
|
|
|
|
|
|
|
for (entry of schema.e) {
|
|
|
|
_cachedEntriesMap.set(entry.name, entry)
|
|
|
|
|
|
|
|
if (!_cachedUnionsMap.has(entry.type)) {
|
|
|
|
_cachedUnionsMap.set(entry.type, [])
|
|
|
|
}
|
|
|
|
_cachedUnionsMap.get(entry.type)!.push(entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
entries: _cachedEntriesMap,
|
|
|
|
unions: _cachedUnionsMap,
|
|
|
|
}
|
|
|
|
}
|