typeorm 0.3.2 → 0.3.3-dev.a641c5d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
File without changes
@@ -434,10 +434,9 @@ export class DataSource {
434
434
  // validate all created entity metadatas to make sure user created entities are valid and correct
435
435
  entityMetadataValidator.validateMany(this.entityMetadatas.filter((metadata) => metadata.tableType !== "view"), this.driver);
436
436
  // set current data source to the entities
437
- for (let entityKey in flattenedEntities) {
438
- const entity = flattenedEntities[entityKey];
439
- if (InstanceChecker.isBaseEntityConstructor(entity)) {
440
- entity.useDataSource(this);
437
+ for (let entityMetadata of entityMetadatas) {
438
+ if (InstanceChecker.isBaseEntityConstructor(entityMetadata.target)) {
439
+ entityMetadata.target.useDataSource(this);
441
440
  }
442
441
  }
443
442
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/data-source/DataSource.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAChF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAA;AAKhG,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAA;AAElF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAIlE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAA;AAErF,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAA;AAC1G,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAA;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EA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ACvB,CAAA;QACD,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAA;QAEtD,yBAAyB;QACzB,MAAM,iBAAiB,GAAG,WAAW,CAAC,gBAAgB,CAClD,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAC9B,CAAA;QACD,MAAM,eAAe,GACjB,MAAM,yBAAyB,CAAC,oBAAoB,CAChD,iBAAiB,CACpB,CAAA;QACL,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAA;QAE9D,6BAA6B;QAC7B,MAAM,mBAAmB,GAAG,WAAW,CAAC,gBAAgB,CACpD,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAChC,CAAA;QACD,MAAM,UAAU,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAC9D,mBAAmB,CACtB,CAAA;QACD,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAA;QAEpD,iGAAiG;QACjG,uBAAuB,CAAC,YAAY,CAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CACvB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,KAAK,MAAM,CAC9C,EACD,IAAI,CAAC,MAAM,CACd,CAAA;QAED,0CAA0C;QAC1C,KAAK,IAAI,SAAS,IAAI,iBAAiB,EAAE;YACrC,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAA;YAC3C,IAAI,eAAe,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE;gBACjD,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;aAC7B;SACJ;IACL,CAAC;CACJ","file":"DataSource.js","sourcesContent":["import { Driver } from \"../driver/Driver\"\nimport { Repository } from \"../repository/Repository\"\nimport { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { ObjectType } from \"../common/ObjectType\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport { CannotExecuteNotConnectedError } from \"../error/CannotExecuteNotConnectedError\"\nimport { CannotConnectAlreadyConnectedError } from \"../error/CannotConnectAlreadyConnectedError\"\nimport { TreeRepository } from \"../repository/TreeRepository\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { Logger } from \"../logger/Logger\"\nimport { EntityMetadataNotFoundError } from \"../error/EntityMetadataNotFoundError\"\nimport { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport { Migration } from \"../migration/Migration\"\nimport { MongoRepository } from \"../repository/MongoRepository\"\nimport { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport { DataSourceOptions } from \"./DataSourceOptions\"\nimport { QueryRunnerProviderAlreadyReleasedError } from \"../error/QueryRunnerProviderAlreadyReleasedError\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error/TypeORMError\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * DataSource is a pre-defined connection configuration to a specific database.\n * You can have multiple data sources connected (with multiple connections in it),\n * connected to multiple databases in your application.\n *\n * Before, it was called `Connection`, but now `Connection` is deprecated\n * because `Connection` isn't the best name for what it's actually is.\n */\nexport class DataSource {\n readonly \"@instanceof\" = Symbol.for(\"DataSource\")\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n *\n * @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.\n */\n readonly name: string\n\n /**\n * Connection options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if DataSource is initialized or not.\n */\n readonly isInitialized: boolean\n\n /**\n * Database driver used by this connection.\n */\n driver: Driver\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager\n\n /**\n * Naming strategy used in the connection.\n */\n namingStrategy: NamingStrategyInterface\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string\n\n /**\n * Logger used to log orm events.\n */\n logger: Logger\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = []\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = []\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = []\n\n /**\n * Used to work with query result cache.\n */\n queryResultCache?: QueryResultCache\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader\n\n readonly relationIdLoader: RelationIdLoader\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: DataSourceOptions) {\n this.name = options.name || \"default\"\n this.options = options\n this.logger = new LoggerFactory().create(\n this.options.logger,\n this.options.logging,\n )\n this.driver = new DriverFactory().create(this)\n this.manager = this.createEntityManager()\n this.namingStrategy =\n options.namingStrategy || new DefaultNamingStrategy()\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\"\n this.queryResultCache = options.cache\n ? new QueryResultCacheFactory(this).create()\n : undefined\n this.relationLoader = new RelationLoader(this)\n this.relationIdLoader = new RelationIdLoader(this)\n this.isInitialized = false\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n Indicates if DataSource is initialized or not.\n *\n * @deprecated use .isInitialized instead\n */\n get isConnected() {\n return this.isInitialized\n }\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(\n `MongoEntityManager is only available for MongoDB databases.`,\n )\n\n return this.manager as MongoEntityManager\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!InstanceChecker.isSqljsEntityManager(this.manager))\n throw new TypeORMError(\n `SqljsEntityManager is only available for Sqljs databases.`,\n )\n\n return this.manager\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n /**\n * Updates current connection options with provided options.\n */\n setOptions(options: Partial<DataSourceOptions>): this {\n Object.assign(this.options, options)\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async initialize(): Promise<this> {\n if (this.isInitialized)\n throw new CannotConnectAlreadyConnectedError(this.name)\n\n // connect to the database via its driver\n await this.driver.connect()\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache) await this.queryResultCache.connect()\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isInitialized: true })\n\n try {\n // build all metadatas registered in the current connection\n await this.buildMetadatas()\n\n await this.driver.afterConnect()\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema) await this.dropDatabase()\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({\n transaction: this.options.migrationsTransactionMode,\n })\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize) await this.synchronize()\n } catch (error) {\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close()\n throw error\n }\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n *\n * @deprecated use .initialize method instead\n */\n async connect(): Promise<this> {\n return this.initialize()\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async destroy(): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n await this.driver.disconnect()\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache) await this.queryResultCache.disconnect()\n\n ObjectUtils.assign(this, { isInitialized: false })\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n *\n * @deprecated use .destroy method instead\n */\n async close(): Promise<void> {\n return this.destroy()\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n if (dropBeforeSync) await this.dropDatabase()\n\n const schemaBuilder = this.driver.createSchemaBuilder()\n await schemaBuilder.build()\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner()\n try {\n if (\n this.driver.options.type === \"mssql\" ||\n DriverUtils.isMySQLFamily(this.driver) ||\n this.driver.options.type === \"aurora-mysql\" ||\n DriverUtils.isSQLiteFamily(this.driver)\n ) {\n const databases: string[] = []\n this.entityMetadatas.forEach((metadata) => {\n if (\n metadata.database &&\n databases.indexOf(metadata.database) === -1\n )\n databases.push(metadata.database)\n })\n if (databases.length === 0 && this.driver.database) {\n databases.push(this.driver.database)\n }\n\n if (databases.length === 0) {\n await queryRunner.clearDatabase()\n } else {\n for (const database of databases) {\n await queryRunner.clearDatabase(database)\n }\n }\n } else {\n await queryRunner.clearDatabase()\n }\n } finally {\n await queryRunner.release()\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<Migration[]> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n const successMigrations =\n await migrationExecutor.executePendingMigrations()\n return successMigrations\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n await migrationExecutor.undoLastMigration()\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isInitialized) {\n throw new CannotExecuteNotConnectedError(this.name)\n }\n const migrationExecutor = new MigrationExecutor(this)\n return await migrationExecutor.showMigrations()\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target)\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target)\n if (!metadata) throw new EntityMetadataNotFoundError(target)\n\n return metadata\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {\n return this.manager.getRepository(target)\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity>(\n target: EntityTarget<Entity>,\n ): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target)\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity>(\n target: EntityTarget<Entity>,\n ): MongoRepository<Entity> {\n if (!(this.driver.options.type === \"mongodb\"))\n throw new TypeORMError(\n `You can use getMongoRepository only for MongoDB connections.`,\n )\n\n return this.manager.getRepository(target) as any\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository)\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationLevel: IsolationLevel,\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationOrRunInTransaction:\n | IsolationLevel\n | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>,\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any,\n )\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(\n query: string,\n parameters?: any[],\n queryRunner?: QueryRunner,\n ): Promise<any> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError()\n\n const usedQueryRunner = queryRunner || this.createQueryRunner()\n\n try {\n return await usedQueryRunner.query(query, parameters) // await is needed here because we are using finally\n } finally {\n if (!queryRunner) await usedQueryRunner.release()\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityClass: EntityTarget<Entity>,\n alias: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityOrRunner?: EntityTarget<Entity> | QueryRunner,\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`)\n\n if (alias) {\n alias = DriverUtils.buildAlias(this.driver, alias)\n const metadata = this.getMetadata(\n entityOrRunner as EntityTarget<Entity>,\n )\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias)\n } else {\n return new SelectQueryBuilder(\n this,\n entityOrRunner as QueryRunner | undefined,\n )\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode)\n const manager = this.createEntityManager(queryRunner)\n Object.assign(queryRunner, { manager: manager })\n return queryRunner\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(\n entityTarget: EntityTarget<any>,\n relationPropertyPath: string,\n ) {\n const relationMetadata =\n this.getMetadata(entityTarget).findRelationWithPropertyPath(\n relationPropertyPath,\n )\n if (!relationMetadata)\n throw new TypeORMError(\n `Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`,\n )\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(\n `Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`,\n )\n\n return relationMetadata.junctionEntityMetadata\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner)\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n return this.entityMetadatas.find((metadata) => {\n if (metadata.target === target) return true\n if (InstanceChecker.isEntitySchema(target)) {\n return metadata.name === target.options.name\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target\n } else {\n return (\n metadata.name === target ||\n metadata.tableName === target\n )\n }\n }\n if (\n ObjectUtils.isObject(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n return metadata.tablePath === target.name\n } else {\n return (\n metadata.name === target.name ||\n metadata.tableName === target.name\n )\n }\n }\n\n return false\n })\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this)\n const entityMetadataValidator = new EntityMetadataValidator()\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const flattenedSubscribers = ObjectUtils.mixedListToArray(\n this.options.subscribers || [],\n )\n const subscribers = await connectionMetadataBuilder.buildSubscribers(\n flattenedSubscribers,\n )\n ObjectUtils.assign(this, { subscribers: subscribers })\n\n // build entity metadatas\n const flattenedEntities = ObjectUtils.mixedListToArray(\n this.options.entities || [],\n )\n const entityMetadatas =\n await connectionMetadataBuilder.buildEntityMetadatas(\n flattenedEntities,\n )\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations || [],\n )\n const migrations = await connectionMetadataBuilder.buildMigrations(\n flattenedMigrations,\n )\n ObjectUtils.assign(this, { migrations: migrations })\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(\n this.entityMetadatas.filter(\n (metadata) => metadata.tableType !== \"view\",\n ),\n this.driver,\n )\n\n // set current data source to the entities\n for (let entityKey in flattenedEntities) {\n const entity = flattenedEntities[entityKey]\n if (InstanceChecker.isBaseEntityConstructor(entity)) {\n entity.useDataSource(this)\n }\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/data-source/DataSource.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAChF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAA;AAKhG,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAA;AAElF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAIlE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAA;AAErF,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAA;AAC1G,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAA;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO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AW,GAAG,MAAM,yBAAyB,CAAC,gBAAgB,CAChE,oBAAoB,CACvB,CAAA;QACD,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAA;QAEtD,yBAAyB;QACzB,MAAM,iBAAiB,GAAG,WAAW,CAAC,gBAAgB,CAClD,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAC9B,CAAA;QACD,MAAM,eAAe,GACjB,MAAM,yBAAyB,CAAC,oBAAoB,CAChD,iBAAiB,CACpB,CAAA;QACL,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAA;QAE9D,6BAA6B;QAC7B,MAAM,mBAAmB,GAAG,WAAW,CAAC,gBAAgB,CACpD,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAChC,CAAA;QACD,MAAM,UAAU,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAC9D,mBAAmB,CACtB,CAAA;QACD,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAA;QAEpD,iGAAiG;QACjG,uBAAuB,CAAC,YAAY,CAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CACvB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,KAAK,MAAM,CAC9C,EACD,IAAI,CAAC,MAAM,CACd,CAAA;QAED,0CAA0C;QAC1C,KAAK,IAAI,cAAc,IAAI,eAAe,EAAE;YACxC,IACI,eAAe,CAAC,uBAAuB,CAAC,cAAc,CAAC,MAAM,CAAC,EAChE;gBACE,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;aAC5C;SACJ;IACL,CAAC;CACJ","file":"DataSource.js","sourcesContent":["import { Driver } from \"../driver/Driver\"\nimport { Repository } from \"../repository/Repository\"\nimport { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { ObjectType } from \"../common/ObjectType\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport { CannotExecuteNotConnectedError } from \"../error/CannotExecuteNotConnectedError\"\nimport { CannotConnectAlreadyConnectedError } from \"../error/CannotConnectAlreadyConnectedError\"\nimport { TreeRepository } from \"../repository/TreeRepository\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { Logger } from \"../logger/Logger\"\nimport { EntityMetadataNotFoundError } from \"../error/EntityMetadataNotFoundError\"\nimport { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport { Migration } from \"../migration/Migration\"\nimport { MongoRepository } from \"../repository/MongoRepository\"\nimport { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport { DataSourceOptions } from \"./DataSourceOptions\"\nimport { QueryRunnerProviderAlreadyReleasedError } from \"../error/QueryRunnerProviderAlreadyReleasedError\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error/TypeORMError\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * DataSource is a pre-defined connection configuration to a specific database.\n * You can have multiple data sources connected (with multiple connections in it),\n * connected to multiple databases in your application.\n *\n * Before, it was called `Connection`, but now `Connection` is deprecated\n * because `Connection` isn't the best name for what it's actually is.\n */\nexport class DataSource {\n readonly \"@instanceof\" = Symbol.for(\"DataSource\")\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n *\n * @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.\n */\n readonly name: string\n\n /**\n * Connection options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if DataSource is initialized or not.\n */\n readonly isInitialized: boolean\n\n /**\n * Database driver used by this connection.\n */\n driver: Driver\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager\n\n /**\n * Naming strategy used in the connection.\n */\n namingStrategy: NamingStrategyInterface\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string\n\n /**\n * Logger used to log orm events.\n */\n logger: Logger\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = []\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = []\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = []\n\n /**\n * Used to work with query result cache.\n */\n queryResultCache?: QueryResultCache\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader\n\n readonly relationIdLoader: RelationIdLoader\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: DataSourceOptions) {\n this.name = options.name || \"default\"\n this.options = options\n this.logger = new LoggerFactory().create(\n this.options.logger,\n this.options.logging,\n )\n this.driver = new DriverFactory().create(this)\n this.manager = this.createEntityManager()\n this.namingStrategy =\n options.namingStrategy || new DefaultNamingStrategy()\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\"\n this.queryResultCache = options.cache\n ? new QueryResultCacheFactory(this).create()\n : undefined\n this.relationLoader = new RelationLoader(this)\n this.relationIdLoader = new RelationIdLoader(this)\n this.isInitialized = false\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n Indicates if DataSource is initialized or not.\n *\n * @deprecated use .isInitialized instead\n */\n get isConnected() {\n return this.isInitialized\n }\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(\n `MongoEntityManager is only available for MongoDB databases.`,\n )\n\n return this.manager as MongoEntityManager\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!InstanceChecker.isSqljsEntityManager(this.manager))\n throw new TypeORMError(\n `SqljsEntityManager is only available for Sqljs databases.`,\n )\n\n return this.manager\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n /**\n * Updates current connection options with provided options.\n */\n setOptions(options: Partial<DataSourceOptions>): this {\n Object.assign(this.options, options)\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async initialize(): Promise<this> {\n if (this.isInitialized)\n throw new CannotConnectAlreadyConnectedError(this.name)\n\n // connect to the database via its driver\n await this.driver.connect()\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache) await this.queryResultCache.connect()\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isInitialized: true })\n\n try {\n // build all metadatas registered in the current connection\n await this.buildMetadatas()\n\n await this.driver.afterConnect()\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema) await this.dropDatabase()\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({\n transaction: this.options.migrationsTransactionMode,\n })\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize) await this.synchronize()\n } catch (error) {\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close()\n throw error\n }\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n *\n * @deprecated use .initialize method instead\n */\n async connect(): Promise<this> {\n return this.initialize()\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async destroy(): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n await this.driver.disconnect()\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache) await this.queryResultCache.disconnect()\n\n ObjectUtils.assign(this, { isInitialized: false })\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n *\n * @deprecated use .destroy method instead\n */\n async close(): Promise<void> {\n return this.destroy()\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n if (dropBeforeSync) await this.dropDatabase()\n\n const schemaBuilder = this.driver.createSchemaBuilder()\n await schemaBuilder.build()\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner()\n try {\n if (\n this.driver.options.type === \"mssql\" ||\n DriverUtils.isMySQLFamily(this.driver) ||\n this.driver.options.type === \"aurora-mysql\" ||\n DriverUtils.isSQLiteFamily(this.driver)\n ) {\n const databases: string[] = []\n this.entityMetadatas.forEach((metadata) => {\n if (\n metadata.database &&\n databases.indexOf(metadata.database) === -1\n )\n databases.push(metadata.database)\n })\n if (databases.length === 0 && this.driver.database) {\n databases.push(this.driver.database)\n }\n\n if (databases.length === 0) {\n await queryRunner.clearDatabase()\n } else {\n for (const database of databases) {\n await queryRunner.clearDatabase(database)\n }\n }\n } else {\n await queryRunner.clearDatabase()\n }\n } finally {\n await queryRunner.release()\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<Migration[]> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n const successMigrations =\n await migrationExecutor.executePendingMigrations()\n return successMigrations\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n await migrationExecutor.undoLastMigration()\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isInitialized) {\n throw new CannotExecuteNotConnectedError(this.name)\n }\n const migrationExecutor = new MigrationExecutor(this)\n return await migrationExecutor.showMigrations()\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target)\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target)\n if (!metadata) throw new EntityMetadataNotFoundError(target)\n\n return metadata\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {\n return this.manager.getRepository(target)\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity>(\n target: EntityTarget<Entity>,\n ): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target)\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity>(\n target: EntityTarget<Entity>,\n ): MongoRepository<Entity> {\n if (!(this.driver.options.type === \"mongodb\"))\n throw new TypeORMError(\n `You can use getMongoRepository only for MongoDB connections.`,\n )\n\n return this.manager.getRepository(target) as any\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository)\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationLevel: IsolationLevel,\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationOrRunInTransaction:\n | IsolationLevel\n | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>,\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any,\n )\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(\n query: string,\n parameters?: any[],\n queryRunner?: QueryRunner,\n ): Promise<any> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError()\n\n const usedQueryRunner = queryRunner || this.createQueryRunner()\n\n try {\n return await usedQueryRunner.query(query, parameters) // await is needed here because we are using finally\n } finally {\n if (!queryRunner) await usedQueryRunner.release()\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityClass: EntityTarget<Entity>,\n alias: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityOrRunner?: EntityTarget<Entity> | QueryRunner,\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`)\n\n if (alias) {\n alias = DriverUtils.buildAlias(this.driver, alias)\n const metadata = this.getMetadata(\n entityOrRunner as EntityTarget<Entity>,\n )\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias)\n } else {\n return new SelectQueryBuilder(\n this,\n entityOrRunner as QueryRunner | undefined,\n )\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode)\n const manager = this.createEntityManager(queryRunner)\n Object.assign(queryRunner, { manager: manager })\n return queryRunner\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(\n entityTarget: EntityTarget<any>,\n relationPropertyPath: string,\n ) {\n const relationMetadata =\n this.getMetadata(entityTarget).findRelationWithPropertyPath(\n relationPropertyPath,\n )\n if (!relationMetadata)\n throw new TypeORMError(\n `Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`,\n )\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(\n `Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`,\n )\n\n return relationMetadata.junctionEntityMetadata\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner)\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n return this.entityMetadatas.find((metadata) => {\n if (metadata.target === target) return true\n if (InstanceChecker.isEntitySchema(target)) {\n return metadata.name === target.options.name\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target\n } else {\n return (\n metadata.name === target ||\n metadata.tableName === target\n )\n }\n }\n if (\n ObjectUtils.isObject(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n return metadata.tablePath === target.name\n } else {\n return (\n metadata.name === target.name ||\n metadata.tableName === target.name\n )\n }\n }\n\n return false\n })\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this)\n const entityMetadataValidator = new EntityMetadataValidator()\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const flattenedSubscribers = ObjectUtils.mixedListToArray(\n this.options.subscribers || [],\n )\n const subscribers = await connectionMetadataBuilder.buildSubscribers(\n flattenedSubscribers,\n )\n ObjectUtils.assign(this, { subscribers: subscribers })\n\n // build entity metadatas\n const flattenedEntities = ObjectUtils.mixedListToArray(\n this.options.entities || [],\n )\n const entityMetadatas =\n await connectionMetadataBuilder.buildEntityMetadatas(\n flattenedEntities,\n )\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations || [],\n )\n const migrations = await connectionMetadataBuilder.buildMigrations(\n flattenedMigrations,\n )\n ObjectUtils.assign(this, { migrations: migrations })\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(\n this.entityMetadatas.filter(\n (metadata) => metadata.tableType !== \"view\",\n ),\n this.driver,\n )\n\n // set current data source to the entities\n for (let entityMetadata of entityMetadatas) {\n if (\n InstanceChecker.isBaseEntityConstructor(entityMetadata.target)\n ) {\n entityMetadata.target.useDataSource(this)\n }\n }\n }\n}\n"],"sourceRoot":".."}
@@ -21,7 +21,7 @@ export declare class BaseEntity {
21
21
  /**
22
22
  * DataSource used in all static methods of the BaseEntity.
23
23
  */
24
- private static dataSource?;
24
+ private static dataSource;
25
25
  /**
26
26
  * Checks if entity has an id.
27
27
  * If entity composite compose ids, it will check them all.
@@ -51,7 +51,7 @@ export declare class BaseEntity {
51
51
  /**
52
52
  * Sets DataSource to be used by entity.
53
53
  */
54
- static useDataSource(dataSource: DataSource): void;
54
+ static useDataSource(dataSource: DataSource | null): void;
55
55
  /**
56
56
  * Gets current entity's Repository.
57
57
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAWnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,U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AEhB,OAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAElB,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAER,KAAa,EACb,UAAkB;QAElB,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n // @ts-ignore: Unused variable which is actually used\n private static dataSource?: DataSource\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const newestEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneOrFail(baseEntity.getId(this))\n\n ObjectUtils.assign(this, newestEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository() as Repository<T>\n return thisRepository.preload(entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAqB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAuB;QAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAkB,CAAA;IAC5E,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAqB;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,OAAqB;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC5D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACR,MAAM,UAAU,GAAG,IAA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,EAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAEZ,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,CAEd,EAAqC;QAErC,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAEhB,OAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAElB,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAER,KAAa,EACb,UAAkB;QAElB,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const newestEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneOrFail(baseEntity.getId(this))\n\n ObjectUtils.assign(this, newestEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository() as Repository<T>\n return thisRepository.preload(entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
File without changes
File without changes
package/cli.js CHANGED
File without changes
@@ -437,10 +437,9 @@ class DataSource {
437
437
  // validate all created entity metadatas to make sure user created entities are valid and correct
438
438
  entityMetadataValidator.validateMany(this.entityMetadatas.filter((metadata) => metadata.tableType !== "view"), this.driver);
439
439
  // set current data source to the entities
440
- for (let entityKey in flattenedEntities) {
441
- const entity = flattenedEntities[entityKey];
442
- if (InstanceChecker_1.InstanceChecker.isBaseEntityConstructor(entity)) {
443
- entity.useDataSource(this);
440
+ for (let entityMetadata of entityMetadatas) {
441
+ if (InstanceChecker_1.InstanceChecker.isBaseEntityConstructor(entityMetadata.target)) {
442
+ entityMetadata.target.useDataSource(this);
444
443
  }
445
444
  }
446
445
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data-source/DataSource.ts"],"names":[],"mappings":";;;AAMA,oFAAgF;AAChF,4FAAwF;AACxF,oGAAgG;AAKhG,sFAAkF;AAElF,sEAAkE;AAIlE,yFAAqF;AAErF,8GAA0G;AAC1G,iFAA6E;AAC7E,2DAAuD;AACvD,uFAAmF;AAEnF,4EAAwE;AACxE,2DAAuD;AACvD,8EAA0E;AAG1E,oEAAgE;AAChE,qDAAiD;AAGjD,wDAAoD;AACpD,wEAAoE;AACpE,uDAAmD;AACnD,6DAAyD;AAEzD;;;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EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAA;QAE9D,6BAA6B;QAC7B,MAAM,mBAAmB,GAAG,yBAAW,CAAC,gBAAgB,CACpD,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAChC,CAAA;QACD,MAAM,UAAU,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAC9D,mBAAmB,CACtB,CAAA;QACD,yBAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAA;QAEpD,iGAAiG;QACjG,uBAAuB,CAAC,YAAY,CAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CACvB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,KAAK,MAAM,CAC9C,EACD,IAAI,CAAC,MAAM,CACd,CAAA;QAED,0CAA0C;QAC1C,KAAK,IAAI,SAAS,IAAI,iBAAiB,EAAE;YACrC,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAA;YAC3C,IAAI,iCAAe,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE;gBACjD,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;aAC7B;SACJ;IACL,CAAC;CACJ;AAtnBD,gCAsnBC","file":"DataSource.js","sourcesContent":["import { Driver } from \"../driver/Driver\"\nimport { Repository } from \"../repository/Repository\"\nimport { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { ObjectType } from \"../common/ObjectType\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport { CannotExecuteNotConnectedError } from \"../error/CannotExecuteNotConnectedError\"\nimport { CannotConnectAlreadyConnectedError } from \"../error/CannotConnectAlreadyConnectedError\"\nimport { TreeRepository } from \"../repository/TreeRepository\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { Logger } from \"../logger/Logger\"\nimport { EntityMetadataNotFoundError } from \"../error/EntityMetadataNotFoundError\"\nimport { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport { Migration } from \"../migration/Migration\"\nimport { MongoRepository } from \"../repository/MongoRepository\"\nimport { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport { DataSourceOptions } from \"./DataSourceOptions\"\nimport { QueryRunnerProviderAlreadyReleasedError } from \"../error/QueryRunnerProviderAlreadyReleasedError\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error/TypeORMError\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * DataSource is a pre-defined connection configuration to a specific database.\n * You can have multiple data sources connected (with multiple connections in it),\n * connected to multiple databases in your application.\n *\n * Before, it was called `Connection`, but now `Connection` is deprecated\n * because `Connection` isn't the best name for what it's actually is.\n */\nexport class DataSource {\n readonly \"@instanceof\" = Symbol.for(\"DataSource\")\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n *\n * @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.\n */\n readonly name: string\n\n /**\n * Connection options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if DataSource is initialized or not.\n */\n readonly isInitialized: boolean\n\n /**\n * Database driver used by this connection.\n */\n driver: Driver\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager\n\n /**\n * Naming strategy used in the connection.\n */\n namingStrategy: NamingStrategyInterface\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string\n\n /**\n * Logger used to log orm events.\n */\n logger: Logger\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = []\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = []\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = []\n\n /**\n * Used to work with query result cache.\n */\n queryResultCache?: QueryResultCache\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader\n\n readonly relationIdLoader: RelationIdLoader\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: DataSourceOptions) {\n this.name = options.name || \"default\"\n this.options = options\n this.logger = new LoggerFactory().create(\n this.options.logger,\n this.options.logging,\n )\n this.driver = new DriverFactory().create(this)\n this.manager = this.createEntityManager()\n this.namingStrategy =\n options.namingStrategy || new DefaultNamingStrategy()\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\"\n this.queryResultCache = options.cache\n ? new QueryResultCacheFactory(this).create()\n : undefined\n this.relationLoader = new RelationLoader(this)\n this.relationIdLoader = new RelationIdLoader(this)\n this.isInitialized = false\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n Indicates if DataSource is initialized or not.\n *\n * @deprecated use .isInitialized instead\n */\n get isConnected() {\n return this.isInitialized\n }\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(\n `MongoEntityManager is only available for MongoDB databases.`,\n )\n\n return this.manager as MongoEntityManager\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!InstanceChecker.isSqljsEntityManager(this.manager))\n throw new TypeORMError(\n `SqljsEntityManager is only available for Sqljs databases.`,\n )\n\n return this.manager\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n /**\n * Updates current connection options with provided options.\n */\n setOptions(options: Partial<DataSourceOptions>): this {\n Object.assign(this.options, options)\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async initialize(): Promise<this> {\n if (this.isInitialized)\n throw new CannotConnectAlreadyConnectedError(this.name)\n\n // connect to the database via its driver\n await this.driver.connect()\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache) await this.queryResultCache.connect()\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isInitialized: true })\n\n try {\n // build all metadatas registered in the current connection\n await this.buildMetadatas()\n\n await this.driver.afterConnect()\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema) await this.dropDatabase()\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({\n transaction: this.options.migrationsTransactionMode,\n })\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize) await this.synchronize()\n } catch (error) {\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close()\n throw error\n }\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n *\n * @deprecated use .initialize method instead\n */\n async connect(): Promise<this> {\n return this.initialize()\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async destroy(): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n await this.driver.disconnect()\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache) await this.queryResultCache.disconnect()\n\n ObjectUtils.assign(this, { isInitialized: false })\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n *\n * @deprecated use .destroy method instead\n */\n async close(): Promise<void> {\n return this.destroy()\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n if (dropBeforeSync) await this.dropDatabase()\n\n const schemaBuilder = this.driver.createSchemaBuilder()\n await schemaBuilder.build()\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner()\n try {\n if (\n this.driver.options.type === \"mssql\" ||\n DriverUtils.isMySQLFamily(this.driver) ||\n this.driver.options.type === \"aurora-mysql\" ||\n DriverUtils.isSQLiteFamily(this.driver)\n ) {\n const databases: string[] = []\n this.entityMetadatas.forEach((metadata) => {\n if (\n metadata.database &&\n databases.indexOf(metadata.database) === -1\n )\n databases.push(metadata.database)\n })\n if (databases.length === 0 && this.driver.database) {\n databases.push(this.driver.database)\n }\n\n if (databases.length === 0) {\n await queryRunner.clearDatabase()\n } else {\n for (const database of databases) {\n await queryRunner.clearDatabase(database)\n }\n }\n } else {\n await queryRunner.clearDatabase()\n }\n } finally {\n await queryRunner.release()\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<Migration[]> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n const successMigrations =\n await migrationExecutor.executePendingMigrations()\n return successMigrations\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n await migrationExecutor.undoLastMigration()\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isInitialized) {\n throw new CannotExecuteNotConnectedError(this.name)\n }\n const migrationExecutor = new MigrationExecutor(this)\n return await migrationExecutor.showMigrations()\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target)\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target)\n if (!metadata) throw new EntityMetadataNotFoundError(target)\n\n return metadata\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {\n return this.manager.getRepository(target)\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity>(\n target: EntityTarget<Entity>,\n ): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target)\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity>(\n target: EntityTarget<Entity>,\n ): MongoRepository<Entity> {\n if (!(this.driver.options.type === \"mongodb\"))\n throw new TypeORMError(\n `You can use getMongoRepository only for MongoDB connections.`,\n )\n\n return this.manager.getRepository(target) as any\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository)\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationLevel: IsolationLevel,\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationOrRunInTransaction:\n | IsolationLevel\n | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>,\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any,\n )\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(\n query: string,\n parameters?: any[],\n queryRunner?: QueryRunner,\n ): Promise<any> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError()\n\n const usedQueryRunner = queryRunner || this.createQueryRunner()\n\n try {\n return await usedQueryRunner.query(query, parameters) // await is needed here because we are using finally\n } finally {\n if (!queryRunner) await usedQueryRunner.release()\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityClass: EntityTarget<Entity>,\n alias: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityOrRunner?: EntityTarget<Entity> | QueryRunner,\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`)\n\n if (alias) {\n alias = DriverUtils.buildAlias(this.driver, alias)\n const metadata = this.getMetadata(\n entityOrRunner as EntityTarget<Entity>,\n )\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias)\n } else {\n return new SelectQueryBuilder(\n this,\n entityOrRunner as QueryRunner | undefined,\n )\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode)\n const manager = this.createEntityManager(queryRunner)\n Object.assign(queryRunner, { manager: manager })\n return queryRunner\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(\n entityTarget: EntityTarget<any>,\n relationPropertyPath: string,\n ) {\n const relationMetadata =\n this.getMetadata(entityTarget).findRelationWithPropertyPath(\n relationPropertyPath,\n )\n if (!relationMetadata)\n throw new TypeORMError(\n `Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`,\n )\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(\n `Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`,\n )\n\n return relationMetadata.junctionEntityMetadata\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner)\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n return this.entityMetadatas.find((metadata) => {\n if (metadata.target === target) return true\n if (InstanceChecker.isEntitySchema(target)) {\n return metadata.name === target.options.name\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target\n } else {\n return (\n metadata.name === target ||\n metadata.tableName === target\n )\n }\n }\n if (\n ObjectUtils.isObject(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n return metadata.tablePath === target.name\n } else {\n return (\n metadata.name === target.name ||\n metadata.tableName === target.name\n )\n }\n }\n\n return false\n })\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this)\n const entityMetadataValidator = new EntityMetadataValidator()\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const flattenedSubscribers = ObjectUtils.mixedListToArray(\n this.options.subscribers || [],\n )\n const subscribers = await connectionMetadataBuilder.buildSubscribers(\n flattenedSubscribers,\n )\n ObjectUtils.assign(this, { subscribers: subscribers })\n\n // build entity metadatas\n const flattenedEntities = ObjectUtils.mixedListToArray(\n this.options.entities || [],\n )\n const entityMetadatas =\n await connectionMetadataBuilder.buildEntityMetadatas(\n flattenedEntities,\n )\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations || [],\n )\n const migrations = await connectionMetadataBuilder.buildMigrations(\n flattenedMigrations,\n )\n ObjectUtils.assign(this, { migrations: migrations })\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(\n this.entityMetadatas.filter(\n (metadata) => metadata.tableType !== \"view\",\n ),\n this.driver,\n )\n\n // set current data source to the entities\n for (let entityKey in flattenedEntities) {\n const entity = flattenedEntities[entityKey]\n if (InstanceChecker.isBaseEntityConstructor(entity)) {\n entity.useDataSource(this)\n }\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/data-source/DataSource.ts"],"names":[],"mappings":";;;AAMA,oFAAgF;AAChF,4FAAwF;AACxF,oGAAgG;AAKhG,sFAAkF;AAElF,sEAAkE;AAIlE,yFAAqF;AAErF,8GAA0G;AAC1G,iFAA6E;AAC7E,2DAAuD;AACvD,uFAAmF;AAEnF,4EAAwE;AACxE,2DAAuD;AACvD,8EAA0E;AAG1E,oEAAgE;AAChE,qDAAiD;AAGjD,wDAAoD;AACpD,wEAAoE;AACpE,uDAAmD;AACnD,6DAAyD;AAEzD;;;;;;;GAOG;AACH,MAAa,UAAU;IA4EnB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,OAA0B;QA/E7B,mBAAa,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAgDjD;;WAEG;QACM,eAAU,GAAyB,EAAE,CAAA;QAE9C;;WAEG;QACM,gBAAW,GAAqC,EAAE,CAAA;QAE3D;;WAEG;QACM,oBAAe,GAAqB,EAAE,CAAA;QAmB3C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAAA;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,EAAE,CAAC,MAAM,CACpC,IAAI,CAAC,OAAO,CAAC,MAAM,EACnB,IAAI,CAAC,OAAO,CAAC,OAAO,CACvB,CAAA;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,EAAE,CAAC,MAAM,CAAC,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C,cAAc,CAAC,MAAM,CAAC,EAChE;gBACE,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;aAC5C;SACJ;IACL,CAAC;CACJ;AAvnBD,gCAunBC","file":"DataSource.js","sourcesContent":["import { Driver } from \"../driver/Driver\"\nimport { Repository } from \"../repository/Repository\"\nimport { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { ObjectType } from \"../common/ObjectType\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport { CannotExecuteNotConnectedError } from \"../error/CannotExecuteNotConnectedError\"\nimport { CannotConnectAlreadyConnectedError } from \"../error/CannotConnectAlreadyConnectedError\"\nimport { TreeRepository } from \"../repository/TreeRepository\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { Logger } from \"../logger/Logger\"\nimport { EntityMetadataNotFoundError } from \"../error/EntityMetadataNotFoundError\"\nimport { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport { Migration } from \"../migration/Migration\"\nimport { MongoRepository } from \"../repository/MongoRepository\"\nimport { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport { DataSourceOptions } from \"./DataSourceOptions\"\nimport { QueryRunnerProviderAlreadyReleasedError } from \"../error/QueryRunnerProviderAlreadyReleasedError\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error/TypeORMError\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * DataSource is a pre-defined connection configuration to a specific database.\n * You can have multiple data sources connected (with multiple connections in it),\n * connected to multiple databases in your application.\n *\n * Before, it was called `Connection`, but now `Connection` is deprecated\n * because `Connection` isn't the best name for what it's actually is.\n */\nexport class DataSource {\n readonly \"@instanceof\" = Symbol.for(\"DataSource\")\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n *\n * @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.\n */\n readonly name: string\n\n /**\n * Connection options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if DataSource is initialized or not.\n */\n readonly isInitialized: boolean\n\n /**\n * Database driver used by this connection.\n */\n driver: Driver\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager\n\n /**\n * Naming strategy used in the connection.\n */\n namingStrategy: NamingStrategyInterface\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string\n\n /**\n * Logger used to log orm events.\n */\n logger: Logger\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = []\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = []\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = []\n\n /**\n * Used to work with query result cache.\n */\n queryResultCache?: QueryResultCache\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader\n\n readonly relationIdLoader: RelationIdLoader\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: DataSourceOptions) {\n this.name = options.name || \"default\"\n this.options = options\n this.logger = new LoggerFactory().create(\n this.options.logger,\n this.options.logging,\n )\n this.driver = new DriverFactory().create(this)\n this.manager = this.createEntityManager()\n this.namingStrategy =\n options.namingStrategy || new DefaultNamingStrategy()\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\"\n this.queryResultCache = options.cache\n ? new QueryResultCacheFactory(this).create()\n : undefined\n this.relationLoader = new RelationLoader(this)\n this.relationIdLoader = new RelationIdLoader(this)\n this.isInitialized = false\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n Indicates if DataSource is initialized or not.\n *\n * @deprecated use .isInitialized instead\n */\n get isConnected() {\n return this.isInitialized\n }\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(\n `MongoEntityManager is only available for MongoDB databases.`,\n )\n\n return this.manager as MongoEntityManager\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!InstanceChecker.isSqljsEntityManager(this.manager))\n throw new TypeORMError(\n `SqljsEntityManager is only available for Sqljs databases.`,\n )\n\n return this.manager\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n /**\n * Updates current connection options with provided options.\n */\n setOptions(options: Partial<DataSourceOptions>): this {\n Object.assign(this.options, options)\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async initialize(): Promise<this> {\n if (this.isInitialized)\n throw new CannotConnectAlreadyConnectedError(this.name)\n\n // connect to the database via its driver\n await this.driver.connect()\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache) await this.queryResultCache.connect()\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isInitialized: true })\n\n try {\n // build all metadatas registered in the current connection\n await this.buildMetadatas()\n\n await this.driver.afterConnect()\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema) await this.dropDatabase()\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({\n transaction: this.options.migrationsTransactionMode,\n })\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize) await this.synchronize()\n } catch (error) {\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close()\n throw error\n }\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n *\n * @deprecated use .initialize method instead\n */\n async connect(): Promise<this> {\n return this.initialize()\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async destroy(): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n await this.driver.disconnect()\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache) await this.queryResultCache.disconnect()\n\n ObjectUtils.assign(this, { isInitialized: false })\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n *\n * @deprecated use .destroy method instead\n */\n async close(): Promise<void> {\n return this.destroy()\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n if (dropBeforeSync) await this.dropDatabase()\n\n const schemaBuilder = this.driver.createSchemaBuilder()\n await schemaBuilder.build()\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner()\n try {\n if (\n this.driver.options.type === \"mssql\" ||\n DriverUtils.isMySQLFamily(this.driver) ||\n this.driver.options.type === \"aurora-mysql\" ||\n DriverUtils.isSQLiteFamily(this.driver)\n ) {\n const databases: string[] = []\n this.entityMetadatas.forEach((metadata) => {\n if (\n metadata.database &&\n databases.indexOf(metadata.database) === -1\n )\n databases.push(metadata.database)\n })\n if (databases.length === 0 && this.driver.database) {\n databases.push(this.driver.database)\n }\n\n if (databases.length === 0) {\n await queryRunner.clearDatabase()\n } else {\n for (const database of databases) {\n await queryRunner.clearDatabase(database)\n }\n }\n } else {\n await queryRunner.clearDatabase()\n }\n } finally {\n await queryRunner.release()\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<Migration[]> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n const successMigrations =\n await migrationExecutor.executePendingMigrations()\n return successMigrations\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n }): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n\n await migrationExecutor.undoLastMigration()\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isInitialized) {\n throw new CannotExecuteNotConnectedError(this.name)\n }\n const migrationExecutor = new MigrationExecutor(this)\n return await migrationExecutor.showMigrations()\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target)\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target)\n if (!metadata) throw new EntityMetadataNotFoundError(target)\n\n return metadata\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {\n return this.manager.getRepository(target)\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity>(\n target: EntityTarget<Entity>,\n ): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target)\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity>(\n target: EntityTarget<Entity>,\n ): MongoRepository<Entity> {\n if (!(this.driver.options.type === \"mongodb\"))\n throw new TypeORMError(\n `You can use getMongoRepository only for MongoDB connections.`,\n )\n\n return this.manager.getRepository(target) as any\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository)\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationLevel: IsolationLevel,\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationOrRunInTransaction:\n | IsolationLevel\n | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>,\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any,\n )\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(\n query: string,\n parameters?: any[],\n queryRunner?: QueryRunner,\n ): Promise<any> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError()\n\n const usedQueryRunner = queryRunner || this.createQueryRunner()\n\n try {\n return await usedQueryRunner.query(query, parameters) // await is needed here because we are using finally\n } finally {\n if (!queryRunner) await usedQueryRunner.release()\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityClass: EntityTarget<Entity>,\n alias: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(\n entityOrRunner?: EntityTarget<Entity> | QueryRunner,\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`)\n\n if (alias) {\n alias = DriverUtils.buildAlias(this.driver, alias)\n const metadata = this.getMetadata(\n entityOrRunner as EntityTarget<Entity>,\n )\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias)\n } else {\n return new SelectQueryBuilder(\n this,\n entityOrRunner as QueryRunner | undefined,\n )\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode)\n const manager = this.createEntityManager(queryRunner)\n Object.assign(queryRunner, { manager: manager })\n return queryRunner\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(\n entityTarget: EntityTarget<any>,\n relationPropertyPath: string,\n ) {\n const relationMetadata =\n this.getMetadata(entityTarget).findRelationWithPropertyPath(\n relationPropertyPath,\n )\n if (!relationMetadata)\n throw new TypeORMError(\n `Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`,\n )\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(\n `Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`,\n )\n\n return relationMetadata.junctionEntityMetadata\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner)\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n return this.entityMetadatas.find((metadata) => {\n if (metadata.target === target) return true\n if (InstanceChecker.isEntitySchema(target)) {\n return metadata.name === target.options.name\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target\n } else {\n return (\n metadata.name === target ||\n metadata.tableName === target\n )\n }\n }\n if (\n ObjectUtils.isObject(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n return metadata.tablePath === target.name\n } else {\n return (\n metadata.name === target.name ||\n metadata.tableName === target.name\n )\n }\n }\n\n return false\n })\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this)\n const entityMetadataValidator = new EntityMetadataValidator()\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const flattenedSubscribers = ObjectUtils.mixedListToArray(\n this.options.subscribers || [],\n )\n const subscribers = await connectionMetadataBuilder.buildSubscribers(\n flattenedSubscribers,\n )\n ObjectUtils.assign(this, { subscribers: subscribers })\n\n // build entity metadatas\n const flattenedEntities = ObjectUtils.mixedListToArray(\n this.options.entities || [],\n )\n const entityMetadatas =\n await connectionMetadataBuilder.buildEntityMetadatas(\n flattenedEntities,\n )\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations || [],\n )\n const migrations = await connectionMetadataBuilder.buildMigrations(\n flattenedMigrations,\n )\n ObjectUtils.assign(this, { migrations: migrations })\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(\n this.entityMetadatas.filter(\n (metadata) => metadata.tableType !== \"view\",\n ),\n this.driver,\n )\n\n // set current data source to the entities\n for (let entityMetadata of entityMetadatas) {\n if (\n InstanceChecker.isBaseEntityConstructor(entityMetadata.target)\n ) {\n entityMetadata.target.useDataSource(this)\n }\n }\n }\n}\n"],"sourceRoot":".."}
package/package.json CHANGED
@@ -1,261 +1 @@
1
- {
2
- "name": "typeorm",
3
- "private": false,
4
- "version": "0.3.2",
5
- "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.",
6
- "license": "MIT",
7
- "readmeFilename": "README.md",
8
- "author": {
9
- "name": "Umed Khudoiberdiev",
10
- "email": "pleerock.me@gmail.com"
11
- },
12
- "engines": {
13
- "node": ">= 12.9.0"
14
- },
15
- "exports": {
16
- ".": {
17
- "node": {
18
- "import": "./index.mjs",
19
- "require": "./index.js"
20
- },
21
- "browser": {
22
- "require": "./index.js",
23
- "import": "./browser/index.js",
24
- "default": "./index.js"
25
- }
26
- },
27
- "./browser": "./browser/index.js",
28
- "./*.js": "./*.js",
29
- "./*": {
30
- "require": "./*.js",
31
- "import": "./*"
32
- }
33
- },
34
- "main": "./index.js",
35
- "module": "./index.mjs",
36
- "types": "./index.d.ts",
37
- "browser": {
38
- "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js",
39
- "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js",
40
- "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js",
41
- "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
42
- "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
43
- "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
44
- "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
45
- "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js",
46
- "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
47
- "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
48
- "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
49
- "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
50
- "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
51
- "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js",
52
- "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js",
53
- "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js",
54
- "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js",
55
- "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js",
56
- "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js",
57
- "./index.js": "./browser/index.js",
58
- "./index.mjs": "./browser/index.js"
59
- },
60
- "repository": {
61
- "type": "git",
62
- "url": "https://github.com/typeorm/typeorm.git"
63
- },
64
- "bugs": {
65
- "url": "https://github.com/typeorm/typeorm/issues"
66
- },
67
- "tags": [
68
- "orm",
69
- "typescript",
70
- "typescript-orm",
71
- "mysql",
72
- "mysql-orm",
73
- "postgresql",
74
- "postgresql-orm",
75
- "mariadb",
76
- "mariadb-orm",
77
- "sqlite",
78
- "sqlite-orm",
79
- "sql-server",
80
- "sql-server-orm",
81
- "oracle",
82
- "oracle-orm"
83
- ],
84
- "devDependencies": {
85
- "@types/app-root-path": "^1.2.4",
86
- "@types/chai": "^4.2.15",
87
- "@types/chai-as-promised": "^7.1.3",
88
- "@types/debug": "^4.1.5",
89
- "@types/js-yaml": "^4.0.0",
90
- "@types/mkdirp": "^1.0.1",
91
- "@types/mocha": "^8.2.1",
92
- "@types/node": "^14.14.31",
93
- "@types/rimraf": "^3.0.0",
94
- "@types/sha.js": "^2.4.0",
95
- "@types/sinon": "^9.0.10",
96
- "@types/source-map-support": "^0.5.3",
97
- "@types/uuid": "^8.3.4",
98
- "@types/xml2js": "^0.4.8",
99
- "@types/yargs": "^17.0.2",
100
- "better-sqlite3": "^7.1.2",
101
- "chai": "^4.3.0",
102
- "chai-as-promised": "^7.1.1",
103
- "class-transformer": "^0.4.0",
104
- "conventional-changelog-angular": "^5.0.12",
105
- "conventional-changelog-cli": "^2.1.1",
106
- "del": "^6.0.0",
107
- "gulp": "^4.0.2",
108
- "gulp-istanbul": "^1.1.3",
109
- "gulp-mocha": "^8.0.0",
110
- "gulp-rename": "^2.0.0",
111
- "gulp-replace": "^1.0.0",
112
- "gulp-shell": "^0.8.0",
113
- "gulp-sourcemaps": "^3.0.0",
114
- "gulp-typescript": "^6.0.0-alpha.1",
115
- "gulpclass": "^0.2.0",
116
- "husky": "^5.1.1",
117
- "mocha": "^8.3.0",
118
- "mongodb": "^3.6.4",
119
- "mssql": "^7.3.0",
120
- "mysql": "^2.18.1",
121
- "mysql2": "^2.2.5",
122
- "pg": "^8.5.1",
123
- "pg-query-stream": "^4.0.0",
124
- "redis": "^3.1.1",
125
- "remap-istanbul": "^0.13.0",
126
- "rimraf": "^3.0.2",
127
- "sinon": "^9.2.4",
128
- "sinon-chai": "^3.5.0",
129
- "source-map-support": "^0.5.19",
130
- "sql.js": "^1.4.0",
131
- "sqlite3": "^5.0.2",
132
- "ts-node": "^10.7.0",
133
- "typeorm-aurora-data-api-driver": "^2.0.0",
134
- "typescript": "^4.6.2",
135
- "prettier": "^2.5.1"
136
- },
137
- "peerDependencies": {
138
- "@sap/hana-client": "^2.11.14",
139
- "better-sqlite3": "^7.1.2",
140
- "hdb-pool": "^0.1.6",
141
- "ioredis": "^4.28.3",
142
- "mongodb": "^3.6.0",
143
- "mssql": "^6.3.1",
144
- "mysql2": "^2.2.5",
145
- "oracledb": "^5.1.0",
146
- "pg": "^8.5.1",
147
- "pg-native": "^3.0.0",
148
- "pg-query-stream": "^4.0.0",
149
- "redis": "^3.1.1",
150
- "sql.js": "^1.4.0",
151
- "sqlite3": "^5.0.2",
152
- "ts-node": "^10.7.0",
153
- "typeorm-aurora-data-api-driver": "^2.0.0"
154
- },
155
- "peerDependenciesMeta": {
156
- "@sap/hana-client": {
157
- "optional": true
158
- },
159
- "better-sqlite3": {
160
- "optional": true
161
- },
162
- "hdb-pool": {
163
- "optional": true
164
- },
165
- "ioredis": {
166
- "optional": true
167
- },
168
- "mongodb": {
169
- "optional": true
170
- },
171
- "mssql": {
172
- "optional": true
173
- },
174
- "mysql2": {
175
- "optional": true
176
- },
177
- "oracledb": {
178
- "optional": true
179
- },
180
- "pg": {
181
- "optional": true
182
- },
183
- "pg-native": {
184
- "optional": true
185
- },
186
- "pg-query-stream": {
187
- "optional": true
188
- },
189
- "redis": {
190
- "optional": true
191
- },
192
- "sql.js": {
193
- "optional": true
194
- },
195
- "sqlite3": {
196
- "optional": true
197
- },
198
- "ts-node": {
199
- "optional": true
200
- },
201
- "typeorm-aurora-data-api-driver": {
202
- "optional": true
203
- }
204
- },
205
- "dependencies": {
206
- "@sqltools/formatter": "^1.2.2",
207
- "app-root-path": "^3.0.0",
208
- "buffer": "^6.0.3",
209
- "chalk": "^4.1.0",
210
- "cli-highlight": "^2.1.11",
211
- "debug": "^4.3.3",
212
- "dotenv": "^16.0.0",
213
- "glob": "^7.2.0",
214
- "js-yaml": "^4.1.0",
215
- "mkdirp": "^1.0.4",
216
- "reflect-metadata": "^0.1.13",
217
- "sha.js": "^2.4.11",
218
- "tslib": "^2.3.1",
219
- "uuid": "^8.3.2",
220
- "xml2js": "^0.4.23",
221
- "yargs": "^17.3.1",
222
- "date-fns": "^2.28.0"
223
- },
224
- "scripts": {
225
- "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test",
226
- "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test",
227
- "compile": "rimraf ./build && tsc",
228
- "watch": "./node_modules/.bin/tsc -w",
229
- "package": "gulp package",
230
- "pack": "gulp pack",
231
- "lint": "prettier --check \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"",
232
- "format": "prettier --write \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"",
233
- "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2"
234
- },
235
- "bin": {
236
- "typeorm": "./cli.js",
237
- "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js",
238
- "typeorm-ts-node-esm": "./cli-ts-node-esm.js"
239
- },
240
- "funding": "https://opencollective.com/typeorm",
241
- "collective": {
242
- "type": "opencollective",
243
- "url": "https://opencollective.com/typeorm",
244
- "logo": "https://opencollective.com/opencollective/logo.txt"
245
- },
246
- "nyc": {
247
- "all": true,
248
- "cache": false,
249
- "exclude": [
250
- "**/*.d.ts"
251
- ],
252
- "extension": [
253
- ".ts"
254
- ],
255
- "include": [
256
- "build/compiled/src/**",
257
- "src/**"
258
- ],
259
- "reporter": "json"
260
- }
261
- }
1
+ { "name": "typeorm", "private": false, "version": "0.3.3-dev.a641c5d", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "engines": { "node": ">= 12.9.0" }, "exports": { ".": { "node": { "import": "./index.mjs", "require": "./index.js" }, "browser": { "require": "./index.js", "import": "./browser/index.js", "default": "./index.js" } }, "./browser": "./browser/index.js", "./*.js": "./*.js", "./*": { "require": "./*.js", "import": "./*" } }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "browser": { "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./index.js": "./browser/index.js", "./index.mjs": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm" ], "devDependencies": { "@types/app-root-path": "^1.2.4", "@types/chai": "^4.2.15", "@types/chai-as-promised": "^7.1.3", "@types/debug": "^4.1.5", "@types/js-yaml": "^4.0.0", "@types/mkdirp": "^1.0.1", "@types/mocha": "^8.2.1", "@types/node": "^14.14.31", "@types/rimraf": "^3.0.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^9.0.10", "@types/source-map-support": "^0.5.3", "@types/uuid": "^8.3.4", "@types/xml2js": "^0.4.8", "@types/yargs": "^17.0.2", "better-sqlite3": "^7.1.2", "chai": "^4.3.0", "chai-as-promised": "^7.1.1", "class-transformer": "^0.4.0", "conventional-changelog-angular": "^5.0.12", "conventional-changelog-cli": "^2.1.1", "del": "^6.0.0", "gulp": "^4.0.2", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^8.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.0.0", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^5.1.1", "mocha": "^8.3.0", "mongodb": "^3.6.4", "mssql": "^7.3.0", "mysql": "^2.18.1", "mysql2": "^2.2.5", "pg": "^8.5.1", "pg-query-stream": "^4.0.0", "redis": "^3.1.1", "remap-istanbul": "^0.13.0", "rimraf": "^3.0.2", "sinon": "^9.2.4", "sinon-chai": "^3.5.0", "source-map-support": "^0.5.19", "sql.js": "^1.4.0", "sqlite3": "^5.0.2", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0", "typescript": "^4.6.2", "prettier": "^2.5.1" }, "peerDependencies": { "@sap/hana-client": "^2.11.14", "better-sqlite3": "^7.1.2", "hdb-pool": "^0.1.6", "ioredis": "^4.28.3", "mongodb": "^3.6.0", "mssql": "^6.3.1", "mysql2": "^2.2.5", "oracledb": "^5.1.0", "pg": "^8.5.1", "pg-native": "^3.0.0", "pg-query-stream": "^4.0.0", "redis": "^3.1.1", "sql.js": "^1.4.0", "sqlite3": "^5.0.2", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0" }, "peerDependenciesMeta": { "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "ts-node": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.2", "app-root-path": "^3.0.0", "buffer": "^6.0.3", "chalk": "^4.1.0", "cli-highlight": "^2.1.11", "debug": "^4.3.3", "dotenv": "^16.0.0", "glob": "^7.2.0", "js-yaml": "^4.1.0", "mkdirp": "^1.0.4", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.3.1", "uuid": "^8.3.2", "xml2js": "^0.4.23", "yargs": "^17.3.1", "date-fns": "^2.28.0" }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "prettier --check \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "format": "prettier --write \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js", "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js", "typeorm-ts-node-esm": "./cli-ts-node-esm.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" }, "nyc": { "all": true, "cache": false, "exclude": [ "**/*.d.ts" ], "extension": [ ".ts" ], "include": [ "build/compiled/src/**", "src/**" ], "reporter": "json" } }
@@ -21,7 +21,7 @@ export declare class BaseEntity {
21
21
  /**
22
22
  * DataSource used in all static methods of the BaseEntity.
23
23
  */
24
- private static dataSource?;
24
+ private static dataSource;
25
25
  /**
26
26
  * Checks if entity has an id.
27
27
  * If entity composite compose ids, it will check them all.
@@ -51,7 +51,7 @@ export declare class BaseEntity {
51
51
  /**
52
52
  * Sets DataSource to be used by entity.
53
53
  */
54
- static useDataSource(dataSource: DataSource): void;
54
+ static useDataSource(dataSource: DataSource | null): void;
55
55
  /**
56
56
  * Gets current entity's Repository.
57
57
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/repository/BaseEntity.ts"],"names":[],"mappings":";;;AAaA,qDAAiD;AAKjD;;GAEG;AACH,MAAa,UAAU;IAWnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAqB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAuB;QAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAkB,CAAA;IAC5E,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAqB;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,OAAqB;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC5D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACR,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC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AAO,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAEZ,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,CAEd,EAAqC;QAErC,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAEhB,OAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAElB,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAER,KAAa,EACb,UAAkB;QAElB,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ;AAzgBD,gCAygBC","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n // @ts-ignore: Unused variable which is actually used\n private static dataSource?: DataSource\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const newestEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneOrFail(baseEntity.getId(this))\n\n ObjectUtils.assign(this, newestEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository() as Repository<T>\n return thisRepository.preload(entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/repository/BaseEntity.ts"],"names":[],"mappings":";;;AAaA,qDAAiD;AAKjD;;GAEG;AACH,MAAa,UAAU;IAUnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAqB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAuB;QAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAkB,CAAA;IAC5E,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAqB;QAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAA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esContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const newestEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneOrFail(baseEntity.getId(this))\n\n ObjectUtils.assign(this, newestEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository() as Repository<T>\n return thisRepository.preload(entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}