Skip to content

Commit 7f3dcbd

Browse files
committed
feat: modularize the library for external use of internal processing function
1 parent b28db0b commit 7f3dcbd

25 files changed

+388
-207
lines changed

package-lock.json

Lines changed: 64 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"typescript": "5.0.4"
3030
},
3131
"dependencies": {
32-
"io-ts": "^2.1.2"
32+
"io-ts": "^2.2.3"
3333
},
3434
"engines": {
3535
"node": ">=18"

packages/cli/package.json

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,21 @@
3434
"pgtyped": "lib/index.js"
3535
},
3636
"dependencies": {
37-
"@pgtyped/parser": "^2.4.2",
38-
"@pgtyped/query": "^2.4.2",
39-
"@pgtyped/wire": "^2.4.2",
40-
"camel-case": "^5.0.0",
41-
"chalk": "^4.0.0",
42-
"chokidar": "^4.0.0",
43-
"debug": "^4.1.1",
44-
"fp-ts": "^2.5.3",
45-
"fs-extra": "^11.0.0",
46-
"glob": "^11.0.0",
37+
"@pgtyped/typegen": "^2.4.2",
38+
"piscina": "^5.0.0",
39+
"yargs": "^18.0.0",
4740
"io-ts": "^2.2.20",
4841
"io-ts-reporters": "^2.0.1",
49-
"minimatch": "^10.0.1",
50-
"nunjucks": "3.2.4",
51-
"pascal-case": "^4.0.0",
52-
"piscina": "^5.0.0",
53-
"tinypool": "^1.0.0",
5442
"ts-parse-database-url": "^1.0.3",
55-
"yargs": "^18.0.0"
43+
"chokidar": "^4.0.0",
44+
"nunjucks": "3.2.4",
45+
"glob": "^11.0.0",
46+
"debug": "^4.1.1"
5647
},
5748
"devDependencies": {
5849
"@types/debug": "4.1.12",
5950
"@types/fs-extra": "11.0.4",
60-
"@types/nunjucks": "^3.1.3",
61-
"@types/yargs": "17.0.33"
51+
"@types/nunjucks": "^3.1.3"
6252
},
6353
"peerDependencies": {
6454
"typescript": "3.1 - 5"

packages/cli/src/config.ts

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
/** @fileoverview Config file parser */
2-
31
import { Type } from '@pgtyped/query';
4-
import * as Either from 'fp-ts/lib/Either.js';
52
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';
84
import { isAbsolute, join } from 'path';
9-
import tls from 'tls';
5+
import { reporter } from 'io-ts-reporters';
106
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';
1215

1316
// module import hack
1417
const { default: parseDatabaseUri } = dbUrlModule as any;
@@ -54,56 +57,19 @@ const configParser = t.type({
5457
maxWorkerThreads: t.union([t.number, t.undefined]),
5558
transforms: t.array(TransformCodec),
5659
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]),
6160
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,
8663
});
8764

8865
export type IConfig = typeof configParser._O;
8966

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;
9969
maxWorkerThreads: number | undefined;
100-
failOnError: boolean;
101-
camelCaseColumnNames: boolean;
102-
hungarianNotation: boolean;
103-
nonEmptyArrayParams: boolean;
10470
transforms: IConfig['transforms'];
10571
srcDir: IConfig['srcDir'];
106-
typesOverrides: Record<string, Partial<TypeDefinition>>;
72+
nonEmptyArrayParams: boolean;
10773
}
10874

10975
function merge<T>(base: T, ...overrides: Partial<T>[]): T {

packages/cli/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import { AsyncQueue } from '@pgtyped/wire';
55
import chokidar from 'chokidar';
66
import nun from 'nunjucks';
77

8-
import { Piscina as PiscinaPool } from 'piscina';
98
import yargs from 'yargs';
109
import { hideBin } from 'yargs/helpers';
11-
import { parseConfig, ParsedConfig, TransformConfig } from './config.js';
10+
import { Piscina as PiscinaPool } from 'piscina';
11+
import { ParsedConfig, TransformConfig, parseConfig } from './config.js';
12+
import debugBase from 'debug';
1213
import { TypedSqlTagTransformer } from './typedSqlTagTransformer.js';
1314
import { TypescriptAndSqlTransformer } from './typescriptAndSqlTransformer.js';
14-
import { debug } from './util.js';
15+
export const debug = debugBase('pg-typegen');
1516

1617
// tslint:disable:no-console
1718

packages/cli/src/typedSqlTagTransformer.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import chokidar from 'chokidar';
22
import fs from 'fs-extra';
33
import { globSync } from 'glob';
44
import path from 'path';
5-
import { ParsedConfig, TSTypedSQLTagTransformConfig } from './config.js';
65
import {
6+
TypeDeclarationSet,
7+
getTypeDecsFnResult,
8+
TypeAllocator,
79
generateDeclarations,
810
genTypedSQLOverloadFunctions,
911
TSTypedQuery,
10-
TypeDeclarationSet,
11-
} from './generator.js';
12+
} from '@pgtyped/typegen';
1213
import { TransformJob, WorkerPool } from './index.js';
13-
import { TypeAllocator } from './types.js';
14-
import { debug } from './util.js';
15-
import { getTypeDecsFnResult } from './worker.js';
14+
import { ParsedConfig, TSTypedSQLTagTransformConfig } from './config.js';
15+
import debugBase from 'debug';
16+
17+
const debug = debugBase('pg-typegen');
1618

1719
type TypedSQLTagTransformResult = TypeDeclarationSet | undefined;
1820

packages/cli/src/typescriptAndSqlTransformer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import chokidar from 'chokidar';
22
import { globSync } from 'glob';
33
import path from 'path';
4-
import { ParsedConfig, TransformConfig } from './config.js';
4+
import { minimatch } from 'minimatch';
55
import { TransformJob, WorkerPool } from './index.js';
6-
import { debug } from './util.js';
6+
import { ParsedConfig, TransformConfig } from './config.js';
77
import { processFileFnResult } from './worker.js';
8-
import { minimatch } from 'minimatch';
8+
import debugBase from 'debug';
9+
10+
const debug = debugBase('pg-typegen');
911

1012
// tslint:disable:no-console
1113

0 commit comments

Comments
 (0)