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 10, 2023
1 parent e7e8e24 commit 123208c
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 41 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ module.exports = {
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
'no-return-await': 'off', // this does not help anything and actually leads to bugs if we subsequently wrap the return in a try catch without remembering to _then_ add await
'@typescript-eslint/return-await': 'off',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const normalizeCreateFunctionDdl = ({ ddl }: { ddl: string }) => {
// make sure that function inputs each have their own line. postgres returns them all on one line - hard to read
prettierSql = (() => {
const partsSplitOnParens = prettierSql.split(/([\(\)])/g);
const functionParams = partsSplitOnParens[2];
const functionParams = partsSplitOnParens[2]!;
const functionParamsWithNewlines = `\n ${functionParams
.replace(/, /g, ',\n ')
.trim()}\n`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import uuid from 'uuid/v4';
import { pg as prepare } from 'yesql';

import {
DatabaseConnection,
getDatabaseConnection,
} from '../../../__test_utils__/databaseConnection';
import { getShowCreateFunction } from '../../../__test_utils__/getShowCreateFunction';
import { uuid } from '../../../deps';
import { Entity } from '../../../domain';
import * as prop from '../../define/defineProperty';
import { generateEntityTables } from '../entityTables/generateEntityTables';
Expand Down Expand Up @@ -84,8 +84,10 @@ describe('generateEntityBackfillCurrentVersionPointers', () => {
return { name, sql: upsertSql };
};
const recreateTheBackfillMethod = async () => {
const { name, sql: upsertSql } =
generateEntityBackfillCurrentVersionPointers({ entity: car });
const {
name,
sql: upsertSql,
} = generateEntityBackfillCurrentVersionPointers({ entity: car });
await dbConnection.query({ sql: `DROP FUNCTION IF EXISTS ${name}` });
await dbConnection.query({ sql: upsertSql });
return { name, sql: upsertSql };
Expand Down Expand Up @@ -258,7 +260,7 @@ describe('generateEntityBackfillCurrentVersionPointers', () => {

// manually update each row, ensuring that ids are out of sync
await Promise.all(
idsOfNewCars.map(async (id) => deleteCvpRecordForCarById({ id })),
idsOfNewCars.map(async id => deleteCvpRecordForCarById({ id })),
);

// show that limit is respected
Expand All @@ -268,8 +270,9 @@ describe('generateEntityBackfillCurrentVersionPointers', () => {
expect(rowsAffectedByBackfillNow).toEqual(3);

// and double prove it by showing that the remainder will be backfilled on running it again
const rowsAffectedByBackfillNowAgain =
await backfillCurrentVersionPointers({ limit: 1000 });
const rowsAffectedByBackfillNowAgain = await backfillCurrentVersionPointers(
{ limit: 1000 },
);
expect(rowsAffectedByBackfillNowAgain).toEqual(2);
});

Expand Down Expand Up @@ -302,7 +305,7 @@ describe('generateEntityBackfillCurrentVersionPointers', () => {

// manually update each row, ensuring that ids are out of sync
await Promise.all(
idsOfNewCars.map(async (id) => manuallyChangeVersionOfCarById({ id })),
idsOfNewCars.map(async id => manuallyChangeVersionOfCarById({ id })),
);

// show that limit is respected
Expand All @@ -312,8 +315,9 @@ describe('generateEntityBackfillCurrentVersionPointers', () => {
expect(rowsAffectedByBackfillNow).toEqual(3);

// and double prove it by showing that the remainder will be backfilled on running it again
const rowsAffectedByBackfillNowAgain =
await backfillCurrentVersionPointers({ limit: 1000 });
const rowsAffectedByBackfillNowAgain = await backfillCurrentVersionPointers(
{ limit: 1000 },
);
expect(rowsAffectedByBackfillNowAgain).toEqual(2);
});
it('should respect the limit on combinations of inserts and updates', async () => {
Expand Down Expand Up @@ -342,12 +346,12 @@ describe('generateEntityBackfillCurrentVersionPointers', () => {

// manually update each row, ensuring that ids are out of sync
await Promise.all(
idsOfNewCarsToDeleteRecordsFor.map(async (id) =>
idsOfNewCarsToDeleteRecordsFor.map(async id =>
deleteCvpRecordForCarById({ id }),
),
);
await Promise.all(
idsOfNewCarsToUpdate.map(async (id) =>
idsOfNewCarsToUpdate.map(async id =>
manuallyChangeVersionOfCarById({ id }),
),
);
Expand All @@ -359,8 +363,9 @@ describe('generateEntityBackfillCurrentVersionPointers', () => {
expect(rowsAffectedByBackfillNow).toEqual(7);

// and double prove it by showing that the remainder will be backfilled on running it again
const rowsAffectedByBackfillNowAgain =
await backfillCurrentVersionPointers({ limit: 1000 });
const rowsAffectedByBackfillNowAgain = await backfillCurrentVersionPointers(
{ limit: 1000 },
);
expect(rowsAffectedByBackfillNowAgain).toEqual(3);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ export const defineFindOrCreateStaticEntityLogic = ({

// define the static property names
const staticPropertyNames = Object.entries(entity.properties)
.filter((entry) => !entry[1].updatable)
.map((entry) => entry[0]);
.filter(entry => !entry[1].updatable)
.map(entry => entry[0]);

// define the column names and the column value references for the static properties
const staticPropertyColumnNames = staticPropertyNames.map((name) =>
castPropertyToColumnName({ name, definition: entity.properties[name] }),
const staticPropertyColumnNames = staticPropertyNames.map(name =>
castPropertyToColumnName({ name, definition: entity.properties[name]! }),
);
const staticPropertyColumnValueReferences = staticPropertyNames.map((name) =>
const staticPropertyColumnValueReferences = staticPropertyNames.map(name =>
castPropertyToTableColumnValueReference({
name,
definition: entity.properties[name],
definition: entity.properties[name]!,
}),
);

Expand All @@ -46,13 +46,13 @@ export const defineFindOrCreateStaticEntityLogic = ({
}

// otherwise, define the where clause conditionals as normal
const uniqueStaticPropertyNames = staticPropertyNames.filter((name) =>
const uniqueStaticPropertyNames = staticPropertyNames.filter(name =>
entity.unique.includes(name),
);
return uniqueStaticPropertyNames.map((name) =>
return uniqueStaticPropertyNames.map(name =>
castPropertyToWhereClauseConditional({
name,
definition: entity.properties[name],
definition: entity.properties[name]!,
tableAlias: 's',
}),
);
Expand All @@ -61,7 +61,7 @@ export const defineFindOrCreateStaticEntityLogic = ({
// define the array properties, for which we'll need to insert into a mapping table
const staticArrayProperties = pickKeysFromObject({
object: entity.properties,
keep: (property) => !!property.array && !property.updatable,
keep: property => !!property.array && !property.updatable,
});
const mappingTableInserts = Object.entries(staticArrayProperties).map(
([name, definition]) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export const defineInsertVersionIfDynamicDataChangedLogic = ({

// define the column names and the column value references for the updatable properties
const updatablePropertyColumnNames = updatablePropertyNames.map((name) =>
castPropertyToColumnName({ name, definition: entity.properties[name] }),
castPropertyToColumnName({ name, definition: entity.properties[name]! }),
);
const updatablePropertyColumnValueReferences = updatablePropertyNames.map(
(name) =>
castPropertyToTableColumnValueReference({
name,
definition: entity.properties[name],
definition: entity.properties[name]!,
}),
);

Expand All @@ -35,7 +35,7 @@ export const defineInsertVersionIfDynamicDataChangedLogic = ({
(name) =>
castPropertyToWhereClauseConditional({
name,
definition: entity.properties[name],
definition: entity.properties[name]!,
tableAlias: 'v',
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sha256 from 'simple-sha256';
import uuidV4 from 'uuid/v4';
import { pg as prepare } from 'yesql';

import { normalizeCreateFunctionDdl } from '../../../../__nonpublished_modules__/postgres-show-create-ddl/showCreateFunction/normalizeCreateFunctionDdl';
import { getShowCreateFunction } from '../../../../__test_utils__/getShowCreateFunction';
import { uuid as uuidV4 } from '../../../../deps';
import { Entity, ValueObject } from '../../../../domain';
import * as prop from '../../../define/defineProperty';
import {
Expand Down Expand Up @@ -727,8 +727,8 @@ describe('generateEntityUpsert', () => {
// alter the languages its in and upsert it again
const updatedLanguageIds = [languageIds[2], languageIds[0]]; // drop middle, swap first and last
const updatedPosterUuids = [
movieProps.poster_uuids[1],
movieProps.poster_uuids[0],
movieProps.poster_uuids[1]!,
movieProps.poster_uuids[0]!,
]; // drop last, swap first and middle
const idAgain = await upsertMovie({
...movieProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe('castPropertyToWhereClauseConditional', () => {
it('should define the conditional accurately for a unit property', () => {
const definition = castPropertyToWhereClauseConditional({
name: 'creator_id',
definition: plan.properties.creator_id,
definition: plan.properties.creator_id!,
tableAlias: 't',
});
expect(definition).toMatchSnapshot();
});
it('should define the conditional accurately for a array property', () => {
const definition = castPropertyToWhereClauseConditional({
name: 'participant_ids',
definition: plan.properties.participant_ids,
definition: plan.properties.participant_ids!,
tableAlias: 't',
});
expect(definition).toContain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('generateMappingTablesForArrayProperties', () => {
properties,
});
expect(entityMappingTables.length).toEqual(1);
expect(entityMappingTables[0].name).toEqual('wrench_to_diameter');
expect(entityMappingTables[0]!.name).toEqual('wrench_to_diameter');
expect(generateTableMock).toHaveBeenCalledTimes(1);
expect(generateTableMock).toHaveBeenCalledWith({
tableName: 'wrench_to_diameter',
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('generateMappingTablesForArrayProperties', () => {
properties,
});
expect(entityMappingTables.length).toEqual(1);
expect(entityMappingTables[0].name).toEqual('wrench_version_to_tag'); // since updatable, only the version of a wrench points to a tag
expect(entityMappingTables[0]!.name).toEqual('wrench_version_to_tag'); // since updatable, only the version of a wrench points to a tag
expect(generateTableMock).toHaveBeenCalledTimes(1);
expect(generateTableMock).toHaveBeenCalledWith({
tableName: 'wrench_version_to_tag',
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('generateMappingTablesForArrayProperties', () => {
properties,
});
expect(entityMappingTables.length).toEqual(1);
expect(entityMappingTables[0].name).toEqual('wrench_to_diameter_uuid');
expect(entityMappingTables[0]!.name).toEqual('wrench_to_diameter_uuid');
expect(generateTableMock).toHaveBeenCalledTimes(1);
expect(generateTableMock).toHaveBeenCalledWith({
tableName: 'wrench_to_diameter_uuid',
Expand All @@ -103,7 +103,9 @@ describe('generateMappingTablesForArrayProperties', () => {
properties,
});
expect(entityMappingTables.length).toEqual(1);
expect(entityMappingTables[0].name).toEqual('wrench_version_to_tag_uuid'); // since updatable, only the version of a wrench points to a tag
expect(entityMappingTables[0]!.name).toEqual(
'wrench_version_to_tag_uuid',
); // since updatable, only the version of a wrench points to a tag
expect(generateTableMock).toHaveBeenCalledTimes(1);
expect(generateTableMock).toHaveBeenCalledWith({
tableName: 'wrench_version_to_tag_uuid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const generateTableForStaticProperties = ({
? 'uuid' // uuid is special case as we can be unique on it without user specifying it explicitly - so, if its uuid, we know its not going to need a name change
: castPropertyToColumnName({
name: propertyName,
definition: properties[propertyName],
definition: properties[propertyName]!,
}),
);
const tableSql = generateTable({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import uuid from 'uuid/v4';
import { pg as prepare } from 'yesql';

import {
DatabaseConnection,
getDatabaseConnection,
} from '../../../__test_utils__/databaseConnection';
import { uuid } from '../../../deps';
import { Entity, ValueObject } from '../../../domain';
import * as prop from '../../define/defineProperty';
import { createTablesForEntity, dropTablesForEntity } from '../__test_utils__';
Expand Down Expand Up @@ -377,7 +377,10 @@ describe('generateEntityViewCurrent', () => {
// update the entity dynamic properties
const updatedProps = {
...props,
wheel_ids: `{${wheelIds.split(',').slice(1, 2).join(',')}}`,
wheel_ids: `{${wheelIds
.split(',')
.slice(1, 2)
.join(',')}}`,
};
const idAgain = await upsertVehicle(updatedProps);
expect(idAgain).toEqual(id);
Expand Down
4 changes: 2 additions & 2 deletions src/logic/generate/entityViews/generateEntityCurrentView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export const generateEntityCurrentView = ({ entity }: { entity: Entity }) => {
castPropertyToSelector({
entityName: entity.name,
name,
definition: entity.properties[name],
definition: entity.properties[name]!,
}),
);
const updateablePropertySelectors = updateablePropertyNames.map((name) =>
castPropertyToSelector({
entityName: entity.name,
name,
definition: entity.properties[name],
definition: entity.properties[name]!,
}),
);

Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"resolveJsonModule": true,
"sourceMap": true,
"outDir": "dist",
"useUnknownInCatchVariables": false,
"exactOptionalPropertyTypes": false,
"target": "es6",
},
"include": [
Expand Down

0 comments on commit 123208c

Please sign in to comment.