Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 64 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"typescript": "5.0.4"
},
"dependencies": {
"io-ts": "^2.1.2"
"io-ts": "^2.2.3"
},
"engines": {
"node": ">=18"
Expand Down
26 changes: 8 additions & 18 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,21 @@
"pgtyped": "lib/index.js"
},
"dependencies": {
"@pgtyped/parser": "^2.4.2",
"@pgtyped/query": "^2.4.2",
"@pgtyped/wire": "^2.4.2",
"camel-case": "^5.0.0",
"chalk": "^4.0.0",
"chokidar": "^4.0.0",
"debug": "^4.1.1",
"fp-ts": "^2.5.3",
"fs-extra": "^11.0.0",
"glob": "^11.0.0",
"@pgtyped/typegen": "^2.4.2",
"piscina": "^5.0.0",
"yargs": "^18.0.0",
"io-ts": "^2.2.20",
"io-ts-reporters": "^2.0.1",
"minimatch": "^10.0.1",
"nunjucks": "3.2.4",
"pascal-case": "^4.0.0",
"piscina": "^5.0.0",
"tinypool": "^1.0.0",
"ts-parse-database-url": "^1.0.3",
"yargs": "^18.0.0"
"chokidar": "^4.0.0",
"nunjucks": "3.2.4",
"glob": "^11.0.0",
"debug": "^4.1.1"
},
"devDependencies": {
"@types/debug": "4.1.12",
"@types/fs-extra": "11.0.4",
"@types/nunjucks": "^3.1.3",
"@types/yargs": "17.0.33"
"@types/nunjucks": "^3.1.3"
},
"peerDependencies": {
"typescript": "3.1 - 5"
Expand Down
64 changes: 15 additions & 49 deletions packages/cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/** @fileoverview Config file parser */

import { Type } from '@pgtyped/query';
import * as Either from 'fp-ts/lib/Either.js';
import * as t from 'io-ts';
import { reporter } from 'io-ts-reporters';
import { createRequire } from 'module';
import * as Either from 'fp-ts/lib/Either.js';
import { isAbsolute, join } from 'path';
import tls from 'tls';
import { reporter } from 'io-ts-reporters';
import { DatabaseConfig, default as dbUrlModule } from 'ts-parse-database-url';
import { TypeDefinition } from './types.js';
import {
DbCodec,
DbConfig,
TypegenCodec,
TypegenConfig,
TypeDefinition,
} from '@pgtyped/typegen';
import { createRequire } from 'module';

// module import hack
const { default: parseDatabaseUri } = dbUrlModule as any;
Expand Down Expand Up @@ -54,56 +57,19 @@ const configParser = t.type({
maxWorkerThreads: t.union([t.number, t.undefined]),
transforms: t.array(TransformCodec),
srcDir: t.string,
failOnError: t.union([t.boolean, t.undefined]),
camelCaseColumnNames: t.union([t.boolean, t.undefined]),
hungarianNotation: t.union([t.boolean, t.undefined]),
nonEmptyArrayParams: t.union([t.boolean, t.undefined]),
dbUrl: t.union([t.string, t.undefined]),
db: t.union([
t.type({
host: t.union([t.string, t.undefined]),
password: t.union([t.string, t.undefined]),
port: t.union([t.number, t.undefined]),
user: t.union([t.string, t.undefined]),
dbName: t.union([t.string, t.undefined]),
ssl: t.union([t.UnknownRecord, t.boolean, t.undefined]),
}),
t.undefined,
]),
typesOverrides: t.union([
t.record(
t.string,
t.union([
t.string,
t.type({
parameter: t.union([t.string, t.undefined]),
return: t.union([t.string, t.undefined]),
}),
]),
),
t.undefined,
]),
db: t.union([DbCodec, t.undefined]),
...TypegenCodec.props,
});

export type IConfig = typeof configParser._O;

export interface ParsedConfig {
db: {
host: string;
user: string;
password: string | undefined;
dbName: string;
port: number;
ssl?: tls.ConnectionOptions | boolean;
};
export interface ParsedConfig extends TypegenConfig {
db: DbConfig;
maxWorkerThreads: number | undefined;
failOnError: boolean;
camelCaseColumnNames: boolean;
hungarianNotation: boolean;
nonEmptyArrayParams: boolean;
transforms: IConfig['transforms'];
srcDir: IConfig['srcDir'];
typesOverrides: Record<string, Partial<TypeDefinition>>;
nonEmptyArrayParams: boolean;
}

function merge<T>(base: T, ...overrides: Partial<T>[]): T {
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { AsyncQueue } from '@pgtyped/wire';
import chokidar from 'chokidar';
import nun from 'nunjucks';

import { Piscina as PiscinaPool } from 'piscina';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { parseConfig, ParsedConfig, TransformConfig } from './config.js';
import { Piscina as PiscinaPool } from 'piscina';
import { ParsedConfig, TransformConfig, parseConfig } from './config.js';
import debugBase from 'debug';
import { TypedSqlTagTransformer } from './typedSqlTagTransformer.js';
import { TypescriptAndSqlTransformer } from './typescriptAndSqlTransformer.js';
import { debug } from './util.js';
export const debug = debugBase('pg-typegen');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const debug = debugBase('pg-typegen');
const debug = debugBase('pg-typegen');


// tslint:disable:no-console

Expand Down
14 changes: 8 additions & 6 deletions packages/cli/src/typedSqlTagTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import chokidar from 'chokidar';
import fs from 'fs-extra';
import { globSync } from 'glob';
import path from 'path';
import { ParsedConfig, TSTypedSQLTagTransformConfig } from './config.js';
import {
TypeDeclarationSet,
getTypeDecsFnResult,
TypeAllocator,
generateDeclarations,
genTypedSQLOverloadFunctions,
TSTypedQuery,
TypeDeclarationSet,
} from './generator.js';
} from '@pgtyped/typegen';
import { TransformJob, WorkerPool } from './index.js';
import { TypeAllocator } from './types.js';
import { debug } from './util.js';
import { getTypeDecsFnResult } from './worker.js';
import { ParsedConfig, TSTypedSQLTagTransformConfig } from './config.js';
import debugBase from 'debug';

const debug = debugBase('pg-typegen');

type TypedSQLTagTransformResult = TypeDeclarationSet | undefined;

Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/typescriptAndSqlTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import chokidar from 'chokidar';
import { globSync } from 'glob';
import path from 'path';
import { ParsedConfig, TransformConfig } from './config.js';
import { minimatch } from 'minimatch';
import { TransformJob, WorkerPool } from './index.js';
import { debug } from './util.js';
import { ParsedConfig, TransformConfig } from './config.js';
import { processFileFnResult } from './worker.js';
import { minimatch } from 'minimatch';
import debugBase from 'debug';

const debug = debugBase('pg-typegen');

// tslint:disable:no-console

Expand Down
Loading