-
Notifications
You must be signed in to change notification settings - Fork 1
/
define_config.ts
37 lines (33 loc) · 935 Bytes
/
define_config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { RuntimeException } from "@poppinss/utils";
import type { ClickHouseConnectionsList } from './types.js'
export function defineConfig<T extends ClickHouseConnectionsList>(
config: {
connection: keyof T,
connections: T
}
): {
connection: keyof T,
connections: T
} {
if (!config) {
throw new RuntimeException("Invalid config. It must be an object");
}
if (!config.connections) {
throw new RuntimeException(
'Missing "connections" property in the clickhouse config file'
);
}
if (!config.connection) {
throw new RuntimeException(
'Missing "connection" property in clickhouse config. Specify a default connection to use'
);
}
if (!config.connections[config.connection]) {
throw new RuntimeException(
`Missing "connections.${String(
config.connection
)}". It is referenced by the "default" clickhouse connection`
);
}
return config;
}