Skip to content

Commit

Permalink
Change some typescript compilation options and fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Jun 15, 2023
1 parent 3b62444 commit b8db72b
Show file tree
Hide file tree
Showing 175 changed files with 627 additions and 540 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
module.exports = {
parser: '@typescript-eslint/parser',

plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.cjs', 'dist', '*.exclude.*'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
},
root: true,
};
20 changes: 1 addition & 19 deletions backend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
module.exports = {
parser: '@typescript-eslint/parser',

parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin', 'require-extensions'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:require-extensions/recommended',
],
extends: ['../.eslintrc.cjs'],
root: false,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.cjs'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
9 changes: 1 addition & 8 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"migrate": "PICSUR_PRODUCTION=\"true\" yarn typeorm migration:generate -d ./src/datasource.ts",
"format": "prettier --write \"src/**/*.ts\"",
"clean": "rimraf dist",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"purge": "rm -rf dist && rm -rf node_modules"
},
"dependencies": {
Expand All @@ -40,10 +39,9 @@
"bcrypt": "^5.1.0",
"bmp-img": "^1.2.1",
"cors": "^2.8.5",
"eslint-plugin-require-extensions": "^0.1.3",
"file-type": "^18.5.0",
"is-docker": "^3.0.0",
"ms": "^2.1.3",
"ms": "3.0.0-canary.1",
"node-fetch": "^3.3.1",
"p-timeout": "^6.1.1",
"passport": "^0.6.0",
Expand Down Expand Up @@ -77,11 +75,6 @@
"@types/passport-strategy": "^0.2.35",
"@types/sharp": "^0.32.0",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.8",
"source-map-support": "^0.5.21",
"ts-loader": "^9.4.3",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const imageCorsConfig = cors({
const imageCorsOverride = (
req: IncomingMessage,
res: ServerResponse,
next: Function,
next: () => void,
) => {
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');

Expand Down
7 changes: 6 additions & 1 deletion backend/src/collections/apikey-db/apikey-db.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import {
AsyncFailable,
Fail,
FT,
HasFailed,
} from 'picsur-shared/dist/types/failable';
import { FindResult } from 'picsur-shared/dist/types/find-result';
import { generateRandomString } from 'picsur-shared/dist/util/random';
import { Repository } from 'typeorm';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/collections/image-db/image-db.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types';
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types/failable';
import { FindResult } from 'picsur-shared/dist/types/find-result';
import { generateRandomString } from 'picsur-shared/dist/util/random';
import { In, LessThan, Repository } from 'typeorm';
Expand Down
7 changes: 6 additions & 1 deletion backend/src/collections/image-db/image-file-db.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { ImageEntryVariant } from 'picsur-shared/dist/dto/image-entry-variant.enum';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import {
AsyncFailable,
Fail,
FT,
HasFailed,
} from 'picsur-shared/dist/types/failable';
import { LessThan, Repository } from 'typeorm';
import { EImageDerivativeBackend } from '../../database/entities/images/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/images/image-file.entity';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Failable,
FT,
HasFailed,
} from 'picsur-shared/dist/types';
} from 'picsur-shared/dist/types/failable';

type Enum = Record<string, string>;
type EnumValue<E> = E[keyof E];
Expand Down
17 changes: 11 additions & 6 deletions backend/src/collections/preference-db/sys-preference-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
SysPreferenceValidators,
SysPreferenceValueTypes,
} from 'picsur-shared/dist/dto/sys-preferences.enum';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import {
AsyncFailable,
Fail,
FT,
HasFailed,
} from 'picsur-shared/dist/types/failable';
import { Repository } from 'typeorm';
import {
ESysPreferenceBackend,
Expand All @@ -37,7 +42,7 @@ export class SysPreferenceDbService {
value: PrefValueType,
): AsyncFailable<DecodedSysPref> {
// Validate
let sysPreference = await this.encodeSysPref(key, value);
const sysPreference = await this.encodeSysPref(key, value);
if (HasFailed(sysPreference)) return sysPreference;

// Set
Expand All @@ -60,7 +65,7 @@ export class SysPreferenceDbService {

public async getPreference(key: string): AsyncFailable<DecodedSysPref> {
// Validate
let validatedKey = this.prefCommon.validatePrefKey(key, SysPreference);
const validatedKey = this.prefCommon.validatePrefKey(key, SysPreference);
if (HasFailed(validatedKey)) return validatedKey;

// See the comment in 'mutex-fallback.ts' for why we are using a mutex here
Expand Down Expand Up @@ -112,7 +117,7 @@ export class SysPreferenceDbService {
key: string,
type: PrefValueTypeStrings,
): AsyncFailable<PrefValueType> {
let pref = await this.getPreference(key);
const pref = await this.getPreference(key);
if (HasFailed(pref)) return pref;
if (pref.type !== type)
return Fail(FT.UsrValidation, 'Invalid preference type');
Expand All @@ -122,7 +127,7 @@ export class SysPreferenceDbService {

public async getAllPreferences(): AsyncFailable<DecodedSysPref[]> {
// TODO: We are fetching each value invidually, we should fetch all at once
let internalSysPrefs = await Promise.all(
const internalSysPrefs = await Promise.all(
SysPreferenceList.map((key) => this.getPreference(key)),
);
if (internalSysPrefs.some((pref) => HasFailed(pref))) {
Expand Down Expand Up @@ -158,7 +163,7 @@ export class SysPreferenceDbService {
return Fail(FT.UsrValidation, undefined, valueValidated.error);
}

let verifySysPreference = new ESysPreferenceBackend();
const verifySysPreference = new ESysPreferenceBackend();
verifySysPreference.key = validated.key;
verifySysPreference.value = validated.value;

Expand Down
17 changes: 11 additions & 6 deletions backend/src/collections/preference-db/usr-preference-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
UsrPreferenceValidators,
UsrPreferenceValueTypes,
} from 'picsur-shared/dist/dto/usr-preferences.enum';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import {
AsyncFailable,
Fail,
FT,
HasFailed,
} from 'picsur-shared/dist/types/failable';
import { Repository } from 'typeorm';
import {
EUsrPreferenceBackend,
Expand All @@ -38,7 +43,7 @@ export class UsrPreferenceDbService {
value: PrefValueType,
): AsyncFailable<DecodedUsrPref> {
// Validate
let usrPreference = await this.encodeUsrPref(userid, key, value);
const usrPreference = await this.encodeUsrPref(userid, key, value);
if (HasFailed(usrPreference)) return usrPreference;

// Set
Expand Down Expand Up @@ -66,7 +71,7 @@ export class UsrPreferenceDbService {
key: string,
): AsyncFailable<DecodedUsrPref> {
// Validate
let validatedKey = this.prefCommon.validatePrefKey(key, UsrPreference);
const validatedKey = this.prefCommon.validatePrefKey(key, UsrPreference);
if (HasFailed(validatedKey)) return validatedKey;

// See the comment in 'mutex-fallback.ts' for why we are using a mutex here
Expand Down Expand Up @@ -145,7 +150,7 @@ export class UsrPreferenceDbService {
key: string,
type: PrefValueTypeStrings,
): AsyncFailable<PrefValueType> {
let pref = await this.getPreference(userid, key);
const pref = await this.getPreference(userid, key);
if (HasFailed(pref)) return pref;
if (pref.type !== type)
return Fail(FT.UsrValidation, 'Invalid preference type');
Expand All @@ -157,7 +162,7 @@ export class UsrPreferenceDbService {
userid: string,
): AsyncFailable<DecodedUsrPref[]> {
// TODO: We are fetching each value invidually, we should fetch all at once
let internalSysPrefs = await Promise.all(
const internalSysPrefs = await Promise.all(
UsrPreferenceList.map((key) => this.getPreference(userid, key)),
);
if (internalSysPrefs.some((pref) => HasFailed(pref))) {
Expand Down Expand Up @@ -199,7 +204,7 @@ export class UsrPreferenceDbService {
return Fail(FT.UsrValidation, undefined, valueValidated.error);
}

let verifySysPreference = new EUsrPreferenceBackend();
const verifySysPreference = new EUsrPreferenceBackend();
verifySysPreference.key = validated.key;
verifySysPreference.value = validated.value;
verifySysPreference.user_id = userid;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/collections/role-db/role-db.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger, Module, OnModuleInit } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { HasFailed } from 'picsur-shared/dist/types';
import { HasFailed } from 'picsur-shared/dist/types/failable';
import { EarlyConfigModule } from '../../config/early/early-config.module';
import { HostConfigService } from '../../config/early/host.config.service';
import { ERoleBackend } from '../../database/entities/users/role.entity';
Expand Down
8 changes: 4 additions & 4 deletions backend/src/collections/role-db/role-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FT,
HasFailed,
HasSuccess,
} from 'picsur-shared/dist/types';
} from 'picsur-shared/dist/types/failable';
import { makeUnique } from 'picsur-shared/dist/util/unique';
import { In, Repository } from 'typeorm';
import { ERoleBackend } from '../../database/entities/users/role.entity';
Expand All @@ -33,7 +33,7 @@ export class RoleDbService {
if (await this.exists(name))
return Fail(FT.Conflict, 'Role already exists');

let role = new ERoleBackend();
const role = new ERoleBackend();
role.name = name;
role.permissions = permissions;

Expand Down Expand Up @@ -105,7 +105,7 @@ export class RoleDbService {
role: string | ERoleBackend,
permissions: Permissions,
// Extra bypass for internal use
allowImmutable: boolean = false,
allowImmutable = false,
): AsyncFailable<ERoleBackend> {
const roleToModify = await this.resolve(role);
if (HasFailed(roleToModify)) return roleToModify;
Expand Down Expand Up @@ -166,7 +166,7 @@ export class RoleDbService {
return HasSuccess(await this.findOne(name));
}

public async nukeSystemRoles(IAmSure: boolean = false): AsyncFailable<true> {
public async nukeSystemRoles(IAmSure = false): AsyncFailable<true> {
if (!IAmSure)
return Fail(
FT.SysValidation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types';
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types/failable';
import { Repository } from 'typeorm';
import { ESystemStateBackend } from '../../database/entities/system/system-state.entity';

Expand Down
2 changes: 1 addition & 1 deletion backend/src/collections/user-db/user-db.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger, Module, OnModuleInit } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { HasFailed } from 'picsur-shared/dist/types';
import { HasFailed } from 'picsur-shared/dist/types/failable';
import { generateRandomString } from 'picsur-shared/dist/util/random';
import { AuthConfigService } from '../../config/early/auth.config.service';
import { EarlyConfigModule } from '../../config/early/early-config.module';
Expand Down
6 changes: 3 additions & 3 deletions backend/src/collections/user-db/user-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
FT,
HasFailed,
HasSuccess,
} from 'picsur-shared/dist/types';
} from 'picsur-shared/dist/types/failable';
import { FindResult } from 'picsur-shared/dist/types/find-result';
import { makeUnique } from 'picsur-shared/dist/util/unique';
import { Repository } from 'typeorm';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class UserDbService {
const strength = await this.getBCryptStrength();
const hashedPassword = await bcrypt.hash(password, strength);

let user = new EUserBackend();
const user = new EUserBackend();
user.username = username;
user.hashed_password = hashedPassword;
if (byPassRoleCheck) {
Expand Down Expand Up @@ -208,7 +208,7 @@ export class UserDbService {
username: string,
// Also fetch fields that aren't normally sent to the client
// (e.g. hashed password)
getPrivate: boolean = false,
getPrivate = false,
): AsyncFailable<EUserBackend> {
try {
const found = await this.usersRepository.findOne({
Expand Down
8 changes: 4 additions & 4 deletions backend/src/config/early/type-orm.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
import { ParseInt, ParseString } from 'picsur-shared/dist/util/parse-simple';
import { EntityList } from '../../database/entities';
import { MigrationList } from '../../database/migrations';
import { EntityList } from '../../database/entities/index';
import { MigrationList } from '../../database/migrations/index';
import { DefaultName, EnvPrefix } from '../config.static';
import { HostConfigService } from './host.config.service';

Expand Down Expand Up @@ -48,10 +48,10 @@ export class TypeOrmConfigService implements TypeOrmOptionsFactory {
return varOptions;
}

public createTypeOrmOptions(connectionName?: string) {
public createTypeOrmOptions() {
const varOptions = this.getTypeOrmServerOptions();
return {
type: 'postgres' as 'postgres',
type: 'postgres' as const,
synchronize: !this.hostService.isProduction(),

migrationsRun: true,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/late/info.config.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { SysPreference } from 'picsur-shared/dist/dto/sys-preferences.enum';
import { HasFailed } from 'picsur-shared/dist/types';
import { HasFailed } from 'picsur-shared/dist/types/failable';
import { SysPreferenceDbService } from '../../collections/preference-db/sys-preference-db.service';

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/late/jwt.config.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FactoryProvider, Injectable, Logger } from '@nestjs/common';
import { JwtModuleOptions, JwtOptionsFactory } from '@nestjs/jwt';
import ms from 'ms';
import { ThrowIfFailed } from 'picsur-shared/dist/types';
import { ThrowIfFailed } from 'picsur-shared/dist/types/failable';
import { SysPreferenceDbService } from '../../collections/preference-db/sys-preference-db.service';

@Injectable()
Expand Down
7 changes: 6 additions & 1 deletion backend/src/config/late/usage.config.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Injectable } from '@nestjs/common';
import { SysPreference } from 'picsur-shared/dist/dto/sys-preferences.enum';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import {
AsyncFailable,
Fail,
FT,
HasFailed,
} from 'picsur-shared/dist/types/failable';
import { URLRegex, UUIDRegex } from 'picsur-shared/dist/util/common-regex';
import { SysPreferenceDbService } from '../../collections/preference-db/sys-preference-db.service';
import { ReportInterval, ReportUrl } from '../config.static';
Expand Down
Loading

0 comments on commit b8db72b

Please sign in to comment.