|
1 | 1 | import fs from 'node:fs'
|
| 2 | +import path from 'node:path' |
2 | 3 | import type { NodeFieldMetadataByTag } from './inferFieldMetadata'
|
3 | 4 | import { expressionFields, nullableFields, typeMappings } from './typeMappings'
|
4 | 5 |
|
@@ -76,24 +77,19 @@ const bitMasks: Record<string, string[]> = {
|
76 | 77 | ],
|
77 | 78 | }
|
78 | 79 |
|
79 |
| -async function main() { |
80 |
| - const baseURL = |
81 |
| - 'https://raw.githubusercontent.com/pganalyze/libpg_query/16-latest/srcdata/' |
| 80 | +function readSrcData<T>(fileName: string): T { |
| 81 | + const filePath = path.join(__dirname, '../libpg_query/srcdata', fileName) |
| 82 | + const content = fs.readFileSync(filePath, 'utf-8') |
| 83 | + return JSON.parse(content) as T |
| 84 | +} |
82 | 85 |
|
| 86 | +async function main() { |
83 | 87 | const [structsByModule, enumsByModule, typeDefs, nodeTypes] =
|
84 | 88 | await Promise.all([
|
85 |
| - fetch(baseURL + 'struct_defs.json').then(r => |
86 |
| - r.json(), |
87 |
| - ) as Promise<StructsByModule>, |
88 |
| - fetch(baseURL + 'enum_defs.json').then(r => |
89 |
| - r.json(), |
90 |
| - ) as Promise<EnumsByModule>, |
91 |
| - fetch(baseURL + 'typedefs.json').then(r => r.json()) as Promise< |
92 |
| - TypeDef[] |
93 |
| - >, |
94 |
| - fetch(baseURL + 'nodetypes.json') |
95 |
| - .then(r => r.json()) |
96 |
| - .then(r => new Set(r as string[])), |
| 89 | + readSrcData<StructsByModule>('struct_defs.json'), |
| 90 | + readSrcData<EnumsByModule>('enum_defs.json'), |
| 91 | + readSrcData<TypeDef[]>('typedefs.json'), |
| 92 | + new Set(readSrcData<string[]>('nodetypes.json')), |
97 | 93 | ])
|
98 | 94 |
|
99 | 95 | const entityNames = [
|
|
0 commit comments