typeorm 0.3.12-dev.4df969e → 0.3.12-dev.54ca9dd

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.
Files changed (72) hide show
  1. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +6 -0
  2. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  3. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +3 -1
  4. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  5. package/browser/driver/postgres/PostgresQueryRunner.js +1 -1
  6. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  7. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +12 -0
  8. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  9. package/browser/find-options/FindOperatorType.d.ts +1 -1
  10. package/browser/find-options/FindOperatorType.js.map +1 -1
  11. package/browser/find-options/FindOptionsWhere.d.ts +5 -1
  12. package/browser/find-options/FindOptionsWhere.js.map +1 -1
  13. package/browser/find-options/operator/JsonContains.d.ts +6 -0
  14. package/browser/find-options/operator/JsonContains.js +10 -0
  15. package/browser/find-options/operator/JsonContains.js.map +1 -0
  16. package/browser/index.d.ts +2 -0
  17. package/browser/index.js +2 -0
  18. package/browser/index.js.map +1 -1
  19. package/browser/metadata-builder/RelationJoinColumnBuilder.js +2 -1
  20. package/browser/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
  21. package/browser/migration/MigrationExecutor.js +1 -1
  22. package/browser/migration/MigrationExecutor.js.map +1 -1
  23. package/browser/naming-strategy/LegacyOracleNamingStrategy.d.ts +21 -0
  24. package/browser/naming-strategy/LegacyOracleNamingStrategy.js +46 -0
  25. package/browser/naming-strategy/LegacyOracleNamingStrategy.js.map +1 -0
  26. package/browser/persistence/SubjectTopoligicalSorter.js +2 -6
  27. package/browser/persistence/SubjectTopoligicalSorter.js.map +1 -1
  28. package/browser/platform/BrowserPlatformTools.js +2 -2
  29. package/browser/platform/BrowserPlatformTools.js.map +1 -1
  30. package/browser/query-builder/QueryBuilder.js +2 -0
  31. package/browser/query-builder/QueryBuilder.js.map +1 -1
  32. package/browser/query-builder/SelectQueryBuilder.d.ts +1 -1
  33. package/browser/query-builder/SelectQueryBuilder.js +1 -1
  34. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  35. package/browser/query-builder/WhereClause.d.ts +1 -1
  36. package/browser/query-builder/WhereClause.js.map +1 -1
  37. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +6 -0
  38. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  39. package/driver/better-sqlite3/BetterSqlite3Driver.js +3 -1
  40. package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  41. package/driver/postgres/PostgresQueryRunner.js +1 -1
  42. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  43. package/driver/sqlite-abstract/AbstractSqliteDriver.js +12 -0
  44. package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  45. package/find-options/FindOperatorType.d.ts +1 -1
  46. package/find-options/FindOperatorType.js.map +1 -1
  47. package/find-options/FindOptionsWhere.d.ts +5 -1
  48. package/find-options/FindOptionsWhere.js.map +1 -1
  49. package/find-options/operator/JsonContains.d.ts +6 -0
  50. package/find-options/operator/JsonContains.js +14 -0
  51. package/find-options/operator/JsonContains.js.map +1 -0
  52. package/index.d.ts +2 -0
  53. package/index.js +4 -1
  54. package/index.js.map +1 -1
  55. package/index.mjs +4 -0
  56. package/metadata-builder/RelationJoinColumnBuilder.js +2 -1
  57. package/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
  58. package/migration/MigrationExecutor.js +1 -1
  59. package/migration/MigrationExecutor.js.map +1 -1
  60. package/naming-strategy/LegacyOracleNamingStrategy.d.ts +21 -0
  61. package/naming-strategy/LegacyOracleNamingStrategy.js +50 -0
  62. package/naming-strategy/LegacyOracleNamingStrategy.js.map +1 -0
  63. package/package.json +1 -1
  64. package/persistence/SubjectTopoligicalSorter.js +2 -6
  65. package/persistence/SubjectTopoligicalSorter.js.map +1 -1
  66. package/query-builder/QueryBuilder.js +2 -0
  67. package/query-builder/QueryBuilder.js.map +1 -1
  68. package/query-builder/SelectQueryBuilder.d.ts +1 -1
  69. package/query-builder/SelectQueryBuilder.js +1 -1
  70. package/query-builder/SelectQueryBuilder.js.map +1 -1
  71. package/query-builder/WhereClause.d.ts +1 -1
  72. package/query-builder/WhereClause.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/migration/MigrationExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,OAAO,EAAE,qCAAqC,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IA+B1B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,UAAsB,EACtB,WAAyB;QADzB,eAAU,GAAV,UAAU,CAAY;QACtB,gBAAW,GAAX,WAAW,CAAc;QApCvC,4EAA4E;QAC5E,oBAAoB;QACpB,4EAA4E;QAE5E;;;;;WAKG;QACH,gBAAW,GAA4B,KAAK,CAAA;QA4BxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,CAAA;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAA;QAChD,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAA;QAClC,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAA;QAC9B,IAAI,CAAC,mBAAmB;YACpB,UAA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eAAe,CAAC;iBAC1B,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC;iBAC/C,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;iBACxC,aAAa,CAAC,UAAU,CAAC;iBACzB,OAAO,EAAE,CAAA;SACjB;IACL,CAAC;IAES,KAAK,CAAC,eAAe,CAC3B,QAAsD;QAEtD,MAAM,WAAW,GACb,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;QAE3D,IAAI;YACA,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAA;SAC/B;gBAAS;YACN,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;gBACnB,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;aAC9B;SACJ;IACL,CAAC;CACJ","file":"MigrationExecutor.js","sourcesContent":["import { Table } from \"../schema-builder/table/Table\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { Migration } from \"./Migration\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { MongoQueryRunner } from \"../driver/mongodb/MongoQueryRunner\"\nimport { ForbiddenTransactionModeOverrideError, TypeORMError } from \"../error\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Executes migrations: runs pending and reverts previously executed migrations.\n */\nexport class MigrationExecutor {\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 * Option to fake-run or fake-revert a migration, adding to the\n * executed migrations table, but not actually running it. This feature is\n * useful for when migrations are added after the fact or for\n * interoperability between applications which are desired to each keep\n * a consistent migration history.\n */\n fake: boolean\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(\n protected connection: DataSource,\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 =\n connection.options.migrationsTableName || \"migrations\"\n this.migrationsTable = this.connection.driver.buildTableName(\n this.migrationsTableName,\n schema,\n database,\n )\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\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n await queryRunner.beforeMigration()\n await (migration.instance as any).up(queryRunner)\n await queryRunner.afterMigration()\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(\n (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) =>\n this.insertExecutedMigration(q, migration),\n )\n }\n\n /**\n * Deletes an executed migration.\n */\n public deleteMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner((q) =>\n this.deleteExecutedMigration(q, migration),\n )\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 =\n this.queryRunner || this.connection.createQueryRunner()\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(\n queryRunner,\n )\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(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n\n if (executedMigration) {\n this.connection.logger.logSchemaBuild(\n `[X] ${executedMigration.id} ${migration.name}`,\n )\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 const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create the typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\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(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n 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 successfully\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(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n if (executedMigration) 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) await queryRunner.release()\n return []\n }\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${allMigrations.length} migrations were found in the source code.`,\n )\n if (lastTimeExecutedMigration)\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\n this.connection.logger.logSchemaBuild(\n `${pendingMigrations.length} migrations are new migrations must be executed.`,\n )\n\n if (this.transaction === \"all\") {\n // If we desire to run all migrations in a single transaction\n // but there is a migration that explicitly overrides the transaction mode\n // then we have to fail since we cannot properly resolve that intent\n // In theory we could support overrides that are set to `true`,\n // however to keep the interface more rigid, we fail those too\n const migrationsOverridingTransactionMode =\n pendingMigrations.filter(\n (migration) =>\n !(migration.instance?.transaction === undefined),\n )\n\n if (migrationsOverridingTransactionMode.length > 0) {\n const error = new ForbiddenTransactionModeOverrideError(\n migrationsOverridingTransactionMode,\n )\n this.connection.logger.logMigration(\n `Migrations failed, error: ${error.message}`,\n )\n throw error\n }\n }\n\n // Set the per-migration defaults for the transaction mode\n // so that we have one centralized place that controls this behavior\n\n // When transaction mode is `each` the default is to run in a transaction\n // When transaction mode is `none` the default is to not run in a transaction\n // When transaction mode is `all` the default is to not run in a transaction\n // since all the migrations are already running in one single transaction\n\n const txModeDefault = {\n each: true,\n none: false,\n all: false,\n }[this.transaction]\n\n for (const migration of pendingMigrations) {\n if (migration.instance) {\n const instanceTx = migration.instance.transaction\n\n if (instanceTx === undefined) {\n migration.transaction = txModeDefault\n } else {\n migration.transaction = instanceTx\n }\n }\n }\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.fake) {\n // directly insert migration record into the database if it is fake\n await this.insertExecutedMigration(queryRunner, migration)\n\n // nothing else needs to be done, continue to next migration\n continue\n }\n\n if (migration.transaction && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n await migration\n .instance!.up(queryRunner)\n .catch((error) => {\n // informative log about migration failure\n this.connection.logger.logMigration(\n `Migration \"${migration.name}\" failed, error: ${error?.message}`,\n )\n throw error\n })\n .then(async () => {\n // now when migration is executed we need to insert record about it into the database\n await this.insertExecutedMigration(\n queryRunner,\n migration,\n )\n // commit transaction if we started it\n if (migration.transaction && transactionStartedByUs)\n await queryRunner.commitTransaction()\n })\n .then(() => {\n // informative log about migration success\n successMigrations.push(migration)\n this.connection.logger.logSchemaBuild(\n `Migration ${migration.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } executed successfully.`,\n )\n })\n }\n\n // commit transaction if we started it\n if (this.transaction === \"all\" && transactionStartedByUs)\n await queryRunner.commitTransaction()\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n }\n return successMigrations\n }\n\n /**\n * Reverts last migration that were run.\n */\n async undoLastMigration(): Promise<void> {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\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(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n this.getLatestExecutedMigration(executedMigrations)\n\n // if no migrations found in the database then nothing to revert\n if (!lastTimeExecutedMigration) {\n this.connection.logger.logSchemaBuild(\n `No migrations was found in the database. Nothing to revert!`,\n )\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(\n (migration) => migration.name === lastTimeExecutedMigration!.name,\n )\n\n // if no migrations found in the database then nothing to revert\n if (!migrationToRevert)\n throw new TypeORMError(\n `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\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\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 if (!this.fake) {\n await queryRunner.beforeMigration()\n await migrationToRevert.instance!.down(queryRunner)\n await queryRunner.afterMigration()\n }\n\n await this.deleteExecutedMigration(queryRunner, migrationToRevert)\n this.connection.logger.logSchemaBuild(\n `Migration ${migrationToRevert.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } reverted successfully.`,\n )\n\n // commit transaction if we started it\n if (transactionStartedByUs) await queryRunner.commitTransaction()\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) 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(\n queryRunner: QueryRunner,\n ): Promise<void> {\n // If driver is mongo no need to create\n if (this.connection.driver.options.type === \"mongodb\") {\n return\n }\n const tableExist = await queryRunner.hasTable(this.migrationsTable) // todo: table name should be configurable\n if (!tableExist) {\n await queryRunner.createTable(\n new Table({\n database: this.migrationsDatabase,\n schema: this.migrationsSchema,\n name: this.migrationsTable,\n columns: [\n {\n name: \"id\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationId,\n }),\n isGenerated: true,\n generationStrategy: \"increment\",\n isPrimary: true,\n isNullable: false,\n },\n {\n name: \"timestamp\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"name\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationName,\n }),\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(\n queryRunner: QueryRunner,\n ): Promise<Migration[]> {\n if (this.connection.driver.options.type === \"mongodb\") {\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(\n parseInt(migrationRaw[\"id\"]),\n parseInt(migrationRaw[\"timestamp\"]),\n migrationRaw[\"name\"],\n )\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 =\n migration.name || (migration.constructor as any).name\n const migrationTimestamp = parseInt(\n migrationClassName.substr(-13),\n 10,\n )\n if (!migrationTimestamp || isNaN(migrationTimestamp)) {\n throw new TypeORMError(\n `${migrationClassName} migration name is wrong. Migration class name should have a JavaScript timestamp appended.`,\n )\n }\n\n return new Migration(\n undefined,\n migrationTimestamp,\n migrationClassName,\n migration,\n )\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(\n new Set(\n migrationNames.filter(\n (migrationName, index) =>\n migrationNames.indexOf(migrationName) < index,\n ),\n ),\n )\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(\n migrations: Migration[],\n ): Migration | undefined {\n const sortedMigrations = migrations\n .map((migration) => migration)\n .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(\n sortedMigrations: Migration[],\n ): 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(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const values: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n values[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n values[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n values[\"timestamp\"] = migration.timestamp\n values[\"name\"] = migration.name\n }\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .insertOne(values)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .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(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const conditions: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n conditions[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n conditions[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n conditions[\"timestamp\"] = migration.timestamp\n conditions[\"name\"] = migration.name\n }\n\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .deleteOne(conditions)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .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 protected async withQueryRunner<T extends any>(\n callback: (queryRunner: QueryRunner) => T | Promise<T>,\n ) {\n const queryRunner =\n 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":["../browser/src/migration/MigrationExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,OAAO,EAAE,qCAAqC,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IA+B1B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,UAAsB,EACtB,WAAyB;QADzB,eAAU,GAAV,UAAU,CAAY;QACtB,gBAAW,GAAX,WAAW,CAAc;QApCvC,4EAA4E;QAC5E,oBAAoB;QACpB,4EAA4E;QAE5E;;;;;WAKG;QACH,gBAAW,GAA4B,KAAK,CAAA;QA4BxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,CAAA;QACxD,MAAM,QAAQ,GAAG,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SAAS,CAAC,UAAU,CAAC,CAAA;SAC7B;aAAM;YACH,MAAM,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;YACnD,MAAM,EAAE;iBACH,MAAM,EAAE;iBACR,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;iBAC1B,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC;iBAC/C,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;iBACxC,aAAa,CAAC,UAAU,CAAC;iBACzB,OAAO,EAAE,CAAA;SACjB;IACL,CAAC;IAES,KAAK,CAAC,eAAe,CAC3B,QAAsD;QAEtD,MAAM,WAAW,GACb,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;QAE3D,IAAI;YACA,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAA;SAC/B;gBAAS;YACN,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;gBACnB,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;aAC9B;SACJ;IACL,CAAC;CACJ","file":"MigrationExecutor.js","sourcesContent":["import { Table } from \"../schema-builder/table/Table\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { Migration } from \"./Migration\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { MongoQueryRunner } from \"../driver/mongodb/MongoQueryRunner\"\nimport { ForbiddenTransactionModeOverrideError, TypeORMError } from \"../error\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Executes migrations: runs pending and reverts previously executed migrations.\n */\nexport class MigrationExecutor {\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 * Option to fake-run or fake-revert a migration, adding to the\n * executed migrations table, but not actually running it. This feature is\n * useful for when migrations are added after the fact or for\n * interoperability between applications which are desired to each keep\n * a consistent migration history.\n */\n fake: boolean\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(\n protected connection: DataSource,\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 =\n connection.options.migrationsTableName || \"migrations\"\n this.migrationsTable = this.connection.driver.buildTableName(\n this.migrationsTableName,\n schema,\n database,\n )\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\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n await queryRunner.beforeMigration()\n await (migration.instance as any).up(queryRunner)\n await queryRunner.afterMigration()\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(\n (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) =>\n this.insertExecutedMigration(q, migration),\n )\n }\n\n /**\n * Deletes an executed migration.\n */\n public deleteMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner((q) =>\n this.deleteExecutedMigration(q, migration),\n )\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 =\n this.queryRunner || this.connection.createQueryRunner()\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(\n queryRunner,\n )\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(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n\n if (executedMigration) {\n this.connection.logger.logSchemaBuild(\n `[X] ${executedMigration.id} ${migration.name}`,\n )\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 const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create the typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\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(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n 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 successfully\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(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n if (executedMigration) 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) await queryRunner.release()\n return []\n }\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${allMigrations.length} migrations were found in the source code.`,\n )\n if (lastTimeExecutedMigration)\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\n this.connection.logger.logSchemaBuild(\n `${pendingMigrations.length} migrations are new migrations must be executed.`,\n )\n\n if (this.transaction === \"all\") {\n // If we desire to run all migrations in a single transaction\n // but there is a migration that explicitly overrides the transaction mode\n // then we have to fail since we cannot properly resolve that intent\n // In theory we could support overrides that are set to `true`,\n // however to keep the interface more rigid, we fail those too\n const migrationsOverridingTransactionMode =\n pendingMigrations.filter(\n (migration) =>\n !(migration.instance?.transaction === undefined),\n )\n\n if (migrationsOverridingTransactionMode.length > 0) {\n const error = new ForbiddenTransactionModeOverrideError(\n migrationsOverridingTransactionMode,\n )\n this.connection.logger.logMigration(\n `Migrations failed, error: ${error.message}`,\n )\n throw error\n }\n }\n\n // Set the per-migration defaults for the transaction mode\n // so that we have one centralized place that controls this behavior\n\n // When transaction mode is `each` the default is to run in a transaction\n // When transaction mode is `none` the default is to not run in a transaction\n // When transaction mode is `all` the default is to not run in a transaction\n // since all the migrations are already running in one single transaction\n\n const txModeDefault = {\n each: true,\n none: false,\n all: false,\n }[this.transaction]\n\n for (const migration of pendingMigrations) {\n if (migration.instance) {\n const instanceTx = migration.instance.transaction\n\n if (instanceTx === undefined) {\n migration.transaction = txModeDefault\n } else {\n migration.transaction = instanceTx\n }\n }\n }\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.fake) {\n // directly insert migration record into the database if it is fake\n await this.insertExecutedMigration(queryRunner, migration)\n\n // nothing else needs to be done, continue to next migration\n continue\n }\n\n if (migration.transaction && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n await migration\n .instance!.up(queryRunner)\n .catch((error) => {\n // informative log about migration failure\n this.connection.logger.logMigration(\n `Migration \"${migration.name}\" failed, error: ${error?.message}`,\n )\n throw error\n })\n .then(async () => {\n // now when migration is executed we need to insert record about it into the database\n await this.insertExecutedMigration(\n queryRunner,\n migration,\n )\n // commit transaction if we started it\n if (migration.transaction && transactionStartedByUs)\n await queryRunner.commitTransaction()\n })\n .then(() => {\n // informative log about migration success\n successMigrations.push(migration)\n this.connection.logger.logSchemaBuild(\n `Migration ${migration.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } executed successfully.`,\n )\n })\n }\n\n // commit transaction if we started it\n if (this.transaction === \"all\" && transactionStartedByUs)\n await queryRunner.commitTransaction()\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n }\n return successMigrations\n }\n\n /**\n * Reverts last migration that were run.\n */\n async undoLastMigration(): Promise<void> {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\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(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n this.getLatestExecutedMigration(executedMigrations)\n\n // if no migrations found in the database then nothing to revert\n if (!lastTimeExecutedMigration) {\n this.connection.logger.logSchemaBuild(\n `No migrations were found in the database. Nothing to revert!`,\n )\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(\n (migration) => migration.name === lastTimeExecutedMigration!.name,\n )\n\n // if no migrations found in the database then nothing to revert\n if (!migrationToRevert)\n throw new TypeORMError(\n `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\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\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 if (!this.fake) {\n await queryRunner.beforeMigration()\n await migrationToRevert.instance!.down(queryRunner)\n await queryRunner.afterMigration()\n }\n\n await this.deleteExecutedMigration(queryRunner, migrationToRevert)\n this.connection.logger.logSchemaBuild(\n `Migration ${migrationToRevert.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } reverted successfully.`,\n )\n\n // commit transaction if we started it\n if (transactionStartedByUs) await queryRunner.commitTransaction()\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) 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(\n queryRunner: QueryRunner,\n ): Promise<void> {\n // If driver is mongo no need to create\n if (this.connection.driver.options.type === \"mongodb\") {\n return\n }\n const tableExist = await queryRunner.hasTable(this.migrationsTable) // todo: table name should be configurable\n if (!tableExist) {\n await queryRunner.createTable(\n new Table({\n database: this.migrationsDatabase,\n schema: this.migrationsSchema,\n name: this.migrationsTable,\n columns: [\n {\n name: \"id\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationId,\n }),\n isGenerated: true,\n generationStrategy: \"increment\",\n isPrimary: true,\n isNullable: false,\n },\n {\n name: \"timestamp\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"name\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationName,\n }),\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(\n queryRunner: QueryRunner,\n ): Promise<Migration[]> {\n if (this.connection.driver.options.type === \"mongodb\") {\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(\n parseInt(migrationRaw[\"id\"]),\n parseInt(migrationRaw[\"timestamp\"]),\n migrationRaw[\"name\"],\n )\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 =\n migration.name || (migration.constructor as any).name\n const migrationTimestamp = parseInt(\n migrationClassName.substr(-13),\n 10,\n )\n if (!migrationTimestamp || isNaN(migrationTimestamp)) {\n throw new TypeORMError(\n `${migrationClassName} migration name is wrong. Migration class name should have a JavaScript timestamp appended.`,\n )\n }\n\n return new Migration(\n undefined,\n migrationTimestamp,\n migrationClassName,\n migration,\n )\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(\n new Set(\n migrationNames.filter(\n (migrationName, index) =>\n migrationNames.indexOf(migrationName) < index,\n ),\n ),\n )\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(\n migrations: Migration[],\n ): Migration | undefined {\n const sortedMigrations = migrations\n .map((migration) => migration)\n .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(\n sortedMigrations: Migration[],\n ): 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(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const values: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n values[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n values[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n values[\"timestamp\"] = migration.timestamp\n values[\"name\"] = migration.name\n }\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .insertOne(values)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .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(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const conditions: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n conditions[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n conditions[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n conditions[\"timestamp\"] = migration.timestamp\n conditions[\"name\"] = migration.name\n }\n\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .deleteOne(conditions)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .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 protected async withQueryRunner<T extends any>(\n callback: (queryRunner: QueryRunner) => T | Promise<T>,\n ) {\n const queryRunner =\n 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":".."}
@@ -0,0 +1,21 @@
1
+ import { NamingStrategyInterface } from "./NamingStrategyInterface";
2
+ import { DefaultNamingStrategy } from "./DefaultNamingStrategy";
3
+ /**
4
+ * Shorten strategy
5
+ */
6
+ export declare type ShortenStrategy = "truncate" | "hash";
7
+ /**
8
+ * Naming strategy for legacy Oracle database with 30 bytes identifier limit.
9
+ *
10
+ * Currently, only column name must be shorten in order to avoid ORA-00972.
11
+ * Issues with other identifiers were fixed.
12
+ */
13
+ export declare class LegacyOracleNamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
14
+ readonly IDENTIFIER_MAX_SIZE = 30;
15
+ readonly DEFAULT_COLUMN_PREFIX = "COL_";
16
+ protected shortenStrategy: ShortenStrategy;
17
+ constructor(shortenStrategy?: ShortenStrategy);
18
+ columnName(propertyName: string, customName: string, embeddedPrefixes: string[]): string;
19
+ protected hashIdentifier(input: string, prefix: string): string;
20
+ protected truncateIdentifier(input: string): string;
21
+ }
@@ -0,0 +1,46 @@
1
+ import { RandomGenerator } from "../util/RandomGenerator";
2
+ import { DefaultNamingStrategy } from "./DefaultNamingStrategy";
3
+ import { TypeORMError } from "../error";
4
+ /**
5
+ * Naming strategy for legacy Oracle database with 30 bytes identifier limit.
6
+ *
7
+ * Currently, only column name must be shorten in order to avoid ORA-00972.
8
+ * Issues with other identifiers were fixed.
9
+ */
10
+ export class LegacyOracleNamingStrategy extends DefaultNamingStrategy {
11
+ constructor(shortenStrategy = "hash") {
12
+ super();
13
+ this.IDENTIFIER_MAX_SIZE = 30;
14
+ this.DEFAULT_COLUMN_PREFIX = "COL_";
15
+ this.shortenStrategy = shortenStrategy;
16
+ }
17
+ columnName(propertyName, customName, embeddedPrefixes) {
18
+ const longName = super.columnName(propertyName, customName, embeddedPrefixes);
19
+ if (this.shortenStrategy === "truncate") {
20
+ return this.truncateIdentifier(longName);
21
+ }
22
+ else if (this.shortenStrategy === "hash") {
23
+ return this.hashIdentifier(longName, this.DEFAULT_COLUMN_PREFIX);
24
+ }
25
+ else {
26
+ throw new TypeORMError(`Invalid shortenStrategy`);
27
+ }
28
+ }
29
+ hashIdentifier(input, prefix) {
30
+ if (prefix.length >= this.IDENTIFIER_MAX_SIZE) {
31
+ throw new TypeORMError(`Prefix must be shorter than IDENTIFIER_MAX_SIZE`);
32
+ }
33
+ return (prefix +
34
+ RandomGenerator.sha1(input).substring(0, this.IDENTIFIER_MAX_SIZE - prefix.length));
35
+ }
36
+ truncateIdentifier(input) {
37
+ if (input.length > this.IDENTIFIER_MAX_SIZE) {
38
+ return input.substring(0, this.IDENTIFIER_MAX_SIZE);
39
+ }
40
+ else {
41
+ return input;
42
+ }
43
+ }
44
+ }
45
+
46
+ //# sourceMappingURL=LegacyOracleNamingStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../browser/src/naming-strategy/LegacyOracleNamingStrategy.ts"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AM,GAAG,IAAI,CAAC,mBAAmB,EAAE;YACzC,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAA;SACtD;aAAM;YACH,OAAO,KAAK,CAAA;SACf;IACL,CAAC;CACJ","file":"LegacyOracleNamingStrategy.js","sourcesContent":["import { NamingStrategyInterface } from \"./NamingStrategyInterface\"\nimport { RandomGenerator } from \"../util/RandomGenerator\"\nimport { DefaultNamingStrategy } from \"./DefaultNamingStrategy\"\nimport { TypeORMError } from \"../error\"\n\n/**\n * Shorten strategy\n */\nexport type ShortenStrategy = \"truncate\" | \"hash\"\n\n/**\n * Naming strategy for legacy Oracle database with 30 bytes identifier limit.\n *\n * Currently, only column name must be shorten in order to avoid ORA-00972.\n * Issues with other identifiers were fixed.\n */\nexport class LegacyOracleNamingStrategy\n extends DefaultNamingStrategy\n implements NamingStrategyInterface\n{\n public readonly IDENTIFIER_MAX_SIZE = 30\n public readonly DEFAULT_COLUMN_PREFIX = \"COL_\"\n protected shortenStrategy: ShortenStrategy\n\n constructor(shortenStrategy: ShortenStrategy = \"hash\") {\n super()\n this.shortenStrategy = shortenStrategy\n }\n\n columnName(\n propertyName: string,\n customName: string,\n embeddedPrefixes: string[],\n ): string {\n const longName: string = super.columnName(\n propertyName,\n customName,\n embeddedPrefixes,\n )\n if (this.shortenStrategy === \"truncate\") {\n return this.truncateIdentifier(longName)\n } else if (this.shortenStrategy === \"hash\") {\n return this.hashIdentifier(longName, this.DEFAULT_COLUMN_PREFIX)\n } else {\n throw new TypeORMError(`Invalid shortenStrategy`)\n }\n }\n\n protected hashIdentifier(input: string, prefix: string): string {\n if (prefix.length >= this.IDENTIFIER_MAX_SIZE) {\n throw new TypeORMError(\n `Prefix must be shorter than IDENTIFIER_MAX_SIZE`,\n )\n }\n return (\n prefix +\n RandomGenerator.sha1(input).substring(\n 0,\n this.IDENTIFIER_MAX_SIZE - prefix.length,\n )\n )\n }\n\n protected truncateIdentifier(input: string): string {\n if (input.length > this.IDENTIFIER_MAX_SIZE) {\n return input.substring(0, this.IDENTIFIER_MAX_SIZE)\n } else {\n return input\n }\n }\n}\n"],"sourceRoot":".."}
@@ -39,12 +39,8 @@ export class SubjectTopoligicalSorter {
39
39
  // go thought each of them and find all subjects with sorted entity target
40
40
  // add those sorted targets and remove them from original array of targets
41
41
  sortedNonNullableEntityTargets.forEach((sortedEntityTarget) => {
42
- const entityTargetSubjects = this.subjects.filter((subject) => {
43
- var _a;
44
- return subject.metadata.targetName === sortedEntityTarget ||
45
- ((_a = subject.metadata.parentEntityMetadata) === null || _a === void 0 ? void 0 : _a.targetName) ===
46
- sortedEntityTarget;
47
- });
42
+ const entityTargetSubjects = this.subjects.filter((subject) => subject.metadata.targetName === sortedEntityTarget ||
43
+ subject.metadata.inheritanceTree.some((s) => s.name === sortedEntityTarget));
48
44
  sortedSubjects.push(...entityTargetSubjects);
49
45
  this.removeAlreadySorted(entityTargetSubjects);
50
46
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/persistence/SubjectTopoligicalSorter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IAejC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,QAAmB;QAC3B,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAA,CAAC,kDAAkD;QAChF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,IAAI,CAAC,SAA8B;QAC/B,uGAAuG;QACvG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAA;QAEhD,MAAM,cAAc,GAAc,EAAE,CAAA;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IAAI,CAAA;YAC3B,CAAC,CAAC,CAAA;YACF,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE;gBACvB,IAAI,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gBACrC,GAAG;oBACC,IAAI,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;oBAC5B,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;iBAC5C,QAAQ,CAAC,EAAC;aACd;YAED,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;QAC3B,CAAC;QAED,OAAO,MAAM,CAAA;IACjB,CAAC;CACJ","file":"SubjectTopoligicalSorter.js","sourcesContent":["import { Subject } from \"./Subject\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { TypeORMError } from \"../error\"\n\n/**\n * Orders insert or remove subjects in proper order (using topological sorting)\n * to make sure insert or remove operations are executed in a proper order.\n */\nexport class SubjectTopoligicalSorter {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Insert subjects needs to be sorted.\n */\n subjects: Subject[]\n\n /**\n * Unique list of entity metadatas of this subject.\n */\n metadatas: EntityMetadata[]\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(subjects: Subject[]) {\n this.subjects = [...subjects] // copy subjects to prevent changing of sent array\n this.metadatas = this.getUniqueMetadatas(this.subjects)\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sorts (orders) subjects in their topological order.\n */\n sort(direction: \"insert\" | \"delete\"): Subject[] {\n // if there are no metadatas it probably mean there is no subjects... we don't have to do anything here\n if (!this.metadatas.length) return this.subjects\n\n const sortedSubjects: Subject[] = []\n\n // first if we sort for deletion all junction subjects\n // junction subjects are subjects without entity and database entity set\n if (direction === \"delete\") {\n const junctionSubjects = this.subjects.filter(\n (subject) => !subject.entity && !subject.databaseEntity,\n )\n sortedSubjects.push(...junctionSubjects)\n this.removeAlreadySorted(junctionSubjects)\n }\n\n // next we always insert entities with non-nullable relations, sort them first\n const nonNullableDependencies = this.getNonNullableDependencies()\n let sortedNonNullableEntityTargets = this.toposort(\n nonNullableDependencies,\n )\n if (direction === \"insert\")\n sortedNonNullableEntityTargets =\n sortedNonNullableEntityTargets.reverse()\n\n // so we have a sorted entity targets\n // go thought each of them and find all subjects with sorted entity target\n // add those sorted targets and remove them from original array of targets\n sortedNonNullableEntityTargets.forEach((sortedEntityTarget) => {\n const entityTargetSubjects = this.subjects.filter(\n (subject) =>\n subject.metadata.targetName === sortedEntityTarget ||\n subject.metadata.parentEntityMetadata?.targetName ===\n sortedEntityTarget,\n )\n sortedSubjects.push(...entityTargetSubjects)\n this.removeAlreadySorted(entityTargetSubjects)\n })\n\n // next sort all other entities\n // same process as in above but with other entities\n const otherDependencies: string[][] = this.getDependencies()\n let sortedOtherEntityTargets = this.toposort(otherDependencies)\n if (direction === \"insert\")\n sortedOtherEntityTargets = sortedOtherEntityTargets.reverse()\n\n sortedOtherEntityTargets.forEach((sortedEntityTarget) => {\n const entityTargetSubjects = this.subjects.filter(\n (subject) => subject.metadata.targetName === sortedEntityTarget,\n )\n sortedSubjects.push(...entityTargetSubjects)\n this.removeAlreadySorted(entityTargetSubjects)\n })\n\n // if we have something left in the subjects add them as well\n sortedSubjects.push(...this.subjects)\n return sortedSubjects\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Removes already sorted subjects from this.subjects list of subjects.\n */\n protected removeAlreadySorted(subjects: Subject[]) {\n subjects.forEach((subject) => {\n this.subjects.splice(this.subjects.indexOf(subject), 1)\n })\n }\n\n /**\n * Extracts all unique metadatas from the given subjects.\n */\n protected getUniqueMetadatas(subjects: Subject[]) {\n const metadatas: EntityMetadata[] = []\n subjects.forEach((subject) => {\n if (metadatas.indexOf(subject.metadata) === -1)\n metadatas.push(subject.metadata)\n })\n return metadatas\n }\n\n /**\n * Gets dependency tree for all entity metadatas with non-nullable relations.\n * We need to execute insertions first for entities which non-nullable relations.\n */\n protected getNonNullableDependencies(): string[][] {\n return this.metadatas.reduce((dependencies, metadata) => {\n metadata.relationsWithJoinColumns.forEach((relation) => {\n if (relation.isNullable) return\n\n dependencies.push([\n metadata.targetName,\n relation.inverseEntityMetadata.targetName,\n ])\n })\n return dependencies\n }, [] as string[][])\n }\n\n /**\n * Gets dependency tree for all entity metadatas with non-nullable relations.\n * We need to execute insertions first for entities which non-nullable relations.\n */\n protected getDependencies(): string[][] {\n return this.metadatas.reduce((dependencies, metadata) => {\n metadata.relationsWithJoinColumns.forEach((relation) => {\n // if relation is self-referenced we skip it\n if (relation.inverseEntityMetadata === metadata) return\n\n dependencies.push([\n metadata.targetName,\n relation.inverseEntityMetadata.targetName,\n ])\n })\n return dependencies\n }, [] as string[][])\n }\n\n /**\n * Sorts given graph using topological sorting algorithm.\n *\n * Algorithm is kindly taken from https://github.com/marcelklehr/toposort repository.\n */\n protected toposort(edges: any[][]) {\n function uniqueNodes(arr: any[]) {\n let res = []\n for (let i = 0, len = arr.length; i < len; i++) {\n let edge: any = arr[i]\n if (res.indexOf(edge[0]) < 0) res.push(edge[0])\n if (res.indexOf(edge[1]) < 0) res.push(edge[1])\n }\n return res\n }\n\n const nodes = uniqueNodes(edges)\n let cursor = nodes.length,\n sorted = new Array(cursor),\n visited: any = {},\n i = cursor\n\n while (i--) {\n if (!visited[i]) visit(nodes[i], i, [])\n }\n\n function visit(node: any, i: number, predecessors: any[]) {\n if (predecessors.indexOf(node) >= 0) {\n throw new TypeORMError(\n \"Cyclic dependency: \" + JSON.stringify(node),\n ) // todo: better error\n }\n\n if (!~nodes.indexOf(node)) {\n throw new TypeORMError(\n \"Found unknown node. Make sure to provided all involved nodes. Unknown node: \" +\n JSON.stringify(node),\n )\n }\n\n if (visited[i]) return\n visited[i] = true\n\n // outgoing edges\n let outgoing = edges.filter(function (edge) {\n return edge[0] === node\n })\n if ((i = outgoing.length)) {\n let preds = predecessors.concat(node)\n do {\n let child = outgoing[--i][1]\n visit(child, nodes.indexOf(child), preds)\n } while (i)\n }\n\n sorted[--cursor] = node\n }\n\n return sorted\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/persistence/SubjectTopoligicalSorter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IAejC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,QAAmB;QAC3B,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAA,CAAC,kDAAkD;QAChF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,IAAI,CAAC,SAA8B;QAC/B,uGAAuG;QACvG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAA;QAEhD,MAAM,cAAc,GAAc,EAAE,CAAA;QAEpC,sDAAsD;QACtD,wEAAwE;QACxE,IAAI,SAAS,KAAK,QAAQ,EAAE;YACxB,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CACzC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAC1D,CAAA;YACD,cAAc,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAA;YACxC,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAA;SAC7C;QAED,8EAA8E;QAC9E,MAAM,uBAAuB,GAAG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,CAAC,EAAC;aACd;YAED,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;QAC3B,CAAC;QAED,OAAO,MAAM,CAAA;IACjB,CAAC;CACJ","file":"SubjectTopoligicalSorter.js","sourcesContent":["import { Subject } from \"./Subject\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { TypeORMError } from \"../error\"\n\n/**\n * Orders insert or remove subjects in proper order (using topological sorting)\n * to make sure insert or remove operations are executed in a proper order.\n */\nexport class SubjectTopoligicalSorter {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Insert subjects needs to be sorted.\n */\n subjects: Subject[]\n\n /**\n * Unique list of entity metadatas of this subject.\n */\n metadatas: EntityMetadata[]\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(subjects: Subject[]) {\n this.subjects = [...subjects] // copy subjects to prevent changing of sent array\n this.metadatas = this.getUniqueMetadatas(this.subjects)\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sorts (orders) subjects in their topological order.\n */\n sort(direction: \"insert\" | \"delete\"): Subject[] {\n // if there are no metadatas it probably mean there is no subjects... we don't have to do anything here\n if (!this.metadatas.length) return this.subjects\n\n const sortedSubjects: Subject[] = []\n\n // first if we sort for deletion all junction subjects\n // junction subjects are subjects without entity and database entity set\n if (direction === \"delete\") {\n const junctionSubjects = this.subjects.filter(\n (subject) => !subject.entity && !subject.databaseEntity,\n )\n sortedSubjects.push(...junctionSubjects)\n this.removeAlreadySorted(junctionSubjects)\n }\n\n // next we always insert entities with non-nullable relations, sort them first\n const nonNullableDependencies = this.getNonNullableDependencies()\n let sortedNonNullableEntityTargets = this.toposort(\n nonNullableDependencies,\n )\n if (direction === \"insert\")\n sortedNonNullableEntityTargets =\n sortedNonNullableEntityTargets.reverse()\n\n // so we have a sorted entity targets\n // go thought each of them and find all subjects with sorted entity target\n // add those sorted targets and remove them from original array of targets\n sortedNonNullableEntityTargets.forEach((sortedEntityTarget) => {\n const entityTargetSubjects = this.subjects.filter(\n (subject) =>\n subject.metadata.targetName === sortedEntityTarget ||\n subject.metadata.inheritanceTree.some(\n (s) => s.name === sortedEntityTarget,\n ),\n )\n sortedSubjects.push(...entityTargetSubjects)\n this.removeAlreadySorted(entityTargetSubjects)\n })\n\n // next sort all other entities\n // same process as in above but with other entities\n const otherDependencies: string[][] = this.getDependencies()\n let sortedOtherEntityTargets = this.toposort(otherDependencies)\n if (direction === \"insert\")\n sortedOtherEntityTargets = sortedOtherEntityTargets.reverse()\n\n sortedOtherEntityTargets.forEach((sortedEntityTarget) => {\n const entityTargetSubjects = this.subjects.filter(\n (subject) => subject.metadata.targetName === sortedEntityTarget,\n )\n sortedSubjects.push(...entityTargetSubjects)\n this.removeAlreadySorted(entityTargetSubjects)\n })\n\n // if we have something left in the subjects add them as well\n sortedSubjects.push(...this.subjects)\n return sortedSubjects\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Removes already sorted subjects from this.subjects list of subjects.\n */\n protected removeAlreadySorted(subjects: Subject[]) {\n subjects.forEach((subject) => {\n this.subjects.splice(this.subjects.indexOf(subject), 1)\n })\n }\n\n /**\n * Extracts all unique metadatas from the given subjects.\n */\n protected getUniqueMetadatas(subjects: Subject[]) {\n const metadatas: EntityMetadata[] = []\n subjects.forEach((subject) => {\n if (metadatas.indexOf(subject.metadata) === -1)\n metadatas.push(subject.metadata)\n })\n return metadatas\n }\n\n /**\n * Gets dependency tree for all entity metadatas with non-nullable relations.\n * We need to execute insertions first for entities which non-nullable relations.\n */\n protected getNonNullableDependencies(): string[][] {\n return this.metadatas.reduce((dependencies, metadata) => {\n metadata.relationsWithJoinColumns.forEach((relation) => {\n if (relation.isNullable) return\n\n dependencies.push([\n metadata.targetName,\n relation.inverseEntityMetadata.targetName,\n ])\n })\n return dependencies\n }, [] as string[][])\n }\n\n /**\n * Gets dependency tree for all entity metadatas with non-nullable relations.\n * We need to execute insertions first for entities which non-nullable relations.\n */\n protected getDependencies(): string[][] {\n return this.metadatas.reduce((dependencies, metadata) => {\n metadata.relationsWithJoinColumns.forEach((relation) => {\n // if relation is self-referenced we skip it\n if (relation.inverseEntityMetadata === metadata) return\n\n dependencies.push([\n metadata.targetName,\n relation.inverseEntityMetadata.targetName,\n ])\n })\n return dependencies\n }, [] as string[][])\n }\n\n /**\n * Sorts given graph using topological sorting algorithm.\n *\n * Algorithm is kindly taken from https://github.com/marcelklehr/toposort repository.\n */\n protected toposort(edges: any[][]) {\n function uniqueNodes(arr: any[]) {\n let res = []\n for (let i = 0, len = arr.length; i < len; i++) {\n let edge: any = arr[i]\n if (res.indexOf(edge[0]) < 0) res.push(edge[0])\n if (res.indexOf(edge[1]) < 0) res.push(edge[1])\n }\n return res\n }\n\n const nodes = uniqueNodes(edges)\n let cursor = nodes.length,\n sorted = new Array(cursor),\n visited: any = {},\n i = cursor\n\n while (i--) {\n if (!visited[i]) visit(nodes[i], i, [])\n }\n\n function visit(node: any, i: number, predecessors: any[]) {\n if (predecessors.indexOf(node) >= 0) {\n throw new TypeORMError(\n \"Cyclic dependency: \" + JSON.stringify(node),\n ) // todo: better error\n }\n\n if (!~nodes.indexOf(node)) {\n throw new TypeORMError(\n \"Found unknown node. Make sure to provided all involved nodes. Unknown node: \" +\n JSON.stringify(node),\n )\n }\n\n if (visited[i]) return\n visited[i] = true\n\n // outgoing edges\n let outgoing = edges.filter(function (edge) {\n return edge[0] === node\n })\n if ((i = outgoing.length)) {\n let preds = predecessors.concat(node)\n do {\n let child = outgoing[--i][1]\n visit(child, nodes.indexOf(child), preds)\n } while (i)\n }\n\n sorted[--cursor] = node\n }\n\n return sorted\n }\n}\n"],"sourceRoot":".."}
@@ -130,11 +130,11 @@ export class Readable {
130
130
  }
131
131
  export class Writable {
132
132
  }
133
- if (typeof window !== "undefined") {
133
+ if (typeof window !== "undefined" && typeof require !== "undefined") {
134
134
  window.Buffer = require("buffer/").Buffer;
135
135
  }
136
136
  // NativeScript uses global, not window
137
- if (typeof global !== "undefined") {
137
+ if (typeof global !== "undefined" && typeof require !== "undefined") {
138
138
  global.Buffer = require("buffer/").Buffer;
139
139
  }
140
140
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/platform/BrowserPlatformTools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IAOtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YAC/B,OAAO,MAAM,CAAA;SAChB;aAAM;YACH,uCAAuC;YACvC,OAAO,MAAM,CAAA;SAChB;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,gGAAgG,IAAI,KAAK,CAAC,CAAC;QAE/H,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAe;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,uGAAuG,OAAO,KAAK,CAAC,CAAC;QAEzI,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAe;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,qGAAqG,OAAO,KAAK,CAAC,CAAC;QAEvI,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAe;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,qGAAqG,OAAO,KAAK,CAAC,CAAC;QAEvI,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SA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C,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,MAAc,EAAE,KAAU;QACtC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,OAAY;QACvC,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,OAAe;QACtB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe;QACvB,OAAO,OAAO,CAAC;IACnB,CAAC;;AAtID;;GAEG;AACI,kBAAI,GAAqB,SAAS,CAAC;AAsI9C;;;GAGG;AACH,MAAM,OAAO,YAAY;CAAG;AAE5B,MAAM,OAAO,QAAQ;CAAG;AAExB,MAAM,OAAO,QAAQ;CAAG;AAYxB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IAC/B,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;CAC7C;AACD,uCAAuC;AACvC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IAC/B,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;CAC7C","file":"BrowserPlatformTools.js","sourcesContent":["/**\n * Browser's implementation of the platform-specific tools.\n *\n * This file gonna replace PlatformTools for browser environment.\n * For node.js environment this class is not getting packaged.\n * Don't use methods of this class in the code, use PlatformTools methods instead.\n */\nexport class PlatformTools {\n\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\"|\"node\" = \"browser\";\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n if (typeof window !== \"undefined\") {\n return window\n } else {\n // NativeScript uses global, not window\n return global\n }\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: require(\"${name}\").`);\n\n return \"\";\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\".\n */\n static pathNormalize(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync(\"${pathStr}\").`);\n\n return false;\n }\n\n static dotenv(pathStr: string): void {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: dotenv.config({ path: \"${pathStr}\" }).`);\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n // if (this.type === \"browser\")\n // throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env[\"${name}\"].`);\n return undefined;\n }\n\n static readFileSync(filename: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.readFileSync(\"${filename}\").`);\n return null;\n }\n\n static appendFileSync(filename: string, data: any) {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.appendFileSync(\"${filename}\").`);\n }\n\n static writeFile(path: string, data: any): Promise<void> {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.writeFile(\"${path}\").`);\n return Promise.reject(null);\n }\n\n /**\n * Highlights sql string to be print in the console.\n */\n static highlightSql(sql: string) {\n return sql;\n }\n\n /**\n * Highlights json string to be print in the console.\n */\n static highlightJson(json: string) {\n return json;\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger (but here without chalk)\n */\n static logInfo(prefix: string, info: any) {\n console.info(prefix + \" \", info);\n }\n\n static logError(prefix: string, error: any) {\n console.error(prefix + \" \", error);\n }\n\n static logWarn(prefix: string, warning: any) {\n console.warn(prefix + \" \", warning);\n }\n\n static log(message: string) {\n console.log(message);\n }\n\n static warn(message: string) {\n return message;\n }\n}\n\n/**\n * These classes are needed for stream operations or\n * in the mongodb driver. Both aren't supported in the browser.\n */\nexport class EventEmitter {}\n\nexport class Readable {}\n\nexport class Writable {}\n\nexport interface ReadStream {}\n\n/**\n * This loads a polyfill to enable Buffers in the browser.\n */\ninterface Window {\n Buffer: any;\n}\n\ndeclare var window: Window;\nif (typeof window !== \"undefined\") {\n window.Buffer = require(\"buffer/\").Buffer;\n}\n// NativeScript uses global, not window\nif (typeof global !== \"undefined\") {\n global.Buffer = require(\"buffer/\").Buffer;\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/platform/BrowserPlatformTools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IAOtB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YAC/B,OAAO,MAAM,CAAA;SAChB;aAAM;YACH,uCAAuC;YACvC,OAAO,MAAM,CAAA;SAChB;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,IAAY;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,gGAAgG,IAAI,KAAK,CAAC,CAAC;QAE/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AAO,QAAQ;CAAG;AAExB,MAAM,OAAO,QAAQ;CAAG;AAYxB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;IACjE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;CAC7C;AACD,uCAAuC;AACvC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;IACjE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;CAC7C","file":"BrowserPlatformTools.js","sourcesContent":["/**\n * Browser's implementation of the platform-specific tools.\n *\n * This file gonna replace PlatformTools for browser environment.\n * For node.js environment this class is not getting packaged.\n * Don't use methods of this class in the code, use PlatformTools methods instead.\n */\nexport class PlatformTools {\n\n /**\n * Type of the currently running platform.\n */\n static type: \"browser\"|\"node\" = \"browser\";\n\n /**\n * Gets global variable where global stuff can be stored.\n */\n static getGlobalVariable(): any {\n if (typeof window !== \"undefined\") {\n return window\n } else {\n // NativeScript uses global, not window\n return global\n }\n }\n\n /**\n * Loads (\"require\"-s) given file or package.\n * This operation only supports on node platform\n */\n static load(name: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: require(\"${name}\").`);\n\n return \"\";\n }\n\n /**\n * Normalizes given path. Does \"path.normalize\".\n */\n static pathNormalize(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Gets file extension. Does \"path.extname\".\n */\n static pathExtname(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Resolved given path. Does \"path.resolve\".\n */\n static pathResolve(pathStr: string): string {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve(\"${pathStr}\").`);\n\n return \"\";\n }\n\n /**\n * Synchronously checks if file exist. Does \"fs.existsSync\".\n */\n static fileExist(pathStr: string): boolean {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync(\"${pathStr}\").`);\n\n return false;\n }\n\n static dotenv(pathStr: string): void {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: dotenv.config({ path: \"${pathStr}\" }).`);\n }\n\n /**\n * Gets environment variable.\n */\n static getEnvVariable(name: string): any {\n // if (this.type === \"browser\")\n // throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env[\"${name}\"].`);\n return undefined;\n }\n\n static readFileSync(filename: string): any {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.readFileSync(\"${filename}\").`);\n return null;\n }\n\n static appendFileSync(filename: string, data: any) {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.appendFileSync(\"${filename}\").`);\n }\n\n static writeFile(path: string, data: any): Promise<void> {\n if (this.type === \"browser\")\n throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.writeFile(\"${path}\").`);\n return Promise.reject(null);\n }\n\n /**\n * Highlights sql string to be print in the console.\n */\n static highlightSql(sql: string) {\n return sql;\n }\n\n /**\n * Highlights json string to be print in the console.\n */\n static highlightJson(json: string) {\n return json;\n }\n\n /**\n * Logging functions needed by AdvancedConsoleLogger (but here without chalk)\n */\n static logInfo(prefix: string, info: any) {\n console.info(prefix + \" \", info);\n }\n\n static logError(prefix: string, error: any) {\n console.error(prefix + \" \", error);\n }\n\n static logWarn(prefix: string, warning: any) {\n console.warn(prefix + \" \", warning);\n }\n\n static log(message: string) {\n console.log(message);\n }\n\n static warn(message: string) {\n return message;\n }\n}\n\n/**\n * These classes are needed for stream operations or\n * in the mongodb driver. Both aren't supported in the browser.\n */\nexport class EventEmitter {}\n\nexport class Readable {}\n\nexport class Writable {}\n\nexport interface ReadStream {}\n\n/**\n * This loads a polyfill to enable Buffers in the browser.\n */\ninterface Window {\n Buffer: any;\n}\n\ndeclare var window: Window;\nif (typeof window !== \"undefined\" && typeof require !== \"undefined\") {\n window.Buffer = require(\"buffer/\").Buffer;\n}\n// NativeScript uses global, not window\nif (typeof global !== \"undefined\" && typeof require !== \"undefined\") {\n global.Buffer = require(\"buffer/\").Buffer;\n}\n"],"sourceRoot":".."}
@@ -679,6 +679,8 @@ export class QueryBuilder {
679
679
  return `${condition.parameters[0]} <= ${condition.parameters[1]}`;
680
680
  case "arrayContains":
681
681
  return `${condition.parameters[0]} @> ${condition.parameters[1]}`;
682
+ case "jsonContains":
683
+ return `${condition.parameters[0]} ::jsonb @> ${condition.parameters[1]}`;
682
684
  case "arrayContainedBy":
683
685
  return `${condition.parameters[0]} <@ ${condition.parameters[1]}`;
684
686
  case "arrayOverlap":