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