Skip to content

Commit fd451cc

Browse files
committed
refactor: stop using fetch to get srcdata when it exists locally
1 parent adb53dc commit fd451cc

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

scripts/generateTypes.ts

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs'
2+
import path from 'node:path'
23
import type { NodeFieldMetadataByTag } from './inferFieldMetadata'
34
import { expressionFields, nullableFields, typeMappings } from './typeMappings'
45

@@ -76,24 +77,19 @@ const bitMasks: Record<string, string[]> = {
7677
],
7778
}
7879

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+
}
8285

86+
async function main() {
8387
const [structsByModule, enumsByModule, typeDefs, nodeTypes] =
8488
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')),
9793
])
9894

9995
const entityNames = [

0 commit comments

Comments
 (0)