typeorm 0.3.7 → 0.3.8-dev.03317a3

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 (174) hide show
  1. package/browser/cli-ts-node-commonjs.js +0 -0
  2. package/browser/cli-ts-node-esm.js +0 -0
  3. package/browser/data-source/DataSource.d.ts +2 -0
  4. package/browser/data-source/DataSource.js +2 -0
  5. package/browser/data-source/DataSource.js.map +1 -1
  6. package/browser/driver/Driver.d.ts +4 -0
  7. package/browser/driver/Driver.js.map +1 -1
  8. package/browser/driver/DriverUtils.d.ts +1 -0
  9. package/browser/driver/DriverUtils.js +5 -0
  10. package/browser/driver/DriverUtils.js.map +1 -1
  11. package/browser/driver/aurora-mysql/AuroraMysqlQueryRunner.js +4 -1
  12. package/browser/driver/aurora-mysql/AuroraMysqlQueryRunner.js.map +1 -1
  13. package/browser/driver/cockroachdb/CockroachQueryRunner.js +4 -1
  14. package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  15. package/browser/driver/mysql/MysqlDriver.d.ts +4 -0
  16. package/browser/driver/mysql/MysqlDriver.js +1 -0
  17. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  18. package/browser/driver/mysql/MysqlQueryRunner.js +9 -1
  19. package/browser/driver/mysql/MysqlQueryRunner.js.map +1 -1
  20. package/browser/driver/oracle/OracleConnectionOptions.d.ts +1 -1
  21. package/browser/driver/oracle/OracleConnectionOptions.js.map +1 -1
  22. package/browser/driver/oracle/OracleQueryRunner.js +4 -1
  23. package/browser/driver/oracle/OracleQueryRunner.js.map +1 -1
  24. package/browser/driver/postgres/PostgresConnectionOptions.d.ts +1 -1
  25. package/browser/driver/postgres/PostgresConnectionOptions.js.map +1 -1
  26. package/browser/driver/postgres/PostgresDriver.d.ts +4 -0
  27. package/browser/driver/postgres/PostgresDriver.js +3 -2
  28. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  29. package/browser/driver/postgres/PostgresQueryRunner.d.ts +1 -1
  30. package/browser/driver/postgres/PostgresQueryRunner.js +22 -13
  31. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  32. package/browser/driver/sap/SapQueryRunner.js +4 -1
  33. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  34. package/browser/driver/spanner/SpannerQueryRunner.js +4 -1
  35. package/browser/driver/spanner/SpannerQueryRunner.js.map +1 -1
  36. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.d.ts +1 -1
  37. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +20 -13
  38. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  39. package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +7 -2
  40. package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  41. package/browser/driver/sqlserver/SqlServerQueryRunner.js +4 -1
  42. package/browser/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
  43. package/browser/entity-manager/EntityManager.js +1 -0
  44. package/browser/entity-manager/EntityManager.js.map +1 -1
  45. package/browser/entity-manager/MongoEntityManager.d.ts +1 -1
  46. package/browser/entity-manager/MongoEntityManager.js +17 -10
  47. package/browser/entity-manager/MongoEntityManager.js.map +1 -1
  48. package/browser/find-options/FindOneOptions.d.ts +1 -0
  49. package/browser/find-options/FindOneOptions.js.map +1 -1
  50. package/browser/find-options/FindOptionsOrder.d.ts +1 -1
  51. package/browser/find-options/FindOptionsOrder.js.map +1 -1
  52. package/browser/find-options/FindOptionsRelations.d.ts +1 -1
  53. package/browser/find-options/FindOptionsRelations.js.map +1 -1
  54. package/browser/find-options/FindOptionsSelect.d.ts +1 -1
  55. package/browser/find-options/FindOptionsSelect.js.map +1 -1
  56. package/browser/find-options/FindOptionsWhere.d.ts +1 -1
  57. package/browser/find-options/FindOptionsWhere.js.map +1 -1
  58. package/browser/migration/MigrationExecutor.d.ts +8 -0
  59. package/browser/migration/MigrationExecutor.js +13 -5
  60. package/browser/migration/MigrationExecutor.js.map +1 -1
  61. package/browser/persistence/SubjectTopoligicalSorter.js +6 -1
  62. package/browser/persistence/SubjectTopoligicalSorter.js.map +1 -1
  63. package/browser/query-builder/QueryExpressionMap.d.ts +4 -0
  64. package/browser/query-builder/QueryExpressionMap.js +1 -0
  65. package/browser/query-builder/QueryExpressionMap.js.map +1 -1
  66. package/browser/query-builder/SelectQueryBuilder.d.ts +4 -0
  67. package/browser/query-builder/SelectQueryBuilder.js +57 -18
  68. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  69. package/browser/query-builder/UpdateQueryBuilder.js +1 -0
  70. package/browser/query-builder/UpdateQueryBuilder.js.map +1 -1
  71. package/browser/query-runner/BaseQueryRunner.d.ts +5 -0
  72. package/browser/query-runner/BaseQueryRunner.js +7 -0
  73. package/browser/query-runner/BaseQueryRunner.js.map +1 -1
  74. package/browser/schema-builder/options/TableOptions.d.ts +4 -0
  75. package/browser/schema-builder/options/TableOptions.js.map +1 -1
  76. package/browser/schema-builder/table/Table.d.ts +4 -0
  77. package/browser/schema-builder/table/Table.js +8 -0
  78. package/browser/schema-builder/table/Table.js.map +1 -1
  79. package/browser/util/DateUtils.d.ts +1 -1
  80. package/browser/util/DateUtils.js +7 -8
  81. package/browser/util/DateUtils.js.map +1 -1
  82. package/cli-ts-node-commonjs.js +0 -0
  83. package/cli-ts-node-esm.js +0 -0
  84. package/cli.js +0 -0
  85. package/commands/CommandUtils.js +7 -3
  86. package/commands/CommandUtils.js.map +1 -1
  87. package/commands/InitCommand.js +1 -1
  88. package/commands/InitCommand.js.map +1 -1
  89. package/commands/MigrationRevertCommand.d.ts +2 -0
  90. package/commands/MigrationRevertCommand.js +6 -0
  91. package/commands/MigrationRevertCommand.js.map +1 -1
  92. package/commands/MigrationRunCommand.d.ts +2 -0
  93. package/commands/MigrationRunCommand.js +8 -0
  94. package/commands/MigrationRunCommand.js.map +1 -1
  95. package/data-source/DataSource.d.ts +2 -0
  96. package/data-source/DataSource.js +2 -0
  97. package/data-source/DataSource.js.map +1 -1
  98. package/driver/Driver.d.ts +4 -0
  99. package/driver/Driver.js.map +1 -1
  100. package/driver/DriverUtils.d.ts +1 -0
  101. package/driver/DriverUtils.js +5 -0
  102. package/driver/DriverUtils.js.map +1 -1
  103. package/driver/aurora-mysql/AuroraMysqlQueryRunner.js +4 -1
  104. package/driver/aurora-mysql/AuroraMysqlQueryRunner.js.map +1 -1
  105. package/driver/cockroachdb/CockroachQueryRunner.js +4 -1
  106. package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  107. package/driver/mysql/MysqlDriver.d.ts +4 -0
  108. package/driver/mysql/MysqlDriver.js +1 -0
  109. package/driver/mysql/MysqlDriver.js.map +1 -1
  110. package/driver/mysql/MysqlQueryRunner.js +9 -1
  111. package/driver/mysql/MysqlQueryRunner.js.map +1 -1
  112. package/driver/oracle/OracleConnectionOptions.d.ts +1 -1
  113. package/driver/oracle/OracleConnectionOptions.js.map +1 -1
  114. package/driver/oracle/OracleQueryRunner.js +4 -1
  115. package/driver/oracle/OracleQueryRunner.js.map +1 -1
  116. package/driver/postgres/PostgresConnectionOptions.d.ts +1 -1
  117. package/driver/postgres/PostgresConnectionOptions.js.map +1 -1
  118. package/driver/postgres/PostgresDriver.d.ts +4 -0
  119. package/driver/postgres/PostgresDriver.js +3 -2
  120. package/driver/postgres/PostgresDriver.js.map +1 -1
  121. package/driver/postgres/PostgresQueryRunner.d.ts +1 -1
  122. package/driver/postgres/PostgresQueryRunner.js +22 -13
  123. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  124. package/driver/sap/SapQueryRunner.js +4 -1
  125. package/driver/sap/SapQueryRunner.js.map +1 -1
  126. package/driver/spanner/SpannerQueryRunner.js +4 -1
  127. package/driver/spanner/SpannerQueryRunner.js.map +1 -1
  128. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.d.ts +1 -1
  129. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +20 -13
  130. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  131. package/driver/sqlserver/SqlServerConnectionOptions.d.ts +7 -2
  132. package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  133. package/driver/sqlserver/SqlServerQueryRunner.js +4 -1
  134. package/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
  135. package/entity-manager/EntityManager.js +1 -0
  136. package/entity-manager/EntityManager.js.map +1 -1
  137. package/entity-manager/MongoEntityManager.d.ts +1 -1
  138. package/entity-manager/MongoEntityManager.js +17 -10
  139. package/entity-manager/MongoEntityManager.js.map +1 -1
  140. package/find-options/FindOneOptions.d.ts +1 -0
  141. package/find-options/FindOneOptions.js.map +1 -1
  142. package/find-options/FindOptionsOrder.d.ts +1 -1
  143. package/find-options/FindOptionsOrder.js.map +1 -1
  144. package/find-options/FindOptionsRelations.d.ts +1 -1
  145. package/find-options/FindOptionsRelations.js.map +1 -1
  146. package/find-options/FindOptionsSelect.d.ts +1 -1
  147. package/find-options/FindOptionsSelect.js.map +1 -1
  148. package/find-options/FindOptionsWhere.d.ts +1 -1
  149. package/find-options/FindOptionsWhere.js.map +1 -1
  150. package/migration/MigrationExecutor.d.ts +8 -0
  151. package/migration/MigrationExecutor.js +13 -5
  152. package/migration/MigrationExecutor.js.map +1 -1
  153. package/package.json +1 -274
  154. package/persistence/SubjectTopoligicalSorter.js +6 -1
  155. package/persistence/SubjectTopoligicalSorter.js.map +1 -1
  156. package/query-builder/QueryExpressionMap.d.ts +4 -0
  157. package/query-builder/QueryExpressionMap.js +1 -0
  158. package/query-builder/QueryExpressionMap.js.map +1 -1
  159. package/query-builder/SelectQueryBuilder.d.ts +4 -0
  160. package/query-builder/SelectQueryBuilder.js +57 -18
  161. package/query-builder/SelectQueryBuilder.js.map +1 -1
  162. package/query-builder/UpdateQueryBuilder.js +1 -0
  163. package/query-builder/UpdateQueryBuilder.js.map +1 -1
  164. package/query-runner/BaseQueryRunner.d.ts +5 -0
  165. package/query-runner/BaseQueryRunner.js +7 -0
  166. package/query-runner/BaseQueryRunner.js.map +1 -1
  167. package/schema-builder/options/TableOptions.d.ts +4 -0
  168. package/schema-builder/options/TableOptions.js.map +1 -1
  169. package/schema-builder/table/Table.d.ts +4 -0
  170. package/schema-builder/table/Table.js +8 -0
  171. package/schema-builder/table/Table.js.map +1 -1
  172. package/util/DateUtils.d.ts +1 -1
  173. package/util/DateUtils.js +7 -8
  174. package/util/DateUtils.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/schema-builder/table/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAInD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD;;GAEG;AACH,MAAM,OAAO,KAAK;IAkEd,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,OAAsB;QArEzB,mBAAa,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAuB5C;;WAEG;QACH,YAAO,GAAkB,EAAE,CAAA;QAE3B;;WAEG;QACH,YAAO,GAAiB,EAAE,CAAA;QAE1B;;WAEG;QACH,gBAAW,GAAsB,EAAE,CAAA;QAEnC;;WAEG;QACH,YAAO,GAAkB,EAAE,CAAA;QAE3B;;WAEG;QACH,WAAM,GAAiB,EAAE,CAAA;QAEzB;;WAEG;QACH,eAAU,GAAqB,EAAE,CAAA;QAEjC;;;;WAIG;QACH,gBAAW,GAAY,KAAK,CAAA;QAYxB,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAA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;YAC1B,QAAQ,EAAE,cAAc,CAAC,QAAQ;YACjC,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,IAAI,EAAE,MAAM,CAAC,cAAc,CACvB,cAAc,CAAC,SAAS,EACxB,MAAM,EACN,QAAQ,CACX;YACD,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,OAAO,EAAE,cAAc,CAAC,OAAO;iBAC1B,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;iBAC1B,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACZ,UAAU,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CACtD;YACL,OAAO,EAAE,cAAc,CAAC,OAAO;iBAC1B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC;iBAC7C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7C,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC3C,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAC7B;YACD,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACxC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAC3B;YACD,UAAU,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CACpD,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CACnC;SACJ,CAAA;QAED,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC;CACJ","file":"Table.js","sourcesContent":["import { TableColumn } from \"./TableColumn\"\nimport { TableIndex } from \"./TableIndex\"\nimport { TableForeignKey } from \"./TableForeignKey\"\nimport { Driver } from \"../../driver/Driver\"\nimport { TableOptions } from \"../options/TableOptions\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { TableUtils } from \"../util/TableUtils\"\nimport { TableUnique } from \"./TableUnique\"\nimport { TableCheck } from \"./TableCheck\"\nimport { TableExclusion } from \"./TableExclusion\"\n\n/**\n * Table in the database represented in this class.\n */\nexport class Table {\n readonly \"@instanceof\" = Symbol.for(\"Table\")\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Database name that this table resides in if it applies.\n */\n database?: string\n\n /**\n * Schema name that this table resides in if it applies.\n */\n schema?: string\n\n /**\n * May contain database name, schema name and table name, unless they're the current database.\n *\n * E.g. myDB.mySchema.myTable\n */\n name: string\n\n /**\n * Table columns.\n */\n columns: TableColumn[] = []\n\n /**\n * Table indices.\n */\n indices: TableIndex[] = []\n\n /**\n * Table foreign keys.\n */\n foreignKeys: TableForeignKey[] = []\n\n /**\n * Table unique constraints.\n */\n uniques: TableUnique[] = []\n\n /**\n * Table check constraints.\n */\n checks: TableCheck[] = []\n\n /**\n * Table exclusion constraints.\n */\n exclusions: TableExclusion[] = []\n\n /**\n * Indicates if table was just created.\n * This is needed, for example to check if we need to skip primary keys creation\n * for new tables.\n */\n justCreated: boolean = false\n\n /**\n * Table engine.\n */\n engine?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options?: TableOptions) {\n if (options) {\n this.database = options.database\n\n this.schema = options.schema\n\n this.name = options.name\n\n if (options.columns)\n this.columns = options.columns.map(\n (column) => new TableColumn(column),\n )\n\n if (options.indices)\n this.indices = options.indices.map(\n (index) => new TableIndex(index),\n )\n\n if (options.foreignKeys)\n this.foreignKeys = options.foreignKeys.map(\n (foreignKey) =>\n new TableForeignKey({\n ...foreignKey,\n referencedDatabase:\n foreignKey?.referencedDatabase ||\n options.database,\n referencedSchema:\n foreignKey?.referencedSchema || options.schema,\n }),\n )\n\n if (options.uniques)\n this.uniques = options.uniques.map(\n (unique) => new TableUnique(unique),\n )\n\n if (options.checks)\n this.checks = options.checks.map(\n (check) => new TableCheck(check),\n )\n\n if (options.exclusions)\n this.exclusions = options.exclusions.map(\n (exclusion) => new TableExclusion(exclusion),\n )\n\n if (options.justCreated !== undefined)\n this.justCreated = options.justCreated\n\n this.engine = options.engine\n }\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n get primaryColumns(): TableColumn[] {\n return this.columns.filter((column) => column.isPrimary)\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Clones this table to a new table with all properties cloned.\n */\n clone(): Table {\n return new Table({\n schema: this.schema,\n database: this.database,\n name: this.name,\n columns: this.columns.map((column) => column.clone()),\n indices: this.indices.map((constraint) => constraint.clone()),\n foreignKeys: this.foreignKeys.map((constraint) =>\n constraint.clone(),\n ),\n uniques: this.uniques.map((constraint) => constraint.clone()),\n checks: this.checks.map((constraint) => constraint.clone()),\n exclusions: this.exclusions.map((constraint) => constraint.clone()),\n justCreated: this.justCreated,\n engine: this.engine,\n })\n }\n\n /**\n * Add column and creates its constraints.\n */\n addColumn(column: TableColumn): void {\n this.columns.push(column)\n }\n\n /**\n * Remove column and its constraints.\n */\n removeColumn(column: TableColumn): void {\n const foundColumn = this.columns.find((c) => c.name === column.name)\n if (foundColumn)\n this.columns.splice(this.columns.indexOf(foundColumn), 1)\n }\n\n /**\n * Adds unique constraint.\n */\n addUniqueConstraint(uniqueConstraint: TableUnique): void {\n this.uniques.push(uniqueConstraint)\n if (uniqueConstraint.columnNames.length === 1) {\n const uniqueColumn = this.columns.find(\n (column) => column.name === uniqueConstraint.columnNames[0],\n )\n if (uniqueColumn) uniqueColumn.isUnique = true\n }\n }\n\n /**\n * Removes unique constraint.\n */\n removeUniqueConstraint(removedUnique: TableUnique): void {\n const foundUnique = this.uniques.find(\n (unique) => unique.name === removedUnique.name,\n )\n if (foundUnique) {\n this.uniques.splice(this.uniques.indexOf(foundUnique), 1)\n if (foundUnique.columnNames.length === 1) {\n const uniqueColumn = this.columns.find(\n (column) => column.name === foundUnique.columnNames[0],\n )\n if (uniqueColumn) uniqueColumn.isUnique = false\n }\n }\n }\n\n /**\n * Adds check constraint.\n */\n addCheckConstraint(checkConstraint: TableCheck): void {\n this.checks.push(checkConstraint)\n }\n\n /**\n * Removes check constraint.\n */\n removeCheckConstraint(removedCheck: TableCheck): void {\n const foundCheck = this.checks.find(\n (check) => check.name === removedCheck.name,\n )\n if (foundCheck) {\n this.checks.splice(this.checks.indexOf(foundCheck), 1)\n }\n }\n\n /**\n * Adds exclusion constraint.\n */\n addExclusionConstraint(exclusionConstraint: TableExclusion): void {\n this.exclusions.push(exclusionConstraint)\n }\n\n /**\n * Removes exclusion constraint.\n */\n removeExclusionConstraint(removedExclusion: TableExclusion): void {\n const foundExclusion = this.exclusions.find(\n (exclusion) => exclusion.name === removedExclusion.name,\n )\n if (foundExclusion) {\n this.exclusions.splice(this.exclusions.indexOf(foundExclusion), 1)\n }\n }\n\n /**\n * Adds foreign keys.\n */\n addForeignKey(foreignKey: TableForeignKey): void {\n this.foreignKeys.push(foreignKey)\n }\n\n /**\n * Removes foreign key.\n */\n removeForeignKey(removedForeignKey: TableForeignKey): void {\n const fk = this.foreignKeys.find(\n (foreignKey) => foreignKey.name === removedForeignKey.name,\n )\n if (fk) this.foreignKeys.splice(this.foreignKeys.indexOf(fk), 1)\n }\n\n /**\n * Adds index.\n */\n addIndex(index: TableIndex, isMysql: boolean = false): void {\n this.indices.push(index)\n\n // in Mysql unique indices and unique constraints are the same thing\n // if index is unique and have only one column, we mark this column as unique\n if (index.columnNames.length === 1 && index.isUnique && isMysql) {\n const column = this.columns.find(\n (c) => c.name === index.columnNames[0],\n )\n if (column) column.isUnique = true\n }\n }\n\n /**\n * Removes index.\n */\n removeIndex(tableIndex: TableIndex, isMysql: boolean = false): void {\n const index = this.indices.find(\n (index) => index.name === tableIndex.name,\n )\n if (index) {\n this.indices.splice(this.indices.indexOf(index), 1)\n\n // in Mysql unique indices and unique constraints are the same thing\n // if index is unique and have only one column, we move `unique` attribute from its column\n if (index.columnNames.length === 1 && index.isUnique && isMysql) {\n const column = this.columns.find(\n (c) => c.name === index.columnNames[0],\n )\n if (column)\n column.isUnique = this.indices.some(\n (ind) =>\n ind.columnNames.length === 1 &&\n ind.columnNames[0] === column.name &&\n !!index.isUnique,\n )\n }\n }\n }\n\n findColumnByName(name: string): TableColumn | undefined {\n return this.columns.find((column) => column.name === name)\n }\n\n /**\n * Returns all column indices.\n */\n findColumnIndices(column: TableColumn): TableIndex[] {\n return this.indices.filter((index) => {\n return !!index.columnNames.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n /**\n * Returns all column foreign keys.\n */\n findColumnForeignKeys(column: TableColumn): TableForeignKey[] {\n return this.foreignKeys.filter((foreignKey) => {\n return !!foreignKey.columnNames.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n /**\n * Returns all column uniques.\n */\n findColumnUniques(column: TableColumn): TableUnique[] {\n return this.uniques.filter((unique) => {\n return !!unique.columnNames.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n /**\n * Returns all column checks.\n */\n findColumnChecks(column: TableColumn): TableCheck[] {\n return this.checks.filter((check) => {\n return !!check.columnNames!.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n // -------------------------------------------------------------------------\n // Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates table from a given entity metadata.\n */\n static create(entityMetadata: EntityMetadata, driver: Driver): Table {\n const database =\n entityMetadata.database === driver.database\n ? undefined\n : entityMetadata.database\n const schema =\n entityMetadata.schema === (driver.options as any).schema\n ? undefined\n : entityMetadata.schema\n\n const options: TableOptions = {\n database: entityMetadata.database,\n schema: entityMetadata.schema,\n name: driver.buildTableName(\n entityMetadata.tableName,\n schema,\n database,\n ),\n engine: entityMetadata.engine,\n columns: entityMetadata.columns\n .filter((column) => column)\n .map((column) =>\n TableUtils.createTableColumnOptions(column, driver),\n ),\n indices: entityMetadata.indices\n .filter((index) => index.synchronize === true)\n .map((index) => TableIndex.create(index)),\n uniques: entityMetadata.uniques.map((unique) =>\n TableUnique.create(unique),\n ),\n checks: entityMetadata.checks.map((check) =>\n TableCheck.create(check),\n ),\n exclusions: entityMetadata.exclusions.map((exclusion) =>\n TableExclusion.create(exclusion),\n ),\n }\n\n return new Table(options)\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/schema-builder/table/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAInD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD;;GAEG;AACH,MAAM,OAAO,KAAK;IAuEd,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,OAAsB;QA1EzB,mBAAa,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAuB5C;;WAEG;QACH,YAAO,GAAkB,EAAE,CAAA;QAE3B;;WAEG;QACH,YAAO,GAAiB,EAAE,CAAA;QAE1B;;WAEG;QACH,gBAAW,GAAsB,EAAE,CAAA;QAEnC;;WAEG;QACH,YAAO,GAAkB,EAAE,CAAA;QAE3B;;WAEG;QACH,WAAM,GAAiB,EAAE,CAAA;QAEzB;;WAEG;QACH,eAAU,GAAqB,EAAE,CAAA;QAEjC;;;;WAIG;QACH,gBAAW,GAAY,KAAK,CAAA;QAE5B;;WAEG;QACH,iBAAY,GAAa,KAAK,CAAA;QAY1B,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,QAAQ,GAAG,OAAO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,CAAA;IAC7B,CAAC;CACJ","file":"Table.js","sourcesContent":["import { TableColumn } from \"./TableColumn\"\nimport { TableIndex } from \"./TableIndex\"\nimport { TableForeignKey } from \"./TableForeignKey\"\nimport { Driver } from \"../../driver/Driver\"\nimport { TableOptions } from \"../options/TableOptions\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { TableUtils } from \"../util/TableUtils\"\nimport { TableUnique } from \"./TableUnique\"\nimport { TableCheck } from \"./TableCheck\"\nimport { TableExclusion } from \"./TableExclusion\"\n\n/**\n * Table in the database represented in this class.\n */\nexport class Table {\n readonly \"@instanceof\" = Symbol.for(\"Table\")\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Database name that this table resides in if it applies.\n */\n database?: string\n\n /**\n * Schema name that this table resides in if it applies.\n */\n schema?: string\n\n /**\n * May contain database name, schema name and table name, unless they're the current database.\n *\n * E.g. myDB.mySchema.myTable\n */\n name: string\n\n /**\n * Table columns.\n */\n columns: TableColumn[] = []\n\n /**\n * Table indices.\n */\n indices: TableIndex[] = []\n\n /**\n * Table foreign keys.\n */\n foreignKeys: TableForeignKey[] = []\n\n /**\n * Table unique constraints.\n */\n uniques: TableUnique[] = []\n\n /**\n * Table check constraints.\n */\n checks: TableCheck[] = []\n\n /**\n * Table exclusion constraints.\n */\n exclusions: TableExclusion[] = []\n\n /**\n * Indicates if table was just created.\n * This is needed, for example to check if we need to skip primary keys creation\n * for new tables.\n */\n justCreated: boolean = false\n\n /**\n * Enables Sqlite \"WITHOUT ROWID\" modifier for the \"CREATE TABLE\" statement\n */\n withoutRowid?: boolean = false\n\n /**\n * Table engine.\n */\n engine?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options?: TableOptions) {\n if (options) {\n this.database = options.database\n this.schema = options.schema\n this.name = options.name\n\n if (options.columns)\n this.columns = options.columns.map(\n (column) => new TableColumn(column),\n )\n\n if (options.indices)\n this.indices = options.indices.map(\n (index) => new TableIndex(index),\n )\n\n if (options.foreignKeys)\n this.foreignKeys = options.foreignKeys.map(\n (foreignKey) =>\n new TableForeignKey({\n ...foreignKey,\n referencedDatabase:\n foreignKey?.referencedDatabase ||\n options.database,\n referencedSchema:\n foreignKey?.referencedSchema || options.schema,\n }),\n )\n\n if (options.uniques)\n this.uniques = options.uniques.map(\n (unique) => new TableUnique(unique),\n )\n\n if (options.checks)\n this.checks = options.checks.map(\n (check) => new TableCheck(check),\n )\n\n if (options.exclusions)\n this.exclusions = options.exclusions.map(\n (exclusion) => new TableExclusion(exclusion),\n )\n\n if (options.justCreated !== undefined)\n this.justCreated = options.justCreated\n\n if (options.withoutRowid) this.withoutRowid = options.withoutRowid\n\n this.engine = options.engine\n }\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n get primaryColumns(): TableColumn[] {\n return this.columns.filter((column) => column.isPrimary)\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Clones this table to a new table with all properties cloned.\n */\n clone(): Table {\n return new Table({\n schema: this.schema,\n database: this.database,\n name: this.name,\n columns: this.columns.map((column) => column.clone()),\n indices: this.indices.map((constraint) => constraint.clone()),\n foreignKeys: this.foreignKeys.map((constraint) =>\n constraint.clone(),\n ),\n uniques: this.uniques.map((constraint) => constraint.clone()),\n checks: this.checks.map((constraint) => constraint.clone()),\n exclusions: this.exclusions.map((constraint) => constraint.clone()),\n justCreated: this.justCreated,\n withoutRowid: this.withoutRowid,\n engine: this.engine,\n })\n }\n\n /**\n * Add column and creates its constraints.\n */\n addColumn(column: TableColumn): void {\n this.columns.push(column)\n }\n\n /**\n * Remove column and its constraints.\n */\n removeColumn(column: TableColumn): void {\n const foundColumn = this.columns.find((c) => c.name === column.name)\n if (foundColumn)\n this.columns.splice(this.columns.indexOf(foundColumn), 1)\n }\n\n /**\n * Adds unique constraint.\n */\n addUniqueConstraint(uniqueConstraint: TableUnique): void {\n this.uniques.push(uniqueConstraint)\n if (uniqueConstraint.columnNames.length === 1) {\n const uniqueColumn = this.columns.find(\n (column) => column.name === uniqueConstraint.columnNames[0],\n )\n if (uniqueColumn) uniqueColumn.isUnique = true\n }\n }\n\n /**\n * Removes unique constraint.\n */\n removeUniqueConstraint(removedUnique: TableUnique): void {\n const foundUnique = this.uniques.find(\n (unique) => unique.name === removedUnique.name,\n )\n if (foundUnique) {\n this.uniques.splice(this.uniques.indexOf(foundUnique), 1)\n if (foundUnique.columnNames.length === 1) {\n const uniqueColumn = this.columns.find(\n (column) => column.name === foundUnique.columnNames[0],\n )\n if (uniqueColumn) uniqueColumn.isUnique = false\n }\n }\n }\n\n /**\n * Adds check constraint.\n */\n addCheckConstraint(checkConstraint: TableCheck): void {\n this.checks.push(checkConstraint)\n }\n\n /**\n * Removes check constraint.\n */\n removeCheckConstraint(removedCheck: TableCheck): void {\n const foundCheck = this.checks.find(\n (check) => check.name === removedCheck.name,\n )\n if (foundCheck) {\n this.checks.splice(this.checks.indexOf(foundCheck), 1)\n }\n }\n\n /**\n * Adds exclusion constraint.\n */\n addExclusionConstraint(exclusionConstraint: TableExclusion): void {\n this.exclusions.push(exclusionConstraint)\n }\n\n /**\n * Removes exclusion constraint.\n */\n removeExclusionConstraint(removedExclusion: TableExclusion): void {\n const foundExclusion = this.exclusions.find(\n (exclusion) => exclusion.name === removedExclusion.name,\n )\n if (foundExclusion) {\n this.exclusions.splice(this.exclusions.indexOf(foundExclusion), 1)\n }\n }\n\n /**\n * Adds foreign keys.\n */\n addForeignKey(foreignKey: TableForeignKey): void {\n this.foreignKeys.push(foreignKey)\n }\n\n /**\n * Removes foreign key.\n */\n removeForeignKey(removedForeignKey: TableForeignKey): void {\n const fk = this.foreignKeys.find(\n (foreignKey) => foreignKey.name === removedForeignKey.name,\n )\n if (fk) this.foreignKeys.splice(this.foreignKeys.indexOf(fk), 1)\n }\n\n /**\n * Adds index.\n */\n addIndex(index: TableIndex, isMysql: boolean = false): void {\n this.indices.push(index)\n\n // in Mysql unique indices and unique constraints are the same thing\n // if index is unique and have only one column, we mark this column as unique\n if (index.columnNames.length === 1 && index.isUnique && isMysql) {\n const column = this.columns.find(\n (c) => c.name === index.columnNames[0],\n )\n if (column) column.isUnique = true\n }\n }\n\n /**\n * Removes index.\n */\n removeIndex(tableIndex: TableIndex, isMysql: boolean = false): void {\n const index = this.indices.find(\n (index) => index.name === tableIndex.name,\n )\n if (index) {\n this.indices.splice(this.indices.indexOf(index), 1)\n\n // in Mysql unique indices and unique constraints are the same thing\n // if index is unique and have only one column, we move `unique` attribute from its column\n if (index.columnNames.length === 1 && index.isUnique && isMysql) {\n const column = this.columns.find(\n (c) => c.name === index.columnNames[0],\n )\n if (column)\n column.isUnique = this.indices.some(\n (ind) =>\n ind.columnNames.length === 1 &&\n ind.columnNames[0] === column.name &&\n !!index.isUnique,\n )\n }\n }\n }\n\n findColumnByName(name: string): TableColumn | undefined {\n return this.columns.find((column) => column.name === name)\n }\n\n /**\n * Returns all column indices.\n */\n findColumnIndices(column: TableColumn): TableIndex[] {\n return this.indices.filter((index) => {\n return !!index.columnNames.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n /**\n * Returns all column foreign keys.\n */\n findColumnForeignKeys(column: TableColumn): TableForeignKey[] {\n return this.foreignKeys.filter((foreignKey) => {\n return !!foreignKey.columnNames.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n /**\n * Returns all column uniques.\n */\n findColumnUniques(column: TableColumn): TableUnique[] {\n return this.uniques.filter((unique) => {\n return !!unique.columnNames.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n /**\n * Returns all column checks.\n */\n findColumnChecks(column: TableColumn): TableCheck[] {\n return this.checks.filter((check) => {\n return !!check.columnNames!.find(\n (columnName) => columnName === column.name,\n )\n })\n }\n\n // -------------------------------------------------------------------------\n // Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates table from a given entity metadata.\n */\n static create(entityMetadata: EntityMetadata, driver: Driver): Table {\n const database =\n entityMetadata.database === driver.database\n ? undefined\n : entityMetadata.database\n const schema =\n entityMetadata.schema === (driver.options as any).schema\n ? undefined\n : entityMetadata.schema\n\n const options: TableOptions = {\n database: entityMetadata.database,\n schema: entityMetadata.schema,\n name: driver.buildTableName(\n entityMetadata.tableName,\n schema,\n database,\n ),\n withoutRowid: entityMetadata.withoutRowid,\n engine: entityMetadata.engine,\n columns: entityMetadata.columns\n .filter((column) => column)\n .map((column) =>\n TableUtils.createTableColumnOptions(column, driver),\n ),\n indices: entityMetadata.indices\n .filter((index) => index.synchronize === true)\n .map((index) => TableIndex.create(index)),\n uniques: entityMetadata.uniques.map((unique) =>\n TableUnique.create(unique),\n ),\n checks: entityMetadata.checks.map((check) =>\n TableCheck.create(check),\n ),\n exclusions: entityMetadata.exclusions.map((exclusion) =>\n TableExclusion.create(exclusion),\n ),\n }\n\n return new Table(options)\n }\n}\n"],"sourceRoot":"../.."}
