Skip to content

Commit

Permalink
feat: add antfu plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Sep 30, 2023
1 parent dc55112 commit f42648d
Show file tree
Hide file tree
Showing 42 changed files with 136 additions and 137 deletions.
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import rubiin from "@rubiin/eslint-config";

export default rubiin({
stylistic: true, // enable stylistic rules
yaml: true, // enable yaml rules,
jsonc : true, // enable jsonc rules
markdown: true, // enable markdown rules
typescript: {
tsconfigPath: "tsconfig.json", // path to tsconfig.json
},
Expand Down
2 changes: 0 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ default:
makemigration env="dev":
NODE_ENV={{env}} npm run orm migration:create


# run migration
migrate env="dev":
NODE_ENV={{env}} npm run orm migration:up
Expand All @@ -16,7 +15,6 @@ migrate env="dev":
unmigrate env="dev":
NODE_ENV={{env}} npm run orm migration:down


# one stop command to make migration and migrate it
quick-migrate: makemigration migrate

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"scripts": {
"build": "nest build",
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint -c eslint.config.mjs '{src,test}/**/*.ts' --cache",
"lint:fix": "ESLINT_USE_FLAT_CONFIG=true eslint -c eslint.config.mjs '{src,test}/**/*.ts' --cache --fix",
"lint:fix": "ESLINT_USE_FLAT_CONFIG=true eslint -c eslint.config.mjs '{src,test}/**/*.ts' --cache --fix --debug",
"orm": "npx mikro-orm",
"prebuild": "rimraf dist",
"sample": "cd env; npx sample-env --env .env.dev",
Expand Down
12 changes: 6 additions & 6 deletions src/common/@types/enums/misc.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export enum PostStateEnum {
PUBLISHED = "PUBLISHED",
}

export const enum Server {
export enum Server {
SES = "SES",
SMTP = "SMTP",
}

export const enum TemplateEngine {
export enum TemplateEngine {
ETA = "ETA",
PUG = "PUG",
HBS = "HBS",
Expand All @@ -42,13 +42,13 @@ export const FileType: Record<keyof typeof FileSize, RegExp> = {

// database enums

export const enum CursorType {
export enum CursorType {
DATE = "DATE",
STRING = "STRING",
NUMBER = "NUMBER",
}

export const enum QueryCursor {
export enum QueryCursor {
DATE = "DATE",
ALPHA = "ALPHA",
}
Expand All @@ -63,12 +63,12 @@ export enum ReferralStatus {
COMPLETED = "COMPLETED",
}

export const enum RoutingKey {
export enum RoutingKey {
SEND_MAIL = "send-mail",
SEND_NEWSLETTER = "send-newsletter",
}

export const enum PaginationType {
export enum PaginationType {
OFFSET = "OFFSET",
CURSOR = "CURSOR",
}
15 changes: 9 additions & 6 deletions src/common/@types/interfaces/pagination.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ export interface PaginationAbstractResponse<T, Y> {
export type Order = "$gt" | "$lt";
export type OppositeOrder = "$gte" | "$lte";

export const getCursorType = (cursor: QueryCursor): CursorType =>
cursor === QueryCursor.DATE ? CursorType.NUMBER : CursorType.STRING;
export function getCursorType(cursor: QueryCursor): CursorType {
return cursor === QueryCursor.DATE ? CursorType.NUMBER : CursorType.STRING;
}

export const getQueryOrder = (order: QueryOrder): Order =>
order === QueryOrder.ASC ? "$gt" : "$lt";
export function getQueryOrder(order: QueryOrder): Order {
return order === QueryOrder.ASC ? "$gt" : "$lt";
}

export const getOppositeOrder = (order: QueryOrder): OppositeOrder =>
order === QueryOrder.ASC ? "$lte" : "$gte";
export function getOppositeOrder(order: QueryOrder): OppositeOrder {
return order === QueryOrder.ASC ? "$lte" : "$gte";
}

export type PaginationRequest = CursorPaginationDto | OffsetPaginationDto;
export type PaginationResponse<T> = CursorPaginationResponse<T> | OffsetPaginationResponse<T>;
3 changes: 2 additions & 1 deletion src/common/database/mikro-orm-cli.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const baseOptions = {
migrations: {
migrations: {
fileName: (timestamp: string, name?: string) => {
if (!name) return `Migration${timestamp}`;
if (!name)
return `Migration${timestamp}`;

return `Migration${timestamp}_${name}`;
},
Expand Down
15 changes: 6 additions & 9 deletions src/common/decorators/api-file.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ApiFilesOptions extends ApiFileOptions {
* @param options_ - IApiFileOptions - The options for the decorator.
* @returns A function that returns a decorator.
*/
export const ApiFile = (options_?: ApiFileOptions) => {
export function ApiFile(options_?: ApiFileOptions) {
const options: ApiFileOptions = { fieldName: "file", required: false, ...options_ };

return applyDecorators(
Expand All @@ -45,15 +45,15 @@ export const ApiFile = (options_?: ApiFileOptions) => {
},
}),
);
};
}

/**
* It adds the `@UseInterceptors(FilesInterceptor(...))` decorator to the route handler, and adds the
* `@ApiConsumes("multipart/form-data")` and `@ApiBody({...})` decorators to the route handler
* @param options_ - The options for the decorator.
* @returns A function that returns a decorator.
*/
export const ApiFiles = (options_?: ApiFilesOptions) => {
export function ApiFiles(options_?: ApiFilesOptions) {
const options: ApiFilesOptions = {
fieldName: "files",
required: false,
Expand Down Expand Up @@ -82,7 +82,7 @@ export const ApiFiles = (options_?: ApiFilesOptions) => {
},
}),
);
};
}

/**
* It takes an array of MulterFields and returns a decorator that will add the appropriate OpenAPI
Expand All @@ -92,10 +92,7 @@ export const ApiFiles = (options_?: ApiFilesOptions) => {
* multer.
*/

export const ApiFileFields = (
options: (MulterField & { required?: boolean })[],
localOptions?: MulterOptions,
) => {
export function ApiFileFields(options: (MulterField & { required?: boolean })[], localOptions?: MulterOptions) {
const bodyProperties: Record<string, SchemaObject | ReferenceObject> = Object.assign(
{},
...options.map((field) => {
Expand All @@ -114,4 +111,4 @@ export const ApiFileFields = (
},
}),
);
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/api-paginated.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CursorPaginationResponse, OffsetPaginationResponse } from "@common/@typ
* includes information about the pagination type (cursor or offset) and the data items returned.
*/

export const ApiPaginatedResponse = <TModel extends Type>(model: TModel) => {
export function ApiPaginatedResponse<TModel extends Type>(model: TModel) {
return applyDecorators(
ApiOperation({ summary: `${model.name.toLowerCase()} list` }),
ApiExtraModels(CursorPaginationResponse, OffsetPaginationResponse, model),
Expand Down Expand Up @@ -49,4 +49,4 @@ export const ApiPaginatedResponse = <TModel extends Type>(model: TModel) => {
},
}),
);
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/auth.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface AuthGuard {
* @returns A function that returns a function
*/

export const Auth = (options_?: AuthGuard) => {
export function Auth(options_?: AuthGuard) {
const options: AuthGuard = {
guards: [JwtAuthGuard, PoliciesGuard],
unauthorizedResponse: API_UNAUTHORISED_RESPONSE,
Expand All @@ -28,4 +28,4 @@ export const Auth = (options_?: AuthGuard) => {
ApiBearerAuth(),
ApiUnauthorizedResponse({ description: options.unauthorizedResponse }),
);
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/controller.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Auth } from "./auth.decorator";
* @param secured - whether or not the controller should be secured
* @returns A function that takes in a class and returns a class.
*/
export const GenericController = (name: string, secured = true) => {
export function GenericController(name: string, secured = true) {
const decsToApply: (ClassDecorator | MethodDecorator | PropertyDecorator)[] = [
ApiTags(capitalize(name)),
Controller(name),
Expand All @@ -20,4 +20,4 @@ export const GenericController = (name: string, secured = true) => {
decsToApply.push(Auth());

return applyDecorators(...decsToApply);
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/custom-cache.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import { NoCache } from "./nocache.decorator";
* (e.g. Authorization to properly identify profile endpoints).
* @returns A function that returns a decorator.
*/
export const ApplyCustomCache = () => {
export function ApplyCustomCache() {
return applyDecorators(NoCache, UseInterceptors(CacheKeyInterceptor));
};
}
6 changes: 3 additions & 3 deletions src/common/decorators/swagger-api.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ interface SwaggerResponseOptions<T, K> {
response?: Type<K>
}

export const SwaggerResponse = ({
export function SwaggerResponse({
operation,
notFound,
badRequest,
params,
body,
response,
}: SwaggerResponseOptions<typeof body, typeof response>) => {
}: SwaggerResponseOptions<typeof body, typeof response>) {
const decsToApply = [ApiOperation({ summary: operation })];

if (params) {
Expand All @@ -39,4 +39,4 @@ export const SwaggerResponse = ({
decsToApply.push(ApiResponse({ type: response }));

return applyDecorators(...decsToApply);
};
}
7 changes: 2 additions & 5 deletions src/common/decorators/uuid-param.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class CustomException extends Error {

const exceptionFactory = () => new CustomException();

export const UUIDParam = (
property: string,
...pipes: (Type<PipeTransform> | PipeTransform)[]
): ParameterDecorator => {
export function UUIDParam(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): ParameterDecorator {
return Param(property, new ParseUUIDPipe({ version: "4", exceptionFactory }), ...pipes);
};
}
7 changes: 2 additions & 5 deletions src/common/decorators/validation/is-after.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ class IsAfterConstraint implements ValidatorConstraintInterface {
}
}

export const IsAfterField = <T = any>(
property: keyof T,
validationOptions?: ValidationOptions,
): PropertyDecorator => {
export function IsAfterField<T = any>(property: keyof T, validationOptions?: ValidationOptions): PropertyDecorator {
return function (object: Record<string, any>, propertyName: string | symbol) {
registerDecorator({
target: object.constructor,
Expand All @@ -39,4 +36,4 @@ export const IsAfterField = <T = any>(
validator: IsAfterConstraint,
});
};
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/validation/is-date-field.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { validationI18nMessage } from "@lib/i18n";
* @returns A decorator function that takes in a target, propertyKey, and descriptor.
*/

export const IsDateField = (options_?: DateFieldOptions) => {
export function IsDateField(options_?: DateFieldOptions) {
const options: DateFieldOptions = {
each: false,
required: true,
Expand Down Expand Up @@ -60,4 +60,4 @@ export const IsDateField = (options_?: DateFieldOptions) => {
}

return applyDecorators(...decoratorsToApply);
};
}
7 changes: 2 additions & 5 deletions src/common/decorators/validation/is-date-format.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ class IsDateInFormatConstraint implements ValidatorConstraintInterface {
}
}

export const IsDateInFormat = (
format: DateFormats,
validationOptions?: ValidationOptions,
): PropertyDecorator => {
export function IsDateInFormat(format: DateFormats, validationOptions?: ValidationOptions): PropertyDecorator {
return function (object: Record<string, any>, propertyName: string | symbol) {
registerDecorator({
target: object.constructor,
Expand All @@ -57,4 +54,4 @@ export const IsDateInFormat = (
validator: IsDateInFormatConstraint,
});
};
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/validation/is-email.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Transform } from "class-transformer";
import type { EmailFieldOptions } from "@common/@types";
import { validationI18nMessage } from "@lib/i18n";

export const IsEmailField = (options_?: EmailFieldOptions) => {
export function IsEmailField(options_?: EmailFieldOptions) {
const options: EmailFieldOptions = {
each: false,
required: true,
Expand Down Expand Up @@ -54,4 +54,4 @@ export const IsEmailField = (options_?: EmailFieldOptions) => {
}

return applyDecorators(...decoratorsToApply);
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/validation/is-enum-field.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { EnumFieldOptions } from "@common/@types";
* @param options_ - EnumFieldOptions
* @returns A decorator function that takes in a target, propertyKey, and descriptor.
*/
export const IsEnumField = (entity: Record<string, string>, options_?: EnumFieldOptions) => {
export function IsEnumField(entity: Record<string, string>, options_?: EnumFieldOptions) {
const options: EnumFieldOptions = {
each: false,
required: true,
Expand Down Expand Up @@ -56,4 +56,4 @@ export const IsEnumField = (entity: Record<string, string>, options_?: EnumField
}

return applyDecorators(...decoratorsToApply);
};
}
7 changes: 2 additions & 5 deletions src/common/decorators/validation/is-equal-to.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class IsEqualToConstraint implements ValidatorConstraintInterface {
}
}

export const IsEqualToField = <T = any>(
property: keyof T,
validationOptions?: ValidationOptions,
): PropertyDecorator => {
export function IsEqualToField<T = any>(property: keyof T, validationOptions?: ValidationOptions): PropertyDecorator {
return function (object: Record<string, any>, propertyName: string | symbol) {
registerDecorator({
target: object.constructor,
Expand All @@ -38,4 +35,4 @@ export const IsEqualToField = <T = any>(
validator: IsEqualToConstraint,
});
};
};
}
7 changes: 2 additions & 5 deletions src/common/decorators/validation/is-greater-than.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class IsGreaterThanConstraint implements ValidatorConstraintInterface {
}
}

export const IsGreaterThan = <T = any>(
property: keyof T,
validationOptions?: ValidationOptions,
): PropertyDecorator => {
export function IsGreaterThan<T = any>(property: keyof T, validationOptions?: ValidationOptions): PropertyDecorator {
return function (object: Record<string, any>, propertyName: string | symbol) {
registerDecorator({
target: object.constructor,
Expand All @@ -38,4 +35,4 @@ export const IsGreaterThan = <T = any>(
validator: IsGreaterThanConstraint,
});
};
};
}
4 changes: 2 additions & 2 deletions src/common/decorators/validation/is-number-field.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { NumberFieldOptions } from "@common/@types";
* @returns A function that returns a decorator.
*/

export const IsNumberField = (options_?: NumberFieldOptions) => {
export function IsNumberField(options_?: NumberFieldOptions) {
const options: NumberFieldOptions = {
min: 1,
required: true,
Expand Down Expand Up @@ -110,4 +110,4 @@ export const IsNumberField = (options_?: NumberFieldOptions) => {
}

return applyDecorators(...decoratorsToApply);
};
}
Loading

0 comments on commit f42648d

Please sign in to comment.