Registry / database / ngrx-entity-relationship

ngrx-entity-relationship

JSON →
library1.7.1jsnpmunverified

An ORM-like library for managing entity relationships in NgRx applications built on top of @ngrx/entity and @ngrx/data. Current stable version: 1.7.1. Release cadence is intermittent with patch updates as needed. Key differentiators: provides a declarative API to define relationships (hasOne, hasMany, belongsTo) between entities, automatically resolves nested data, and integrates with @ngrx/entity selectors. It simplifies the boilerplate of normalizing and denormalizing relational data in the store. Supports Angular 12+ and RxJS 6+; TypeScript types are included. Alternative to manual selector composition or libraries like ngrx-normalizr.

npm install ngrx-entity-relationship
INSTALL
IMPORT
SIG · NGRX-ENTITY-RELATI
N
ngrx-entity-relationship
databasejavascriptv1.7.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

selectEntity
import { selectEntity } from 'ngrx-entity-relationship'
Main selector function for fetching an entity with its relationships.
rootEntities
import { rootEntities } from 'ngrx-entity-relationship'
Function to define root entity selectors for relationship chaining.
rootEntity
import { rootEntity } from 'ngrx-entity-relationship'
Function to define a single root entity selector.

Defines a root entity relationship with a hasMany relation and uses selectEntity to fetch it.

import { select, Store } from '@ngrx/store'; import { rootEntity, selectEntity, hasMany, hasOne } from 'ngrx-entity-relationship'; // Define relationships const authorRel = rootEntity( (state: any) => state.authors, 'id', { books: hasMany( (state: any) => state.books, 'authorId', ), }, ); // In component class MyComponent { author$ = this.store.pipe( select(selectEntity(authorRel, 'authorId')), ); constructor(private store: Store) {} }
Debug
Known issues
gotchaThe library uses memoization based on function identity. Ensure relationship definitions are stable references to avoid unnecessary re-renders.
fix
Define relationships outside of component class or use memoization techniques (e.g., store in a constant or use a factory with shared references).
affects: >=1.0.0
breakingIn v2 (future) the API for rootEntities may change to require explicit entity adapters. Check changelog on migration.
fix
Update to use adapter selectors provided by @ngrx/entity.
affects: >=2.0.0
deprecatedUsing flat selectors like 'selectEntitiesArray' is deprecated in favor of 'selectEntities' with proper mapping.
fix
Replace selectEntitiesArray with selectEntities and map the result if needed.
affects: >=1.5.0
Errors
Common errors & fixes
TypeError: Cannot read property 'ids' of undefined
The entity adapter state is not properly initialized in the store (e.g., missing initial state).
fix
Ensure the reducer for the entity state is created using the adapter's initial state (e.g., adapter.getInitialState()).
Error: The relationship 'books' is not defined for the given root entity
Typo in relationship name or missing relationship definition in the root entity object.
fix
Check that the relationship name matches exactly the key in the rootEntity config object.
NullInjectorError: No provider for Store!
The NgRx Store module is not imported in the root module/standalone component.
fix
Add StoreModule.forRoot({}) to your imports or provide the store in standalone bootstrap.
Upgrade
Version history
1.7.1latest on npm
Audit
Dependencies
@ngrx/entityrequiredPEER dependency: used for entity state management
@ngrx/storerequiredPEER dependency: used for state selectors
rxjsrequiredPEER dependency: used for reactive streams
Agent activity
4 hits · last 30 days
node
4
Resources
ngrx-entity-relationship — npm install ngrx-entity-relationship · libregistry