@@ -48,7 +48,7 @@ export declare class DateUtils {
48
48
  static simpleEnumToString(value: any): string;
49
49
  static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata): any;
50
50
  /**
51
- * Formats given number to "0x" format, e.g. if it is 1 then it will return "01".
51
+ * Formats given number to "0x" format, e.g. if the totalLength = 2 and the value is 1 then it will return "01".
52
52
  */
53
53
  private static formatZerolessValue;
54
54
  /**
@@ -21,7 +21,7 @@ export class DateUtils {
21
21
  */
22
22
  static mixedDateToDateString(value) {
23
23
  if (value instanceof Date)
24
- return (this.formatZerolessValue(value.getFullYear()) +
24
+ return (this.formatZerolessValue(value.getFullYear(), 4) +
25
25
  "-" +
26
26
  this.formatZerolessValue(value.getMonth() + 1) +
27
27
  "-" +
@@ -110,7 +110,7 @@ export class DateUtils {
110
110
  value = new Date(value);
111
111
  }
112
112
  if (value instanceof Date) {
113
- let finalValue = this.formatZerolessValue(value.getFullYear()) +
113
+ let finalValue = this.formatZerolessValue(value.getFullYear(), 4) +
114
114
  "-" +
115
115
  this.formatZerolessValue(value.getMonth() + 1) +
116
116
  "-" +
@@ -135,7 +135,7 @@ export class DateUtils {
135
135
  value = new Date(value);
136
136
  }
137
137
  if (value instanceof Date) {
138
- return (this.formatZerolessValue(value.getUTCFullYear()) +
138
+ return (this.formatZerolessValue(value.getUTCFullYear(), 4) +
139
139
  "-" +
140
140
  this.formatZerolessValue(value.getUTCMonth() + 1) +
141
141
  "-" +
@@ -196,12 +196,11 @@ export class DateUtils {
196
196
  // Private Static Methods
197
197
  // -------------------------------------------------------------------------
198
198
  /**
199
- * Formats given number to "0x" format, e.g. if it is 1 then it will return "01".
199
+ * Formats given number to "0x" format, e.g. if the totalLength = 2 and the value is 1 then it will return "01".
200
200
  */
201
- static formatZerolessValue(value) {
202
- if (value < 10)
203
- return "0" + value;
204
- return String(value);
201
+ static formatZerolessValue(value, totalLength = 2) {
202
+ const pad = "0".repeat(totalLength);
203
+ return String(`${pad}${value}`).slice(-totalLength);
205
204
  }
206
205
  /**
207
206
  * Formats given number to "0x" format, e.g. if it is 1 then it will return "01".
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/util/DateUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,qBAAqB,CACxB,SAAoC;QAEpC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAA;QAEhC,OAAO,OAAO,SAAS,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;YACrB,CAAC,CAAE,SAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAoB;QAC7C,IAAI,KAAK,YAAY,IAAI;YACrB,OAAO,CACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC7C,GA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Q,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAChE,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,KAAU;QAChC,OAAO,EAAE,GAAG,KAAK,CAAA;IACrB,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,KAAU,EAAE,cAA8B;QAChE,IACI,cAAc,CAAC,IAAI;YACnB,CAAC,KAAK,CAAC,KAAK,CAAC;YACb,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EACnD;YACE,4DAA4D;YAC5D,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;SAC1B;QAED,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,4EAA4E;IAC5E,yBAAyB;IACzB,4EAA4E;IAE5E;;OAEG;IACK,MAAM,CAAC,mBAAmB,CAAC,KAAa;QAC5C,IAAI,KAAK,GAAG,EAAE;YAAE,OAAO,GAAG,GAAG,KAAK,CAAA;QAElC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,GAAG,KAAK,CAAA;SACtB;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE;YACpB,OAAO,GAAG,GAAG,KAAK,CAAA;SACrB;aAAM;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACvB;IACL,CAAC;CACJ","file":"DateUtils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { parseISO } from \"date-fns\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getFullYear()) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n /**\n * new Date(ISOString) is not a reliable parser to date strings.\n * It's better to use 'date-fns' parser to parser string in ISO Format.\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n *\n * https://stackoverflow.com/a/2587398\n */\n let date =\n typeof mixedDate === \"string\" ? parseISO(mixedDate) : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear()) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear()) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number): string {\n if (value < 10) return \"0\" + value\n\n return String(value)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/util/DateUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB,4EAA4E;IAC5E,wBAAw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AAA;IACvD,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,GAAG,KAAK,CAAA;SACtB;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE;YACpB,OAAO,GAAG,GAAG,KAAK,CAAA;SACrB;aAAM;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACvB;IACL,CAAC;CACJ","file":"DateUtils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { parseISO } from \"date-fns\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n /**\n * new Date(ISOString) is not a reliable parser to date strings.\n * It's better to use 'date-fns' parser to parser string in ISO Format.\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n *\n * https://stackoverflow.com/a/2587398\n */\n let date =\n typeof mixedDate === \"string\" ? parseISO(mixedDate) : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n}\n"],"sourceRoot":".."}
File without changes
File without changes
package/cli.js CHANGED
File without changes
@@ -26,9 +26,13 @@ class CommandUtils {
26
26
  throw new Error(`Given data source file must contain export of a DataSource instance`);
27
27
  }
28
28
  const dataSourceExports = [];
29
- for (let fileExport in dataSourceFileExports) {
30
- if (InstanceChecker_1.InstanceChecker.isDataSource(dataSourceFileExports[fileExport])) {
31
- dataSourceExports.push(dataSourceFileExports[fileExport]);
29
+ for (const fileExportKey in dataSourceFileExports) {
30
+ const fileExport = dataSourceFileExports[fileExportKey];
31
+ // It is necessary to await here in case of the exported async value (Promise<DataSource>).
32
+ // e.g. the DataSource is instantiated with an async factory in the source file
33
+ const awaitedFileExport = fileExport instanceof Promise ? await fileExport : fileExport;
34
+ if (InstanceChecker_1.InstanceChecker.isDataSource(awaitedFileExport)) {
35
+ dataSourceExports.push(awaitedFileExport);
32
36
  }
33
37
  }
34
38
  if (dataSourceExports.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/CommandUtils.ts"],"names":[],"mappings":";;;;AAAA,+CAAwB;AACxB,mDAA4B;AAC5B,4DAA2B;AAC3B,oCAAuC;AAEvC,6DAAyD;AACzD,qDAAyD;AAEzD;;GAEG;AACH,MAAa,YAAY;IACrB,MAAM,CAAC,KAAK,CAAC,cAAc,CACvB,kBAA0B;QAE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ommandUtils.js","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport mkdirp from \"mkdirp\"\nimport { TypeORMError } from \"../error\"\nimport { DataSource } from \"../data-source\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Command line utils functions.\n */\nexport class CommandUtils {\n static async loadDataSource(\n dataSourceFilePath: string,\n ): Promise<DataSource> {\n let dataSourceFileExports\n try {\n ;[dataSourceFileExports] = await importOrRequireFile(\n dataSourceFilePath,\n )\n } catch (err) {\n throw new Error(\n `Unable to open file: \"${dataSourceFilePath}\". ${err.message}`,\n )\n }\n\n if (\n !dataSourceFileExports ||\n typeof dataSourceFileExports !== \"object\"\n ) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n\n const dataSourceExports = []\n for (let fileExport in dataSourceFileExports) {\n if (\n InstanceChecker.isDataSource(dataSourceFileExports[fileExport])\n ) {\n dataSourceExports.push(dataSourceFileExports[fileExport])\n }\n }\n\n if (dataSourceExports.length === 0) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n if (dataSourceExports.length > 1) {\n throw new Error(\n `Given data source file must contain only one export of DataSource instance`,\n )\n }\n return dataSourceExports[0]\n }\n\n /**\n * Creates directories recursively.\n */\n static createDirectories(directory: string) {\n return mkdirp(directory)\n }\n\n /**\n * Creates a file with the given content in the given path.\n */\n static async createFile(\n filePath: string,\n content: string,\n override: boolean = true,\n ): Promise<void> {\n await CommandUtils.createDirectories(path.dirname(filePath))\n return new Promise<void>((ok, fail) => {\n if (override === false && fs.existsSync(filePath)) return ok()\n\n fs.writeFile(filePath, content, (err) => (err ? fail(err) : ok()))\n })\n }\n\n /**\n * Reads everything from a given file and returns its content as a string.\n */\n static async readFile(filePath: string): Promise<string> {\n return new Promise<string>((ok, fail) => {\n fs.readFile(filePath, (err, data) =>\n err ? fail(err) : ok(data.toString()),\n )\n })\n }\n\n static async fileExists(filePath: string) {\n return fs.existsSync(filePath)\n }\n\n /**\n * Gets migration timestamp and validates argument (if sent)\n */\n static getTimestamp(timestampOptionArgument: any): number {\n if (\n timestampOptionArgument &&\n (isNaN(timestampOptionArgument) || timestampOptionArgument < 0)\n ) {\n throw new TypeORMError(\n `timestamp option should be a non-negative number. received: ${timestampOptionArgument}`,\n )\n }\n return timestampOptionArgument\n ? new Date(Number(timestampOptionArgument)).getTime()\n : Date.now()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/CommandUtils.ts"],"names":[],"mappings":";;;;AAAA,+CAAwB;AACxB,mDAA4B;AAC5B,4DAA2B;AAC3B,oCAAuC;AAEvC,6DAAyD;AACzD,qDAAyD;AAEzD;;GAEG;AACH,MAAa,YAAY;IACrB,MAAM,CAAC,KAAK,CAAC,cAAc,CACvB,kBAA0B;QAE1B,IAAI,qBAAqB,CAAA;QACzB,IAAI;YACA,CAAC;YAAA,CAAC,qBAAqB,CAAC,GAAG,MAAM,IAAA,iCAAmB,EAChD,kBAAkB,CACrB,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,KAAK,CACX,yBAAyB,kBAAkB,MAAM,GAAG,CAAC,OAAO,EAAE,CACjE,CAAA;SACJ;QAED,IACI,CAAC,qBAAqB;YACtB,OAAO,qBAAqB,KAAK,QAAQ,EAC3C;YACE,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;SACJ;QAED,MAAM,iBAAiB,GAAG,EAAE,CAAA;QAC5B,KAAK,MAAM,aAAa,IAAI,qBAAqB,EAAE;YAC/C,MAAM,UAAU,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAAA;YACvD,2FAA2F;YAC3F,+EAA+E;YAC/E,MAAM,iBAAiB,GACnB,UAAU,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,CAAC,CAAC,UAAU,CAAA;YACjE,IAAI,iCAAe,CAAC,YAAY,CAAC,iBAAiB,CAAC,EAAE;g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AChC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CACxC,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAgB;QACpC,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,uBAA4B;QAC5C,IACI,uBAAuB;YACvB,CAAC,KAAK,CAAC,uBAAuB,CAAC,IAAI,uBAAuB,GAAG,CAAC,CAAC,EACjE;YACE,MAAM,IAAI,oBAAY,CAClB,+DAA+D,uBAAuB,EAAE,CAC3F,CAAA;SACJ;QACD,OAAO,uBAAuB;YAC1B,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,OAAO,EAAE;YACrD,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACpB,CAAC;CACJ;AAvGD,oCAuGC","file":"CommandUtils.js","sourcesContent":["import * as fs from \"fs\"\nimport * as path from \"path\"\nimport mkdirp from \"mkdirp\"\nimport { TypeORMError } from \"../error\"\nimport { DataSource } from \"../data-source\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { importOrRequireFile } from \"../util/ImportUtils\"\n\n/**\n * Command line utils functions.\n */\nexport class CommandUtils {\n static async loadDataSource(\n dataSourceFilePath: string,\n ): Promise<DataSource> {\n let dataSourceFileExports\n try {\n ;[dataSourceFileExports] = await importOrRequireFile(\n dataSourceFilePath,\n )\n } catch (err) {\n throw new Error(\n `Unable to open file: \"${dataSourceFilePath}\". ${err.message}`,\n )\n }\n\n if (\n !dataSourceFileExports ||\n typeof dataSourceFileExports !== \"object\"\n ) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n\n const dataSourceExports = []\n for (const fileExportKey in dataSourceFileExports) {\n const fileExport = dataSourceFileExports[fileExportKey]\n // It is necessary to await here in case of the exported async value (Promise<DataSource>).\n // e.g. the DataSource is instantiated with an async factory in the source file\n const awaitedFileExport =\n fileExport instanceof Promise ? await fileExport : fileExport\n if (InstanceChecker.isDataSource(awaitedFileExport)) {\n dataSourceExports.push(awaitedFileExport)\n }\n }\n\n if (dataSourceExports.length === 0) {\n throw new Error(\n `Given data source file must contain export of a DataSource instance`,\n )\n }\n if (dataSourceExports.length > 1) {\n throw new Error(\n `Given data source file must contain only one export of DataSource instance`,\n )\n }\n return dataSourceExports[0]\n }\n\n /**\n * Creates directories recursively.\n */\n static createDirectories(directory: string) {\n return mkdirp(directory)\n }\n\n /**\n * Creates a file with the given content in the given path.\n */\n static async createFile(\n filePath: string,\n content: string,\n override: boolean = true,\n ): Promise<void> {\n await CommandUtils.createDirectories(path.dirname(filePath))\n return new Promise<void>((ok, fail) => {\n if (override === false && fs.existsSync(filePath)) return ok()\n\n fs.writeFile(filePath, content, (err) => (err ? fail(err) : ok()))\n })\n }\n\n /**\n * Reads everything from a given file and returns its content as a string.\n */\n static async readFile(filePath: string): Promise<string> {\n return new Promise<string>((ok, fail) => {\n fs.readFile(filePath, (err, data) =>\n err ? fail(err) : ok(data.toString()),\n )\n })\n }\n\n static async fileExists(filePath: string) {\n return fs.existsSync(filePath)\n }\n\n /**\n * Gets migration timestamp and validates argument (if sent)\n */\n static getTimestamp(timestampOptionArgument: any): number {\n if (\n timestampOptionArgument &&\n (isNaN(timestampOptionArgument) || timestampOptionArgument < 0)\n ) {\n throw new TypeORMError(\n `timestamp option should be a non-negative number. received: ${timestampOptionArgument}`,\n )\n }\n return timestampOptionArgument\n ? new Date(Number(timestampOptionArgument)).getTime()\n : Date.now()\n }\n}\n"],"sourceRoot":".."}
@@ -588,7 +588,7 @@ Steps to run this project:
588
588
  packageJson.dependencies["oracledb"] = "^5.1.0";
589
589
  break;
590
590
  case "mssql":
591
- packageJson.dependencies["mssql"] = "^6.3.0";
591
+ packageJson.dependencies["mssql"] = "^7.3.0";
592
592
  break;
593
593
  case "mongodb":
594
594
  packageJson.dependencies["mongodb"] = "^3.0.8";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAmsB3E,CAAC;IAjsBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf,QAAQ,EACJ,8FAA8F;SACrG,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EACJ,4EAA4E;SACnF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;YACxB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,oDAAoD;SACjE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC;YAC5B,OAAO,EAAE,UAAU;YACnB,QAAQ,EACJ,wEAAwE;SAC/E,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI;YACA,MAAM,QAAQ,GAAY,IAAI,CAAC,QAAgB,IAAI,UAAU,CAAA;YAC7D,M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,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAxsBD,kCAwsBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^6.3.0\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAmsB3E,CAAC;IAjsBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf,QAAQ,EACJ,8FAA8F;SACrG,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EACJ,4EAA4E;SACnF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;YACxB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,oDAAoD;SACjE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC;YAC5B,OAAO,EAAE,UAAU;YACnB,QAAQ,EACJ,wEAAwE;SAC/E,CAAC,CAAA;IACV,CAAC;IAED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AAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAxsBD,kCAwsBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^7.3.0\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
@@ -9,6 +9,8 @@ export declare class MigrationRevertCommand implements yargs.CommandModule {
9
9
  dataSource: unknown;
10
10
  } & {
11
11
  transaction: string;
12
+ } & {
13
+ fake: boolean;
12
14
  }>;
13
15
  handler(args: yargs.Arguments): Promise<void>;
14
16
  }
@@ -25,6 +25,12 @@ class MigrationRevertCommand {
25
25
  alias: "t",
26
26
  default: "default",
27
27
  describe: "Indicates if transaction should be used or not for migration revert. Enabled by default.",
28
+ })
29
+ .option("fake", {
30
+ alias: "f",
31
+ type: "boolean",
32
+ default: false,
33
+ describe: "Fakes reverting the migration",
28
34
  });
29
35
  }
30
36
  async handler(args) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,sBAAsB;IAAnC;QACI,YAAO,GAAG,kBAAkB,CAAA;QAC5B,aAAQ,GAAG,kCAAkC,CAAA;IAiEjD,CAAC;IA/DG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,aAAa,EAAE;YACnB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YACl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CAAA;YAE9B,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAnED,wDAmEC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration revert. Enabled by default.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\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 subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AACzD,wDAAuB;AACv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O,CAAC,WAAW,GAAG,KAAK,CAAA;oBAC3B,MAAK;gBACT,KAAK,MAAM,CAAC;gBACZ,KAAK,OAAO;oBACR,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,KAAK,MAAM;oBACP,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,QAAQ;gBACR,OAAO;aACV;YAED,MAAM,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;YAC3C,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,6BAAa,CAAC,SAAS,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;YAE9D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAzED,wDAyEC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration revert. Enabled by default.\",\n })\n .option(\"fake\", {\n alias: \"f\",\n type: \"boolean\",\n default: false,\n describe: \"Fakes reverting the migration\",\n })\n }\n\n async handler(args: yargs.Arguments) {\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 subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -9,6 +9,8 @@ export declare class MigrationRunCommand implements yargs.CommandModule {
9
9
  dataSource: unknown;
10
10
  } & {
11
11
  transaction: string;
12
+ } & {
13
+ fake: boolean;
12
14
  }>;
13
15
  handler(args: yargs.Arguments): Promise<void>;
14
16
  }
@@ -25,6 +25,13 @@ class MigrationRunCommand {
25
25
  alias: "t",
26
26
  default: "default",
27
27
  describe: "Indicates if transaction should be used or not for migration run. Enabled by default.",
28
+ })
29
+ .option("fake", {
30
+ alias: "f",
31
+ type: "boolean",
32
+ default: false,
33
+ describe: "Fakes running the migrations if table schema has already been changed manually or externally " +
34
+ "(e.g. through another project)",
28
35
  });
29
36
  }
30
37
  async handler(args) {
@@ -42,6 +49,7 @@ class MigrationRunCommand {
42
49
  await dataSource.initialize();
43
50
  const options = {
44
51
  transaction: (_a = dataSource.options.migrationsTransactionMode) !== null && _a !== void 0 ? _a : "all",
52
+ fake: !!args.f,
45
53
  };
46
54
  switch (args.t) {
47
55
  case "all":
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRunCommand.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,yDAAkC;AAElC,6DAAyD;AA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AAK,MAAM;oBACP,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,QAAQ;gBACR,OAAO;aACV;YAED,MAAM,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;YACvC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,4BAA4B;YAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,6BAAa,CAAC,SAAS,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YAE3D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAtED,kDAsEC","file":"MigrationRunCommand.js","sourcesContent":["import path from \"path\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Runs migration command.\n */\nexport class MigrationRunCommand implements yargs.CommandModule {\n command = \"migration:run\"\n describe = \"Runs all pending migrations.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration run. Enabled by default.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\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 subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.runMigrations(options)\n await dataSource.destroy()\n\n // exit process if no errors\n process.exit(0)\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration run:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRunCommand.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,yDAAkC;AAElC,6DAAyD;AAEzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GAAG,8BAA8B,CAAA;IA6E7C,CAAC;IA3EG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,aAAa,EAAE;YACnB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YAClB,QAAQ,EACJ,uFAAuF;SAC9F,CAAC;aACD,MAAM,CAAC,MAAM,EAAE;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EACJ,+FAA+F;gBAC/F,gCAAgC;SACvC,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAA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"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Runs migration command.\n */\nexport class MigrationRunCommand implements yargs.CommandModule {\n command = \"migration:run\"\n describe = \"Runs all pending migrations.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration run. Enabled by default.\",\n })\n .option(\"fake\", {\n alias: \"f\",\n type: \"boolean\",\n default: false,\n describe:\n \"Fakes running the migrations if table schema has already been changed manually or externally \" +\n \"(e.g. through another project)\",\n })\n }\n\n async handler(args: yargs.Arguments) {\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 subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n fake: !!args.f,\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.runMigrations(options)\n await dataSource.destroy()\n\n // exit process if no errors\n process.exit(0)\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration run:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}