typeorm 0.3.22-dev.834e856 → 0.3.22-dev.863caf1

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 (101) hide show
  1. package/browser/connection/ConnectionOptionsReader.js +5 -9
  2. package/browser/connection/ConnectionOptionsReader.js.map +1 -1
  3. package/browser/driver/DriverUtils.js +1 -2
  4. package/browser/driver/DriverUtils.js.map +1 -1
  5. package/browser/driver/aurora-mysql/AuroraMysqlDriver.js +1 -1
  6. package/browser/driver/aurora-mysql/AuroraMysqlDriver.js.map +1 -1
  7. package/browser/driver/cockroachdb/CockroachDriver.js +4 -6
  8. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  9. package/browser/driver/cockroachdb/CockroachQueryRunner.d.ts +1 -1
  10. package/browser/driver/cockroachdb/CockroachQueryRunner.js +7 -4
  11. package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  12. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +111 -142
  13. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  14. package/browser/driver/mongodb/MongoDriver.d.ts +2 -3
  15. package/browser/driver/mongodb/MongoDriver.js +57 -65
  16. package/browser/driver/mongodb/MongoDriver.js.map +1 -1
  17. package/browser/driver/mysql/MysqlDriver.js +8 -10
  18. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  19. package/browser/driver/mysql/MysqlQueryRunner.d.ts +1 -1
  20. package/browser/driver/mysql/MysqlQueryRunner.js +8 -2
  21. package/browser/driver/mysql/MysqlQueryRunner.js.map +1 -1
  22. package/browser/driver/oracle/OracleDriver.js +1 -1
  23. package/browser/driver/oracle/OracleDriver.js.map +1 -1
  24. package/browser/driver/postgres/PostgresDriver.d.ts +2 -1
  25. package/browser/driver/postgres/PostgresDriver.js +12 -18
  26. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  27. package/browser/driver/postgres/PostgresQueryRunner.d.ts +1 -1
  28. package/browser/driver/postgres/PostgresQueryRunner.js +8 -7
  29. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  30. package/browser/driver/sap/SapDriver.d.ts +4 -0
  31. package/browser/driver/sap/SapDriver.js +8 -10
  32. package/browser/driver/sap/SapDriver.js.map +1 -1
  33. package/browser/driver/sap/SapQueryRunner.d.ts +7 -0
  34. package/browser/driver/sap/SapQueryRunner.js +17 -10
  35. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  36. package/browser/driver/sqlserver/SqlServerDriver.js +1 -1
  37. package/browser/driver/sqlserver/SqlServerDriver.js.map +1 -1
  38. package/browser/index.d.ts +1 -0
  39. package/browser/index.js +1 -0
  40. package/browser/index.js.map +1 -1
  41. package/browser/migration/MigrationExecutor.js +2 -2
  42. package/browser/migration/MigrationExecutor.js.map +1 -1
  43. package/browser/query-builder/InsertQueryBuilder.js +2 -1
  44. package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
  45. package/browser/subscriber/event/QueryEvent.d.ts +1 -1
  46. package/browser/subscriber/event/QueryEvent.js.map +1 -1
  47. package/browser/util/VersionUtils.d.ts +1 -2
  48. package/browser/util/VersionUtils.js +14 -7
  49. package/browser/util/VersionUtils.js.map +1 -1
  50. package/commands/MigrationGenerateCommand.js +2 -2
  51. package/commands/MigrationGenerateCommand.js.map +1 -1
  52. package/connection/ConnectionOptionsReader.js +5 -9
  53. package/connection/ConnectionOptionsReader.js.map +1 -1
  54. package/driver/DriverUtils.js +1 -2
  55. package/driver/DriverUtils.js.map +1 -1
  56. package/driver/aurora-mysql/AuroraMysqlDriver.js +1 -1
  57. package/driver/aurora-mysql/AuroraMysqlDriver.js.map +1 -1
  58. package/driver/cockroachdb/CockroachDriver.js +4 -6
  59. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  60. package/driver/cockroachdb/CockroachQueryRunner.d.ts +1 -1
  61. package/driver/cockroachdb/CockroachQueryRunner.js +7 -4
  62. package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  63. package/driver/mongodb/MongoConnectionOptions.d.ts +111 -142
  64. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  65. package/driver/mongodb/MongoDriver.d.ts +2 -3
  66. package/driver/mongodb/MongoDriver.js +57 -65
  67. package/driver/mongodb/MongoDriver.js.map +1 -1
  68. package/driver/mysql/MysqlDriver.js +8 -10
  69. package/driver/mysql/MysqlDriver.js.map +1 -1
  70. package/driver/mysql/MysqlQueryRunner.d.ts +1 -1
  71. package/driver/mysql/MysqlQueryRunner.js +8 -2
  72. package/driver/mysql/MysqlQueryRunner.js.map +1 -1
  73. package/driver/oracle/OracleDriver.js +1 -1
  74. package/driver/oracle/OracleDriver.js.map +1 -1
  75. package/driver/postgres/PostgresDriver.d.ts +2 -1
  76. package/driver/postgres/PostgresDriver.js +12 -18
  77. package/driver/postgres/PostgresDriver.js.map +1 -1
  78. package/driver/postgres/PostgresQueryRunner.d.ts +1 -1
  79. package/driver/postgres/PostgresQueryRunner.js +8 -7
  80. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  81. package/driver/sap/SapDriver.d.ts +4 -0
  82. package/driver/sap/SapDriver.js +8 -10
  83. package/driver/sap/SapDriver.js.map +1 -1
  84. package/driver/sap/SapQueryRunner.d.ts +7 -0
  85. package/driver/sap/SapQueryRunner.js +17 -10
  86. package/driver/sap/SapQueryRunner.js.map +1 -1
  87. package/driver/sqlserver/SqlServerDriver.js +1 -1
  88. package/driver/sqlserver/SqlServerDriver.js.map +1 -1
  89. package/index.d.ts +1 -0
  90. package/index.js +1 -0
  91. package/index.js.map +1 -1
  92. package/migration/MigrationExecutor.js +2 -2
  93. package/migration/MigrationExecutor.js.map +1 -1
  94. package/package.json +1 -1
  95. package/query-builder/InsertQueryBuilder.js +2 -1
  96. package/query-builder/InsertQueryBuilder.js.map +1 -1
  97. package/subscriber/event/QueryEvent.d.ts +1 -1
  98. package/subscriber/event/QueryEvent.js.map +1 -1
  99. package/util/VersionUtils.d.ts +1 -2
  100. package/util/VersionUtils.js +14 -7
  101. package/util/VersionUtils.js.map +1 -1
