tangled
alpha
login
or
join now
cosmik.network
/
semble
43
fork
atom
A social knowledge tool for researchers built on ATProto
43
fork
atom
overview
issues
13
pulls
pipelines
clean up mock config for persistence
Wesley Finck
4 months ago
9210de5e
9d1c118d
+23
-23
5 changed files
expand all
collapse all
unified
split
package.json
src
shared
infrastructure
config
EnvironmentConfigService.ts
http
factories
ServiceFactory.ts
locking
LockServiceFactory.ts
processes
AppProcess.ts
+1
-1
package.json
···
34
34
"dev:app:inner": "dotenv -e .env.local -- concurrently -k -n TYPE,APP -c red,blue \"tsc --noEmit --watch\" \"tsup --watch --onSuccess='node dist/index.js'\"",
35
35
"dev:worker:feeds:inner": "dotenv -e .env.local -- concurrently -k -n WORKER -c green \"tsup --watch --onSuccess='node dist/workers/feed-worker.js'\"",
36
36
"dev:worker:search:inner": "dotenv -e .env.local -- concurrently -k -n WORKER -c yellow \"tsup --watch --onSuccess='node dist/workers/search-worker.js'\"",
37
37
-
"dev:mock": "USE_PERSISTENCE=false USE_FAKE_PUBLISHERS=true USE_MOCK_AUTH=true npm run dev:app:inner",
37
37
+
"dev:mock": "USE_MOCK_PERSISTENCE=true USE_FAKE_PUBLISHERS=true USE_MOCK_AUTH=true npm run dev:app:inner",
38
38
"dev:mock:pub:auth": "USE_FAKE_PUBLISHERS=true USE_MOCK_AUTH=true npm run dev",
39
39
"dev": "bash ./scripts/dev-combined.sh",
40
40
"migrate": "node dist/scripts/migrate.js",
+15
-15
src/shared/infrastructure/config/EnvironmentConfigService.ts
···
7
7
export interface EnvironmentConfig {
8
8
environment: Environment;
9
9
runtime: {
10
10
-
usePersistence: boolean;
10
10
+
useMockPersistence: boolean;
11
11
useMockAuth: boolean;
12
12
useFakePublishers: boolean;
13
13
useMockVectorDb: boolean;
···
64
64
this.config = {
65
65
environment,
66
66
runtime: {
67
67
-
usePersistence: this.determinePersistenceFlag(),
67
67
+
useMockPersistence: this.determineMockPersistenceFlag(),
68
68
useMockAuth: process.env.USE_MOCK_AUTH === 'true',
69
69
useFakePublishers: process.env.USE_FAKE_PUBLISHERS === 'true',
70
70
useMockVectorDb: process.env.USE_MOCK_VECTOR_DB === 'true',
···
198
198
return this.config.runtime;
199
199
}
200
200
201
201
-
public shouldUsePersistence(): boolean {
202
202
-
return this.config.runtime.usePersistence;
201
201
+
public shouldUseMockPersistence(): boolean {
202
202
+
return this.config.runtime.useMockPersistence;
203
203
}
204
204
205
205
public shouldUseMockRepos(): boolean {
206
206
-
return !this.config.runtime.usePersistence;
206
206
+
return this.config.runtime.useMockPersistence;
207
207
}
208
208
209
209
public shouldUseInMemoryEvents(): boolean {
210
210
-
return !this.config.runtime.usePersistence;
210
210
+
return this.config.runtime.useMockPersistence;
211
211
}
212
212
213
213
public shouldUseMockAuth(): boolean {
···
225
225
// Convenience methods for common combinations
226
226
public isFullyMocked(): boolean {
227
227
const r = this.config.runtime;
228
228
-
return !r.usePersistence && r.useMockAuth && r.useFakePublishers;
228
228
+
return r.useMockPersistence && r.useMockAuth && r.useFakePublishers;
229
229
}
230
230
231
231
-
public isPersistenceEnabled(): boolean {
232
232
-
return this.config.runtime.usePersistence;
231
231
+
public isMockPersistenceEnabled(): boolean {
232
232
+
return this.config.runtime.useMockPersistence;
233
233
}
234
234
235
235
-
private determinePersistenceFlag(): boolean {
235
235
+
private determineMockPersistenceFlag(): boolean {
236
236
// New unified flag takes precedence
237
237
-
if (process.env.USE_PERSISTENCE !== undefined) {
238
238
-
return process.env.USE_PERSISTENCE === 'true';
237
237
+
if (process.env.USE_MOCK_PERSISTENCE !== undefined) {
238
238
+
return process.env.USE_MOCK_PERSISTENCE === 'true';
239
239
}
240
240
241
241
// Legacy support - if either old flag is false, persistence is disabled
···
243
243
process.env.USE_MOCK_REPOS === 'true' ||
244
244
process.env.USE_IN_MEMORY_EVENTS === 'true'
245
245
) {
246
246
-
return false;
246
246
+
return true;
247
247
}
248
248
249
249
-
// Default to true (use persistence) unless explicitly disabled
250
250
-
return true;
249
249
+
// Default to false (use mock persistence) unless explicitly enabled
250
250
+
return false;
251
251
}
252
252
}
+2
-3
src/shared/infrastructure/http/factories/ServiceFactory.ts
···
48
48
import { RedisFactory } from '../../redis/RedisFactory';
49
49
import { IEventSubscriber } from 'src/shared/application/events/IEventSubscriber';
50
50
import { FeedService } from '../../../../modules/feeds/domain/services/FeedService';
51
51
-
import { CardCollectionSaga } from '../../../../modules/feeds/application/sagas/CardCollectionSaga';
52
51
import { ATProtoIdentityResolutionService } from '../../../../modules/atproto/infrastructure/services/ATProtoIdentityResolutionService';
53
52
import { IIdentityResolutionService } from '../../../../modules/atproto/domain/services/IIdentityResolutionService';
54
53
import { CookieService } from '../services/CookieService';
···
293
292
const baseProfileService = new BlueskyProfileService(atProtoAgentService);
294
293
295
294
let profileService: IProfileService;
296
296
-
const usePersistence = configService.shouldUsePersistence();
295
295
+
const useMockPersistence = configService.shouldUseMockPersistence();
297
296
298
297
// caching requires persistence
299
299
-
if (!usePersistence) {
298
298
+
if (useMockPersistence) {
300
299
profileService = baseProfileService;
301
300
} else {
302
301
// Create Redis connection for caching
+3
-2
src/shared/infrastructure/locking/LockServiceFactory.ts
···
2
2
import { RedisLockService } from './RedisLockService';
3
3
import { InMemoryLockService } from './InMemoryLockService';
4
4
import { RedisFactory } from '../redis/RedisFactory';
5
5
+
import { configService } from '../config';
5
6
6
7
export class LockServiceFactory {
7
8
static create(): ILockService {
8
8
-
const useMockRepos = process.env.USE_MOCK_REPOS === 'true';
9
9
-
if (!useMockRepos) {
9
9
+
const useMockPersistence = configService.shouldUseMockPersistence();
10
10
+
if (!useMockPersistence) {
10
11
try {
11
12
const redis = RedisFactory.createConnection({
12
13
host: process.env.REDIS_HOST || 'localhost',
+2
-2
src/shared/infrastructure/processes/AppProcess.ts
···
10
10
// Get configuration
11
11
const config = this.configService.get();
12
12
13
13
-
const useMockRepos = process.env.USE_MOCK_REPOS === 'true';
14
14
-
if (!useMockRepos) {
13
13
+
const useMockPersistence = this.configService.shouldUseMockPersistence();
14
14
+
if (!useMockPersistence) {
15
15
// Create database connection with config
16
16
const db = DatabaseFactory.createConnection(
17
17
this.configService.getDatabaseConfig(),