Skip to content

Commit

Permalink
refactor: stop using fetch to get srcdata when it exists locally
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 7, 2024
1 parent adb53dc commit fd451cc
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions scripts/generateTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'node:fs'
import path from 'node:path'
import type { NodeFieldMetadataByTag } from './inferFieldMetadata'
import { expressionFields, nullableFields, typeMappings } from './typeMappings'

Expand Down Expand Up @@ -76,24 +77,19 @@ const bitMasks: Record<string, string[]> = {
],
}

async function main() {
const baseURL =
'https://raw.githubusercontent.com/pganalyze/libpg_query/16-latest/srcdata/'
function readSrcData<T>(fileName: string): T {
const filePath = path.join(__dirname, '../libpg_query/srcdata', fileName)
const content = fs.readFileSync(filePath, 'utf-8')
return JSON.parse(content) as T
}

async function main() {
const [structsByModule, enumsByModule, typeDefs, nodeTypes] =
await Promise.all([
fetch(baseURL + 'struct_defs.json').then(r =>
r.json(),
) as Promise<StructsByModule>,
fetch(baseURL + 'enum_defs.json').then(r =>
r.json(),
) as Promise<EnumsByModule>,
fetch(baseURL + 'typedefs.json').then(r => r.json()) as Promise<
TypeDef[]
>,
fetch(baseURL + 'nodetypes.json')
.then(r => r.json())
.then(r => new Set(r as string[])),
readSrcData<StructsByModule>('struct_defs.json'),
readSrcData<EnumsByModule>('enum_defs.json'),
readSrcData<TypeDef[]>('typedefs.json'),
new Set(readSrcData<string[]>('nodetypes.json')),
])

const entityNames = [
Expand Down

0 comments on commit fd451cc

Please sign in to comment.