introspeql 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function introspectDatabase(config:
|
|
1
|
+
import { type IntrospeQLConfig } from "./introspeql-config";
|
|
2
|
+
export declare function introspectDatabase(config: IntrospeQLConfig): Promise<void>;
|
|
@@ -7,13 +7,15 @@ import { introspectEnum, } from "./introspect-enum";
|
|
|
7
7
|
import { writeHeader } from "./write-header";
|
|
8
8
|
import { prepareDataForWriting } from "./prepare-data-for-writing";
|
|
9
9
|
import { appendSchema } from "./append-schema";
|
|
10
|
+
import { introspeqlConfig } from "./introspeql-config";
|
|
10
11
|
export async function introspectDatabase(config) {
|
|
11
|
-
const
|
|
12
|
+
const parsedConfig = introspeqlConfig.parse(config);
|
|
13
|
+
const client = "dbConnectionString" in parsedConfig
|
|
12
14
|
? new Client({
|
|
13
|
-
connectionString:
|
|
15
|
+
connectionString: parsedConfig.dbConnectionString,
|
|
14
16
|
})
|
|
15
17
|
: new Client({
|
|
16
|
-
...
|
|
18
|
+
...parsedConfig.dbConnectionParams,
|
|
17
19
|
});
|
|
18
20
|
try {
|
|
19
21
|
await client.connect();
|
|
@@ -24,7 +26,7 @@ export async function introspectDatabase(config) {
|
|
|
24
26
|
// Read table data
|
|
25
27
|
let tableDataObjects;
|
|
26
28
|
try {
|
|
27
|
-
tableDataObjects = await introspectTables(client,
|
|
29
|
+
tableDataObjects = await introspectTables(client, parsedConfig);
|
|
28
30
|
}
|
|
29
31
|
catch (e) {
|
|
30
32
|
throw new Error("Failed to introspect tables.", { cause: e });
|
|
@@ -54,7 +56,7 @@ export async function introspectDatabase(config) {
|
|
|
54
56
|
// Read procedure data and update enums object when enum types are found
|
|
55
57
|
let procedureDataObjects;
|
|
56
58
|
try {
|
|
57
|
-
procedureDataObjects = await introspectProcedures(client,
|
|
59
|
+
procedureDataObjects = await introspectProcedures(client, parsedConfig);
|
|
58
60
|
}
|
|
59
61
|
catch (e) {
|
|
60
62
|
throw new Error("Failed to introspect procedures.", { cause: e });
|
|
@@ -91,10 +93,10 @@ export async function introspectDatabase(config) {
|
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
await client.end();
|
|
94
|
-
const outputPath = "outFile" in
|
|
95
|
-
?
|
|
96
|
-
: path.join(
|
|
97
|
-
writeHeader(outputPath,
|
|
98
|
-
const schemas = prepareDataForWriting(enumDataObjects, tableDataObjects, columnDataObjectsByTableId, procedureDataObjects,
|
|
96
|
+
const outputPath = "outFile" in parsedConfig
|
|
97
|
+
? parsedConfig.outFile
|
|
98
|
+
: path.join(parsedConfig.outDir, "introspeql-types.ts");
|
|
99
|
+
writeHeader(outputPath, parsedConfig);
|
|
100
|
+
const schemas = prepareDataForWriting(enumDataObjects, tableDataObjects, columnDataObjectsByTableId, procedureDataObjects, parsedConfig);
|
|
99
101
|
schemas.forEach((schema) => appendSchema(outputPath, schema));
|
|
100
102
|
}
|