UNPKG

3.18 kBTypeScriptView Raw
1import { TypeDescriptor } from './TypeDescriptor';
2/**
3 * Helper class to perform object type introspection and object instantiation.
4 *
5 * This class has symmetric implementation across all languages supported
6 * by Pip.Services toolkit and used to support dynamic data processing.
7 *
8 * Because all languages have different casing and case sensitivity rules,
9 * this TypeReflector treats all type names as case insensitive.
10 *
11 * @see [[TypeDescriptor]]
12 *
13 * ### Example ###
14 *
15 * let descriptor = new TypeDescriptor("MyObject", "mylibrary");
16 * Typeeflector.getTypeByDescriptor(descriptor);
17 * let myObj = TypeReflector.createInstanceByDescriptor(descriptor);
18 *
19 * TypeDescriptor.isPrimitive(myObject); // Result: false
20 * TypeDescriptor.isPrimitive(123); // Result: true
21 */
22export declare class TypeReflector {
23 /**
24 * Gets object type by its name and library where it is defined.
25 *
26 * @param name an object type name.
27 * @param library a library where the type is defined
28 * @returns the object type or null is the type wasn't found.
29 */
30 static getType(name: string, library: string): any;
31 /**
32 * Gets object type by type descriptor.
33 *
34 * @param descriptor a type descriptor that points to an object type
35 * @returns the object type or null is the type wasn't found.
36 *
37 * @see [[getType]]
38 * @see [[TypeDescriptor]]
39 */
40 static getTypeByDescriptor(descriptor: TypeDescriptor): any;
41 /**
42 * Creates an instance of an object type.
43 *
44 * @param type an object type (factory function) to create.
45 * @param args arguments for the object constructor.
46 * @returns the created object instance.
47 */
48 static createInstanceByType(type: any, ...args: any[]): any;
49 /**
50 * Creates an instance of an object type specified by its name
51 * and library where it is defined.
52 *
53 * @param name an object type name.
54 * @param library a library (module) where object type is defined.
55 * @param args arguments for the object constructor.
56 * @returns the created object instance.
57 *
58 * @see [[getType]]
59 * @see [[createInstanceByType]]
60 */
61 static createInstance(name: string, library: string, ...args: any[]): any;
62 /**
63 * Creates an instance of an object type specified by type descriptor.
64 *
65 * @param descriptor a type descriptor that points to an object type
66 * @param args arguments for the object constructor.
67 * @returns the created object instance.
68 *
69 * @see [[createInstance]]
70 * @see [[TypeDescriptor]]
71 */
72 static createInstanceByDescriptor(descriptor: TypeDescriptor, ...args: any[]): any;
73 /**
74 * Checks if value has primitive type.
75 *
76 * Primitive types are: numbers, strings, booleans, date and time.
77 * Complex (non-primitive types are): objects, maps and arrays
78 *
79 * @param value a value to check
80 * @returns true if the value has primitive type and false if value type is complex.
81 *
82 * @see [[TypeConverter.toTypeCode]]
83 * @see [[TypeCode]]
84 */
85 static isPrimitive(value: any): boolean;
86}