Skip to content

Commit

Permalink
fix(format): apply prettier changes post bestpracts upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Feb 12, 2023
1 parent 21f6bfc commit 50e45fb
Show file tree
Hide file tree
Showing 111 changed files with 1,035 additions and 500 deletions.
93 changes: 65 additions & 28 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"build:ts": "tsc -p ./tsconfig.build.json",
"prepublish": "npm run build",
"commit:with-cli": "npx cz",
"fix:format:terraform": "echo 'no terraform'",
"fix:format:prettier": "prettier --write '**/*.ts' --config ./prettier.config.js",
"fix:format": "npm run fix:format:prettier && npm run fix:format:terraform",
"fix:lint": "eslint -c ./.eslintrc.js src/**/*.ts --fix",
Expand All @@ -52,6 +53,7 @@
"provision:integration-test-db": "npm run provision:docker:up && npm run provision:docker:await",
"test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
"test:types": "tsc -p ./tsconfig.build.json --noEmit",
"test:format:terraform": "echo 'no terraform'",
"test:format:prettier": "prettier --parser typescript --check 'src/**/*.ts' --config ./prettier.config.js",
"test:format": "npm run test:format:prettier && npm run test:format:terraform",
"test:lint": "npm run test:lint:eslint && npm run test:lint:deps",
Expand Down Expand Up @@ -79,6 +81,7 @@
"listr": "0.14.3",
"mysql2": "1.6.5",
"oclif": "3.3.1",
"pascal-case": "3.1.2",
"schematic-joi-model": "1.2.2",
"simple-sha256": "1.0.0",
"sql-strip-comments": "0.0.23",
Expand Down
10 changes: 8 additions & 2 deletions src/contract/commands/generate.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import SqlCodeGenerator from './generate';

describe('generate', () => {
it('should be able to generate code for valid config and sql, generating both types and query functions', async () => {
await SqlCodeGenerator.run(['-c', `${__dirname}/../__test_assets__/codegen.sql.yml`]);
await SqlCodeGenerator.run([
'-c',
`${__dirname}/../__test_assets__/codegen.sql.yml`,
]);
});
it('should be able to generate code for valid config and sql, only generating types', async () => {
await SqlCodeGenerator.run(['-c', `${__dirname}/../__test_assets__/codegen.sql.only-types.yml`]);
await SqlCodeGenerator.run([
'-c',
`${__dirname}/../__test_assets__/codegen.sql.only-types.yml`,
]);
});
});
7 changes: 5 additions & 2 deletions src/contract/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Command, Flags } from '@oclif/core';

import { generate } from '../../logic/commands/generate/generate';

export default class Generate extends Command {
public static description = 'generate typescript code by parsing sql definitions for types and usage';
public static description =
'generate typescript code by parsing sql definitions for types and usage';

public static flags = {
help: Flags.help({ char: 'h' }),
Expand All @@ -19,7 +21,8 @@ export default class Generate extends Command {
const config = flags.config!;

// generate the code
const configPath = config.slice(0, 1) === '/' ? config : `${process.cwd()}/${config}`; // if starts with /, consider it as an absolute path
const configPath =
config.slice(0, 1) === '/' ? config : `${process.cwd()}/${config}`; // if starts with /, consider it as an absolute path
await generate({ configPath });
}
}
14 changes: 10 additions & 4 deletions src/domain/objects/GeneratorConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DatabaseLanguage } from '../constants';
import { GeneratorConfig } from './GeneratorConfig';
import { QueryDeclaration } from './QueryDeclaration';
import { ResourceDeclaration } from './ResourceDeclaration';
import { GeneratorConfig } from './GeneratorConfig';
import { DatabaseLanguage } from '../constants';

describe('GeneratorConfig', () => {
const queryDec = new QueryDeclaration({
Expand All @@ -17,14 +17,20 @@ describe('GeneratorConfig', () => {
rootDir: '__DIR__',
language: DatabaseLanguage.MYSQL,
dialect: '5.7',
generates: { types: '__TYPES_PATH__', queryFunctions: '__QUERY_FUNCTIONS_PATH__' },
generates: {
types: '__TYPES_PATH__',
queryFunctions: '__QUERY_FUNCTIONS_PATH__',
},
declarations: [queryDec, resourceDec],
});
expect(config).toMatchObject({
rootDir: '__DIR__',
language: DatabaseLanguage.MYSQL,
dialect: '5.7',
generates: { types: '__TYPES_PATH__', queryFunctions: '__QUERY_FUNCTIONS_PATH__' },
generates: {
types: '__TYPES_PATH__',
queryFunctions: '__QUERY_FUNCTIONS_PATH__',
},
declarations: [queryDec, resourceDec],
});
});
Expand Down
13 changes: 10 additions & 3 deletions src/domain/objects/GeneratorConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Joi from 'joi';
import { DomainObject } from 'domain-objects';
import Joi from 'joi';

import { DatabaseLanguage, GeneratedOutputPaths } from '../constants';
import { QueryDeclaration } from './QueryDeclaration';
import { ResourceDeclaration } from './ResourceDeclaration';
Expand All @@ -12,7 +13,10 @@ const generatorConfigSchema = Joi.object().keys({
types: Joi.string().required(),
queryFunctions: Joi.string().optional(),
}),
declarations: Joi.array().items(QueryDeclaration.schema, ResourceDeclaration.schema),
declarations: Joi.array().items(
QueryDeclaration.schema,
ResourceDeclaration.schema,
),
});

type DeclarationObject = QueryDeclaration | ResourceDeclaration;
Expand All @@ -23,6 +27,9 @@ export interface GeneratorConfig {
dialect: string;
declarations: DeclarationObject[];
}
export class GeneratorConfig extends DomainObject<GeneratorConfig> implements GeneratorConfig {
export class GeneratorConfig
extends DomainObject<GeneratorConfig>
implements GeneratorConfig
{
public static schema = generatorConfigSchema;
}
7 changes: 5 additions & 2 deletions src/domain/objects/QueryDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi';
import { DomainObject } from 'domain-objects';
import Joi from 'joi';

const schema = Joi.object().keys({
path: Joi.string().required(),
Expand All @@ -9,6 +9,9 @@ export interface QueryDeclaration {
path: string;
sql: string;
}
export class QueryDeclaration extends DomainObject<QueryDeclaration> implements QueryDeclaration {
export class QueryDeclaration
extends DomainObject<QueryDeclaration>
implements QueryDeclaration
{
public static schema = schema;
}
7 changes: 5 additions & 2 deletions src/domain/objects/ResourceDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi';
import { DomainObject } from 'domain-objects';
import Joi from 'joi';

const schema = Joi.object().keys({
path: Joi.string().required(),
Expand All @@ -10,6 +10,9 @@ export interface ResourceDeclaration {
path: string;
sql: string;
}
export class ResourceDeclaration extends DomainObject<ResourceDeclaration> implements ResourceDeclaration {
export class ResourceDeclaration
extends DomainObject<ResourceDeclaration>
implements ResourceDeclaration
{
public static schema = schema;
}
7 changes: 5 additions & 2 deletions src/domain/objects/SqlSubqueryReference.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi';
import { DomainObject } from 'domain-objects';
import Joi from 'joi';

const schema = Joi.object().keys({
id: Joi.string().required(),
Expand All @@ -9,6 +9,9 @@ export interface SqlSubqueryReference {
id: string;
sql: string;
}
export class SqlSubqueryReference extends DomainObject<SqlSubqueryReference> implements SqlSubqueryReference {
export class SqlSubqueryReference
extends DomainObject<SqlSubqueryReference>
implements SqlSubqueryReference
{
public static schema = schema;
}
9 changes: 6 additions & 3 deletions src/domain/objects/TypeDefinitionOfQuery.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Joi from 'joi';
import { DomainObject } from 'domain-objects';
import Joi from 'joi';

import { TypeDefinitionOfQueryInputVariable } from './TypeDefinitionOfQueryInputVariable';
import { TypeDefinitionOfQuerySelectExpression } from './TypeDefinitionOfQuerySelectExpression';
import { TypeDefinitionOfQueryTableReference } from './TypeDefinitionOfQueryTableReference';
import { TypeDefinitionOfQueryInputVariable } from './TypeDefinitionOfQueryInputVariable';

const schema = Joi.object().keys({
name: Joi.string().required(),
Expand All @@ -25,6 +25,9 @@ export interface TypeDefinitionOfQuery {
tableReferences: TypeDefinitionOfQueryTableReference[];
inputVariables: TypeDefinitionOfQueryInputVariable[];
}
export class TypeDefinitionOfQuery extends DomainObject<TypeDefinitionOfQuery> implements TypeDefinitionOfQuery {
export class TypeDefinitionOfQuery
extends DomainObject<TypeDefinitionOfQuery>
implements TypeDefinitionOfQuery
{
public static schema = schema;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataType } from '../constants';
import { TypeDefinitionOfQueryInputVariable } from './TypeDefinitionOfQueryInputVariable';
import { TypeDefinitionReference } from './TypeDefinitionReference';
import { DataType } from '../constants';

describe('TypeDefinitionOfQueryInputVariable', () => {
it('should initialize for valid inputs', () => {
Expand Down
11 changes: 7 additions & 4 deletions src/domain/objects/TypeDefinitionOfQueryInputVariable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Joi from 'joi';
import { DomainObject } from 'domain-objects';
import { TypeDefinitionReference } from './TypeDefinitionReference';
import Joi from 'joi';

import { DataType } from '../constants';
import { TypeDefinitionReference } from './TypeDefinitionReference';

const schema = Joi.object().keys({
name: Joi.string().required(),
Expand All @@ -21,7 +22,9 @@ export interface TypeDefinitionOfQueryInputVariable {
*/
type: TypeDefinitionReference | DataType[];
}
export class TypeDefinitionOfQueryInputVariable extends DomainObject<TypeDefinitionOfQueryInputVariable>
implements TypeDefinitionOfQueryInputVariable {
export class TypeDefinitionOfQueryInputVariable
extends DomainObject<TypeDefinitionOfQueryInputVariable>
implements TypeDefinitionOfQueryInputVariable
{
public static schema = schema;
}
Loading

0 comments on commit 50e45fb

Please sign in to comment.