mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 20:35:24 +00:00
move config settings getter to shared package
This commit is contained in:
parent
d6ca03c297
commit
58d6da72eb
6 changed files with 44 additions and 40 deletions
|
|
@ -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',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export {
|
|||
loadConfig,
|
||||
loadJsonFile,
|
||||
isRemotePath,
|
||||
getConfigSettings,
|
||||
} from "./utils.js";
|
||||
export {
|
||||
syncSearchContexts,
|
||||
|
|
|
|||
3
packages/shared/src/types.ts
Normal file
3
packages/shared/src/types.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { Settings as SettingsSchema } from "@sourcebot/schemas/v3/index.type";
|
||||
|
||||
export type ConfigSettings = Required<SettingsSchema>;
|
||||
|
|
@ -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<SourcebotConfig> =
|
|||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
export const getConfigSettings = async (configPath?: string): Promise<ConfigSettings> => {
|
||||
if (!configPath) {
|
||||
return DEFAULT_CONFIG_SETTINGS;
|
||||
}
|
||||
|
||||
const config = await loadConfig(configPath);
|
||||
|
||||
return {
|
||||
...DEFAULT_CONFIG_SETTINGS,
|
||||
...config.settings,
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue