Skip to content

Commit

Permalink
fix(types): resolve type errors after typescript upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Feb 12, 2023
1 parent df2354a commit bfba1f8
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export const lowercaseEverythingAfterFirstAs = ({ ddl }: { ddl: string }) => {
const casedAsDdlParts = ddl.split(' AS ');
const casedDdl = [casedAsDdlParts[0], casedAsDdlParts[1].toLowerCase()].join(
const casedDdl = [casedAsDdlParts[0], casedAsDdlParts[1]!.toLowerCase()].join(
' AS ',
);
return casedDdl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const removeParenthesisFromWhereConditions = ({
flattenedSql,
}: {
flattenedSql: string;
}) => {
}): string => {
const whereCasing = !!flattenedSql.match(/\sWHERE\s/) ? 'WHERE' : 'where'; // determine if user is using upper case or lower case "where"
const sqlSplitOnWhere = flattenedSql.split(whereCasing);
if (sqlSplitOnWhere.length > 2) {
Expand All @@ -16,11 +16,11 @@ export const removeParenthesisFromWhereConditions = ({
}
const sqlWithoutParens =
sqlSplitOnWhere.length === 2
? sqlSplitOnWhere[0] +
? sqlSplitOnWhere[0]! +
'\n' +
whereCasing +
'\n' +
sqlSplitOnWhere[1].replace(/[\(\)]/g, '') // tslint:disable-line prefer-template
: sqlSplitOnWhere[0]; // if no where clause, then nothing to replace
sqlSplitOnWhere[1]!.replace(/[\(\)]/g, '') // tslint:disable-line prefer-template
: sqlSplitOnWhere[0]!; // if no where clause, then nothing to replace
return sqlWithoutParens;
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const removeParenthesisSurroundingJoinsInFromClause = ({
); // fail fast

// remove the parens that encapsulate each join
const fromClauseWithoutParens = flattenedSqlParts[1]
const fromClauseWithoutParens = flattenedSqlParts[1]!
.replace(/\(/g, '')
.replace(/\)/g, ''); // note: we replace all parens, since subqueries are taken care of

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const normalizeCreateFunctionDdl = ({ ddl }: { ddl: string }) => {
prettierDdl = (() => {
const partsSplitOnParens = prettierDdl.split(/([\(\)])/g);
const functionParams = partsSplitOnParens[2];
const functionParamsWithNewlines = `\n ${functionParams
const functionParamsWithNewlines = `\n ${functionParams!
.replace(/, /g, ',\n ')
.trim()}\n`;
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('breakSqlIntoNestedSqlArraysAtParentheses', () => {
const sql = "SELECT CONCAT('hel', 'lo');";
const nestedSqlArray = breakSqlIntoNestedSqlArraysAtParentheses({ sql });
expect(nestedSqlArray).toHaveLength(3);
expect(nestedSqlArray[1][0][0]).toEqual('(');
expect(nestedSqlArray[1][0].slice(-1)[0]).toEqual(')');
expect(nestedSqlArray[1]![0]![0]).toEqual('(');
expect(nestedSqlArray[1]![0]!.slice(-1)[0]).toEqual(')');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FROM ice_cream s

// should have got the reference
expect(references.length).toEqual(1);
expect(references[0].sql).toEqual(sqlParts[1]);
expect(references[0]!.sql).toEqual(sqlParts[1]);

// it should have replaced the sql in the referenced sql parts for the subquery
expect(referencedSqlParts[1]).toMatch(/__SSQ:[\w-]+__/);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import uuid from 'uuid';

import { uuid } from '../../deps';
import { getTokenForSqlSubqueryReference } from './getTokenForSubqueryReference';
import { SqlSubqueryReference } from './model/SqlSubqueryReference';

Expand Down
2 changes: 1 addition & 1 deletion src/logic/commands/displayPlans/displayPlans.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Chalk from 'chalk';
import sha256 from 'simple-sha256';
import { stdout } from 'stdout-stderr';
import uuid from 'uuid/v4';

import { uuid } from '../../../deps';
import {
ChangeDefinition,
DefinitionPlan,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const extractResourceTypeAndNameFromDDL = ({ ddl }: { ddl: string }) => {
const type = regexTypeMatchToTypeEnum[regexTypeMatch];

// extract the name
const name = extractionMatches[2];
const name = extractionMatches[2]!;

// return type and name
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sha256 from 'simple-sha256';
import uuid from 'uuid/v4';

import { promiseConfig } from '../../../__test_assets__/connection.config';
import { uuid } from '../../../deps';
import {
ChangeDefinition,
DefinitionPlan,
Expand Down
2 changes: 1 addition & 1 deletion src/logic/plan/getPlanForDefinition.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sha256 from 'simple-sha256';
import uuid from 'uuid/v4';

import { uuid } from '../../deps';
import {
ChangeDefinition,
ChangeDefinitionStatus,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sha256 from 'simple-sha256';
import uuid from 'uuid/v4';

import { promiseConfig } from '../../../../__test_assets__/connection.config';
import { uuid } from '../../../../deps';
import {
ChangeDefinition,
ControlConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sha256 from 'simple-sha256';
import uuid from 'uuid/v4';

import { promiseConfig } from '../../../../__test_assets__/connection.config';
import { uuid } from '../../../../deps';
import {
DatabaseLanguage,
DatabaseConnection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sha256 from 'simple-sha256';
import uuid from 'uuid/v4';

import { promiseConfig } from '../../../../__test_assets__/connection.config';
import { uuid } from '../../../../deps';
import {
ChangeDefinition,
ChangeDefinitionStatus,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sha256 from 'simple-sha256';
import uuid from 'uuid/v4';

import { promiseConfig } from '../../../../__test_assets__/connection.config';
import { uuid } from '../../../../deps';
import {
ChangeDefinition,
DatabaseConnection,
Expand Down
3 changes: 1 addition & 2 deletions src/logic/schema/getReferenceIdForDefinition.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sha256 from 'simple-sha256';

import { uuid } from '../../deps';
import {
ChangeDefinition,
ChangeDefinitionStatus,
Expand All @@ -8,8 +9,6 @@ import {
} from '../../types';
import { getReferenceIdForDefinition } from './getReferenceIdForDefinition';

import uuid = require('uuid');

describe('getReferenceIdForDefinition', () => {
it('should accurately define the plan id for a change definition', async () => {
const definition = new ChangeDefinition({
Expand Down
2 changes: 1 addition & 1 deletion src/logic/schema/getStatusForDefinition.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sha256 from 'simple-sha256';
import uuid from 'uuid/v4';

import { uuid } from '../../deps';
import {
ChangeDefinition,
ResourceDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('getUncontrolledResources', () => {
controlledResources,
});
expect(uncontrolledResources.length).toEqual(1);
expect(uncontrolledResources[0].name).toEqual(liveResource.name);
expect(uncontrolledResources[0]!.name).toEqual(liveResource.name);
});
it('should find that a resource in pullResources that does exist in liveResource is controlled', async () => {
const liveResource = new ResourceDefinition({
Expand All @@ -73,7 +73,7 @@ describe('getUncontrolledResources', () => {
connection: '__CONNECTION__' as any,
controlledResources: [] as any,
});
uncontrolledResources.map((uncontrolledResource) =>
uncontrolledResources.map(uncontrolledResource =>
expect(uncontrolledResource.status).toEqual(
ResourceDefinitionStatus.NOT_CONTROLLED,
),
Expand All @@ -91,7 +91,7 @@ describe('getUncontrolledResources', () => {
connection: '__CONNECTION__' as any,
controlledResources: [] as any,
});
uncontrolledResources.map((uncontrolledResource) =>
uncontrolledResources.map(uncontrolledResource =>
expect(uncontrolledResource.path).toEqual(
`${liveResource.type.toLowerCase()}:${liveResource.name}`,
),
Expand Down
4 changes: 2 additions & 2 deletions src/types/objects/DefinitionPlan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Joi from 'joi';
import Joi, { SchemaLikeWithoutArray } from 'joi';
import SchematicJoiModel from 'schematic-joi-model';

import { RequiredAction } from '../constants';
Expand All @@ -10,7 +10,7 @@ const definitionPlanSchema = Joi.object().keys({
definition: Joi.alternatives().try([
ChangeDefinition.schema,
ResourceDefinition.schema,
]),
] as any as SchemaLikeWithoutArray),
difference: Joi.string().optional(), // a human readable string of the difference
action: Joi.string().valid(Object.values(RequiredAction)), // a key that catogorizes how to display the definition (e.g., color it, bold it, warn about it, throw an error)
});
Expand Down

0 comments on commit bfba1f8

Please sign in to comment.