Skip to content

Commit 58d6da7

Browse files
move config settings getter to shared package
1 parent d6ca03c commit 58d6da7

6 files changed

Lines changed: 44 additions & 40 deletions

File tree

packages/backend/src/constants.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
11
import { env } from "./env.js";
2-
import { Settings } from "./types.js";
32
import path from "path";
43

5-
/**
6-
* Default settings.
7-
*/
8-
export const DEFAULT_SETTINGS: Settings = {
9-
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
10-
maxTrigramCount: 20000,
11-
reindexIntervalMs: 1000 * 60 * 60, // 1 hour
12-
resyncConnectionIntervalMs: 1000 * 60 * 60 * 24, // 24 hours
13-
resyncConnectionPollingIntervalMs: 1000 * 1, // 1 second
14-
reindexRepoPollingIntervalMs: 1000 * 1, // 1 second
15-
maxConnectionSyncJobConcurrency: 8,
16-
maxRepoIndexingJobConcurrency: 8,
17-
maxRepoGarbageCollectionJobConcurrency: 8,
18-
repoGarbageCollectionGracePeriodMs: 10 * 1000, // 10 seconds
19-
repoIndexTimeoutMs: 1000 * 60 * 60 * 2, // 2 hours
20-
enablePublicAccess: false, // deprected, use FORCE_ENABLE_ANONYMOUS_ACCESS instead
21-
experiment_repoDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours
22-
experiment_userDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours
23-
}
24-
254
export const PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES = [
265
'github',
276
];

packages/backend/src/index.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import "./instrument.js";
22

33
import { PrismaClient } from "@sourcebot/db";
44
import { createLogger } from "@sourcebot/logger";
5-
import { hasEntitlement, loadConfig } from '@sourcebot/shared';
5+
import { getConfigSettings, hasEntitlement } from '@sourcebot/shared';
66
import { existsSync } from 'fs';
77
import { mkdir } from 'fs/promises';
88
import { Redis } from 'ioredis';
99
import { ConnectionManager } from './connectionManager.js';
10-
import { DEFAULT_SETTINGS, INDEX_CACHE_DIR, REPOS_CACHE_DIR } from './constants.js';
10+
import { INDEX_CACHE_DIR, REPOS_CACHE_DIR } from './constants.js';
1111
import { RepoPermissionSyncer } from './ee/repoPermissionSyncer.js';
1212
import { UserPermissionSyncer } from "./ee/userPermissionSyncer.js";
1313
import { GithubAppManager } from "./ee/githubAppManager.js";
@@ -18,20 +18,6 @@ import { PromClient } from './promClient.js';
1818

1919
const logger = createLogger('backend-entrypoint');
2020

21-
const getSettings = async (configPath?: string) => {
22-
if (!configPath) {
23-
return DEFAULT_SETTINGS;
24-
}
25-
26-
const config = await loadConfig(configPath);
27-
28-
return {
29-
...DEFAULT_SETTINGS,
30-
...config.settings,
31-
}
32-
}
33-
34-
3521
const reposPath = REPOS_CACHE_DIR;
3622
const indexPath = INDEX_CACHE_DIR;
3723

@@ -57,8 +43,7 @@ redis.ping().then(() => {
5743

5844
const promClient = new PromClient();
5945

60-
const settings = await getSettings(env.CONFIG_PATH);
61-
46+
const settings = await getConfigSettings(env.CONFIG_PATH);
6247

6348
if (hasEntitlement('github-app')) {
6449
await GithubAppManager.getInstance().init(prisma);

packages/shared/src/constants.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ConfigSettings } from "./types.js";
12

23
export const SOURCEBOT_SUPPORT_EMAIL = 'team@sourcebot.dev';
34

@@ -8,4 +9,24 @@ export const SOURCEBOT_CLOUD_ENVIRONMENT = [
89
"prod",
910
] as const;
1011

11-
export const SOURCEBOT_UNLIMITED_SEATS = -1;
12+
export const SOURCEBOT_UNLIMITED_SEATS = -1;
13+
14+
/**
15+
* Default settings.
16+
*/
17+
export const DEFAULT_CONFIG_SETTINGS: ConfigSettings = {
18+
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
19+
maxTrigramCount: 20000,
20+
reindexIntervalMs: 1000 * 60 * 60, // 1 hour
21+
resyncConnectionIntervalMs: 1000 * 60 * 60 * 24, // 24 hours
22+
resyncConnectionPollingIntervalMs: 1000 * 1, // 1 second
23+
reindexRepoPollingIntervalMs: 1000 * 1, // 1 second
24+
maxConnectionSyncJobConcurrency: 8,
25+
maxRepoIndexingJobConcurrency: 8,
26+
maxRepoGarbageCollectionJobConcurrency: 8,
27+
repoGarbageCollectionGracePeriodMs: 10 * 1000, // 10 seconds
28+
repoIndexTimeoutMs: 1000 * 60 * 60 * 2, // 2 hours
29+
enablePublicAccess: false, // deprected, use FORCE_ENABLE_ANONYMOUS_ACCESS instead
30+
experiment_repoDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours
31+
experiment_userDrivenPermissionSyncIntervalMs: 1000 * 60 * 60 * 24, // 24 hours
32+
}

packages/shared/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export {
1414
loadConfig,
1515
loadJsonFile,
1616
isRemotePath,
17+
getConfigSettings,
1718
} from "./utils.js";
1819
export {
1920
syncSearchContexts,

packages/shared/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Settings as SettingsSchema } from "@sourcebot/schemas/v3/index.type";
2+
3+
export type ConfigSettings = Required<SettingsSchema>;

packages/shared/src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { readFile } from 'fs/promises';
44
import stripJsonComments from 'strip-json-comments';
55
import { Ajv } from "ajv";
66
import { z } from "zod";
7+
import { DEFAULT_CONFIG_SETTINGS } from "./constants.js";
8+
import { ConfigSettings } from "./types.js";
79

810
const ajv = new Ajv({
911
validateFormats: false,
@@ -130,3 +132,16 @@ export const loadConfig = async (configPath: string): Promise<SourcebotConfig> =
130132
}
131133
return config;
132134
}
135+
136+
export const getConfigSettings = async (configPath?: string): Promise<ConfigSettings> => {
137+
if (!configPath) {
138+
return DEFAULT_CONFIG_SETTINGS;
139+
}
140+
141+
const config = await loadConfig(configPath);
142+
143+
return {
144+
...DEFAULT_CONFIG_SETTINGS,
145+
...config.settings,
146+
}
147+
}

0 commit comments

Comments
 (0)