@drupal-js-sdk/entity
Overview
Adapter-based entity loader. Register one or more adapters (e.g., JSON:API) and load entities via a single, consistent facade.
Usage
JavaScript
import { Drupal } from "@drupal-js-sdk/core";
import { DrupalEntity } from "@drupal-js-sdk/entity";
import { JsonApiEntityAdapter } from "@drupal-js-sdk/jsonapi";
const drupal = new Drupal({ baseURL: "https://example.com" });
const entities = new DrupalEntity(drupal)
.registerAdapter("jsonapi", (ctx) => new JsonApiEntityAdapter(ctx))
.setDefaultAdapter("jsonapi");
// Optionally type attributes in TS; in JS just call load
const loader = entities.entity({ entity: "node", bundle: "article" });
const article = await loader.load("123");
Public API
class EntityLoader<T>
load
class EntityService
Constructor
registerAdapter
setDefaultAdapter
entity
class DrupalEntity
(facade)
Constructor
registerAdapter
setDefaultAdapter
entity
Types
EntityIdentifier
,EntityAttributes
,EntityRecord
,EntityLoadOptions
EntityAdapterContext
,EntityAdapter
,EntityAdapterFactory
Notes
- Adapters encapsulate backend specifics (e.g., JSON:API).
- Uses the HTTP client and config from the provided
CoreInterface
.