import Serializer, { RelationshipConfig } from './serializer'; import Model from '../data/model'; import Action, { RenderOptions } from '../runtime/action'; import { RelationshipDescriptor } from '../data/descriptors'; /** * Renders the payload as a flat JSON object or array at the top level. Related * models are embedded. * * @package data * @since 0.1.0 */ export default abstract class JSONSerializer extends Serializer { /** * The default content type to apply to responses formatted by this * serializer * * @since 0.1.0 */ contentType: string; /** * Renders the payload, either a primary data model(s) or an error payload. * * @since 0.1.0 */ serialize(body: any, action: Action, options?: RenderOptions): Promise; /** * Renders a primary data payload (a model or array of models). * * @since 0.1.0 */ protected renderPrimary(payload: any, action: Action, options: RenderOptions): Promise; /** * If the primary data isn't a model, just render whatever it is directly * * @since 0.1.0 */ renderItem(item: any, action: Action, options: RenderOptions): Promise; /** * Renders an individual model * * @since 0.1.0 */ renderModel(model: Model, action: Action, options: RenderOptions): Promise; /** * Serialize the attributes for a given model * * @since 0.1.0 */ protected serializeAttributes(model: Model, action: Action, options: RenderOptions): any; /** * Transform attribute names into their over-the-wire representation. Default * behavior uses the attribute name as-is. * * @since 0.1.0 */ protected serializeAttributeName(attributeName: string): string; /** * Take an attribute value and return the serialized value. Useful for * changing how certain types of values are serialized, i.e. Date objects. * * The default implementation returns the attribute's value unchanged. * * @since 0.1.0 */ protected serializeAttributeValue(value: any, key: string, model: any): any; /** * Serialize the relationships for a given model * * @since 0.1.0 */ protected serializeRelationships(model: Model, action: Action, options: RenderOptions): Promise<{ [key: string]: any; }>; /** * Serializes a relationship * * @since 0.1.0 */ protected serializeRelationship(relationship: string, config: RelationshipConfig, descriptor: RelationshipDescriptor, model: Model, action: Action, options: RenderOptions): Promise; /** * Transform relationship names into their over-the-wire representation. * Default behavior uses the relationship name as-is. * * @since 0.1.0 */ protected serializeRelationshipName(name: string): string; /** * Render an error payload * * @since 0.1.0 */ protected renderError(error: any, action: Action, options: any): any; }