@@ -1,4 +1,3 @@
1
- export type Version = [number, number, number];
2
1
  export declare class VersionUtils {
3
- static isGreaterOrEqual(version: string, targetVersion: string): boolean;
2
+ static isGreaterOrEqual(version: string | undefined, targetVersion: string): boolean;
4
3
  }
@@ -1,16 +1,23 @@
1
1
  export class VersionUtils {
2
2
  static isGreaterOrEqual(version, targetVersion) {
3
+ if (!version) {
4
+ return false;
5
+ }
3
6
  const v1 = parseVersion(version);
4
7
  const v2 = parseVersion(targetVersion);
5
- return (v1[0] > v2[0] ||
6
- (v1[0] === v2[0] && v1[1] > v2[1]) ||
7
- (v1[0] === v2[0] && v1[1] === v2[1] && v1[2] >= v2[2]));
8
+ for (let i = 0; i < v1.length && i < v2.length; i++) {
9
+ if (v1[i] > v2[i]) {
10
+ return true;
11
+ }
12
+ else if (v1[i] < v2[i]) {
13
+ return false;
14
+ }
15
+ }
16
+ return true;
8
17
  }
9
18
  }
10
- function parseVersion(version = "") {
11
- const v = [0, 0, 0];
12
- version.split(".").forEach((value, i) => (v[i] = parseInt(value, 10)));
13
- return v;
19
+ function parseVersion(version) {
20
+ return version.split(".").map((value) => parseInt(value, 10));
14
21
  }
15
22
 
16
23
  //# sourceMappingURL=VersionUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/util/VersionUtils.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;IACrB,MAAM,CAAC,gBAAgB,CAAC,OAAe,EAAE,aAAqB;QAC1D,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QAChC,MAAM,EAAE,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;QAEtC,OAAO,CACH,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YACb,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;YAClC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CACzD,CAAA;IACL,CAAC;CACJ;AAED,SAAS,YAAY,CAAC,UAAkB,EAAE;IACtC,MAAM,CAAC,GAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAE5B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAEtE,OAAO,CAAC,CAAA;AACZ,CAAC","file":"VersionUtils.js","sourcesContent":["export type Version = [number, number, number]\n\nexport class VersionUtils {\n static isGreaterOrEqual(version: string, targetVersion: string): boolean {\n const v1 = parseVersion(version)\n const v2 = parseVersion(targetVersion)\n\n return (\n v1[0] > v2[0] ||\n (v1[0] === v2[0] && v1[1] > v2[1]) ||\n (v1[0] === v2[0] && v1[1] === v2[1] && v1[2] >= v2[2])\n )\n }\n}\n\nfunction parseVersion(version: string = \"\"): Version {\n const v: Version = [0, 0, 0]\n\n version.split(\".\").forEach((value, i) => (v[i] = parseInt(value, 10)))\n\n return v\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/util/VersionUtils.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;IACrB,MAAM,CAAC,gBAAgB,CACnB,OAA2B,EAC3B,aAAqB;QAErB,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,KAAK,CAAA;QAChB,CAAC;QAED,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QAChC,MAAM,EAAE,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;QAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClD,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChB,OAAO,IAAI,CAAA;YACf,CAAC;iBAAM,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAA;YAChB,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AAED,SAAS,YAAY,CAAC,OAAe;IACjC,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAA;AACjE,CAAC","file":"VersionUtils.js","sourcesContent":["export class VersionUtils {\n static isGreaterOrEqual(\n version: string | undefined,\n targetVersion: string,\n ): boolean {\n if (!version) {\n return false\n }\n\n const v1 = parseVersion(version)\n const v2 = parseVersion(targetVersion)\n\n for (let i = 0; i < v1.length && i < v2.length; i++) {\n if (v1[i] > v2[i]) {\n return true\n } else if (v1[i] < v2[i]) {\n return false\n }\n }\n\n return true\n }\n}\n\nfunction parseVersion(version: string): number[] {\n return version.split(\".\").map((value) => parseInt(value, 10))\n}\n"],"sourceRoot":".."}
@@ -94,14 +94,14 @@ class MigrationGenerateCommand {
94
94
  }
95
95
  sqlInMemory.upQueries.forEach((upQuery) => {
96
96
  upSqls.push(" await queryRunner.query(`" +
97
- upQuery.query.replace(new RegExp("`", "g"), "\\`") +
97
+ upQuery.query.replaceAll("`", "\\`") +
98
98
  "`" +
99
99
  MigrationGenerateCommand.queryParams(upQuery.parameters) +
100
100
  ");");
101
101
  });
102
102
  sqlInMemory.downQueries.forEach((downQuery) => {
103
103
  downSqls.push(" await queryRunner.query(`" +
104
- downQuery.query.replace(new RegExp("`", "g"), "\\`") +
104
+ downQuery.query.replaceAll("`", "\\`") +
105
105
  "`" +
106
106
  MigrationGenerateCommand.queryParams(downQuery.parameters) +
107
107
  ");");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,uEAA6D;AAC7D,0DAAwB;AACxB,wDAAuB;AACvB,8DAA6B;AAG7B,6DAAyD;AACzD,qDAA+C;AAC/C,iDAA6C;AAE7C;;GAEG;AACH,MAAa,wBAAwB;IAArC;QACI,YAAO,GAAG,2BAA2B,CAAA;QACrC,aAAQ,GACJ,gFAAgF,CAAA;IAgRxF,CAAC;IA9QG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,4BAA4B;YACtC,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,QAAQ;YACd,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,4BAA4B;SACzC,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,+DAA+D;SACtE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,0EAA0E;SACjF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE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AAA;QAE5D,OAAO;;eAEA,aAAa;cACd,aAAa;;;EAGzB,MAAM,CAAC,IAAI,CAAC;CACb,CAAC;;;;EAIA,QAAQ,CAAC,IAAI,CAAC;CACf,CAAC;;;;CAID,CAAA;IACG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,qBAAqB,CAClC,IAAY,EACZ,SAAiB,EACjB,MAAgB,EAChB,QAAkB;QAElB,MAAM,aAAa,GAAG,GAAG,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS,EAAE,CAAA;QAE5D,OAAO,0BAA0B,aAAa;cACxC,aAAa;;;EAGzB,MAAM,CAAC,IAAI,CAAC;CACb,CAAC;;;;EAIA,QAAQ,CAAC,IAAI,CAAC;CACf,CAAC;;;CAGD,CAAA;IACG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,aAAa,CAAC,KAAa;QACxC,MAAM,cAAc,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QACxD,OAAO,CACH,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CACtE,CAAA;IACL,CAAC;CACJ;AAnRD,4DAmRC","file":"MigrationGenerateCommand.js","sourcesContent":["import { format } from \"@sqltools/formatter/lib/sqlFormatter\"\nimport ansi from \"ansis\"\nimport path from \"path\"\nimport process from \"process\"\nimport yargs from \"yargs\"\nimport { DataSource } from \"../data-source\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { camelCase } from \"../util/StringUtils\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n command = \"migration:generate <path>\"\n describe =\n \"Generates a new migration file with sql needs to be executed to update schema.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"path\", {\n type: \"string\",\n describe: \"Path of the migration file\",\n demandOption: true,\n })\n .option(\"dataSource\", {\n alias: \"d\",\n type: \"string\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe:\n \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe:\n \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments<any & { path: string }>) {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const extension = args.outputJs ? \".js\" : \".ts\"\n const fullPath = args.path.startsWith(\"/\")\n ? args.path\n : path.resolve(process.cwd(), args.path)\n const filename = timestamp + \"-\" + path.basename(fullPath) + extension\n\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const upSqls: string[] = [],\n downSqls: string[] = []\n\n try {\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach((upQuery) => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(\n upQuery.query,\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downQuery.query =\n MigrationGenerateCommand.prettifyQuery(\n downQuery.query,\n )\n })\n }\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n upSqls.push(\n \" await queryRunner.query(`\" +\n upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n upQuery.parameters,\n ) +\n \");\",\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downSqls.push(\n \" await queryRunner.query(`\" +\n downQuery.query.replace(\n new RegExp(\"`\", \"g\"),\n \"\\\\`\",\n ) +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n downQuery.parameters,\n ) +\n \");\",\n )\n })\n } finally {\n await dataSource.destroy()\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(\n ansi.green`No changes in database schema were found`,\n )\n process.exit(0)\n } else {\n console.log(\n ansi.yellow`No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`,\n )\n process.exit(1)\n }\n } else if (!args.path) {\n console.log(ansi.yellow`Please specify a migration path`)\n process.exit(1)\n }\n\n const fileContent = args.outputJs\n ? MigrationGenerateCommand.getJavascriptTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n : MigrationGenerateCommand.getTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n\n if (args.check) {\n console.log(\n ansi.yellow`Unexpected changes in database schema were found in check mode:\\n\\n${ansi.white(\n fileContent,\n )}`,\n )\n process.exit(1)\n }\n\n if (args.dryrun) {\n console.log(\n ansi.green(\n `Migration ${ansi.blue(\n fullPath + extension,\n )} has content:\\n\\n${ansi.white(fileContent)}`,\n ),\n )\n } else {\n const migrationFileName =\n path.dirname(fullPath) + \"/\" + filename\n await CommandUtils.createFile(migrationFileName, fileContent)\n\n console.log(\n ansi.green`Migration ${ansi.blue(\n migrationFileName,\n )} has been generated successfully.`,\n )\n if (args.exitProcess !== false) {\n process.exit(0)\n }\n }\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration generation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\"\n }\n\n return `, ${JSON.stringify(parameters)}`\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `import { MigrationInterface, QueryRunner } from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `module.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" })\n return (\n \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \"\n )\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,uEAA6D;AAC7D,0DAAwB;AACxB,wDAAuB;AACvB,8DAA6B;AAG7B,6DAAyD;AACzD,qDAA+C;AAC/C,iDAA6C;AAE7C;;GAEG;AACH,MAAa,wBAAwB;IAArC;QACI,YAAO,GAAG,2BAA2B,CAAA;QACrC,aAAQ,GACJ,gFAAgF,CAAA;IA6QxF,CAAC;IA3QG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,MAAM,EAAE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AC,CAAA;QACxD,OAAO,CACH,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CACtE,CAAA;IACL,CAAC;CACJ;AAhRD,4DAgRC","file":"MigrationGenerateCommand.js","sourcesContent":["import { format } from \"@sqltools/formatter/lib/sqlFormatter\"\nimport ansi from \"ansis\"\nimport path from \"path\"\nimport process from \"process\"\nimport yargs from \"yargs\"\nimport { DataSource } from \"../data-source\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { camelCase } from \"../util/StringUtils\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n command = \"migration:generate <path>\"\n describe =\n \"Generates a new migration file with sql needs to be executed to update schema.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"path\", {\n type: \"string\",\n describe: \"Path of the migration file\",\n demandOption: true,\n })\n .option(\"dataSource\", {\n alias: \"d\",\n type: \"string\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe:\n \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe:\n \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe:\n \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n })\n }\n\n async handler(args: yargs.Arguments<any & { path: string }>) {\n const timestamp = CommandUtils.getTimestamp(args.timestamp)\n const extension = args.outputJs ? \".js\" : \".ts\"\n const fullPath = args.path.startsWith(\"/\")\n ? args.path\n : path.resolve(process.cwd(), args.path)\n const filename = timestamp + \"-\" + path.basename(fullPath) + extension\n\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n const upSqls: string[] = [],\n downSqls: string[] = []\n\n try {\n const sqlInMemory = await dataSource.driver\n .createSchemaBuilder()\n .log()\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach((upQuery) => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(\n upQuery.query,\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downQuery.query =\n MigrationGenerateCommand.prettifyQuery(\n downQuery.query,\n )\n })\n }\n\n sqlInMemory.upQueries.forEach((upQuery) => {\n upSqls.push(\n \" await queryRunner.query(`\" +\n upQuery.query.replaceAll(\"`\", \"\\\\`\") +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n upQuery.parameters,\n ) +\n \");\",\n )\n })\n sqlInMemory.downQueries.forEach((downQuery) => {\n downSqls.push(\n \" await queryRunner.query(`\" +\n downQuery.query.replaceAll(\"`\", \"\\\\`\") +\n \"`\" +\n MigrationGenerateCommand.queryParams(\n downQuery.parameters,\n ) +\n \");\",\n )\n })\n } finally {\n await dataSource.destroy()\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(\n ansi.green`No changes in database schema were found`,\n )\n process.exit(0)\n } else {\n console.log(\n ansi.yellow`No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`,\n )\n process.exit(1)\n }\n } else if (!args.path) {\n console.log(ansi.yellow`Please specify a migration path`)\n process.exit(1)\n }\n\n const fileContent = args.outputJs\n ? MigrationGenerateCommand.getJavascriptTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n : MigrationGenerateCommand.getTemplate(\n path.basename(fullPath),\n timestamp,\n upSqls,\n downSqls.reverse(),\n )\n\n if (args.check) {\n console.log(\n ansi.yellow`Unexpected changes in database schema were found in check mode:\\n\\n${ansi.white(\n fileContent,\n )}`,\n )\n process.exit(1)\n }\n\n if (args.dryrun) {\n console.log(\n ansi.green(\n `Migration ${ansi.blue(\n fullPath + extension,\n )} has content:\\n\\n${ansi.white(fileContent)}`,\n ),\n )\n } else {\n const migrationFileName =\n path.dirname(fullPath) + \"/\" + filename\n await CommandUtils.createFile(migrationFileName, fileContent)\n\n console.log(\n ansi.green`Migration ${ansi.blue(\n migrationFileName,\n )} has been generated successfully.`,\n )\n if (args.exitProcess !== false) {\n process.exit(0)\n }\n }\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration generation:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\"\n }\n\n return `, ${JSON.stringify(parameters)}`\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `import { MigrationInterface, QueryRunner } from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(\n name: string,\n timestamp: number,\n upSqls: string[],\n downSqls: string[],\n ): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`\n\n return `module.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" })\n return (\n \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \"\n )\n }\n}\n"],"sourceRoot":".."}
