Skip to content

Commit

Permalink
refactor: unify codestyle (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Apr 26, 2024
1 parent 07da8ef commit 381d270
Show file tree
Hide file tree
Showing 57 changed files with 331 additions and 222 deletions.
37 changes: 33 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ export type {
CreateCast,
CreateCastFn,
CreateCastOptions,
CreateCastWithFunctionOptions,
CreateCastWithInoutOptions,
CreateCastWithoutFunctionOptions,
DropCast,
DropCastOptions,
} from './operations/casts';
export type {
AlterDomain,
AlterDomainOptions,
CreateDomain,
CreateDomainFn,
CreateDomainOptions,
DomainOptions,
DomainOptionsAlter,
DomainOptionsCreate,
DropDomain,
DropDomainOptions,
RenameDomain,
RenameDomainFn,
} from './operations/domains';
Expand All @@ -21,13 +26,16 @@ export type {
CreateExtensionFn,
CreateExtensionOptions,
DropExtension,
DropExtensionOptions,
Extension,
StringExtension,
} from './operations/extensions';
export type {
CreateFunction,
CreateFunctionFn,
CreateFunctionOptions,
DropFunction,
DropFunctionOptions,
FunctionOptions,
FunctionParam,
FunctionParamType,
Expand Down Expand Up @@ -95,6 +103,7 @@ export type {
CreateMaterializedViewFn,
CreateMaterializedViewOptions,
DropMaterializedView,
DropMaterializedViewOptions,
RefreshMaterializedView,
RefreshMaterializedViewFn,
RefreshMaterializedViewOptions,
Expand All @@ -113,11 +122,14 @@ export type {
CreateOperatorClassOptions,
CreateOperatorFamily,
CreateOperatorFamilyFn,
CreateOperatorFamilyOptions,
CreateOperatorFn,
CreateOperatorOptions,
DropOperator,
DropOperatorClass,
DropOperatorClassOptions,
DropOperatorFamily,
DropOperatorFamilyOptions,
DropOperatorOptions,
OperatorListDefinition,
RemoveFromOperatorFamily,
Expand All @@ -132,6 +144,7 @@ export type {
CreatePolicyOptions,
CreatePolicyOptionsEn,
DropPolicy,
DropPolicyOptions,
PolicyOptions,
RenamePolicy,
RenamePolicyFn,
Expand All @@ -140,33 +153,40 @@ export type {
AlterRole,
CreateRole,
CreateRoleFn,
CreateRoleOptions,
DropRole,
DropRoleOptions,
RenameRole,
RenameRoleFn,
RoleOptions,
} from './operations/roles';
export type {
CreateSchema,
CreateSchemaFn,
CreateSchemaOptions,
DropSchema,
DropSchemaOptions,
RenameSchema,
RenameSchemaFn,
} from './operations/schemas';
export type {
AlterSequence,
AlterSequenceOptions,
CreateSequence,
CreateSequenceFn,
CreateSequenceOptions,
DropSequence,
DropSequenceOptions,
RenameSequence,
RenameSequenceFn,
SequenceOptions,
SequenceOptionsAlter,
SequenceOptionsCreate,
} from './operations/sequences';
export type { Sql } from './operations/sql';
export type {
Action,
AddColumns,
AddColumnsFn,
AddColumnsOptions,
AlterColumn,
AlterColumnOptions,
AlterTable,
Expand All @@ -176,11 +196,16 @@ export type {
ConstraintOptions,
CreateConstraint,
CreateConstraintFn,
CreateConstraintFn1,
CreateConstraintFn2,
CreateTable,
CreateTableFn,
DropColumns,
DropColumnsOptions,
DropConstraint,
DropConstraintOptions,
DropTable,
DropTableOptions,
ForeignKeyOptions,
Like,
LikeOptions,
Expand All @@ -200,6 +225,7 @@ export type {
CreateTriggerFn1,
CreateTriggerFn2,
DropTrigger,
DropTriggerOptions,
RenameTrigger,
RenameTriggerFn,
TriggerOptions,
Expand All @@ -213,6 +239,8 @@ export type {
CreateTypeFn,
DropType,
DropTypeAttribute,
DropTypeAttributeOptions,
DropTypeOptions,
RenameType,
RenameTypeAttribute,
RenameTypeAttributeFn,
Expand All @@ -230,6 +258,7 @@ export type {
CreateViewFn,
CreateViewOptions,
DropView,
DropViewOptions,
RenameView,
RenameViewFn,
ViewOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/operations/casts/createCast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type CreateCast = Reversible<CreateCastFn>;

export function createCast(mOptions: MigrationOptions): CreateCast {
const _create: CreateCast = (sourceType, targetType, options = {}) => {
const { functionName, argumentTypes, inout, as } = options;
const { functionName, argumentTypes, inout = false, as } = options;

let conversion = '';
if (functionName) {
Expand Down
9 changes: 5 additions & 4 deletions src/operations/casts/dropCast.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import type { MigrationOptions } from '../../types';
import type { DropOptions } from '../generalTypes';
import type { IfExistsOption } from '../generalTypes';

export type DropCastOptions = Omit<DropOptions, 'cascade'>;
export type DropCastOptions = IfExistsOption;

export type DropCast = (
fromType: string,
toType: string,
dropOptions: DropCastOptions
dropOptions?: DropCastOptions
) => string;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function dropCast(mOptions: MigrationOptions): DropCast {
const _drop: DropCast = (sourceType, targetType, options = {}) => {
const { ifExists } = options;
const { ifExists = false } = options;

const ifExistsStr = ifExists ? ' IF EXISTS' : '';

return `DROP CAST${ifExistsStr} (${sourceType} AS ${targetType});`;
Expand Down
6 changes: 3 additions & 3 deletions src/operations/domains/alterDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { escapeValue } from '../../utils';
import type { Name } from '../generalTypes';
import type { DomainOptions } from './shared';

export interface DomainOptionsAlter extends DomainOptions {
export interface AlterDomainOptions extends DomainOptions {
allowNull?: boolean;
}

export type AlterDomain = (
domainName: Name,
domainOptions: DomainOptionsAlter
domainOptions: AlterDomainOptions
) => string;

export function alterDomain(mOptions: MigrationOptions): AlterDomain {
const _alter: AlterDomain = (domainName, options) => {
const {
default: defaultValue,
notNull,
allowNull,
allowNull = false,
check,
constraintName,
} = options;
Expand Down
9 changes: 5 additions & 4 deletions src/operations/domains/createDomain.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type { MigrationOptions } from '../../types';
import { applyType, escapeValue } from '../../utils';
import type { DropOptions, Name, Reversible, Type } from '../generalTypes';
import type { Name, Reversible, Type } from '../generalTypes';
import type { DropDomainOptions } from './dropDomain';
import { dropDomain } from './dropDomain';
import type { DomainOptions } from './shared';

export interface DomainOptionsCreate extends DomainOptions {
export interface CreateDomainOptions extends DomainOptions {
collation?: string;
}

export type CreateDomainFn = (
domainName: Name,
type: Type,
domainOptions?: DomainOptionsCreate & DropOptions
domainOptions?: CreateDomainOptions & DropDomainOptions
) => string;

export type CreateDomain = Reversible<CreateDomainFn>;
Expand All @@ -21,7 +22,7 @@ export function createDomain(mOptions: MigrationOptions): CreateDomain {
const {
default: defaultValue,
collation,
notNull,
notNull = false,
check,
constraintName,
} = options;
Expand Down
6 changes: 4 additions & 2 deletions src/operations/domains/dropDomain.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name } from '../generalTypes';

export type DropDomainOptions = DropOptions;

export type DropDomain = (
domainName: Name,
dropOptions?: DropOptions
dropOptions?: DropDomainOptions
) => string;

export function dropDomain(mOptions: MigrationOptions): DropDomain {
const _drop: DropDomain = (domainName, options = {}) => {
const { ifExists, cascade } = options;
const { ifExists = false, cascade = false } = options;

const ifExistsStr = ifExists ? ' IF EXISTS' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
Expand Down
11 changes: 4 additions & 7 deletions src/operations/extensions/createExtension.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { MigrationOptions } from '../../types';
import { toArray } from '../../utils';
import type {
DropOptions,
IfNotExistsOption,
Reversible,
} from '../generalTypes';
import type { IfNotExistsOption, Reversible } from '../generalTypes';
import type { DropExtensionOptions } from './dropExtension';
import { dropExtension } from './dropExtension';
import type { StringExtension } from './shared';

Expand All @@ -14,14 +11,14 @@ export interface CreateExtensionOptions extends IfNotExistsOption {

export type CreateExtensionFn = (
extension: StringExtension | StringExtension[],
options?: CreateExtensionOptions & DropOptions
extensionOptions?: CreateExtensionOptions & DropExtensionOptions
) => string | string[];

export type CreateExtension = Reversible<CreateExtensionFn>;

export function createExtension(mOptions: MigrationOptions): CreateExtension {
const _create: CreateExtension = (_extensions, options = {}) => {
const { ifNotExists, schema } = options;
const { ifNotExists = false, schema } = options;

const extensions = toArray(_extensions);
const ifNotExistsStr = ifNotExists ? ' IF NOT EXISTS' : '';
Expand Down
6 changes: 4 additions & 2 deletions src/operations/extensions/dropExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { toArray } from '../../utils';
import type { DropOptions } from '../generalTypes';
import type { StringExtension } from './shared';

export type DropExtensionOptions = DropOptions;

export type DropExtension = (
extension: StringExtension | StringExtension[],
dropOptions?: DropOptions
dropOptions?: DropExtensionOptions
) => string | string[];

export function dropExtension(mOptions: MigrationOptions): DropExtension {
const _drop: DropExtension = (_extensions, options = {}) => {
const { ifExists, cascade } = options;
const { ifExists = false, cascade = false } = options;

const extensions = toArray(_extensions);
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
Expand Down
11 changes: 7 additions & 4 deletions src/operations/functions/createFunction.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { MigrationOptions } from '../../types';
import { escapeValue, formatParams } from '../../utils';
import type { DropOptions, Name, Reversible, Value } from '../generalTypes';
import type { DropFunctionOptions } from './dropFunction';
import { dropFunction } from './dropFunction';
import type { FunctionOptions, FunctionParam } from './shared';

export type CreateFunctionOptions = FunctionOptions & DropOptions;

export type CreateFunctionFn = (
functionName: Name,
functionParams: FunctionParam[],
functionOptions: FunctionOptions & DropOptions,
functionOptions: CreateFunctionOptions & DropFunctionOptions,
definition: Value
) => string;

Expand All @@ -21,12 +24,12 @@ export function createFunction(mOptions: MigrationOptions): CreateFunction {
definition
) => {
const {
replace,
replace = false,
returns = 'void',
language,
window,
window = false,
behavior = 'VOLATILE',
onNull,
onNull = false,
parallel,
} = functionOptions;

Expand Down
6 changes: 4 additions & 2 deletions src/operations/functions/dropFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { formatParams } from '../../utils';
import type { DropOptions, Name } from '../generalTypes';
import type { FunctionParam } from './shared';

export type DropFunctionOptions = DropOptions;

export type DropFunction = (
functionName: Name,
functionParams: FunctionParam[],
dropOptions?: DropOptions
dropOptions?: DropFunctionOptions
) => string;

export function dropFunction(mOptions: MigrationOptions): DropFunction {
Expand All @@ -15,7 +17,7 @@ export function dropFunction(mOptions: MigrationOptions): DropFunction {
functionParams = [],
options = {}
) => {
const { ifExists, cascade } = options;
const { ifExists = false, cascade = false } = options;

const ifExistsStr = ifExists ? ' IF EXISTS' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
Expand Down
Loading

0 comments on commit 381d270

Please sign in to comment.