Skip to content

Commit

Permalink
chore: upgrade typescript and lint (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman authored Nov 21, 2024
1 parent 27a358d commit ae3a6c5
Show file tree
Hide file tree
Showing 22 changed files with 637 additions and 237 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
project: './tsconfig.json',
},
rules: {
'no-void': ['warn', { allowAsStatement: true }],
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
Expand Down Expand Up @@ -43,5 +44,15 @@ module.exports = {
'@typescript-eslint/no-dupe-class-members': ['error'],
},
},
{
files: ['**/__tests__/**/*.ts', '**/__tests__/**/*.tsx', '**/__tests__/**/*.d.ts'],
parserOptions: {
project: './tsconfig.json',
},
rules: {
// ts-mockito verify function needs void functions within verify which is a void function
'@typescript-eslint/no-confusing-void-expression': 'off',
},
},
],
};
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
"@types/node": "^20.14.1",
"@types/uuid": "^8.3.0",
"barrelsby": "^2.8.1",
"eslint": "^8.56.0",
"eslint-config-universe": "^13.0.0",
"eslint": "^8.57.1",
"eslint-config-universe": "^14.0.0",
"eslint-plugin-tsdoc": "^0.3.0",
"ioredis": "^5.4.1",
"jest": "^29.7.0",
"lerna": "^5.4.0",
"lru-cache": "^6.0.0",
"nullthrows": "^1.1.1",
"pg": "8.12.0",
"prettier": "^3.3.2",
"pg": "8.13.1",
"prettier": "^3.3.3",
"ts-jest": "^29.1.5",
"ts-mockito": "^2.6.1",
"typedoc": "^0.26.2",
"typescript": "^5.5.4",
"typedoc": "^0.26.11",
"typescript": "^5.6.3",
"uuid": "^8.3.0"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class LocalMemoryCacheAdapterProvider implements IEntityCacheAdap
);
}

private localMemoryCacheAdapterMap = new Map<string, GenericEntityCacheAdapter<any>>();
private readonly localMemoryCacheAdapterMap = new Map<string, GenericEntityCacheAdapter<any>>();

