diff --git a/packages/backend/src/constants.ts b/packages/backend/src/constants.ts index 3ede6d4e..3150187e 100644 --- a/packages/backend/src/constants.ts +++ b/packages/backend/src/constants.ts @@ -1,27 +1,6 @@ import { env } from "./env.js"; -import { Settings } from "./types.js"; import path from "path"; -/** - * Default settings. - */ -export const DEFAULT_SETTINGS: Settings = { - maxFileSize: 2 * 1024 * 1024, // 2MB in bytes - maxTrigramCount: 20000, - reindexIntervalMs: 1000 * 60 * 60, // 1 hour - resyncConnectionIntervalMs: 1000 * 60 * 60 * 24, // 24 hours - resyncConnectionPollingIntervalMs: 1000 * 1, // 1 second - reindexRepoPollingIntervalMs: 1000 * 1, // 1 second - maxConnectionSyncJobConcurrency: 8, - maxRepoIndexingJobConcurrency: 8, - maxRepoGarbageCollectionJobConcurrency: 8, - repoGarbageCollectionGracePeriodMs: 10 * 1000, // 10 seconds - repoIndexTimeoutMs: 1000 * 60 * 60 * 2, // 2 hours - enablePublicAccess: false, // deprected, use FORCE_ENABLE_ANONYMOUS_ACCESS instead - experiment_repoDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours - experiment_userDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours -} - export const PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES = [ 'github', ]; diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index d4b0f5db..2e2ec569 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -2,12 +2,12 @@ import "./instrument.js"; import { PrismaClient } from "@sourcebot/db"; import { createLogger } from "@sourcebot/logger"; -import { hasEntitlement, loadConfig } from '@sourcebot/shared'; +import { getConfigSettings, hasEntitlement } from '@sourcebot/shared'; import { existsSync } from 'fs'; import { mkdir } from 'fs/promises'; import { Redis } from 'ioredis'; import { ConnectionManager } from './connectionManager.js'; -import { DEFAULT_SETTINGS, INDEX_CACHE_DIR, REPOS_CACHE_DIR } from './constants.js'; +import { INDEX_CACHE_DIR, REPOS_CACHE_DIR } from './constants.js'; import { RepoPermissionSyncer } from './ee/repoPermissionSyncer.js'; import { UserPermissionSyncer } from "./ee/userPermissionSyncer.js"; import { GithubAppManager } from "./ee/githubAppManager.js"; @@ -18,20 +18,6 @@ import { PromClient } from './promClient.js'; const logger = createLogger('backend-entrypoint'); -const getSettings = async (configPath?: string) => { - if (!configPath) { - return DEFAULT_SETTINGS; - } - - const config = await loadConfig(configPath); - - return { - ...DEFAULT_SETTINGS, - ...config.settings, - } -} - - const reposPath = REPOS_CACHE_DIR; const indexPath = INDEX_CACHE_DIR; @@ -57,8 +43,7 @@ redis.ping().then(() => { const promClient = new PromClient(); -const settings = await getSettings(env.CONFIG_PATH); - +const settings = await getConfigSettings(env.CONFIG_PATH); if (hasEntitlement('github-app')) { await GithubAppManager.getInstance().init(prisma); diff --git a/packages/shared/src/constants.ts b/packages/shared/src/constants.ts index e0bbd29b..42e1aa69 100644 --- a/packages/shared/src/constants.ts +++ b/packages/shared/src/constants.ts @@ -1,3 +1,4 @@ +import { ConfigSettings } from "./types.js"; export const SOURCEBOT_SUPPORT_EMAIL = 'team@sourcebot.dev'; @@ -8,4 +9,24 @@ export const SOURCEBOT_CLOUD_ENVIRONMENT = [ "prod", ] as const; -export const SOURCEBOT_UNLIMITED_SEATS = -1; \ No newline at end of file +export const SOURCEBOT_UNLIMITED_SEATS = -1; + +/** + * Default settings. + */ +export const DEFAULT_CONFIG_SETTINGS: ConfigSettings = { + maxFileSize: 2 * 1024 * 1024, // 2MB in bytes + maxTrigramCount: 20000, + reindexIntervalMs: 1000 * 60 * 60, // 1 hour + resyncConnectionIntervalMs: 1000 * 60 * 60 * 24, // 24 hours + resyncConnectionPollingIntervalMs: 1000 * 1, // 1 second + reindexRepoPollingIntervalMs: 1000 * 1, // 1 second + maxConnectionSyncJobConcurrency: 8, + maxRepoIndexingJobConcurrency: 8, + maxRepoGarbageCollectionJobConcurrency: 8, + repoGarbageCollectionGracePeriodMs: 10 * 1000, // 10 seconds + repoIndexTimeoutMs: 1000 * 60 * 60 * 2, // 2 hours + enablePublicAccess: false, // deprected, use FORCE_ENABLE_ANONYMOUS_ACCESS instead + experiment_repoDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours + experiment_userDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours +} diff --git a/packages/shared/src/index.server.ts b/packages/shared/src/index.server.ts index ce00642e..566e6718 100644 --- a/packages/shared/src/index.server.ts +++ b/packages/shared/src/index.server.ts @@ -14,6 +14,7 @@ export { loadConfig, loadJsonFile, isRemotePath, + getConfigSettings, } from "./utils.js"; export { syncSearchContexts, diff --git a/packages/shared/src/types.ts b/packages/shared/src/types.ts new file mode 100644 index 00000000..b6f6e159 --- /dev/null +++ b/packages/shared/src/types.ts @@ -0,0 +1,3 @@ +import { Settings as SettingsSchema } from "@sourcebot/schemas/v3/index.type"; + +export type ConfigSettings = Required; \ No newline at end of file diff --git a/packages/shared/src/utils.ts b/packages/shared/src/utils.ts index 69cbc52e..f7c1b56e 100644 --- a/packages/shared/src/utils.ts +++ b/packages/shared/src/utils.ts @@ -4,6 +4,8 @@ import { readFile } from 'fs/promises'; import stripJsonComments from 'strip-json-comments'; import { Ajv } from "ajv"; import { z } from "zod"; +import { DEFAULT_CONFIG_SETTINGS } from "./constants.js"; +import { ConfigSettings } from "./types.js"; const ajv = new Ajv({ validateFormats: false, @@ -130,3 +132,16 @@ export const loadConfig = async (configPath: string): Promise = } return config; } + +export const getConfigSettings = async (configPath?: string): Promise => { + if (!configPath) { + return DEFAULT_CONFIG_SETTINGS; + } + + const config = await loadConfig(configPath); + + return { + ...DEFAULT_CONFIG_SETTINGS, + ...config.settings, + } +} \ No newline at end of file