mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
chore(studio}: enforce import order, remove bare import specifiers (#44585)
This commit is contained in:
1 parent
c6b5a1ad5b
commit
205cbe7d26
445 files changed
+2503
-2320
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { apiAuthenticate } from './apiAuthenticate'
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
@@ -13,7 +14,7 @@ const mocks = vi.hoisted(() => {
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('lib/gotrue', () => ({
|
||||
vi.mock('@/lib/gotrue', () => ({
|
||||
getUserClaims: mocks.getUserClaims,
|
||||
}))
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { JwtPayload } from '@supabase/supabase-js'
|
||||
import { getUserClaims } from 'lib/gotrue'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import type { ResponseError } from 'types'
|
||||
|
||||
import { getUserClaims } from '@/lib/gotrue'
|
||||
import type { ResponseError } from '@/types'
|
||||
|
||||
/**
|
||||
* Use this method on api routes to check if user is authenticated and having required permissions.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { IncomingHttpHeaders } from 'node:http'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import {
|
||||
commaSeparatedStringIntoArray,
|
||||
constructHeaders,
|
||||
@@ -8,7 +9,7 @@ import {
|
||||
zBooleanString,
|
||||
} from './apiHelpers'
|
||||
|
||||
vi.mock('lib/constants', () => ({
|
||||
vi.mock('@/lib/constants', () => ({
|
||||
IS_PLATFORM: false,
|
||||
}))
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { IS_PLATFORM } from 'lib/constants'
|
||||
import { snakeCase } from 'lodash'
|
||||
import type { IncomingHttpHeaders } from 'node:http'
|
||||
import { snakeCase } from 'lodash'
|
||||
import z from 'zod'
|
||||
|
||||
import { IS_PLATFORM } from '@/lib/constants'
|
||||
|
||||
/**
|
||||
* Construct headers for api request.
|
||||
* For platform, it will include apiKey into the provided headers.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { JwtPayload } from '@supabase/supabase-js'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { ResponseError, ResponseFailure } from 'types'
|
||||
|
||||
import { IS_PLATFORM } from '../constants'
|
||||
import { apiAuthenticate } from './apiAuthenticate'
|
||||
import { ResponseError, ResponseFailure } from '@/types'
|
||||
|
||||
export function isResponseOk<T>(response: T | ResponseFailure | undefined): response is T {
|
||||
if (response === undefined || response === null) {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import type { JwtPayload } from '@supabase/supabase-js'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { ResponseError } from 'types'
|
||||
import apiWrapper from './apiWrapper'
|
||||
import { apiAuthenticate } from './apiAuthenticate'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.mock('lib/constants', () => ({
|
||||
import { apiAuthenticate } from './apiAuthenticate'
|
||||
import apiWrapper from './apiWrapper'
|
||||
import { ResponseError } from '@/types'
|
||||
|
||||
vi.mock('@/lib/constants', () => ({
|
||||
IS_PLATFORM: true,
|
||||
API_URL: 'https://api.example.com',
|
||||
}))
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { UIMessage } from 'ai'
|
||||
import { sanitizeMessagePart } from 'lib/ai/tools/tool-sanitizer'
|
||||
import { expect, test, vi } from 'vitest'
|
||||
|
||||
// End of third-party imports
|
||||
|
||||
import generateV4 from '../../pages/api/ai/sql/generate-v4'
|
||||
import { sanitizeMessagePart } from '@/lib/ai/tools/tool-sanitizer'
|
||||
|
||||
vi.mock('lib/ai/tools/tool-sanitizer', () => ({
|
||||
vi.mock('@/lib/ai/tools/tool-sanitizer', () => ({
|
||||
sanitizeMessagePart: vi.fn((part) => part),
|
||||
}))
|
||||
|
||||
@@ -45,7 +43,7 @@ test('generateV4 calls the tool sanitizer', async () => {
|
||||
setHeader: vi.fn(() => mockRes),
|
||||
}
|
||||
|
||||
vi.mock('lib/ai/ai-details', () => ({
|
||||
vi.mock('@/lib/ai/ai-details', () => ({
|
||||
getOrgAIDetails: vi.fn().mockResolvedValue({
|
||||
aiOptInLevel: 'schema_and_log_and_data',
|
||||
hasAccessToAdvanceModel: true,
|
||||
@@ -57,18 +55,18 @@ test('generateV4 calls the tool sanitizer', async () => {
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('lib/ai/model', () => ({
|
||||
vi.mock('@/lib/ai/model', () => ({
|
||||
getModel: vi.fn().mockResolvedValue({
|
||||
modelParams: { model: {} },
|
||||
promptProviderOptions: {},
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('data/sql/execute-sql-query', () => ({
|
||||
vi.mock('@/data/sql/execute-sql-query', () => ({
|
||||
executeSql: vi.fn().mockResolvedValue({ result: [] }),
|
||||
}))
|
||||
|
||||
vi.mock('lib/ai/tools', () => ({
|
||||
vi.mock('@/lib/ai/tools', () => ({
|
||||
getTools: vi.fn().mockResolvedValue({}),
|
||||
}))
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { IS_PROD } from 'common'
|
||||
import { createHash } from 'crypto'
|
||||
import { IS_PROD } from 'common'
|
||||
import z from 'zod'
|
||||
|
||||
import { InternalServerError } from 'lib/api/apiHelpers'
|
||||
import { InternalServerError } from '@/lib/api/apiHelpers'
|
||||
|
||||
const INCIDENT_IO_BASE_URL = 'https://api.incident.io/v2'
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IS_PLATFORM } from 'common'
|
||||
import { InternalServerError } from 'lib/api/apiHelpers'
|
||||
import z from 'zod'
|
||||
|
||||
import { InternalServerError } from '@/lib/api/apiHelpers'
|
||||
|
||||
export type IncidentCache = {
|
||||
affected_regions: Array<string> | null
|
||||
affects_project_creation: boolean
|
||||
|
||||
@@ -43,7 +43,7 @@ test('rate calls the tool sanitizer', async () => {
|
||||
setHeader: vi.fn(() => mockRes),
|
||||
}
|
||||
|
||||
vi.mock('lib/ai/ai-details', () => ({
|
||||
vi.mock('@/lib/ai/ai-details', () => ({
|
||||
getOrgAIDetails: vi.fn().mockResolvedValue({
|
||||
aiOptInLevel: 'schema_and_log_and_data',
|
||||
hasAccessToAdvanceModel: true,
|
||||
@@ -55,7 +55,7 @@ test('rate calls the tool sanitizer', async () => {
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('lib/ai/model', () => ({
|
||||
vi.mock('@/lib/ai/model', () => ({
|
||||
getModel: vi.fn().mockResolvedValue({
|
||||
modelParams: { model: {} },
|
||||
}),
|
||||
@@ -70,7 +70,7 @@ test('rate calls the tool sanitizer', async () => {
|
||||
Output: { object: vi.fn() },
|
||||
}))
|
||||
|
||||
vi.mock('components/ui/AIAssistantPanel/Message.utils', () => ({
|
||||
vi.mock('@/components/ui/AIAssistantPanel/Message.utils', () => ({
|
||||
rateMessageResponseSchema: {},
|
||||
}))
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from 'node:assert'
|
||||
|
||||
import { FileSystemFunctionsArtifactStore } from './fileSystemStore'
|
||||
import { assertSelfHosted } from '../util'
|
||||
import { FileSystemFunctionsArtifactStore } from './fileSystemStore'
|
||||
|
||||
export function getFunctionsArtifactStore() {
|
||||
assertSelfHosted()
|
||||
|
||||
@@ -2,11 +2,11 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { generateTypescriptTypes } from './generate-types'
|
||||
|
||||
vi.mock('data/fetchers', () => ({
|
||||
vi.mock('@/data/fetchers', () => ({
|
||||
fetchGet: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('lib/constants', () => ({
|
||||
vi.mock('@/lib/constants', () => ({
|
||||
PG_META_URL: 'http://localhost:8080',
|
||||
}))
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('api/self-hosted/generate-types', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
const fetchers = await import('data/fetchers')
|
||||
const fetchers = await import('@/data/fetchers')
|
||||
const util = await import('./util')
|
||||
|
||||
mockFetchGet = vi.mocked(fetchers.fetchGet)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { fetchGet } from 'data/fetchers'
|
||||
import { PG_META_URL } from 'lib/constants'
|
||||
import type { ResponseError } from 'types'
|
||||
import { assertSelfHosted } from './util'
|
||||
import { fetchGet } from '@/data/fetchers'
|
||||
import { PG_META_URL } from '@/lib/constants'
|
||||
import type { ResponseError } from '@/types'
|
||||
|
||||
export type GenerateTypescriptTypesOptions = {
|
||||
headers?: HeadersInit
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { enrichLintsQuery, getLintsSQL } from '@supabase/pg-meta'
|
||||
import { paths } from 'api-types'
|
||||
import { DOCS_URL } from 'lib/constants'
|
||||
|
||||
import { executeQuery } from './query'
|
||||
import { DOCS_URL } from '@/lib/constants'
|
||||
|
||||
interface GetLintsOptions {
|
||||
headers?: HeadersInit
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { PROJECT_ANALYTICS_URL } from 'lib/constants/api'
|
||||
import { WrappedResult } from './types'
|
||||
import { assertSelfHosted } from './util'
|
||||
import assert from 'node:assert'
|
||||
import { LogsService } from '@supabase/mcp-server-supabase/platform'
|
||||
import { stripIndent } from 'common-tags'
|
||||
|
||||
import { WrappedResult } from './types'
|
||||
import { assertSelfHosted } from './util'
|
||||
import { PROJECT_ANALYTICS_URL } from '@/lib/constants/api'
|
||||
|
||||
export type RetrieveAnalyticsDataOptions = {
|
||||
name: string
|
||||
projectRef: string
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ExecuteSqlOptions,
|
||||
GetLogsOptions,
|
||||
} from '@supabase/mcp-server-supabase/platform'
|
||||
import { ResponseError } from 'types'
|
||||
|
||||
import { DEFAULT_EXPOSED_SCHEMAS } from './constants'
|
||||
import { generateTypescriptTypes } from './generate-types'
|
||||
import { getLints } from './lints'
|
||||
@@ -16,6 +16,7 @@ import { getLogQuery, retrieveAnalyticsData } from './logs'
|
||||
import { applyAndTrackMigrations, listMigrationVersions } from './migrations'
|
||||
import { executeQuery } from './query'
|
||||
import { getProjectSettings } from './settings'
|
||||
import { ResponseError } from '@/types'
|
||||
|
||||
export type GetDatabaseOperationsOptions = {
|
||||
headers?: HeadersInit
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { source } from 'common-tags'
|
||||
import { makeRandomString } from 'lib/helpers'
|
||||
|
||||
import { executeQuery } from './query'
|
||||
import { PgMetaDatabaseError, WrappedResult } from './types'
|
||||
import { assertSelfHosted } from './util'
|
||||
import { makeRandomString } from '@/lib/helpers'
|
||||
|
||||
export type ListMigrationsResult = {
|
||||
version: string
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
import { PG_META_URL } from 'lib/constants/index'
|
||||
|
||||
import { constructHeaders } from '../apiHelpers'
|
||||
import { PgMetaDatabaseError, databaseErrorSchema, WrappedResult } from './types'
|
||||
import { databaseErrorSchema, PgMetaDatabaseError, WrappedResult } from './types'
|
||||
import { assertSelfHosted, encryptString, getConnectionString } from './util'
|
||||
import { PG_META_URL } from '@/lib/constants/index'
|
||||
|
||||
export type QueryOptions = {
|
||||
query: string
|
||||
|
||||
@@ -6,7 +6,7 @@ vi.mock('./util', () => ({
|
||||
assertSelfHosted: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('lib/constants/api', () => ({
|
||||
vi.mock('@/lib/constants/api', () => ({
|
||||
PROJECT_ENDPOINT: 'localhost:8000',
|
||||
PROJECT_ENDPOINT_PROTOCOL: 'http',
|
||||
}))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { components } from 'api-types'
|
||||
import { PROJECT_ENDPOINT, PROJECT_ENDPOINT_PROTOCOL } from 'lib/constants/api'
|
||||
|
||||
import { assertSelfHosted } from './util'
|
||||
import { PROJECT_ENDPOINT, PROJECT_ENDPOINT_PROTOCOL } from '@/lib/constants/api'
|
||||
|
||||
type ProjectAppConfig = components['schemas']['ProjectSettingsResponse']['app_config'] & {
|
||||
protocol?: string
|
||||
|
||||
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { assertSelfHosted, encryptString, getConnectionString } from './util'
|
||||
|
||||
vi.mock('lib/constants', () => ({
|
||||
vi.mock('@/lib/constants', () => ({
|
||||
IS_PLATFORM: false,
|
||||
}))
|
||||
|
||||
@@ -27,14 +27,14 @@ describe('api/self-hosted/util', () => {
|
||||
|
||||
describe('assertSelfHosted', () => {
|
||||
it('should not throw when IS_PLATFORM is false', async () => {
|
||||
const constants = await import('lib/constants')
|
||||
const constants = await import('@/lib/constants')
|
||||
vi.spyOn(constants, 'IS_PLATFORM', 'get').mockReturnValue(false)
|
||||
|
||||
expect(() => assertSelfHosted()).not.toThrow()
|
||||
})
|
||||
|
||||
it('should throw error when IS_PLATFORM is true', async () => {
|
||||
const constants = await import('lib/constants')
|
||||
const constants = await import('@/lib/constants')
|
||||
vi.spyOn(constants, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
||||
|
||||
expect(() => assertSelfHosted()).toThrow(
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import crypto from 'crypto-js'
|
||||
import { IS_PLATFORM } from 'lib/constants'
|
||||
|
||||
import {
|
||||
ENCRYPTION_KEY,
|
||||
POSTGRES_DATABASE,
|
||||
POSTGRES_HOST,
|
||||
POSTGRES_PASSWORD,
|
||||
POSTGRES_PORT,
|
||||
POSTGRES_USER_READ_WRITE,
|
||||
POSTGRES_USER_READ_ONLY,
|
||||
POSTGRES_USER_READ_WRITE,
|
||||
} from './constants'
|
||||
import { IS_PLATFORM } from '@/lib/constants'
|
||||
|
||||
/**
|
||||
* Asserts that the current environment is self-hosted.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { generateDeterministicUuid } from './snippets.browser'
|
||||
|
||||
describe('snippets.utils', () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { generateDeterministicUuid } from './snippets.browser'
|
||||
import {
|
||||
createFolder,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from 'fs/promises'
|
||||
import { compact, sortBy } from 'lodash'
|
||||
import path from 'path'
|
||||
import { compact, sortBy } from 'lodash'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { z } from 'zod'
|
||||
|
||||
|
||||
Reference in new issue
Block a user