From e073e027808f388f12cf374a6a305c25222bf242 Mon Sep 17 00:00:00 2001 From: Umed Khudoiberdiev Date: Wed, 27 May 2020 21:11:04 +0300 Subject: [PATCH] fix: revert fix handle URL objects as column field values (#6145) This reverts commit 50a0641592c21f32a89c1be38da75ca6e7ac0f5a. --- src/util/OrmUtils.ts | 7 ++--- test/github-issues/5762/entity/User.ts | 24 ---------------- test/github-issues/5762/issue-5762.ts | 39 -------------------------- 3 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 test/github-issues/5762/entity/User.ts delete mode 100644 test/github-issues/5762/issue-5762.ts diff --git a/src/util/OrmUtils.ts b/src/util/OrmUtils.ts index 73d1c458ce..fe8f0a332e 100644 --- a/src/util/OrmUtils.ts +++ b/src/util/OrmUtils.ts @@ -1,5 +1,4 @@ import { ObjectLiteral } from "../common/ObjectLiteral"; -import { URL } from "url"; export class OrmUtils { @@ -83,8 +82,7 @@ export class OrmUtils { && !(value instanceof Set) && !(value instanceof Date) && !(value instanceof Buffer) - && !(value instanceof RegExp) - && !(value instanceof URL)) { + && !(value instanceof RegExp)) { if (!target[key]) Object.assign(target, { [key]: Object.create(Object.getPrototypeOf(value)) }); this.mergeDeep(target[key], value); @@ -214,8 +212,7 @@ export class OrmUtils { (x instanceof Date && y instanceof Date) || (x instanceof RegExp && y instanceof RegExp) || (x instanceof String && y instanceof String) || - (x instanceof Number && y instanceof Number) || - (x instanceof URL && y instanceof URL)) + (x instanceof Number && y instanceof Number)) return x.toString() === y.toString(); // At last checking prototypes as good as we can diff --git a/test/github-issues/5762/entity/User.ts b/test/github-issues/5762/entity/User.ts deleted file mode 100644 index 6fd70a6141..0000000000 --- a/test/github-issues/5762/entity/User.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {Entity} from "../../../../src/decorator/entity/Entity"; -import {PrimaryColumn, Column} from "../../../../src"; -import { URL } from "url"; - -@Entity() -export class User { - - @PrimaryColumn() - id: number; - - @Column("varchar", { - // marshall - transformer: { - from(value: string): URL { - return new URL(value); - }, - to(value: URL): string { - return value.toString(); - }, - }, - }) - url: URL; - -} diff --git a/test/github-issues/5762/issue-5762.ts b/test/github-issues/5762/issue-5762.ts deleted file mode 100644 index 7f90cd23be..0000000000 --- a/test/github-issues/5762/issue-5762.ts +++ /dev/null @@ -1,39 +0,0 @@ -import "reflect-metadata"; -import {expect} from "chai"; -import {Connection} from "../../../src"; -import {User} from "./entity/User"; -import {createTestingConnections, reloadTestingDatabases, closeTestingConnections} from "../../utils/test-utils"; -import { URL } from "url"; - -describe("github issues > #5762 `Using URL as a rich column type breaks", () => { - - let connections: Connection[]; - - before(async () => { - connections = await createTestingConnections({ - entities: [User], - schemaCreate: true, - dropSchema: true - }); - }); - beforeEach(() => reloadTestingDatabases(connections)); - after(() => closeTestingConnections(connections)); - - it("should allow assigning URL as a field value", () => - Promise.all(connections.map(async (connection) => { - const userRepository = connection.getRepository(User); - - const url = new URL("https://typeorm.io"); - - const user = new User(); - user.id = 1; - user.url = url; - - const promise = userRepository.save(user); - - return expect(promise).to.eventually.be.deep.equal(user) - .and.to.have.property("url").be.instanceOf(URL) - .and.to.have.nested.property("href").equal(url.href); - }))); - -});