From c0040c8adf9a726c418b88124b24e6ee41f100f1 Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Sun, 8 Sep 2024 19:31:32 +0200 Subject: [PATCH] fix: remove @tsed/typeorm package --- packages/orm/typeorm/.npmignore | 8 - packages/orm/typeorm/package.json | 50 ----- packages/orm/typeorm/readme.md | 207 ------------------ packages/orm/typeorm/src/TypeORMModule.ts | 75 ------- .../typeorm/src/decorators/useConnection.ts | 23 -- packages/orm/typeorm/src/index.ts | 8 - .../orm/typeorm/src/interfaces/interfaces.ts | 9 - .../src/services/TypeORMService.spec.ts | 66 ------ .../typeorm/src/services/TypeORMService.ts | 36 --- .../src/utils/createConnection.spec.ts | 67 ------ .../orm/typeorm/src/utils/createConnection.ts | 20 -- packages/orm/typeorm/test/helpers/Server.ts | 38 ---- .../helpers/connections/ConnectionProvider.ts | 23 -- .../orm/typeorm/test/helpers/entity/User.ts | 9 - .../test/helpers/repository/UserRepository.ts | 5 - .../test/helpers/services/UserService.ts | 18 -- packages/orm/typeorm/test/integration.spec.ts | 52 ----- packages/orm/typeorm/tsconfig.cjs.json | 28 --- packages/orm/typeorm/tsconfig.esm.json | 28 --- packages/orm/typeorm/tsconfig.json | 31 --- packages/orm/typeorm/tsconfig.spec.json | 37 ---- packages/orm/typeorm/vitest.config.mts | 21 -- 22 files changed, 859 deletions(-) delete mode 100644 packages/orm/typeorm/.npmignore delete mode 100644 packages/orm/typeorm/package.json delete mode 100644 packages/orm/typeorm/readme.md delete mode 100644 packages/orm/typeorm/src/TypeORMModule.ts delete mode 100644 packages/orm/typeorm/src/decorators/useConnection.ts delete mode 100644 packages/orm/typeorm/src/index.ts delete mode 100644 packages/orm/typeorm/src/interfaces/interfaces.ts delete mode 100644 packages/orm/typeorm/src/services/TypeORMService.spec.ts delete mode 100644 packages/orm/typeorm/src/services/TypeORMService.ts delete mode 100644 packages/orm/typeorm/src/utils/createConnection.spec.ts delete mode 100644 packages/orm/typeorm/src/utils/createConnection.ts delete mode 100644 packages/orm/typeorm/test/helpers/Server.ts delete mode 100644 packages/orm/typeorm/test/helpers/connections/ConnectionProvider.ts delete mode 100644 packages/orm/typeorm/test/helpers/entity/User.ts delete mode 100644 packages/orm/typeorm/test/helpers/repository/UserRepository.ts delete mode 100644 packages/orm/typeorm/test/helpers/services/UserService.ts delete mode 100644 packages/orm/typeorm/test/integration.spec.ts delete mode 100644 packages/orm/typeorm/tsconfig.cjs.json delete mode 100644 packages/orm/typeorm/tsconfig.esm.json delete mode 100644 packages/orm/typeorm/tsconfig.json delete mode 100644 packages/orm/typeorm/tsconfig.spec.json delete mode 100644 packages/orm/typeorm/vitest.config.mts diff --git a/packages/orm/typeorm/.npmignore b/packages/orm/typeorm/.npmignore deleted file mode 100644 index 672ed765244..00000000000 --- a/packages/orm/typeorm/.npmignore +++ /dev/null @@ -1,8 +0,0 @@ -src -test -coverage -tsconfig.json -tsconfig.*.json -__mock__ -*.spec.js -*.tsbuildinfo diff --git a/packages/orm/typeorm/package.json b/packages/orm/typeorm/package.json deleted file mode 100644 index b819d74674b..00000000000 --- a/packages/orm/typeorm/package.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "name": "@tsed/typeorm", - "description": "TypeORM package for Ts.ED framework", - "type": "commonjs", - "version": "8.0.0-alpha.2", - "source": "./src/index.ts", - "main": "./lib/cjs/index.js", - "module": "./lib/esm/index.js", - "typings": "./lib/types/index.d.ts", - "exports": { - ".": { - "types": "./lib/types/index.d.ts", - "import": "./lib/esm/index.js", - "require": "./lib/cjs/index.js", - "default": "./lib/cjs/index.js" - } - }, - "scripts": { - "build": "yarn barrels && yarn build:ts", - "barrels": "barrels", - "test": "vitest run", - "build:ts": "tsc --build tsconfig.json", - "test:ci": "vitest run --coverage.thresholds.autoUpdate=true" - }, - "dependencies": { - "tslib": "2.6.1" - }, - "devDependencies": { - "@tsed/barrels": "workspace:*", - "@tsed/core": "workspace:*", - "@tsed/di": "workspace:*", - "@tsed/json-mapper": "workspace:*", - "@tsed/schema": "workspace:*", - "@tsed/typescript": "workspace:*", - "eslint": "^8.57.0", - "typeorm": "^0.2.45", - "typescript": "4.9.5", - "vitest": "2.0.4" - }, - "peerDependencies": { - "@tsed/core": "8.0.0-alpha.2", - "@tsed/di": "8.0.0-alpha.2", - "@tsed/json-mapper": "8.0.0-alpha.2", - "@tsed/schema": "8.0.0-alpha.2", - "typeorm": "^0.2.26" - }, - "publishConfig": { - "distTag": "deprecated" - } -} diff --git a/packages/orm/typeorm/readme.md b/packages/orm/typeorm/readme.md deleted file mode 100644 index c82fb5acd13..00000000000 --- a/packages/orm/typeorm/readme.md +++ /dev/null @@ -1,207 +0,0 @@ -

