Skip to content

build(deps-dev): bump axios from 1.4.0 to 1.6.0 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 11 additions & 17 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"start:dev": "npx nodemon"
},
"devDependencies": {
"@koa/router": "^12.0.0",
"@types/js-yaml": "^4.0.5",
"@types/koa": "^2.13.8",
"@types/koa__router": "^12.0.0",
Expand All @@ -19,7 +18,7 @@
"@types/node": "^18.16.18",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"axios": "^1.4.0",
"axios": "^1.6.0",
"eslint": "^8.43.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.6.0",
Expand All @@ -32,6 +31,7 @@
"prettier": "^2.8.8"
},
"dependencies": {
"@koa/router": "^12.0.0",
"dotenv": "^10.0.0",
"http-status-codes": "^2.2.0",
"js-yaml": "^4.1.0",
Expand All @@ -56,4 +56,4 @@
},
"author": "",
"license": "ISC"
}
}
2 changes: 1 addition & 1 deletion src/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const Headers = {
};

export const ErrorMessages = {
SWAGGER_NOT_PARSABLE: 'Could not parse swagger data',
SWAGGER_NOT_PARSABLE: 'Could not parse swagger file content',
SWAGGER_NAME_ALREADY_EXISTS: 'Swagger with the same name already exists',
SWAGGER_TITLE_ALREADY_EXISTS: 'Swagger with the same title already exists',
SWAGGER_NOT_FOUND: 'Swagger not found',
Expand Down
1 change: 1 addition & 0 deletions src/server/database/connectors/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const TableNames = {
SWAGGERS_TABLE_NAME: 'swaggers',
SWAGGERS_CONTENT_TABLE_NAME: 'swaggers_content',
};
21 changes: 18 additions & 3 deletions src/server/database/connectors/sequlize/migrations/00_initial.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { DataTypes } from 'sequelize';
import { TableNames } from '../../consts';

export const up = async ({ context }) =>
export const up = async ({ context }) => {
await context.createTable(TableNames.SWAGGERS_CONTENT_TABLE_NAME, {
id: {
type: DataTypes.UUID,
primaryKey: true,
},
file_content: {
type: DataTypes.TEXT('long'),
allowNull: false,
},
});
await context.createTable(TableNames.SWAGGERS_TABLE_NAME, {
id: {
type: DataTypes.UUID,
Expand All @@ -12,9 +22,13 @@ export const up = async ({ context }) =>
type: DataTypes.STRING,
allowNull: false,
},
data: {
type: DataTypes.TEXT('long'),
file_content_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: TableNames.SWAGGERS_CONTENT_TABLE_NAME,
key: 'id',
},
},
created_at: {
type: DataTypes.DATE,
Expand All @@ -25,6 +39,7 @@ export const up = async ({ context }) =>
allowNull: false,
},
});
};

export const down = async ({ context: queryInterface }) =>
await queryInterface.dropTable(TableNames.SWAGGERS_TABLE_NAME);
104 changes: 88 additions & 16 deletions src/server/database/models/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,67 @@
import { v4 } from 'uuid';
import { DataTypes, Model, Optional, Sequelize } from 'sequelize';
import { DataTypes, Model, ModelStatic, Sequelize } from 'sequelize';
import { TableNames } from '../connectors/consts';

export enum SwaggerFormats {
Yaml = 'yaml',
Json = 'json',
}

interface SwaggerAttributes {
export interface SwaggerFileContent {
id: string;
file_content: string;
}

export interface InternalSwaggerResource {
id: string;
name: string;
data: string;
file_content_id?: string;
FileContent?: SwaggerFileContent;
created_at?: Date;
updated_at?: Date;
}
export type SwaggerRequestBody = Optional<
SwaggerAttributes,
'id' | 'created_at' | 'updated_at'
>;
export type SwaggerResource = Required<SwaggerAttributes>;
export type SwaggerRequestBody = {
name: string;
file_content: string;
};
export type SwaggerResource = Omit<
InternalSwaggerResource,
'file_content_id'
> & {
file_content?: string;
};

class SwaggerModel
extends Model<SwaggerAttributes, SwaggerRequestBody>
implements SwaggerAttributes
extends Model<InternalSwaggerResource, SwaggerRequestBody>
implements InternalSwaggerResource
{
public static FileContent: ModelStatic<Model<SwaggerFileContent>>;

public id!: string;
public name!: string;
public data!: string;
public readonly file_content_id!: string;
public readonly created_at!: Date;
public readonly updated_at!: Date;

public static initializeModel(sequelizeClient: Sequelize): void {
this.FileContent = sequelizeClient.define(
'FileContent',
{
id: {
type: DataTypes.UUID,
primaryKey: true,
},
file_content: {
type: DataTypes.TEXT('long'),
allowNull: false,
},
},
{
tableName: TableNames.SWAGGERS_CONTENT_TABLE_NAME,
timestamps: false,
}
);

this.init(
{
id: {
Expand All @@ -41,27 +72,68 @@ class SwaggerModel
type: DataTypes.STRING,
allowNull: false,
},
data: {
type: DataTypes.TEXT('long'),
allowNull: false,
},
},
{
tableName: TableNames.SWAGGERS_TABLE_NAME,
sequelize: sequelizeClient,
}
);

this.belongsTo(this.FileContent, {
foreignKey: {
name: 'file_content_id',
allowNull: false,
},
});
}

public static fromRequest(requestBody: SwaggerRequestBody): SwaggerResource {
const now = new Date();

return {
id: v4(),
...requestBody,
name: requestBody.name,
file_content: requestBody.file_content,
created_at: now,
updated_at: now,
};
}

public static toResponse(swagger: SwaggerModel): SwaggerResource {
const { file_content_id, FileContent, ...restSwaggerProps } =
swagger.dataValues;

if (FileContent) {
return this.toResponseWithFileContent(restSwaggerProps, FileContent);
}

return restSwaggerProps;
}

private static toResponseWithFileContent(
swagger: SwaggerResource,
swaggerFileContent: SwaggerFileContent
): SwaggerResource {
return {
id: swagger.id,
name: swagger.name,
file_content: swaggerFileContent.file_content,
created_at: swagger.created_at,
updated_at: swagger.updated_at,
};
}

public static async includeFileContent(
swagger: SwaggerModel
): Promise<SwaggerResource> {
const fileContent = (await swagger[
'getFileContent'
]()) as SwaggerFileContent;

const { file_content_id, ...restSwaggerProps } = swagger.dataValues;

return this.toResponseWithFileContent(restSwaggerProps, fileContent);
}
}

export default SwaggerModel;
Loading