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