website refactor
This commit is contained in:
38
apps/website/lib/contracts/view-data/ViewData.ts
Normal file
38
apps/website/lib/contracts/view-data/ViewData.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* ViewData contract
|
||||
*
|
||||
* Represents the shape of data that can be passed to Templates.
|
||||
*
|
||||
* Based on VIEW_DATA.md:
|
||||
* - JSON-serializable only
|
||||
* - Contains only template-ready values (strings/numbers/booleans)
|
||||
* - MUST NOT contain class instances
|
||||
*
|
||||
* This is a type-level contract, not a class-based one.
|
||||
*/
|
||||
|
||||
import type { JsonValue, JsonObject } from '../types/primitives';
|
||||
|
||||
/**
|
||||
* Base interface for ViewData objects
|
||||
*
|
||||
* All ViewData must be JSON-serializable.
|
||||
* This type ensures no class instances or functions are included.
|
||||
*/
|
||||
export interface ViewData extends JsonObject {
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper type to ensure a type is ViewData-compatible
|
||||
*
|
||||
* Usage:
|
||||
* ```typescript
|
||||
* type MyViewData = ViewData & {
|
||||
* title: string;
|
||||
* count: number;
|
||||
* items: string[];
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
export type ViewDataOf<T extends ViewData> = T;
|
||||
Reference in New Issue
Block a user