Skip to content

Commit 67911d5

Browse files
Copilothotlong
andcommitted
refactor: add JSDoc comments explaining object vs Record<string, unknown> type strategy
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent db6be24 commit 67911d5

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/foundation/types/src/driver.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ export interface BaseDriverConfig {
169169
// Driver Interface
170170
// ============================================================================
171171

172+
/**
173+
* Database driver interface. All storage backends implement this contract.
174+
*
175+
* Type strategy:
176+
* - `Record<string, unknown>` for data payloads (plain field-value maps)
177+
* - `object` for query/filter/command parameters that may receive named interfaces
178+
* (e.g., UnifiedQuery, Filter) which lack implicit index signatures
179+
* - `unknown` for opaque values (transaction handles, heterogeneous returns)
180+
*/
172181
export interface Driver {
173182
/** Driver identifier (e.g., 'memory', 'sql', 'mongo') */
174183
readonly name?: string;

packages/foundation/types/src/hook.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ export interface BaseHookContext<_T = Record<string, unknown>> {
6161
export interface RetrievalHookContext<T = Record<string, unknown>> extends BaseHookContext<T> {
6262
operation: 'find' | 'count';
6363

64-
/** The query criteria being executed. Modifiable in 'before' hooks. */
64+
/**
65+
* The query criteria being executed. Modifiable in 'before' hooks.
66+
* Typed as `object` (not `Record<string, unknown>`) because named interfaces
67+
* like UnifiedQuery lack index signatures and aren't assignable to Record types.
68+
*/
6569
query: object;
6670

6771
/** The result of the query. Only available in 'after' hooks. */

packages/foundation/types/src/repository.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
import { UnifiedQuery, Filter } from "./query";
1010

11+
/**
12+
* Repository interface for CRUD operations on a single object type.
13+
*
14+
* Note: `object` is used for filter/query parameters instead of `Record<string, unknown>`
15+
* because named TypeScript interfaces (e.g., UnifiedQuery, Filter) lack implicit index
16+
* signatures and are not assignable to `Record<string, unknown>`.
17+
*
18+
* @typeParam T - The document shape returned by queries. Defaults to `Record<string, unknown>`.
19+
*/
1120
export interface IObjectRepository<T = Record<string, unknown>> {
1221
find(query?: UnifiedQuery): Promise<T[]>;
1322
findOne(idOrQuery: string | number | UnifiedQuery): Promise<T | null>;

0 commit comments

Comments
 (0)