@@ -4,11 +4,11 @@ exports.ConnectionOptionsReader = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const app_root_path_1 = tslib_1.__importDefault(require("app-root-path"));
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
7
- const PlatformTools_1 = require("../platform/PlatformTools");
8
- const ConnectionOptionsEnvReader_1 = require("./options-reader/ConnectionOptionsEnvReader");
9
7
  const error_1 = require("../error");
10
- const PathUtils_1 = require("../util/PathUtils");
8
+ const PlatformTools_1 = require("../platform/PlatformTools");
11
9
  const ImportUtils_1 = require("../util/ImportUtils");
10
+ const PathUtils_1 = require("../util/PathUtils");
11
+ const ConnectionOptionsEnvReader_1 = require("./options-reader/ConnectionOptionsEnvReader");
12
12
  /**
13
13
  * Reads connection options from the ormconfig.
14
14
  */
@@ -184,17 +184,13 @@ class ConnectionOptionsReader {
184
184
  * Gets directory where configuration file should be located.
185
185
  */
186
186
  get baseDirectory() {
187
- if (this.options && this.options.root)
188
- return this.options.root;
189
- return app_root_path_1.default.path;
187
+ return this.options?.root ?? app_root_path_1.default.path;
190
188
  }
191
189
  /**
192
190
  * Gets configuration file name.
193
191
  */
194
192
  get baseConfigName() {
195
- if (this.options && this.options.configName)
196
- return this.options.configName;
197
- return "ormconfig";
193
+ return this.options?.configName ?? "ormconfig";
198
194
  }
199
195
  }
