Skip to content

Commit

Permalink
chore: enable explicit-module-boundary-types
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Mar 1, 2024
1 parent 1d33c71 commit edddd1d
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 84 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ module.exports = defineConfig({
{ default: 'array-simple', readonly: 'generic' },
],
'@typescript-eslint/consistent-type-imports': 'error',
// TODO @Shinigami92 2024-02-29: Enable explicit-module-boundary-types later
// '@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
// TODO @Shinigami92 2024-02-29: Enable naming-convention later
// '@typescript-eslint/naming-convention': [
// 'error',
Expand Down
18 changes: 11 additions & 7 deletions src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fs from 'fs';
import mkdirp from 'mkdirp';
import path from 'path';
import type { QueryResult } from 'pg';
import type { DBConnection } from './db';
import MigrationBuilder from './migration-builder';
import type { ColumnDefinitions } from './operations/tablesTypes';
Expand Down Expand Up @@ -52,7 +53,7 @@ const SEPARATOR = '_';
export const loadMigrationFiles = async (
dir: string,
ignorePattern?: string
) => {
): Promise<string[]> => {
const dirContent = await readdir(`${dir}/`, { withFileTypes: true });
const files = dirContent
.map((file) => (file.isFile() || file.isSymbolicLink() ? file.name : null))
Expand Down Expand Up @@ -118,7 +119,7 @@ export class Migration implements RunMigration {
_language?: 'js' | 'ts' | 'sql' | CreateOptions,
_ignorePattern?: string,
_filenameFormat?: FilenameFormat
) {
): Promise<string> {
if (typeof _language === 'string') {
console.warn(
'This usage is deprecated. Please use this method with options object argument'
Expand Down Expand Up @@ -204,7 +205,7 @@ export class Migration implements RunMigration {
this.logger = logger;
}

_getMarkAsRun(action: MigrationAction) {
_getMarkAsRun(action: MigrationAction): string {
const schema = getMigrationTableSchema(this.options);
const { migrationsTable } = this.options;
const { name } = this;
Expand All @@ -220,7 +221,10 @@ export class Migration implements RunMigration {
}
}

async _apply(action: MigrationAction, pgm: MigrationBuilder) {
async _apply(
action: MigrationAction,
pgm: MigrationBuilder
): Promise<unknown> {
if (action.length === 2) {
await new Promise<void>((resolve) => {
action(pgm, resolve);
Expand Down Expand Up @@ -259,7 +263,7 @@ export class Migration implements RunMigration {
);
}

_getAction(direction: MigrationDirection) {
_getAction(direction: MigrationDirection): MigrationAction {
if (direction === 'down' && this.down === undefined) {
this.down = this.up;
}
Expand All @@ -281,7 +285,7 @@ export class Migration implements RunMigration {
return action;
}

apply(direction: MigrationDirection) {
apply(direction: MigrationDirection): Promise<unknown> {
const pgm = new MigrationBuilder(
this.db,
this.typeShorthands,
Expand All @@ -298,7 +302,7 @@ export class Migration implements RunMigration {
return this._apply(action, pgm);
}

markAsRun(direction: MigrationDirection) {
markAsRun(direction: MigrationDirection): Promise<QueryResult> {
return this.db.query(this._getMarkAsRun(this._getAction(direction)));
}
}
8 changes: 4 additions & 4 deletions src/operations/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

export { CreateDomain, DropDomain, AlterDomain, RenameDomain };

export function dropDomain(mOptions: MigrationOptions) {
export function dropDomain(mOptions: MigrationOptions): DropDomain {
const _drop: DropDomain = (domainName, options = {}) => {
const { ifExists, cascade } = options;
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
Expand All @@ -21,7 +21,7 @@ export function dropDomain(mOptions: MigrationOptions) {
return _drop;
}

export function createDomain(mOptions: MigrationOptions) {
export function createDomain(mOptions: MigrationOptions): CreateDomain {
const _create: CreateDomain = (domainName, type, options = {}) => {
const {
default: defaultValue,
Expand Down Expand Up @@ -68,7 +68,7 @@ export function createDomain(mOptions: MigrationOptions) {
return _create;
}

export function alterDomain(mOptions: MigrationOptions) {
export function alterDomain(mOptions: MigrationOptions): AlterDomain {
const _alter: AlterDomain = (domainName, options) => {
const {
default: defaultValue,
Expand Down Expand Up @@ -102,7 +102,7 @@ export function alterDomain(mOptions: MigrationOptions) {
return _alter;
}

export function renameDomain(mOptions: MigrationOptions) {
export function renameDomain(mOptions: MigrationOptions): RenameDomain {
const _rename: RenameDomain = (domainName, newDomainName) => {
const domainNameStr = mOptions.literal(domainName);
const newDomainNameStr = mOptions.literal(newDomainName);
Expand Down
4 changes: 2 additions & 2 deletions src/operations/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CreateExtension, DropExtension } from './extensionsTypes';

export { CreateExtension, DropExtension };

export function dropExtension(mOptions: MigrationOptions) {
export function dropExtension(mOptions: MigrationOptions): DropExtension {
const _drop: DropExtension = (_extensions, options = {}) => {
const { ifExists, cascade } = options;
const extensions = Array.isArray(_extensions) ? _extensions : [_extensions];
Expand All @@ -18,7 +18,7 @@ export function dropExtension(mOptions: MigrationOptions) {
return _drop;
}

export function createExtension(mOptions: MigrationOptions) {
export function createExtension(mOptions: MigrationOptions): CreateExtension {
const _create: CreateExtension = (_extensions, options = {}) => {
const { ifNotExists, schema } = options;
const extensions = Array.isArray(_extensions) ? _extensions : [_extensions];
Expand Down
6 changes: 3 additions & 3 deletions src/operations/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CreateFunction, DropFunction, RenameFunction } from './functionsTypes';

export { CreateFunction, DropFunction, RenameFunction };

export function dropFunction(mOptions: MigrationOptions) {
export function dropFunction(mOptions: MigrationOptions): DropFunction {
const _drop: DropFunction = (
functionName,
functionParams = [],
Expand All @@ -21,7 +21,7 @@ export function dropFunction(mOptions: MigrationOptions) {
return _drop;
}

export function createFunction(mOptions: MigrationOptions) {
export function createFunction(mOptions: MigrationOptions): CreateFunction {
const _create: CreateFunction = (
functionName,
functionParams = [],
Expand Down Expand Up @@ -76,7 +76,7 @@ export function createFunction(mOptions: MigrationOptions) {
return _create;
}

export function renameFunction(mOptions: MigrationOptions) {
export function renameFunction(mOptions: MigrationOptions): RenameFunction {
const _rename: RenameFunction = (
oldFunctionName,
functionParams = [],
Expand Down
4 changes: 2 additions & 2 deletions src/operations/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function generateColumnsString(
.join(', ');
}

export function dropIndex(mOptions: MigrationOptions) {
export function dropIndex(mOptions: MigrationOptions): DropIndex {
const _drop: DropIndex = (tableName, rawColumns, options = {}) => {
const { concurrently, ifExists, cascade } = options;
const columns = Array.isArray(rawColumns)
Expand All @@ -83,7 +83,7 @@ export function dropIndex(mOptions: MigrationOptions) {
return _drop;
}

export function createIndex(mOptions: MigrationOptions) {
export function createIndex(mOptions: MigrationOptions): CreateIndex {
const _create: CreateIndex = (tableName, rawColumns, options = {}) => {
/*
columns - the column, columns, or expression to create the index on
Expand Down
36 changes: 26 additions & 10 deletions src/operations/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export {
RemoveFromOperatorFamily,
};

export function dropOperator(mOptions: MigrationOptions) {
export function dropOperator(mOptions: MigrationOptions): DropOperator {
const _drop: DropOperator = (operatorName, options = {}) => {
const { ifExists, cascade, left, right } = options;

Expand All @@ -44,7 +44,7 @@ export function dropOperator(mOptions: MigrationOptions) {
return _drop;
}

export function createOperator(mOptions: MigrationOptions) {
export function createOperator(mOptions: MigrationOptions): CreateOperator {
const _create: CreateOperator = (operatorName, options) => {
const {
procedure,
Expand Down Expand Up @@ -100,7 +100,9 @@ export function createOperator(mOptions: MigrationOptions) {
return _create;
}

export function dropOperatorFamily(mOptions: MigrationOptions) {
export function dropOperatorFamily(
mOptions: MigrationOptions
): DropOperatorFamily {
const _drop: DropOperatorFamily = (
operatorFamilyName,
indexMethod,
Expand All @@ -116,7 +118,9 @@ export function dropOperatorFamily(mOptions: MigrationOptions) {
return _drop;
}

export function createOperatorFamily(mOptions: MigrationOptions) {
export function createOperatorFamily(
mOptions: MigrationOptions
): CreateOperatorFamily {
const _create: CreateOperatorFamily = (operatorFamilyName, indexMethod) => {
const operatorFamilyNameStr = mOptions.literal(operatorFamilyName);
return `CREATE OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod};`;
Expand Down Expand Up @@ -148,7 +152,9 @@ const operatorMap =
throw new Error('Operator "type" must be either "function" or "operator"');
};

export const removeFromOperatorFamily = (mOptions: MigrationOptions) => {
export const removeFromOperatorFamily = (
mOptions: MigrationOptions
): RemoveFromOperatorFamily => {
const method: RemoveFromOperatorFamily = (
operatorFamilyName,
indexMethod,
Expand All @@ -166,7 +172,9 @@ export const removeFromOperatorFamily = (mOptions: MigrationOptions) => {
return method;
};

export const addToOperatorFamily = (mOptions: MigrationOptions) => {
export const addToOperatorFamily = (
mOptions: MigrationOptions
): AddToOperatorFamily => {
const method: AddToOperatorFamily = (
operatorFamilyName,
indexMethod,
Expand All @@ -185,7 +193,9 @@ export const addToOperatorFamily = (mOptions: MigrationOptions) => {
return method;
};

export function renameOperatorFamily(mOptions: MigrationOptions) {
export function renameOperatorFamily(
mOptions: MigrationOptions
): RenameOperatorFamily {
const _rename: RenameOperatorFamily = (
oldOperatorFamilyName,
indexMethod,
Expand All @@ -205,7 +215,9 @@ export function renameOperatorFamily(mOptions: MigrationOptions) {
return _rename;
}

export function dropOperatorClass(mOptions: MigrationOptions) {
export function dropOperatorClass(
mOptions: MigrationOptions
): DropOperatorClass {
const _drop: DropOperatorClass = (
operatorClassName,
indexMethod,
Expand All @@ -222,7 +234,9 @@ export function dropOperatorClass(mOptions: MigrationOptions) {
return _drop;
}

export function createOperatorClass(mOptions: MigrationOptions) {
export function createOperatorClass(
mOptions: MigrationOptions
): CreateOperatorClass {
const _create: CreateOperatorClass = (
operatorClassName,
type,
Expand Down Expand Up @@ -254,7 +268,9 @@ export function createOperatorClass(mOptions: MigrationOptions) {
return _create;
}

export function renameOperatorClass(mOptions: MigrationOptions) {
export function renameOperatorClass(
mOptions: MigrationOptions
): RenameOperatorClass {
const _rename: RenameOperatorClass = (
oldOperatorClassName,
indexMethod,
Expand Down
8 changes: 4 additions & 4 deletions src/operations/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const makeClauses = ({ role, using, check }: PolicyOptions) => {
return clauses;
};
export function dropPolicy(mOptions: MigrationOptions) {
export function dropPolicy(mOptions: MigrationOptions): DropPolicy {
const _drop: DropPolicy = (tableName, policyName, options = {}) => {
const { ifExists } = options;
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
Expand All @@ -39,7 +39,7 @@ export function dropPolicy(mOptions: MigrationOptions) {
return _drop;
}
export function createPolicy(mOptions: MigrationOptions) {
export function createPolicy(mOptions: MigrationOptions): CreatePolicy {
const _create: CreatePolicy = (tableName, policyName, options = {}) => {
const createOptions = {
...options,
Expand All @@ -59,7 +59,7 @@ export function createPolicy(mOptions: MigrationOptions) {
return _create;
}
export function alterPolicy(mOptions: MigrationOptions) {
export function alterPolicy(mOptions: MigrationOptions): AlterPolicy {
const _alter: AlterPolicy = (tableName, policyName, options = {}) => {
const clausesStr = makeClauses(options).join(' ');
const policyNameStr = mOptions.literal(policyName);
Expand All @@ -70,7 +70,7 @@ export function alterPolicy(mOptions: MigrationOptions) {
return _alter;
}
export function renamePolicy(mOptions: MigrationOptions) {
export function renamePolicy(mOptions: MigrationOptions): RenamePolicy {
const _rename: RenamePolicy = (tableName, policyName, newPolicyName) => {
const policyNameStr = mOptions.literal(policyName);
const newPolicyNameStr = mOptions.literal(newPolicyName);
Expand Down
8 changes: 4 additions & 4 deletions src/operations/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const formatRoleOptions = (roleOptions: RoleOptions = {}) => {
return options.join(' ');
};

export function dropRole(mOptions: MigrationOptions) {
export function dropRole(mOptions: MigrationOptions): DropRole {
const _drop: DropRole = (roleName, options = {}) => {
const { ifExists } = options;
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
Expand All @@ -87,7 +87,7 @@ export function dropRole(mOptions: MigrationOptions) {
return _drop;
}

export function createRole(mOptions: MigrationOptions) {
export function createRole(mOptions: MigrationOptions): CreateRole {
const _create: CreateRole = (roleName, roleOptions = {}) => {
const options = formatRoleOptions({
...roleOptions,
Expand All @@ -106,7 +106,7 @@ export function createRole(mOptions: MigrationOptions) {
return _create;
}

export function alterRole(mOptions: MigrationOptions) {
export function alterRole(mOptions: MigrationOptions): AlterRole {
const _alter: AlterRole = (roleName, roleOptions = {}) => {
const options = formatRoleOptions(roleOptions);
return options
Expand All @@ -117,7 +117,7 @@ export function alterRole(mOptions: MigrationOptions) {
return _alter;
}

export function renameRole(mOptions: MigrationOptions) {
export function renameRole(mOptions: MigrationOptions): RenameRole {
const _rename: RenameRole = (oldRoleName, newRoleName) => {
const oldRoleNameStr = mOptions.literal(oldRoleName);
const newRoleNameStr = mOptions.literal(newRoleName);
Expand Down
6 changes: 3 additions & 3 deletions src/operations/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CreateSchema, DropSchema, RenameSchema } from './schemasTypes';

export { CreateSchema, DropSchema, RenameSchema };

export function dropSchema(mOptions: MigrationOptions) {
export function dropSchema(mOptions: MigrationOptions): DropSchema {
const _drop: DropSchema = (schemaName, options = {}) => {
const { ifExists, cascade } = options;
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
Expand All @@ -15,7 +15,7 @@ export function dropSchema(mOptions: MigrationOptions) {
return _drop;
}

export function createSchema(mOptions: MigrationOptions) {
export function createSchema(mOptions: MigrationOptions): CreateSchema {
const _create: CreateSchema = (schemaName: string, options = {}) => {
const { ifNotExists, authorization } = options;
const ifNotExistsStr = ifNotExists ? ' IF NOT EXISTS' : '';
Expand All @@ -30,7 +30,7 @@ export function createSchema(mOptions: MigrationOptions) {
return _create;
}

export function renameSchema(mOptions: MigrationOptions) {
export function renameSchema(mOptions: MigrationOptions): RenameSchema {
const _rename: RenameSchema = (schemaName, newSchemaName) => {
const schemaNameStr = mOptions.literal(schemaName);
const newSchemaNameStr = mOptions.literal(newSchemaName);
Expand Down
Loading

0 comments on commit edddd1d

Please sign in to comment.