refactor(backend): route legacy Postgres access through legacySupabaseClient

Made-with: Cursor
This commit is contained in:
Saravana Achu Mac 2026-04-04 19:30:15 -07:00
parent 72ec663125
commit 7884639876
7 changed files with 37 additions and 17 deletions

View File

@ -1,7 +1,7 @@
import { getContainer } from '@bytelyst/cosmos';
import { config } from '../config/index.js';
import logger from '../utils/logger.js';
import { supabaseService } from './SupabaseService.js';
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
import type { CapitalLedgerRecord } from './CapitalLedger.js';
const CONTAINER_NAME = 'capital_ledgers';
@ -27,7 +27,7 @@ function isCosmosConfigured(): boolean {
}
function getLegacyClient() {
return supabaseService.getClient();
return getLegacySupabaseClient();
}
function toLedgerRecord(doc: Partial<CapitalLedgerDocument> | null | undefined): CapitalLedgerRecord | null {

View File

@ -1,5 +1,5 @@
import logger from '../utils/logger.js';
import { supabaseService } from './SupabaseService.js';
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
import { healthTracker } from './healthTracker.js';
import { observabilityService } from './observabilityService.js';
import * as distributedLockRepository from './distributedLockRepository.js';
@ -21,7 +21,7 @@ export class DistributedLockService {
private async tryAcquireRowLockLegacy(profileId: string, symbol: string | undefined, owner: string, ttlSeconds: number = 30): Promise<boolean> {
if (!profileId || !owner) return false;
const normalizedSymbol = normalizeSymbol(symbol);
const client = supabaseService.getClient();
const client = getLegacySupabaseClient();
if (!client) return false;
const ttl = Number.isFinite(ttlSeconds) ? Math.max(1, ttlSeconds) : 30;
@ -62,7 +62,7 @@ export class DistributedLockService {
private async releaseRowLockLegacy(profileId: string, symbol: string | undefined, owner: string): Promise<boolean> {
if (!profileId || !owner) return false;
const normalizedSymbol = normalizeSymbol(symbol);
const client = supabaseService.getClient();
const client = getLegacySupabaseClient();
if (!client) return false;
const { data, error } = await client
@ -97,7 +97,7 @@ export class DistributedLockService {
private async tryAcquireReconciliationLockLegacy(profileId: string, owner: string, ttlSeconds: number = 30): Promise<boolean> {
if (!profileId || !owner) return false;
const client = supabaseService.getClient();
const client = getLegacySupabaseClient();
if (!client) return false;
const ttl = Number.isFinite(ttlSeconds) ? Math.max(1, ttlSeconds) : 30;
@ -132,7 +132,7 @@ export class DistributedLockService {
private async releaseReconciliationLockLegacy(profileId: string, owner: string): Promise<boolean> {
if (!profileId || !owner) return false;
const client = supabaseService.getClient();
const client = getLegacySupabaseClient();
if (!client) return false;
const { data, error } = await client
@ -162,7 +162,7 @@ export class DistributedLockService {
private async isEntryInProgressLegacy(profileId: string, symbol?: string): Promise<boolean> {
if (!profileId) return false;
const normalizedSymbol = normalizeSymbol(symbol);
const client = supabaseService.getClient();
const client = getLegacySupabaseClient();
if (!client) return false;
const { data, error } = await client

View File

@ -0,0 +1,20 @@
import type { SupabaseClient } from '@supabase/supabase-js';
import { supabaseService } from './SupabaseService.js';
/**
* Single import surface for legacy Postgres (Supabase JS client) access outside SupabaseService.
* Auth-specific entry points stay on platformAuthService / supabaseService as needed.
*/
export function getLegacySupabaseClient(): SupabaseClient | null {
return supabaseService.getClient();
}
export async function loadLatestLegacyBotStateSnapshot(
ownerId: string
): Promise<{ state: unknown } | null> {
return supabaseService.loadLatestBotStateSnapshot(ownerId);
}
export async function saveLegacyBotStateSnapshot(ownerId: string, state: unknown): Promise<void> {
await supabaseService.saveBotStateSnapshot(ownerId, state);
}

View File

@ -2,7 +2,7 @@ import { getContainer } from '@bytelyst/cosmos';
import { randomUUID } from 'node:crypto';
import { config } from '../config/index.js';
import logger from '../utils/logger.js';
import { supabaseService } from './SupabaseService.js';
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
export interface TradingUserProfile {
user_id: string;
@ -62,7 +62,7 @@ function isCosmosConfigured(): boolean {
}
function getLegacyClient() {
return supabaseService.getClient();
return getLegacySupabaseClient();
}
function normalizeProfile(row: Partial<TradeProfileRecord> | null | undefined): TradeProfileRecord | null {

View File

@ -1,7 +1,7 @@
import { getContainer } from '@bytelyst/cosmos';
import { config } from '../config/index.js';
import logger from '../utils/logger.js';
import { supabaseService } from './SupabaseService.js';
import { loadLatestLegacyBotStateSnapshot, saveLegacyBotStateSnapshot } from './legacySupabaseClient.js';
import { listActiveTradingUsers } from './userRepository.js';
const CONTAINER_NAME = 'bot_state_snapshots';
@ -46,7 +46,7 @@ export async function loadLatestBotStateSnapshot(
): Promise<{ state: unknown } | null> {
if (!ownerId) return null;
const loadLegacySnapshot = async () => supabaseService.loadLatestBotStateSnapshot(ownerId);
const loadLegacySnapshot = async () => loadLatestLegacyBotStateSnapshot(ownerId);
if (!isCosmosConfigured()) {
return loadLegacySnapshot();
@ -108,5 +108,5 @@ export async function saveBotStateSnapshot(
}
}
await supabaseService.saveBotStateSnapshot(ownerId, state);
await saveLegacyBotStateSnapshot(ownerId, state);
}

View File

@ -2,7 +2,7 @@ import { getContainer } from '@bytelyst/cosmos';
import { randomUUID } from 'node:crypto';
import { config } from '../config/index.js';
import logger from '../utils/logger.js';
import { supabaseService } from './SupabaseService.js';
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
const PRESET_CONTAINER = 'strategy_presets';
@ -19,7 +19,7 @@ function isCosmosConfigured(): boolean {
}
function getLegacyClient() {
return supabaseService.getClient();
return getLegacySupabaseClient();
}
export async function listStrategyPresets(): Promise<any[]> {

View File

@ -1,7 +1,7 @@
import { getContainer } from '@bytelyst/cosmos';
import { config } from '../config/index.js';
import logger from '../utils/logger.js';
import { supabaseService } from './SupabaseService.js';
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
import type { UserConfig } from './tradingUserTypes.js';
const USER_PROFILE_CONTAINER = 'trading_users';
@ -63,7 +63,7 @@ export async function listActiveTradingUsers(): Promise<UserConfig[]> {
}
}
const client = supabaseService.getClient();
const client = getLegacySupabaseClient();
if (!client) {
return [];
}