E32A fix(storage): route every getDb call through tenant resolution by Mnehmos · Pull Request #84 · Mnehmos/mnehmos.rpg.mcp · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
2 changes: 1 addition & 1 deletion src/server/consolidated/aura-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type AuraManageAction = typeof ACTIONS[number];
// ═══════════════════════════════════════════════════════════════════════════

function ensureDb() {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return {
auraRepo: new AuraRepository(db),
encounterRepo: new EncounterRepository(db),
Expand Down
2 changes: 1 addition & 1 deletion src/server/consolidated/character-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const CLASS_SAVE_KEYS: Record<string, z.infer<typeof SaveProficiencySchema>> = {
// ═══════════════════════════════════════════════════════════════════════════

function ensureDb() {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return {
db,
characterRepo: new CharacterRepository(db)
Expand Down
2 changes: 1 addition & 1 deletion src/server/consolidated/combat-action.ts
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const definitions: Record<CombatAction, ActionDefinition> = {
// wrap the create in a try/get fallback — the loser of the race
// adopts the winner's engine.
if (!engine) {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
const repo = new EncounterRepository(db);
const persisted = repo.loadState(params.encounterId);
if (persisted) {
Expand Down
8 changes: 4 additions & 4 deletions src/server/consolidated/combat-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const definitions: Record<CombatManageAction, ActionDefinition> = {
const runtime = getAgentRuntime() ?? (() => {
const factory = new ProviderFactory();
factory.initialize();
return buildAgentRuntime(getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db'), factory);
return buildAgentRuntime(getDb(), factory);
})();

const agent = runtime.agentRepo.findByCharacterId(currentActorId);
Expand Down Expand Up @@ -364,7 +364,7 @@ const definitions: Record<CombatManageAction, ActionDefinition> = {
let loadedFromDb = false;

if (!engine) {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
const repo = new EncounterRepository(db);
const persisted = repo.loadState(params.encounterId);
if (persisted) {
Expand All @@ -388,7 +388,7 @@ const definitions: Record<CombatManageAction, ActionDefinition> = {
// DB state. Roll back the in-memory addParticipants and
// surface an explicit error.
try {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
const repo = new EncounterRepository(db);
repo.saveState(params.encounterId, state);
} catch (err) {
Expand Down Expand Up @@ -489,7 +489,7 @@ const definitions: Record<CombatManageAction, ActionDefinition> = {
get_history: {
schema: GetHistorySchema,
handler: async (params: z.infer<typeof GetHistorySchema>) => {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
const actionLogRepo = new CombatActionLogRepository(db);

let actions;
Expand Down
2 changes: 1 addition & 1 deletion src/server/consolidated/concentration-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ConcentrationAction = typeof ACTIONS[number];
// ═══════════════════════════════════════════════════════════════════════════

function ensureDb() {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return {
characterRepo: new CharacterRepository(db),
concentrationRepo: new ConcentrationRepository(db),
Expand Down
8 changes: 4 additions & 4 deletions src/server/consolidated/npc-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type NpcManageAction = typeof ACTIONS[number];
// ═══════════════════════════════════════════════════════════════════════════

function getRepo(): NpcMemoryRepository {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return new NpcMemoryRepository(db);
}

Expand Down Expand Up @@ -269,7 +269,7 @@ async function handleCreateNpc(args: z.infer<typeof NewCreateSchema>): Promise<o
origin: charResult.origin
};

const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
const memoryRepo = new NpcMemoryRepository(db);

// STEP 5: Seed initial relationship (best-effort)
Expand Down Expand Up @@ -400,7 +400,7 @@ async function handleCreateNpc(args: z.infer<typeof NewCreateSchema>): Promise<o
// ----- Full context bundle -----

async function handleGetFullContext(args: z.infer<typeof GetFullContextSchema>): Promise<object> {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
const charRepo = new CharacterRepository(db);
const agentRepo = new AgentRepository(db);
const memoryRepo = new NpcMemoryRepository(db);
Expand Down Expand Up @@ -900,7 +900,7 @@ async function handleGetContext(args: z.infer<typeof GetContextSchema>): Promise
}

async function handleInteract(args: z.infer<typeof InteractSchema>): Promise<object> {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
const charRepo = new CharacterRepository(db);
const spatialRepo = new SpatialRepository(db);
const memoryRepo = new NpcMemoryRepository(db);
Expand Down
2 changes: 1 addition & 1 deletion src/server/consolidated/rest-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RestAction = typeof ACTIONS[number];
// ═══════════════════════════════════════════════════════════════════════════

function ensureDb() {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return {
characterRepo: new CharacterRepository(db)
};
Expand Down
2 changes: 1 addition & 1 deletion src/server/consolidated/scroll-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const SpellcastingClassEnum = z.enum([
// ═══════════════════════════════════════════════════════════════════════════

function ensureDb() {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return {
characterRepo: new CharacterRepository(db),
itemRepo: new ItemRepository(db),
Expand Down
2 changes: 1 addition & 1 deletion src/server/consolidated/theft-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TheftManageAction = typeof ACTIONS[number];
// ═══════════════════════════════════════════════════════════════════════════

function getRepo(): TheftRepository {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return new TheftRepository(db);
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/consolidated/world-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type WorldManageAction = typeof ACTIONS[number];
// ═══════════════════════════════════════════════════════════════════════════

function getWorldRepo(): WorldRepository {
const db = getDb(process.env.NODE_ENV === 'test' ? ':memory:' : 'rpg.db');
const db = getDb();
return new WorldRepository(db);
}

Expand Down
Loading
Loading
0