typeorm 0.2.42-dev.a855b90 → 0.2.42-dev.d10484e
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.
- package/README.md +38 -0
- package/browser/common/RelationType.d.ts +14 -0
- package/browser/common/RelationType.js +3 -0
- package/browser/common/RelationType.js.map +1 -0
- package/browser/connection/Connection.d.ts +1 -1
- package/browser/connection/Connection.js +45 -30
- package/browser/connection/Connection.js.map +1 -1
- package/browser/connection/ConnectionMetadataBuilder.d.ts +3 -3
- package/browser/connection/ConnectionMetadataBuilder.js +54 -22
- package/browser/connection/ConnectionMetadataBuilder.js.map +1 -1
- package/browser/connection/ConnectionOptionsReader.js +33 -28
- package/browser/connection/ConnectionOptionsReader.js.map +1 -1
- package/browser/find-options/operator/Like.d.ts +1 -1
- package/browser/find-options/operator/Like.js +1 -1
- package/browser/find-options/operator/Like.js.map +1 -1
- package/browser/globals.js +34 -7
- package/browser/globals.js.map +1 -1
- package/browser/index.d.ts +1 -0
- package/browser/index.js +1 -0
- package/browser/index.js.map +1 -1
- package/browser/migration/MigrationExecutor.js +1 -1
- package/browser/migration/MigrationExecutor.js.map +1 -1
- package/browser/util/DirectoryExportedClassesLoader.d.ts +1 -1
- package/browser/util/DirectoryExportedClassesLoader.js +55 -31
- package/browser/util/DirectoryExportedClassesLoader.js.map +1 -1
- package/browser/util/ImportUtils.d.ts +1 -0
- package/browser/util/ImportUtils.js +90 -0
- package/browser/util/ImportUtils.js.map +1 -0
- package/commands/InitCommand.d.ts +9 -7
- package/commands/InitCommand.js +72 -43
- package/commands/InitCommand.js.map +1 -1
- package/common/RelationType.d.ts +14 -0
- package/common/RelationType.js +4 -0
- package/common/RelationType.js.map +1 -0
- package/connection/Connection.d.ts +1 -1
- package/connection/Connection.js +45 -30
- package/connection/Connection.js.map +1 -1
- package/connection/ConnectionMetadataBuilder.d.ts +3 -3
- package/connection/ConnectionMetadataBuilder.js +53 -21
- package/connection/ConnectionMetadataBuilder.js.map +1 -1
- package/connection/ConnectionOptionsReader.js +32 -27
- package/connection/ConnectionOptionsReader.js.map +1 -1
- package/find-options/operator/Like.d.ts +1 -1
- package/find-options/operator/Like.js +1 -1
- package/find-options/operator/Like.js.map +1 -1
- package/globals.js +33 -6
- package/globals.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/index.mjs +352 -0
- package/migration/MigrationExecutor.js +1 -1
- package/migration/MigrationExecutor.js.map +1 -1
- package/package.json +1 -1
- package/util/DirectoryExportedClassesLoader.d.ts +1 -1
- package/util/DirectoryExportedClassesLoader.js +54 -31
- package/util/DirectoryExportedClassesLoader.js.map +1 -1
- package/util/ImportUtils.d.ts +1 -0
- package/util/ImportUtils.js +94 -0
- package/util/ImportUtils.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/migration/MigrationExecutor.ts"],"names":[],"mappings":";;;;AAAA,uDAAoD;AAEpD,yCAAsC;AAGtC,uEAAoE;AACpE,qEAAkE;AAClE,2EAAwE;AACxE,6DAA0D;AAE1D,kCAAsC;AAEtC;;GAEG;AACH;IAuBI,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,2BAAsB,UAAsB,EACtB,WAAyB;QADzB,eAAU,GAAV,UAAU,CAAY;QACtB,gBAAW,GAAX,WAAW,CAAc;QA1B/C,4EAA4E;QAC5E,oBAAoB;QACpB,4EAA4E;QAE5E;;;;;WAKG;QACH,gBAAW,GAA4B,KAAK,CAAC;QAkBjC,IAAA,MAAM,GAAK,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,OAA1C,CAA2C;QACzD,IAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjD,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAC;QACnC,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC;QAC/B,IAAI,CAAC,mBAAmB,GAAG,UAA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,CAAC,WAAW,EAAjB,wBAAiB;wBACjB,qBAAM,WAAW,CAAC,OAAO,EAAE,EAAA;;wBAA3B,SAA2B,CAAC;;;;;;;KAGvC;IACL,wBAAC;AAAD,CAnfA,AAmfC,IAAA;AAnfY,8CAAiB","file":"MigrationExecutor.js","sourcesContent":["import {Table} from \"../schema-builder/table/Table\";\nimport {Connection} from \"../connection/Connection\";\nimport {Migration} from \"./Migration\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MssqlParameter} from \"../driver/sqlserver/MssqlParameter\";\nimport {RdbmsSchemaBuilder} from \"../schema-builder/RdbmsSchemaBuilder\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {MongoQueryRunner} from \"../driver/mongodb/MongoQueryRunner\";\nimport {TypeORMError} from \"../error\";\n\n/**\n * Executes migrations: runs pending and reverts previously executed migrations.\n */\nexport class MigrationExecutor {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Indicates how migrations should be run in transactions.\n * all: all migrations are run in a single transaction\n * none: all migrations are run without a transaction\n * each: each migration is run in a separate transaction\n */\n transaction: \"all\" | \"none\" | \"each\" = \"all\";\n\n // -------------------------------------------------------------------------\n // Private Properties\n // -------------------------------------------------------------------------\n\n private readonly migrationsDatabase?: string;\n private readonly migrationsSchema?: string;\n private readonly migrationsTable: string;\n private readonly migrationsTableName: string;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: Connection,\n protected queryRunner?: QueryRunner) {\n\n const { schema } = this.connection.driver.options as any;\n const database = this.connection.driver.database;\n this.migrationsDatabase = database;\n this.migrationsSchema = schema;\n this.migrationsTableName = connection.options.migrationsTableName || \"migrations\";\n this.migrationsTable = this.connection.driver.buildTableName(this.migrationsTableName, schema, database);\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Tries to execute a single migration given.\n */\n public async executeMigration(migration: Migration): Promise<Migration> {\n return this.withQueryRunner(async (queryRunner) => {\n await this.createMigrationsTableIfNotExist(queryRunner);\n await (migration.instance as any).up(queryRunner);\n await this.insertExecutedMigration(queryRunner, migration);\n\n return migration;\n });\n }\n\n /**\n * Returns an array of all migrations.\n */\n public async getAllMigrations(): Promise<Migration[]> {\n return Promise.resolve(this.getMigrations());\n }\n\n /**\n * Returns an array of all executed migrations.\n */\n public async getExecutedMigrations(): Promise<Migration[]> {\n return this.withQueryRunner(async queryRunner => {\n await this.createMigrationsTableIfNotExist(queryRunner);\n\n return await this.loadExecutedMigrations(queryRunner);\n });\n }\n\n /**\n * Returns an array of all pending migrations.\n */\n public async getPendingMigrations(): Promise<Migration[]> {\n const allMigrations = await this.getAllMigrations();\n const executedMigrations = await this.getExecutedMigrations();\n\n return allMigrations.filter(migration =>\n !executedMigrations.find(\n executedMigration =>\n executedMigration.name === migration.name\n )\n );\n }\n\n /**\n * Inserts an executed migration.\n */\n public insertMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner(q => this.insertExecutedMigration(q, migration));\n }\n\n /**\n * Deletes an executed migration.\n */\n public deleteMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner(q => this.deleteExecutedMigration(q, migration));\n }\n\n /**\n * Lists all migrations and whether they have been executed or not\n * returns true if there are unapplied migrations\n */\n async showMigrations(): Promise<boolean> {\n let hasUnappliedMigrations = false;\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner);\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(queryRunner);\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations();\n\n for (const migration of allMigrations) {\n const executedMigration = executedMigrations.find(executedMigration => executedMigration.name === migration.name);\n\n if (executedMigration) {\n this.connection.logger.logSchemaBuild(` [X] ${migration.name}`);\n } else {\n hasUnappliedMigrations = true;\n this.connection.logger.logSchemaBuild(` [ ] ${migration.name}`);\n }\n }\n\n // if query runner was created by us then release it\n if (!this.queryRunner) {\n await queryRunner.release();\n }\n\n return hasUnappliedMigrations;\n }\n\n /**\n * Executes all pending migrations. Pending migrations are migrations that are not yet executed,\n * thus not saved in the database.\n */\n async executePendingMigrations(): Promise<Migration[]> {\n\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner);\n\n // create the typeorm_metadata table if necessary\n const schemaBuilder = this.connection.driver.createSchemaBuilder();\n\n if (schemaBuilder instanceof RdbmsSchemaBuilder) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner);\n }\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(queryRunner);\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration = this.getLatestTimestampMigration(executedMigrations);\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations();\n\n // variable to store all migrations we did successefuly\n const successMigrations: Migration[] = [];\n\n // find all migrations that needs to be executed\n const pendingMigrations = allMigrations.filter(migration => {\n // check if we already have executed migration\n const executedMigration = executedMigrations.find(executedMigration => executedMigration.name === migration.name);\n if (executedMigration)\n return false;\n\n // migration is new and not executed. now check if its timestamp is correct\n // if (lastTimeExecutedMigration && migration.timestamp < lastTimeExecutedMigration.timestamp)\n // throw new TypeORMError(`New migration found: ${migration.name}, however this migration's timestamp is not valid. Migration's timestamp should not be older then migrations already executed in the database.`);\n\n // every check is passed means that migration was not run yet and we need to run it\n return true;\n });\n\n // if no migrations are pending then nothing to do here\n if (!pendingMigrations.length) {\n this.connection.logger.logSchemaBuild(`No migrations are pending`);\n // if query runner was created by us then release it\n if (!this.queryRunner)\n await queryRunner.release();\n return [];\n }\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(`${executedMigrations.length} migrations are already loaded in the database.`);\n this.connection.logger.logSchemaBuild(`${allMigrations.length} migrations were found in the source code.`);\n if (lastTimeExecutedMigration)\n this.connection.logger.logSchemaBuild(`${lastTimeExecutedMigration.name} is the last executed migration. It was executed on ${new Date(lastTimeExecutedMigration.timestamp).toString()}.`);\n this.connection.logger.logSchemaBuild(`${pendingMigrations.length} migrations are new migrations that needs to be executed.`);\n\n // start transaction if its not started yet\n let transactionStartedByUs = false;\n if (this.transaction === \"all\" && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction();\n transactionStartedByUs = true;\n }\n\n // run all pending migrations in a sequence\n try {\n for (const migration of pendingMigrations) {\n if (this.transaction === \"each\" && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction();\n transactionStartedByUs = true;\n }\n\n await migration.instance!.up(queryRunner)\n .catch(error => { // informative log about migration failure\n this.connection.logger.logMigration(`Migration \"${migration.name}\" has been failed, error: ${error?.message}`);\n throw error;\n })\n .then(async () => { // now when migration is executed we need to insert record about it into the database\n await this.insertExecutedMigration(queryRunner, migration);\n // commit transaction if we started it\n if (this.transaction === \"each\" && transactionStartedByUs)\n await queryRunner.commitTransaction();\n })\n .then(() => { // informative log about migration success\n successMigrations.push(migration);\n this.connection.logger.logSchemaBuild(`Migration ${migration.name} has been executed successfully.`);\n });\n }\n\n // commit transaction if we started it\n if (this.transaction === \"all\" && transactionStartedByUs)\n await queryRunner.commitTransaction();\n\n } catch (err) { // rollback transaction if we started it\n if (transactionStartedByUs) {\n try { // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction();\n } catch (rollbackError) { }\n }\n\n throw err;\n\n } finally {\n\n // if query runner was created by us then release it\n if (!this.queryRunner)\n await queryRunner.release();\n }\n return successMigrations;\n\n }\n\n /**\n * Reverts last migration that were run.\n */\n async undoLastMigration(): Promise<void> {\n\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner);\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(queryRunner);\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration = this.getLatestExecutedMigration(executedMigrations);\n\n // if no migrations found in the database then nothing to revert\n if (!lastTimeExecutedMigration) {\n this.connection.logger.logSchemaBuild(`No migrations was found in the database. Nothing to revert!`);\n return;\n }\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations();\n\n // find the instance of the migration we need to remove\n const migrationToRevert = allMigrations.find(migration => migration.name === lastTimeExecutedMigration!.name);\n\n // if no migrations found in the database then nothing to revert\n if (!migrationToRevert)\n throw new TypeORMError(`No migration ${lastTimeExecutedMigration.name} was found in the source code. Make sure you have this migration in your codebase and its included in the connection options.`);\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(`${executedMigrations.length} migrations are already loaded in the database.`);\n this.connection.logger.logSchemaBuild(`${lastTimeExecutedMigration.name} is the last executed migration. It was executed on ${new Date(lastTimeExecutedMigration.timestamp).toString()}.`);\n this.connection.logger.logSchemaBuild(`Now reverting it...`);\n\n // start transaction if its not started yet\n let transactionStartedByUs = false;\n if ((this.transaction !== \"none\") && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction();\n transactionStartedByUs = true;\n }\n\n try {\n await migrationToRevert.instance!.down(queryRunner);\n await this.deleteExecutedMigration(queryRunner, migrationToRevert);\n this.connection.logger.logSchemaBuild(`Migration ${migrationToRevert.name} has been reverted successfully.`);\n\n // commit transaction if we started it\n if (transactionStartedByUs)\n await queryRunner.commitTransaction();\n\n } catch (err) { // rollback transaction if we started it\n if (transactionStartedByUs) {\n try { // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction();\n } catch (rollbackError) { }\n }\n\n throw err;\n\n } finally {\n\n // if query runner was created by us then release it\n if (!this.queryRunner)\n await queryRunner.release();\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates table \"migrations\" that will store information about executed migrations.\n */\n protected async createMigrationsTableIfNotExist(queryRunner: QueryRunner): Promise<void> {\n // If driver is mongo no need to create\n if (this.connection.driver instanceof MongoDriver) {\n return;\n }\n const tableExist = await queryRunner.hasTable(this.migrationsTable); // todo: table name should be configurable\n if (!tableExist) {\n await queryRunner.createTable(new Table(\n {\n database: this.migrationsDatabase,\n schema: this.migrationsSchema,\n name: this.migrationsTable,\n columns: [\n {\n name: \"id\",\n type: this.connection.driver.normalizeType({type: this.connection.driver.mappedDataTypes.migrationId}),\n isGenerated: true,\n generationStrategy: \"increment\",\n isPrimary: true,\n isNullable: false\n },\n {\n name: \"timestamp\",\n type: this.connection.driver.normalizeType({type: this.connection.driver.mappedDataTypes.migrationTimestamp}),\n isPrimary: false,\n isNullable: false\n },\n {\n name: \"name\",\n type: this.connection.driver.normalizeType({type: this.connection.driver.mappedDataTypes.migrationName}),\n isNullable: false\n },\n ]\n },\n ));\n }\n }\n\n /**\n * Loads all migrations that were executed and saved into the database (sorts by id).\n */\n protected async loadExecutedMigrations(queryRunner: QueryRunner): Promise<Migration[]> {\n if (this.connection.driver instanceof MongoDriver) {\n const mongoRunner = queryRunner as MongoQueryRunner;\n return await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .find<Migration>()\n .sort({\"_id\": -1})\n .toArray();\n } else {\n const migrationsRaw: ObjectLiteral[] = await this.connection.manager\n .createQueryBuilder(queryRunner)\n .select()\n .orderBy(this.connection.driver.escape(\"id\"), \"DESC\")\n .from(this.migrationsTable, this.migrationsTableName)\n .getRawMany();\n return migrationsRaw.map(migrationRaw => {\n return new Migration(parseInt(migrationRaw[\"id\"]), parseInt(migrationRaw[\"timestamp\"]), migrationRaw[\"name\"]);\n });\n }\n }\n\n /**\n * Gets all migrations that setup for this connection.\n */\n protected getMigrations(): Migration[] {\n const migrations = this.connection.migrations.map(migration => {\n const migrationClassName = migration.name || (migration.constructor as any).name;\n const migrationTimestamp = parseInt(migrationClassName.substr(-13), 10);\n if (!migrationTimestamp || isNaN(migrationTimestamp)) {\n throw new TypeORMError(`${migrationClassName} migration name is wrong. Migration class name should have a JavaScript timestamp appended.`);\n }\n\n return new Migration(undefined, migrationTimestamp, migrationClassName, migration);\n });\n\n this.checkForDuplicateMigrations(migrations);\n\n // sort them by timestamp\n return migrations.sort((a, b) => a.timestamp - b.timestamp);\n }\n\n protected checkForDuplicateMigrations(migrations: Migration[]) {\n const migrationNames = migrations.map(migration => migration.name);\n const duplicates = Array.from(new Set(migrationNames.filter((migrationName, index) => migrationNames.indexOf(migrationName) < index)));\n if (duplicates.length > 0) {\n throw Error(`Duplicate migrations: ${duplicates.join(\", \")}`);\n }\n }\n\n /**\n * Finds the latest migration (sorts by timestamp) in the given array of migrations.\n */\n protected getLatestTimestampMigration(migrations: Migration[]): Migration|undefined {\n const sortedMigrations = migrations.map(migration => migration).sort((a, b) => (a.timestamp - b.timestamp) * -1);\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined;\n }\n\n /**\n * Finds the latest migration in the given array of migrations.\n * PRE: Migration array must be sorted by descending id.\n */\n protected getLatestExecutedMigration(sortedMigrations: Migration[]): Migration|undefined {\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined;\n }\n\n /**\n * Inserts new executed migration's data into migrations table.\n */\n protected async insertExecutedMigration(queryRunner: QueryRunner, migration: Migration): Promise<void> {\n const values: ObjectLiteral = {};\n if (this.connection.driver instanceof SqlServerDriver) {\n values[\"timestamp\"] = new MssqlParameter(migration.timestamp, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationTimestamp }) as any);\n values[\"name\"] = new MssqlParameter(migration.name, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationName }) as any);\n } else {\n values[\"timestamp\"] = migration.timestamp;\n values[\"name\"] = migration.name;\n }\n if (this.connection.driver instanceof MongoDriver) {\n const mongoRunner = queryRunner as MongoQueryRunner;\n await mongoRunner.databaseConnection.db(this.connection.driver.database!).collection(this.migrationsTableName).insertOne(values);\n } else {\n const qb = queryRunner.manager.createQueryBuilder();\n await qb.insert()\n .into(this.migrationsTable)\n .values(values)\n .execute();\n }\n }\n\n /**\n * Delete previously executed migration's data from the migrations table.\n */\n protected async deleteExecutedMigration(queryRunner: QueryRunner, migration: Migration): Promise<void> {\n\n const conditions: ObjectLiteral = {};\n if (this.connection.driver instanceof SqlServerDriver) {\n conditions[\"timestamp\"] = new MssqlParameter(migration.timestamp, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationTimestamp }) as any);\n conditions[\"name\"] = new MssqlParameter(migration.name, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationName }) as any);\n } else {\n conditions[\"timestamp\"] = migration.timestamp;\n conditions[\"name\"] = migration.name;\n }\n\n if (this.connection.driver instanceof MongoDriver) {\n const mongoRunner = queryRunner as MongoQueryRunner;\n await mongoRunner.databaseConnection.db(this.connection.driver.database!).collection(this.migrationsTableName).deleteOne(conditions);\n } else {\n const qb = queryRunner.manager.createQueryBuilder();\n await qb.delete()\n .from(this.migrationsTable)\n .where(`${qb.escape(\"timestamp\")} = :timestamp`)\n .andWhere(`${qb.escape(\"name\")} = :name`)\n .setParameters(conditions)\n .execute();\n }\n\n }\n\n protected async withQueryRunner<T extends any>(callback: (queryRunner: QueryRunner) => T | Promise<T>) {\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n\n try {\n return callback(queryRunner);\n } finally {\n if (!this.queryRunner) {\n await queryRunner.release();\n }\n }\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/migration/MigrationExecutor.ts"],"names":[],"mappings":";;;;AAAA,uDAAoD;AAEpD,yCAAsC;AAGtC,uEAAoE;AACpE,qEAAkE;AAClE,2EAAwE;AACxE,6DAA0D;AAE1D,kCAAsC;AAEtC;;GAEG;AACH;IAuBI,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,2BAAsB,UAAsB,EACtB,WAAyB;QADzB,eAAU,GAAV,UAAU,CAAY;QACtB,gBAAW,GAAX,WAAW,CAAc;QA1B/C,4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AAe,CAAC;iCAC/C,QAAQ,CAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,aAAU,CAAC;iCACxC,aAAa,CAAC,UAAU,CAAC;iCACzB,OAAO,EAAE,EAAA;;wBALd,SAKc,CAAC;;;;;;KAGtB;IAEe,2CAAe,GAA/B,UAA+C,QAAsD;;;;;;wBAC3F,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC;;;;wBAGxE,sBAAO,QAAQ,CAAC,WAAW,CAAC,EAAC;;6BAEzB,CAAC,IAAI,CAAC,WAAW,EAAjB,wBAAiB;wBACjB,qBAAM,WAAW,CAAC,OAAO,EAAE,EAAA;;wBAA3B,SAA2B,CAAC;;;;;;;KAGvC;IACL,wBAAC;AAAD,CAnfA,AAmfC,IAAA;AAnfY,8CAAiB","file":"MigrationExecutor.js","sourcesContent":["import {Table} from \"../schema-builder/table/Table\";\nimport {Connection} from \"../connection/Connection\";\nimport {Migration} from \"./Migration\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MssqlParameter} from \"../driver/sqlserver/MssqlParameter\";\nimport {RdbmsSchemaBuilder} from \"../schema-builder/RdbmsSchemaBuilder\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {MongoQueryRunner} from \"../driver/mongodb/MongoQueryRunner\";\nimport {TypeORMError} from \"../error\";\n\n/**\n * Executes migrations: runs pending and reverts previously executed migrations.\n */\nexport class MigrationExecutor {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Indicates how migrations should be run in transactions.\n * all: all migrations are run in a single transaction\n * none: all migrations are run without a transaction\n * each: each migration is run in a separate transaction\n */\n transaction: \"all\" | \"none\" | \"each\" = \"all\";\n\n // -------------------------------------------------------------------------\n // Private Properties\n // -------------------------------------------------------------------------\n\n private readonly migrationsDatabase?: string;\n private readonly migrationsSchema?: string;\n private readonly migrationsTable: string;\n private readonly migrationsTableName: string;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: Connection,\n protected queryRunner?: QueryRunner) {\n\n const { schema } = this.connection.driver.options as any;\n const database = this.connection.driver.database;\n this.migrationsDatabase = database;\n this.migrationsSchema = schema;\n this.migrationsTableName = connection.options.migrationsTableName || \"migrations\";\n this.migrationsTable = this.connection.driver.buildTableName(this.migrationsTableName, schema, database);\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Tries to execute a single migration given.\n */\n public async executeMigration(migration: Migration): Promise<Migration> {\n return this.withQueryRunner(async (queryRunner) => {\n await this.createMigrationsTableIfNotExist(queryRunner);\n await (migration.instance as any).up(queryRunner);\n await this.insertExecutedMigration(queryRunner, migration);\n\n return migration;\n });\n }\n\n /**\n * Returns an array of all migrations.\n */\n public async getAllMigrations(): Promise<Migration[]> {\n return Promise.resolve(this.getMigrations());\n }\n\n /**\n * Returns an array of all executed migrations.\n */\n public async getExecutedMigrations(): Promise<Migration[]> {\n return this.withQueryRunner(async queryRunner => {\n await this.createMigrationsTableIfNotExist(queryRunner);\n\n return await this.loadExecutedMigrations(queryRunner);\n });\n }\n\n /**\n * Returns an array of all pending migrations.\n */\n public async getPendingMigrations(): Promise<Migration[]> {\n const allMigrations = await this.getAllMigrations();\n const executedMigrations = await this.getExecutedMigrations();\n\n return allMigrations.filter(migration =>\n !executedMigrations.find(\n executedMigration =>\n executedMigration.name === migration.name\n )\n );\n }\n\n /**\n * Inserts an executed migration.\n */\n public insertMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner(q => this.insertExecutedMigration(q, migration));\n }\n\n /**\n * Deletes an executed migration.\n */\n public deleteMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner(q => this.deleteExecutedMigration(q, migration));\n }\n\n /**\n * Lists all migrations and whether they have been executed or not\n * returns true if there are unapplied migrations\n */\n async showMigrations(): Promise<boolean> {\n let hasUnappliedMigrations = false;\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner);\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(queryRunner);\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations();\n\n for (const migration of allMigrations) {\n const executedMigration = executedMigrations.find(executedMigration => executedMigration.name === migration.name);\n\n if (executedMigration) {\n this.connection.logger.logSchemaBuild(` [X] ${migration.name}`);\n } else {\n hasUnappliedMigrations = true;\n this.connection.logger.logSchemaBuild(` [ ] ${migration.name}`);\n }\n }\n\n // if query runner was created by us then release it\n if (!this.queryRunner) {\n await queryRunner.release();\n }\n\n return hasUnappliedMigrations;\n }\n\n /**\n * Executes all pending migrations. Pending migrations are migrations that are not yet executed,\n * thus not saved in the database.\n */\n async executePendingMigrations(): Promise<Migration[]> {\n\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner);\n\n // create the typeorm_metadata table if necessary\n const schemaBuilder = this.connection.driver.createSchemaBuilder();\n\n if (schemaBuilder instanceof RdbmsSchemaBuilder) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner);\n }\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(queryRunner);\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration = this.getLatestTimestampMigration(executedMigrations);\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations();\n\n // variable to store all migrations we did successefuly\n const successMigrations: Migration[] = [];\n\n // find all migrations that needs to be executed\n const pendingMigrations = allMigrations.filter(migration => {\n // check if we already have executed migration\n const executedMigration = executedMigrations.find(executedMigration => executedMigration.name === migration.name);\n if (executedMigration)\n return false;\n\n // migration is new and not executed. now check if its timestamp is correct\n // if (lastTimeExecutedMigration && migration.timestamp < lastTimeExecutedMigration.timestamp)\n // throw new TypeORMError(`New migration found: ${migration.name}, however this migration's timestamp is not valid. Migration's timestamp should not be older then migrations already executed in the database.`);\n\n // every check is passed means that migration was not run yet and we need to run it\n return true;\n });\n\n // if no migrations are pending then nothing to do here\n if (!pendingMigrations.length) {\n this.connection.logger.logSchemaBuild(`No migrations are pending`);\n // if query runner was created by us then release it\n if (!this.queryRunner)\n await queryRunner.release();\n return [];\n }\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(`${executedMigrations.length} migrations are already loaded in the database.`);\n this.connection.logger.logSchemaBuild(`${allMigrations.length} migrations were found in the source code.`);\n if (lastTimeExecutedMigration)\n this.connection.logger.logSchemaBuild(`${lastTimeExecutedMigration.name} is the last executed migration. It was executed on ${new Date(lastTimeExecutedMigration.timestamp).toString()}.`);\n this.connection.logger.logSchemaBuild(`${pendingMigrations.length} migrations are new migrations that needs to be executed.`);\n\n // start transaction if its not started yet\n let transactionStartedByUs = false;\n if (this.transaction === \"all\" && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction();\n transactionStartedByUs = true;\n }\n\n // run all pending migrations in a sequence\n try {\n for (const migration of pendingMigrations) {\n if (this.transaction === \"each\" && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction();\n transactionStartedByUs = true;\n }\n\n await migration.instance!.up(queryRunner)\n .catch(error => { // informative log about migration failure\n this.connection.logger.logMigration(`Migration \"${migration.name}\" failed, error: ${error?.message}`);\n throw error;\n })\n .then(async () => { // now when migration is executed we need to insert record about it into the database\n await this.insertExecutedMigration(queryRunner, migration);\n // commit transaction if we started it\n if (this.transaction === \"each\" && transactionStartedByUs)\n await queryRunner.commitTransaction();\n })\n .then(() => { // informative log about migration success\n successMigrations.push(migration);\n this.connection.logger.logSchemaBuild(`Migration ${migration.name} has been executed successfully.`);\n });\n }\n\n // commit transaction if we started it\n if (this.transaction === \"all\" && transactionStartedByUs)\n await queryRunner.commitTransaction();\n\n } catch (err) { // rollback transaction if we started it\n if (transactionStartedByUs) {\n try { // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction();\n } catch (rollbackError) { }\n }\n\n throw err;\n\n } finally {\n\n // if query runner was created by us then release it\n if (!this.queryRunner)\n await queryRunner.release();\n }\n return successMigrations;\n\n }\n\n /**\n * Reverts last migration that were run.\n */\n async undoLastMigration(): Promise<void> {\n\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner);\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(queryRunner);\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration = this.getLatestExecutedMigration(executedMigrations);\n\n // if no migrations found in the database then nothing to revert\n if (!lastTimeExecutedMigration) {\n this.connection.logger.logSchemaBuild(`No migrations was found in the database. Nothing to revert!`);\n return;\n }\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations();\n\n // find the instance of the migration we need to remove\n const migrationToRevert = allMigrations.find(migration => migration.name === lastTimeExecutedMigration!.name);\n\n // if no migrations found in the database then nothing to revert\n if (!migrationToRevert)\n throw new TypeORMError(`No migration ${lastTimeExecutedMigration.name} was found in the source code. Make sure you have this migration in your codebase and its included in the connection options.`);\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(`${executedMigrations.length} migrations are already loaded in the database.`);\n this.connection.logger.logSchemaBuild(`${lastTimeExecutedMigration.name} is the last executed migration. It was executed on ${new Date(lastTimeExecutedMigration.timestamp).toString()}.`);\n this.connection.logger.logSchemaBuild(`Now reverting it...`);\n\n // start transaction if its not started yet\n let transactionStartedByUs = false;\n if ((this.transaction !== \"none\") && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction();\n transactionStartedByUs = true;\n }\n\n try {\n await migrationToRevert.instance!.down(queryRunner);\n await this.deleteExecutedMigration(queryRunner, migrationToRevert);\n this.connection.logger.logSchemaBuild(`Migration ${migrationToRevert.name} has been reverted successfully.`);\n\n // commit transaction if we started it\n if (transactionStartedByUs)\n await queryRunner.commitTransaction();\n\n } catch (err) { // rollback transaction if we started it\n if (transactionStartedByUs) {\n try { // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction();\n } catch (rollbackError) { }\n }\n\n throw err;\n\n } finally {\n\n // if query runner was created by us then release it\n if (!this.queryRunner)\n await queryRunner.release();\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates table \"migrations\" that will store information about executed migrations.\n */\n protected async createMigrationsTableIfNotExist(queryRunner: QueryRunner): Promise<void> {\n // If driver is mongo no need to create\n if (this.connection.driver instanceof MongoDriver) {\n return;\n }\n const tableExist = await queryRunner.hasTable(this.migrationsTable); // todo: table name should be configurable\n if (!tableExist) {\n await queryRunner.createTable(new Table(\n {\n database: this.migrationsDatabase,\n schema: this.migrationsSchema,\n name: this.migrationsTable,\n columns: [\n {\n name: \"id\",\n type: this.connection.driver.normalizeType({type: this.connection.driver.mappedDataTypes.migrationId}),\n isGenerated: true,\n generationStrategy: \"increment\",\n isPrimary: true,\n isNullable: false\n },\n {\n name: \"timestamp\",\n type: this.connection.driver.normalizeType({type: this.connection.driver.mappedDataTypes.migrationTimestamp}),\n isPrimary: false,\n isNullable: false\n },\n {\n name: \"name\",\n type: this.connection.driver.normalizeType({type: this.connection.driver.mappedDataTypes.migrationName}),\n isNullable: false\n },\n ]\n },\n ));\n }\n }\n\n /**\n * Loads all migrations that were executed and saved into the database (sorts by id).\n */\n protected async loadExecutedMigrations(queryRunner: QueryRunner): Promise<Migration[]> {\n if (this.connection.driver instanceof MongoDriver) {\n const mongoRunner = queryRunner as MongoQueryRunner;\n return await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .find<Migration>()\n .sort({\"_id\": -1})\n .toArray();\n } else {\n const migrationsRaw: ObjectLiteral[] = await this.connection.manager\n .createQueryBuilder(queryRunner)\n .select()\n .orderBy(this.connection.driver.escape(\"id\"), \"DESC\")\n .from(this.migrationsTable, this.migrationsTableName)\n .getRawMany();\n return migrationsRaw.map(migrationRaw => {\n return new Migration(parseInt(migrationRaw[\"id\"]), parseInt(migrationRaw[\"timestamp\"]), migrationRaw[\"name\"]);\n });\n }\n }\n\n /**\n * Gets all migrations that setup for this connection.\n */\n protected getMigrations(): Migration[] {\n const migrations = this.connection.migrations.map(migration => {\n const migrationClassName = migration.name || (migration.constructor as any).name;\n const migrationTimestamp = parseInt(migrationClassName.substr(-13), 10);\n if (!migrationTimestamp || isNaN(migrationTimestamp)) {\n throw new TypeORMError(`${migrationClassName} migration name is wrong. Migration class name should have a JavaScript timestamp appended.`);\n }\n\n return new Migration(undefined, migrationTimestamp, migrationClassName, migration);\n });\n\n this.checkForDuplicateMigrations(migrations);\n\n // sort them by timestamp\n return migrations.sort((a, b) => a.timestamp - b.timestamp);\n }\n\n protected checkForDuplicateMigrations(migrations: Migration[]) {\n const migrationNames = migrations.map(migration => migration.name);\n const duplicates = Array.from(new Set(migrationNames.filter((migrationName, index) => migrationNames.indexOf(migrationName) < index)));\n if (duplicates.length > 0) {\n throw Error(`Duplicate migrations: ${duplicates.join(\", \")}`);\n }\n }\n\n /**\n * Finds the latest migration (sorts by timestamp) in the given array of migrations.\n */\n protected getLatestTimestampMigration(migrations: Migration[]): Migration|undefined {\n const sortedMigrations = migrations.map(migration => migration).sort((a, b) => (a.timestamp - b.timestamp) * -1);\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined;\n }\n\n /**\n * Finds the latest migration in the given array of migrations.\n * PRE: Migration array must be sorted by descending id.\n */\n protected getLatestExecutedMigration(sortedMigrations: Migration[]): Migration|undefined {\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined;\n }\n\n /**\n * Inserts new executed migration's data into migrations table.\n */\n protected async insertExecutedMigration(queryRunner: QueryRunner, migration: Migration): Promise<void> {\n const values: ObjectLiteral = {};\n if (this.connection.driver instanceof SqlServerDriver) {\n values[\"timestamp\"] = new MssqlParameter(migration.timestamp, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationTimestamp }) as any);\n values[\"name\"] = new MssqlParameter(migration.name, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationName }) as any);\n } else {\n values[\"timestamp\"] = migration.timestamp;\n values[\"name\"] = migration.name;\n }\n if (this.connection.driver instanceof MongoDriver) {\n const mongoRunner = queryRunner as MongoQueryRunner;\n await mongoRunner.databaseConnection.db(this.connection.driver.database!).collection(this.migrationsTableName).insertOne(values);\n } else {\n const qb = queryRunner.manager.createQueryBuilder();\n await qb.insert()\n .into(this.migrationsTable)\n .values(values)\n .execute();\n }\n }\n\n /**\n * Delete previously executed migration's data from the migrations table.\n */\n protected async deleteExecutedMigration(queryRunner: QueryRunner, migration: Migration): Promise<void> {\n\n const conditions: ObjectLiteral = {};\n if (this.connection.driver instanceof SqlServerDriver) {\n conditions[\"timestamp\"] = new MssqlParameter(migration.timestamp, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationTimestamp }) as any);\n conditions[\"name\"] = new MssqlParameter(migration.name, this.connection.driver.normalizeType({ type: this.connection.driver.mappedDataTypes.migrationName }) as any);\n } else {\n conditions[\"timestamp\"] = migration.timestamp;\n conditions[\"name\"] = migration.name;\n }\n\n if (this.connection.driver instanceof MongoDriver) {\n const mongoRunner = queryRunner as MongoQueryRunner;\n await mongoRunner.databaseConnection.db(this.connection.driver.database!).collection(this.migrationsTableName).deleteOne(conditions);\n } else {\n const qb = queryRunner.manager.createQueryBuilder();\n await qb.delete()\n .from(this.migrationsTable)\n .where(`${qb.escape(\"timestamp\")} = :timestamp`)\n .andWhere(`${qb.escape(\"name\")} = :name`)\n .setParameters(conditions)\n .execute();\n }\n\n }\n\n protected async withQueryRunner<T extends any>(callback: (queryRunner: QueryRunner) => T | Promise<T>) {\n const queryRunner = this.queryRunner || this.connection.createQueryRunner();\n\n try {\n return callback(queryRunner);\n } finally {\n if (!this.queryRunner) {\n await queryRunner.release();\n }\n }\n }\n}\n"],"sourceRoot":".."}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "typeorm", "private": false, "version": "0.2.42-dev.
|
|
1
|
+
{ "name": "typeorm", "private": false, "version": "0.2.42-dev.d10484e", "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" }, "exports": { ".": { "import": "./index.mjs", "require": "./index.js" }, "./*": "./*" }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "type": "commonjs", "browser": { "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./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/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./index.js": "./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/dotenv": "^8.2.0", "@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/xml2js": "^0.4.8", "@types/yargs": "^17.0.2", "@typescript-eslint/eslint-plugin": "^4.15.2", "@typescript-eslint/parser": "^4.15.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", "eslint": "^7.20.0", "gulp": "^4.0.2", "gulp-eslint": "^6.0.0", "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", "lint-staged": "^10.5.4", "mocha": "^8.3.0", "mongodb": "^3.6.4", "mssql": "^6.3.1", "mysql": "^2.18.1", "mysql2": "^2.2.5", "oracledb": "^5.1.0", "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": "^9.1.1", "typeorm-aurora-data-api-driver": "^2.0.0", "typescript": "^4.2.2" }, "peerDependencies": { "@sap/hana-client": "*", "better-sqlite3": "*", "hdb-pool": "*", "ioredis": "*", "mongodb": "^3.6.0", "mssql": "*", "mysql2": "*", "oracledb": "*", "pg": "*", "pg-native": "*", "pg-query-stream": "*", "redis": "*", "sql.js": "*", "sqlite3": "*", "typeorm-aurora-data-api-driver": "*" }, "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 }, "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.1", "dotenv": "^8.2.0", "glob": "^7.1.6", "js-yaml": "^4.0.0", "mkdirp": "^1.0.4", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.1.0", "xml2js": "^0.4.23", "yargs": "^17.0.1", "zen-observable-ts": "^1.0.0" }, "lint-staged": { "*.ts": [ "eslint --fix", "git add" ] }, "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": "eslint -c ./.eslintrc.js src/**/*.ts test/**/*.ts sample/**/*.ts", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.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" } }
|
|
@@ -2,7 +2,7 @@ import { Logger } from "../logger/Logger";
|
|
|
2
2
|
/**
|
|
3
3
|
* Loads all exported classes from the given directory.
|
|
4
4
|
*/
|
|
5
|
-
export declare function importClassesFromDirectories(logger: Logger, directories: string[], formats?: string[]): Function[]
|
|
5
|
+
export declare function importClassesFromDirectories(logger: Logger, directories: string[], formats?: string[]): Promise<Function[]>;
|
|
6
6
|
/**
|
|
7
7
|
* Loads all json files from the given directory.
|
|
8
8
|
*/
|
|
@@ -5,42 +5,65 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var glob_1 = (0, tslib_1.__importDefault)(require("glob"));
|
|
6
6
|
var PlatformTools_1 = require("../platform/PlatformTools");
|
|
7
7
|
var EntitySchema_1 = require("../entity-schema/EntitySchema");
|
|
8
|
+
var ImportUtils_1 = require("./ImportUtils");
|
|
8
9
|
/**
|
|
9
10
|
* Loads all exported classes from the given directory.
|
|
10
11
|
*/
|
|
11
12
|
function importClassesFromDirectories(logger, directories, formats) {
|
|
12
|
-
if (formats === void 0) { formats = [".js", ".cjs", ".ts"]; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (formats === void 0) { formats = [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]; }
|
|
14
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
15
|
+
function loadFileClasses(exported, allLoaded) {
|
|
16
|
+
if (typeof exported === "function" || exported instanceof EntitySchema_1.EntitySchema) {
|
|
17
|
+
allLoaded.push(exported);
|
|
18
|
+
}
|
|
19
|
+
else if (Array.isArray(exported)) {
|
|
20
|
+
exported.forEach(function (i) { return loadFileClasses(i, allLoaded); });
|
|
21
|
+
}
|
|
22
|
+
else if (typeof exported === "object" && exported !== null) {
|
|
23
|
+
Object.keys(exported).forEach(function (key) { return loadFileClasses(exported[key], allLoaded); });
|
|
24
|
+
}
|
|
25
|
+
return allLoaded;
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
var logLevel, classesNotFoundMessage, classesFoundMessage, allFiles, dirPromises, dirs;
|
|
28
|
+
var _this = this;
|
|
29
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
30
|
+
switch (_a.label) {
|
|
31
|
+
case 0:
|
|
32
|
+
logLevel = "info";
|
|
33
|
+
classesNotFoundMessage = "No classes were found using the provided glob pattern: ";
|
|
34
|
+
classesFoundMessage = "All classes found using provided glob pattern";
|
|
35
|
+
allFiles = directories.reduce(function (allDirs, dir) {
|
|
36
|
+
return allDirs.concat(glob_1.default.sync(PlatformTools_1.PlatformTools.pathNormalize(dir)));
|
|
37
|
+
}, []);
|
|
38
|
+
if (directories.length > 0 && allFiles.length === 0) {
|
|
39
|
+
logger.log(logLevel, classesNotFoundMessage + " \"" + directories + "\"");
|
|
40
|
+
}
|
|
41
|
+
else if (allFiles.length > 0) {
|
|
42
|
+
logger.log(logLevel, classesFoundMessage + " \"" + directories + "\" : \"" + allFiles + "\"");
|
|
43
|
+
}
|
|
44
|
+
dirPromises = allFiles
|
|
45
|
+
.filter(function (file) {
|
|
46
|
+
var dtsExtension = file.substring(file.length - 5, file.length);
|
|
47
|
+
return formats.indexOf(PlatformTools_1.PlatformTools.pathExtname(file)) !== -1 && dtsExtension !== ".d.ts";
|
|
48
|
+
})
|
|
49
|
+
.map(function (file) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
50
|
+
var _a, importOrRequireResult;
|
|
51
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
52
|
+
switch (_b.label) {
|
|
53
|
+
case 0: return [4 /*yield*/, (0, ImportUtils_1.importOrRequireFile)(PlatformTools_1.PlatformTools.pathResolve(file))];
|
|
54
|
+
case 1:
|
|
55
|
+
_a = tslib_1.__read.apply(void 0, [_b.sent(), 1]), importOrRequireResult = _a[0];
|
|
56
|
+
return [2 /*return*/, importOrRequireResult];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); });
|
|
60
|
+
return [4 /*yield*/, Promise.all(dirPromises)];
|
|
61
|
+
case 1:
|
|
62
|
+
dirs = _a.sent();
|
|
63
|
+
return [2 /*return*/, loadFileClasses(dirs, [])];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
44
67
|
}
|
|
45
68
|
exports.importClassesFromDirectories = importClassesFromDirectories;
|
|
46
69
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/DirectoryExportedClassesLoader.ts"],"names":[],"mappings":";;;;AAAA,2DAAwB;AACxB,2DAAwD;AACxD,8DAA2D;AAE3D;;GA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M,CAAC,UAAC,OAAO,EAAE,GAAG;QAC7C,OAAO,OAAO,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,6BAAa,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC,EAAE,EAAc,CAAC,CAAC;IAEnB,OAAO,QAAQ;SACV,MAAM,CAAC,UAAA,IAAI,IAAI,OAAA,6BAAa,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,MAAM,EAA1C,CAA0C,CAAC;SAC1D,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,OAAO,CAAC,6BAAa,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAxC,CAAwC,CAAC,CAAC;AAC/D,CAAC;AATD,gEASC","file":"DirectoryExportedClassesLoader.js","sourcesContent":["import glob from \"glob\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {Logger} from \"../logger/Logger\";\nimport {importOrRequireFile} from \"./ImportUtils\";\n/**\n * Loads all exported classes from the given directory.\n */\nexport async function importClassesFromDirectories(logger: Logger, directories: string[], formats = [\".js\", \".mjs\", \".cjs\", \".ts\", \".mts\", \".cts\"]): Promise<Function[]> {\n\n const logLevel = \"info\";\n const classesNotFoundMessage = \"No classes were found using the provided glob pattern: \";\n const classesFoundMessage = \"All classes found using provided glob pattern\";\n function loadFileClasses(exported: any, allLoaded: Function[]) {\n if (typeof exported === \"function\" || exported instanceof EntitySchema) {\n allLoaded.push(exported);\n\n } else if (Array.isArray(exported)) {\n exported.forEach((i: any) => loadFileClasses(i, allLoaded));\n\n } else if (typeof exported === \"object\" && exported !== null) {\n Object.keys(exported).forEach(key => loadFileClasses(exported[key], allLoaded));\n\n }\n return allLoaded;\n }\n\n const allFiles = directories.reduce((allDirs, dir) => {\n return allDirs.concat(glob.sync(PlatformTools.pathNormalize(dir)));\n }, [] as string[]);\n\n if (directories.length > 0 && allFiles.length === 0) {\n logger.log(logLevel, `${classesNotFoundMessage} \"${directories}\"`);\n } else if (allFiles.length > 0) {\n logger.log(logLevel, `${classesFoundMessage} \"${directories}\" : \"${allFiles}\"`);\n }\n const dirPromises = allFiles\n .filter(file => {\n const dtsExtension = file.substring(file.length - 5, file.length);\n return formats.indexOf(PlatformTools.pathExtname(file)) !== -1 && dtsExtension !== \".d.ts\";\n })\n .map(async file => {\n const [importOrRequireResult] = await importOrRequireFile(PlatformTools.pathResolve(file));\n return importOrRequireResult;\n });\n\n const dirs = await Promise.all(dirPromises);\n\n return loadFileClasses(dirs, []);\n}\n\n/**\n * Loads all json files from the given directory.\n */\nexport function importJsonsFromDirectories(directories: string[], format = \".json\"): any[] {\n\n const allFiles = directories.reduce((allDirs, dir) => {\n return allDirs.concat(glob.sync(PlatformTools.pathNormalize(dir)));\n }, [] as string[]);\n\n return allFiles\n .filter(file => PlatformTools.pathExtname(file) === format)\n .map(file => require(PlatformTools.pathResolve(file)));\n}\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function importOrRequireFile(filePath: string): Promise<[result: any, moduleType: "esm" | "commonjs"]>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.importOrRequireFile = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
6
|
+
var path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
7
|
+
function importOrRequireFile(filePath) {
|
|
8
|
+
var _a;
|
|
9
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
10
|
+
var tryToImport, tryToRequire, extension, packageJson, isModule;
|
|
11
|
+
var _this = this;
|
|
12
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
13
|
+
switch (_b.label) {
|
|
14
|
+
case 0:
|
|
15
|
+
tryToImport = function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
16
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
17
|
+
switch (_a.label) {
|
|
18
|
+
case 0: return [4 /*yield*/, Function("return filePath => import(filePath)")()(filePath)];
|
|
19
|
+
case 1:
|
|
20
|
+
// `Function` is required to make sure the `import` statement wil stay `import` after
|
|
21
|
+
// transpilation and won't be converted to `require`
|
|
22
|
+
return [2 /*return*/, [_a.sent(), "esm"]];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}); };
|
|
26
|
+
tryToRequire = function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
27
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
28
|
+
return [2 /*return*/, [require(filePath), "commonjs"]];
|
|
29
|
+
});
|
|
30
|
+
}); };
|
|
31
|
+
extension = filePath.substring(filePath.lastIndexOf(".") + ".".length);
|
|
32
|
+
if (!(extension === "mjs" || extension === "mts")) return [3 /*break*/, 1];
|
|
33
|
+
return [2 /*return*/, tryToImport()];
|
|
34
|
+
case 1:
|
|
35
|
+
if (!(extension === "cjs" || extension === "cts")) return [3 /*break*/, 2];
|
|
36
|
+
return [2 /*return*/, tryToRequire()];
|
|
37
|
+
case 2:
|
|
38
|
+
if (!(extension === "js" || extension === "ts")) return [3 /*break*/, 4];
|
|
39
|
+
return [4 /*yield*/, getNearestPackageJson(filePath)];
|
|
40
|
+
case 3:
|
|
41
|
+
packageJson = _b.sent();
|
|
42
|
+
if (packageJson != null) {
|
|
43
|
+
isModule = ((_a = packageJson) === null || _a === void 0 ? void 0 : _a.type) === "module";
|
|
44
|
+
if (isModule)
|
|
45
|
+
return [2 /*return*/, tryToImport()];
|
|
46
|
+
else
|
|
47
|
+
return [2 /*return*/, tryToRequire()];
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
return [2 /*return*/, tryToRequire()];
|
|
51
|
+
_b.label = 4;
|
|
52
|
+
case 4: return [2 /*return*/, tryToRequire()];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.importOrRequireFile = importOrRequireFile;
|
|
58
|
+
function getNearestPackageJson(filePath) {
|
|
59
|
+
return new Promise(function (accept) {
|
|
60
|
+
var currentPath = filePath;
|
|
61
|
+
function searchPackageJson() {
|
|
62
|
+
var nextPath = path_1.default.dirname(currentPath);
|
|
63
|
+
if (currentPath === nextPath) // the top of the file tree is reached
|
|
64
|
+
accept(null);
|
|
65
|
+
else {
|
|
66
|
+
currentPath = nextPath;
|
|
67
|
+
var potentialPackageJson_1 = path_1.default.join(currentPath, "package.json");
|
|
68
|
+
fs_1.default.stat(potentialPackageJson_1, function (err, stats) {
|
|
69
|
+
if (err != null)
|
|
70
|
+
searchPackageJson();
|
|
71
|
+
else if (stats.isFile()) {
|
|
72
|
+
fs_1.default.readFile(potentialPackageJson_1, "utf8", function (err, data) {
|
|
73
|
+
if (err != null)
|
|
74
|
+
accept(null);
|
|
75
|
+
else {
|
|
76
|
+
try {
|
|
77
|
+
accept(JSON.parse(data));
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
accept(null);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
searchPackageJson();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
searchPackageJson();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=ImportUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/ImportUtils.ts"],"names":[],"mappings":";;;;AAAA,uDAAoB;AACpB,2DAAwB;AAExB,SAAsB,mBAAmB,CAAC,QAAgB;;;;;;;;oBAChD,WAAW,GAAG;;;wCAGR,qBAAM,QAAQ,CAAC,qCAAqC,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAA;;gCAFzE,qFAAqF;gCACrF,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IAAI,CAAC,CAAC;iBACZ;gBACD,WAAW,GAAG,QAAQ,CAAC;gBACvB,IAAM,sBAAoB,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;gBAEpE,YAAE,CAAC,IAAI,CAAC,sBAAoB,EAAE,UAAC,GAAG,EAAE,KAAK;oBACrC,IAAI,GAAG,IAAI,IAAI;wBACX,iBAAiB,EAAE,CAAC;yBACnB,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE;wBACrB,YAAE,CAAC,QAAQ,CAAC,sBAAoB,EAAE,MAAM,EAAE,UAAC,GAAG,EAAE,IAAI;4BAChD,IAAI,GAAG,IAAI,IAAI;gCACX,MAAM,CAAC,IAAI,CAAC,CAAC;iCACZ;gCACD,IAAI;oCACA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;iCAC5B;gCAAC,OAAO,GAAG,EAAE;oCACV,MAAM,CAAC,IAAI,CAAC,CAAC;iCAChB;6BACJ;wBACL,CAAC,CAAC,CAAC;qBACN;;wBACG,iBAAiB,EAAE,CAAC;gBAC5B,CAAC,CAAC,CAAC;aACN;QACL,CAAC;QAED,iBAAiB,EAAE,CAAC;IACxB,CAAC,CAAC,CAAC;AACP,CAAC","file":"ImportUtils.js","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nexport async function importOrRequireFile(filePath: string): Promise<[result: any, moduleType: \"esm\" | \"commonjs\"]> {\n const tryToImport = async (): Promise<[any, \"esm\"]> => {\n // `Function` is required to make sure the `import` statement wil stay `import` after\n // transpilation and won't be converted to `require`\n return [await Function(\"return filePath => import(filePath)\")()(filePath), \"esm\"];\n };\n const tryToRequire = async (): Promise<[any, \"commonjs\"]> => {\n return [require(filePath), \"commonjs\"];\n };\n\n const extension = filePath.substring(filePath.lastIndexOf(\".\") + \".\".length);\n\n if (extension === \"mjs\" || extension === \"mts\")\n return tryToImport();\n else if (extension === \"cjs\" || extension === \"cts\")\n return tryToRequire();\n else if (extension === \"js\" || extension === \"ts\") {\n const packageJson = await getNearestPackageJson(filePath);\n\n if (packageJson != null) {\n const isModule = (packageJson as any)?.type === \"module\";\n\n if (isModule)\n return tryToImport();\n else\n return tryToRequire();\n } else\n return tryToRequire();\n }\n\n return tryToRequire();\n}\n\nfunction getNearestPackageJson(filePath: string): Promise<object | null> {\n return new Promise((accept) => {\n let currentPath = filePath;\n\n function searchPackageJson() {\n const nextPath = path.dirname(currentPath);\n\n if (currentPath === nextPath) // the top of the file tree is reached\n accept(null);\n else {\n currentPath = nextPath;\n const potentialPackageJson = path.join(currentPath, \"package.json\");\n\n fs.stat(potentialPackageJson, (err, stats) => {\n if (err != null)\n searchPackageJson();\n else if (stats.isFile()) {\n fs.readFile(potentialPackageJson, \"utf8\", (err, data) => {\n if (err != null)\n accept(null);\n else {\n try {\n accept(JSON.parse(data));\n } catch (err) {\n accept(null);\n }\n }\n });\n } else\n searchPackageJson();\n });\n }\n }\n\n searchPackageJson();\n });\n}\n"],"sourceRoot":".."}
|