- Ts.ED logo -

- -
-

TypeORM

- -[![Build & Release](https://github.com/tsedio/tsed/workflows/Build%20&%20Release/badge.svg)](https://github.com/tsedio/tsed/actions?query=workflow%3A%22Build+%26+Release%22) -[![PR Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md) -[![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon) -[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) -[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) -[![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita) -[![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed) - -
- -
- Website -   •   - Getting started -   •   - Slack -   •   - Twitter -
- -
- -A package of Ts.ED framework. See website: https://tsed.io/tutorials/typeorm - -## Feature - -Currently, `@tsed/typeorm` allows you: - -- Configure one or more TypeORM connections via the `@Configuration` decorator. All databases will be initialized when the server starts during the server's `OnInit` phase. -- Use the Entity TypeORM as Model for Controllers, AJV Validation and Swagger. - -## Installation - -To begin, install the TypeORM module for TS.ED: - -```bash -npm install --save @tsed/typeorm -npm install --save typeorm -``` - -Then import `@tsed/typeorm` in your Server: - -```typescript -import {Configuration} from "@tsed/common"; -import "@tsed/typeorm"; // import typeorm ts.ed module - -@Configuration({ - typeorm: [ - { - name: 'default', - type: 'postgres', - ..., - - entities: [ - `./entity/*{.ts,.js}` - ], - migrations: [ - `./migrations/*{.ts,.js}` - ], - subscribers: [ - `./subscriber/*{.ts,.js}` - ] - }, - { - name: 'mongo', - type: 'mongodb', - ... - } - ] -}) -export class Server { - -} -``` - -## TypeORMService - -TypeORMService let you to retrieve an instance of TypeORM Connection. - -```typescript -import {Service, AfterRoutesInit} from "@tsed/common"; -import {TypeORMService} from "@tsed/typeorm"; -import {Connection} from "typeorm"; - -@Service() -export class UsersService implements AfterRoutesInit { - private connection: Connection; - constructor(private typeORMService: TypeORMService) { - - } - - $afterRoutesInit() { - this.connection = this.typeORMService.get("db1"); - } - - async create(user: User): Promise { - - // do something - ... - // Then save - await this.connection.manager.save(user); - console.log("Saved a new user with id: " + user.id); - - return user; - } - - async find(): Promise { - const users = await this.connection.manager.find(User); - console.log("Loaded users: ", users); - - return users; - } - -} -``` - -For more information about TypeORM look his documentation [here](https://github.com/typeorm/typeorm); - -## Use Entity TypeORM with Controller - -To begin, we need to define an Entity TypeORM like this and use Ts.ED Decorator to define the JSON Schema. - -```typescript -import {Property, MaxLength, Required} from "@tsed/common"; -import {Entity, PrimaryGeneratedColumn, Column} from "typeorm"; - -@Entity() -export class User { - @PrimaryGeneratedColumn() - @Property() - id: number; - - @Column() - @MaxLength(100) - @Required() - firstName: string; - - @Column() - @MaxLength(100) - @Required() - lastName: string; - - @Column() - @Mininum(0) - @Maximum(100) - age: number; -} -``` - -Now, the model is correctly defined and can be used with a [Controller](https://tsed.io/docs/controllers.html), [AJV validation](tutorials/ajv.md), -[Swagger](tutorials/swagger.md) and [TypeORM](https://github.com/typeorm/typeorm). - -We can use this model with a Controller like that: - -```typescript -import {Controller, Post, BodyParams} from "@tsed/common"; - -@Controller("/users") -export class UsersCtrl { - constructor(private usersService: UsersService) {} - - @Post("/") - create(@BodyParams() user: User): Promise { - return this.usersService.create(user); - } - - @Get("/") - getList(): Promise { - return this.usersService.find(); - } -} -``` - -## Contributors - -Please read [contributing guidelines here](https://tsed.io/contributing.html) - - - -## Backers - -Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)] - - - -## Sponsors - -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)] - -## License - -The MIT License (MIT) - -Copyright (c) 2016 - 2022 Romain Lenzotti - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/orm/typeorm/src/TypeORMModule.ts b/packages/orm/typeorm/src/TypeORMModule.ts deleted file mode 100644 index 90326eee0d0..00000000000 --- a/packages/orm/typeorm/src/TypeORMModule.ts +++ /dev/null @@ -1,75 +0,0 @@ -import {ancestorsOf, isClass, Type} from "@tsed/core"; -import {Configuration, InjectorService, OnDestroy, registerProvider} from "@tsed/di"; -import {AbstractRepository, ConnectionOptions, ContainedType, getCustomRepository, Repository, useContainer} from "typeorm"; -import {TypeORMService} from "./services/TypeORMService.js"; - -const WHITELIST = [Repository, AbstractRepository]; - -export class TypeORMModule implements OnDestroy { - private settings: ConnectionOptions[]; - - constructor( - configuration: Configuration, - private typeORMService: TypeORMService - ) { - this.settings = configuration.get("typeorm", []); - } - - init(): Promise { - const promises = this.settings.map((opts) => this.typeORMService.createConnection(opts)); - - return Promise.all(promises); - } - - $onDestroy(): Promise | void { - return this.typeORMService.closeConnections(); - } -} - -function isRepository(type: Type) { - const ancestors = ancestorsOf(type); - - return ( - isClass(type) && - ancestors.find((ancestor) => { - return WHITELIST.includes(ancestor); - }) - ); -} - -registerProvider({ - provide: TypeORMModule, - deps: [Configuration, TypeORMService, InjectorService], - resolvers: [ - { - deps: [TypeORMModule], - get(type, options: any) { - if (isRepository(type as any)) { - try { - return getCustomRepository(type as any, options.connection || "default"); - } catch (er) { - if (process.env.NODE_ENV !== "test") { - throw er; - } - } - } - } - } - ], - injectable: false, - async useAsyncFactory(configuration: Configuration, typeORMService: TypeORMService, injector: InjectorService) { - useContainer( - { - get(type: ContainedType): T { - return injector.hasProvider(type) ? injector.get(type as any)! : undefined!; - } - }, - {fallback: true} - ); - - const typeORMModule = new TypeORMModule(configuration, typeORMService); - await typeORMModule.init(); - - return typeORMModule; - } -}); diff --git a/packages/orm/typeorm/src/decorators/useConnection.ts b/packages/orm/typeorm/src/decorators/useConnection.ts deleted file mode 100644 index e48282af0ae..00000000000 --- a/packages/orm/typeorm/src/decorators/useConnection.ts +++ /dev/null @@ -1,23 +0,0 @@ -import {UseOpts} from "@tsed/di"; - -/** - * Configure the connection used by injector repository. - * - * ```typescript - * import {Injectable} from "@tsed/di"; - * import {UseConnection} from "@tsed/typeorm"; - * - * @Injectable() - * export class MyService { - * constructor(UseConnection("db1") userRepositoryDb1: UserRepository, - * UseConnection("db2") userRepositoryDb2: UserRepository) - * - * } - * ``` - * - * @param connection The connection name of the database. - * @decorator - */ -export function UseConnection(connection: string) { - return UseOpts({connection}); -} diff --git a/packages/orm/typeorm/src/index.ts b/packages/orm/typeorm/src/index.ts deleted file mode 100644 index 2b76b5ab621..00000000000 --- a/packages/orm/typeorm/src/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @file Automatically generated by @tsed/barrels. - */ -export * from "./decorators/useConnection.js"; -export * from "./interfaces/interfaces.js"; -export * from "./services/TypeORMService.js"; -export * from "./TypeORMModule.js"; -export * from "./utils/createConnection.js"; diff --git a/packages/orm/typeorm/src/interfaces/interfaces.ts b/packages/orm/typeorm/src/interfaces/interfaces.ts deleted file mode 100644 index edbef89b3f8..00000000000 --- a/packages/orm/typeorm/src/interfaces/interfaces.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {ConnectionOptions} from "typeorm"; - -declare global { - namespace TsED { - interface Configuration { - typeorm: ConnectionOptions[]; - } - } -} diff --git a/packages/orm/typeorm/src/services/TypeORMService.spec.ts b/packages/orm/typeorm/src/services/TypeORMService.spec.ts deleted file mode 100644 index 42a1a9dfdee..00000000000 --- a/packages/orm/typeorm/src/services/TypeORMService.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {PlatformTest} from "@tsed/common"; -import {getConnectionManager} from "typeorm"; -import {TypeORMService} from "../index.js"; - -vi.mock("typeorm"); - -function getConnectionFixture() { - const service = PlatformTest.get(TypeORMService); - - return { - service - }; -} - -class FakeConnectionManager extends Map { - get connections() { - return [...this.values()]; - } - - create(connectionOptions: any) { - connectionOptions = { - ...connectionOptions, - connect: vi.fn().mockImplementation(() => { - connectionOptions.isConnected = true; - }), - close: vi.fn().mockImplementation(() => { - connectionOptions.isConnected = false; - }), - isConnected: false - }; - this.set(connectionOptions.name, connectionOptions); - } -} - -describe("TypeORMService", () => { - const connectionManager = new FakeConnectionManager(); - beforeEach(() => { - vi.mocked(getConnectionManager).mockReturnValue(connectionManager as never); - }); - beforeEach(() => PlatformTest.create()); - afterEach(() => PlatformTest.reset()); - - describe("createConnection()", () => { - it("should create connection and close connection", async () => { - const {service} = getConnectionFixture(); - // GIVEN - - // WHEN - const result1 = await service.createConnection({name: "mydb", config: "config"} as any); - const result2 = await service.createConnection({name: "mydb", config: "config"} as any); - const result3 = await service.createConnection({config: "config"} as any); - const result4 = await service.createConnection({config: "config"} as any); - - // THEN - expect(result1).toEqual(service.get("mydb")); - expect(result2).toEqual(service.get("mydb")); - expect(result3).toEqual(service.get("default")); - expect(result4).toEqual(service.get()); - expect(service.has("default")).toEqual(true); - expect(service.has("default1")).toEqual(false); - - // WHEN close - await service.closeConnections(); - }); - }); -}); diff --git a/packages/orm/typeorm/src/services/TypeORMService.ts b/packages/orm/typeorm/src/services/TypeORMService.ts deleted file mode 100644 index b685859201c..00000000000 --- a/packages/orm/typeorm/src/services/TypeORMService.ts +++ /dev/null @@ -1,36 +0,0 @@ -import {Inject, InjectorService, Service} from "@tsed/di"; -import {Connection, ConnectionManager, ConnectionOptions, getConnectionManager} from "typeorm"; -import {createConnection} from "../utils/createConnection.js"; - -@Service() -export class TypeORMService { - readonly connectionManager: ConnectionManager = getConnectionManager(); - - @Inject(InjectorService) - private injector: InjectorService; - - async createConnection(connectionOptions: ConnectionOptions): Promise { - const connection = await createConnection(connectionOptions); - this.injector.logger.info(`Connected with typeorm to database: ${connection.name}`); - - return connection; - } - - get(id: string = "default"): Connection { - return this.connectionManager.get(id); - } - - has(id: string = "default"): boolean { - return this.connectionManager.has(id); - } - - closeConnections(): Promise { - const promises = this.connectionManager.connections.map((instance) => { - if (instance.isConnected) { - return instance.close(); - } - }); - - return Promise.all(promises); - } -} diff --git a/packages/orm/typeorm/src/utils/createConnection.spec.ts b/packages/orm/typeorm/src/utils/createConnection.spec.ts deleted file mode 100644 index a5c09e34915..00000000000 --- a/packages/orm/typeorm/src/utils/createConnection.spec.ts +++ /dev/null @@ -1,67 +0,0 @@ -import {ConnectionManager, getConnectionManager} from "typeorm"; -import * as Connection from "typeorm/connection/Connection"; -import {createConnection} from "./createConnection.js"; - -vi.mock("typeorm", async (importOriginal) => { - const mod = await importOriginal(); - return { - ...mod, - getConnectionManager: vi.fn() - }; -}); - -function getConnectionFixture() { - const defaultConnection: any = { - name: "default", - isConnected: true, - connect: vi.fn().mockResolvedValue(undefined), - close: vi.fn() - }; - const customConnection: any = { - isConnected: true, - connect: vi.fn().mockResolvedValue(undefined), - close: vi.fn() - }; - - // create ConnectionManager - const connectionManager = new ConnectionManager(); - const connectionManagerCreateSpy = vi.spyOn(connectionManager, "create"); - - // replace - (getConnectionManager as any).mockReturnValue(connectionManager); - - // replace Connection constructor - const connectionStub = vi.spyOn(Connection, "Connection").mockImplementation((opts) => { - if (opts.name == null || opts.name === "default") { - return defaultConnection; - } else { - customConnection.name = opts.name; - return customConnection; - } - }); - - return { - connectionManager, - connectionManagerCreateSpy, - connectionStub, - defaultConnection, - customConnection - }; -} - -describe("createConnection", () => { - it("should create connection and return cache", async () => { - // GIVEN - const {customConnection, connectionManagerCreateSpy, defaultConnection} = getConnectionFixture(); - - // WHEN - const result1 = await createConnection({name: "mydb", type: "mysql"}); - const result2 = await createConnection({name: "mydb", type: "mysql"}); - - // THEN - expect(result1).toEqual(customConnection); - expect(result2).toEqual(customConnection); - expect(connectionManagerCreateSpy).toHaveBeenCalledWith({name: "mydb", type: "mysql"}); - expect(defaultConnection.connect).not.toHaveBeenCalled(); - }); -}); diff --git a/packages/orm/typeorm/src/utils/createConnection.ts b/packages/orm/typeorm/src/utils/createConnection.ts deleted file mode 100644 index 1e9c40a8dc0..00000000000 --- a/packages/orm/typeorm/src/utils/createConnection.ts +++ /dev/null @@ -1,20 +0,0 @@ -import {getValue} from "@tsed/core"; -import {Connection, ConnectionOptions, getConnectionManager} from "typeorm"; - -export async function createConnection(connectionOptions: ConnectionOptions): Promise { - const connectionManager = getConnectionManager(); - - const name = getValue(connectionOptions, "name", "default"); - - if (!connectionManager.has(name)) { - connectionManager.create({...connectionOptions, name}!); - } - - const connection = connectionManager.get(name); - - if (!connection.isConnected) { - await connection.connect(); - } - - return connection; -} diff --git a/packages/orm/typeorm/test/helpers/Server.ts b/packages/orm/typeorm/test/helpers/Server.ts deleted file mode 100644 index 15cb4f48817..00000000000 --- a/packages/orm/typeorm/test/helpers/Server.ts +++ /dev/null @@ -1,38 +0,0 @@ -import {Configuration, Inject, PlatformApplication} from "@tsed/common"; -import "@tsed/platform-express"; -import "@tsed/typeorm"; -import bodyParser from "body-parser"; -import compress from "compression"; -import cookieParser from "cookie-parser"; -import methodOverride from "method-override"; -import "./connections/ConnectionProvider"; - -const rootDir = __dirname; // automatically replaced by import.meta.dirname on build - -@Configuration({ - rootDir, - port: 8001, - httpsPort: false, - disableComponentScan: true, - logger: { - level: "info", - logRequest: true - } -}) -export class Server { - @Inject() - app: PlatformApplication; - - public $beforeRoutesInit(): void { - this.app - .use(bodyParser.json()) - .use( - bodyParser.urlencoded({ - extended: true - }) - ) - .use(cookieParser()) - .use(compress({})) - .use(methodOverride()); - } -} diff --git a/packages/orm/typeorm/test/helpers/connections/ConnectionProvider.ts b/packages/orm/typeorm/test/helpers/connections/ConnectionProvider.ts deleted file mode 100644 index 46848b15758..00000000000 --- a/packages/orm/typeorm/test/helpers/connections/ConnectionProvider.ts +++ /dev/null @@ -1,23 +0,0 @@ -import {Configuration, registerProvider} from "@tsed/di"; -import {createConnection} from "@tsed/typeorm"; -import {Connection, ConnectionOptions} from "typeorm"; - -export const CONNECTION = Symbol.for("CONNECTION"); // declare your own symbol -export type CONNECTION = Connection; // Set alias types (optional) - -const CONNECTION_NAME = "default"; // change the name according to your server configuration - -registerProvider({ - provide: CONNECTION, - deps: [Configuration], - useAsyncFactory(configuration: Configuration) { - const settings = configuration.get("typeorm")! || []; - const connectionOptions = settings.find((o) => o.name === CONNECTION_NAME); - - if (connectionOptions) { - return createConnection(connectionOptions!); - } - - return Promise.resolve({}); - } -}); diff --git a/packages/orm/typeorm/test/helpers/entity/User.ts b/packages/orm/typeorm/test/helpers/entity/User.ts deleted file mode 100644 index 46c75d2226e..00000000000 --- a/packages/orm/typeorm/test/helpers/entity/User.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {Property} from "@tsed/schema"; -import {Entity, PrimaryGeneratedColumn} from "typeorm"; - -@Entity() -export class User { - @PrimaryGeneratedColumn() - @Property() - id: number; -} diff --git a/packages/orm/typeorm/test/helpers/repository/UserRepository.ts b/packages/orm/typeorm/test/helpers/repository/UserRepository.ts deleted file mode 100644 index db279904aa7..00000000000 --- a/packages/orm/typeorm/test/helpers/repository/UserRepository.ts +++ /dev/null @@ -1,5 +0,0 @@ -import {EntityRepository, Repository} from "typeorm"; -import {User} from "../entity/User.js"; - -@EntityRepository(User) -export class UserRepository extends Repository {} diff --git a/packages/orm/typeorm/test/helpers/services/UserService.ts b/packages/orm/typeorm/test/helpers/services/UserService.ts deleted file mode 100644 index ac188bf552e..00000000000 --- a/packages/orm/typeorm/test/helpers/services/UserService.ts +++ /dev/null @@ -1,18 +0,0 @@ -import {Inject, Injectable} from "@tsed/di"; -import {UseConnection} from "../../../src/index.js"; -import {UserRepository} from "../repository/UserRepository.js"; - -@Injectable() -export class UserService { - @Inject() - repo2: UserRepository; - - @Inject() - @UseConnection("db2") - repo3: UserRepository; - - constructor( - @UseConnection("db2") public repo4: UserRepository, - public repo1: UserRepository - ) {} -} diff --git a/packages/orm/typeorm/test/integration.spec.ts b/packages/orm/typeorm/test/integration.spec.ts deleted file mode 100644 index 7bf1a11667e..00000000000 --- a/packages/orm/typeorm/test/integration.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import {PlatformTest} from "@tsed/common"; -import {TestMongooseContext} from "@tsed/testing-mongoose"; -import {User} from "./helpers/entity/User.js"; -import {UserRepository} from "./helpers/repository/UserRepository.js"; -import {Server} from "./helpers/Server.js"; -import {UserService} from "./helpers/services/UserService.js"; - -describe.skip("TypeORM integration", () => { - beforeEach(async () => { - await TestMongooseContext.install(); - const {url} = await TestMongooseContext.getMongooseOptions(); - const bstrp = PlatformTest.bootstrap(Server, { - disableComponentScan: true, - typeorm: [ - { - type: "mongodb", - url, - entities: [User], - useUnifiedTopology: true - }, - { - name: "db2", - type: "mongodb", - url, - entities: [User], - useUnifiedTopology: true - } - ] - }); - - await bstrp(); - }); - afterEach(TestMongooseContext.reset); - - it("should return repository", () => { - const service = PlatformTest.injector.get(UserService)!; - const repository = PlatformTest.injector.get(UserRepository); - - expect(!!repository).toBe(true); - expect(service).toBeInstanceOf(UserService); - expect(service.repo1).toBeInstanceOf(UserRepository); - expect(service.repo1.manager.connection.name).toBe("default"); - - expect(service.repo3).toBeInstanceOf(UserRepository); - expect(service.repo3.manager.connection.name).toBe("db2"); - expect(service.repo4).toBeInstanceOf(UserRepository); - expect(service.repo4.manager.connection.name).toBe("db2"); - - expect(service.repo2).toBeInstanceOf(UserRepository); - expect(service.repo2.manager.connection.name).toBe("default"); - }); -}); diff --git a/packages/orm/typeorm/tsconfig.cjs.json b/packages/orm/typeorm/tsconfig.cjs.json deleted file mode 100644 index 7f23b116d2b..00000000000 --- a/packages/orm/typeorm/tsconfig.cjs.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "extends": "@tsed/typescript/tsconfig.node.json", - "compilerOptions": { - "baseUrl": ".", - "module": "commonjs", - "moduleResolution": "Node16", - "rootDir": "src", - "outDir": "./lib/cjs", - "declaration": true, - "declarationDir": "./lib/types", - "composite": true, - "noEmit": false - }, - "include": ["src", "src/**/*.json"], - "exclude": [ - "node_modules", - "test", - "lib", - "benchmark", - "coverage", - "spec", - "**/*.benchmark.ts", - "**/*.spec.ts", - "keys", - "**/__mock__/**", - "webpack.config.js" - ] -} diff --git a/packages/orm/typeorm/tsconfig.esm.json b/packages/orm/typeorm/tsconfig.esm.json deleted file mode 100644 index ce32a9e0718..00000000000 --- a/packages/orm/typeorm/tsconfig.esm.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "extends": "@tsed/typescript/tsconfig.node.json", - "compilerOptions": { - "baseUrl": ".", - "module": "ESNext", - "moduleResolution": "nodenext", - "rootDir": "src", - "outDir": "./lib/esm", - "declarationDir": "./lib/types-esm", - "declaration": true, - "composite": true, - "noEmit": false - }, - "include": ["src", "src/**/*.json"], - "exclude": [ - "node_modules", - "test", - "lib", - "benchmark", - "coverage", - "spec", - "**/*.benchmark.ts", - "**/*.spec.ts", - "keys", - "**/__mock__/**", - "webpack.config.js" - ] -} diff --git a/packages/orm/typeorm/tsconfig.json b/packages/orm/typeorm/tsconfig.json deleted file mode 100644 index 0e0b63ab8f9..00000000000 --- a/packages/orm/typeorm/tsconfig.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "extends": "@tsed/typescript/tsconfig.node.json", - "compilerOptions": { - "baseUrl": ".", - "noEmit": true - }, - "include": [], - "references": [ - { - "path": "../../core/tsconfig.json" - }, - { - "path": "../../di/tsconfig.json" - }, - { - "path": "../../specs/json-mapper/tsconfig.json" - }, - { - "path": "../../specs/schema/tsconfig.json" - }, - { - "path": "./tsconfig.cjs.json" - }, - { - "path": "./tsconfig.esm.json" - }, - { - "path": "./tsconfig.spec.json" - } - ] -} diff --git a/packages/orm/typeorm/tsconfig.spec.json b/packages/orm/typeorm/tsconfig.spec.json deleted file mode 100644 index 21485bab96d..00000000000 --- a/packages/orm/typeorm/tsconfig.spec.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "extends": "@tsed/typescript/tsconfig.node.json", - "compilerOptions": { - "baseUrl": ".", - "rootDir": "../..", - "module": "commonjs", - "outDir": "./lib/cjs", - "declaration": false, - "composite": false, - "noEmit": true, - "paths": { - "@tsed/openspec": ["../../specs/openspec/src"], - "@tsed/schema": ["../../specs/schema/src"], - "@tsed/di": ["../../di/src"], - "@tsed/exceptions": ["../../specs/exceptions/src"], - "@tsed/json-mapper": ["../../specs/json-mapper/src"], - "@tsed/platform-exceptions": ["../../platform/platform-exceptions/src"], - "@tsed/platform-middlewares": ["../../platform/platform-middlewares/src"], - "@tsed/platform-params": ["../../platform/platform-params/src"], - "@tsed/platform-log-middleware": ["../../platform/platform-log-middleware/src"], - "@tsed/platform-response-filter": ["../../platform/platform-response-filter/src"], - "@tsed/platform-router": ["../../platform/platform-router/src"], - "@tsed/platform-views": ["../../platform/platform-views/src"], - "@tsed/components-scan": ["../../third-parties/components-scan/src"], - "@tsed/common": ["../../platform/common/src"], - "@tsed/ajv": ["../../specs/ajv/src"], - "@tsed/platform-cache": ["../../platform/platform-cache/src"], - "@tsed/swagger": ["../../specs/swagger/src"], - "@tsed/platform-test-sdk": ["../../platform/platform-test-sdk/src"], - "@tsed/platform-express": ["../../platform/platform-express/src"], - "@tsed/platform-koa": ["../../platform/platform-koa/src"] - }, - "types": ["vite/client", "vitest/globals"] - }, - "include": ["src/**/*.spec.ts", "test/**/*.spec.ts", "vitest.config.mts"], - "exclude": ["node_modules", "test", "lib", "benchmark", "coverage"] -} diff --git a/packages/orm/typeorm/vitest.config.mts b/packages/orm/typeorm/vitest.config.mts deleted file mode 100644 index d759e817941..00000000000 --- a/packages/orm/typeorm/vitest.config.mts +++ /dev/null @@ -1,21 +0,0 @@ -// @ts-ignore -import {presets} from "@tsed/vitest/presets"; -import {defineConfig} from "vitest/config"; - -export default defineConfig( - { - ...presets, - test: { - ...presets.test, - coverage: { - ...presets.test.coverage, - thresholds: { - statements: 0, - branches: 0, - functions: 0, - lines: 0 - } - } - } - } -);