Skip to content

API reference > @kontsedal/olas-entities > EntityDef

EntityDef type ​

Module-scoped descriptor for an entity type. Define one per entity class (Post, User, Comment), then pass the resulting handles toentitiesPlugin({ entities: [...] }).

idOf extracts a string id from a value if it IS an entity of this type, or returns null / undefined if it isn't. The plugin uses idOf both to walk query results (testing every reachable subtree value) and to look up entities in the store. Falsy returns are treated as "not an entity."

The phantom type slot lets entities.signal(Post, id) returnReadSignal<Post | undefined> rather than a type-erased unknown.

Signature:

typescript
export type EntityDef<T> = {
  readonly [BRAND]: 'entity';
  readonly name: string;
  readonly idOf: (value: unknown) => string | null | undefined;
  readonly isCanonical?: (value: unknown) => boolean;
  readonly maxSlots?: number;
  readonly [PHANTOM]?: T;
};

Released under the MIT License.