200
196
  exports.ConnectionOptionsReader = ConnectionOptionsReader;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,wDAAuB;AAEvB,6DAAyD;AACzD,4FAAwF;AACxF,oCAAuC;AACvC,iDAA8C;AA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CAAC;CACJ;AArQD,0DAqQC","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\"\nimport path from \"path\"\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { ConnectionOptionsEnvReader } from \"./options-reader/ConnectionOptionsEnvReader\"\nimport { TypeORMError } from \"../error\"\nimport { isAbsolute } from \"../util/PathUtils\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Reads connection options from the ormconfig.\n */\nexport class ConnectionOptionsReader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n },\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<DataSourceOptions[]> {\n const options = await this.load()\n if (!options)\n throw new TypeORMError(\n `No connection options were found in any orm configuration files.`,\n )\n\n return options\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<DataSourceOptions> {\n const allOptions = await this.all()\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n if (!targetOptions)\n throw new TypeORMError(\n `Cannot find connection ${name} because its not defined in any orm configuration files.`,\n )\n\n return targetOptions\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load()\n if (!allOptions) return false\n\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n return !!targetOptions\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<DataSourceOptions[] | undefined> {\n let connectionOptions:\n | DataSourceOptions\n | DataSourceOptions[]\n | undefined = undefined\n\n const fileFormats = [\n \"env\",\n \"js\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"mts\",\n \"cts\",\n \"json\",\n ]\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(\n this.baseFilePath.lastIndexOf(\".\"),\n )\n const fileExtension = fileFormats.find(\n (extension) => `.${extension}` === possibleExtension,\n )\n\n // try to find any of following configuration formats\n const foundFileFormat =\n fileExtension ||\n fileFormats.find((format) => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format)\n })\n\n // Determine config file name\n const configFile = fileExtension\n ? this.baseFilePath\n : this.baseFilePath + \".\" + foundFileFormat\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile)\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\")\n }\n\n // try to find connection options from any of available sources of configuration\n if (\n PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") ||\n PlatformTools.getEnvVariable(\"TYPEORM_URL\")\n ) {\n connectionOptions = await new ConnectionOptionsEnvReader().read()\n } else if (\n foundFileFormat === \"js\" ||\n foundFileFormat === \"mjs\" ||\n foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" ||\n foundFileFormat === \"mts\" ||\n foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] =\n await importOrRequireFile(configFile)\n const configModule = await importOrRequireResult\n\n if (\n moduleSystem === \"esm\" ||\n (configModule &&\n \"__esModule\" in configModule &&\n \"default\" in configModule)\n ) {\n connectionOptions = configModule.default\n } else {\n connectionOptions = configModule\n }\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile)\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions)\n }\n\n return undefined\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(\n connectionOptions: DataSourceOptions | DataSourceOptions[],\n ): DataSourceOptions[] {\n if (!Array.isArray(connectionOptions))\n connectionOptions = [connectionOptions]\n\n connectionOptions.forEach((options) => {\n options.baseDirectory = this.baseDirectory\n if (options.entities) {\n const entities = (options.entities as any[]).map((entity) => {\n if (\n typeof entity === \"string\" &&\n entity.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + entity\n\n return entity\n })\n Object.assign(connectionOptions, { entities: entities })\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(\n (subscriber) => {\n if (\n typeof subscriber === \"string\" &&\n subscriber.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + subscriber\n\n return subscriber\n },\n )\n Object.assign(connectionOptions, { subscribers: subscribers })\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(\n (migration) => {\n if (\n typeof migration === \"string\" &&\n migration.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + migration\n\n return migration\n },\n )\n Object.assign(connectionOptions, { migrations: migrations })\n }\n\n // make database path file in sqlite relative to package.json\n if (\n options.type === \"sqlite\" ||\n options.type === \"better-sqlite3\"\n ) {\n if (\n typeof options.database === \"string\" &&\n !isAbsolute(options.database) &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\"\n ) {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database,\n })\n }\n }\n })\n\n return connectionOptions\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName)\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root) return this.options.root\n\n return appRootPath.path\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName\n\n return \"ormconfig\"\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,wDAAuB;AAGvB,oCAAuC;AACvC,6DAAyD;AACzD,qDAAyD;AACzD,iDAA8C;AAC9C,4FAAwF;AAExF;;GAEG;AACH,MAAa,uBAAuB;IAChC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,OAWT;QAXS,YAAO,GAAP,OAAO,CAWhB;IACF,CAAC;IAEJ,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,GAAG;QACL,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACjC,IAAI,CAAC,OAAO;YACR,MAAM,IAAI,oBAAY,CAClB,kEAAkE,CACrE,CAAA;QAEL,OAAO,OAAO,CAAA;IAClB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY;QAClB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,CAAA;QACnC,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CACjC,CAAC,OAAO,EAAE,EAAE,CACR,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CACrE,CAAA;QACD,IAAI,CAAC,aAAa;YACd,MAAM,IAAI,oBAAY,CAClB,0BAA0B,IAAI,0DAA0D,CAC3F,CAAA;QAEL,OAAO,aAAa,CAAA;IACxB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY;QAClB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACpC,IAAI,CAAC,UAAU;YAAE,OAAO,KAAK,CAAA;QAE7B,MAAM,aAAa,GAAG,UAAU,CAAC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B,OAAO,IAAI,CAAC,OAAO,EAAE,UAAU,IAAI,WAAW,CAAA;IAClD,CAAC;CACJ;AAhQD,0DAgQC","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\"\nimport path from \"path\"\n\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\nimport { isAbsolute } from \"../util/PathUtils\"\nimport { ConnectionOptionsEnvReader } from \"./options-reader/ConnectionOptionsEnvReader\"\n\n/**\n * Reads connection options from the ormconfig.\n */\nexport class ConnectionOptionsReader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n },\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<DataSourceOptions[]> {\n const options = await this.load()\n if (!options)\n throw new TypeORMError(\n `No connection options were found in any orm configuration files.`,\n )\n\n return options\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<DataSourceOptions> {\n const allOptions = await this.all()\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n if (!targetOptions)\n throw new TypeORMError(\n `Cannot find connection ${name} because its not defined in any orm configuration files.`,\n )\n\n return targetOptions\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load()\n if (!allOptions) return false\n\n const targetOptions = allOptions.find(\n (options) =>\n options.name === name || (name === \"default\" && !options.name),\n )\n return !!targetOptions\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<DataSourceOptions[] | undefined> {\n let connectionOptions:\n | DataSourceOptions\n | DataSourceOptions[]\n | undefined = undefined\n\n const fileFormats = [\n \"env\",\n \"js\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"mts\",\n \"cts\",\n \"json\",\n ]\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(\n this.baseFilePath.lastIndexOf(\".\"),\n )\n const fileExtension = fileFormats.find(\n (extension) => `.${extension}` === possibleExtension,\n )\n\n // try to find any of following configuration formats\n const foundFileFormat =\n fileExtension ||\n fileFormats.find((format) => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format)\n })\n\n // Determine config file name\n const configFile = fileExtension\n ? this.baseFilePath\n : this.baseFilePath + \".\" + foundFileFormat\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile)\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\")\n }\n\n // try to find connection options from any of available sources of configuration\n if (\n PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") ||\n PlatformTools.getEnvVariable(\"TYPEORM_URL\")\n ) {\n connectionOptions = await new ConnectionOptionsEnvReader().read()\n } else if (\n foundFileFormat === \"js\" ||\n foundFileFormat === \"mjs\" ||\n foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" ||\n foundFileFormat === \"mts\" ||\n foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] =\n await importOrRequireFile(configFile)\n const configModule = await importOrRequireResult\n\n if (\n moduleSystem === \"esm\" ||\n (configModule &&\n \"__esModule\" in configModule &&\n \"default\" in configModule)\n ) {\n connectionOptions = configModule.default\n } else {\n connectionOptions = configModule\n }\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile)\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions)\n }\n\n return undefined\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(\n connectionOptions: DataSourceOptions | DataSourceOptions[],\n ): DataSourceOptions[] {\n if (!Array.isArray(connectionOptions))\n connectionOptions = [connectionOptions]\n\n connectionOptions.forEach((options) => {\n options.baseDirectory = this.baseDirectory\n if (options.entities) {\n const entities = (options.entities as any[]).map((entity) => {\n if (\n typeof entity === \"string\" &&\n entity.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + entity\n\n return entity\n })\n Object.assign(connectionOptions, { entities: entities })\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(\n (subscriber) => {\n if (\n typeof subscriber === \"string\" &&\n subscriber.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + subscriber\n\n return subscriber\n },\n )\n Object.assign(connectionOptions, { subscribers: subscribers })\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(\n (migration) => {\n if (\n typeof migration === \"string\" &&\n migration.substr(0, 1) !== \"/\"\n )\n return this.baseDirectory + \"/\" + migration\n\n return migration\n },\n )\n Object.assign(connectionOptions, { migrations: migrations })\n }\n\n // make database path file in sqlite relative to package.json\n if (\n options.type === \"sqlite\" ||\n options.type === \"better-sqlite3\"\n ) {\n if (\n typeof options.database === \"string\" &&\n !isAbsolute(options.database) &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\"\n ) {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database,\n })\n }\n }\n })\n\n return connectionOptions\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName)\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n return this.options?.root ?? appRootPath.path\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n return this.options?.configName ?? \"ormconfig\"\n }\n}\n"],"sourceRoot":".."}
