Registry /
api / tramway-formatter-hateaos
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.
services
✓ import { services } from 'tramway-formatter-hateaos';
✗ const services = require('tramway-formatter-hateaos').services;
This export is an object containing service declarations for dependency injection (DI) container. Use named import for ESM. CommonJS require may work but is less idiomatic.
providers
✓ import { providers } from 'tramway-formatter-hateaos';
✗ const { providers } = require('tramway-formatter-hateaos');
Contains HATEAOSAPIProvider, a decorator for APIProvider. Named import for ESM.
HATEAOSEntity
✓ import { HATEAOSEntity } from 'tramway-formatter-hateaos';
Named export for the HATEAOS entity class. CommonJS require also works.
HATEAOSCollection
✓ import { HATEAOSCollection } from 'tramway-formatter-hateaos';
Named export for the HATEAOS collection class.
Demonstrates how to import and register the Tramway HATEAOS Formatter services and providers in a dependency injection container for REST API formatting.
// Assuming ESM environment with tramway-core-router set up
import { services } from 'tramway-formatter-hateaos';
// Use services object to register DI in your config/services/index.js
// Then access HATEAOSFormatter in a controller:
// this.formatter.formatEntity(entity);
// this.formatter.formatCollection(collection);
// this.formatter.send(res, formattedItem, options);
// For paginated variant, use 'hateoas.service.formatter:paginated' in DI.
// To use HATEAOSAPIProvider:
import { providers } from 'tramway-formatter-hateaos';
const { HATEAOSAPIProvider } = providers;
// Register in DI:
// "provider.hateaos": {
// "class": HATEAOSAPIProvider,
// "constructor": [
// {"type": "service", "key": "provider.api"},
// {"type": "service", "key": "factory.hateaos"},
// {"type": "parameter", "key": "api_resource"}
// ]
// }
Errors
Common errors & fixes
Error: Cannot find module 'tramway-core-router'
Missing peer dependency tramway-core-router
fixInstall tramway-core-router: npm install tramway-core-router@^3.3.0
TypeError: Cannot read properties of undefined (reading 'formatEntity')
HATEAOSFormatter service not properly injected into controller
fixAdd hateoas.service.formatter to the controller's constructor dependencies in services config.
Error: Cannot find module 'tramway-connection-rest-api'
Missing dependencies for HATEAOSAPIProvider
fixInstall tramway-connection-rest-api: npm install tramway-connection-rest-api
TypeError: options.links is not iterable
Options passed to send method does not contain a links array
fixProvide options with links array: this.formatter.send(res, item, { links: [] }); Audit
Dependencies
tramway-core-routerrequiredPeer dependency required for routing and HTTP response handling.