ing
This commit is contained in:
parent
0402e448b2
commit
8b3c97cfd6
|
@ -5,7 +5,7 @@ export interface Type<T> extends Function {
|
|||
}
|
||||
|
||||
export declare type IdentityType<T> = T | symbol;
|
||||
export declare type PropertyKeyType = IdentityType<string | number>;
|
||||
export declare type PropertyKeyType = IdentityType<string>;
|
||||
export declare type MetadataKeyType = IdentityType<string>;
|
||||
|
||||
export enum PrimitiveType {
|
||||
|
|
|
@ -21,7 +21,7 @@ export abstract class AccessibleObject implements AnnotatedElement {
|
|||
}
|
||||
|
||||
public isAnnotationPresent<AnnotationType extends Annotation>(annotationClass: Type<AnnotationType>): boolean {
|
||||
return null !== this.getAnnotation(annotationClass);
|
||||
return undefined !== this.getAnnotation(annotationClass);
|
||||
}
|
||||
|
||||
public getOwnAnnotation<AnnotationType extends Annotation>(annotationClass: Type<AnnotationType>): AnnotationType | undefined {
|
||||
|
|
|
@ -38,11 +38,9 @@ export class Class extends AccessibleObject {
|
|||
SystemClassRegistry.set(type, clazz);
|
||||
}
|
||||
|
||||
if (null === clazz._constructor) {
|
||||
if (undefined === clazz._constructor) {
|
||||
const parameterTypes = Metadata.getOwnParamTypes(type);
|
||||
if (undefined !== parameterTypes) {
|
||||
clazz._constructor = new Constructor(clazz, parameterTypes);
|
||||
}
|
||||
clazz._constructor = new Constructor(clazz, parameterTypes);
|
||||
}
|
||||
|
||||
return clazz;
|
||||
|
@ -124,9 +122,6 @@ export class Class extends AccessibleObject {
|
|||
const fields: Map<PropertyKeyType, Field> = new Map();
|
||||
|
||||
const types = TypeUtil.ancestorsOf(this._type);
|
||||
if (null === types || 0 === types.length) {
|
||||
return fields;
|
||||
}
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
const tType = types[i];
|
||||
const tClazz = Class.forType(tType);
|
||||
|
@ -160,9 +155,6 @@ export class Class extends AccessibleObject {
|
|||
const methods: Map<PropertyKeyType, Method> = new Map();
|
||||
|
||||
const types = TypeUtil.ancestorsOf(this._type);
|
||||
if (null === types || 0 === types.length) {
|
||||
return methods;
|
||||
}
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
const tClazzType = types[i];
|
||||
const tClazz = Class.forType(tClazzType);
|
||||
|
@ -188,9 +180,6 @@ export class Class extends AccessibleObject {
|
|||
const annotations: Map<Type<any>, Annotation> = new Map();
|
||||
|
||||
const types = TypeUtil.ancestorsOf(this._type);
|
||||
if (null === types || 0 === types.length) {
|
||||
return annotations;
|
||||
}
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
const tClazzType = types[i];
|
||||
const tClazz = Class.forType(tClazzType);
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
import { Class } from './Class';
|
||||
import { Executable } from './Executable';
|
||||
|
||||
const CONSTRUCTOR_NAME = 'constructor';
|
||||
|
||||
export class Constructor extends Executable {
|
||||
// private _rawConstructor: Function;
|
||||
|
||||
|
@ -19,5 +21,3 @@ export class Constructor extends Executable {
|
|||
return new (ctor.bind.apply(ctor, [null].concat(args)))();
|
||||
}
|
||||
}
|
||||
|
||||
const CONSTRUCTOR_NAME = 'constructor';
|
||||
|
|
|
@ -49,10 +49,6 @@ export abstract class Executable extends AccessibleObject implements Member {
|
|||
* getParameterCount
|
||||
*/
|
||||
public getParameterCount(): number {
|
||||
if (null === this._parameters) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this._parameters.length;
|
||||
}
|
||||
/**
|
||||
|
@ -65,9 +61,6 @@ export abstract class Executable extends AccessibleObject implements Member {
|
|||
* getParameter
|
||||
*/
|
||||
public getParameter(index: number): Parameter | undefined {
|
||||
if (null === this._parameters) {
|
||||
return undefined;
|
||||
}
|
||||
if (0 > index || this._parameters.length <= index) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,31 @@ import {
|
|||
|
||||
import { TypeUtil } from '../util/TypeUtil';
|
||||
|
||||
/**
|
||||
* Metadata key
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const DESIGN_PARAM_TYPES = 'design:paramtypes';
|
||||
/**
|
||||
* Metadata key
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const DESIGN_TYPE = 'design:type';
|
||||
/**
|
||||
* Metadata key
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const DESIGN_RETURN_TYPE = 'design:returntype';
|
||||
/**
|
||||
* Properties collections
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const PROPERTIES: Map<MetadataKeyType, any[]> = new Map<MetadataKeyType, any[]>();
|
||||
|
||||
export class Metadata {
|
||||
/**
|
||||
* Gets the metadata value for the provided metadata key on the target object or its prototype chain.
|
||||
|
@ -504,28 +529,3 @@ export class Metadata {
|
|||
return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata key
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const DESIGN_PARAM_TYPES = 'design:paramtypes';
|
||||
/**
|
||||
* Metadata key
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const DESIGN_TYPE = 'design:type';
|
||||
/**
|
||||
* Metadata key
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const DESIGN_RETURN_TYPE = 'design:returntype';
|
||||
/**
|
||||
* Properties collections
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
const PROPERTIES: Map<MetadataKeyType, any[]> = new Map<MetadataKeyType, any[]>();
|
||||
|
|
|
@ -4,6 +4,10 @@ import {
|
|||
Type,
|
||||
} from '../core';
|
||||
|
||||
const COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||
const DEFAULT_PARAMS = /=[^,]+/mg;
|
||||
const FAT_ARROWS = /=>.*$/mg;
|
||||
|
||||
export class TypeUtil {
|
||||
/**
|
||||
* Get the provide constructor.
|
||||
|
@ -151,7 +155,7 @@ export class TypeUtil {
|
|||
* @returns {boolean}
|
||||
*/
|
||||
public static isMethod(target: any, propertyKey: PropertyKeyType): boolean {
|
||||
if (typeof(target[propertyKey]) === undefined) {
|
||||
if (typeof target.propertyKey === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -389,26 +393,27 @@ export class TypeUtil {
|
|||
* @param {number} time
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
public static promiseTimeout(promise: Promise<any>, time = 1000): Promise<{ ok: boolean, response: any }> {
|
||||
const timeout = (p: Promise<any>, t: number) => new Promise((resolve) => {
|
||||
p.then((response) => {
|
||||
resolve();
|
||||
|
||||
return response;
|
||||
});
|
||||
setTimeout(() => resolve({ ok: false }), t);
|
||||
});
|
||||
|
||||
promise = promise.then((response) => ({ ok: true, response }));
|
||||
public static promiseTimeout(promise: Promise<any>, timeout = 1000): Promise<{ ok: boolean, response?: any }> {
|
||||
let _hTimeout: any;
|
||||
|
||||
return Promise.race([
|
||||
promise,
|
||||
timeout(promise, time),
|
||||
new Promise((resolve, reject) => {
|
||||
promise.then(response => {
|
||||
clearTimeout(_hTimeout);
|
||||
|
||||
resolve();
|
||||
|
||||
return { ok: true, response };
|
||||
}).catch(reason => {
|
||||
clearTimeout(_hTimeout);
|
||||
reject(reason);
|
||||
});
|
||||
|
||||
_hTimeout = setTimeout(() => {
|
||||
resolve({ ok: false });
|
||||
}, timeout);
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||
const DEFAULT_PARAMS = /=[^,]+/mg;
|
||||
const FAT_ARROWS = /=>.*$/mg;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
"module": "esnext",
|
||||
"target": "es5",
|
||||
"types": [
|
||||
"jest",
|
||||
"node",
|
||||
"reflect-metadata",
|
||||
],
|
||||
"lib": [
|
||||
|
|
Loading…
Reference in New Issue
Block a user