UNPKG

@deja-js/json-object-mapper

Version:

A TypeScript library to serialize and deserialize JSON objects in a fast and non-recursive way

218 lines (211 loc) 7.25 kB
declare module 'ObjectMapper/src/main/ReflectHelper' { /** * Helper functions for JS reflections. */ import 'reflect-metadata'; import { JsonPropertyDecoratorMetadata } from 'ObjectMapper/src/main/DecoratorMetadata'; /** * Returns the JsonProperty decorator metadata. */ export const getJsonPropertyDecoratorMetadata: (target: any, key: string) => JsonPropertyDecoratorMetadata; /** * Returns the JsonProperty name (if any) associated with the object instance. * If any JsonProperty metadata found, it returns the key name as the name of the property. */ export const getKeyName: (target: any, key: string) => string; /** * Returns the JsonPropertyDecoratorMetadata for the property */ export const getJsonPropertyDecorator: (metadata: any) => { (target: Function): void; (target: Object, propertyKey: string | symbol): void; }; export const getPropertyDecorator: (metadataKey: string, metadata: any) => { (target: Function): void; (target: Object, propertyKey: string | symbol): void; }; /** * Checks to see if the specified type is a standard JS object type. */ export const isSimpleType: (typeName: string) => boolean; /** * Returns the the instance type name by looking at the constructor name. * Stupid IE does not have name property! Hence the hack. */ export const getTypeNameFromInstance: (instance: any) => string; export const isArrayType: (instance: any, key: string) => boolean; export const getTypeName: (instance: any, key: any) => string; export const Constants: { OBJECT_TYPE: string; OBJECT_TYPE_LOWERCASE: string; STRING_TYPE: string; STRING_TYPE_LOWERCASE: string; NUMBER_TYPE: string; NUMBER_TYPE_LOWERCASE: string; BOOLEAN_TYPE: string; BOOLEAN_TYPE_LOWERCASE: string; DATE_TYPE: string; DATE_TYPE_LOWERCASE: string; ARRAY_TYPE: string; ARRAY_TYPE_LOWERCASE: string; FROM_ARRAY: string; }; export const getCachedType: (type: any, cache: Object) => any; } declare module 'ObjectMapper/src/main/DecoratorMetadata' { /** * Decorator names */ export const JSON_PROPERTY_DECORATOR_NAME = "JsonProperty"; /** * Decorator metadata definition for JsonProperty */ export interface JsonPropertyDecoratorMetadata { name?: string; required?: boolean; access?: AccessType; type?: any; serializer?: any; deserializer?: any; } export enum AccessType { READ_ONLY = 0, WRITE_ONLY = 1, BOTH = 2, } export interface Serializer { serialize(value: any): any; } export interface Deserializer { deserialize(value: any): any; } /** * JsonProperty Decorator function. */ export const JsonProperty: (metadata?: string | JsonPropertyDecoratorMetadata) => any; /** * Decorator for specifying cache key. * Used for Serializer/Deserializer caching. * * @export * @param {string} key * @returns */ export const CacheKey: (key: string) => Function; /** * Json convertion error type. */ export class JsonConverstionError { private json; private message; private stack; constructor(message: string, json: string); } } declare module 'ObjectMapper/src/main/DeserializationHelper' { /** * Deserializes a standard js object type(string, number and boolean) from json. */ export const DeserializeSimpleType: (instance: Object, instanceKey: string, type: any, json: any, jsonKey: string) => any[]; /** * Deserializes a standard js Date object type from json. */ export const DeserializeDateType: (instance: Object, instanceKey: string, type: any, json: any, jsonKey: string) => ConversionFunctionStructure[]; /** * Deserializes a JS array type from json. */ export const DeserializeArrayType: (instance: Object, instanceKey: string, type: any, json: Object, jsonKey: string) => ConversionFunctionStructure[]; /** * Deserializes a js object type from json. */ export const DeserializeComplexType: (instance: Object, instanceKey: string, type: any, json: any, jsonKey: string) => ConversionFunctionStructure[]; /** * Conversion function parameters structure that will be used to call the function. */ export interface ConversionFunctionStructure { functionName: string; instance: any; instanceKey?: string; type?: any; json: any; jsonKey?: string; } /** * Object to cache deserializers */ export const deserializers: Object; /** * Checks to see if the deserializer already exists or not. * If not, creates a new one and caches it, returns the * cached instance otherwise. */ export const getOrCreateDeserializer: (type: any) => any; /** * List of JSON object conversion functions. */ export const conversionFunctions: Object; } declare module 'ObjectMapper/src/main/SerializationHelper' { import { Serializer } from 'ObjectMapper/src/main/DecoratorMetadata'; export interface SerializationStructure { id: string; type: string; instance: any; values: Array<String>; parentIndex: number; key: string; visited: boolean; } export const SerializeArrayType: (parentStructure: SerializationStructure, instanceStructure: SerializationStructure, instanceIndex: number) => SerializationStructure[]; export const serializeObject: (key: string, instanceValuesStack: String[]) => string; export const serializeArray: (key: string, instanceValuesStack: String[]) => string; export const mergeObjectOrArrayValuesAndCopyToParents: (instanceStructure: SerializationStructure, parentStructure: SerializationStructure) => void; export const mergeObjectOrArrayValues: (instanceStructure: SerializationStructure) => void; export const SerializeObjectType: (parentStructure: SerializationStructure, instanceStructure: SerializationStructure, instanceIndex: number) => SerializationStructure[]; export class DateSerializer implements Serializer { serialize: (value: Date) => number; } /** * Object to cache serializers */ export const serializers: Object; /** * Checks to see if the serializer already exists or not. * If not, creates a new one and caches it, returns the * cached instance otherwise. */ export const getOrCreateSerializer: (type: any) => any; export const serializeFunctions: any[]; } declare module 'ObjectMapper/src/main/index' { export namespace ObjectMapper { /** * Deserializes an array of object types with the passed on JSON data. */ const deserializeArray: <T>(type: new () => T, json: Object) => T[]; /** * Deserializes a Object type with the passed on JSON data. */ const deserialize: <T>(type: new () => T, json: Object) => T; /** * Serializes an object instance to JSON string. */ const serialize: (obj: any) => String; } export { JsonProperty, JsonConverstionError, AccessType, CacheKey } from 'ObjectMapper/src/main/DecoratorMetadata'; export { DateSerializer } from 'ObjectMapper/src/main/SerializationHelper'; } declare module 'ObjectMapper/src/test/NameSpaces' { export namespace a { class NamespaceAClass { f: number; t: number; } } export namespace b { class NamespaceBClass { c: string; d: a.NamespaceAClass; } } }