mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Syntax fixes (#5367)
* Declare return types on functions And a very few other type related minor fixes * Minor syntax fixes * Remove unnecessary escape chars in regexes * Remove unnecessary awaits * Replace deprecated req.connection with req.socket * Replace deprecated upload with uploadOne * Remove unnecessary eslint-disable-next-line comments * Comment empty functions / catch or finally clauses * Fix irregular whitespaces * Add missing returns (null) * Remove unreachable code * A few logical fixes * Remove / Handle non-null assertions which are certainly unnecessary (e.g. in tests)
This commit is contained in:
@@ -53,7 +53,7 @@ export class AzureBlobWebServicesStorage extends Storage {
|
||||
/**
|
||||
* Prefixes the given filePath with the storage root location
|
||||
*/
|
||||
protected _fullPath(filePath: string) {
|
||||
protected _fullPath(filePath: string): string {
|
||||
return normalize(path.join(this.$root, filePath));
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ export class GoogleCloudStorage extends Storage {
|
||||
/**
|
||||
* Prefixes the given filePath with the storage root location
|
||||
*/
|
||||
protected _fullPath(filePath: string) {
|
||||
protected _fullPath(filePath: string): string {
|
||||
return normalize(path.join(this.$root, filePath));
|
||||
}
|
||||
|
||||
@@ -94,13 +94,13 @@ export class GoogleCloudStorage extends Storage {
|
||||
const result = await this._file(location).delete();
|
||||
return { raw: result, wasDeleted: true };
|
||||
} catch (e) {
|
||||
e = handleError(e, location);
|
||||
const error = handleError(e, location);
|
||||
|
||||
if (e instanceof FileNotFound) {
|
||||
if (error instanceof FileNotFound) {
|
||||
return { raw: undefined, wasDeleted: false };
|
||||
}
|
||||
|
||||
throw e;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ export class AmazonWebServicesS3Storage extends Storage {
|
||||
|
||||
constructor(config: AmazonWebServicesS3StorageConfig) {
|
||||
super();
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const S3 = require('aws-sdk/clients/s3');
|
||||
|
||||
this.$driver = new S3({
|
||||
@@ -56,7 +55,7 @@ export class AmazonWebServicesS3Storage extends Storage {
|
||||
/**
|
||||
* Prefixes the given filePath with the storage root location
|
||||
*/
|
||||
protected _fullPath(filePath: string) {
|
||||
protected _fullPath(filePath: string): string {
|
||||
return normalize(path.join(this.$root, filePath));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,13 +72,13 @@ export class LocalFileSystemStorage extends Storage {
|
||||
const result = await fse.unlink(this._fullPath(location));
|
||||
return { raw: result, wasDeleted: true };
|
||||
} catch (e) {
|
||||
e = handleError(e, location);
|
||||
const error = handleError(e, location);
|
||||
|
||||
if (e instanceof FileNotFound) {
|
||||
if (error instanceof FileNotFound) {
|
||||
return { raw: undefined, wasDeleted: false };
|
||||
}
|
||||
|
||||
throw e;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import Storage from './Storage';
|
||||
* Returns a boolean indication if stream param
|
||||
* is a readable stream or not.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function isReadableStream(stream: any): stream is NodeJS.ReadableStream {
|
||||
return (
|
||||
stream !== null &&
|
||||
|
||||
@@ -39,8 +39,6 @@ jest.mock('fs-extra', () => {
|
||||
errors.map = map;
|
||||
try {
|
||||
await handler();
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
errors.map = {};
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('Storage Manager', () => {
|
||||
const storageManager = new StorageManager({
|
||||
default: 'local',
|
||||
disks: {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error No driver
|
||||
local: {},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import { SchemaOverview } from '../types/overview';
|
||||
import { SchemaInspector } from '../types/schema';
|
||||
|
||||
export default class MySQL extends KnexMySQL implements SchemaInspector {
|
||||
async overview() {
|
||||
async overview(): Promise<SchemaOverview> {
|
||||
const columns = await this.knex.raw(
|
||||
`
|
||||
SELECT
|
||||
|
||||
@@ -4,7 +4,7 @@ import { SchemaInspector } from '../types/schema';
|
||||
import { mapKeys } from 'lodash';
|
||||
|
||||
export default class Oracle extends KnexOracle implements SchemaInspector {
|
||||
async overview() {
|
||||
async overview(): Promise<SchemaOverview> {
|
||||
type RawColumn = {
|
||||
TABLE_NAME: string;
|
||||
COLUMN_NAME: string;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { SchemaOverview } from '../types/overview';
|
||||
import { SchemaInspector } from '../types/schema';
|
||||
|
||||
export default class Postgres extends KnexPostgres implements SchemaInspector {
|
||||
async overview() {
|
||||
async overview(): Promise<SchemaOverview> {
|
||||
const [columnsResult, primaryKeysResult] = await Promise.all([
|
||||
// Only select columns from BASE TABLEs to exclude views (Postgres views
|
||||
// cannot have primary keys so they cannot be used)
|
||||
|
||||
@@ -12,7 +12,7 @@ type RawColumn = {
|
||||
};
|
||||
|
||||
export default class SQLite extends KnexSQLite implements SchemaInspector {
|
||||
async overview() {
|
||||
async overview(): Promise<SchemaOverview> {
|
||||
const tablesWithAutoIncrementPrimaryKeys = (
|
||||
await this.knex.select('name').from('sqlite_master').whereRaw(`sql LIKE "%AUTOINCREMENT%"`)
|
||||
).map(({ name }) => name);
|
||||
|
||||
@@ -33,7 +33,9 @@ export class Auth implements IAuth {
|
||||
this.refresher = new Debouncer(this.refreshToken.bind(this));
|
||||
try {
|
||||
this.updateRefresh(this.options?.refresh);
|
||||
} catch (err) {}
|
||||
} catch {
|
||||
// Ignore error
|
||||
}
|
||||
}
|
||||
|
||||
get token(): string | null {
|
||||
@@ -122,8 +124,12 @@ export class Auth implements IAuth {
|
||||
if (this.options.refresh!.auto) {
|
||||
this.timer = setTimeout(() => {
|
||||
this.refresh()
|
||||
.then(() => {})
|
||||
.catch((_) => {});
|
||||
.then(() => {
|
||||
// Do nothing
|
||||
})
|
||||
.catch(() => {
|
||||
// Do nothing
|
||||
});
|
||||
}, remaining);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export class ActivityHandler<T = DefaultType> extends ItemsHandler<ActivityItem<
|
||||
this._comments = new CommentsHandler(this.transport);
|
||||
}
|
||||
|
||||
get comments() {
|
||||
get comments(): CommentsHandler<T> {
|
||||
return this._comments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class ExtensionHandler {
|
||||
this.transport = transport;
|
||||
}
|
||||
|
||||
endpoint(name: string) {
|
||||
endpoint(name: string): ExtensionEndpoint {
|
||||
return new ExtensionEndpoint(this.transport, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@ export class GraphQLHandler {
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
async items<T>(query: string, variables?: any): Promise<TransportResponse<T>> {
|
||||
return await this.request('/graphql', query, variables);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
async system<T>(query: string, variables?: any): Promise<TransportResponse<T>> {
|
||||
return await this.request('/graphql/system', query, variables);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IStorage } from '../../../src/storage';
|
||||
|
||||
export function createStorageTests(createStorage: () => IStorage) {
|
||||
return function () {
|
||||
return function (): void {
|
||||
beforeEach(() => {
|
||||
// These run both in node and browser mode
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
|
||||
@@ -77,11 +77,11 @@ describe('axios transport', function () {
|
||||
} catch (err) {
|
||||
const terr = err as TransportError;
|
||||
expect(terr).toBeInstanceOf(TransportError);
|
||||
expect(terr.response!.status).toBe(403);
|
||||
expect(terr.response?.status).toBe(403);
|
||||
expect(terr.message).toBe('You don\'t have permission access to "contacts" collection.');
|
||||
expect(terr.errors.length).toBe(1);
|
||||
expect(terr.errors[0]!.message).toBe('You don\'t have permission access to "contacts" collection.');
|
||||
expect(terr.errors[0]!.extensions?.code).toBe('FORBIDDEN');
|
||||
expect(terr.errors[0]?.message).toBe('You don\'t have permission access to "contacts" collection.');
|
||||
expect(terr.errors[0]?.extensions?.code).toBe('FORBIDDEN');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -101,7 +101,7 @@ describe('axios transport', function () {
|
||||
expect(terr.response).toBeUndefined();
|
||||
expect(terr.message).toBe('Random error');
|
||||
expect(terr.parent).not.toBeUndefined();
|
||||
expect(terr.parent!.message).toBe('Random error');
|
||||
expect(terr.parent?.message).toBe('Random error');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -129,7 +129,7 @@ describe('axios transport', function () {
|
||||
expect(terr.response).toBeUndefined();
|
||||
expect(terr.message).toBe('this is not an axios error');
|
||||
expect(terr.parent).not.toBeUndefined();
|
||||
expect(terr.parent!.message).toBe('this is not an axios error');
|
||||
expect(terr.parent?.message).toBe('this is not an axios error');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('utils', function () {
|
||||
const sdk = new Directus(url);
|
||||
const hash = await sdk.utils.hash.generate('wolfulus');
|
||||
|
||||
expect(hash.substr(0, 7)).toBe('$argon2');
|
||||
expect(hash?.substr(0, 7)).toBe('$argon2');
|
||||
});
|
||||
|
||||
test(`hash verify`, async (url, nock) => {
|
||||
@@ -54,7 +54,7 @@ describe('utils', function () {
|
||||
const sdk = new Directus(url);
|
||||
const hash = await sdk.utils.hash.generate('wolfulus');
|
||||
|
||||
expect(hash.substr(0, 7)).toBe('$argon2');
|
||||
expect(hash?.substr(0, 7)).toBe('$argon2');
|
||||
|
||||
nock()
|
||||
.post('/utils/hash/verify')
|
||||
@@ -64,7 +64,7 @@ describe('utils', function () {
|
||||
};
|
||||
});
|
||||
|
||||
const result = await sdk.utils.hash.verify('wolfulus', hash);
|
||||
const result = await sdk.utils.hash.verify('wolfulus', hash || '');
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
@@ -23,9 +23,9 @@ describe('items', function () {
|
||||
|
||||
expect(item).not.toBeNull();
|
||||
expect(item).not.toBeUndefined();
|
||||
expect(item!.id).toBe(1);
|
||||
expect(item!.title).toBe(`My first post`);
|
||||
expect(item!.body).toBe('<h1>Hey there!</h1>');
|
||||
expect(item?.id).toBe(1);
|
||||
expect(item?.title).toBe(`My first post`);
|
||||
expect(item?.body).toBe('<h1>Hey there!</h1>');
|
||||
});
|
||||
|
||||
test(`should encode ids`, async (url, nock) => {
|
||||
@@ -43,8 +43,8 @@ describe('items', function () {
|
||||
|
||||
expect(item).not.toBeNull();
|
||||
expect(item).not.toBeUndefined();
|
||||
expect(item!.slug).toBe('double slash');
|
||||
expect(item!.name).toBe('Double Slash');
|
||||
expect(item?.slug).toBe('double slash');
|
||||
expect(item?.name).toBe('Double Slash');
|
||||
});
|
||||
|
||||
test(`can get multiple items by id`, async (url, nock) => {
|
||||
@@ -70,14 +70,14 @@ describe('items', function () {
|
||||
const sdk = new Directus<Blog>(url);
|
||||
const items = await sdk.items('posts').readMany();
|
||||
|
||||
expect(items.data![0]).toMatchObject({
|
||||
expect(items.data?.[0]).toMatchObject({
|
||||
id: 1,
|
||||
title: 'My first post',
|
||||
body: '<h1>Hey there!</h1>',
|
||||
published: false,
|
||||
});
|
||||
|
||||
expect(items.data![1]).toMatchObject({
|
||||
expect(items.data?.[1]).toMatchObject({
|
||||
id: 2,
|
||||
title: 'My second post',
|
||||
body: '<h1>Hey there!</h1>',
|
||||
@@ -109,13 +109,13 @@ describe('items', function () {
|
||||
fields: ['id', 'title'],
|
||||
});
|
||||
|
||||
expect(items.data![0]!.id).toBe(1);
|
||||
expect(items.data![0]!.title).toBe(`My first post`);
|
||||
expect(items.data![0]!.body).toBeUndefined();
|
||||
expect(items.data?.[0]?.id).toBe(1);
|
||||
expect(items.data?.[0]?.title).toBe(`My first post`);
|
||||
expect(items.data?.[0]?.body).toBeUndefined();
|
||||
|
||||
expect(items.data![1]!.id).toBe(2);
|
||||
expect(items.data![1]!.title).toBe(`My second post`);
|
||||
expect(items.data![1]!.body).toBeUndefined();
|
||||
expect(items.data?.[1]?.id).toBe(2);
|
||||
expect(items.data?.[1]?.title).toBe(`My second post`);
|
||||
expect(items.data?.[1]?.body).toBeUndefined();
|
||||
});
|
||||
|
||||
test(`create one item`, async (url, nock) => {
|
||||
@@ -179,14 +179,14 @@ describe('items', function () {
|
||||
},
|
||||
]);
|
||||
|
||||
expect(items.data![0]).toMatchObject({
|
||||
expect(items.data?.[0]).toMatchObject({
|
||||
id: 4,
|
||||
title: 'New post 2',
|
||||
body: 'This is a new post 2',
|
||||
published: false,
|
||||
});
|
||||
|
||||
expect(items.data![1]).toMatchObject({
|
||||
expect(items.data?.[1]).toMatchObject({
|
||||
id: 5,
|
||||
title: 'New post 3',
|
||||
body: 'This is a new post 3',
|
||||
@@ -256,14 +256,14 @@ describe('items', function () {
|
||||
},
|
||||
]);
|
||||
|
||||
expect(item.data![0]).toMatchObject({
|
||||
expect(item.data?.[0]).toMatchObject({
|
||||
id: 1,
|
||||
title: 'Updated post',
|
||||
body: 'Updated post content',
|
||||
published: true,
|
||||
});
|
||||
|
||||
expect(item.data![1]).toMatchObject({
|
||||
expect(item.data?.[1]).toMatchObject({
|
||||
id: 2,
|
||||
title: 'Updated post 2',
|
||||
body: 'Updated post content 2',
|
||||
|
||||
@@ -36,9 +36,9 @@ describe('singleton', function () {
|
||||
|
||||
expect(settings).not.toBeNull();
|
||||
expect(settings).not.toBeUndefined();
|
||||
expect(settings!.url).toBe('http://website.com');
|
||||
expect(settings!.title).toBe(`Website Title`);
|
||||
expect(settings!.show_menu).toBe(true);
|
||||
expect(settings?.url).toBe('http://website.com');
|
||||
expect(settings?.title).toBe(`Website Title`);
|
||||
expect(settings?.show_menu).toBe(true);
|
||||
});
|
||||
|
||||
test(`can update an item`, async (url, nock) => {
|
||||
@@ -63,8 +63,8 @@ describe('singleton', function () {
|
||||
|
||||
expect(settings).not.toBeNull();
|
||||
expect(settings).not.toBeUndefined();
|
||||
expect(settings!.url).toBe('http://website.com');
|
||||
expect(settings!.title).toBe(`New Website Title`);
|
||||
expect(settings!.show_menu).toBe(true);
|
||||
expect(settings?.url).toBe('http://website.com');
|
||||
expect(settings?.title).toBe(`New Website Title`);
|
||||
expect(settings?.show_menu).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ export type TestSettings = {
|
||||
fixture?: string;
|
||||
};
|
||||
|
||||
export function test(name: string, test: Test, settings?: TestSettings) {
|
||||
export function test(name: string, test: Test, settings?: TestSettings): void {
|
||||
it(name, async () => {
|
||||
nock.cleanAll();
|
||||
|
||||
@@ -40,7 +40,7 @@ export async function timers(
|
||||
skip: (func: () => Promise<void>, date?: boolean) => Promise<any>;
|
||||
}) => Promise<void>,
|
||||
initial: number = Date.now()
|
||||
) {
|
||||
): Promise<void> {
|
||||
const originals = {
|
||||
setTimeout: global.setTimeout,
|
||||
setImmediate: global.setImmediate,
|
||||
|
||||
Reference in New Issue
Block a user