private constructor(
private readonly localMemoryCacheCreator: <TFields>() => LocalMemoryCache<TFields>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import wrapNativeRedisCallAsync from '../wrapNativeRedisCallAsync';
describe(wrapNativeRedisCallAsync, () => {
it('rethrows literals', async () => {
const throwingFn = async (): Promise<void> => {
// eslint-disable-next-line no-throw-literal,@typescript-eslint/no-throw-literal
// eslint-disable-next-line no-throw-literal,@typescript-eslint/only-throw-error
throw 'hello';
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import wrapNativePostgresCallAsync from '../wrapNativePostgresCallAsync';
describe(wrapNativePostgresCallAsync, () => {
it('rethrows literals', async () => {
const throwingFn = async (): Promise<void> => {
// eslint-disable-next-line no-throw-literal,@typescript-eslint/no-throw-literal
// eslint-disable-next-line no-throw-literal,@typescript-eslint/only-throw-error
throw 'hello';
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class ThrowConditionallyTrigger extends EntityMutationTrigger<
PostgresTriggerTestEntity
> {
constructor(
private fieldName: keyof PostgresTriggerTestEntityFields,
private badValue: string,
private readonly fieldName: keyof PostgresTriggerTestEntityFields,
private readonly badValue: string,
) {
super();
}
Expand Down Expand Up @@ -147,8 +147,8 @@ class ThrowConditionallyNonTransactionalTrigger extends EntityNonTransactionalMu
PostgresTriggerTestEntity
> {
constructor(
private fieldName: keyof PostgresTriggerTestEntityFields,
private badValue: string,
private readonly fieldName: keyof PostgresTriggerTestEntityFields,
private readonly badValue: string,
) {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class ThrowConditionallyTrigger extends EntityMutationTrigger<
PostgresValidatorTestEntity
> {
constructor(
private fieldName: keyof PostgresValidatorTestEntityFields,
private badValue: string,
private readonly fieldName: keyof PostgresValidatorTestEntityFields,
private readonly badValue: string,
) {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class InMemoryDatabaseAdapter<T extends Record<string, any>> extends EntityDatab
...dbObjects[objectIndex],
...object,
};
return [dbObjects[objectIndex]!];
return [dbObjects[objectIndex]];
}

protected async deleteInternalAsync(
Expand Down
2 changes: 1 addition & 1 deletion packages/entity-example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ async function mainAsync(): Promise<void> {
app.listen(3000);
}

mainAsync();
void mainAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class AuthorizationResultBasedEntityLoader<
entityResultsForFieldValue !== undefined,
`${fieldValue} should be guaranteed to be present in returned map of entities`,
);
return entityResultsForFieldValue!;
return entityResultsForFieldValue;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions packages/entity/src/EntityCompanionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ export default class EntityCompanionProvider {
*/
constructor(
public readonly metricsAdapter: IEntityMetricsAdapter,
private databaseAdapterFlavors: ReadonlyMap<
private readonly databaseAdapterFlavors: ReadonlyMap<
DatabaseAdapterFlavor,
DatabaseAdapterFlavorDefinition
>,
private cacheAdapterFlavors: ReadonlyMap<CacheAdapterFlavor, CacheAdapterFlavorDefinition>,
private readonly cacheAdapterFlavors: ReadonlyMap<
CacheAdapterFlavor,
CacheAdapterFlavorDefinition
>,
readonly globalMutationTriggers: EntityMutationTriggerConfiguration<
any,
any,
Expand Down
2 changes: 1 addition & 1 deletion packages/entity/src/EntityMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ export class DeleteMutator<
* Convenience method that throws upon delete failure.
*/
async enforceDeleteAsync(): Promise<void> {
return await enforceAsyncResult(this.deleteAsync());
await enforceAsyncResult(this.deleteAsync());
}

private async deleteInTransactionAsync(
Expand Down
8 changes: 4 additions & 4 deletions packages/entity/src/__tests__/EntityCommonUseCases-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ it('runs through a common workflow', async () => {
const vc2 = new TestUserViewerContext(entityCompanionProvider, uuidv4());

const blahOwner1 = await enforceAsyncResult(
BlahEntity.creator(vc1).setField('ownerID', vc1.getUserID()!).createAsync(),
BlahEntity.creator(vc1).setField('ownerID', vc1.getUserID()).createAsync(),
);

await enforceAsyncResult(
BlahEntity.creator(vc1).setField('ownerID', vc1.getUserID()!).createAsync(),
BlahEntity.creator(vc1).setField('ownerID', vc1.getUserID()).createAsync(),
);

const blahOwner2 = await enforceAsyncResult(
BlahEntity.creator(vc2).setField('ownerID', vc2.getUserID()!).createAsync(),
BlahEntity.creator(vc2).setField('ownerID', vc2.getUserID()).createAsync(),
);

// sanity check created objects
Expand All @@ -149,7 +149,7 @@ it('runs through a common workflow', async () => {
const results = await enforceResultsAsync(
BlahEntity.loader(vc1)
.withAuthorizationResults()
.loadManyByFieldEqualingAsync('ownerID', vc1.getUserID()!),
.loadManyByFieldEqualingAsync('ownerID', vc1.getUserID()),
);
expect(results).toHaveLength(2);

Expand Down
2 changes: 1 addition & 1 deletion packages/entity/src/__tests__/EntityCompanion-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe(EntityCompanion, () => {

expect(mergedTriggers).toStrictEqual({
afterCreate: [localTriggers!.afterCreate![0], globalMutationTriggers.afterCreate![0]],
afterAll: [localTriggers!.afterAll![0], globalMutationTriggers!.afterAll![0]],
afterAll: [localTriggers!.afterAll![0], globalMutationTriggers.afterAll![0]],
afterCommit: [localTriggers!.afterCommit![0]],
});
});
Expand Down
12 changes: 6 additions & 6 deletions packages/entity/src/__tests__/EntityDatabaseAdapter-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { FieldTransformerMap } from '../internal/EntityFieldTransformationUtils'
import { TestFields, testEntityConfiguration } from '../testfixtures/TestEntity';

class TestEntityDatabaseAdapter extends EntityDatabaseAdapter<TestFields> {
private fetchResults: object[];
private insertResults: object[];
private updateResults: object[];
private fetchEqualityConditionResults: object[];
private fetchRawWhereResults: object[];
private deleteCount: number;
private readonly fetchResults: object[];
private readonly insertResults: object[];
private readonly updateResults: object[];
private readonly fetchEqualityConditionResults: object[];
private readonly fetchRawWhereResults: object[];
private readonly deleteCount: number;

constructor({
fetchResults = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class TestEntity extends Entity<
selectedFields: Readonly<TestFields>;
}) {
if (constructorParams.selectedFields.id === ID_SENTINEL_THROW_LITERAL) {
// eslint-disable-next-line no-throw-literal,@typescript-eslint/no-throw-literal
// eslint-disable-next-line no-throw-literal,@typescript-eslint/only-throw-error
throw 'hello';
} else if (constructorParams.selectedFields.id === ID_SENTINEL_THROW_ERROR) {
throw new Error('world');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getDatabaseFieldForEntityField = <TFields extends Record<string, an
): string => {
const databaseField = entityConfiguration.entityToDBFieldsKeyMapping.get(entityField);
invariant(databaseField, `database field mapping missing for ${String(entityField)}`);
return databaseField!;
return databaseField;
};

export const transformDatabaseObjectToFields = <TFields extends Record<string, any>>(
Expand Down Expand Up @@ -60,7 +60,7 @@ export const transformFieldsToDatabaseObject = <TFields extends Record<string, a
const val = fields[k]!;
const databaseKey = entityConfiguration.entityToDBFieldsKeyMapping.get(k as any);
invariant(databaseKey, `must be database key for field: ${k}`);
databaseObject[databaseKey!] = maybeTransformFieldValueToDatabaseValue(
databaseObject[databaseKey] = maybeTransformFieldValueToDatabaseValue(
entityConfiguration,
fieldTransformerMap,
k,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ describe(EntityDataManager, () => {
const cacheSpy = jest.spyOn(entityCache, 'readManyThroughAsync');

await entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'testIndexedField', [
objectInQuestion['testIndexedField']!,
objectInQuestion['testIndexedField'],
]);
await entityDataManager.invalidateObjectFieldsAsync(objectInQuestion);
await entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'testIndexedField', [
objectInQuestion['testIndexedField']!,
objectInQuestion['testIndexedField'],
]);

expect(dbSpy).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -345,11 +345,11 @@ describe(EntityDataManager, () => {
const cacheSpy = jest.spyOn(entityCache, 'readManyThroughAsync');

await entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'testIndexedField', [
objectInQuestion['testIndexedField']!,
objectInQuestion['testIndexedField'],
]);
await entityDataManager.invalidateObjectFieldsAsync(objectInQuestion);
await entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'customIdField', [
objectInQuestion['customIdField']!,
objectInQuestion['customIdField'],
]);

expect(dbSpy).toHaveBeenCalledTimes(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe(mapKeys, () => {
['hello', 'world'],
['amphibian', 'creature'],
]);
const map2 = await mapKeys(map, (k) => k.length);
const map2 = mapKeys(map, (k) => k.length);
expect(map2.size).toEqual(2);
expect(map2.get(5)).toEqual('world');
expect(map2.get(9)).toEqual('creature');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const describePrivacyPolicyRule = <
new Map(),
);

return describePrivacyPolicyRuleWithAsyncTestCase(privacyPolicyRule, {
describePrivacyPolicyRuleWithAsyncTestCase(privacyPolicyRule, {
allowCases: makeCasesMap(allowCases),
skipCases: makeCasesMap(skipCases),
denyCases: makeCasesMap(denyCases),
Expand Down
2 changes: 1 addition & 1 deletion packages/entity/src/utils/testing/StubDatabaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default class StubDatabaseAdapter<
...objectCollection[objectIndex],
...object,
};
return [objectCollection[objectIndex]!];
return [objectCollection[objectIndex]];
}

protected async deleteInternalAsync(
Expand Down
Loading

0 comments on commit ae3a6c5

Please sign in to comment.