Skip to content

Commit fc64793

Browse files
committed
added EntityRecord
1 parent a1ebbbd commit fc64793

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export * from "./types.js";
3636
export type {
3737
EntitiesModule,
3838
EntityHandler,
39+
EntityRecord,
3940
EntityTypeRegistry,
4041
RealtimeEventType,
4142
RealtimeEvent,

src/modules/entities.types.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,37 @@ export type SortField<T> =
8080
| `+${keyof T & string}`
8181
| `-${keyof T & string}`;
8282

83+
/**
84+
* Fields added by the server to every entity record (id, dates, created_by, etc.).
85+
*/
86+
interface ServerEntityFields {
87+
/** Unique identifier of the record */
88+
id: string;
89+
/** ISO 8601 timestamp when the record was created */
90+
created_date: string;
91+
/** ISO 8601 timestamp when the record was last updated */
92+
updated_date: string;
93+
/** Email of the user who created the record (may be hidden in some responses) */
94+
created_by?: string | null;
95+
/** ID of the user who created the record */
96+
created_by_id?: string | null;
97+
/** Whether the record is sample/seed data */
98+
is_sample?: boolean;
99+
}
100+
83101
/**
84102
* Registry mapping entity names to their TypeScript types.
85-
* Augment this interface to enable type-safe entity access.
103+
* Augment this interface with your entity schema (user-defined fields only).
86104
*/
87105
export interface EntityTypeRegistry {}
88106

107+
/**
108+
* Full record type for each entity: schema fields + server-injected fields (id, created_date, etc.).
109+
*/
110+
export type EntityRecord = {
111+
[K in keyof EntityTypeRegistry]: EntityTypeRegistry[K] & ServerEntityFields;
112+
};
113+
89114
/**
90115
* Entity handler providing CRUD operations for a specific entity type.
91116
*
@@ -389,10 +414,10 @@ export interface EntityHandler<T = any> {
389414
}
390415

391416
/**
392-
* Typed entities module - maps registry keys to typed handlers.
417+
* Typed entities module - maps registry keys to typed handlers (full record type).
393418
*/
394419
type TypedEntitiesModule = {
395-
[K in keyof EntityTypeRegistry]: EntityHandler<EntityTypeRegistry[K]>;
420+
[K in keyof EntityTypeRegistry]: EntityHandler<EntityRecord[K]>;
396421
};
397422

398423
/**

0 commit comments

Comments
 (0)