Skip to content

Commit

Permalink
refactor!: cleanup type definitions (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Feb 21, 2025
1 parent e2cf12a commit 7d0a4d9
Show file tree
Hide file tree
Showing 102 changed files with 1,194 additions and 1,364 deletions.
29 changes: 25 additions & 4 deletions src/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
This file just manages the database connection and provides a query method
*/
import { inspect } from 'node:util';
import type {
Client,
Expand All @@ -12,7 +9,31 @@ import type {
QueryResult,
} from 'pg';
import pg from 'pg';
import type { DB, Logger } from './types';
import type { Logger } from './logger';

// This file just manages the database connection and provides a query method

// see ClientBase in @types/pg
export interface DB {
/* eslint-disable @typescript-eslint/no-explicit-any */
query(
queryConfig: QueryArrayConfig,
values?: any[]
): Promise<QueryArrayResult>;
query(queryConfig: QueryConfig): Promise<QueryResult>;
query(
queryTextOrConfig: string | QueryConfig,
values?: any[]
): Promise<QueryResult>;

select(queryConfig: QueryArrayConfig, values?: any[]): Promise<any[]>;
select(queryConfig: QueryConfig): Promise<any[]>;
select(
queryTextOrConfig: string | QueryConfig,
values?: any[]
): Promise<any[]>;
/* eslint-enable @typescript-eslint/no-explicit-any */
}

/* eslint-disable @typescript-eslint/no-explicit-any */
export interface DBConnection extends DB {
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { Migration } from './migration';
export type { default as MigrationBuilder } from './migrationBuilder';
export type {
CreateCast,
CreateCastFn,
Expand Down Expand Up @@ -261,8 +262,8 @@ export type {
RenameViewFn,
ViewOptions,
} from './operations/views';
export { PgType } from './pgType';
export { runner as default, runner } from './runner';
export { PgType } from './types';
export type { MigrationBuilder, RunnerOption } from './types';
export type { RunnerOption } from './runner';
export { PgLiteral, isPgLiteral } from './utils';
export type { PgLiteralValue } from './utils';
8 changes: 8 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type LogFn = (msg: string) => void;

export type Logger = {
debug?: LogFn;
info: LogFn;
warn: LogFn;
error: LogFn;
};
30 changes: 15 additions & 15 deletions src/migration.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
A new Migration is instantiated for each migration file.
It is responsible for storing the name of the file and knowing how to execute
the up and down migrations defined in the file.
*/

import { glob } from 'glob';
import { createReadStream, createWriteStream } from 'node:fs';
import { mkdir, readdir } from 'node:fs/promises';
import { basename, extname, join, resolve } from 'node:path';
import { cwd } from 'node:process';
import type { QueryResult } from 'pg';
import type { DBConnection } from './db';
import type { Logger } from './logger';
import MigrationBuilder from './migrationBuilder';
import type { ColumnDefinitions } from './operations/tables';
import type {
Logger,
MigrationAction,
MigrationBuilderActions,
MigrationDirection,
RunnerOption,
} from './types';
import type { MigrationDirection, RunnerOption } from './runner';
import type { MigrationBuilderActions } from './sqlMigration';
import { getMigrationTableSchema } from './utils';

/*
* A new Migration is instantiated for each migration file.
*
* It is responsible for storing the name of the file and knowing how to execute
* the up and down migrations defined in the file.
*/

export type MigrationAction = (
pgm: MigrationBuilder,
run?: () => void
) => Promise<void> | void;

export interface RunMigration {
readonly path: string;
readonly name: string;
Expand Down
Loading

0 comments on commit 7d0a4d9

Please sign in to comment.