refactor(backend): route legacy Postgres access through legacySupabaseClient
Made-with: Cursor
This commit is contained in:
parent
72ec663125
commit
7884639876
@ -1,7 +1,7 @@
|
|||||||
import { getContainer } from '@bytelyst/cosmos';
|
import { getContainer } from '@bytelyst/cosmos';
|
||||||
import { config } from '../config/index.js';
|
import { config } from '../config/index.js';
|
||||||
import logger from '../utils/logger.js';
|
import logger from '../utils/logger.js';
|
||||||
import { supabaseService } from './SupabaseService.js';
|
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
|
||||||
import type { CapitalLedgerRecord } from './CapitalLedger.js';
|
import type { CapitalLedgerRecord } from './CapitalLedger.js';
|
||||||
|
|
||||||
const CONTAINER_NAME = 'capital_ledgers';
|
const CONTAINER_NAME = 'capital_ledgers';
|
||||||
@ -27,7 +27,7 @@ function isCosmosConfigured(): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLegacyClient() {
|
function getLegacyClient() {
|
||||||
return supabaseService.getClient();
|
return getLegacySupabaseClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
function toLedgerRecord(doc: Partial<CapitalLedgerDocument> | null | undefined): CapitalLedgerRecord | null {
|
function toLedgerRecord(doc: Partial<CapitalLedgerDocument> | null | undefined): CapitalLedgerRecord | null {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import logger from '../utils/logger.js';
|
import logger from '../utils/logger.js';
|
||||||
import { supabaseService } from './SupabaseService.js';
|
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
|
||||||
import { healthTracker } from './healthTracker.js';
|
import { healthTracker } from './healthTracker.js';
|
||||||
import { observabilityService } from './observabilityService.js';
|
import { observabilityService } from './observabilityService.js';
|
||||||
import * as distributedLockRepository from './distributedLockRepository.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> {
|
private async tryAcquireRowLockLegacy(profileId: string, symbol: string | undefined, owner: string, ttlSeconds: number = 30): Promise<boolean> {
|
||||||
if (!profileId || !owner) return false;
|
if (!profileId || !owner) return false;
|
||||||
const normalizedSymbol = normalizeSymbol(symbol);
|
const normalizedSymbol = normalizeSymbol(symbol);
|
||||||
const client = supabaseService.getClient();
|
const client = getLegacySupabaseClient();
|
||||||
if (!client) return false;
|
if (!client) return false;
|
||||||
|
|
||||||
const ttl = Number.isFinite(ttlSeconds) ? Math.max(1, ttlSeconds) : 30;
|
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> {
|
private async releaseRowLockLegacy(profileId: string, symbol: string | undefined, owner: string): Promise<boolean> {
|
||||||
if (!profileId || !owner) return false;
|
if (!profileId || !owner) return false;
|
||||||
const normalizedSymbol = normalizeSymbol(symbol);
|
const normalizedSymbol = normalizeSymbol(symbol);
|
||||||
const client = supabaseService.getClient();
|
const client = getLegacySupabaseClient();
|
||||||
if (!client) return false;
|
if (!client) return false;
|
||||||
|
|
||||||
const { data, error } = await client
|
const { data, error } = await client
|
||||||
@ -97,7 +97,7 @@ export class DistributedLockService {
|
|||||||
|
|
||||||
private async tryAcquireReconciliationLockLegacy(profileId: string, owner: string, ttlSeconds: number = 30): Promise<boolean> {
|
private async tryAcquireReconciliationLockLegacy(profileId: string, owner: string, ttlSeconds: number = 30): Promise<boolean> {
|
||||||
if (!profileId || !owner) return false;
|
if (!profileId || !owner) return false;
|
||||||
const client = supabaseService.getClient();
|
const client = getLegacySupabaseClient();
|
||||||
if (!client) return false;
|
if (!client) return false;
|
||||||
|
|
||||||
const ttl = Number.isFinite(ttlSeconds) ? Math.max(1, ttlSeconds) : 30;
|
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> {
|
private async releaseReconciliationLockLegacy(profileId: string, owner: string): Promise<boolean> {
|
||||||
if (!profileId || !owner) return false;
|
if (!profileId || !owner) return false;
|
||||||
const client = supabaseService.getClient();
|
const client = getLegacySupabaseClient();
|
||||||
if (!client) return false;
|
if (!client) return false;
|
||||||
|
|
||||||
const { data, error } = await client
|
const { data, error } = await client
|
||||||
@ -162,7 +162,7 @@ export class DistributedLockService {
|
|||||||
private async isEntryInProgressLegacy(profileId: string, symbol?: string): Promise<boolean> {
|
private async isEntryInProgressLegacy(profileId: string, symbol?: string): Promise<boolean> {
|
||||||
if (!profileId) return false;
|
if (!profileId) return false;
|
||||||
const normalizedSymbol = normalizeSymbol(symbol);
|
const normalizedSymbol = normalizeSymbol(symbol);
|
||||||
const client = supabaseService.getClient();
|
const client = getLegacySupabaseClient();
|
||||||
if (!client) return false;
|
if (!client) return false;
|
||||||
|
|
||||||
const { data, error } = await client
|
const { data, error } = await client
|
||||||
|
|||||||
20
backend/src/services/legacySupabaseClient.ts
Normal file
20
backend/src/services/legacySupabaseClient.ts
Normal 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);
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@ import { getContainer } from '@bytelyst/cosmos';
|
|||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
import { config } from '../config/index.js';
|
import { config } from '../config/index.js';
|
||||||
import logger from '../utils/logger.js';
|
import logger from '../utils/logger.js';
|
||||||
import { supabaseService } from './SupabaseService.js';
|
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
|
||||||
|
|
||||||
export interface TradingUserProfile {
|
export interface TradingUserProfile {
|
||||||
user_id: string;
|
user_id: string;
|
||||||
@ -62,7 +62,7 @@ function isCosmosConfigured(): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLegacyClient() {
|
function getLegacyClient() {
|
||||||
return supabaseService.getClient();
|
return getLegacySupabaseClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeProfile(row: Partial<TradeProfileRecord> | null | undefined): TradeProfileRecord | null {
|
function normalizeProfile(row: Partial<TradeProfileRecord> | null | undefined): TradeProfileRecord | null {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { getContainer } from '@bytelyst/cosmos';
|
import { getContainer } from '@bytelyst/cosmos';
|
||||||
import { config } from '../config/index.js';
|
import { config } from '../config/index.js';
|
||||||
import logger from '../utils/logger.js';
|
import logger from '../utils/logger.js';
|
||||||
import { supabaseService } from './SupabaseService.js';
|
import { loadLatestLegacyBotStateSnapshot, saveLegacyBotStateSnapshot } from './legacySupabaseClient.js';
|
||||||
import { listActiveTradingUsers } from './userRepository.js';
|
import { listActiveTradingUsers } from './userRepository.js';
|
||||||
|
|
||||||
const CONTAINER_NAME = 'bot_state_snapshots';
|
const CONTAINER_NAME = 'bot_state_snapshots';
|
||||||
@ -46,7 +46,7 @@ export async function loadLatestBotStateSnapshot(
|
|||||||
): Promise<{ state: unknown } | null> {
|
): Promise<{ state: unknown } | null> {
|
||||||
if (!ownerId) return null;
|
if (!ownerId) return null;
|
||||||
|
|
||||||
const loadLegacySnapshot = async () => supabaseService.loadLatestBotStateSnapshot(ownerId);
|
const loadLegacySnapshot = async () => loadLatestLegacyBotStateSnapshot(ownerId);
|
||||||
|
|
||||||
if (!isCosmosConfigured()) {
|
if (!isCosmosConfigured()) {
|
||||||
return loadLegacySnapshot();
|
return loadLegacySnapshot();
|
||||||
@ -108,5 +108,5 @@ export async function saveBotStateSnapshot(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await supabaseService.saveBotStateSnapshot(ownerId, state);
|
await saveLegacyBotStateSnapshot(ownerId, state);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { getContainer } from '@bytelyst/cosmos';
|
|||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
import { config } from '../config/index.js';
|
import { config } from '../config/index.js';
|
||||||
import logger from '../utils/logger.js';
|
import logger from '../utils/logger.js';
|
||||||
import { supabaseService } from './SupabaseService.js';
|
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
|
||||||
|
|
||||||
const PRESET_CONTAINER = 'strategy_presets';
|
const PRESET_CONTAINER = 'strategy_presets';
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ function isCosmosConfigured(): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLegacyClient() {
|
function getLegacyClient() {
|
||||||
return supabaseService.getClient();
|
return getLegacySupabaseClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listStrategyPresets(): Promise<any[]> {
|
export async function listStrategyPresets(): Promise<any[]> {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { getContainer } from '@bytelyst/cosmos';
|
import { getContainer } from '@bytelyst/cosmos';
|
||||||
import { config } from '../config/index.js';
|
import { config } from '../config/index.js';
|
||||||
import logger from '../utils/logger.js';
|
import logger from '../utils/logger.js';
|
||||||
import { supabaseService } from './SupabaseService.js';
|
import { getLegacySupabaseClient } from './legacySupabaseClient.js';
|
||||||
import type { UserConfig } from './tradingUserTypes.js';
|
import type { UserConfig } from './tradingUserTypes.js';
|
||||||
|
|
||||||
const USER_PROFILE_CONTAINER = 'trading_users';
|
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) {
|
if (!client) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user