# Prompt: Complete dbis_core TypeScript Fixes (Phases 1–4)

**Use this prompt in Agent mode to execute the full TypeScript fix plan.**

---

## Execution Status (2026-01-31)

**Phases 1–4 executed.** Current TS error count: ~1186. See `reports/REMAINING_TASKS_MASTER_20260201.md` for Phase review table and `TYPESCRIPT_FIXES_PRIORITIZED_PLAN.md` for continuation strategy. Remaining errors in defi, exchange, governance/msgf, gateway, and other modules.

---

## Context

The dbis_core package has ~500+ TypeScript errors. Execute fixes in four phases, following `TYPESCRIPT_FIXES_PRIORITIZED_PLAN.md`. Run `pnpm exec tsc --noEmit` after each phase to verify error reduction. Work in `dbis_core/` directory.

---

## Master Prompt

```
Complete all four phases of the dbis_core TypeScript fix plan (TYPESCRIPT_FIXES_PRIORITIZED_PLAN.md). Execute sequentially. Run `pnpm exec tsc --noEmit` after each phase to confirm error reduction before proceeding.

## Phase 1: Quick Wins

### 1.1 Missing Imports
- Add `import { v4 as uuidv4 } from 'uuid'` where uuidv4 is used but not imported
- Add `import { Decimal } from '@prisma/client/runtime/library'` where Decimal is used
- Add `import { Prisma } from '@prisma/client'` where Prisma namespace is used
- Key files: mrecp-harmonization.service.ts, multiverse-fx.service.ts, multiverse-ssu.service.ts

### 1.2 Missing Return Statements in Routes
- Add `return` before every `res.json()`, `res.status().json()`, and `next(error)` in Express route handlers
- Files: dbis-admin.routes.ts, scb-admin.routes.ts, beie.routes.ts, gase.routes.ts, rssck.routes.ts, and all other *.routes.ts

### 1.3 Simple Type Assertions
- For `X as Record<string, unknown>` or similar, use `X as unknown as Record<string, unknown>` when TS complains
- Fix type conversion warnings in 5–8 affected files

---

## Phase 2: Pattern-Based Fixes

### 2.1 JsonValue Type Mismatches
- Cast `Record<string, unknown>` → `as Prisma.InputJsonValue` when assigning to Prisma Json fields
- For nullable: `value ? (value as Prisma.InputJsonValue) : Prisma.JsonNull`
- High-impact: uhem-encoding.service.ts, defi-module.service.ts, gdsl-clearing.service.ts, gsds-contract.service.ts, msgf-*.service.ts

### 2.2 Property Access on Unknown Types
- Add type assertions: `(data as Record<string, unknown>).property` or define interfaces
- Files: reporting-engine.service.ts, sandbox.service.ts, supervision-engine.service.ts

### 2.3 Type Conversion via Unknown
- Change `as TargetType` to `as unknown as TargetType` where TS rejects direct cast
- Files: corridor-controls.service.ts, gru-controls.service.ts, network-controls.service.ts, dscn-aml-scanner.service.ts, rssck.service.ts

---

## Phase 3: Type System Fixes

### 3.1 Prisma Property Access
- Check prisma/schema.prisma for correct field names (e.g. indexValue not price, include relations for bondName/bondCode)
- Add `include` for relations when accessing nested fields
- Files: global-overview.service.ts, gru-command.service.ts, cbdc-fx.service.ts, supervisory-ai.service.ts

### 3.2 Prisma UpdateMany Errors
- Use correct field names from schema; switch to `update` instead of `updateMany` if field not in UpdateManyMutationInput
- File: gru-controls.service.ts

### 3.3 Request Type Extensions
- Create `src/types/express.d.ts` extending Request with `sovereignBankId?: string` or use `(req as { sovereignBankId?: string }).sovereignBankId`
- Files: dbis-admin.routes.ts, scb-admin.routes.ts

### 3.4 Null Safety
- Add optional chaining (`?.`), null checks, or non-null assertion (`!`) where "possibly null" errors occur
- Files: gru-command.service.ts, multiverse-fx.service.ts, uhem-analytics.service.ts

---

## Phase 4: Schema & Property Fixes

### 4.1 Prisma Schema Mismatches
- Replace `prisma.settlement` → `prisma.gasSettlement`, `prisma.aiAutonomousAction` → `prisma.aifx_autonomous_actions` (or correct model per schema)
- Ensure model names match schema (snake_case vs camelCase)
- Files: legal-harmonization.service.ts, trade-harmonization.service.ts, scdc-ai-mandate.service.ts, mrecp-convergence.service.ts

### 4.2 Complex Type Assignments
- Fix array/object type mismatches; add missing `id` or required fields; correct function parameter types
- Files: global-overview.service.ts, gdsl-contract.service.ts, gsds-contract.service.ts, multiverse-fx.service.ts

### 4.3 Decimal Operations
- Use `decimal.plus(n)` instead of `decimal + n`; use `decimal.toString()` for string conversion
- Files: regulatory-equivalence.service.ts, zk-balance-proof.service.ts

---

## Success Criteria
- Phase 1: < 500 errors
- Phase 2: < 300 errors  
- Phase 3: < 150 errors
- Phase 4: 0 errors (build passes)

## Constraints
- Do not modify prisma/schema.prisma unless a field is truly missing
- Prefer type assertions over schema changes when schema is correct
- Commit after each phase with message like "dbis_core: Phase N TypeScript fixes"
```

---

## Shorter One-Liner Prompt

```
In dbis_core, complete Phases 1–4 of TYPESCRIPT_FIXES_PRIORITIZED_PLAN.md: (1) Add missing imports uuidv4/Decimal/Prisma, add return before res.json/next in routes, fix simple type assertions; (2) Cast JsonValue, fix unknown property access, add as unknown as for conversions; (3) Fix Prisma field names, add Express Request extension for sovereignBankId, add null checks; (4) Fix Prisma model names, complex type assignments, Decimal method usage. Run tsc --noEmit after each phase. Target: 0 errors.
```

---

## File Reference

| Phase | Key Files |
|-------|-----------|
| 1 | mrecp-harmonization, multiverse-fx, multiverse-ssu, *-routes.ts |
| 2 | uhem-encoding, defi-module, gdsl-clearing, gsds-contract, msgf-*, reporting-engine, sandbox, supervision-engine, corridor-controls, gru-controls, network-controls, dscn-aml-scanner, rssck |
| 3 | global-overview, gru-command, cbdc-fx, supervisory-ai, gru-controls, dbis-admin.routes, scb-admin.routes, multiverse-fx, uhem-analytics |
| 4 | legal-harmonization, trade-harmonization, scdc-ai-mandate, mrecp-convergence, global-overview, gdsl-contract, gsds-contract, regulatory-equivalence, zk-balance-proof |
