fixed issues compiling typeorm with babel

This commit is contained in:
Umed Khudoiberdiev 2017-01-27 16:44:08 +05:00
parent 4242879e1c
commit 02d037494a
21 changed files with 103 additions and 60 deletions

View File

@ -1,7 +1,7 @@
{
"name": "typeorm",
"private": true,
"version": "0.0.8-alpha.5",
"version": "0.0.8-alpha.6",
"description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, WebSQL databases.",
"license": "MIT",
"readmeFilename": "README.md",

View File

@ -45,17 +45,20 @@ export function Column(typeOrOptions?: ColumnType|ColumnOptions, options?: Colum
return function (object: Object, propertyName: string) {
// todo: need to store not string type, but original type instead? (like in relation metadata)
const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// if type is not given implicitly then try to guess it
if (!type)
type = ColumnTypes.determineTypeFromFunction((Reflect as any).getMetadata("design:type", object, propertyName));
if (!type) {
const reflectMetadataType = Reflect && (Reflect as any).getMetadata ? (Reflect as any).getMetadata("design:type", object, propertyName) : undefined;
if (reflectMetadataType)
type = ColumnTypes.determineTypeFromFunction(reflectMetadataType);
}
// if column options are not given then create a new empty options
if (!options) options = {} as ColumnOptions;
// check if there is no type in column options then set type from first function argument, or guessed one
if (!options.type)
if (!options.type && type)
options = Object.assign({ type: type } as ColumnOptions, options);
// if we still don't have a type then we need to give error to user that type is required
@ -70,7 +73,7 @@ export function Column(typeOrOptions?: ColumnType|ColumnOptions, options?: Colum
const args: ColumnMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
mode: "regular",
options: options
};

View File

@ -11,7 +11,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs";
export function CreateDateColumn(options?: ColumnOptions): Function {
return function (object: Object, propertyName: string) {
const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// if column options are not given then create a new empty options
if (!options) options = {} as ColumnOptions;
@ -23,7 +23,7 @@ export function CreateDateColumn(options?: ColumnOptions): Function {
const args: ColumnMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
mode: "createDate",
options: options
};

View File

@ -33,18 +33,21 @@ export function PrimaryColumn(typeOrOptions?: ColumnType|ColumnOptions, options?
}
return function (object: Object, propertyName: string) {
const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// if type is not given implicitly then try to guess it
if (!type)
type = ColumnTypes.determineTypeFromFunction((Reflect as any).getMetadata("design:type", object, propertyName));
if (!type) {
const reflectMetadataType = Reflect && (Reflect as any).getMetadata ? (Reflect as any).getMetadata("design:type", object, propertyName) : undefined;
if (reflectMetadataType)
type = ColumnTypes.determineTypeFromFunction(reflectMetadataType);
}
// if column options are not given then create a new empty options
if (!options) options = {} as ColumnOptions;
// check if there is no type in column options then set type from first function argument, or guessed one
if (!options.type)
options = Object.assign({type: type} as ColumnOptions, options);
if (!options.type && type)
options = Object.assign({ type: type } as ColumnOptions, options);
// if we still don't have a type then we need to give error to user that type is required
if (!options.type)
@ -61,7 +64,7 @@ export function PrimaryColumn(typeOrOptions?: ColumnType|ColumnOptions, options?
const args: ColumnMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
mode: "regular",
options: options
};

View File

@ -12,8 +12,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs";
*/
export function PrimaryGeneratedColumn(options?: ColumnOptions): Function {
return function (object: Object, propertyName: string) {
const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// if column options are not given then create a new empty options
if (!options) options = {} as ColumnOptions;
@ -33,7 +32,7 @@ export function PrimaryGeneratedColumn(options?: ColumnOptions): Function {
const args: ColumnMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
mode: "regular",
options: options
};

View File

@ -10,7 +10,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs";
export function UpdateDateColumn(options?: ColumnOptions): Function {
return function (object: Object, propertyName: string) {
const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// if column options are not given then create a new empty options
if (!options) options = {} as ColumnOptions;
@ -22,7 +22,7 @@ export function UpdateDateColumn(options?: ColumnOptions): Function {
const args: ColumnMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
mode: "updateDate",
options: options
};

View File

@ -11,7 +11,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs";
export function VersionColumn(options?: ColumnOptions): Function {
return function (object: Object, propertyName: string) {
const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// if column options are not given then create a new empty options
if (!options) options = {} as ColumnOptions;
@ -25,7 +25,7 @@ export function VersionColumn(options?: ColumnOptions): Function {
const args: ColumnMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
mode: "version",
options: options
};

View File

@ -44,4 +44,10 @@ export interface RelationOptions {
*/
readonly primary?: boolean;
/**
* Set this relation to be lazy. Note: lazy relations are promises. When you call them they return promise
* which resolve relation result then. If your property's type is Promise then this relation is set to lazy automatically.
*/
readonly lazy?: boolean;
}

View File

@ -9,7 +9,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs";
* multiple instances of Entity1. To achieve it, this type of relation creates a junction table, where it storage
* entity1 and entity2 ids. This is owner side of the relationship.
*/
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean }): Function;
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function;
/**
* Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have
@ -18,7 +18,7 @@ export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, optio
*/
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>,
inverseSide?: string|((object: T) => any),
options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean }): Function;
options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function;
/**
* Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have
@ -26,8 +26,8 @@ export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>,
* entity1 and entity2 ids. This is owner side of the relationship.
*/
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>,
inverseSideOrOptions?: string|((object: T) => any)|{ cascadeInsert?: boolean, cascadeUpdate?: boolean },
options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean }): Function {
inverseSideOrOptions?: string|((object: T) => any)|{ cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean },
options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function {
let inverseSideProperty: string|((object: T) => any);
if (typeof inverseSideOrOptions === "object") {
options = <RelationOptions> inverseSideOrOptions;
@ -38,13 +38,18 @@ export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>,
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
const isLazy = reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise";
// now try to determine it its lazy relation
let isLazy = options && options.lazy === true ? true : false;
if (!isLazy && Reflect && (Reflect as any).getMetadata) { // automatic determination
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
if (reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise")
isLazy = true;
}
const args: RelationMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
relationType: RelationTypes.MANY_TO_MANY,
isLazy: isLazy,
type: typeFunction,

View File

@ -38,13 +38,18 @@ export function ManyToOne<T>(typeFunction: (type?: any) => ObjectType<T>,
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
const isLazy = reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise";
// now try to determine it its lazy relation
let isLazy = options && options.lazy === true ? true : false;
if (!isLazy && Reflect && (Reflect as any).getMetadata) { // automatic determination
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
if (reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise")
isLazy = true;
}
const args: RelationMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
relationType: RelationTypes.MANY_TO_ONE,
isLazy: isLazy,
type: typeFunction,

View File

@ -10,16 +10,22 @@ import {RelationOptions} from "../options/RelationOptions";
* One-to-many relation allows to create type of relation when Entity2 can have multiple instances of Entity1.
* Entity1 have only one Entity2. Entity1 is an owner of the relationship, and storages Entity2 id on its own side.
*/
export function OneToMany<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide: string|((object: T) => any), options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean }): Function {
export function OneToMany<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide: string|((object: T) => any), options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function {
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
const isLazy = reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise";
// now try to determine it its lazy relation
let isLazy = options && options.lazy === true ? true : false;
if (!isLazy && Reflect && (Reflect as any).getMetadata) { // automatic determination
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
if (reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise")
isLazy = true;
}
const args: RelationMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
isLazy: isLazy,
relationType: RelationTypes.ONE_TO_MANY,
type: typeFunction,

View File

@ -35,13 +35,18 @@ export function OneToOne<T>(typeFunction: (type?: any) => ObjectType<T>,
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
const isLazy = reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise";
// now try to determine it its lazy relation
let isLazy = options && options.lazy === true ? true : false;
if (!isLazy && Reflect && (Reflect as any).getMetadata) { // automatic determination
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
if (reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise")
isLazy = true;
}
const args: RelationMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
isLazy: isLazy,
relationType: RelationTypes.ONE_TO_ONE,
type: typeFunction,

View File

@ -6,19 +6,24 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs";
/**
* Marks a specific property of the class as a children of the tree.
*/
export function TreeChildren(options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean }): Function {
export function TreeChildren(options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function {
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
const isLazy = reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise";
// now try to determine it its lazy relation
let isLazy = options && options.lazy === true ? true : false;
if (!isLazy && Reflect && (Reflect as any).getMetadata) { // automatic determination
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
if (reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise")
isLazy = true;
}
// add one-to-many relation for this
const args: RelationMetadataArgs = {
isTreeChildren: true,
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
isLazy: isLazy,
relationType: RelationTypes.ONE_TO_MANY,
type: () => object.constructor,

View File

@ -9,7 +9,7 @@ import {ColumnMetadataArgs} from "../../metadata-args/ColumnMetadataArgs";
export function TreeLevelColumn(): Function {
return function (object: Object, propertyName: string) {
const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// const reflectedType = ColumnTypes.typeToString((Reflect as any).getMetadata("design:type", object, propertyName));
// implicitly set a type, because this column's type cannot be anything else except number
const options: ColumnOptions = { type: ColumnTypes.INTEGER };
@ -18,7 +18,7 @@ export function TreeLevelColumn(): Function {
const args: ColumnMetadataArgs = {
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
mode: "treeLevel",
options: options
};

View File

@ -6,17 +6,23 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs";
/**
* Marks a specific property of the class as a parent of the tree.
*/
export function TreeParent(options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean }): Function {
export function TreeParent(options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function {
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
const isLazy = reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise";
// now try to determine it its lazy relation
let isLazy = options && options.lazy === true ? true : false;
if (!isLazy && Reflect && (Reflect as any).getMetadata) { // automatic determination
const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName);
if (reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise")
isLazy = true;
}
const args: RelationMetadataArgs = {
isTreeParent: true,
target: object.constructor,
propertyName: propertyName,
propertyType: reflectedType,
// propertyType: reflectedType,
isLazy: isLazy,
relationType: RelationTypes.MANY_TO_ONE,
type: () => object.constructor,

View File

@ -21,7 +21,7 @@ export interface ColumnMetadataArgs {
*
* todo: check when this is not set, because for the entity schemas we don't set it.
*/
readonly propertyType?: string;
// readonly propertyType?: string;
/**
* Column mode in which column will work.

View File

@ -33,7 +33,7 @@ export interface RelationMetadataArgs {
*
* todo: this can be empty for relations from entity schemas.
*/
readonly propertyType?: any;
// readonly propertyType?: any;
/**
* Type of relation. Can be one of the value of the RelationTypes class.

View File

@ -364,7 +364,7 @@ export class EntityMetadataBuilder {
const parentRelationColumn = new ColumnMetadata({
target: metadata.parentEntityMetadata.table.target,
propertyName: parentEntityMetadataPrimaryColumn.propertyName,
propertyType: parentEntityMetadataPrimaryColumn.propertyType,
// propertyType: parentEntityMetadataPrimaryColumn.propertyType,
mode: "parentId",
options: <ColumnOptions> {
name: columnName,
@ -400,7 +400,7 @@ export class EntityMetadataBuilder {
relationalColumn = new ColumnMetadata({
target: metadata.target,
propertyName: relation.name,
propertyType: inverseSideColumn.propertyType,
// propertyType: inverseSideColumn.propertyType,
mode: "virtual",
options: <ColumnOptions> {
type: inverseSideColumn.type,

View File

@ -37,7 +37,7 @@ export class JunctionEntityMetadataBuilder {
const junctionColumn1 = new ColumnMetadata({
target: "__virtual__",
propertyType: column1.type,
// propertyType: column1.type,
propertyName: args.joinTable.joinColumnName,
mode: "virtual",
options: <ColumnOptions> {
@ -50,7 +50,7 @@ export class JunctionEntityMetadataBuilder {
});
const junctionColumn2 = new ColumnMetadata({
target: "__virtual__",
propertyType: column2.type,
// propertyType: column2.type,
propertyName: args.joinTable.inverseJoinColumnName,
mode: "virtual",
options: <ColumnOptions> {

View File

@ -53,7 +53,7 @@ export class ColumnMetadata {
/**
* The real reflected property type.
*/
readonly propertyType: string;
// readonly propertyType: string;
/**
* The database type of the column.
@ -145,8 +145,8 @@ export class ColumnMetadata {
if (args.mode)
this.mode = args.mode;
if (args.propertyType)
this.propertyType = args.propertyType.toLowerCase();
// if (args.propertyType)
// this.propertyType = args.propertyType.toLowerCase();
if (args.options.name)
this._name = args.options.name;
if (args.options.type)

View File

@ -134,7 +134,7 @@ export class RelationMetadata {
/**
* The real reflected property type.
*/
readonly propertyType: any;
// readonly propertyType: any;
// ---------------------------------------------------------------------
// Private Properties
@ -161,8 +161,8 @@ export class RelationMetadata {
if (args.inverseSideProperty)
this._inverseSideProperty = args.inverseSideProperty;
if (args.propertyType)
this.propertyType = args.propertyType;
// if (args.propertyType)
// this.propertyType = args.propertyType;
if (args.isLazy !== undefined)
this.isLazy = args.isLazy;
if (args.options.cascadeInsert || args.options.cascadeAll)