|
1 | | -/** @fileoverview Config file parser */ |
2 | | - |
3 | 1 | import { Type } from '@pgtyped/query'; |
4 | | -import * as Either from 'fp-ts/lib/Either.js'; |
5 | 2 | import * as t from 'io-ts'; |
6 | | -import { reporter } from 'io-ts-reporters'; |
7 | | -import { createRequire } from 'module'; |
| 3 | +import * as Either from 'fp-ts/lib/Either.js'; |
8 | 4 | import { isAbsolute, join } from 'path'; |
9 | | -import tls from 'tls'; |
| 5 | +import { reporter } from 'io-ts-reporters'; |
10 | 6 | import { DatabaseConfig, default as dbUrlModule } from 'ts-parse-database-url'; |
11 | | -import { TypeDefinition } from './types.js'; |
| 7 | +import { |
| 8 | + DbCodec, |
| 9 | + DbConfig, |
| 10 | + TypegenCodec, |
| 11 | + TypegenConfig, |
| 12 | + TypeDefinition, |
| 13 | +} from '@pgtyped/typegen'; |
| 14 | +import { createRequire } from 'module'; |
12 | 15 |
|
13 | 16 | // module import hack |
14 | 17 | const { default: parseDatabaseUri } = dbUrlModule as any; |
@@ -54,56 +57,19 @@ const configParser = t.type({ |
54 | 57 | maxWorkerThreads: t.union([t.number, t.undefined]), |
55 | 58 | transforms: t.array(TransformCodec), |
56 | 59 | srcDir: t.string, |
57 | | - failOnError: t.union([t.boolean, t.undefined]), |
58 | | - camelCaseColumnNames: t.union([t.boolean, t.undefined]), |
59 | | - hungarianNotation: t.union([t.boolean, t.undefined]), |
60 | | - nonEmptyArrayParams: t.union([t.boolean, t.undefined]), |
61 | 60 | dbUrl: t.union([t.string, t.undefined]), |
62 | | - db: t.union([ |
63 | | - t.type({ |
64 | | - host: t.union([t.string, t.undefined]), |
65 | | - password: t.union([t.string, t.undefined]), |
66 | | - port: t.union([t.number, t.undefined]), |
67 | | - user: t.union([t.string, t.undefined]), |
68 | | - dbName: t.union([t.string, t.undefined]), |
69 | | - ssl: t.union([t.UnknownRecord, t.boolean, t.undefined]), |
70 | | - }), |
71 | | - t.undefined, |
72 | | - ]), |
73 | | - typesOverrides: t.union([ |
74 | | - t.record( |
75 | | - t.string, |
76 | | - t.union([ |
77 | | - t.string, |
78 | | - t.type({ |
79 | | - parameter: t.union([t.string, t.undefined]), |
80 | | - return: t.union([t.string, t.undefined]), |
81 | | - }), |
82 | | - ]), |
83 | | - ), |
84 | | - t.undefined, |
85 | | - ]), |
| 61 | + db: t.union([DbCodec, t.undefined]), |
| 62 | + ...TypegenCodec.props, |
86 | 63 | }); |
87 | 64 |
|
88 | 65 | export type IConfig = typeof configParser._O; |
89 | 66 |
|
90 | | -export interface ParsedConfig { |
91 | | - db: { |
92 | | - host: string; |
93 | | - user: string; |
94 | | - password: string | undefined; |
95 | | - dbName: string; |
96 | | - port: number; |
97 | | - ssl?: tls.ConnectionOptions | boolean; |
98 | | - }; |
| 67 | +export interface ParsedConfig extends TypegenConfig { |
| 68 | + db: DbConfig; |
99 | 69 | maxWorkerThreads: number | undefined; |
100 | | - failOnError: boolean; |
101 | | - camelCaseColumnNames: boolean; |
102 | | - hungarianNotation: boolean; |
103 | | - nonEmptyArrayParams: boolean; |
104 | 70 | transforms: IConfig['transforms']; |
105 | 71 | srcDir: IConfig['srcDir']; |
106 | | - typesOverrides: Record<string, Partial<TypeDefinition>>; |
| 72 | + nonEmptyArrayParams: boolean; |
107 | 73 | } |
108 | 74 |
|
109 | 75 | function merge<T>(base: T, ...overrides: Partial<T>[]): T { |
|
0 commit comments