From 801e86855452bd32d49475d8b07ce151c11e962a Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Thu, 29 Apr 2021 15:55:12 -0400 Subject: [PATCH] Fix remaining eslint errors h/t @paescuj --- api/src/app.ts | 50 +++++----- api/src/cache.ts | 6 +- api/src/cli/commands/bootstrap/index.ts | 8 +- api/src/cli/commands/database/install.ts | 2 +- api/src/cli/commands/init/index.ts | 27 +++-- api/src/cli/commands/roles/create.ts | 2 +- api/src/cli/commands/users/create.ts | 12 ++- api/src/cli/commands/users/passwd.ts | 2 +- api/src/cli/index.ts | 13 ++- api/src/cli/utils/create-env/index.ts | 12 +-- api/src/cli/utils/drivers.ts | 2 +- api/src/controllers/activity.ts | 12 +-- api/src/controllers/assets.ts | 39 ++++---- api/src/controllers/auth.ts | 24 ++--- api/src/controllers/collections.ts | 4 +- api/src/controllers/extensions.ts | 4 +- api/src/controllers/fields.ts | 17 ++-- api/src/controllers/files.ts | 20 ++-- api/src/controllers/folders.ts | 8 +- api/src/controllers/graphql.ts | 6 +- api/src/controllers/items.ts | 10 +- api/src/controllers/not-found.ts | 3 +- api/src/controllers/permissions.ts | 10 +- api/src/controllers/presets.ts | 10 +- api/src/controllers/relations.ts | 10 +- api/src/controllers/revisions.ts | 6 +- api/src/controllers/roles.ts | 10 +- api/src/controllers/server.ts | 9 +- api/src/controllers/settings.ts | 6 +- api/src/controllers/users.ts | 10 +- api/src/controllers/utils.ts | 12 +-- api/src/controllers/webhooks.ts | 10 +- api/src/database/index.ts | 15 ++- .../20201029C-remove-system-fields.ts | 2 +- api/src/database/migrations/run.ts | 4 +- api/src/database/run-ast.ts | 16 +-- api/src/database/seeds/run.ts | 6 +- .../app-access-permissions/index.ts | 4 +- .../database/system-data/collections/index.ts | 2 +- api/src/database/system-data/fields/index.ts | 8 +- .../database/system-data/relations/index.ts | 2 +- api/src/env.ts | 11 +-- api/src/exceptions/database/dialects/mssql.ts | 5 +- api/src/exceptions/database/dialects/mysql.ts | 2 +- .../exceptions/database/dialects/postgres.ts | 2 +- .../exceptions/database/dialects/sqlite.ts | 2 +- api/src/exceptions/database/translate.ts | 6 +- api/src/exceptions/failed-validation.ts | 2 +- api/src/exceptions/forbidden.ts | 10 +- api/src/exceptions/range-not-satisfiable.ts | 2 +- api/src/extensions.ts | 23 +++-- api/src/middleware/authenticate.ts | 8 +- api/src/middleware/cache.ts | 7 +- api/src/middleware/check-ip.ts | 2 +- api/src/middleware/collection-exists.ts | 4 +- api/src/middleware/error-handler.ts | 6 +- api/src/middleware/graphql.ts | 6 +- api/src/middleware/rate-limiter.ts | 8 +- api/src/middleware/respond.ts | 10 +- api/src/middleware/validate-batch.ts | 2 +- api/src/rate-limiter.ts | 10 +- api/src/server.ts | 16 +-- api/src/services/activity.ts | 2 +- api/src/services/assets.ts | 12 +-- api/src/services/authentication.ts | 23 +++-- api/src/services/authorization.ts | 22 ++--- api/src/services/collections.ts | 20 ++-- api/src/services/fields.ts | 34 +++---- api/src/services/files.ts | 26 ++--- api/src/services/folders.ts | 2 +- api/src/services/graphql.ts | 99 +++++++++---------- api/src/services/items.ts | 41 ++++---- api/src/services/mail/index.ts | 17 ++-- api/src/services/mailer.ts | 2 +- api/src/services/meta.ts | 8 +- api/src/services/payload.ts | 53 +++++----- api/src/services/permissions.ts | 13 +-- api/src/services/presets.ts | 2 +- api/src/services/relations.ts | 10 +- api/src/services/revisions.ts | 4 +- api/src/services/roles.ts | 11 +-- api/src/services/server.ts | 20 ++-- api/src/services/settings.ts | 2 +- api/src/services/specifications.ts | 28 +++--- api/src/services/users.ts | 36 +++---- api/src/services/utils.ts | 6 +- api/src/services/webhooks.ts | 4 +- api/src/storage.ts | 15 ++- api/src/types/collection.ts | 2 +- api/src/types/express.d.ts | 5 +- api/src/types/extensions.ts | 8 +- api/src/types/graphql.ts | 2 +- api/src/types/schema.ts | 4 +- api/src/types/services.ts | 4 +- api/src/utils/apply-query.ts | 10 +- api/src/utils/async-handler.ts | 2 +- api/src/utils/deep-map.ts | 4 +- api/src/utils/generate-joi.ts | 6 +- api/src/utils/get-ast-from-query.ts | 16 +-- api/src/utils/get-config-from-env.ts | 2 +- api/src/utils/get-default-value.ts | 4 +- api/src/utils/get-local-type.ts | 4 +- api/src/utils/get-schema.ts | 15 ++- api/src/utils/merge-permissions.ts | 2 +- api/src/utils/parse-filter.ts | 4 +- api/src/utils/parse-iptc.ts | 16 +-- api/src/utils/reduce-schema.ts | 2 +- api/src/utils/sanitize-query.ts | 4 +- api/src/utils/track.ts | 10 +- api/src/utils/validate-env.ts | 4 +- api/src/utils/validate-query.ts | 6 +- api/src/webhooks.ts | 8 +- app/src/api.ts | 4 +- app/src/auth.ts | 4 +- app/src/components/register.ts | 33 +++---- app/src/components/v-card/index.ts | 6 +- app/src/components/v-dialog/v-dialog.vue | 2 - app/src/components/v-drawer/v-drawer.vue | 2 +- .../v-fancy-select/v-fancy-select.vue | 6 +- .../v-field-select/v-field-select.vue | 1 - .../v-field-template/v-field-template.vue | 3 - .../v-form/form-field-interface.vue | 2 +- app/src/components/v-form/form-field-menu.vue | 14 +-- app/src/components/v-form/v-form.vue | 2 +- .../v-icon/custom-icons/directus.vue | 8 +- .../components/v-icon/custom-icons/logout.vue | 8 +- .../v-icon/custom-icons/signal_wifi_1_bar.vue | 4 +- app/src/components/v-icon/v-icon.vue | 2 +- app/src/components/v-item-group/v-item.vue | 10 +- app/src/components/v-list/index.ts | 10 +- app/src/components/v-list/v-list-group.vue | 6 +- .../components/v-list/v-list-item-hint.vue | 2 +- app/src/components/v-list/v-list.vue | 2 +- app/src/components/v-menu/use-popper.ts | 11 +-- app/src/components/v-menu/v-menu.vue | 13 ++- app/src/components/v-overlay/v-overlay.vue | 2 +- .../components/v-pagination/v-pagination.vue | 5 +- app/src/components/v-table/v-table.vue | 4 +- app/src/components/v-tabs/index.ts | 4 +- app/src/components/v-tabs/v-tabs.vue | 2 +- app/src/components/v-upload/v-upload.vue | 2 +- app/src/composables/groupable/groupable.ts | 6 +- .../use-collection/use-collection.ts | 2 +- .../use-custom-selection.ts | 2 +- .../use-element-size/use-element-size.ts | 2 +- .../use-event-listener/use-event-listener.ts | 2 +- .../use-field-tree/use-field-tree.ts | 6 +- .../use-form-fields/use-form-fields.ts | 10 +- app/src/composables/use-item/use-item.ts | 10 +- app/src/composables/use-items/use-items.ts | 7 +- app/src/composables/use-permissions.ts | 6 +- app/src/composables/use-preset/use-preset.ts | 7 +- .../use-scroll-distance.ts | 4 +- .../composables/use-shortcut/use-shortcut.ts | 6 +- app/src/composables/use-template-data.ts | 5 +- .../use-time-from-now/use-time-from-now.ts | 2 +- app/src/composables/use-title/use-title.ts | 1 - .../use-window-size/use-window-size.ts | 2 +- app/src/directives/register.ts | 3 +- app/src/directives/tooltip/tooltip.ts | 2 +- app/src/displays/boolean/boolean.vue | 8 +- app/src/displays/color/color.vue | 2 +- app/src/displays/define.ts | 2 +- app/src/displays/mime-type/index.ts | 2 +- app/src/displays/register.ts | 6 +- app/src/displays/related-values/index.ts | 10 +- app/src/displays/related-values/options.vue | 2 - .../related-values/related-values.vue | 2 + app/src/displays/types.ts | 2 +- app/src/hydrate.ts | 19 ++-- app/src/interfaces/_system/field/field.vue | 3 +- .../interface-options/interface-options.vue | 2 +- .../_system/interface/interface.vue | 3 +- .../_system/system-language/index.ts | 2 +- .../system-language/system-language.vue | 2 +- app/src/interfaces/_system/tfa-setup/index.ts | 2 +- .../_system/tfa-setup/tfa-setup.vue | 2 +- app/src/interfaces/code/index.ts | 2 +- app/src/interfaces/define.ts | 2 +- app/src/interfaces/hash/hash.vue | 12 ++- app/src/interfaces/hash/index.ts | 2 +- app/src/interfaces/image/image.vue | 3 +- .../interfaces/m2a-builder/m2a-builder.vue | 4 +- .../interfaces/many-to-many/many-to-many.vue | 2 +- .../interfaces/many-to-many/use-actions.ts | 2 +- app/src/interfaces/many-to-many/use-edit.ts | 2 +- .../interfaces/many-to-many/use-preview.ts | 8 +- .../interfaces/many-to-many/use-relation.ts | 4 +- .../interfaces/many-to-many/use-selection.ts | 6 +- app/src/interfaces/many-to-many/use-sort.ts | 2 +- .../interfaces/many-to-one/many-to-one.vue | 9 +- app/src/interfaces/many-to-one/options.vue | 2 - .../markdown/composables/use-edit.ts | 26 ++--- app/src/interfaces/markdown/index.ts | 2 +- app/src/interfaces/numeric/index.ts | 2 +- app/src/interfaces/register.ts | 6 +- app/src/interfaces/repeater/index.ts | 2 +- app/src/interfaces/slider/index.ts | 2 +- app/src/interfaces/tags/index.ts | 2 +- app/src/interfaces/text-input/index.ts | 2 +- app/src/interfaces/textarea/index.ts | 2 +- app/src/interfaces/toggle/index.ts | 2 +- app/src/interfaces/translations/index.ts | 2 +- .../interfaces/translations/translations.vue | 2 +- app/src/interfaces/tree-view/index.ts | 2 +- app/src/interfaces/tree-view/item-preview.vue | 2 +- app/src/interfaces/tree-view/tree-view.vue | 3 +- app/src/interfaces/types.ts | 4 +- app/src/interfaces/user/index.ts | 2 +- app/src/interfaces/user/user.vue | 2 +- app/src/interfaces/wysiwyg/index.ts | 2 +- app/src/interfaces/wysiwyg/useImage.ts | 6 +- app/src/interfaces/wysiwyg/useLink.ts | 6 +- app/src/interfaces/wysiwyg/useMedia.ts | 6 +- app/src/interfaces/wysiwyg/useSourceCode.ts | 4 +- app/src/lang/index.ts | 6 +- app/src/lang/set-language.ts | 14 ++- app/src/layouts/define.ts | 2 +- app/src/layouts/register.ts | 4 +- app/src/layouts/types.ts | 3 +- app/src/main.ts | 35 +++---- .../modules/activity/routes/collection.vue | 8 +- app/src/modules/activity/routes/item.vue | 7 +- .../collections/components/navigation.vue | 6 +- .../collections/composables/use-navigation.ts | 3 +- app/src/modules/collections/index.ts | 6 +- app/src/modules/define.ts | 2 +- .../modules/docs/components/navigation.vue | 2 +- app/src/modules/docs/index.ts | 4 +- .../files/components/navigation-folder.vue | 2 +- .../modules/files/components/replace-file.vue | 7 +- app/src/modules/files/index.ts | 2 +- app/src/modules/register.ts | 8 +- .../settings/composables/use-project-info.ts | 6 +- app/src/modules/settings/index.ts | 34 +++---- .../field-detail/components/display.vue | 2 +- .../field-detail/components/field.vue | 2 +- .../field-detail/components/interface.vue | 4 +- .../components/relationship-m2m.vue | 2 +- .../field-detail/components/schema.vue | 2 +- .../field-detail/components/translations.vue | 5 +- .../routes/data-model/field-detail/store.ts | 12 +-- .../routes/data-model/new-collection.vue | 7 +- .../modules/settings/routes/presets/item.vue | 11 --- .../roles/item/composables/use-permissions.ts | 2 +- .../composables/use-update-permissions.ts | 2 +- .../settings/routes/roles/item/item.vue | 3 +- .../permissions-detail/components/actions.vue | 2 +- .../settings/routes/webhooks/collection.vue | 2 +- .../modules/settings/routes/webhooks/item.vue | 4 - app/src/modules/types.ts | 6 +- .../users/composables/use-navigation.ts | 3 +- app/src/modules/users/index.ts | 1 - app/src/plugins.ts | 4 +- app/src/router.ts | 13 ++- .../components/continue-as/continue-as.vue | 2 +- .../components/login-form/login-form.vue | 5 +- app/src/routes/logout/logout.vue | 2 +- app/src/stores/collections.ts | 8 +- app/src/stores/fields.ts | 12 +-- app/src/stores/notifications.ts | 4 +- app/src/stores/permissions.ts | 4 +- app/src/stores/presets.ts | 12 +-- app/src/stores/relations.ts | 4 +- app/src/stores/requests.ts | 2 +- app/src/stores/server.ts | 2 +- app/src/stores/settings.ts | 4 +- app/src/stores/user.ts | 3 +- app/src/types/index.ts | 12 +-- app/src/utils/abbreviate-number.ts | 6 +- .../adjust-fields-for-displays.ts | 4 +- app/src/utils/deep-map.ts | 2 +- .../filters-to-query/filters-to-query.ts | 3 +- app/src/utils/generate-joi/index.ts | 4 +- app/src/utils/hljs-graphql.ts | 2 +- .../localized-format-distance.ts | 2 +- .../localized-format/localized-format.ts | 2 +- app/src/utils/parse-filter.ts | 2 +- .../readable-mime-type/readable-mime-type.ts | 2 +- .../register-component/register-component.ts | 2 +- app/src/utils/unexpected-error.ts | 4 +- app/src/utils/upload-file/upload-file.ts | 3 +- app/src/utils/upload-files/upload-files.ts | 2 +- app/src/utils/user-name.ts | 2 +- .../comment-item-header.vue | 3 +- .../filter-sidebar-detail/field-list-item.vue | 5 +- .../module-bar-avatar/module-bar-avatar.vue | 2 - .../module-bar-logo/module-bar-logo.vue | 7 +- .../notification-dialogs.vue | 13 +-- .../notifications-preview.vue | 10 +- .../components/project-info/project-info.vue | 4 +- .../revisions-drawer-preview.vue | 7 +- .../revisions-drawer-updates-change.vue | 6 +- app/src/views/private/private-view.vue | 6 +- app/src/views/register.ts | 2 +- .../lib/check-requirements.js | 2 +- packages/create-directus-project/lib/index.js | 8 +- packages/drive/tests/StorageManager.test.ts | 2 +- packages/format-title/src/index.ts | 6 +- .../gatsby-source-directus/gatsby-node.js | 53 +++++----- packages/schema/src/dialects/oracledb.ts | 10 +- packages/schema/src/dialects/sqlite.ts | 2 +- packages/sdk/src/base/auth.ts | 4 +- packages/sdk/src/base/storage/localstorage.ts | 4 +- packages/sdk/src/base/storage/memory.ts | 2 +- packages/sdk/src/handlers/utils.ts | 2 +- packages/sdk/src/items.ts | 4 +- packages/sdk/tests/utils.ts | 2 +- 308 files changed, 1031 insertions(+), 1221 deletions(-) diff --git a/api/src/app.ts b/api/src/app.ts index 36022443b2..401af5bf6c 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -1,23 +1,10 @@ -import expressLogger from 'express-pino-logger'; -import cookieParser from 'cookie-parser'; import bodyParser from 'body-parser'; +import cookieParser from 'cookie-parser'; import express from 'express'; -import logger from './logger'; +import expressLogger from 'express-pino-logger'; +import fse from 'fs-extra'; import path from 'path'; import qs from 'qs'; - -import { validateDBConnection, isInstalled } from './database'; - -import { validateEnv } from './utils/validate-env'; -import env from './env'; -import { track } from './utils/track'; - -import errorHandler from './middleware/error-handler'; -import cors from './middleware/cors'; -import rateLimiter from './middleware/rate-limiter'; -import cache from './middleware/cache'; -import extractToken from './middleware/extract-token'; -import authenticate from './middleware/authenticate'; import activityRouter from './controllers/activity'; import assetsRouter from './controllers/assets'; import authRouter from './controllers/auth'; @@ -26,7 +13,9 @@ import extensionsRouter from './controllers/extensions'; import fieldsRouter from './controllers/fields'; import filesRouter from './controllers/files'; import foldersRouter from './controllers/folders'; +import graphqlRouter from './controllers/graphql'; import itemsRouter from './controllers/items'; +import notFoundHandler from './controllers/not-found'; import permissionsRouter from './controllers/permissions'; import presetsRouter from './controllers/presets'; import relationsRouter from './controllers/relations'; @@ -37,19 +26,24 @@ import settingsRouter from './controllers/settings'; import usersRouter from './controllers/users'; import utilsRouter from './controllers/utils'; import webhooksRouter from './controllers/webhooks'; -import graphqlRouter from './controllers/graphql'; -import schema from './middleware/schema'; - -import notFoundHandler from './controllers/not-found'; -import sanitizeQuery from './middleware/sanitize-query'; -import { checkIP } from './middleware/check-ip'; -import { InvalidPayloadException } from './exceptions'; - -import { initializeExtensions, registerExtensionEndpoints, registerExtensionHooks } from './extensions'; -import { register as registerWebhooks } from './webhooks'; +import { isInstalled, validateDBConnection } from './database'; import { emitAsyncSafe } from './emitter'; - -import fse from 'fs-extra'; +import env from './env'; +import { InvalidPayloadException } from './exceptions'; +import { initializeExtensions, registerExtensionEndpoints, registerExtensionHooks } from './extensions'; +import logger from './logger'; +import authenticate from './middleware/authenticate'; +import cache from './middleware/cache'; +import { checkIP } from './middleware/check-ip'; +import cors from './middleware/cors'; +import errorHandler from './middleware/error-handler'; +import extractToken from './middleware/extract-token'; +import rateLimiter from './middleware/rate-limiter'; +import sanitizeQuery from './middleware/sanitize-query'; +import schema from './middleware/schema'; +import { track } from './utils/track'; +import { validateEnv } from './utils/validate-env'; +import { register as registerWebhooks } from './webhooks'; export default async function createApp(): Promise { validateEnv(['KEY', 'SECRET']); diff --git a/api/src/cache.ts b/api/src/cache.ts index 52977ff95f..32e546e9ae 100644 --- a/api/src/cache.ts +++ b/api/src/cache.ts @@ -1,9 +1,9 @@ -import env from './env'; import Keyv, { Options } from 'keyv'; -import { validateEnv } from './utils/validate-env'; -import { getConfigFromEnv } from './utils/get-config-from-env'; import ms from 'ms'; +import env from './env'; import logger from './logger'; +import { getConfigFromEnv } from './utils/get-config-from-env'; +import { validateEnv } from './utils/validate-env'; let cache: Keyv | null = null; diff --git a/api/src/cli/commands/bootstrap/index.ts b/api/src/cli/commands/bootstrap/index.ts index 59e6efcd8f..7983ddcc53 100644 --- a/api/src/cli/commands/bootstrap/index.ts +++ b/api/src/cli/commands/bootstrap/index.ts @@ -1,9 +1,9 @@ +import { nanoid } from 'nanoid'; +import runMigrations from '../../../database/migrations/run'; +import installDatabase from '../../../database/seeds/run'; import env from '../../../env'; import logger from '../../../logger'; -import installDatabase from '../../../database/seeds/run'; -import runMigrations from '../../../database/migrations/run'; import { getSchema } from '../../../utils/get-schema'; -import { nanoid } from 'nanoid'; export default async function bootstrap(): Promise { logger.info('Initializing bootstrap...'); @@ -71,7 +71,7 @@ async function isDatabaseAvailable() { const tries = 5; const secondsBetweenTries = 5; - for (var i = 0; i < tries; i++) { + for (let i = 0; i < tries; i++) { if (await hasDatabaseConnection()) { return true; } diff --git a/api/src/cli/commands/database/install.ts b/api/src/cli/commands/database/install.ts index 24e52e669c..5f883b5eb9 100644 --- a/api/src/cli/commands/database/install.ts +++ b/api/src/cli/commands/database/install.ts @@ -1,6 +1,6 @@ import { Knex } from 'knex'; -import installSeeds from '../../../database/seeds/run'; import runMigrations from '../../../database/migrations/run'; +import installSeeds from '../../../database/seeds/run'; export default async function start(): Promise { const database = require('../../../database/index').default as Knex; diff --git a/api/src/cli/commands/init/index.ts b/api/src/cli/commands/init/index.ts index f46d342a1e..0388c3aae8 100644 --- a/api/src/cli/commands/init/index.ts +++ b/api/src/cli/commands/init/index.ts @@ -1,24 +1,21 @@ -import chalk from 'chalk'; -import inquirer from 'inquirer'; -import { databaseQuestions } from './questions'; -import { drivers, getDriverForClient } from '../../utils/drivers'; -import createEnv from '../../utils/create-env'; -import { v4 as uuidV4 } from 'uuid'; -import execa from 'execa'; -import ora from 'ora'; - import argon2 from 'argon2'; - -import runSeed from '../../../database/seeds/run'; -import runMigrations from '../../../database/migrations/run'; - -import createDBConnection, { Credentials } from '../../utils/create-db-connection'; +import chalk from 'chalk'; +import execa from 'execa'; +import inquirer from 'inquirer'; import { Knex } from 'knex'; +import ora from 'ora'; +import { v4 as uuidV4 } from 'uuid'; +import runMigrations from '../../../database/migrations/run'; +import runSeed from '../../../database/seeds/run'; +import createDBConnection, { Credentials } from '../../utils/create-db-connection'; +import createEnv from '../../utils/create-env'; +import { drivers, getDriverForClient } from '../../utils/drivers'; +import { databaseQuestions } from './questions'; export default async function init(): Promise { const rootPath = process.cwd(); - let { client } = await inquirer.prompt([ + const { client } = await inquirer.prompt([ { type: 'list', name: 'client', diff --git a/api/src/cli/commands/roles/create.ts b/api/src/cli/commands/roles/create.ts index 5f47545ec3..27b46ac8c4 100644 --- a/api/src/cli/commands/roles/create.ts +++ b/api/src/cli/commands/roles/create.ts @@ -1,6 +1,6 @@ import { getSchema } from '../../../utils/get-schema'; -export default async function rolesCreate({ name, admin }: any): Promise { +export default async function rolesCreate({ name, admin }: { name: string; admin: boolean }): Promise { const { default: database } = require('../../../database/index'); const { RolesService } = require('../../../services/roles'); diff --git a/api/src/cli/commands/users/create.ts b/api/src/cli/commands/users/create.ts index f2f727790f..e7c8392ee9 100644 --- a/api/src/cli/commands/users/create.ts +++ b/api/src/cli/commands/users/create.ts @@ -1,7 +1,15 @@ import { getSchema } from '../../../utils/get-schema'; -export default async function usersCreate({ email, password, role }: any): Promise { - const { default: database, schemaInspector } = require('../../../database/index'); +export default async function usersCreate({ + email, + password, + role, +}: { + email?: string; + password?: string; + role?: string; +}): Promise { + const { default: database } = require('../../../database/index'); const { UsersService } = require('../../../services/users'); if (!email || !password || !role) { diff --git a/api/src/cli/commands/users/passwd.ts b/api/src/cli/commands/users/passwd.ts index e28d7fc57f..fdf1d707ca 100644 --- a/api/src/cli/commands/users/passwd.ts +++ b/api/src/cli/commands/users/passwd.ts @@ -1,7 +1,7 @@ import argon2 from 'argon2'; import { getSchema } from '../../../utils/get-schema'; -export default async function usersPasswd({ email, password }: any): Promise { +export default async function usersPasswd({ email, password }: { email?: string; password?: string }): Promise { const { default: database } = require('../../../database/index'); const { UsersService } = require('../../../services/users'); diff --git a/api/src/cli/index.ts b/api/src/cli/index.ts index 48206eabd5..70a208c36a 100644 --- a/api/src/cli/index.ts +++ b/api/src/cli/index.ts @@ -1,18 +1,17 @@ #!/usr/bin/env node import program from 'commander'; - -const pkg = require('../../package.json'); - import start from '../start'; -import init from './commands/init'; +import bootstrap from './commands/bootstrap'; +import count from './commands/count'; import dbInstall from './commands/database/install'; import dbMigrate from './commands/database/migrate'; +import init from './commands/init'; +import rolesCreate from './commands/roles/create'; import usersCreate from './commands/users/create'; import usersPasswd from './commands/users/passwd'; -import rolesCreate from './commands/roles/create'; -import count from './commands/count'; -import bootstrap from './commands/bootstrap'; + +const pkg = require('../../package.json'); program.name('directus').usage('[command] [options]'); program.version(pkg.version, '-v, --version'); diff --git a/api/src/cli/utils/create-env/index.ts b/api/src/cli/utils/create-env/index.ts index 86845ce1cd..5a83bff927 100644 --- a/api/src/cli/utils/create-env/index.ts +++ b/api/src/cli/utils/create-env/index.ts @@ -1,11 +1,11 @@ -import { drivers } from '../drivers'; -import { Credentials } from '../create-db-connection'; -import { v4 as uuidv4 } from 'uuid'; -import { nanoid } from 'nanoid'; -import { Liquid } from 'liquidjs'; import fs from 'fs'; -import { promisify } from 'util'; +import { Liquid } from 'liquidjs'; +import { nanoid } from 'nanoid'; import path from 'path'; +import { promisify } from 'util'; +import { v4 as uuidv4 } from 'uuid'; +import { Credentials } from '../create-db-connection'; +import { drivers } from '../drivers'; const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); diff --git a/api/src/cli/utils/drivers.ts b/api/src/cli/utils/drivers.ts index f513c41b2a..94bae572e6 100644 --- a/api/src/cli/utils/drivers.ts +++ b/api/src/cli/utils/drivers.ts @@ -2,7 +2,7 @@ export const drivers = { pg: 'PostgreSQL / Redshift', mysql: 'MySQL / MariaDB / Aurora', sqlite3: 'SQLite', - mssql: 'Microsoft SQL Server', + mssql: 'Microsoft SQL Server', oracledb: 'Oracle Database (Alpha)', }; diff --git a/api/src/controllers/activity.ts b/api/src/controllers/activity.ts index 37c342492d..e5fe4d1f30 100644 --- a/api/src/controllers/activity.ts +++ b/api/src/controllers/activity.ts @@ -1,12 +1,12 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; +import Joi from 'joi'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import { respond } from '../middleware/respond'; +import useCollection from '../middleware/use-collection'; +import { validateBatch } from '../middleware/validate-batch'; import { ActivityService, MetaService } from '../services'; import { Action } from '../types'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; -import { respond } from '../middleware/respond'; -import Joi from 'joi'; -import { validateBatch } from '../middleware/validate-batch'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/assets.ts b/api/src/controllers/assets.ts index b6f606beeb..b392ac148d 100644 --- a/api/src/controllers/assets.ts +++ b/api/src/controllers/assets.ts @@ -1,17 +1,17 @@ -import { Router } from 'express'; -import asyncHandler from '../utils/async-handler'; -import database from '../database'; -import { SYSTEM_ASSET_ALLOW_LIST, ASSET_TRANSFORM_QUERY_KEYS } from '../constants'; -import { InvalidQueryException, ForbiddenException, RangeNotSatisfiableException } from '../exceptions'; -import validate from 'uuid-validate'; -import { pick } from 'lodash'; -import { Transformation } from '../types/assets'; -import storage from '../storage'; -import { PayloadService, AssetsService } from '../services'; -import useCollection from '../middleware/use-collection'; -import env from '../env'; -import ms from 'ms'; import { Range } from '@directus/drive'; +import { Router } from 'express'; +import { pick } from 'lodash'; +import ms from 'ms'; +import validate from 'uuid-validate'; +import { ASSET_TRANSFORM_QUERY_KEYS, SYSTEM_ASSET_ALLOW_LIST } from '../constants'; +import database from '../database'; +import env from '../env'; +import { ForbiddenException, InvalidQueryException, RangeNotSatisfiableException } from '../exceptions'; +import useCollection from '../middleware/use-collection'; +import { AssetsService, PayloadService } from '../services'; +import storage from '../storage'; +import { Transformation } from '../types/assets'; +import asyncHandler from '../utils/async-handler'; const router = Router(); @@ -51,7 +51,7 @@ router.get( const payloadService = new PayloadService('directus_settings', { schema: req.schema }); const defaults = { storage_asset_presets: [], storage_asset_transform: 'all' }; - let savedAssetSettings = await database + const savedAssetSettings = await database .select('storage_asset_presets', 'storage_asset_transform') .from('directus_settings') .first(); @@ -64,13 +64,10 @@ router.get( const transformation = pick(req.query, ASSET_TRANSFORM_QUERY_KEYS); - if (transformation.hasOwnProperty('key') && Object.keys(transformation).length > 1) { + if ('key' in transformation && Object.keys(transformation).length > 1) { throw new InvalidQueryException(`You can't combine the "key" query parameter with any other transformation.`); } - if ( - transformation.hasOwnProperty('quality') && - (Number(transformation.quality) < 1 || Number(transformation.quality) > 100) - ) { + if ('quality' in transformation && (Number(transformation.quality) < 1 || Number(transformation.quality) > 100)) { throw new InvalidQueryException(`"quality" Parameter has to between 1 to 100`); } @@ -133,7 +130,7 @@ router.get( const { stream, file, stat } = await service.getAsset(id, transformation, range); - const access = !!req.accountability?.role ? 'private' : 'public'; + const access = req.accountability?.role ? 'private' : 'public'; res.attachment(file.filename_download); res.setHeader('Content-Type', file.type); @@ -148,7 +145,7 @@ router.get( res.setHeader('Content-Length', stat.size); } - if (req.query.hasOwnProperty('download') === false) { + if ('download' in req.query === false) { res.removeHeader('Content-Disposition'); } diff --git a/api/src/controllers/auth.ts b/api/src/controllers/auth.ts index 311fd937a9..1b308df2cf 100644 --- a/api/src/controllers/auth.ts +++ b/api/src/controllers/auth.ts @@ -1,18 +1,18 @@ import { Router } from 'express'; import session from 'express-session'; -import asyncHandler from '../utils/async-handler'; -import Joi from 'joi'; import grant from 'grant'; -import getEmailFromProfile from '../utils/get-email-from-profile'; -import { InvalidPayloadException } from '../exceptions/invalid-payload'; +import Joi from 'joi'; import ms from 'ms'; -import env from '../env'; -import { UsersService, AuthenticationService } from '../services'; -import grantConfig from '../grant'; -import { InvalidCredentialsException, RouteNotFoundException, ServiceUnavailableException } from '../exceptions'; -import { respond } from '../middleware/respond'; -import { toArray } from '../utils/to-array'; import emitter, { emitAsyncSafe } from '../emitter'; +import env from '../env'; +import { InvalidCredentialsException, RouteNotFoundException, ServiceUnavailableException } from '../exceptions'; +import { InvalidPayloadException } from '../exceptions/invalid-payload'; +import grantConfig from '../grant'; +import { respond } from '../middleware/respond'; +import { AuthenticationService, UsersService } from '../services'; +import asyncHandler from '../utils/async-handler'; +import getEmailFromProfile from '../utils/get-email-from-profile'; +import { toArray } from '../utils/to-array'; const router = Router(); @@ -237,7 +237,7 @@ router.get( req.session.redirect = req.query.redirect as string; } - let hookPayload = { + const hookPayload = { provider: req.params.provider, redirect: req.query?.redirect, }; @@ -284,7 +284,7 @@ router.get( let authResponse: { accessToken: any; refreshToken: any; expires: any; id?: any }; - let hookPayload = req.session.grant.response; + const hookPayload = req.session.grant.response; await emitter.emitAsync(`oauth.${req.params.provider}.login.before`, hookPayload, { event: `oauth.${req.params.provider}.login.before`, diff --git a/api/src/controllers/collections.ts b/api/src/controllers/collections.ts index a7c9ff9d7c..03d4731556 100644 --- a/api/src/controllers/collections.ts +++ b/api/src/controllers/collections.ts @@ -1,10 +1,10 @@ import { Router } from 'express'; -import asyncHandler from '../utils/async-handler'; -import { CollectionsService, MetaService } from '../services'; import { ForbiddenException } from '../exceptions'; import { respond } from '../middleware/respond'; import { validateBatch } from '../middleware/validate-batch'; +import { CollectionsService, MetaService } from '../services'; import { Item } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = Router(); diff --git a/api/src/controllers/extensions.ts b/api/src/controllers/extensions.ts index 9a920a3fdc..99672eb754 100644 --- a/api/src/controllers/extensions.ts +++ b/api/src/controllers/extensions.ts @@ -1,9 +1,9 @@ import express, { Router } from 'express'; -import asyncHandler from '../utils/async-handler'; +import env from '../env'; import { RouteNotFoundException } from '../exceptions'; import { listExtensions } from '../extensions'; -import env from '../env'; import { respond } from '../middleware/respond'; +import asyncHandler from '../utils/async-handler'; const router = Router(); diff --git a/api/src/controllers/fields.ts b/api/src/controllers/fields.ts index ec0652276e..da77105df2 100644 --- a/api/src/controllers/fields.ts +++ b/api/src/controllers/fields.ts @@ -1,14 +1,13 @@ import { Router } from 'express'; -import asyncHandler from '../utils/async-handler'; -import { FieldsService } from '../services/fields'; -import validateCollection from '../middleware/collection-exists'; -import { InvalidPayloadException, ForbiddenException } from '../exceptions'; import Joi from 'joi'; -import { types, Field } from '../types'; -import useCollection from '../middleware/use-collection'; -import { respond } from '../middleware/respond'; import { ALIAS_TYPES } from '../constants'; -import { reduceSchema } from '../utils/reduce-schema'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import validateCollection from '../middleware/collection-exists'; +import { respond } from '../middleware/respond'; +import useCollection from '../middleware/use-collection'; +import { FieldsService } from '../services/fields'; +import { Field, types } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = Router(); @@ -132,7 +131,7 @@ router.patch( } try { - let results: any = []; + const results: any = []; for (const field of req.body) { const updatedField = await service.readOne(req.params.collection, field.field); results.push(updatedField); diff --git a/api/src/controllers/files.ts b/api/src/controllers/files.ts index 5446ef4dfd..dc6cc256a3 100644 --- a/api/src/controllers/files.ts +++ b/api/src/controllers/files.ts @@ -1,17 +1,17 @@ -import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import Busboy from 'busboy'; -import { MetaService, FilesService } from '../services'; -import { File, PrimaryKey } from '../types'; import formatTitle from '@directus/format-title'; -import env from '../env'; +import Busboy from 'busboy'; +import express from 'express'; import Joi from 'joi'; -import { InvalidPayloadException, ForbiddenException } from '../exceptions'; import path from 'path'; -import useCollection from '../middleware/use-collection'; +import env from '../env'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { toArray } from '../utils/to-array'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { FilesService, MetaService } from '../services'; +import { File, PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; +import { toArray } from '../utils/to-array'; const router = express.Router(); @@ -33,7 +33,7 @@ const multipartHandler = asyncHandler(async (req, res, next) => { */ let disk: string = toArray(env.STORAGE_LOCATIONS)[0]; - let payload: Partial = {}; + const payload: Partial = {}; let fileCount = 0; busboy.on('field', (fieldname: keyof File, val) => { diff --git a/api/src/controllers/folders.ts b/api/src/controllers/folders.ts index e36c4e9a5d..0685367895 100644 --- a/api/src/controllers/folders.ts +++ b/api/src/controllers/folders.ts @@ -1,11 +1,11 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { FoldersService, MetaService } from '../services'; import { ForbiddenException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { FoldersService, MetaService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/graphql.ts b/api/src/controllers/graphql.ts index 5fe09e031c..224598abe2 100644 --- a/api/src/controllers/graphql.ts +++ b/api/src/controllers/graphql.ts @@ -1,8 +1,8 @@ import { Router } from 'express'; -import { GraphQLService } from '../services'; -import { respond } from '../middleware/respond'; -import asyncHandler from '../utils/async-handler'; import { parseGraphQL } from '../middleware/graphql'; +import { respond } from '../middleware/respond'; +import { GraphQLService } from '../services'; +import asyncHandler from '../utils/async-handler'; const router = Router(); diff --git a/api/src/controllers/items.ts b/api/src/controllers/items.ts index c5c5208b35..36121abd34 100644 --- a/api/src/controllers/items.ts +++ b/api/src/controllers/items.ts @@ -1,11 +1,11 @@ -import express, { RequestHandler } from 'express'; -import asyncHandler from '../utils/async-handler'; +import express from 'express'; +import { ForbiddenException, RouteNotFoundException } from '../exceptions'; import collectionExists from '../middleware/collection-exists'; -import { ItemsService, MetaService } from '../services'; -import { RouteNotFoundException, ForbiddenException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; import { validateBatch } from '../middleware/validate-batch'; +import { ItemsService, MetaService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/not-found.ts b/api/src/controllers/not-found.ts index 4c37dad33a..f886bf228b 100644 --- a/api/src/controllers/not-found.ts +++ b/api/src/controllers/not-found.ts @@ -1,7 +1,6 @@ import { RequestHandler } from 'express'; -import { RouteNotFoundException } from '../exceptions'; - import emitter from '../emitter'; +import { RouteNotFoundException } from '../exceptions'; /** * Handles not found routes. diff --git a/api/src/controllers/permissions.ts b/api/src/controllers/permissions.ts index e2a563bf4a..cd4137c4a0 100644 --- a/api/src/controllers/permissions.ts +++ b/api/src/controllers/permissions.ts @@ -1,11 +1,11 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { PermissionsService, MetaService } from '../services'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; +import { ForbiddenException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { MetaService, PermissionsService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/presets.ts b/api/src/controllers/presets.ts index 665104716d..f9cd9a248e 100644 --- a/api/src/controllers/presets.ts +++ b/api/src/controllers/presets.ts @@ -1,11 +1,11 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { PresetsService, MetaService } from '../services'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; +import { ForbiddenException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { MetaService, PresetsService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/relations.ts b/api/src/controllers/relations.ts index 32d54bef96..dc1b02f82f 100644 --- a/api/src/controllers/relations.ts +++ b/api/src/controllers/relations.ts @@ -1,11 +1,11 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { RelationsService, MetaService } from '../services'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; +import { ForbiddenException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { MetaService, RelationsService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/revisions.ts b/api/src/controllers/revisions.ts index 51bcc0a53e..f6a15b1e41 100644 --- a/api/src/controllers/revisions.ts +++ b/api/src/controllers/revisions.ts @@ -1,9 +1,9 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { RevisionsService, MetaService } from '../services'; -import useCollection from '../middleware/use-collection'; import { respond } from '../middleware/respond'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { MetaService, RevisionsService } from '../services'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/roles.ts b/api/src/controllers/roles.ts index bc9e478aac..f852abefa8 100644 --- a/api/src/controllers/roles.ts +++ b/api/src/controllers/roles.ts @@ -1,11 +1,11 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { RolesService, MetaService } from '../services'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; +import { ForbiddenException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { MetaService, RolesService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/server.ts b/api/src/controllers/server.ts index 8815ca6654..61e1a6a141 100644 --- a/api/src/controllers/server.ts +++ b/api/src/controllers/server.ts @@ -1,10 +1,9 @@ -import { Router } from 'express'; -import { ServerService } from '../services'; -import { SpecificationService } from '../services'; -import asyncHandler from '../utils/async-handler'; -import { respond } from '../middleware/respond'; import { format } from 'date-fns'; +import { Router } from 'express'; import { RouteNotFoundException } from '../exceptions'; +import { respond } from '../middleware/respond'; +import { ServerService, SpecificationService } from '../services'; +import asyncHandler from '../utils/async-handler'; const router = Router(); diff --git a/api/src/controllers/settings.ts b/api/src/controllers/settings.ts index 61b4771b99..98115b6041 100644 --- a/api/src/controllers/settings.ts +++ b/api/src/controllers/settings.ts @@ -1,9 +1,9 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { SettingsService } from '../services'; import { ForbiddenException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; import { respond } from '../middleware/respond'; +import useCollection from '../middleware/use-collection'; +import { SettingsService } from '../services'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/users.ts b/api/src/controllers/users.ts index e84036603d..b35728eb56 100644 --- a/api/src/controllers/users.ts +++ b/api/src/controllers/users.ts @@ -1,12 +1,12 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; import Joi from 'joi'; -import { InvalidPayloadException, InvalidCredentialsException, ForbiddenException } from '../exceptions'; -import { UsersService, MetaService, AuthenticationService } from '../services'; -import useCollection from '../middleware/use-collection'; +import { ForbiddenException, InvalidCredentialsException, InvalidPayloadException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { AuthenticationService, MetaService, UsersService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/controllers/utils.ts b/api/src/controllers/utils.ts index f0ceb74ec9..6d749179cd 100644 --- a/api/src/controllers/utils.ts +++ b/api/src/controllers/utils.ts @@ -1,12 +1,12 @@ -import { Router } from 'express'; -import asyncHandler from '../utils/async-handler'; -import { nanoid } from 'nanoid'; -import { InvalidQueryException, InvalidPayloadException } from '../exceptions'; import argon2 from 'argon2'; -import collectionExists from '../middleware/collection-exists'; -import { UtilsService, RevisionsService } from '../services'; +import { Router } from 'express'; import Joi from 'joi'; +import { nanoid } from 'nanoid'; +import { InvalidPayloadException, InvalidQueryException } from '../exceptions'; +import collectionExists from '../middleware/collection-exists'; import { respond } from '../middleware/respond'; +import { RevisionsService, UtilsService } from '../services'; +import asyncHandler from '../utils/async-handler'; const router = Router(); diff --git a/api/src/controllers/webhooks.ts b/api/src/controllers/webhooks.ts index 0044e117c2..edca81dfeb 100644 --- a/api/src/controllers/webhooks.ts +++ b/api/src/controllers/webhooks.ts @@ -1,11 +1,11 @@ import express from 'express'; -import asyncHandler from '../utils/async-handler'; -import { WebhooksService, MetaService } from '../services'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import useCollection from '../middleware/use-collection'; +import { ForbiddenException } from '../exceptions'; import { respond } from '../middleware/respond'; -import { PrimaryKey } from '../types'; +import useCollection from '../middleware/use-collection'; import { validateBatch } from '../middleware/validate-batch'; +import { MetaService, WebhooksService } from '../services'; +import { PrimaryKey } from '../types'; +import asyncHandler from '../utils/async-handler'; const router = express.Router(); diff --git a/api/src/database/index.ts b/api/src/database/index.ts index 7ef406a672..4a73ba7855 100644 --- a/api/src/database/index.ts +++ b/api/src/database/index.ts @@ -1,13 +1,12 @@ -import { knex, Knex } from 'knex'; -import dotenv from 'dotenv'; -import path from 'path'; -import logger from '../logger'; -import env from '../env'; -import { validateEnv } from '../utils/validate-env'; -import { performance } from 'perf_hooks'; - import SchemaInspector from '@directus/schema'; +import dotenv from 'dotenv'; +import { knex, Knex } from 'knex'; +import path from 'path'; +import { performance } from 'perf_hooks'; +import env from '../env'; +import logger from '../logger'; import { getConfigFromEnv } from '../utils/get-config-from-env'; +import { validateEnv } from '../utils/validate-env'; dotenv.config({ path: path.resolve(__dirname, '../../', '.env') }); diff --git a/api/src/database/migrations/20201029C-remove-system-fields.ts b/api/src/database/migrations/20201029C-remove-system-fields.ts index 583544b158..9e55110df7 100644 --- a/api/src/database/migrations/20201029C-remove-system-fields.ts +++ b/api/src/database/migrations/20201029C-remove-system-fields.ts @@ -1,5 +1,5 @@ import { Knex } from 'knex'; -import { uniq, merge } from 'lodash'; +import { merge, uniq } from 'lodash'; const defaults = { collection: null, diff --git a/api/src/database/migrations/run.ts b/api/src/database/migrations/run.ts index 2526e3a5c1..913fabf108 100644 --- a/api/src/database/migrations/run.ts +++ b/api/src/database/migrations/run.ts @@ -1,7 +1,7 @@ +import formatTitle from '@directus/format-title'; import fse from 'fs-extra'; import { Knex } from 'knex'; import path from 'path'; -import formatTitle from '@directus/format-title'; import env from '../../env'; type Migration = { @@ -29,7 +29,7 @@ export default async function run(database: Knex, direction: 'up' | 'down' | 'la ...customMigrationFiles.map((path) => parseFilePath(path, true)), ]; - function parseFilePath(filePath: string, custom: boolean = false) { + function parseFilePath(filePath: string, custom = false) { const version = filePath.split('-')[0]; const name = formatTitle(filePath.split('-').slice(1).join('_').split('.')[0]); const completed = !!completedMigrations.find((migration) => migration.version === version); diff --git a/api/src/database/run-ast.ts b/api/src/database/run-ast.ts index 96177e6cee..47c708ede4 100644 --- a/api/src/database/run-ast.ts +++ b/api/src/database/run-ast.ts @@ -1,11 +1,11 @@ -import { AST, NestedCollectionNode, FieldNode } from '../types/ast'; -import { clone, cloneDeep, uniq, pick } from 'lodash'; -import database from './index'; -import { Query, Item, SchemaOverview } from '../types'; -import { PayloadService } from '../services/payload'; -import applyQuery from '../utils/apply-query'; import { Knex } from 'knex'; +import { clone, cloneDeep, pick, uniq } from 'lodash'; +import { PayloadService } from '../services/payload'; +import { Item, Query, SchemaOverview } from '../types'; +import { AST, FieldNode, NestedCollectionNode } from '../types/ast'; +import applyQuery from '../utils/apply-query'; import { toArray } from '../utils/to-array'; +import database from './index'; type RunASTOptions = { /** @@ -86,7 +86,7 @@ export default async function runAST( const nestedNodes = applyParentFilters(nestedCollectionNodes, items); for (const nestedNode of nestedNodes) { - let nestedItems = await runAST(nestedNode, schema, { knex, nested: true }); + const nestedItems = await runAST(nestedNode, schema, { knex, nested: true }); if (nestedItems) { // Merge all fetched nested records with the parent items @@ -160,7 +160,7 @@ function getDBQuery( schema: SchemaOverview, nested?: boolean ): Knex.QueryBuilder { - let dbQuery = knex.select(columns.map((column) => `${table}.${column}`)).from(table); + const dbQuery = knex.select(columns.map((column) => `${table}.${column}`)).from(table); const queryCopy = clone(query); diff --git a/api/src/database/seeds/run.ts b/api/src/database/seeds/run.ts index 10e24ad940..2ad2eb0916 100644 --- a/api/src/database/seeds/run.ts +++ b/api/src/database/seeds/run.ts @@ -1,9 +1,9 @@ -import { Knex } from 'knex'; import fse from 'fs-extra'; -import path from 'path'; import yaml from 'js-yaml'; +import { Knex } from 'knex'; +import { isObject } from 'lodash'; +import path from 'path'; import { types } from '../../types'; -import { isObject, merge } from 'lodash'; type TableSeed = { table: string; diff --git a/api/src/database/system-data/app-access-permissions/index.ts b/api/src/database/system-data/app-access-permissions/index.ts index e14871b34e..a41dc5d30a 100644 --- a/api/src/database/system-data/app-access-permissions/index.ts +++ b/api/src/database/system-data/app-access-permissions/index.ts @@ -1,6 +1,6 @@ -import { requireYAML } from '../../../utils/require-yaml'; -import { Permission } from '../../../types'; import { merge } from 'lodash'; +import { Permission } from '../../../types'; +import { requireYAML } from '../../../utils/require-yaml'; const defaults: Partial = { role: null, diff --git a/api/src/database/system-data/collections/index.ts b/api/src/database/system-data/collections/index.ts index 8ba45f31a7..f384faa395 100644 --- a/api/src/database/system-data/collections/index.ts +++ b/api/src/database/system-data/collections/index.ts @@ -1,6 +1,6 @@ -import { requireYAML } from '../../../utils/require-yaml'; import { merge } from 'lodash'; import { CollectionMeta } from '../../../types'; +import { requireYAML } from '../../../utils/require-yaml'; const systemData = requireYAML(require.resolve('./collections.yaml')); diff --git a/api/src/database/system-data/fields/index.ts b/api/src/database/system-data/fields/index.ts index d7b7491015..b085e359e2 100644 --- a/api/src/database/system-data/fields/index.ts +++ b/api/src/database/system-data/fields/index.ts @@ -1,13 +1,13 @@ -import { requireYAML } from '../../../utils/require-yaml'; -import { merge } from 'lodash'; -import { FieldMeta } from '../../../types'; import fse from 'fs-extra'; +import { merge } from 'lodash'; import path from 'path'; +import { FieldMeta } from '../../../types'; +import { requireYAML } from '../../../utils/require-yaml'; const defaults = requireYAML(require.resolve('./_defaults.yaml')); const fieldData = fse.readdirSync(path.resolve(__dirname)); -export let systemFieldRows: FieldMeta[] = []; +export const systemFieldRows: FieldMeta[] = []; for (const filepath of fieldData) { if (filepath.includes('_defaults') || filepath.includes('index')) continue; diff --git a/api/src/database/system-data/relations/index.ts b/api/src/database/system-data/relations/index.ts index 7ffc843e59..36c913bbf0 100644 --- a/api/src/database/system-data/relations/index.ts +++ b/api/src/database/system-data/relations/index.ts @@ -1,6 +1,6 @@ -import { requireYAML } from '../../../utils/require-yaml'; import { merge } from 'lodash'; import { Relation } from '../../../types'; +import { requireYAML } from '../../../utils/require-yaml'; const systemData = requireYAML(require.resolve('./relations.yaml')); diff --git a/api/src/env.ts b/api/src/env.ts index e044eff4a4..dfa64a0cd0 100644 --- a/api/src/env.ts +++ b/api/src/env.ts @@ -3,14 +3,13 @@ * See example.env for all possible keys */ -import fs from 'fs'; -import path from 'path'; -import { requireYAML } from './utils/require-yaml'; - import dotenv from 'dotenv'; -import { clone, toString, toNumber } from 'lodash'; -import { toArray } from './utils/to-array'; +import fs from 'fs'; +import { clone, toNumber, toString } from 'lodash'; +import path from 'path'; import logger from './logger'; +import { requireYAML } from './utils/require-yaml'; +import { toArray } from './utils/to-array'; const acceptableEnvTypes = ['string', 'number', 'regex', 'array']; diff --git a/api/src/exceptions/database/dialects/mssql.ts b/api/src/exceptions/database/dialects/mssql.ts index 978b37aa57..46e9d42db2 100644 --- a/api/src/exceptions/database/dialects/mssql.ts +++ b/api/src/exceptions/database/dialects/mssql.ts @@ -1,10 +1,9 @@ +import database from '../../../database'; import { InvalidForeignKeyException } from '../invalid-foreign-key'; import { NotNullViolationException } from '../not-null-violation'; import { RecordNotUniqueException } from '../record-not-unique'; -import { ValueTooLongException } from '../value-too-long'; import { ValueOutOfRangeException } from '../value-out-of-range'; - -import database from '../../../database'; +import { ValueTooLongException } from '../value-too-long'; import { MSSQLError } from './types'; enum MSSQLErrorCodes { diff --git a/api/src/exceptions/database/dialects/mysql.ts b/api/src/exceptions/database/dialects/mysql.ts index 86d919ff02..07b128ac88 100644 --- a/api/src/exceptions/database/dialects/mysql.ts +++ b/api/src/exceptions/database/dialects/mysql.ts @@ -1,8 +1,8 @@ import { InvalidForeignKeyException } from '../invalid-foreign-key'; import { NotNullViolationException } from '../not-null-violation'; import { RecordNotUniqueException } from '../record-not-unique'; -import { ValueTooLongException } from '../value-too-long'; import { ValueOutOfRangeException } from '../value-out-of-range'; +import { ValueTooLongException } from '../value-too-long'; import { MySQLError } from './types'; enum MySQLErrorCodes { diff --git a/api/src/exceptions/database/dialects/postgres.ts b/api/src/exceptions/database/dialects/postgres.ts index fca233461b..69ecb93843 100644 --- a/api/src/exceptions/database/dialects/postgres.ts +++ b/api/src/exceptions/database/dialects/postgres.ts @@ -1,8 +1,8 @@ import { InvalidForeignKeyException } from '../invalid-foreign-key'; import { NotNullViolationException } from '../not-null-violation'; import { RecordNotUniqueException } from '../record-not-unique'; -import { ValueTooLongException } from '../value-too-long'; import { ValueOutOfRangeException } from '../value-out-of-range'; +import { ValueTooLongException } from '../value-too-long'; import { PostgresError } from './types'; enum PostgresErrorCodes { diff --git a/api/src/exceptions/database/dialects/sqlite.ts b/api/src/exceptions/database/dialects/sqlite.ts index d9662012ff..285209f74f 100644 --- a/api/src/exceptions/database/dialects/sqlite.ts +++ b/api/src/exceptions/database/dialects/sqlite.ts @@ -1,6 +1,6 @@ import { InvalidForeignKeyException } from '../invalid-foreign-key'; -import { RecordNotUniqueException } from '../record-not-unique'; import { NotNullViolationException } from '../not-null-violation'; +import { RecordNotUniqueException } from '../record-not-unique'; import { SQLiteError } from './types'; // NOTE: diff --git a/api/src/exceptions/database/translate.ts b/api/src/exceptions/database/translate.ts index a767b81b7f..d74ff19e68 100644 --- a/api/src/exceptions/database/translate.ts +++ b/api/src/exceptions/database/translate.ts @@ -1,9 +1,9 @@ import database from '../../database'; -import { extractError as postgres } from './dialects/postgres'; -import { extractError as mysql } from './dialects/mysql'; import { extractError as mssql } from './dialects/mssql'; -import { extractError as sqlite } from './dialects/sqlite'; +import { extractError as mysql } from './dialects/mysql'; import { extractError as oracle } from './dialects/oracle'; +import { extractError as postgres } from './dialects/postgres'; +import { extractError as sqlite } from './dialects/sqlite'; import { SQLError } from './dialects/types'; /** diff --git a/api/src/exceptions/failed-validation.ts b/api/src/exceptions/failed-validation.ts index b57a0f36d5..e13011bebc 100644 --- a/api/src/exceptions/failed-validation.ts +++ b/api/src/exceptions/failed-validation.ts @@ -1,6 +1,6 @@ -import { BaseException } from './base'; import { ValidationErrorItem } from 'joi'; import { FilterOperator, ValidationOperator } from '../types'; +import { BaseException } from './base'; type FailedValidationExtensions = { field: string; diff --git a/api/src/exceptions/forbidden.ts b/api/src/exceptions/forbidden.ts index 338653ca18..4b464d7e00 100644 --- a/api/src/exceptions/forbidden.ts +++ b/api/src/exceptions/forbidden.ts @@ -1,15 +1,7 @@ import { BaseException } from './base'; -import { Permission } from '../types'; - -type Extensions = { - field?: string; - collection?: string; - item?: string | number | (string | number)[]; - action?: Permission['action']; -}; export class ForbiddenException extends BaseException { - constructor(message = `You don't have permission to access this.`, extensions?: Extensions) { + constructor() { super(`You don't have permission to access this.`, 403, 'FORBIDDEN'); /** diff --git a/api/src/exceptions/range-not-satisfiable.ts b/api/src/exceptions/range-not-satisfiable.ts index bb1f9804ba..6b169dde0e 100644 --- a/api/src/exceptions/range-not-satisfiable.ts +++ b/api/src/exceptions/range-not-satisfiable.ts @@ -1,5 +1,5 @@ -import { BaseException } from './base'; import { Range } from '@directus/drive'; +import { BaseException } from './base'; export class RangeNotSatisfiableException extends BaseException { constructor(range: Range) { diff --git a/api/src/extensions.ts b/api/src/extensions.ts index a3dc07e9f4..c577282228 100644 --- a/api/src/extensions.ts +++ b/api/src/extensions.ts @@ -1,17 +1,16 @@ -import listFolders from './utils/list-folders'; -import path from 'path'; -import env from './env'; -import { ServiceUnavailableException } from './exceptions'; import express, { Router } from 'express'; -import emitter from './emitter'; -import logger from './logger'; -import { HookRegisterFunction, EndpointRegisterFunction } from './types'; import { ensureDir } from 'fs-extra'; -import { getSchema } from './utils/get-schema'; - -import * as exceptions from './exceptions'; -import * as services from './services'; +import path from 'path'; import database from './database'; +import emitter from './emitter'; +import env from './env'; +import * as exceptions from './exceptions'; +import { ServiceUnavailableException } from './exceptions'; +import logger from './logger'; +import * as services from './services'; +import { EndpointRegisterFunction, HookRegisterFunction } from './types'; +import { getSchema } from './utils/get-schema'; +import listFolders from './utils/list-folders'; export async function ensureFoldersExist(): Promise { const folders = ['endpoints', 'hooks', 'interfaces', 'modules', 'layouts', 'displays']; @@ -94,7 +93,7 @@ function registerHooks(hooks: string[]) { } } - let events = register({ services, exceptions, env, database, getSchema }); + const events = register({ services, exceptions, env, database, getSchema }); for (const [event, handler] of Object.entries(events)) { emitter.on(event, handler); } diff --git a/api/src/middleware/authenticate.ts b/api/src/middleware/authenticate.ts index bac4bd915a..f408ff3029 100644 --- a/api/src/middleware/authenticate.ts +++ b/api/src/middleware/authenticate.ts @@ -1,10 +1,10 @@ import { RequestHandler } from 'express'; -import jwt, { TokenExpiredError, JsonWebTokenError } from 'jsonwebtoken'; -import isJWT from '../utils/is-jwt'; +import jwt, { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken'; import database from '../database'; -import asyncHandler from '../utils/async-handler'; -import { InvalidCredentialsException } from '../exceptions'; import env from '../env'; +import { InvalidCredentialsException } from '../exceptions'; +import asyncHandler from '../utils/async-handler'; +import isJWT from '../utils/is-jwt'; /** * Verify the passed JWT and assign the user ID and role to `req` diff --git a/api/src/middleware/cache.ts b/api/src/middleware/cache.ts index c639a38fa7..483317226e 100644 --- a/api/src/middleware/cache.ts +++ b/api/src/middleware/cache.ts @@ -1,9 +1,8 @@ import { RequestHandler } from 'express'; -import asyncHandler from '../utils/async-handler'; -import env from '../env'; -import { getCacheKey } from '../utils/get-cache-key'; - import cache from '../cache'; +import env from '../env'; +import asyncHandler from '../utils/async-handler'; +import { getCacheKey } from '../utils/get-cache-key'; const checkCacheMiddleware: RequestHandler = asyncHandler(async (req, res, next) => { if (req.method.toLowerCase() !== 'get') return next(); diff --git a/api/src/middleware/check-ip.ts b/api/src/middleware/check-ip.ts index 369cb270be..2cc029e693 100644 --- a/api/src/middleware/check-ip.ts +++ b/api/src/middleware/check-ip.ts @@ -1,7 +1,7 @@ import { RequestHandler } from 'express'; -import asyncHandler from '../utils/async-handler'; import database from '../database'; import { InvalidIPException } from '../exceptions'; +import asyncHandler from '../utils/async-handler'; export const checkIP: RequestHandler = asyncHandler(async (req, res, next) => { const role = await database diff --git a/api/src/middleware/collection-exists.ts b/api/src/middleware/collection-exists.ts index f7f9e0e876..a5f89b7911 100644 --- a/api/src/middleware/collection-exists.ts +++ b/api/src/middleware/collection-exists.ts @@ -3,9 +3,9 @@ */ import { RequestHandler } from 'express'; -import asyncHandler from '../utils/async-handler'; -import { ForbiddenException } from '../exceptions'; import { systemCollectionRows } from '../database/system-data/collections'; +import { ForbiddenException } from '../exceptions'; +import asyncHandler from '../utils/async-handler'; const collectionExists: RequestHandler = asyncHandler(async (req, res, next) => { if (!req.params.collection) return next(); diff --git a/api/src/middleware/error-handler.ts b/api/src/middleware/error-handler.ts index 267a9635f4..29febc9b67 100644 --- a/api/src/middleware/error-handler.ts +++ b/api/src/middleware/error-handler.ts @@ -1,11 +1,11 @@ import { ErrorRequestHandler } from 'express'; +import { emitAsyncSafe } from '../emitter'; +import env from '../env'; import { BaseException, MethodNotAllowedException } from '../exceptions'; import logger from '../logger'; -import env from '../env'; import { toArray } from '../utils/to-array'; -import { emitAsyncSafe } from '../emitter'; -const errorHandler: ErrorRequestHandler = (err, req, res, next) => { +const errorHandler: ErrorRequestHandler = (err, req, res) => { let payload: any = { errors: [], }; diff --git a/api/src/middleware/graphql.ts b/api/src/middleware/graphql.ts index b17c10df6e..3374e61d5c 100644 --- a/api/src/middleware/graphql.ts +++ b/api/src/middleware/graphql.ts @@ -1,8 +1,8 @@ import { RequestHandler } from 'express'; -import { InvalidQueryException, MethodNotAllowedException, InvalidPayloadException } from '../exceptions'; -import asyncHandler from '../utils/async-handler'; +import { DocumentNode, getOperationAST, parse, Source } from 'graphql'; +import { InvalidPayloadException, InvalidQueryException, MethodNotAllowedException } from '../exceptions'; import { GraphQLParams } from '../types'; -import { getOperationAST, Source, parse, DocumentNode } from 'graphql'; +import asyncHandler from '../utils/async-handler'; export const parseGraphQL: RequestHandler = asyncHandler(async (req, res, next) => { if (req.method !== 'GET' && req.method !== 'POST') { diff --git a/api/src/middleware/rate-limiter.ts b/api/src/middleware/rate-limiter.ts index 14913d9d33..0c59b6b01f 100644 --- a/api/src/middleware/rate-limiter.ts +++ b/api/src/middleware/rate-limiter.ts @@ -1,11 +1,11 @@ import { RequestHandler } from 'express'; -import asyncHandler from '../utils/async-handler'; -import { RateLimiterMemory, RateLimiterRedis, RateLimiterMemcache } from 'rate-limiter-flexible'; +import ms from 'ms'; +import { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible'; import env from '../env'; import { HitRateLimitException } from '../exceptions'; -import ms from 'ms'; -import { validateEnv } from '../utils/validate-env'; import { createRateLimiter } from '../rate-limiter'; +import asyncHandler from '../utils/async-handler'; +import { validateEnv } from '../utils/validate-env'; let checkRateLimit: RequestHandler = (req, res, next) => next(); export let rateLimiter: RateLimiterRedis | RateLimiterMemcache | RateLimiterMemory; diff --git a/api/src/middleware/respond.ts b/api/src/middleware/respond.ts index fe78dc66ad..25e6949c30 100644 --- a/api/src/middleware/respond.ts +++ b/api/src/middleware/respond.ts @@ -1,11 +1,11 @@ import { RequestHandler } from 'express'; -import asyncHandler from '../utils/async-handler'; -import env from '../env'; -import { getCacheKey } from '../utils/get-cache-key'; -import cache from '../cache'; import { Transform, transforms } from 'json2csv'; -import { PassThrough } from 'stream'; import ms from 'ms'; +import { PassThrough } from 'stream'; +import cache from '../cache'; +import env from '../env'; +import asyncHandler from '../utils/async-handler'; +import { getCacheKey } from '../utils/get-cache-key'; export const respond: RequestHandler = asyncHandler(async (req, res) => { if ( diff --git a/api/src/middleware/validate-batch.ts b/api/src/middleware/validate-batch.ts index d297182417..90bcd2538a 100644 --- a/api/src/middleware/validate-batch.ts +++ b/api/src/middleware/validate-batch.ts @@ -1,7 +1,7 @@ import { RequestHandler } from 'express'; -import asyncHandler from '../utils/async-handler'; import Joi from 'joi'; import { FailedValidationException, InvalidPayloadException } from '../exceptions'; +import asyncHandler from '../utils/async-handler'; import { sanitizeQuery } from '../utils/sanitize-query'; export const validateBatch = (scope: 'read' | 'update' | 'delete'): RequestHandler => diff --git a/api/src/rate-limiter.ts b/api/src/rate-limiter.ts index 4d276b3fb0..10cf7f1c7f 100644 --- a/api/src/rate-limiter.ts +++ b/api/src/rate-limiter.ts @@ -1,14 +1,12 @@ +import { merge } from 'lodash'; import { - RateLimiterMemory, - RateLimiterRedis, - RateLimiterMemcache, IRateLimiterOptions, IRateLimiterStoreOptions, RateLimiterAbstract, + RateLimiterMemcache, + RateLimiterMemory, + RateLimiterRedis, } from 'rate-limiter-flexible'; - -import { merge } from 'lodash'; - import env from './env'; import { getConfigFromEnv } from './utils/get-config-from-env'; diff --git a/api/src/server.ts b/api/src/server.ts index be735801e6..e63d623563 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -1,14 +1,14 @@ -import * as http from 'http'; -import * as https from 'https'; -import qs from 'qs'; -import url from 'url'; import { createTerminus, TerminusOptions } from '@godaddy/terminus'; import { Request } from 'express'; -import logger from './logger'; -import { emitAsyncSafe } from './emitter'; -import database from './database'; -import createApp from './app'; +import * as http from 'http'; +import * as https from 'https'; import { once } from 'lodash'; +import qs from 'qs'; +import url from 'url'; +import createApp from './app'; +import database from './database'; +import { emitAsyncSafe } from './emitter'; +import logger from './logger'; export default async function createServer(): Promise { const server = http.createServer(await createApp()); diff --git a/api/src/services/activity.ts b/api/src/services/activity.ts index 5f2b379556..51a6edb6a0 100644 --- a/api/src/services/activity.ts +++ b/api/src/services/activity.ts @@ -1,5 +1,5 @@ -import { ItemsService } from './items'; import { AbstractServiceOptions } from '../types'; +import { ItemsService } from './items'; /** * @TODO only return activity of the collections you have access to diff --git a/api/src/services/assets.ts b/api/src/services/assets.ts index 79e05d9c1f..4a138962a9 100644 --- a/api/src/services/assets.ts +++ b/api/src/services/assets.ts @@ -1,12 +1,12 @@ -import storage from '../storage'; +import { Range, StatResponse } from '@directus/drive'; +import { Knex } from 'knex'; +import path from 'path'; import sharp, { ResizeOptions } from 'sharp'; import database from '../database'; -import path from 'path'; -import { Knex } from 'knex'; -import { Accountability, AbstractServiceOptions, Transformation } from '../types'; -import { AuthorizationService } from './authorization'; -import { Range, StatResponse } from '@directus/drive'; import { RangeNotSatisfiableException } from '../exceptions'; +import storage from '../storage'; +import { AbstractServiceOptions, Accountability, Transformation } from '../types'; +import { AuthorizationService } from './authorization'; export class AssetsService { knex: Knex; diff --git a/api/src/services/authentication.ts b/api/src/services/authentication.ts index 48934ab639..c9875bd8b6 100644 --- a/api/src/services/authentication.ts +++ b/api/src/services/authentication.ts @@ -1,24 +1,23 @@ -import database from '../database'; -import jwt from 'jsonwebtoken'; import argon2 from 'argon2'; -import { nanoid } from 'nanoid'; +import jwt from 'jsonwebtoken'; +import { Knex } from 'knex'; +import { omit } from 'lodash'; import ms from 'ms'; +import { nanoid } from 'nanoid'; +import { authenticator } from 'otplib'; +import database from '../database'; +import emitter, { emitAsyncSafe } from '../emitter'; +import env from '../env'; import { InvalidCredentialsException, - InvalidPayloadException, InvalidOTPException, + InvalidPayloadException, UserSuspendedException, } from '../exceptions'; -import { Session, Accountability, AbstractServiceOptions, Action, SchemaOverview } from '../types'; -import { Knex } from 'knex'; -import { ActivityService } from '../services/activity'; -import env from '../env'; -import { authenticator } from 'otplib'; -import emitter, { emitAsyncSafe } from '../emitter'; -import { omit } from 'lodash'; import { createRateLimiter } from '../rate-limiter'; +import { ActivityService } from '../services/activity'; +import { AbstractServiceOptions, Accountability, Action, SchemaOverview, Session } from '../types'; import { SettingsService } from './settings'; -import { rateLimiter } from '../middleware/rate-limiter'; type AuthenticateOptions = { email: string; diff --git a/api/src/services/authorization.ts b/api/src/services/authorization.ts index 972211a6b2..01da4e7944 100644 --- a/api/src/services/authorization.ts +++ b/api/src/services/authorization.ts @@ -1,25 +1,25 @@ +import { Knex } from 'knex'; +import { cloneDeep, flatten, merge, uniq, uniqWith } from 'lodash'; import database from '../database'; +import { FailedValidationException, ForbiddenException } from '../exceptions'; import { - Accountability, AbstractServiceOptions, + Accountability, AST, - NestedCollectionNode, FieldNode, - Query, + Filter, + Item, + NestedCollectionNode, Permission, PermissionsAction, - Item, PrimaryKey, + Query, SchemaOverview, - Filter, } from '../types'; -import { Knex } from 'knex'; -import { ForbiddenException, FailedValidationException } from '../exceptions'; -import { uniq, uniqWith, merge, flatten, cloneDeep } from 'lodash'; import generateJoi from '../utils/generate-joi'; +import { parseFilter } from '../utils/parse-filter'; import { ItemsService } from './items'; import { PayloadService } from './payload'; -import { parseFilter } from '../utils/parse-filter'; export class AuthorizationService { knex: Knex; @@ -40,7 +40,7 @@ export class AuthorizationService { async processAST(ast: AST, action: PermissionsAction = 'read'): Promise { const collectionsRequested = getCollectionsFromAST(ast); - let permissionsForCollections = uniqWith( + const permissionsForCollections = uniqWith( this.schema.permissions.filter((permission) => { return ( permission.action === action && @@ -218,7 +218,7 @@ export class AuthorizationService { const payloadWithPresets = merge({}, preset, payload); - let requiredColumns: string[] = []; + const requiredColumns: string[] = []; for (const [name, field] of Object.entries(this.schema.collections[collection].fields)) { const specials = field?.special ?? []; diff --git a/api/src/services/collections.ts b/api/src/services/collections.ts index de95e425d1..86ec980ae6 100644 --- a/api/src/services/collections.ts +++ b/api/src/services/collections.ts @@ -1,5 +1,14 @@ +import SchemaInspector from '@directus/schema'; +import { Knex } from 'knex'; +import cache from '../cache'; import { ALIAS_TYPES } from '../constants'; import database, { schemaInspector } from '../database'; +import { systemCollectionRows } from '../database/system-data/collections'; +import env from '../env'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import logger from '../logger'; +import { FieldsService } from '../services/fields'; +import { ItemsService, MutationOptions } from '../services/items'; import { AbstractServiceOptions, Accountability, @@ -8,15 +17,6 @@ import { FieldMeta, SchemaOverview, } from '../types'; -import { Knex } from 'knex'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import { FieldsService } from '../services/fields'; -import { ItemsService, MutationOptions } from '../services/items'; -import cache from '../cache'; -import { systemCollectionRows } from '../database/system-data/collections'; -import SchemaInspector from '@directus/schema'; -import env from '../env'; -import logger from '../logger'; export class CollectionsService { knex: Knex; @@ -357,7 +357,7 @@ export class CollectionsService { .where({ many_collection: collectionKey, many_field: relation.many_field }); await fieldsService.deleteField(relation.one_collection!, relation.one_field!); - } else if (!!relation.one_collection) { + } else if (relation.one_collection) { await this.knex('directus_relations') .update({ one_field: null }) .where({ one_collection: collectionKey, one_field: relation.one_field }); diff --git a/api/src/services/fields.ts b/api/src/services/fields.ts index a946a922f7..eec4e71199 100644 --- a/api/src/services/fields.ts +++ b/api/src/services/fields.ts @@ -1,22 +1,20 @@ +import SchemaInspector from '@directus/schema'; +import { Knex } from 'knex'; +import { Column } from 'knex-schema-inspector/dist/types/column'; +import cache from '../cache'; import { ALIAS_TYPES } from '../constants'; import database, { schemaInspector } from '../database'; -import { Field } from '../types/field'; -import { Accountability, AbstractServiceOptions, FieldMeta, SchemaOverview } from '../types'; -import { ItemsService } from '../services/items'; -import { Knex } from 'knex'; -import getLocalType from '../utils/get-local-type'; -import { types } from '../types'; -import { ForbiddenException, InvalidPayloadException } from '../exceptions'; -import { PayloadService } from '../services/payload'; -import getDefaultValue from '../utils/get-default-value'; -import cache from '../cache'; -import emitter, { emitAsyncSafe } from '../emitter'; -import SchemaInspector from '@directus/schema'; -import { toArray } from '../utils/to-array'; -import env from '../env'; -import { Column } from 'knex-schema-inspector/dist/types/column'; - import { systemFieldRows } from '../database/system-data/fields/'; +import emitter, { emitAsyncSafe } from '../emitter'; +import env from '../env'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import { ItemsService } from '../services/items'; +import { PayloadService } from '../services/payload'; +import { AbstractServiceOptions, Accountability, FieldMeta, SchemaOverview, types } from '../types'; +import { Field } from '../types/field'; +import getDefaultValue from '../utils/get-default-value'; +import getLocalType from '../utils/get-local-type'; +import { toArray } from '../utils/to-array'; type RawField = Partial & { field: string; type: typeof types[number] }; @@ -142,12 +140,12 @@ export class FieldsService { allowedFieldsInCollection[permission.collection] = permission.fields ?? []; }); - if (collection && allowedFieldsInCollection.hasOwnProperty(collection) === false) { + if (collection && collection in allowedFieldsInCollection === false) { throw new ForbiddenException(); } return result.filter((field) => { - if (allowedFieldsInCollection.hasOwnProperty(field.collection) === false) return false; + if (field.collection in allowedFieldsInCollection === false) return false; const allowedFields = allowedFieldsInCollection[field.collection]; if (allowedFields[0] === '*') return true; return allowedFields.includes(field.field); diff --git a/api/src/services/files.ts b/api/src/services/files.ts index 7696f3a10c..c45f1a96ab 100644 --- a/api/src/services/files.ts +++ b/api/src/services/files.ts @@ -1,22 +1,22 @@ -import { ItemsService, MutationOptions } from './items'; -import storage from '../storage'; -import sharp from 'sharp'; -import { parse as parseICC } from 'icc'; +import formatTitle from '@directus/format-title'; +import axios, { AxiosResponse } from 'axios'; import parseEXIF from 'exif-reader'; -import parseIPTC from '../utils/parse-iptc'; -import { AbstractServiceOptions, File, PrimaryKey } from '../types'; +import { parse as parseICC } from 'icc'; import { clone } from 'lodash'; -import cache from '../cache'; -import { ForbiddenException, ServiceUnavailableException } from '../exceptions'; -import { toArray } from '../utils/to-array'; import { extension } from 'mime-types'; import path from 'path'; -import env from '../env'; -import logger from '../logger'; -import axios, { AxiosResponse } from 'axios'; +import sharp from 'sharp'; import url from 'url'; -import formatTitle from '@directus/format-title'; +import cache from '../cache'; import { emitAsyncSafe } from '../emitter'; +import env from '../env'; +import { ForbiddenException, ServiceUnavailableException } from '../exceptions'; +import logger from '../logger'; +import storage from '../storage'; +import { AbstractServiceOptions, File, PrimaryKey } from '../types'; +import parseIPTC from '../utils/parse-iptc'; +import { toArray } from '../utils/to-array'; +import { ItemsService, MutationOptions } from './items'; export class FilesService extends ItemsService { constructor(options: AbstractServiceOptions) { diff --git a/api/src/services/folders.ts b/api/src/services/folders.ts index ff01d2ad01..4d7efb72ac 100644 --- a/api/src/services/folders.ts +++ b/api/src/services/folders.ts @@ -1,5 +1,5 @@ -import { ItemsService } from './items'; import { AbstractServiceOptions } from '../types'; +import { ItemsService } from './items'; export class FoldersService extends ItemsService { constructor(options: AbstractServiceOptions) { diff --git a/api/src/services/graphql.ts b/api/src/services/graphql.ts index f9bec942ca..fe35e22e97 100644 --- a/api/src/services/graphql.ts +++ b/api/src/services/graphql.ts @@ -1,81 +1,75 @@ -import { Knex } from 'knex'; -import database from '../database'; -import { AbstractServiceOptions, Accountability, Query, SchemaOverview, GraphQLParams, Action, Item } from '../types'; import argon2 from 'argon2'; import { - GraphQLString, - GraphQLList, - GraphQLResolveInfo, - ObjectFieldNode, - GraphQLID, - FieldNode, - InlineFragmentNode, - SelectionNode, - GraphQLInt, - IntValueNode, - StringValueNode, - BooleanValueNode, ArgumentNode, - GraphQLBoolean, - ObjectValueNode, - GraphQLUnionType, + BooleanValueNode, execute, - validate, ExecutionResult, - FormattedExecutionResult, - specifiedRules, + FieldNode, formatError, - GraphQLFloat, - GraphQLError, - GraphQLNonNull, + FormattedExecutionResult, FragmentDefinitionNode, - GraphQLSchema, + GraphQLBoolean, GraphQLEnumType, - GraphQLScalarType, + GraphQLError, + GraphQLFloat, + GraphQLID, + GraphQLInt, + GraphQLList, + GraphQLNonNull, GraphQLObjectType, + GraphQLResolveInfo, + GraphQLScalarType, + GraphQLSchema, + GraphQLString, + GraphQLUnionType, + InlineFragmentNode, + IntValueNode, + ObjectFieldNode, + ObjectValueNode, + SelectionNode, + specifiedRules, + StringValueNode, + validate, } from 'graphql'; +import { + GraphQLJSON, + InputTypeComposer, + InputTypeComposerFieldConfigMapDefinition, + ObjectTypeComposer, + ObjectTypeComposerFieldConfigMapDefinition, + SchemaComposer, + toInputObjectType, +} from 'graphql-compose'; +import { Knex } from 'knex'; +import { flatten, get, mapKeys, merge, set, uniq } from 'lodash'; +import ms from 'ms'; +import database from '../database'; +import env from '../env'; +import { BaseException, GraphQLValidationException, InvalidPayloadException } from '../exceptions'; import { listExtensions } from '../extensions'; +import { AbstractServiceOptions, Accountability, Action, GraphQLParams, Item, Query, SchemaOverview } from '../types'; import { getGraphQLType } from '../utils/get-graphql-type'; -import { RelationsService } from './relations'; -import { ItemsService } from './items'; -import { set, merge, get, mapKeys, uniq, flatten } from 'lodash'; +import { reduceSchema } from '../utils/reduce-schema'; import { sanitizeQuery } from '../utils/sanitize-query'; - import { ActivityService } from './activity'; import { AuthenticationService } from './authentication'; import { CollectionsService } from './collections'; import { FieldsService } from './fields'; import { FilesService } from './files'; import { FoldersService } from './folders'; +import { ItemsService } from './items'; import { PermissionsService } from './permissions'; import { PresetsService } from './presets'; +import { RelationsService } from './relations'; import { RevisionsService } from './revisions'; import { RolesService } from './roles'; -import { SettingsService } from './settings'; import { ServerService } from './server'; +import { SettingsService } from './settings'; +import { SpecificationService } from './specifications'; import { UsersService } from './users'; import { UtilsService } from './utils'; import { WebhooksService } from './webhooks'; -import { BaseException, InvalidPayloadException, GraphQLValidationException, ForbiddenException } from '../exceptions'; -import { toArray } from '../utils/to-array'; - -import env from '../env'; -import ms from 'ms'; - -import { reduceSchema } from '../utils/reduce-schema'; - -import { - ObjectTypeComposer, - ObjectTypeComposerFieldConfigMapDefinition, - InputTypeComposerFieldConfigMapDefinition, - SchemaComposer, - InputTypeComposer, - toInputObjectType, - GraphQLJSON, -} from 'graphql-compose'; -import { SpecificationService } from './specifications'; - const GraphQLVoid = new GraphQLScalarType({ name: 'Void', @@ -815,7 +809,7 @@ export class GraphQLService { const args: Record = this.parseArgs(info.fieldNodes[0].arguments || [], info.variableValues); const query = this.getQuery(args, selections, info.variableValues); - if (collection.endsWith('_by_id') && this.schema.collections.hasOwnProperty(collection) === false) { + if (collection.endsWith('_by_id') && collection in this.schema.collections === false) { collection = collection.slice(0, -6); } @@ -861,7 +855,7 @@ export class GraphQLService { const singleton = collection.endsWith('_items') === false && collection.endsWith('_item') === false && - this.schema.collections.hasOwnProperty(collection); + collection in this.schema.collections; const single = collection.endsWith('_items') === false; @@ -1149,7 +1143,6 @@ export class GraphQLService { { CreateCollectionTypes, ReadCollectionTypes, - UpdateCollectionTypes, DeleteCollectionTypes, }: { CreateCollectionTypes: Record>; diff --git a/api/src/services/items.ts b/api/src/services/items.ts index 206922d1ce..332d869513 100644 --- a/api/src/services/items.ts +++ b/api/src/services/items.ts @@ -1,31 +1,28 @@ +import { Knex } from 'knex'; +import { clone, cloneDeep, merge, pick, without } from 'lodash'; +import cache from '../cache'; import database from '../database'; import runAST from '../database/run-ast'; -import getASTFromQuery from '../utils/get-ast-from-query'; +import emitter, { emitAsyncSafe } from '../emitter'; +import env from '../env'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import { translateDatabaseError } from '../exceptions/database/translate'; +import logger from '../logger'; import { - Action, - Accountability, - PermissionsAction, - Item as AnyItem, - Query, - PrimaryKey, AbstractService, AbstractServiceOptions, + Accountability, + Action, + Item as AnyItem, + PermissionsAction, + PrimaryKey, + Query, SchemaOverview, } from '../types'; -import { Knex } from 'knex'; -import cache from '../cache'; -import emitter, { emitAsyncSafe } from '../emitter'; +import getASTFromQuery from '../utils/get-ast-from-query'; import { toArray } from '../utils/to-array'; -import env from '../env'; - -import { PayloadService } from './payload'; import { AuthorizationService } from './authorization'; - -import { pick, clone, cloneDeep, merge, without } from 'lodash'; -import { translateDatabaseError } from '../exceptions/database/translate'; -import { InvalidPayloadException, ForbiddenException } from '../exceptions'; - -import logger from '../logger'; +import { PayloadService } from './payload'; export type QueryOptions = { stripNonRequested?: boolean; @@ -76,7 +73,7 @@ export class ItemsService implements AbstractSer .filter((field) => field.alias === true) .map((field) => field.field); - let payload: AnyItem = cloneDeep(data); + const payload: AnyItem = cloneDeep(data); // By wrapping the logic in a transaction, we make sure we automatically roll back all the // changes in the DB if any of the parts contained within throws an error. This also means @@ -457,10 +454,8 @@ export class ItemsService implements AbstractSer for (const activityRecord of activityRecords) { await trx.insert(activityRecord).into('directus_activity'); - let primaryKey; - const result = await trx.max('id', { as: 'id' }).from('directus_activity').first(); - primaryKey = result.id; + const primaryKey = result.id; activityPrimaryKeys.push(primaryKey); } diff --git a/api/src/services/mail/index.ts b/api/src/services/mail/index.ts index 8b5decca74..b31dd14bfe 100644 --- a/api/src/services/mail/index.ts +++ b/api/src/services/mail/index.ts @@ -1,12 +1,12 @@ -import mailer from '../mailer'; -import { AbstractServiceOptions, Accountability, SchemaOverview } from '../../types'; +import fse from 'fs-extra'; import { Knex } from 'knex'; +import { Liquid } from 'liquidjs'; +import path from 'path'; import database from '../../database'; import env from '../../env'; import logger from '../../logger'; -import fse from 'fs-extra'; -import { Liquid } from 'liquidjs'; -import path from 'path'; +import { AbstractServiceOptions, Accountability, SchemaOverview } from '../../types'; +import mailer from '../mailer'; const liquidEngine = new Liquid({ root: [path.resolve(env.EXTENSIONS_PATH, 'templates'), path.resolve(__dirname, 'templates')], @@ -37,10 +37,11 @@ export class MailService { this.knex = opts?.knex || database; } - async send(options: EmailOptions) { + async send(options: EmailOptions): Promise { if (!mailer) return; - let { to, from, subject, html, text } = options; + const { to, subject, text } = options; + let { from, html } = options; from = from || (env.EMAIL_FROM as string); @@ -67,7 +68,7 @@ export class MailService { } } - private async renderTemplate(template: string, variables: Record, system: boolean = false) { + private async renderTemplate(template: string, variables: Record, system = false) { const resolvedPath = system ? path.join(__dirname, 'templates', template + '.liquid') : path.resolve(env.EXTENSIONS_PATH, 'templates', template + '.liquid'); diff --git a/api/src/services/mailer.ts b/api/src/services/mailer.ts index c9293afb7f..5dbab7bae3 100644 --- a/api/src/services/mailer.ts +++ b/api/src/services/mailer.ts @@ -1,6 +1,6 @@ -import logger from '../logger'; import nodemailer, { Transporter } from 'nodemailer'; import env from '../env'; +import logger from '../logger'; let transporter: Transporter | null = null; diff --git a/api/src/services/meta.ts b/api/src/services/meta.ts index b098673946..e56a01c68a 100644 --- a/api/src/services/meta.ts +++ b/api/src/services/meta.ts @@ -1,9 +1,9 @@ -import { Query } from '../types/query'; -import database from '../database'; -import { AbstractServiceOptions, Accountability, SchemaOverview } from '../types'; import { Knex } from 'knex'; -import { applyFilter, applySearch } from '../utils/apply-query'; +import database from '../database'; import { ForbiddenException } from '../exceptions'; +import { AbstractServiceOptions, Accountability, SchemaOverview } from '../types'; +import { Query } from '../types/query'; +import { applyFilter, applySearch } from '../utils/apply-query'; import { parseFilter } from '../utils/parse-filter'; export class MetaService { diff --git a/api/src/services/payload.ts b/api/src/services/payload.ts index aef275b77a..f1573028e6 100644 --- a/api/src/services/payload.ts +++ b/api/src/services/payload.ts @@ -1,17 +1,14 @@ import argon2 from 'argon2'; +import { format, formatISO, parse, parseISO } from 'date-fns'; +import Joi from 'joi'; +import { Knex } from 'knex'; +import { clone, cloneDeep, isObject, isPlainObject } from 'lodash'; import { v4 as uuidv4 } from 'uuid'; import database from '../database'; -import { clone, isObject, cloneDeep } from 'lodash'; -import { Item, AbstractServiceOptions, Accountability, PrimaryKey, SchemaOverview } from '../types'; -import { ItemsService } from './items'; -import { Knex } from 'knex'; -import { format, formatISO, parse, parseISO } from 'date-fns'; -import { ForbiddenException } from '../exceptions'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import { AbstractServiceOptions, Accountability, Item, PrimaryKey, SchemaOverview } from '../types'; import { toArray } from '../utils/to-array'; -import { systemRelationRows } from '../database/system-data/relations'; -import { InvalidPayloadException } from '../exceptions'; -import { isPlainObject } from 'lodash'; -import Joi from 'joi'; +import { ItemsService } from './items'; type Action = 'create' | 'read' | 'update'; @@ -31,7 +28,7 @@ type Alterations = { update: { [key: string]: any; }[]; - delete: (Number | String)[]; + delete: (number | string)[]; }; /** @@ -101,19 +98,19 @@ export class PayloadService { if (action === 'read') return value ? '**********' : null; return value; }, - async 'user-created'({ action, value, payload, accountability }) { + async 'user-created'({ action, value, accountability }) { if (action === 'create') return accountability?.user || null; return value; }, - async 'user-updated'({ action, value, payload, accountability }) { + async 'user-updated'({ action, value, accountability }) { if (action === 'update') return accountability?.user || null; return value; }, - async 'role-created'({ action, value, payload, accountability }) { + async 'role-created'({ action, value, accountability }) { if (action === 'create') return accountability?.role || null; return value; }, - async 'role-updated'({ action, value, payload, accountability }) { + async 'role-updated'({ action, value, accountability }) { if (action === 'update') return accountability?.role || null; return value; }, @@ -140,18 +137,18 @@ export class PayloadService { action: Action, payload: Partial | Partial[] ): Promise | Partial[]> { - let processedPayload = toArray(payload); + const processedPayload = toArray(payload); if (processedPayload.length === 0) return []; const fieldsInPayload = Object.keys(processedPayload[0]); let specialFieldsInCollection = Object.entries(this.schema.collections[this.collection].fields).filter( - ([name, field]) => field.special && field.special.length > 0 + ([_name, field]) => field.special && field.special.length > 0 ); if (action === 'read') { - specialFieldsInCollection = specialFieldsInCollection.filter(([name, field]) => { + specialFieldsInCollection = specialFieldsInCollection.filter(([name]) => { return fieldsInPayload.includes(name); }); } @@ -198,7 +195,7 @@ export class PayloadService { let value = clone(payload[field.field]); for (const special of fieldSpecials) { - if (this.transformers.hasOwnProperty(special)) { + if (special in this.transformers) { value = await this.transformers[special]({ action, value, @@ -221,7 +218,7 @@ export class PayloadService { ): Promise>[]> { const fieldsInCollection = Object.entries(this.schema.collections[this.collection].fields); - const dateColumns = fieldsInCollection.filter(([name, field]) => + const dateColumns = fieldsInCollection.filter(([_name, field]) => ['dateTime', 'date', 'timestamp'].includes(field.type) ); @@ -286,11 +283,11 @@ export class PayloadService { const revisions: PrimaryKey[] = []; - let payload = cloneDeep(data); + const payload = cloneDeep(data); // Only process related records that are actually in the payload const relationsToProcess = relations.filter((relation) => { - return payload.hasOwnProperty(relation.many_field) && isPlainObject(payload[relation.many_field]); + return relation.many_field in payload && isPlainObject(payload[relation.many_field]); }); for (const relation of relationsToProcess) { @@ -321,7 +318,7 @@ export class PayloadService { const relatedPrimary = this.schema.collections[relatedCollection].primary; const relatedRecord: Partial = payload[relation.many_field]; - const hasPrimaryKey = relatedRecord.hasOwnProperty(relatedPrimary); + const hasPrimaryKey = relatedPrimary in relatedRecord; let relatedPrimaryKey: PrimaryKey = relatedRecord[relatedPrimary]; @@ -355,7 +352,7 @@ export class PayloadService { const payload = cloneDeep(data); // All the revisions saved on this level - let revisions: PrimaryKey[] = []; + const revisions: PrimaryKey[] = []; // Many to one relations that exist on the current collection const relations = this.schema.relations.filter((relation) => { @@ -364,7 +361,7 @@ export class PayloadService { // Only process related records that are actually in the payload const relationsToProcess = relations.filter((relation) => { - return payload.hasOwnProperty(relation.many_field) && isObject(payload[relation.many_field]); + return relation.many_field in payload && isObject(payload[relation.many_field]); }); for (const relation of relationsToProcess) { @@ -379,7 +376,7 @@ export class PayloadService { }); const relatedRecord: Partial = payload[relation.many_field]; - const hasPrimaryKey = relatedRecord.hasOwnProperty(relation.one_primary); + const hasPrimaryKey = relation.one_primary in relatedRecord; if (['string', 'number'].includes(typeof relatedRecord)) continue; @@ -418,12 +415,12 @@ export class PayloadService { return relation.one_collection === this.collection; }); - let payload = cloneDeep(data); + const payload = cloneDeep(data); // Only process related records that are actually in the payload const relationsToProcess = relations.filter((relation) => { if (!relation.one_field) return false; - return payload.hasOwnProperty(relation.one_field); + return relation.one_field in payload; }); const nestedUpdateSchema = Joi.object({ diff --git a/api/src/services/permissions.ts b/api/src/services/permissions.ts index 3d71db74e5..8ed4733b22 100644 --- a/api/src/services/permissions.ts +++ b/api/src/services/permissions.ts @@ -1,9 +1,8 @@ -import { AbstractServiceOptions, PermissionsAction, Query, Item, PrimaryKey } from '../types'; -import { ItemsService, MutationOptions, QueryOptions } from '../services/items'; -import { filterItems } from '../utils/filter-items'; -import logger from '../logger'; - import { appAccessMinimalPermissions } from '../database/system-data/app-access-permissions'; +import logger from '../logger'; +import { ItemsService, QueryOptions } from '../services/items'; +import { AbstractServiceOptions, Item, PermissionsAction, PrimaryKey, Query } from '../types'; +import { filterItems } from '../utils/filter-items'; export class PermissionsService extends ItemsService { constructor(options: AbstractServiceOptions) { @@ -18,7 +17,9 @@ export class PermissionsService extends ItemsService { matchesCollection = permission.collection === collection; } - return permission.action === action; + const matchesAction = permission.action === action; + + return collection ? matchesCollection && matchesAction : matchesAction; }); const fieldsPerCollection: Record = {}; diff --git a/api/src/services/presets.ts b/api/src/services/presets.ts index 675ef9fab7..95a7036024 100644 --- a/api/src/services/presets.ts +++ b/api/src/services/presets.ts @@ -1,5 +1,5 @@ -import { ItemsService } from './items'; import { AbstractServiceOptions } from '../types'; +import { ItemsService } from './items'; export class PresetsService extends ItemsService { constructor(options: AbstractServiceOptions) { diff --git a/api/src/services/relations.ts b/api/src/services/relations.ts index 2a5cdf466b..9b7fd19358 100644 --- a/api/src/services/relations.ts +++ b/api/src/services/relations.ts @@ -1,12 +1,10 @@ -import { ItemsService, QueryOptions } from './items'; -import { AbstractServiceOptions, Query, PrimaryKey, PermissionsAction, Relation } from '../types'; -import { PermissionsService } from './permissions'; -import { toArray } from '../utils/to-array'; - import { systemRelationRows } from '../database/system-data/relations'; import { ForbiddenException } from '../exceptions'; - import logger from '../logger'; +import { AbstractServiceOptions, PermissionsAction, PrimaryKey, Query, Relation } from '../types'; +import { toArray } from '../utils/to-array'; +import { ItemsService, QueryOptions } from './items'; +import { PermissionsService } from './permissions'; export class RelationsService extends ItemsService { permissionsService: PermissionsService; diff --git a/api/src/services/revisions.ts b/api/src/services/revisions.ts index 2f89dfe692..ec2367baa4 100644 --- a/api/src/services/revisions.ts +++ b/api/src/services/revisions.ts @@ -1,6 +1,6 @@ +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import { AbstractServiceOptions, PrimaryKey } from '../types'; import { ItemsService } from './items'; -import { AbstractServiceOptions, PrimaryKey, Revision } from '../types'; -import { InvalidPayloadException, ForbiddenException } from '../exceptions'; export class RevisionsService extends ItemsService { constructor(options: AbstractServiceOptions) { diff --git a/api/src/services/roles.ts b/api/src/services/roles.ts index 48676758f6..57f7203f7c 100644 --- a/api/src/services/roles.ts +++ b/api/src/services/roles.ts @@ -1,10 +1,9 @@ -import { ItemsService } from './items'; -import { AbstractServiceOptions, PrimaryKey } from '../types'; -import { PermissionsService } from './permissions'; -import { UsersService } from './users'; -import { PresetsService } from './presets'; import { UnprocessableEntityException } from '../exceptions'; -import { toArray } from '../utils/to-array'; +import { AbstractServiceOptions, PrimaryKey } from '../types'; +import { ItemsService } from './items'; +import { PermissionsService } from './permissions'; +import { PresetsService } from './presets'; +import { UsersService } from './users'; export class RolesService extends ItemsService { constructor(options: AbstractServiceOptions) { diff --git a/api/src/services/server.ts b/api/src/services/server.ts index 01a15f70cf..65215d9757 100644 --- a/api/src/services/server.ts +++ b/api/src/services/server.ts @@ -1,21 +1,21 @@ -import { AbstractServiceOptions, Accountability, SchemaOverview } from '../types'; import { Knex } from 'knex'; -import database from '../database'; +import { merge } from 'lodash'; +import macosRelease from 'macos-release'; +import { nanoid } from 'nanoid'; import os from 'os'; -import logger from '../logger'; +import { performance } from 'perf_hooks'; // @ts-ignore import { version } from '../../package.json'; -import macosRelease from 'macos-release'; -import { SettingsService } from './settings'; -import mailer from './mailer'; -import env from '../env'; -import { performance } from 'perf_hooks'; import cache from '../cache'; +import database from '../database'; +import env from '../env'; +import logger from '../logger'; import { rateLimiter } from '../middleware/rate-limiter'; import storage from '../storage'; -import { nanoid } from 'nanoid'; +import { AbstractServiceOptions, Accountability, SchemaOverview } from '../types'; import { toArray } from '../utils/to-array'; -import { merge } from 'lodash'; +import mailer from './mailer'; +import { SettingsService } from './settings'; export class ServerService { knex: Knex; diff --git a/api/src/services/settings.ts b/api/src/services/settings.ts index e4edaa4864..48cc503c2b 100644 --- a/api/src/services/settings.ts +++ b/api/src/services/settings.ts @@ -1,5 +1,5 @@ -import { ItemsService } from './items'; import { AbstractServiceOptions } from '../types'; +import { ItemsService } from './items'; export class SettingsService extends ItemsService { constructor(options: AbstractServiceOptions) { diff --git a/api/src/services/specifications.ts b/api/src/services/specifications.ts index 6f331e861e..1187775ba3 100644 --- a/api/src/services/specifications.ts +++ b/api/src/services/specifications.ts @@ -1,3 +1,12 @@ +import formatTitle from '@directus/format-title'; +import openapi from '@directus/specs'; +import { Knex } from 'knex'; +import { cloneDeep, mergeWith } from 'lodash'; +import { OpenAPIObject, OperationObject, PathItemObject, SchemaObject, TagObject } from 'openapi3-ts'; +// @ts-ignore +import { version } from '../../package.json'; +import database from '../database'; +import env from '../env'; import { AbstractServiceOptions, Accountability, @@ -8,22 +17,11 @@ import { SchemaOverview, types, } from '../types'; +import { getRelationType } from '../utils/get-relation-type'; import { CollectionsService } from './collections'; import { FieldsService } from './fields'; -import formatTitle from '@directus/format-title'; -import { cloneDeep, mergeWith } from 'lodash'; -import { RelationsService } from './relations'; -import env from '../env'; -import { OpenAPIObject, PathItemObject, OperationObject, TagObject, SchemaObject } from 'openapi3-ts'; - -// @ts-ignore -import { version } from '../../package.json'; -import openapi from '@directus/specs'; - -import { Knex } from 'knex'; -import database from '../database'; -import { getRelationType } from '../utils/get-relation-type'; import { GraphQLService } from './graphql'; +import { RelationsService } from './relations'; export class SpecificationService { accountability: Accountability | null; @@ -164,7 +162,7 @@ class OASSpecsService implements SpecificationSubService { if (!tags) return paths; for (const tag of tags) { - const isSystem = tag.hasOwnProperty('x-collection') === false || tag['x-collection'].startsWith('directus_'); + const isSystem = 'x-collection' in tag === false || tag['x-collection'].startsWith('directus_'); if (isSystem) { for (const [path, pathItem] of Object.entries(openapi.paths)) { @@ -176,7 +174,7 @@ class OASSpecsService implements SpecificationSubService { const hasPermission = this.accountability?.admin === true || - tag.hasOwnProperty('x-collection') === false || + 'x-collection' in tag === false || !!permissions.find( (permission) => permission.collection === tag['x-collection'] && diff --git a/api/src/services/users.ts b/api/src/services/users.ts index 9df94f1fb1..4b47b1e40d 100644 --- a/api/src/services/users.ts +++ b/api/src/services/users.ts @@ -1,24 +1,24 @@ -import { AuthenticationService } from './authentication'; -import { ItemsService, MutationOptions } from './items'; -import jwt from 'jsonwebtoken'; -import database from '../database'; import argon2 from 'argon2'; -import { - InvalidPayloadException, - ForbiddenException, - UnprocessableEntityException, - FailedValidationException, -} from '../exceptions'; -import { Accountability, PrimaryKey, Item, AbstractServiceOptions, SchemaOverview, Query } from '../types'; +import jwt from 'jsonwebtoken'; import { Knex } from 'knex'; -import env from '../env'; +import { clone } from 'lodash'; import cache from '../cache'; -import { toArray } from '../utils/to-array'; +import database from '../database'; +import env from '../env'; +import { + FailedValidationException, + ForbiddenException, + InvalidPayloadException, + UnprocessableEntityException, +} from '../exceptions'; import { RecordNotUniqueException } from '../exceptions/database/record-not-unique'; import logger from '../logger'; -import { clone } from 'lodash'; -import { SettingsService } from './settings'; +import { AbstractServiceOptions, Accountability, Item, PrimaryKey, Query, SchemaOverview } from '../types'; +import { toArray } from '../utils/to-array'; +import { AuthenticationService } from './authentication'; +import { ItemsService, MutationOptions } from './items'; import { MailService } from './mail'; +import { SettingsService } from './settings'; export class UsersService extends ItemsService { knex: Knex; @@ -132,7 +132,7 @@ export class UsersService extends ItemsService { await this.checkPasswordPolicy([data.password]); } - if (data.hasOwnProperty('tfa_secret')) { + if ('tfa_secret' in data) { throw new InvalidPayloadException(`You can't change the "tfa_secret" value manually.`); } @@ -150,7 +150,7 @@ export class UsersService extends ItemsService { await this.checkPasswordPolicy([data.password]); } - if (data.hasOwnProperty('tfa_secret')) { + if ('tfa_secret' in data) { throw new InvalidPayloadException(`You can't change the "tfa_secret" value manually.`); } @@ -168,7 +168,7 @@ export class UsersService extends ItemsService { await this.checkPasswordPolicy([data.password]); } - if (data.hasOwnProperty('tfa_secret')) { + if ('tfa_secret' in data) { throw new InvalidPayloadException(`You can't change the "tfa_secret" value manually.`); } diff --git a/api/src/services/utils.ts b/api/src/services/utils.ts index 94897813d6..d7a1929a69 100644 --- a/api/src/services/utils.ts +++ b/api/src/services/utils.ts @@ -1,8 +1,8 @@ -import { AbstractServiceOptions, Accountability, PrimaryKey, SchemaOverview } from '../types'; -import database from '../database'; import { Knex } from 'knex'; -import { InvalidPayloadException, ForbiddenException } from '../exceptions'; +import database from '../database'; import { systemCollectionRows } from '../database/system-data/collections'; +import { ForbiddenException, InvalidPayloadException } from '../exceptions'; +import { AbstractServiceOptions, Accountability, PrimaryKey, SchemaOverview } from '../types'; export class UtilsService { knex: Knex; diff --git a/api/src/services/webhooks.ts b/api/src/services/webhooks.ts index 184e9ee22d..76d779a688 100644 --- a/api/src/services/webhooks.ts +++ b/api/src/services/webhooks.ts @@ -1,6 +1,6 @@ -import { ItemsService, MutationOptions } from './items'; -import { Item, PrimaryKey, AbstractServiceOptions } from '../types'; +import { AbstractServiceOptions, Item, PrimaryKey } from '../types'; import { register } from '../webhooks'; +import { ItemsService, MutationOptions } from './items'; export class WebhooksService extends ItemsService { constructor(options: AbstractServiceOptions) { diff --git a/api/src/storage.ts b/api/src/storage.ts index 65359200f4..a027a78dd3 100644 --- a/api/src/storage.ts +++ b/api/src/storage.ts @@ -1,13 +1,12 @@ -import { StorageManager, LocalFileSystemStorage, StorageManagerConfig, Storage } from '@directus/drive'; -import env from './env'; -import { validateEnv } from './utils/validate-env'; -import { getConfigFromEnv } from './utils/get-config-from-env'; -import { toArray } from './utils/to-array'; - +import { LocalFileSystemStorage, Storage, StorageManager, StorageManagerConfig } from '@directus/drive'; +import { AzureBlobWebServicesStorage } from '@directus/drive-azure'; +import { GoogleCloudStorage } from '@directus/drive-gcs'; /** @todo dynamically load these storage adapters */ import { AmazonWebServicesS3Storage } from '@directus/drive-s3'; -import { GoogleCloudStorage } from '@directus/drive-gcs'; -import { AzureBlobWebServicesStorage } from '@directus/drive-azure'; +import env from './env'; +import { getConfigFromEnv } from './utils/get-config-from-env'; +import { toArray } from './utils/to-array'; +import { validateEnv } from './utils/validate-env'; validateEnv(['STORAGE_LOCATIONS']); diff --git a/api/src/types/collection.ts b/api/src/types/collection.ts index 3a2506aae1..6d16a42d1d 100644 --- a/api/src/types/collection.ts +++ b/api/src/types/collection.ts @@ -1,5 +1,5 @@ -import { Field } from './field'; import { Table } from 'knex-schema-inspector/dist/types/table'; +import { Field } from './field'; export type CollectionMeta = { collection: string; diff --git a/api/src/types/express.d.ts b/api/src/types/express.d.ts index fb3896670f..528f44f51a 100644 --- a/api/src/types/express.d.ts +++ b/api/src/types/express.d.ts @@ -2,11 +2,8 @@ * Custom properties on the req object in express */ -import { Permission } from './permissions'; -import { Relation } from './relation'; - -import { Query } from './query'; import { Accountability } from './accountability'; +import { Query } from './query'; import { SchemaOverview } from './schema'; export {}; diff --git a/api/src/types/extensions.ts b/api/src/types/extensions.ts index a614c1b3d1..2250bd89d5 100644 --- a/api/src/types/extensions.ts +++ b/api/src/types/extensions.ts @@ -1,9 +1,9 @@ import { ListenerFn } from 'eventemitter2'; -import * as services from '../services'; -import * as exceptions from '../exceptions'; -import env from '../env'; -import { Knex } from 'knex'; import { Router } from 'express'; +import { Knex } from 'knex'; +import env from '../env'; +import * as exceptions from '../exceptions'; +import * as services from '../services'; import { getSchema } from '../utils/get-schema'; export type ExtensionContext = { diff --git a/api/src/types/graphql.ts b/api/src/types/graphql.ts index fc2ad5f867..978db253bf 100644 --- a/api/src/types/graphql.ts +++ b/api/src/types/graphql.ts @@ -1,5 +1,5 @@ -import { DocumentNode } from 'graphql'; import { Request, Response } from 'express'; +import { DocumentNode } from 'graphql'; export interface GraphQLParams { query: string | null; diff --git a/api/src/types/schema.ts b/api/src/types/schema.ts index 6acf5613c3..8aa19a3c4d 100644 --- a/api/src/types/schema.ts +++ b/api/src/types/schema.ts @@ -1,6 +1,6 @@ -import { Relation } from './relation'; -import { Permission } from './permissions'; import { types } from './field'; +import { Permission } from './permissions'; +import { Relation } from './relation'; type CollectionsOverview = { [name: string]: { diff --git a/api/src/types/services.ts b/api/src/types/services.ts index efd43eb84a..a38673693a 100644 --- a/api/src/types/services.ts +++ b/api/src/types/services.ts @@ -1,9 +1,9 @@ import { Knex } from 'knex'; +import { SchemaOverview } from '../types'; import { Accountability } from './accountability'; import { Item, PrimaryKey } from './items'; -import { Query } from './query'; import { PermissionsAction } from './permissions'; -import { SchemaOverview } from '../types'; +import { Query } from './query'; export type AbstractServiceOptions = { knex?: Knex; diff --git a/api/src/utils/apply-query.ts b/api/src/utils/apply-query.ts index 20bfc80fab..ebdd27902f 100644 --- a/api/src/utils/apply-query.ts +++ b/api/src/utils/apply-query.ts @@ -1,9 +1,9 @@ import { Knex } from 'knex'; -import { Query, Filter, Relation, SchemaOverview } from '../types'; -import { clone, isPlainObject, get, set } from 'lodash'; -import { systemRelationRows } from '../database/system-data/relations'; +import { clone, get, isPlainObject, set } from 'lodash'; import { customAlphabet } from 'nanoid'; import validate from 'uuid-validate'; +import { systemRelationRows } from '../database/system-data/relations'; +import { Filter, Query, Relation, SchemaOverview } from '../types'; const generateAlias = customAlphabet('abcdefghijklmnopqrstuvwxyz', 5); @@ -12,7 +12,7 @@ export default function applyQuery( dbQuery: Knex.QueryBuilder, query: Query, schema: SchemaOverview, - subQuery: boolean = false + subQuery = false ): void { if (query.sort) { dbQuery.orderBy( @@ -49,7 +49,7 @@ export function applyFilter( rootQuery: Knex.QueryBuilder, rootFilter: Filter, collection: string, - subQuery: boolean = false + subQuery = false ): void { const relations: Relation[] = [...schema.relations, ...systemRelationRows]; diff --git a/api/src/utils/async-handler.ts b/api/src/utils/async-handler.ts index a987f244c3..e50cb7b6d8 100644 --- a/api/src/utils/async-handler.ts +++ b/api/src/utils/async-handler.ts @@ -1,4 +1,4 @@ -import { RequestHandler, ErrorRequestHandler } from 'express'; +import { ErrorRequestHandler, RequestHandler } from 'express'; /** * Handles promises in routes. diff --git a/api/src/utils/deep-map.ts b/api/src/utils/deep-map.ts index 854c2274c3..f3b8d1070d 100644 --- a/api/src/utils/deep-map.ts +++ b/api/src/utils/deep-map.ts @@ -11,8 +11,8 @@ export function deepMap( } else if (typeof object === 'object') { const res: Record = {}; - for (var key in object) { - var val = object[key]; + for (const key in object) { + const val = object[key]; if (typeof val === 'object') { res[key] = deepMap(val, iterator, context); diff --git a/api/src/utils/generate-joi.ts b/api/src/utils/generate-joi.ts index 6ffe1cbd95..4f6bc9b5b7 100644 --- a/api/src/utils/generate-joi.ts +++ b/api/src/utils/generate-joi.ts @@ -1,5 +1,5 @@ -import { Filter } from '../types'; import BaseJoi, { AnySchema } from 'joi'; +import { Filter } from '../types'; const Joi: typeof BaseJoi = BaseJoi.extend({ type: 'string', @@ -21,7 +21,7 @@ const Joi: typeof BaseJoi = BaseJoi.extend({ method(substring) { return this.$_addRule({ name: 'contains', args: { substring } }); }, - validate(value, helpers, { substring }, options) { + validate(value, helpers, { substring }) { if (value.includes(substring) === false) { return helpers.error('string.contains', { substring }); } @@ -41,7 +41,7 @@ const Joi: typeof BaseJoi = BaseJoi.extend({ method(substring) { return this.$_addRule({ name: 'ncontains', args: { substring } }); }, - validate(value, helpers, { substring }, options) { + validate(value, helpers, { substring }) { if (value.includes(substring) === true) { return helpers.error('string.ncontains', { substring }); } diff --git a/api/src/utils/get-ast-from-query.ts b/api/src/utils/get-ast-from-query.ts index 2caad17886..da15f390d2 100644 --- a/api/src/utils/get-ast-from-query.ts +++ b/api/src/utils/get-ast-from-query.ts @@ -2,17 +2,17 @@ * Generate an AST based on a given collection and query */ +import { Knex } from 'knex'; +import { cloneDeep, mapKeys, omitBy } from 'lodash'; import { - AST, - NestedCollectionNode, - FieldNode, - Query, - PermissionsAction, Accountability, + AST, + FieldNode, + NestedCollectionNode, + PermissionsAction, + Query, SchemaOverview, } from '../types'; -import { cloneDeep, omitBy, mapKeys } from 'lodash'; -import { Knex } from 'knex'; import { getRelationType } from '../utils/get-relation-type'; type GetASTOptions = { @@ -100,7 +100,7 @@ export default async function getASTFromQuery( collectionScope = scope; } - if (relationalStructure.hasOwnProperty(fieldKey) === false) { + if (fieldKey in relationalStructure === false) { if (collectionScope) { relationalStructure[fieldKey] = { [collectionScope]: [] }; } else { diff --git a/api/src/utils/get-config-from-env.ts b/api/src/utils/get-config-from-env.ts index 671a4c52d4..89c26ed26b 100644 --- a/api/src/utils/get-config-from-env.ts +++ b/api/src/utils/get-config-from-env.ts @@ -1,6 +1,6 @@ import camelcase from 'camelcase'; -import env from '../env'; import { set } from 'lodash'; +import env from '../env'; export function getConfigFromEnv(prefix: string, omitPrefix?: string | string[]): any { const config: any = {}; diff --git a/api/src/utils/get-default-value.ts b/api/src/utils/get-default-value.ts index 4bf11a14d9..afb8d60217 100644 --- a/api/src/utils/get-default-value.ts +++ b/api/src/utils/get-default-value.ts @@ -1,6 +1,6 @@ -import getLocalType from './get-local-type'; -import { Column } from 'knex-schema-inspector/dist/types/column'; import { SchemaOverview } from '@directus/schema/dist/types/overview'; +import { Column } from 'knex-schema-inspector/dist/types/column'; +import getLocalType from './get-local-type'; export default function getDefaultValue( column: SchemaOverview[string]['columns'][string] | Column diff --git a/api/src/utils/get-local-type.ts b/api/src/utils/get-local-type.ts index 22378569a6..18e1e203f3 100644 --- a/api/src/utils/get-local-type.ts +++ b/api/src/utils/get-local-type.ts @@ -1,6 +1,6 @@ -import { FieldMeta, types } from '../types'; -import { Column } from 'knex-schema-inspector/dist/types/column'; import { SchemaOverview } from '@directus/schema/dist/types/overview'; +import { Column } from 'knex-schema-inspector/dist/types/column'; +import { FieldMeta, types } from '../types'; /** * Typemap graciously provided by @gpetrov diff --git a/api/src/utils/get-schema.ts b/api/src/utils/get-schema.ts index 6a4f912f01..9bb0ae8d0b 100644 --- a/api/src/utils/get-schema.ts +++ b/api/src/utils/get-schema.ts @@ -1,17 +1,16 @@ -import { appAccessMinimalPermissions } from '../database/system-data/app-access-permissions'; -import { Accountability, SchemaOverview, Permission, RelationRaw } from '../types'; -import logger from '../logger'; -import { mergePermissions } from './merge-permissions'; -import { Knex } from 'knex'; import SchemaInspector from '@directus/schema'; +import { Knex } from 'knex'; import { mapValues } from 'lodash'; - +import { appAccessMinimalPermissions } from '../database/system-data/app-access-permissions'; import { systemCollectionRows } from '../database/system-data/collections'; import { systemFieldRows } from '../database/system-data/fields'; import { systemRelationRows } from '../database/system-data/relations'; -import getLocalType from './get-local-type'; -import getDefaultValue from './get-default-value'; +import logger from '../logger'; +import { Accountability, Permission, RelationRaw, SchemaOverview } from '../types'; import { toArray } from '../utils/to-array'; +import getDefaultValue from './get-default-value'; +import getLocalType from './get-local-type'; +import { mergePermissions } from './merge-permissions'; export async function getSchema(options?: { accountability?: Accountability; diff --git a/api/src/utils/merge-permissions.ts b/api/src/utils/merge-permissions.ts index c214bf5463..1af0ba1b8e 100644 --- a/api/src/utils/merge-permissions.ts +++ b/api/src/utils/merge-permissions.ts @@ -1,5 +1,5 @@ +import { flatten, merge, omit } from 'lodash'; import { Permission } from '../types'; -import { merge, omit, flatten } from 'lodash'; export function mergePermissions(...permissions: Permission[][]): Permission[] { const allPermissions = flatten(permissions); diff --git a/api/src/utils/parse-filter.ts b/api/src/utils/parse-filter.ts index 8ca2580c12..cf7f311ef9 100644 --- a/api/src/utils/parse-filter.ts +++ b/api/src/utils/parse-filter.ts @@ -1,6 +1,6 @@ -import { Filter, Accountability } from '../types'; -import { deepMap } from './deep-map'; +import { Accountability, Filter } from '../types'; import { toArray } from '../utils/to-array'; +import { deepMap } from './deep-map'; export function parseFilter(filter: Filter, accountability: Accountability | null): any { return deepMap(filter, (val, key) => { diff --git a/api/src/utils/parse-iptc.ts b/api/src/utils/parse-iptc.ts index 21dd8fc187..054ef007e3 100644 --- a/api/src/utils/parse-iptc.ts +++ b/api/src/utils/parse-iptc.ts @@ -16,25 +16,25 @@ const IPTC_ENTRY_MARKER = Buffer.from([0x1c, 0x02]); export default function parseIPTC(buffer: Buffer): Record { if (!Buffer.isBuffer(buffer)) return {}; - let iptc: Record = {}; + const iptc: Record = {}; let lastIptcEntryPos = buffer.indexOf(IPTC_ENTRY_MARKER); while (lastIptcEntryPos !== -1) { lastIptcEntryPos = buffer.indexOf(IPTC_ENTRY_MARKER, lastIptcEntryPos + IPTC_ENTRY_MARKER.byteLength); - let iptcBlockTypePos = lastIptcEntryPos + IPTC_ENTRY_MARKER.byteLength; - let iptcBlockSizePos = iptcBlockTypePos + 1; - let iptcBlockDataPos = iptcBlockSizePos + 2; + const iptcBlockTypePos = lastIptcEntryPos + IPTC_ENTRY_MARKER.byteLength; + const iptcBlockSizePos = iptcBlockTypePos + 1; + const iptcBlockDataPos = iptcBlockSizePos + 2; - let iptcBlockType = buffer.readUInt8(iptcBlockTypePos); - let iptcBlockSize = buffer.readUInt16BE(iptcBlockSizePos); + const iptcBlockType = buffer.readUInt8(iptcBlockTypePos); + const iptcBlockSize = buffer.readUInt16BE(iptcBlockSizePos); if (!IPTC_ENTRY_TYPES.has(iptcBlockType)) { continue; } - let iptcBlockTypeId = IPTC_ENTRY_TYPES.get(iptcBlockType); - let iptcData = buffer.slice(iptcBlockDataPos, iptcBlockDataPos + iptcBlockSize).toString(); + const iptcBlockTypeId = IPTC_ENTRY_TYPES.get(iptcBlockType); + const iptcData = buffer.slice(iptcBlockDataPos, iptcBlockDataPos + iptcBlockSize).toString(); if (iptcBlockTypeId) { if (iptc[iptcBlockTypeId] == null) { diff --git a/api/src/utils/reduce-schema.ts b/api/src/utils/reduce-schema.ts index 25ba34a892..e832aaff4f 100644 --- a/api/src/utils/reduce-schema.ts +++ b/api/src/utils/reduce-schema.ts @@ -1,5 +1,5 @@ -import { PermissionsAction, SchemaOverview } from '../types'; import { uniq } from 'lodash'; +import { PermissionsAction, SchemaOverview } from '../types'; /** * Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only diff --git a/api/src/utils/sanitize-query.ts b/api/src/utils/sanitize-query.ts index c248a22bc8..cc95e2ea8c 100644 --- a/api/src/utils/sanitize-query.ts +++ b/api/src/utils/sanitize-query.ts @@ -1,7 +1,7 @@ -import { Accountability, Query, Sort, Filter, Meta } from '../types'; +import { flatten, get, merge, set } from 'lodash'; import logger from '../logger'; +import { Accountability, Filter, Meta, Query, Sort } from '../types'; import { parseFilter } from '../utils/parse-filter'; -import { flatten, set, merge, get } from 'lodash'; export function sanitizeQuery(rawQuery: Record, accountability?: Accountability | null): Query { const query: Query = {}; diff --git a/api/src/utils/track.ts b/api/src/utils/track.ts index 1da20d2cc5..078e15c74e 100644 --- a/api/src/utils/track.ts +++ b/api/src/utils/track.ts @@ -1,13 +1,11 @@ import axios from 'axios'; -import os from 'os'; -import { machineId } from 'node-machine-id'; import ms from 'ms'; - -import logger from '../logger'; - -import env from '../env'; +import { machineId } from 'node-machine-id'; +import os from 'os'; // @ts-ignore import { version } from '../../package.json'; +import env from '../env'; +import logger from '../logger'; export async function track(event: string): Promise { if (env.TELEMETRY !== false) { diff --git a/api/src/utils/validate-env.ts b/api/src/utils/validate-env.ts index bf1a8d0a4f..39d7b050f7 100644 --- a/api/src/utils/validate-env.ts +++ b/api/src/utils/validate-env.ts @@ -1,5 +1,5 @@ -import logger from '../logger'; import env from '../env'; +import logger from '../logger'; export function validateEnv(requiredKeys: string[]): void { if (env.DB_CLIENT && env.DB_CLIENT === 'sqlite3') { @@ -17,7 +17,7 @@ export function validateEnv(requiredKeys: string[]): void { } for (const requiredKey of requiredKeys) { - if (env.hasOwnProperty(requiredKey) === false) { + if (requiredKey in env === false) { logger.error(`"${requiredKey}" Environment Variable is missing.`); process.exit(1); } diff --git a/api/src/utils/validate-query.ts b/api/src/utils/validate-query.ts index 9e4e6348db..a8c0ba9745 100644 --- a/api/src/utils/validate-query.ts +++ b/api/src/utils/validate-query.ts @@ -1,7 +1,7 @@ -import { Query } from '../types'; import Joi from 'joi'; -import { InvalidQueryException } from '../exceptions'; import { isPlainObject } from 'lodash'; +import { InvalidQueryException } from '../exceptions'; +import { Query } from '../types'; const querySchema = Joi.object({ fields: Joi.array().items(Joi.string()), @@ -39,7 +39,7 @@ export function validateQuery(query: Query): Query { function validateFilter(filter: Query['filter']) { if (!filter) throw new InvalidQueryException('Invalid filter object'); - for (let [key, nested] of Object.entries(filter)) { + for (const [key, nested] of Object.entries(filter)) { if (key === '_and' || key === '_or') { nested.forEach(validateFilter); } else if (isPlainObject(nested)) { diff --git a/api/src/webhooks.ts b/api/src/webhooks.ts index 76c82db5bf..a3dbab1064 100644 --- a/api/src/webhooks.ts +++ b/api/src/webhooks.ts @@ -1,9 +1,9 @@ -import { Webhook } from './types'; -import emitter from './emitter'; -import database from './database'; -import { ListenerFn } from 'eventemitter2'; import axios from 'axios'; +import { ListenerFn } from 'eventemitter2'; +import database from './database'; +import emitter from './emitter'; import logger from './logger'; +import { Webhook } from './types'; let registered: { event: string; handler: ListenerFn }[] = []; diff --git a/app/src/api.ts b/app/src/api.ts index 4a3aef85e5..128f92a8cd 100644 --- a/app/src/api.ts +++ b/app/src/api.ts @@ -1,7 +1,7 @@ -import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'; +import { logout, LogoutReason, refresh } from '@/auth'; import { useRequestsStore } from '@/stores/'; -import { LogoutReason, logout, refresh } from '@/auth'; import { getRootPath } from '@/utils/get-root-path'; +import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; import { addQueryToPath } from './utils/add-query-to-path'; const api = axios.create({ diff --git a/app/src/auth.ts b/app/src/auth.ts index c025e8493d..3782032a81 100644 --- a/app/src/auth.ts +++ b/app/src/auth.ts @@ -1,8 +1,8 @@ -import { RawLocation } from 'vue-router'; import api from '@/api'; -import { hydrate, dehydrate } from '@/hydrate'; +import { dehydrate, hydrate } from '@/hydrate'; import router from '@/router'; import { useAppStore } from '@/stores'; +import { RawLocation } from 'vue-router'; export type LoginCredentials = { email: string; diff --git a/app/src/components/register.ts b/app/src/components/register.ts index 324a012f5d..3923a18348 100644 --- a/app/src/components/register.ts +++ b/app/src/components/register.ts @@ -1,20 +1,29 @@ +import FilterSidebarDetail from '@/views/private/components/filter-sidebar-detail'; +import RenderDisplay from '@/views/private/components/render-display'; +import RenderTemplate from '@/views/private/components/render-template'; +import SidebarDetail from '@/views/private/components/sidebar-detail/'; +import UserPopover from '@/views/private/components/user-popover'; +import ValueNull from '@/views/private/components/value-null'; import Vue from 'vue'; - +import TransitionBounce from './transition/bounce'; +import TransitionDialog from './transition/dialog'; +import TransitionExpand from './transition/expand'; import VAvatar from './v-avatar/'; import VBadge from './v-badge/'; import VBreadcrumb from './v-breadcrumb'; -import VButton from './v-button/'; import VButtonGroup from './v-button-group/'; -import VCard, { VCardActions, VCardTitle, VCardSubtitle, VCardText } from './v-card'; +import VButton from './v-button/'; +import VCard, { VCardActions, VCardSubtitle, VCardText, VCardTitle } from './v-card'; import VCheckbox from './v-checkbox/'; import VChip from './v-chip/'; import VDetail from './v-detail'; import VDialog from './v-dialog'; import VDivider from './v-divider'; +import VDrawer from './v-drawer/'; import VError from './v-error'; import VFancySelect from './v-fancy-select'; -import VFieldTemplate from './v-field-template'; import VFieldSelect from './v-field-select'; +import VFieldTemplate from './v-field-template'; import VForm from './v-form'; import VHover from './v-hover/'; import VIcon from './v-icon/'; @@ -23,7 +32,6 @@ import VInput from './v-input/'; import VItemGroup, { VItem } from './v-item-group'; import VList, { VListGroup, VListItem, VListItemContent, VListItemHint, VListItemIcon } from './v-list/'; import VMenu from './v-menu/'; -import VDrawer from './v-drawer/'; import VNotice from './v-notice/'; import VOverlay from './v-overlay/'; import VPagination from './v-pagination/'; @@ -36,9 +44,9 @@ import VSkeletonLoader from './v-skeleton-loader/'; import VSlider from './v-slider/'; import VSwitch from './v-switch/'; import VTable from './v-table/'; -import VTabs, { VTab, VTabsItems, VTabItem } from './v-tabs/'; -import VTextarea from './v-textarea'; +import VTabs, { VTab, VTabItem, VTabsItems } from './v-tabs/'; import VTextOverflow from './v-text-overflow.vue'; +import VTextarea from './v-textarea'; import VUpload from './v-upload'; Vue.component('v-avatar', VAvatar); @@ -95,21 +103,10 @@ Vue.component('v-textarea', VTextarea); Vue.component('v-text-overflow', VTextOverflow); Vue.component('v-upload', VUpload); -import TransitionBounce from './transition/bounce'; -import TransitionDialog from './transition/dialog'; -import TransitionExpand from './transition/expand'; - Vue.component('transition-bounce', TransitionBounce); Vue.component('transition-dialog', TransitionDialog); Vue.component('transition-expand', TransitionExpand); -import RenderDisplay from '@/views/private/components/render-display'; -import RenderTemplate from '@/views/private/components/render-template'; -import SidebarDetail from '@/views/private/components/sidebar-detail/'; -import FilterSidebarDetail from '@/views/private/components/filter-sidebar-detail'; -import UserPopover from '@/views/private/components/user-popover'; -import ValueNull from '@/views/private/components/value-null'; - Vue.component('render-display', RenderDisplay); Vue.component('render-template', RenderTemplate); Vue.component('filter-sidebar-detail', FilterSidebarDetail); diff --git a/app/src/components/v-card/index.ts b/app/src/components/v-card/index.ts index 00432128b9..63f0acc7e1 100644 --- a/app/src/components/v-card/index.ts +++ b/app/src/components/v-card/index.ts @@ -1,8 +1,8 @@ -import VCard from './v-card.vue'; -import VCardTitle from './v-card-title.vue'; +import VCardActions from './v-card-actions.vue'; import VCardSubtitle from './v-card-subtitle.vue'; import VCardText from './v-card-text.vue'; -import VCardActions from './v-card-actions.vue'; +import VCardTitle from './v-card-title.vue'; +import VCard from './v-card.vue'; export { VCard, VCardTitle, VCardSubtitle, VCardActions, VCardText }; export default VCard; diff --git a/app/src/components/v-dialog/v-dialog.vue b/app/src/components/v-dialog/v-dialog.vue index 7b15d5b32f..2c040ffbbb 100644 --- a/app/src/components/v-dialog/v-dialog.vue +++ b/app/src/components/v-dialog/v-dialog.vue @@ -37,8 +37,6 @@ export default defineComponent({ }, }, setup(props, { emit }) { - const dialog = ref(null); - useShortcut('escape', (event, cancelNext) => { if (_active.value) { emit('esc'); diff --git a/app/src/components/v-drawer/v-drawer.vue b/app/src/components/v-drawer/v-drawer.vue index 1175e48a4c..e2000820b9 100644 --- a/app/src/components/v-drawer/v-drawer.vue +++ b/app/src/components/v-drawer/v-drawer.vue @@ -113,7 +113,7 @@ export default defineComponent({ }); const showCancel = computed(() => { - return listeners.hasOwnProperty('cancel'); + return 'cancel' in listeners; }); return { _active, mainEl, showCancel }; diff --git a/app/src/components/v-fancy-select/v-fancy-select.vue b/app/src/components/v-fancy-select/v-fancy-select.vue index 7cd5518b3c..99a986fe78 100644 --- a/app/src/components/v-fancy-select/v-fancy-select.vue +++ b/app/src/components/v-fancy-select/v-fancy-select.vue @@ -22,11 +22,7 @@
{{ item.description }}
- + diff --git a/app/src/components/v-field-select/v-field-select.vue b/app/src/components/v-field-select/v-field-select.vue index e341babb46..b035501d3e 100644 --- a/app/src/components/v-field-select/v-field-select.vue +++ b/app/src/components/v-field-select/v-field-select.vue @@ -47,7 +47,6 @@ \ No newline at end of file + diff --git a/app/src/components/v-icon/custom-icons/logout.vue b/app/src/components/v-icon/custom-icons/logout.vue index 919e45711b..e6602ab688 100644 --- a/app/src/components/v-icon/custom-icons/logout.vue +++ b/app/src/components/v-icon/custom-icons/logout.vue @@ -10,13 +10,13 @@ stroke-miterlimit="2" xmlns="http://www.w3.org/2000/svg" > + - + d="M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4a2 2 0 00-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z" + /> \ No newline at end of file + diff --git a/app/src/components/v-icon/custom-icons/signal_wifi_1_bar.vue b/app/src/components/v-icon/custom-icons/signal_wifi_1_bar.vue index b52ac7a465..8690cec275 100644 --- a/app/src/components/v-icon/custom-icons/signal_wifi_1_bar.vue +++ b/app/src/components/v-icon/custom-icons/signal_wifi_1_bar.vue @@ -12,9 +12,7 @@ d="M24.02 42.98L47.28 14c-.9-.68-9.85-8-23.28-8S1.62 13.32.72 14l23.26 28.98.02.02.02-.02z" /> - + diff --git a/app/src/components/v-icon/v-icon.vue b/app/src/components/v-icon/v-icon.vue index 656dd7dfca..6733ac9ff4 100644 --- a/app/src/components/v-icon/v-icon.vue +++ b/app/src/components/v-icon/v-icon.vue @@ -112,7 +112,7 @@ export default defineComponent({ return null; }); - const hasClick = computed(() => listeners.hasOwnProperty('click')); + const hasClick = computed(() => 'click' in listeners); return { sizeClass, diff --git a/app/src/components/v-item-group/v-item.vue b/app/src/components/v-item-group/v-item.vue index caa67d578d..4b12d1e063 100644 --- a/app/src/components/v-item-group/v-item.vue +++ b/app/src/components/v-item-group/v-item.vue @@ -20,20 +20,20 @@ export default defineComponent({ }, active: { type: Boolean, - default: undefined + default: undefined, }, watch: { type: Boolean, - default: true - } + default: true, + }, }, setup(props) { - const {active} = toRefs(props) + const { active } = toRefs(props); const { active: isActive, toggle } = useGroupable({ value: props.value, group: props.scope, watch: props.watch, - active + active, }); return { isActive, toggle }; diff --git a/app/src/components/v-list/index.ts b/app/src/components/v-list/index.ts index f6175659f1..2992a9f29a 100644 --- a/app/src/components/v-list/index.ts +++ b/app/src/components/v-list/index.ts @@ -1,9 +1,9 @@ -import VList from './v-list.vue'; -import VListItem from './v-list-item.vue'; -import VListItemContent from './v-list-item-content.vue'; -import VListItemIcon from './v-list-item-icon.vue'; -import VListItemHint from './v-list-item-hint.vue'; import VListGroup from './v-list-group.vue'; +import VListItemContent from './v-list-item-content.vue'; +import VListItemHint from './v-list-item-hint.vue'; +import VListItemIcon from './v-list-item-icon.vue'; +import VListItem from './v-list-item.vue'; +import VList from './v-list.vue'; export { VList, VListItem, VListItemContent, VListItemIcon, VListItemHint, VListGroup }; diff --git a/app/src/components/v-list/v-list-group.vue b/app/src/components/v-list/v-list-group.vue index 1f11590087..42dc470342 100644 --- a/app/src/components/v-list/v-list-group.vue +++ b/app/src/components/v-list/v-list-group.vue @@ -23,7 +23,7 @@ diff --git a/app/src/stores/collections.ts b/app/src/stores/collections.ts index 975492d8b6..000f08d8de 100644 --- a/app/src/stores/collections.ts +++ b/app/src/stores/collections.ts @@ -1,12 +1,12 @@ -import { createStore } from 'pinia'; import api from '@/api'; -import { Collection, CollectionRaw } from '@/types'; import i18n from '@/lang/'; +import { Collection, CollectionRaw } from '@/types'; import { notEmpty } from '@/utils/is-empty/'; -import VueI18n from 'vue-i18n'; -import formatTitle from '@directus/format-title'; import { notify } from '@/utils/notify'; import { unexpectedError } from '@/utils/unexpected-error'; +import formatTitle from '@directus/format-title'; +import { createStore } from 'pinia'; +import VueI18n from 'vue-i18n'; export const useCollectionsStore = createStore({ id: 'collectionsStore', diff --git a/app/src/stores/fields.ts b/app/src/stores/fields.ts index e0d882e0f0..ac34695bac 100644 --- a/app/src/stores/fields.ts +++ b/app/src/stores/fields.ts @@ -1,14 +1,14 @@ -import { createStore } from 'pinia'; import api from '@/api'; -import VueI18n from 'vue-i18n'; -import { notEmpty } from '@/utils/is-empty/'; import { i18n } from '@/lang'; -import formatTitle from '@directus/format-title'; import { useRelationsStore } from '@/stores/'; -import { Relation, FieldRaw, Field } from '@/types'; +import { Field, FieldRaw, Relation } from '@/types'; +import { notEmpty } from '@/utils/is-empty/'; +import { unexpectedError } from '@/utils/unexpected-error'; +import formatTitle from '@directus/format-title'; import { merge, orderBy } from 'lodash'; import { nanoid } from 'nanoid'; -import { unexpectedError } from '@/utils/unexpected-error'; +import { createStore } from 'pinia'; +import VueI18n from 'vue-i18n'; /** * directus_files is a special case. For it to play nice with interfaces/layouts/displays, we need diff --git a/app/src/stores/notifications.ts b/app/src/stores/notifications.ts index 3579fb0de7..3a1bc9d140 100644 --- a/app/src/stores/notifications.ts +++ b/app/src/stores/notifications.ts @@ -1,7 +1,7 @@ -import { createStore } from 'pinia'; import { Notification, NotificationRaw } from '@/types'; -import { nanoid } from 'nanoid'; import { reverse, sortBy } from 'lodash'; +import { nanoid } from 'nanoid'; +import { createStore } from 'pinia'; export const useNotificationsStore = createStore({ id: 'notificationsStore', diff --git a/app/src/stores/permissions.ts b/app/src/stores/permissions.ts index bfb0b49866..f528c6d33b 100644 --- a/app/src/stores/permissions.ts +++ b/app/src/stores/permissions.ts @@ -1,8 +1,8 @@ -import { createStore } from 'pinia'; import api from '@/api'; import { Permission } from '@/types'; -import { useUserStore } from '../stores/user'; import { parseFilter } from '@/utils/parse-filter'; +import { createStore } from 'pinia'; +import { useUserStore } from '../stores/user'; export const usePermissionsStore = createStore({ id: 'permissionsStore', diff --git a/app/src/stores/presets.ts b/app/src/stores/presets.ts index 2fbf2d4e9b..dd8a7d980c 100644 --- a/app/src/stores/presets.ts +++ b/app/src/stores/presets.ts @@ -1,9 +1,9 @@ -import { createStore } from 'pinia'; -import { Preset } from '@/types'; -import { useUserStore } from '@/stores/'; import api from '@/api'; +import { useUserStore } from '@/stores/'; +import { Preset } from '@/types'; +import { cloneDeep, merge } from 'lodash'; import { nanoid } from 'nanoid'; -import { merge, cloneDeep, isEqual } from 'lodash'; +import { createStore } from 'pinia'; const defaultPreset: Omit = { bookmark: null, @@ -93,7 +93,7 @@ const systemDefaults: Record> = { }, }; -let currentUpdate: Record = {}; +const currentUpdate: Record = {}; export const usePresetsStore = createStore({ id: 'presetsStore', @@ -258,7 +258,7 @@ export const usePresetsStore = createStore({ } if (preset.user !== userID) { - if (preset.hasOwnProperty('id')) delete preset.id; + if ('id' in preset) delete preset.id; return await this.create({ ...preset, diff --git a/app/src/stores/relations.ts b/app/src/stores/relations.ts index 06c174a8c2..1c7057b3e7 100644 --- a/app/src/stores/relations.ts +++ b/app/src/stores/relations.ts @@ -1,7 +1,7 @@ -import { createStore } from 'pinia'; -import { Relation } from '@/types'; import api from '@/api'; import { useFieldsStore } from '@/stores/'; +import { Relation } from '@/types'; +import { createStore } from 'pinia'; export const useRelationsStore = createStore({ id: 'relationsStore', diff --git a/app/src/stores/requests.ts b/app/src/stores/requests.ts index 21830d3cec..16bb6c5a1c 100644 --- a/app/src/stores/requests.ts +++ b/app/src/stores/requests.ts @@ -1,5 +1,5 @@ -import { createStore } from 'pinia'; import { nanoid } from 'nanoid'; +import { createStore } from 'pinia'; export const useRequestsStore = createStore({ id: 'requestsStore', diff --git a/app/src/stores/server.ts b/app/src/stores/server.ts index b92143e0a7..b092dc754d 100644 --- a/app/src/stores/server.ts +++ b/app/src/stores/server.ts @@ -1,5 +1,5 @@ -import { createStore } from 'pinia'; import api from '@/api'; +import { createStore } from 'pinia'; type Info = { project: null | { diff --git a/app/src/stores/settings.ts b/app/src/stores/settings.ts index d841e19998..0c9d158f13 100644 --- a/app/src/stores/settings.ts +++ b/app/src/stores/settings.ts @@ -1,9 +1,9 @@ -import { createStore } from 'pinia'; import api from '@/api'; import { i18n } from '@/lang'; -import { merge } from 'lodash'; import { notify } from '@/utils/notify'; import { unexpectedError } from '@/utils/unexpected-error'; +import { merge } from 'lodash'; +import { createStore } from 'pinia'; export const useSettingsStore = createStore({ id: 'settingsStore', diff --git a/app/src/stores/user.ts b/app/src/stores/user.ts index db10df3789..7d2a4790d6 100644 --- a/app/src/stores/user.ts +++ b/app/src/stores/user.ts @@ -1,9 +1,8 @@ -import { createStore } from 'pinia'; import api from '@/api'; import { useLatencyStore } from '@/stores'; - import { User } from '@/types'; import { userName } from '@/utils/user-name'; +import { createStore } from 'pinia'; export const useUserStore = createStore({ id: 'userStore', diff --git a/app/src/types/index.ts b/app/src/types/index.ts index c1b43b0965..3496a00c24 100644 --- a/app/src/types/index.ts +++ b/app/src/types/index.ts @@ -1,8 +1,8 @@ export * from './collections'; -export * from './users'; -export * from './relations'; -export * from './presets'; -export * from './notifications'; -export * from './fields'; -export * from './permissions'; export * from './error'; +export * from './fields'; +export * from './notifications'; +export * from './permissions'; +export * from './presets'; +export * from './relations'; +export * from './users'; diff --git a/app/src/utils/abbreviate-number.ts b/app/src/utils/abbreviate-number.ts index c61c951431..e18453e171 100644 --- a/app/src/utils/abbreviate-number.ts +++ b/app/src/utils/abbreviate-number.ts @@ -10,13 +10,13 @@ export function abbreviateNumber(value: number): number | string { if (dotLessShortValue.length <= 2) break; } - let valueAsString: string = String(shortValue); + let valueAsString = String(shortValue); - if (shortValue % 1 != 0) { + if (shortValue % 1 !== 0) { valueAsString = shortValue.toFixed(1); } - return shortValue + suffixes[suffixNum]; + return valueAsString + suffixes[suffixNum]; } return value; diff --git a/app/src/utils/adjust-fields-for-displays/adjust-fields-for-displays.ts b/app/src/utils/adjust-fields-for-displays/adjust-fields-for-displays.ts index 62b94f463a..9c74d99fb7 100644 --- a/app/src/utils/adjust-fields-for-displays/adjust-fields-for-displays.ts +++ b/app/src/utils/adjust-fields-for-displays/adjust-fields-for-displays.ts @@ -1,7 +1,7 @@ -import { useFieldsStore } from '@/stores/'; -import { Field } from '@/types/'; import { getDisplays } from '@/displays'; import { DisplayConfig } from '@/displays/types'; +import { useFieldsStore } from '@/stores/'; +import { Field } from '@/types/'; export default function adjustFieldsForDisplays(fields: readonly string[], parentCollection: string): string[] { const fieldsStore = useFieldsStore(); diff --git a/app/src/utils/deep-map.ts b/app/src/utils/deep-map.ts index 5cf469edaa..37b7d28b7b 100644 --- a/app/src/utils/deep-map.ts +++ b/app/src/utils/deep-map.ts @@ -1,4 +1,4 @@ -import { transform, isPlainObject } from 'lodash'; +import { isPlainObject, transform } from 'lodash'; // eslint-disable-next-line @typescript-eslint/ban-types export function deepMap(obj: Record, iterator: Function, context?: Function): any { diff --git a/app/src/utils/filters-to-query/filters-to-query.ts b/app/src/utils/filters-to-query/filters-to-query.ts index 677335927d..b1220b9448 100644 --- a/app/src/utils/filters-to-query/filters-to-query.ts +++ b/app/src/utils/filters-to-query/filters-to-query.ts @@ -5,7 +5,8 @@ export default function filtersToQuery(filters: readonly Filter[]): any { const filterList: Record[] = []; for (const filter of filters) { - let { field, operator, value } = clone(filter) as any; + const { field, operator } = clone(filter) as any; + let { value } = clone(filter) as any; if (['empty', 'nempty', 'null', 'nnull'].includes(operator)) { value = true; diff --git a/app/src/utils/generate-joi/index.ts b/app/src/utils/generate-joi/index.ts index 663c8d828c..3c031cdae5 100644 --- a/app/src/utils/generate-joi/index.ts +++ b/app/src/utils/generate-joi/index.ts @@ -25,7 +25,7 @@ const Joi = BaseJoi.extend({ method(substring) { return this.$_addRule({ name: 'contains', args: { substring } }); }, - validate(value, helpers, { substring }, options) { + validate(value, helpers, { substring }) { if (value.includes(substring) === false) { return helpers.error('string.contains', { substring }); } @@ -45,7 +45,7 @@ const Joi = BaseJoi.extend({ method(substring) { return this.$_addRule({ name: 'ncontains', args: { substring } }); }, - validate(value, helpers, { substring }, options) { + validate(value, helpers, { substring }) { if (value.includes(substring) === true) { return helpers.error('string.ncontains', { substring }); } diff --git a/app/src/utils/hljs-graphql.ts b/app/src/utils/hljs-graphql.ts index 1433a7d86f..48b428e638 100644 --- a/app/src/utils/hljs-graphql.ts +++ b/app/src/utils/hljs-graphql.ts @@ -1,4 +1,4 @@ -import { HASH_COMMENT_MODE, QUOTE_STRING_MODE, NUMBER_MODE } from 'highlight.js'; +import { HASH_COMMENT_MODE, NUMBER_MODE, QUOTE_STRING_MODE } from 'highlight.js'; export default (): LanguageDetail & ModeDetails => ({ aliases: ['gql'], diff --git a/app/src/utils/localized-format-distance/localized-format-distance.ts b/app/src/utils/localized-format-distance/localized-format-distance.ts index f31f94779a..a6cd5f30df 100644 --- a/app/src/utils/localized-format-distance/localized-format-distance.ts +++ b/app/src/utils/localized-format-distance/localized-format-distance.ts @@ -1,5 +1,5 @@ -import formatDistanceOriginal from 'date-fns/formatDistance'; import getDateFNSLocale from '@/utils/get-date-fns-locale'; +import formatDistanceOriginal from 'date-fns/formatDistance'; type LocalizedFormatDistance = (...a: Parameters) => Promise; diff --git a/app/src/utils/localized-format/localized-format.ts b/app/src/utils/localized-format/localized-format.ts index be28dab0f5..2b222ba313 100644 --- a/app/src/utils/localized-format/localized-format.ts +++ b/app/src/utils/localized-format/localized-format.ts @@ -1,5 +1,5 @@ -import formatOriginal from 'date-fns/format'; import getDateFNSLocale from '@/utils/get-date-fns-locale'; +import formatOriginal from 'date-fns/format'; type localizedFormat = (...a: Parameters) => Promise; diff --git a/app/src/utils/parse-filter.ts b/app/src/utils/parse-filter.ts index bbeb421868..ffe922e795 100644 --- a/app/src/utils/parse-filter.ts +++ b/app/src/utils/parse-filter.ts @@ -1,5 +1,5 @@ -import { deepMap } from './deep-map'; import { useUserStore } from '@/stores'; +import { deepMap } from './deep-map'; export function parseFilter(filter: Record): Record { const userStore = useUserStore(); diff --git a/app/src/utils/readable-mime-type/readable-mime-type.ts b/app/src/utils/readable-mime-type/readable-mime-type.ts index cc7445a832..bb7f052869 100644 --- a/app/src/utils/readable-mime-type/readable-mime-type.ts +++ b/app/src/utils/readable-mime-type/readable-mime-type.ts @@ -1,5 +1,5 @@ -import types from './types.json'; import extensions from './extensions.json'; +import types from './types.json'; export default function readableMimeType(type: string, extension = false): string | null { if (extension) { diff --git a/app/src/utils/register-component/register-component.ts b/app/src/utils/register-component/register-component.ts index 6a3bfaa193..b4ee86eea0 100644 --- a/app/src/utils/register-component/register-component.ts +++ b/app/src/utils/register-component/register-component.ts @@ -1,4 +1,4 @@ -import Vue, { Component, AsyncComponent } from 'vue'; +import Vue, { AsyncComponent, Component } from 'vue'; function registerComponent(id: string, component: Component | AsyncComponent): void; function registerComponent(id: string, component: Parameters[1]): void; diff --git a/app/src/utils/unexpected-error.ts b/app/src/utils/unexpected-error.ts index 0f3fa7759b..ff3037f723 100644 --- a/app/src/utils/unexpected-error.ts +++ b/app/src/utils/unexpected-error.ts @@ -1,6 +1,6 @@ -import { useNotificationsStore } from '@/stores/'; -import { i18n } from '@/lang'; import { RequestError } from '@/api'; +import { i18n } from '@/lang'; +import { useNotificationsStore } from '@/stores/'; import { APIError } from '@/types'; let store: any; diff --git a/app/src/utils/upload-file/upload-file.ts b/app/src/utils/upload-file/upload-file.ts index 842d8e2df7..467b610605 100644 --- a/app/src/utils/upload-file/upload-file.ts +++ b/app/src/utils/upload-file/upload-file.ts @@ -1,8 +1,7 @@ import api from '@/api'; +import emitter, { Events } from '@/events'; import i18n from '@/lang'; import { notify } from '@/utils/notify'; - -import emitter, { Events } from '@/events'; import { unexpectedError } from '../unexpected-error'; export default async function uploadFile( diff --git a/app/src/utils/upload-files/upload-files.ts b/app/src/utils/upload-files/upload-files.ts index 7462b10cb9..416d14a6c6 100644 --- a/app/src/utils/upload-files/upload-files.ts +++ b/app/src/utils/upload-files/upload-files.ts @@ -1,6 +1,6 @@ -import uploadFile from '@/utils/upload-file'; import i18n from '@/lang'; import { notify } from '@/utils/notify'; +import uploadFile from '@/utils/upload-file'; import { unexpectedError } from '../unexpected-error'; export default async function uploadFiles( diff --git a/app/src/utils/user-name.ts b/app/src/utils/user-name.ts index 180c89a928..854e43327f 100644 --- a/app/src/utils/user-name.ts +++ b/app/src/utils/user-name.ts @@ -1,5 +1,5 @@ -import { User } from '@/types'; import { i18n } from '@/lang'; +import { User } from '@/types'; export function userName(user: Partial): string { if (user.first_name && user.last_name) { diff --git a/app/src/views/private/components/comments-sidebar-detail/comment-item-header.vue b/app/src/views/private/components/comments-sidebar-detail/comment-item-header.vue index 84bdc73e2c..e4161d0bae 100644 --- a/app/src/views/private/components/comments-sidebar-detail/comment-item-header.vue +++ b/app/src/views/private/components/comments-sidebar-detail/comment-item-header.vue @@ -60,7 +60,7 @@