@@ -32,8 +32,7 @@ class DriverUtils {
32
32
  return ["mysql", "mariadb"].includes(driver.options.type);
33
33
  }
34
34
  static isReleaseVersionOrGreater(driver, version) {
35
- return (driver.version != null &&
36
- VersionUtils_1.VersionUtils.isGreaterOrEqual(driver.version, version));
35
+ return VersionUtils_1.VersionUtils.isGreaterOrEqual(driver.version, version);
37
36
  }
38
37
  static isPostgresFamily(driver) {
39
38
  return ["postgres", "aurora-postgres", "cockroachdb"].includes(driver.options.type);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/DriverUtils.ts"],"names":[],"mappings":";;;AACA,qDAAmD;AACnD,uDAAmD;AAEnD;;GAEG;AACH,MAAa,WAAW;IACpB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAc;QAChC,OAAO;YACH,QAAQ;YACR,SAAS;YACT,cAAc;YACd,cAAc;YACd,OAAO;YACP,MAAM;YACN,gBAAgB;YAChB,WAAW;SACd,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAc;QAC/B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,CAAC,yBAAyB,CAAC,MAAc,EAAE,OAAe;QAC5D,OAAO,CACH,MAAM,CAAC,OAAO,IAAI,IAAI;YACtB,2BAAY,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CACzD,CAAA;IACL,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,MAAc;QAClC,OAAO,CAAC,UAAU,EAAE,iBAAi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Q,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;YACtC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;YACvC,QAAQ,EAAE,SAAS,IAAI,SAAS;SACnC,CAAA;QAED,uDAAuD;QACvD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;YACvD,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QAC9B,CAAC;QAED,OAAO,aAAa,CAAA;IACxB,CAAC;CACJ;AApSD,kCAoSC","file":"DriverUtils.js","sourcesContent":["import { Driver } from \"./Driver\"\nimport { hash, shorten } from \"../util/StringUtils\"\nimport { VersionUtils } from \"../util/VersionUtils\"\n\n/**\n * Common driver utility functions.\n */\nexport class DriverUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns true if given driver is SQLite-based driver.\n */\n static isSQLiteFamily(driver: Driver): boolean {\n return [\n \"sqlite\",\n \"cordova\",\n \"react-native\",\n \"nativescript\",\n \"sqljs\",\n \"expo\",\n \"better-sqlite3\",\n \"capacitor\",\n ].includes(driver.options.type)\n }\n\n /**\n * Returns true if given driver is MySQL-based driver.\n */\n static isMySQLFamily(driver: Driver): boolean {\n return [\"mysql\", \"mariadb\"].includes(driver.options.type)\n }\n\n static isReleaseVersionOrGreater(driver: Driver, version: string): boolean {\n return (\n driver.version != null &&\n VersionUtils.isGreaterOrEqual(driver.version, version)\n )\n }\n\n static isPostgresFamily(driver: Driver): boolean {\n return [\"postgres\", \"aurora-postgres\", \"cockroachdb\"].includes(\n driver.options.type,\n )\n }\n\n /**\n * Normalizes and builds a new driver options.\n * Extracts settings from connection url and sets to a new options object.\n */\n static buildDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseConnectionUrl(options.url) as {\n [key: string]: any\n }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * buildDriverOptions for MongodDB only to support replica set\n */\n static buildMongoDBDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseMongoDBConnectionUrl(\n options.url,\n ) as { [key: string]: any }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * Joins and shortens alias if needed.\n *\n * If the alias length is greater than the limit allowed by the current\n * driver, replaces it with a shortend string, if the shortend string\n * is still too long, it will then hash the alias.\n *\n * @param driver Current `Driver`.\n * @param buildOptions Optional settings.\n * @param alias Alias parts.\n *\n * @return An alias that is no longer than the divers max alias length.\n */\n static buildAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | undefined,\n ...alias: string[]\n ): string {\n const joiner =\n buildOptions && buildOptions.joiner ? buildOptions.joiner : \"_\"\n\n const newAlias = alias.length === 1 ? alias[0] : alias.join(joiner)\n\n if (\n maxAliasLength &&\n maxAliasLength > 0 &&\n newAlias.length > maxAliasLength\n ) {\n if (buildOptions && buildOptions.shorten === true) {\n const shortenedAlias = shorten(newAlias)\n if (shortenedAlias.length < maxAliasLength) {\n return shortenedAlias\n }\n }\n\n return hash(newAlias, { length: maxAliasLength })\n }\n\n return newAlias\n }\n\n /**\n * @deprecated use `buildAlias` instead.\n */\n static buildColumnAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | string,\n ...alias: string[]\n ) {\n if (typeof buildOptions === \"string\") {\n alias.unshift(buildOptions)\n buildOptions = { shorten: false, joiner: \"_\" }\n } else {\n buildOptions = Object.assign(\n { shorten: false, joiner: \"_\" },\n buildOptions,\n )\n }\n return this.buildAlias(\n { maxAliasLength } as Driver,\n buildOptions,\n ...alias,\n )\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Extracts connection data from the connection url.\n */\n private static parseConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n // remove mongodb query params\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n const [host, port] = hostAndPort.split(\":\")\n\n return {\n type: type,\n host: host,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n }\n\n /**\n * Extracts connection data from the connection url for MongoDB to support replica set.\n */\n private static parseMongoDBConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n let afterQuestionMark = \"\"\n let host = undefined\n let port = undefined\n let hostReplicaSet = undefined\n let replicaSet = undefined\n\n const optionsObject: any = {}\n\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n // split params\n afterQuestionMark = afterBase.substr(\n afterBase.indexOf(\"?\") + 1,\n afterBase.length,\n )\n\n const optionsList = afterQuestionMark.split(\"&\")\n let optionKey: string\n let optionValue: string\n\n // create optionsObject for merge with connectionUrl object before return\n optionsList.forEach((optionItem) => {\n optionKey = optionItem.split(\"=\")[0]\n optionValue = optionItem.split(\"=\")[1]\n optionsObject[optionKey] = optionValue\n })\n\n // specific replicaSet value to set options about hostReplicaSet\n replicaSet = optionsObject[\"replicaSet\"]\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n\n // If replicaSet have value set It as hostlist, If not set like standalone host\n if (replicaSet) {\n hostReplicaSet = hostAndPort\n } else {\n ;[host, port] = hostAndPort.split(\":\")\n }\n\n const connectionUrl: any = {\n type: type,\n host: host,\n hostReplicaSet: hostReplicaSet,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n\n // Loop to set every options in connectionUrl to object\n for (const [key, value] of Object.entries(optionsObject)) {\n connectionUrl[key] = value\n }\n\n return connectionUrl\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/driver/Driver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from \"./Driver\"\nimport { hash, shorten } from \"../util/StringUtils\"\nimport { VersionUtils } from \"../util/VersionUtils\"\n\n/**\n * Common driver utility functions.\n */\nexport class DriverUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns true if given driver is SQLite-based driver.\n */\n static isSQLiteFamily(driver: Driver): boolean {\n return [\n \"sqlite\",\n \"cordova\",\n \"react-native\",\n \"nativescript\",\n \"sqljs\",\n \"expo\",\n \"better-sqlite3\",\n \"capacitor\",\n ].includes(driver.options.type)\n }\n\n /**\n * Returns true if given driver is MySQL-based driver.\n */\n static isMySQLFamily(driver: Driver): boolean {\n return [\"mysql\", \"mariadb\"].includes(driver.options.type)\n }\n\n static isReleaseVersionOrGreater(driver: Driver, version: string): boolean {\n return VersionUtils.isGreaterOrEqual(driver.version, version)\n }\n\n static isPostgresFamily(driver: Driver): boolean {\n return [\"postgres\", \"aurora-postgres\", \"cockroachdb\"].includes(\n driver.options.type,\n )\n }\n\n /**\n * Normalizes and builds a new driver options.\n * Extracts settings from connection url and sets to a new options object.\n */\n static buildDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseConnectionUrl(options.url) as {\n [key: string]: any\n }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * buildDriverOptions for MongodDB only to support replica set\n */\n static buildMongoDBDriverOptions(\n options: any,\n buildOptions?: { useSid: boolean },\n ): any {\n if (options.url) {\n const urlDriverOptions = this.parseMongoDBConnectionUrl(\n options.url,\n ) as { [key: string]: any }\n\n if (\n buildOptions &&\n buildOptions.useSid &&\n urlDriverOptions.database\n ) {\n urlDriverOptions.sid = urlDriverOptions.database\n }\n\n for (const key of Object.keys(urlDriverOptions)) {\n if (typeof urlDriverOptions[key] === \"undefined\") {\n delete urlDriverOptions[key]\n }\n }\n\n return Object.assign({}, options, urlDriverOptions)\n }\n return Object.assign({}, options)\n }\n\n /**\n * Joins and shortens alias if needed.\n *\n * If the alias length is greater than the limit allowed by the current\n * driver, replaces it with a shortend string, if the shortend string\n * is still too long, it will then hash the alias.\n *\n * @param driver Current `Driver`.\n * @param buildOptions Optional settings.\n * @param alias Alias parts.\n *\n * @return An alias that is no longer than the divers max alias length.\n */\n static buildAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | undefined,\n ...alias: string[]\n ): string {\n const joiner =\n buildOptions && buildOptions.joiner ? buildOptions.joiner : \"_\"\n\n const newAlias = alias.length === 1 ? alias[0] : alias.join(joiner)\n\n if (\n maxAliasLength &&\n maxAliasLength > 0 &&\n newAlias.length > maxAliasLength\n ) {\n if (buildOptions && buildOptions.shorten === true) {\n const shortenedAlias = shorten(newAlias)\n if (shortenedAlias.length < maxAliasLength) {\n return shortenedAlias\n }\n }\n\n return hash(newAlias, { length: maxAliasLength })\n }\n\n return newAlias\n }\n\n /**\n * @deprecated use `buildAlias` instead.\n */\n static buildColumnAlias(\n { maxAliasLength }: Driver,\n buildOptions: { shorten?: boolean; joiner?: string } | string,\n ...alias: string[]\n ) {\n if (typeof buildOptions === \"string\") {\n alias.unshift(buildOptions)\n buildOptions = { shorten: false, joiner: \"_\" }\n } else {\n buildOptions = Object.assign(\n { shorten: false, joiner: \"_\" },\n buildOptions,\n )\n }\n return this.buildAlias(\n { maxAliasLength } as Driver,\n buildOptions,\n ...alias,\n )\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Extracts connection data from the connection url.\n */\n private static parseConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n // remove mongodb query params\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n const [host, port] = hostAndPort.split(\":\")\n\n return {\n type: type,\n host: host,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n }\n\n /**\n * Extracts connection data from the connection url for MongoDB to support replica set.\n */\n private static parseMongoDBConnectionUrl(url: string) {\n const type = url.split(\":\")[0]\n const firstSlashes = url.indexOf(\"//\")\n const preBase = url.substr(firstSlashes + 2)\n const secondSlash = preBase.indexOf(\"/\")\n const base =\n secondSlash !== -1 ? preBase.substr(0, secondSlash) : preBase\n let afterBase =\n secondSlash !== -1 ? preBase.substr(secondSlash + 1) : undefined\n let afterQuestionMark = \"\"\n let host = undefined\n let port = undefined\n let hostReplicaSet = undefined\n let replicaSet = undefined\n\n const optionsObject: any = {}\n\n if (afterBase && afterBase.indexOf(\"?\") !== -1) {\n // split params\n afterQuestionMark = afterBase.substr(\n afterBase.indexOf(\"?\") + 1,\n afterBase.length,\n )\n\n const optionsList = afterQuestionMark.split(\"&\")\n let optionKey: string\n let optionValue: string\n\n // create optionsObject for merge with connectionUrl object before return\n optionsList.forEach((optionItem) => {\n optionKey = optionItem.split(\"=\")[0]\n optionValue = optionItem.split(\"=\")[1]\n optionsObject[optionKey] = optionValue\n })\n\n // specific replicaSet value to set options about hostReplicaSet\n replicaSet = optionsObject[\"replicaSet\"]\n afterBase = afterBase.substr(0, afterBase.indexOf(\"?\"))\n }\n\n const lastAtSign = base.lastIndexOf(\"@\")\n const usernameAndPassword = base.substr(0, lastAtSign)\n const hostAndPort = base.substr(lastAtSign + 1)\n\n let username = usernameAndPassword\n let password = \"\"\n const firstColon = usernameAndPassword.indexOf(\":\")\n if (firstColon !== -1) {\n username = usernameAndPassword.substr(0, firstColon)\n password = usernameAndPassword.substr(firstColon + 1)\n }\n\n // If replicaSet have value set It as hostlist, If not set like standalone host\n if (replicaSet) {\n hostReplicaSet = hostAndPort\n } else {\n ;[host, port] = hostAndPort.split(\":\")\n }\n\n const connectionUrl: any = {\n type: type,\n host: host,\n hostReplicaSet: hostReplicaSet,\n username: decodeURIComponent(username),\n password: decodeURIComponent(password),\n port: port ? parseInt(port) : undefined,\n database: afterBase || undefined,\n }\n\n // Loop to set every options in connectionUrl to object\n for (const [key, value] of Object.entries(optionsObject)) {\n connectionUrl[key] = value\n }\n\n return connectionUrl\n }\n}\n"],"sourceRoot":".."}
@@ -272,7 +272,7 @@ class AuroraMysqlDriver {
272
272
  */
273
273
  async connect() {
274
274
  if (!this.database) {
275
- const queryRunner = await this.createQueryRunner("master");
275
+ const queryRunner = this.createQueryRunner("master");
276
276
  this.database = await queryRunner.getCurrentDatabase();
277
277
  await queryRunner.release();
278
278
  }