Skip to content

Commit de45f21

Browse files
Copilothotlong
andcommitted
feat: add db.ts deprecation annotations, update ROADMAP.md, add logging docs to DEVELOPMENT_WORKFLOW.md
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 3b93b35 commit de45f21

15 files changed

Lines changed: 159 additions & 3 deletions

File tree

DEVELOPMENT_WORKFLOW.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,68 @@ pnpm typecheck
303303
pnpm test
304304
```
305305

306+
## 📝 Logging
307+
308+
HotCRM uses **structured logging** via [pino](https://getpino.io). All log output is JSON, making it easy to search, filter, and aggregate in production.
309+
310+
### Creating a Logger
311+
312+
```typescript
313+
import { createLogger } from '@hotcrm/core';
314+
315+
const logger = createLogger('crm:account');
316+
```
317+
318+
The module name follows the convention `package:module` (e.g. `crm:account`, `finance:invoice`, `ai:cache-manager`).
319+
320+
### Log Levels
321+
322+
| Level | Method | When to use |
323+
|-------|--------|-------------|
324+
| `debug` | `logger.debug(...)` | Verbose development-time tracing |
325+
| `info` | `logger.info(...)` | Normal operational events |
326+
| `warn` | `logger.warn(...)` | Something unexpected but recoverable |
327+
| `error` | `logger.error(...)` | Failures that need attention |
328+
329+
### Structured Data
330+
331+
Always pass structured data as the **first argument** (object), and a short message string as the **second**:
332+
333+
```typescript
334+
// Good — structured data is machine-parseable
335+
logger.info({ accountId, healthScore: 85 }, 'Account scored');
336+
logger.error({ err }, 'Failed to update account');
337+
338+
// Bad — don't embed data in the message string
339+
logger.info(`Account ${accountId} scored 85`);
340+
```
341+
342+
### Controlling Log Level
343+
344+
Set the `LOG_LEVEL` environment variable:
345+
346+
```bash
347+
LOG_LEVEL=debug pnpm dev # See all log output
348+
LOG_LEVEL=warn pnpm start # Only warnings and errors in production
349+
```
350+
351+
### Testing with Logger
352+
353+
In tests, mock `@hotcrm/core` so log calls delegate to `console.*` (allowing existing `vi.spyOn(console, ...)` patterns):
354+
355+
```typescript
356+
vi.mock('@hotcrm/core', () => ({
357+
createLogger: () => ({
358+
info: (...args: any[]) => console.log(...args),
359+
warn: (...args: any[]) => console.warn(...args),
360+
error: (...args: any[]) => console.error(...args),
361+
debug: (...args: any[]) => console.debug(...args),
362+
}),
363+
}));
364+
```
365+
366+
> **Note:** Do not use `console.log` directly in production source code. Always use `createLogger` from `@hotcrm/core`.
367+
306368
## ❓ Troubleshooting FAQ
307369

308370
### `pnpm install` fails

ROADMAP.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
| Studio Builder Configs | 4 (Interface Builder, Page Builder, Canvas Snap, Element Palette) |
6666
| Navigation Areas | 3 (header, sidebar, utility bar) |
6767
| Packages Registered in Root Config | 13 of 13 (all packages registered) |
68-
| Test Files | 192 files, 3799 tests (all passing) |
68+
| Test Files | 194 files, 3813 tests (all passing) |
6969
| TypeScript Compliance | 100% (zero type errors) |
7070
| Protocol Compliance | 100% (all objects pass ObjectSchema.create()) |
7171
| Spec Schema Adoption | ~95 of ~95 application-level schemas used (~100%) |
@@ -193,8 +193,10 @@ These items were deferred during Phase 13 and have been completed:
193193

194194
#### Deferred / Future
195195

196-
- [ ] **Structured logging migration** — Replace `console.log` with pino logger across hook files
197-
- [ ] **Legacy API cleanup** — Remove `db.ts` references and migrate to broker/ObjectQL
196+
- [x] **Structured logging migration** — Replaced `console.log` with pino logger (`createLogger` from `@hotcrm/core`) across 154 hook/action/service files in all 13 packages; removed emoji from log output; added 9 logger unit tests
197+
- [x] **CacheManager test isolation** — Added `CacheManager.resetInstance()` for test isolation; 5 dedicated tests
198+
- [x] **Legacy API cleanup (Phase 1)** — Added `@deprecated` annotations and migration guide to all 13 `db.ts` files; `db` export marked for removal
199+
- [ ] **Legacy API cleanup (Phase 2)** — Remove `db.ts` exports entirely once all consumers migrated to broker/ObjectQL
198200
- [ ] **E2E test coverage** — Build API-layer end-to-end tests for Feed API / MCP API
199201
- [ ] **FormView `as any` cleanup** — Remove `as any` casts once `@objectstack/spec` aligns FormView column types
200202

@@ -204,6 +206,7 @@ These items were deferred during Phase 13 and have been completed:
204206

205207
| Date | From | To | Breaking Changes | Tests |
206208
|------|------|----|-----------------|-------|
209+
| 2026-02-21 | v3.0.8 | v3.0.8 | None (Phase 15 continued: Structured pino logging across 154 files, CacheManager test isolation, db.ts deprecation annotations, emoji removal from logs) | 3813 ✅ |
207210
| 2026-02-21 | v3.0.8 | v3.0.8 | None (Phase 15: Repository quality improvements — hook `any` type migration, CI typecheck, ESLint version alignment, documentation updates, code-quality workflow fixes) | 3799 ✅ |
208211
| 2027-02-21 | v3.0.8 | v3.0.8 | None (Phase 14 complete: Activity Feed/Chatter across 6 clouds, 4 Interface Builder blank pages, Dashboard headers & global filters on 6 clouds, ViewTabs on 18 views, Feed API 8 endpoints, Feed service contract, System metadata, Studio builder configs, Navigation areas, 327 new tests) | 3707 ✅ |
209212
| 2026-02-21 | v3.0.6 | v3.0.8 | None (New: Activity Feed/Chatter system, Interface Builder/Blank Pages, Dashboard headers & global filters, Feed API contracts, Studio builder configs, Oclif CLI plugin, Package conventions; Phase 14 roadmap added) | 3318 ✅ |

packages/analytics/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

packages/community/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

packages/crm/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

packages/education/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

packages/finance/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

packages/financial-services/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

packages/healthcare/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

packages/hr/src/db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/**
2+
* @deprecated This module is scheduled for removal. Migrate to broker/ObjectQL.
3+
*
24
* ObjectQL Broker - Data Access Layer
35
*
46
* Provides a unified data access interface using the ObjectQL broker pattern.
57
* In production, this connects to the @objectstack/runtime engine.
68
* Actions and services use this broker for CRUD operations.
79
* Hooks should prefer ctx.ql (injected by the runtime) for transactional access.
10+
*
11+
* Migration Guide:
12+
* - Hooks: use `ctx.ql` (injected by the runtime) — `(ctx.ql as any).find(...)`
13+
* - Actions: import `broker` from this module (not `db`)
14+
* - The `db` export is a legacy shim and will be removed in a future release.
815
*/
916

1017
export interface BrokerQueryOptions {

0 commit comments

Comments
 (0)