diff --git a/packages/generate/src/cli.ts b/packages/generate/src/cli.ts index 29ce2eac6..db8f23b99 100644 --- a/packages/generate/src/cli.ts +++ b/packages/generate/src/cli.ts @@ -393,6 +393,8 @@ Run this command inside an EdgeDB project directory or specify the desired targe } } catch (e) { exitWithError((e as Error).message); + } finally { + await client.close(); } adapter.process.exit(); }; diff --git a/packages/generate/src/edgeql-js.ts b/packages/generate/src/edgeql-js.ts index bc7ded7ba..3678b429d 100644 --- a/packages/generate/src/edgeql-js.ts +++ b/packages/generate/src/edgeql-js.ts @@ -88,77 +88,73 @@ export async function generateQueryBuilder(params: { const dir = new DirBuilder(); - try { - // tslint:disable-next-line - console.log(`Introspecting database schema...`); - - const [types, scalars, casts, functions, operators, globals, version] = - await Promise.all([ - $.introspect.types(cxn), - $.introspect.scalars(cxn), - $.introspect.casts(cxn), - $.introspect.functions(cxn), - $.introspect.operators(cxn), - $.introspect.globals(cxn), - cxn.queryRequiredSingle(`select sys::get_version()`), - ]); - - const typesByName: Record = {}; - for (const type of types.values()) { - typesByName[type.name] = type; - - // skip "anytype" and "anytuple" - if (!type.name.includes("::")) continue; - } - - const generatorParams: GeneratorParams = { - dir, - types, - typesByName, - casts, - scalars, - functions, - globals, - operators, - edgedbVersion: version, - }; - generateRuntimeSpec(generatorParams); - generateCastMaps(generatorParams); - generateScalars(generatorParams); - generateObjectTypes(generatorParams); - generateFunctionTypes(generatorParams); - generateOperators(generatorParams); - generateSetImpl(generatorParams); - generateGlobals(generatorParams); - - // TODO: Fix 'fts' module generation properly, for now we just disable - // output of this module - dir._modules.delete("fts"); - dir._map.delete("modules/fts"); - // ----------------- - - generateIndex(generatorParams); - - // generate module imports - - const importsFile = dir.getPath("imports"); - - importsFile.addExportStar("edgedb", { as: "edgedb" }); - importsFile.addExportFrom({ spec: true }, "./__spec__", { - allowFileExt: true, - }); - importsFile.addExportStar("./syntax", { - allowFileExt: true, - as: "syntax", - }); - importsFile.addExportStar("./castMaps", { - allowFileExt: true, - as: "castMaps", - }); - } finally { - await cxn.close(); + // tslint:disable-next-line + console.log(`Introspecting database schema...`); + + const [types, scalars, casts, functions, operators, globals, version] = + await Promise.all([ + $.introspect.types(cxn), + $.introspect.scalars(cxn), + $.introspect.casts(cxn), + $.introspect.functions(cxn), + $.introspect.operators(cxn), + $.introspect.globals(cxn), + cxn.queryRequiredSingle(`select sys::get_version()`), + ]); + + const typesByName: Record = {}; + for (const type of types.values()) { + typesByName[type.name] = type; + + // skip "anytype" and "anytuple" + if (!type.name.includes("::")) continue; } + const generatorParams: GeneratorParams = { + dir, + types, + typesByName, + casts, + scalars, + functions, + globals, + operators, + edgedbVersion: version, + }; + generateRuntimeSpec(generatorParams); + generateCastMaps(generatorParams); + generateScalars(generatorParams); + generateObjectTypes(generatorParams); + generateFunctionTypes(generatorParams); + generateOperators(generatorParams); + generateSetImpl(generatorParams); + generateGlobals(generatorParams); + + // TODO: Fix 'fts' module generation properly, for now we just disable + // output of this module + dir._modules.delete("fts"); + dir._map.delete("modules/fts"); + // ----------------- + + generateIndex(generatorParams); + + // generate module imports + + const importsFile = dir.getPath("imports"); + + importsFile.addExportStar("edgedb", { as: "edgedb" }); + importsFile.addExportFrom({ spec: true }, "./__spec__", { + allowFileExt: true, + }); + importsFile.addExportStar("./syntax", { + allowFileExt: true, + as: "syntax", + }); + importsFile.addExportStar("./castMaps", { + allowFileExt: true, + as: "castMaps", + }); + const initialFiles = new Set(await walk(outputDir)); const written = new Set(); diff --git a/packages/generate/src/interfaces.ts b/packages/generate/src/interfaces.ts index b46528694..d8ecae7e3 100644 --- a/packages/generate/src/interfaces.ts +++ b/packages/generate/src/interfaces.ts @@ -42,12 +42,7 @@ export async function runInterfacesGenerator(params: { // tslint:disable-next-line console.log(`Introspecting database schema...`); - let types: $.introspect.Types; - try { - types = await $.introspect.types(client); - } finally { - client.close(); - } + const types = await $.introspect.types(client); const generatorParams = { dir,