@creamapi/cream
Version:
Concise REST API Maker - An extension library for express to create REST APIs faster
107 lines (106 loc) • 5.75 kB
TypeScript
import { Serializer, SerialBite } from './Serializer';
import { SerializerMetaInfo } from './SerializerMetaInfo';
/**
* In this namespace you can find common serializers defined by
* Cream
*/
export declare namespace CreamSerializers {
/**
* This serializer serialize objects to JSON notation
* It does not serialize methods, only attributes
* @remarks circular dependencies are not checked yet and this can
* cause a serious issue with your code.
*/
class JSON extends Serializer {
/**
* This method takes a number as input and returns a string corresponding to that number
* it just uses {@link Number.toString} under the hood
* @param _dataLabel **ignored**
* @param num The number to be serialized
* @returns a string representing the number num in json format
*/
serializeNumber(_dataLabel: string, num: number): Promise<string>;
/**
* This method just adds one quota at the beginning and one at the end of the string
* @param _dataLabel **ignored**
* @param data The string to be serialized
* @returns a string representing the string data in json format
*/
serializeString(_dataLabel: string, data: string): Promise<string>;
/**
* This method returns the string equivalent of the boolean values true/false in the JSON format
* @param _dataLabel **ignored**
* @param data the boolean data to be serialized
* @returns the string equivalent in JSON format of data
*/
serializeBoolean(_dataLabel: string, data: boolean): Promise<string>;
/**
* This method is called when a null valued attribute is found.
* @remarks Beware that this doesn't mean that the value was undefined, but rather that
* the attribute exists but it is null, with not a value.\
* For further information about the difference between undefined and null
* you should look in the JavaScript documentation.
* @param _dataLabel **ignored**
* @returns 'null'
*/
serializeNull(_dataLabel: string): Promise<string>;
/**
* This method is used to serialize a Date into a string
* it works like Date.toJSON except it is calling directly
* Date.toISOString
* @param dataLabel unused. The label of the field containing the date
* @param data the actual date to be serialized
* @returns the serialized date as string, encapsulated by colons ("\<date\>").
*/
serializeDate(dataLabel: string, data: Date): Promise<string>;
/**
* This method will do the job of serializing the input
* object that is automatically converted to a stream.\
* @remarks The stream order is top-down from class notation,
* so the first attribute found in the class will be the first
* to be inserted in the serialStream
* @param _serializedObjectName - **ignored**
* @param serialStream - the input stream the object to be serialized was sliced to by the {@link Serializer.serialize} method
* @param metaInfo - additional meta information about how to handle the object. These attributes were defined
* by {@link Meta} or by the {@link Serializer.serialize} method
* @returns a string representing the serialized version of the stream in JSON format
*/
handleSerializationStream(_serializedObjectName: string, serialStream: SerialBite[], metaInfo: SerializerMetaInfo): Promise<String>;
/**
* This method serializes array-like objects previously identified by
* the {@link Serializer.serialize} method.
* @param serialStream - the serial stream of the array. each object is one object of the array
* SerialBite.dataLabel will be the index of the object
* @returns the string corresponding to the array. If the array is empty it will return a '[]'
* representing the empty array in JSON
*/
serializeArray(serialStream: SerialBite[]): Promise<string>;
/**
* This method is used to serialize a stream that contains object-like data
* {@link SerialBite.dataLabel} will contain either the attribute name or the alternative
* given by the {@link MapTo} decorator. This is not an issue because a reference to
* the actual field is held in {@link SerialBite.data}
* @param serialStream - the array of SerialBites representing the object
* @returns the string representing the serialStream in JSON format
*/
serializeObject(serialStream: SerialBite[]): Promise<string>;
}
/**
* @experimental
* This class will act as a serializer to XML format.
* This is still experimental and it is not yet suggested for
* extensive use. Any help on its enhancement is welcome!
*/
class XML extends Serializer {
static Attribute: string;
static Text: string;
static AddIndex: string;
serializeNumber(dataLabel: string, num: number): Promise<string>;
serializeString(dataLabel: string, data: string): Promise<string>;
serializeBoolean(dataLabel: string, data: boolean): Promise<string>;
serializeNull(dataLabel: string): Promise<string>;
serializeDate(dataLabel: string, data: Date): Promise<string>;
handleSerializationStream(serializedObjectName: string, serialStream: SerialBite[], objectMetaInfo: SerializerMetaInfo): Promise<String>;
serializeArray(arrayName: string, serialStream: SerialBite[], metaInfo: SerializerMetaInfo): Promise<string>;
}
}