From d68ec5fda75fe343ba364ef2601485e661fe3a32 Mon Sep 17 00:00:00 2001 From: Rijk van Zanten Date: Mon, 9 Oct 2023 15:17:29 -0400 Subject: [PATCH] Cleanup imports (#19966) * Cleanup imports * Add changeset --- .changeset/curvy-islands-smash.md | 5 +++++ api/src/database/helpers/schema/dialects/mysql.ts | 2 +- api/src/database/run-ast.ts | 2 +- api/src/middleware/extract-token.test.ts | 4 ++-- api/src/middleware/validate-batch.test.ts | 2 +- api/src/services/collections.ts | 4 ++-- api/src/services/fields.ts | 4 ++-- api/src/services/items.test.ts | 4 ++-- api/src/services/payload.test.ts | 6 +++--- api/src/services/permissions.ts | 4 ++-- api/src/services/specifications.test.ts | 2 +- api/src/utils/async-handler.test.ts | 2 +- api/src/utils/calculate-field-depth.test.ts | 2 +- api/src/utils/filter-items.test.ts | 2 +- api/src/utils/get-ast-from-query.ts | 2 +- api/src/utils/get-auth-providers.test.ts | 2 +- api/src/utils/get-column-path.test.ts | 4 ++-- api/src/utils/get-config-from-env.test.ts | 2 +- api/src/utils/get-permissions.ts | 2 +- api/src/utils/get-relation-info.test.ts | 2 +- api/src/utils/get-relation-type.test.ts | 2 +- api/src/utils/get-string-byte-size.test.ts | 2 +- api/src/utils/is-directus-jwt.test.ts | 2 +- api/src/utils/jwt.test.ts | 4 ++-- api/src/utils/validate-keys.test.ts | 2 +- 25 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 .changeset/curvy-islands-smash.md diff --git a/.changeset/curvy-islands-smash.md b/.changeset/curvy-islands-smash.md new file mode 100644 index 0000000000..c0e1cee456 --- /dev/null +++ b/.changeset/curvy-islands-smash.md @@ -0,0 +1,5 @@ +--- +'@directus/api': patch +--- + +Optimized the file imports diff --git a/api/src/database/helpers/schema/dialects/mysql.ts b/api/src/database/helpers/schema/dialects/mysql.ts index e5339f4baa..7fb5e783c7 100644 --- a/api/src/database/helpers/schema/dialects/mysql.ts +++ b/api/src/database/helpers/schema/dialects/mysql.ts @@ -1,5 +1,5 @@ import type { Knex } from 'knex'; -import { getDatabaseVersion } from '../../../../database/index.js'; +import { getDatabaseVersion } from '../../../index.js'; import { SchemaHelper } from '../types.js'; export class SchemaHelperMySQL extends SchemaHelper { diff --git a/api/src/database/run-ast.ts b/api/src/database/run-ast.ts index ce85a27c4f..af8dbc017c 100644 --- a/api/src/database/run-ast.ts +++ b/api/src/database/run-ast.ts @@ -2,7 +2,7 @@ import type { Item, Query, SchemaOverview } from '@directus/types'; import { toArray } from '@directus/utils'; import type { Knex } from 'knex'; import { clone, cloneDeep, isNil, merge, pick, uniq } from 'lodash-es'; -import { getHelpers } from '../database/helpers/index.js'; +import { getHelpers } from './helpers/index.js'; import env from '../env.js'; import { PayloadService } from '../services/payload.js'; import type { AST, FieldNode, FunctionFieldNode, M2ONode, NestedCollectionNode } from '../types/ast.js'; diff --git a/api/src/middleware/extract-token.test.ts b/api/src/middleware/extract-token.test.ts index 48d114c9d6..c51ee7ce72 100644 --- a/api/src/middleware/extract-token.test.ts +++ b/api/src/middleware/extract-token.test.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; import { beforeEach, expect, test, vi } from 'vitest'; -import extractToken from '../../src/middleware/extract-token.js'; -import '../../src/types/express.d.ts'; +import extractToken from './extract-token.js'; +import '../types/express.d.ts'; let mockRequest: Partial; let mockResponse: Partial; diff --git a/api/src/middleware/validate-batch.test.ts b/api/src/middleware/validate-batch.test.ts index 9e08f463b4..fceb7dc21e 100644 --- a/api/src/middleware/validate-batch.test.ts +++ b/api/src/middleware/validate-batch.test.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; import { beforeEach, expect, test, vi } from 'vitest'; -import '../../src/types/express.d.ts'; +import '../types/express.d.ts'; import { InvalidPayloadError } from '../errors/invalid-payload.js'; import { validateBatch } from './validate-batch.js'; diff --git a/api/src/services/collections.ts b/api/src/services/collections.ts index e98ffc2252..20e1f45d19 100644 --- a/api/src/services/collections.ts +++ b/api/src/services/collections.ts @@ -14,8 +14,8 @@ import { systemCollectionRows } from '../database/system-data/collections/index. import emitter from '../emitter.js'; import env from '../env.js'; import { ForbiddenError, InvalidPayloadError } from '../errors/index.js'; -import { FieldsService } from '../services/fields.js'; -import { ItemsService } from '../services/items.js'; +import { FieldsService } from './fields.js'; +import { ItemsService } from './items.js'; import type { AbstractServiceOptions, ActionEventParams, diff --git a/api/src/services/fields.ts b/api/src/services/fields.ts index eee5d40b9a..f40ad86a16 100644 --- a/api/src/services/fields.ts +++ b/api/src/services/fields.ts @@ -15,8 +15,8 @@ import getDatabase, { getSchemaInspector } from '../database/index.js'; import { systemFieldRows } from '../database/system-data/fields/index.js'; import emitter from '../emitter.js'; import { ForbiddenError, InvalidPayloadError } from '../errors/index.js'; -import { ItemsService } from '../services/items.js'; -import { PayloadService } from '../services/payload.js'; +import { ItemsService } from './items.js'; +import { PayloadService } from './payload.js'; import type { AbstractServiceOptions, ActionEventParams, MutationOptions } from '../types/index.js'; import getDefaultValue from '../utils/get-default-value.js'; import getLocalType from '../utils/get-local-type.js'; diff --git a/api/src/services/items.test.ts b/api/src/services/items.test.ts index e7f36b1ddd..02ef003b01 100644 --- a/api/src/services/items.test.ts +++ b/api/src/services/items.test.ts @@ -5,8 +5,8 @@ import { MockClient, Tracker, createTracker, type RawQuery } from 'knex-mock-cli import { cloneDeep } from 'lodash-es'; import type { MockedFunction } from 'vitest'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { getDatabaseClient } from '../../src/database/index.js'; -import { ItemsService } from '../../src/services/index.js'; +import { getDatabaseClient } from '../database/index.js'; +import { ItemsService } from './index.js'; import { sqlFieldFormatter, sqlFieldList } from '../__utils__/items-utils.js'; import { systemSchema, userSchema } from '../__utils__/schemas.js'; import { InvalidPayloadError } from '../errors/index.js'; diff --git a/api/src/services/payload.test.ts b/api/src/services/payload.test.ts index 069123ba2e..494591f72c 100644 --- a/api/src/services/payload.test.ts +++ b/api/src/services/payload.test.ts @@ -3,9 +3,9 @@ import knex from 'knex'; import { MockClient, Tracker, createTracker } from 'knex-mock-client'; import type { MockedFunction } from 'vitest'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import type { Helpers } from '../../src/database/helpers/index.js'; -import { getHelpers } from '../../src/database/helpers/index.js'; -import { PayloadService } from '../../src/services/index.js'; +import type { Helpers } from '../database/helpers/index.js'; +import { getHelpers } from '../database/helpers/index.js'; +import { PayloadService } from './index.js'; vi.mock('../../src/database/index', () => ({ getDatabaseClient: vi.fn().mockReturnValue('postgres'), diff --git a/api/src/services/permissions.ts b/api/src/services/permissions.ts index e67ab744f9..74a820ddce 100644 --- a/api/src/services/permissions.ts +++ b/api/src/services/permissions.ts @@ -2,8 +2,8 @@ import type { PermissionsAction, Query } from '@directus/types'; import type Keyv from 'keyv'; import { clearSystemCache, getCache } from '../cache.js'; import { appAccessMinimalPermissions } from '../database/system-data/app-access-permissions/index.js'; -import type { QueryOptions } from '../services/items.js'; -import { ItemsService } from '../services/items.js'; +import type { QueryOptions } from './items.js'; +import { ItemsService } from './items.js'; import type { AbstractServiceOptions, Item, MutationOptions, PrimaryKey } from '../types/index.js'; import { filterItems } from '../utils/filter-items.js'; diff --git a/api/src/services/specifications.test.ts b/api/src/services/specifications.test.ts index ec640aa018..20398e2a06 100644 --- a/api/src/services/specifications.test.ts +++ b/api/src/services/specifications.test.ts @@ -3,7 +3,7 @@ import knex from 'knex'; import { createTracker, MockClient, Tracker } from 'knex-mock-client'; import type { MockedFunction } from 'vitest'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { CollectionsService, FieldsService, RelationsService, SpecificationService } from '../../src/services/index.js'; +import { CollectionsService, FieldsService, RelationsService, SpecificationService } from './index.js'; import type { Collection } from '../types/index.js'; class Client_PG extends MockClient {} diff --git a/api/src/utils/async-handler.test.ts b/api/src/utils/async-handler.test.ts index ed3cd9d724..6041bfcf62 100644 --- a/api/src/utils/async-handler.test.ts +++ b/api/src/utils/async-handler.test.ts @@ -1,5 +1,5 @@ import type { RequestHandler, Request, Response } from 'express'; -import '../../src/types/express.d.ts'; +import '../types/express.d.ts'; import asyncHandler from './async-handler.js'; import { expect, vi, test } from 'vitest'; diff --git a/api/src/utils/calculate-field-depth.test.ts b/api/src/utils/calculate-field-depth.test.ts index baf9b4f006..846882f8a2 100644 --- a/api/src/utils/calculate-field-depth.test.ts +++ b/api/src/utils/calculate-field-depth.test.ts @@ -1,4 +1,4 @@ -import { calculateFieldDepth } from '../../src/utils/calculate-field-depth.js'; +import { calculateFieldDepth } from './calculate-field-depth.js'; import { test, expect } from 'vitest'; test('Calculates basic depth', () => { diff --git a/api/src/utils/filter-items.test.ts b/api/src/utils/filter-items.test.ts index 52074499ea..c717804db8 100644 --- a/api/src/utils/filter-items.test.ts +++ b/api/src/utils/filter-items.test.ts @@ -1,4 +1,4 @@ -import { filterItems } from '../../src/utils/filter-items.js'; +import { filterItems } from './filter-items.js'; import { describe, test, expect } from 'vitest'; const items = [ diff --git a/api/src/utils/get-ast-from-query.ts b/api/src/utils/get-ast-from-query.ts index 519e269937..3f3386301a 100644 --- a/api/src/utils/get-ast-from-query.ts +++ b/api/src/utils/get-ast-from-query.ts @@ -7,7 +7,7 @@ import type { Accountability, PermissionsAction, Query, SchemaOverview } from '@ import type { Knex } from 'knex'; import { cloneDeep, isEmpty, mapKeys, omitBy, uniq } from 'lodash-es'; import type { AST, FieldNode, FunctionFieldNode, NestedCollectionNode } from '../types/index.js'; -import { getRelationType } from '../utils/get-relation-type.js'; +import { getRelationType } from './get-relation-type.js'; type GetASTOptions = { accountability?: Accountability | null; diff --git a/api/src/utils/get-auth-providers.test.ts b/api/src/utils/get-auth-providers.test.ts index bd1a12cfbe..18fda219e2 100644 --- a/api/src/utils/get-auth-providers.test.ts +++ b/api/src/utils/get-auth-providers.test.ts @@ -1,5 +1,5 @@ import { describe, expect, vi, test } from 'vitest'; -import { getAuthProviders } from '../../src/utils/get-auth-providers.js'; +import { getAuthProviders } from './get-auth-providers.js'; let factoryEnv: { [k: string]: any } = {}; diff --git a/api/src/utils/get-column-path.test.ts b/api/src/utils/get-column-path.test.ts index 6d7c7adff8..9d89deb922 100644 --- a/api/src/utils/get-column-path.test.ts +++ b/api/src/utils/get-column-path.test.ts @@ -1,8 +1,8 @@ import type { DeepPartial } from '@directus/types'; import { expect, test } from 'vitest'; import { InvalidQueryError } from '../errors/index.js'; -import type { ColPathProps } from '../utils/get-column-path.js'; -import { getColumnPath } from '../utils/get-column-path.js'; +import type { ColPathProps } from './get-column-path.js'; +import { getColumnPath } from './get-column-path.js'; /* { diff --git a/api/src/utils/get-config-from-env.test.ts b/api/src/utils/get-config-from-env.test.ts index 815e7b004d..ed36172142 100644 --- a/api/src/utils/get-config-from-env.test.ts +++ b/api/src/utils/get-config-from-env.test.ts @@ -1,4 +1,4 @@ -import { getConfigFromEnv } from '../../src/utils/get-config-from-env.js'; +import { getConfigFromEnv } from './get-config-from-env.js'; import { describe, test, expect, vi } from 'vitest'; vi.mock('../../src/env', () => { diff --git a/api/src/utils/get-permissions.ts b/api/src/utils/get-permissions.ts index cd97d5d599..10a06d499e 100644 --- a/api/src/utils/get-permissions.ts +++ b/api/src/utils/get-permissions.ts @@ -9,7 +9,7 @@ import env from '../env.js'; import logger from '../logger.js'; import { RolesService } from '../services/roles.js'; import { UsersService } from '../services/users.js'; -import { mergePermissions } from '../utils/merge-permissions.js'; +import { mergePermissions } from './merge-permissions.js'; import { mergePermissionsForShare } from './merge-permissions-for-share.js'; export async function getPermissions(accountability: Accountability, schema: SchemaOverview) { diff --git a/api/src/utils/get-relation-info.test.ts b/api/src/utils/get-relation-info.test.ts index a2732678aa..94bbf0c9c1 100644 --- a/api/src/utils/get-relation-info.test.ts +++ b/api/src/utils/get-relation-info.test.ts @@ -1,6 +1,6 @@ import type { DeepPartial, Relation } from '@directus/types'; import { describe, expect, it } from 'vitest'; -import { getRelationInfo } from '../../src/utils/get-relation-info.js'; +import { getRelationInfo } from './get-relation-info.js'; describe('getRelationInfo', () => { it('Errors on suspiciously long implicit $FOLLOW', () => { diff --git a/api/src/utils/get-relation-type.test.ts b/api/src/utils/get-relation-type.test.ts index 21a6882f05..a48a0ba39a 100644 --- a/api/src/utils/get-relation-type.test.ts +++ b/api/src/utils/get-relation-type.test.ts @@ -1,6 +1,6 @@ import type { Relation } from '@directus/types'; import { expect, test } from 'vitest'; -import { getRelationType } from '../../src/utils/get-relation-type.js'; +import { getRelationType } from './get-relation-type.js'; test('Returns null if no relation object is included', () => { const result = getRelationType({ relation: null, collection: null, field: 'test' }); diff --git a/api/src/utils/get-string-byte-size.test.ts b/api/src/utils/get-string-byte-size.test.ts index dc857f7eac..d83b64905d 100644 --- a/api/src/utils/get-string-byte-size.test.ts +++ b/api/src/utils/get-string-byte-size.test.ts @@ -1,4 +1,4 @@ -import { stringByteSize } from '../../src/utils/get-string-byte-size.js'; +import { stringByteSize } from './get-string-byte-size.js'; import { test, expect } from 'vitest'; test('Returns correct byte size for given input string', () => { diff --git a/api/src/utils/is-directus-jwt.test.ts b/api/src/utils/is-directus-jwt.test.ts index 1cebfcddef..03b9e30319 100644 --- a/api/src/utils/is-directus-jwt.test.ts +++ b/api/src/utils/is-directus-jwt.test.ts @@ -1,4 +1,4 @@ -import isDirectusJWT from '../../src/utils/is-directus-jwt.js'; +import isDirectusJWT from './is-directus-jwt.js'; import jwt from 'jsonwebtoken'; import { test, expect } from 'vitest'; diff --git a/api/src/utils/jwt.test.ts b/api/src/utils/jwt.test.ts index ad95e32fd0..6a77cff734 100644 --- a/api/src/utils/jwt.test.ts +++ b/api/src/utils/jwt.test.ts @@ -1,7 +1,7 @@ import jwt from 'jsonwebtoken'; import { expect, test, vi } from 'vitest'; -import type { DirectusTokenPayload } from '../../src/types/index.js'; -import { verifyAccessJWT, verifyJWT } from '../../src/utils/jwt.js'; +import type { DirectusTokenPayload } from '../types/index.js'; +import { verifyAccessJWT, verifyJWT } from './jwt.js'; import { TokenExpiredError, InvalidTokenError } from '../errors/index.js'; import { ServiceUnavailableError } from '../errors/index.js'; diff --git a/api/src/utils/validate-keys.test.ts b/api/src/utils/validate-keys.test.ts index e5a0b7d7e5..9f577ed5df 100644 --- a/api/src/utils/validate-keys.test.ts +++ b/api/src/utils/validate-keys.test.ts @@ -1,7 +1,7 @@ import type { SchemaOverview } from '@directus/types'; import { v4 as uuid } from 'uuid'; import { describe, expect, it } from 'vitest'; -import { validateKeys } from '../../src/utils/validate-keys.js'; +import { validateKeys } from './validate-keys.js'; const schema: SchemaOverview = { collections: {