typeorm 0.2.42-dev.0626ed1 → 0.2.42-dev.1446e02

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 (282) hide show
  1. package/README.md +38 -0
  2. package/browser/common/RelationType.d.ts +14 -0
  3. package/browser/common/RelationType.js +3 -0
  4. package/browser/common/RelationType.js.map +1 -0
  5. package/browser/connection/BaseConnectionOptions.d.ts +5 -0
  6. package/browser/connection/BaseConnectionOptions.js.map +1 -1
  7. package/browser/connection/Connection.d.ts +7 -3
  8. package/browser/connection/Connection.js +47 -31
  9. package/browser/connection/Connection.js.map +1 -1
  10. package/browser/connection/ConnectionMetadataBuilder.d.ts +3 -3
  11. package/browser/connection/ConnectionMetadataBuilder.js +54 -22
  12. package/browser/connection/ConnectionMetadataBuilder.js.map +1 -1
  13. package/browser/connection/ConnectionOptionsReader.js +33 -28
  14. package/browser/connection/ConnectionOptionsReader.js.map +1 -1
  15. package/browser/connection/options-reader/ConnectionOptionsEnvReader.js +1 -0
  16. package/browser/connection/options-reader/ConnectionOptionsEnvReader.js.map +1 -1
  17. package/browser/decorator/Unique.d.ts +5 -4
  18. package/browser/decorator/Unique.js +7 -3
  19. package/browser/decorator/Unique.js.map +1 -1
  20. package/browser/decorator/options/RelationOptions.d.ts +1 -1
  21. package/browser/decorator/options/RelationOptions.js.map +1 -1
  22. package/browser/decorator/options/UniqueOptions.d.ts +10 -0
  23. package/browser/decorator/options/UniqueOptions.js +3 -0
  24. package/browser/decorator/options/UniqueOptions.js.map +1 -0
  25. package/browser/driver/aurora-data-api/AuroraDataApiQueryRunner.js +1 -1
  26. package/browser/driver/aurora-data-api/AuroraDataApiQueryRunner.js.map +1 -1
  27. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +7 -5
  28. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  29. package/browser/driver/cockroachdb/CockroachQueryRunner.js +1 -1
  30. package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  31. package/browser/driver/mysql/MysqlQueryRunner.js +1 -1
  32. package/browser/driver/mysql/MysqlQueryRunner.js.map +1 -1
  33. package/browser/driver/oracle/OracleQueryRunner.js +1 -1
  34. package/browser/driver/oracle/OracleQueryRunner.js.map +1 -1
  35. package/browser/driver/postgres/PostgresQueryRunner.js +12 -5
  36. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  37. package/browser/driver/sap/SapQueryRunner.js +1 -1
  38. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  39. package/browser/driver/sqlite/SqliteDriver.js +11 -10
  40. package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
  41. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1 -1
  42. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  43. package/browser/entity-manager/EntityManager.d.ts +2 -2
  44. package/browser/entity-manager/EntityManager.js +1 -1
  45. package/browser/entity-manager/EntityManager.js.map +1 -1
  46. package/browser/entity-manager/MongoEntityManager.js +2 -1
  47. package/browser/entity-manager/MongoEntityManager.js.map +1 -1
  48. package/browser/entity-schema/EntitySchemaRelationOptions.d.ts +1 -1
  49. package/browser/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
  50. package/browser/entity-schema/EntitySchemaTransformer.js +2 -1
  51. package/browser/entity-schema/EntitySchemaTransformer.js.map +1 -1
  52. package/browser/entity-schema/EntitySchemaUniqueOptions.d.ts +5 -0
  53. package/browser/entity-schema/EntitySchemaUniqueOptions.js.map +1 -1
  54. package/browser/find-options/FindOneOptions.d.ts +6 -0
  55. package/browser/find-options/FindOneOptions.js.map +1 -1
  56. package/browser/find-options/FindOptionsUtils.js +4 -0
  57. package/browser/find-options/FindOptionsUtils.js.map +1 -1
  58. package/browser/find-options/operator/Like.d.ts +1 -1
  59. package/browser/find-options/operator/Like.js +1 -1
  60. package/browser/find-options/operator/Like.js.map +1 -1
  61. package/browser/globals.js +34 -7
  62. package/browser/globals.js.map +1 -1
  63. package/browser/index.d.ts +2 -0
  64. package/browser/index.js +2 -0
  65. package/browser/index.js.map +1 -1
  66. package/browser/metadata/RelationMetadata.d.ts +1 -1
  67. package/browser/metadata/RelationMetadata.js.map +1 -1
  68. package/browser/metadata/UniqueMetadata.d.ts +5 -0
  69. package/browser/metadata/UniqueMetadata.js +1 -0
  70. package/browser/metadata/UniqueMetadata.js.map +1 -1
  71. package/browser/metadata-args/UniqueMetadataArgs.d.ts +5 -0
  72. package/browser/metadata-args/UniqueMetadataArgs.js.map +1 -1
  73. package/browser/metadata-builder/EntityMetadataValidator.js +1 -0
  74. package/browser/metadata-builder/EntityMetadataValidator.js.map +1 -1
  75. package/browser/migration/MigrationExecutor.js +1 -1
  76. package/browser/migration/MigrationExecutor.js.map +1 -1
  77. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js +3 -0
  78. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  79. package/browser/query-builder/DeleteQueryBuilder.d.ts +4 -2
  80. package/browser/query-builder/DeleteQueryBuilder.js +4 -2
  81. package/browser/query-builder/DeleteQueryBuilder.js.map +1 -1
  82. package/browser/query-builder/InsertQueryBuilder.d.ts +1 -1
  83. package/browser/query-builder/InsertQueryBuilder.js +1 -1
  84. package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
  85. package/browser/query-builder/NotBrackets.d.ts +7 -0
  86. package/browser/query-builder/NotBrackets.js +16 -0
  87. package/browser/query-builder/NotBrackets.js.map +1 -0
  88. package/browser/query-builder/QueryBuilder.d.ts +3 -2
  89. package/browser/query-builder/QueryBuilder.js +2 -1
  90. package/browser/query-builder/QueryBuilder.js.map +1 -1
  91. package/browser/query-builder/RelationLoader.js +11 -6
  92. package/browser/query-builder/RelationLoader.js.map +1 -1
  93. package/browser/query-builder/RelationQueryBuilder.d.ts +1 -1
  94. package/browser/query-builder/RelationQueryBuilder.js +1 -1
  95. package/browser/query-builder/RelationQueryBuilder.js.map +1 -1
  96. package/browser/query-builder/SelectQueryBuilder.d.ts +1 -1
  97. package/browser/query-builder/SelectQueryBuilder.js +1 -1
  98. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  99. package/browser/query-builder/SoftDeleteQueryBuilder.d.ts +1 -1
  100. package/browser/query-builder/SoftDeleteQueryBuilder.js +1 -1
  101. package/browser/query-builder/SoftDeleteQueryBuilder.js.map +1 -1
  102. package/browser/query-builder/UpdateQueryBuilder.d.ts +4 -2
  103. package/browser/query-builder/UpdateQueryBuilder.js +11 -6
  104. package/browser/query-builder/UpdateQueryBuilder.js.map +1 -1
  105. package/browser/query-builder/WhereExpressionBuilder.d.ts +3 -1
  106. package/browser/query-builder/WhereExpressionBuilder.js.map +1 -1
  107. package/browser/query-runner/BaseQueryRunner.d.ts +2 -2
  108. package/browser/query-runner/BaseQueryRunner.js +3 -3
  109. package/browser/query-runner/BaseQueryRunner.js.map +1 -1
  110. package/browser/repository/AbstractRepository.d.ts +2 -2
  111. package/browser/repository/AbstractRepository.js +2 -2
  112. package/browser/repository/AbstractRepository.js.map +1 -1
  113. package/browser/repository/BaseEntity.d.ts +1 -1
  114. package/browser/repository/BaseEntity.js +1 -1
  115. package/browser/repository/BaseEntity.js.map +1 -1
  116. package/browser/repository/Repository.d.ts +1 -1
  117. package/browser/repository/Repository.js +1 -1
  118. package/browser/repository/Repository.js.map +1 -1
  119. package/browser/repository/TreeRepository.js +1 -1
  120. package/browser/repository/TreeRepository.js.map +1 -1
  121. package/browser/schema-builder/RdbmsSchemaBuilder.js +1 -1
  122. package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  123. package/browser/schema-builder/options/TableUniqueOptions.d.ts +5 -0
  124. package/browser/schema-builder/options/TableUniqueOptions.js.map +1 -1
  125. package/browser/schema-builder/table/TableUnique.d.ts +5 -0
  126. package/browser/schema-builder/table/TableUnique.js +5 -2
  127. package/browser/schema-builder/table/TableUnique.js.map +1 -1
  128. package/browser/util/DirectoryExportedClassesLoader.d.ts +1 -1
  129. package/browser/util/DirectoryExportedClassesLoader.js +55 -31
  130. package/browser/util/DirectoryExportedClassesLoader.js.map +1 -1
  131. package/browser/util/ImportUtils.d.ts +1 -0
  132. package/browser/util/ImportUtils.js +90 -0
  133. package/browser/util/ImportUtils.js.map +1 -0
  134. package/commands/CommandUtils.d.ts +4 -0
  135. package/commands/CommandUtils.js +10 -0
  136. package/commands/CommandUtils.js.map +1 -1
  137. package/commands/InitCommand.d.ts +9 -7
  138. package/commands/InitCommand.js +72 -43
  139. package/commands/InitCommand.js.map +1 -1
  140. package/commands/MigrationCreateCommand.d.ts +2 -0
  141. package/commands/MigrationCreateCommand.js +7 -1
  142. package/commands/MigrationCreateCommand.js.map +1 -1
  143. package/commands/MigrationGenerateCommand.d.ts +2 -0
  144. package/commands/MigrationGenerateCommand.js +7 -1
  145. package/commands/MigrationGenerateCommand.js.map +1 -1
  146. package/commands/QueryCommand.d.ts +1 -1
  147. package/commands/QueryCommand.js +1 -1
  148. package/commands/QueryCommand.js.map +1 -1
  149. package/common/RelationType.d.ts +14 -0
  150. package/common/RelationType.js +4 -0
  151. package/common/RelationType.js.map +1 -0
  152. package/connection/BaseConnectionOptions.d.ts +5 -0
  153. package/connection/BaseConnectionOptions.js.map +1 -1
  154. package/connection/Connection.d.ts +7 -3
  155. package/connection/Connection.js +47 -31
  156. package/connection/Connection.js.map +1 -1
  157. package/connection/ConnectionMetadataBuilder.d.ts +3 -3
  158. package/connection/ConnectionMetadataBuilder.js +53 -21
  159. package/connection/ConnectionMetadataBuilder.js.map +1 -1
  160. package/connection/ConnectionOptionsReader.js +32 -27
  161. package/connection/ConnectionOptionsReader.js.map +1 -1
  162. package/connection/options-reader/ConnectionOptionsEnvReader.js +1 -0
  163. package/connection/options-reader/ConnectionOptionsEnvReader.js.map +1 -1
  164. package/decorator/Unique.d.ts +5 -4
  165. package/decorator/Unique.js +7 -3
  166. package/decorator/Unique.js.map +1 -1
  167. package/decorator/options/RelationOptions.d.ts +1 -1
  168. package/decorator/options/RelationOptions.js.map +1 -1
  169. package/decorator/options/UniqueOptions.d.ts +10 -0
  170. package/decorator/options/UniqueOptions.js +4 -0
  171. package/decorator/options/UniqueOptions.js.map +1 -0
  172. package/driver/aurora-data-api/AuroraDataApiQueryRunner.js +1 -1
  173. package/driver/aurora-data-api/AuroraDataApiQueryRunner.js.map +1 -1
  174. package/driver/better-sqlite3/BetterSqlite3Driver.js +7 -5
  175. package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  176. package/driver/cockroachdb/CockroachQueryRunner.js +1 -1
  177. package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  178. package/driver/mysql/MysqlQueryRunner.js +1 -1
  179. package/driver/mysql/MysqlQueryRunner.js.map +1 -1
  180. package/driver/oracle/OracleQueryRunner.js +1 -1
  181. package/driver/oracle/OracleQueryRunner.js.map +1 -1
  182. package/driver/postgres/PostgresQueryRunner.js +12 -5
  183. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  184. package/driver/sap/SapQueryRunner.js +1 -1
  185. package/driver/sap/SapQueryRunner.js.map +1 -1
  186. package/driver/sqlite/SqliteDriver.js +11 -10
  187. package/driver/sqlite/SqliteDriver.js.map +1 -1
  188. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1 -1
  189. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  190. package/entity-manager/EntityManager.d.ts +2 -2
  191. package/entity-manager/EntityManager.js +1 -1
  192. package/entity-manager/EntityManager.js.map +1 -1
  193. package/entity-manager/MongoEntityManager.js +2 -1
  194. package/entity-manager/MongoEntityManager.js.map +1 -1
  195. package/entity-schema/EntitySchemaRelationOptions.d.ts +1 -1
  196. package/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
  197. package/entity-schema/EntitySchemaTransformer.js +2 -1
  198. package/entity-schema/EntitySchemaTransformer.js.map +1 -1
  199. package/entity-schema/EntitySchemaUniqueOptions.d.ts +5 -0
  200. package/entity-schema/EntitySchemaUniqueOptions.js.map +1 -1
  201. package/find-options/FindOneOptions.d.ts +6 -0
  202. package/find-options/FindOneOptions.js.map +1 -1
  203. package/find-options/FindOptionsUtils.js +4 -0
  204. package/find-options/FindOptionsUtils.js.map +1 -1
  205. package/find-options/operator/Like.d.ts +1 -1
  206. package/find-options/operator/Like.js +1 -1
  207. package/find-options/operator/Like.js.map +1 -1
  208. package/globals.js +33 -6
  209. package/globals.js.map +1 -1
  210. package/index.d.ts +2 -0
  211. package/index.js +4 -1
  212. package/index.js.map +1 -1
  213. package/index.mjs +352 -0
  214. package/metadata/RelationMetadata.d.ts +1 -1
  215. package/metadata/RelationMetadata.js.map +1 -1
  216. package/metadata/UniqueMetadata.d.ts +5 -0
  217. package/metadata/UniqueMetadata.js +1 -0
  218. package/metadata/UniqueMetadata.js.map +1 -1
  219. package/metadata-args/UniqueMetadataArgs.d.ts +5 -0
  220. package/metadata-args/UniqueMetadataArgs.js.map +1 -1
  221. package/metadata-builder/EntityMetadataValidator.js +1 -0
  222. package/metadata-builder/EntityMetadataValidator.js.map +1 -1
  223. package/migration/MigrationExecutor.js +1 -1
  224. package/migration/MigrationExecutor.js.map +1 -1
  225. package/package.json +1 -1
  226. package/persistence/subject-builder/OneToManySubjectBuilder.js +3 -0
  227. package/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  228. package/query-builder/DeleteQueryBuilder.d.ts +4 -2
  229. package/query-builder/DeleteQueryBuilder.js +4 -2
  230. package/query-builder/DeleteQueryBuilder.js.map +1 -1
  231. package/query-builder/InsertQueryBuilder.d.ts +1 -1
  232. package/query-builder/InsertQueryBuilder.js +1 -1
  233. package/query-builder/InsertQueryBuilder.js.map +1 -1
  234. package/query-builder/NotBrackets.d.ts +7 -0
  235. package/query-builder/NotBrackets.js +19 -0
  236. package/query-builder/NotBrackets.js.map +1 -0
  237. package/query-builder/QueryBuilder.d.ts +3 -2
  238. package/query-builder/QueryBuilder.js +2 -1
  239. package/query-builder/QueryBuilder.js.map +1 -1
  240. package/query-builder/RelationLoader.js +11 -6
  241. package/query-builder/RelationLoader.js.map +1 -1
  242. package/query-builder/RelationQueryBuilder.d.ts +1 -1
  243. package/query-builder/RelationQueryBuilder.js +1 -1
  244. package/query-builder/RelationQueryBuilder.js.map +1 -1
  245. package/query-builder/SelectQueryBuilder.d.ts +1 -1
  246. package/query-builder/SelectQueryBuilder.js +1 -1
  247. package/query-builder/SelectQueryBuilder.js.map +1 -1
  248. package/query-builder/SoftDeleteQueryBuilder.d.ts +1 -1
  249. package/query-builder/SoftDeleteQueryBuilder.js +1 -1
  250. package/query-builder/SoftDeleteQueryBuilder.js.map +1 -1
  251. package/query-builder/UpdateQueryBuilder.d.ts +4 -2
  252. package/query-builder/UpdateQueryBuilder.js +11 -6
  253. package/query-builder/UpdateQueryBuilder.js.map +1 -1
  254. package/query-builder/WhereExpressionBuilder.d.ts +3 -1
  255. package/query-builder/WhereExpressionBuilder.js.map +1 -1
  256. package/query-runner/BaseQueryRunner.d.ts +2 -2
  257. package/query-runner/BaseQueryRunner.js +3 -3
  258. package/query-runner/BaseQueryRunner.js.map +1 -1
  259. package/repository/AbstractRepository.d.ts +2 -2
  260. package/repository/AbstractRepository.js +2 -2
  261. package/repository/AbstractRepository.js.map +1 -1
  262. package/repository/BaseEntity.d.ts +1 -1
  263. package/repository/BaseEntity.js +1 -1
  264. package/repository/BaseEntity.js.map +1 -1
  265. package/repository/Repository.d.ts +1 -1
  266. package/repository/Repository.js +1 -1
  267. package/repository/Repository.js.map +1 -1
  268. package/repository/TreeRepository.js +1 -1
  269. package/repository/TreeRepository.js.map +1 -1
  270. package/schema-builder/RdbmsSchemaBuilder.js +1 -1
  271. package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  272. package/schema-builder/options/TableUniqueOptions.d.ts +5 -0
  273. package/schema-builder/options/TableUniqueOptions.js.map +1 -1
  274. package/schema-builder/table/TableUnique.d.ts +5 -0
  275. package/schema-builder/table/TableUnique.js +5 -2
  276. package/schema-builder/table/TableUnique.js.map +1 -1
  277. package/util/DirectoryExportedClassesLoader.d.ts +1 -1
  278. package/util/DirectoryExportedClassesLoader.js +54 -31
  279. package/util/DirectoryExportedClassesLoader.js.map +1 -1
  280. package/util/ImportUtils.d.ts +1 -0
  281. package/util/ImportUtils.js +94 -0
  282. package/util/ImportUtils.js.map +1 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,+CAA8C;AAE9C,sDAA6B;AAE7B,6DAA0B;AAC1B,+CAAqC;AACrC,sDAAqD;AAErD;;GAEG;AACH;IAAA;QACI,YAAO,GAAG,MAAM,CAAC;QACjB,aAAQ,GAAG,+CAA+C;YACtD,wEAAwE;YACxE,mEAAmE,CAAC;IAilB5E,CAAC;IA/kBG,6BAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,gDAAgD;SAC7D,CAAC;aACD,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,EAAE,yDAAyD;SACtE,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EAAE,4EAA4E;SACzF,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,CAAC;IACX,CAAC;IAEK,6BAAO,GAAb,UAAc,IAAqB;;;;;;;wBAErB,QAAQ,GAAW,IAAI,CAAC,QAAe,IAAI,OAAO,CAAC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,CAAA,sBAAsB;YAC3E,OAAO,EAAE,+DAA+D;SAC3E,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAEL,kBAAC;AAAD,CArlBA,AAqlBC,IAAA;AArlBY,kCAAW","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\";\nimport { ObjectLiteral } from \"../common/ObjectLiteral\";\nimport * as path from \"path\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { exec } from \"child_process\";\nimport { TypeORMError } from \"../error/TypeORMError\";\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\";\n describe = \"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(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which to run a query\"\n })\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: \"Indicates if express should be included in the project.\"\n })\n .option(\"docker\", {\n describe: \"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 }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = args.database as any || \"mysql\";\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 ? path.basename(args.name as any) : undefined;\n const installNpm = args.pm === \"yarn\" ? false : true;\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.getPackageJsonTemplate(projectName), false);\n if (isDocker)\n await CommandUtils.createFile(basePath + \"/docker-compose.yml\", InitCommand.getDockerComposeTemplate(database), false);\n await CommandUtils.createFile(basePath + \"/.gitignore\", InitCommand.getGitIgnoreFile());\n await CommandUtils.createFile(basePath + \"/README.md\", InitCommand.getReadmeTemplate({ docker: isDocker }), false);\n await CommandUtils.createFile(basePath + \"/tsconfig.json\", InitCommand.getTsConfigTemplate());\n await CommandUtils.createFile(basePath + \"/ormconfig.json\", InitCommand.getOrmConfigTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/entity/User.ts\", InitCommand.getUserEntityTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/index.ts\", InitCommand.getAppIndexTemplate(isExpress));\n await CommandUtils.createDirectories(basePath + \"/src/migration\");\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(basePath + \"/src/routes.ts\", InitCommand.getRoutesTemplate());\n await CommandUtils.createFile(basePath + \"/src/controller/UserController.ts\", InitCommand.getControllerTemplate());\n }\n\n const packageJsonContents = await CommandUtils.readFile(basePath + \"/package.json\");\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.appendPackageJson(packageJsonContents, database, isExpress));\n\n if (args.name) {\n console.log(chalk.green(`Project created inside ${chalk.blue(basePath)} directory.`));\n\n } else {\n console.log(chalk.green(`Project created inside current directory.`));\n }\n\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\");\n } else {\n await InitCommand.executeCommand(\"yarn install\");\n }\n\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during project initialization:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, (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 getOrmConfigTemplate(database: string): string {\n const options: ObjectLiteral = {};\n switch (database) {\n case \"mysql\":\n Object.assign(options, {\n type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"mariadb\":\n Object.assign(options, {\n type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"sqlite\":\n Object.assign(options, {\n type: \"sqlite\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"better-sqlite3\":\n Object.assign(options, {\n type: \"better-sqlite3\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"postgres\":\n Object.assign(options, {\n \"type\": \"postgres\",\n \"host\": \"localhost\",\n \"port\": 5432,\n \"username\": \"test\",\n \"password\": \"test\",\n \"database\": \"test\",\n });\n break;\n case \"cockroachdb\":\n Object.assign(options, {\n \"type\": \"cockroachdb\",\n \"host\": \"localhost\",\n \"port\": 26257,\n \"username\": \"root\",\n \"password\": \"\",\n \"database\": \"defaultdb\",\n });\n break;\n case \"mssql\":\n Object.assign(options, {\n \"type\": \"mssql\",\n \"host\": \"localhost\",\n \"username\": \"sa\",\n \"password\": \"Admin12345\",\n \"database\": \"tempdb\",\n });\n break;\n case \"oracle\":\n Object.assign(options, {\n \"type\": \"oracle\",\n \"host\": \"localhost\",\n \"username\": \"system\",\n \"password\": \"oracle\",\n \"port\": 1521,\n \"sid\": \"xe.oracle.docker\",\n });\n break;\n case \"mongodb\":\n Object.assign(options, {\n \"type\": \"mongodb\",\n \"database\": \"test\",\n });\n break;\n }\n Object.assign(options, {\n synchronize: true,\n logging: false,\n entities: [\n \"src/entity/**/*.ts\"\n ],\n migrations: [\n \"src/migration/**/*.ts\"\n ],\n subscribers: [\n \"src/subscriber/**/*.ts\"\n ],\n cli: {\n entitiesDir: \"src/entity\",\n migrationsDir: \"src/migration\",\n subscribersDir: \"src/subscriber\"\n }\n });\n return JSON.stringify(options, undefined, 3);\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(): string {\n return JSON.stringify({\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, 3);\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, ${ database === \"mongodb\" ? \"ObjectIdColumn, ObjectID\" : \"PrimaryGeneratedColumn\" }, Column} from \"typeorm\";\n\n@Entity()\nexport class User {\n\n ${ database === \"mongodb\" ? \"@ObjectIdColumn()\" : \"@PrimaryGeneratedColumn()\" }\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(): string {\n return `import {UserController} from \"./controller/UserController\";\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(): string {\n return `import {getRepository} from \"typeorm\";\nimport {NextFunction, Request, Response} from \"express\";\nimport {User} from \"../entity/User\";\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.findOne(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(express: boolean): string {\n if (express) {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport * as express from \"express\";\nimport * as bodyParser from \"body-parser\";\nimport {Request, Response} from \"express\";\nimport {Routes} from \"./routes\";\nimport {User} from \"./entity/User\";\n\ncreateConnection().then(async connection => {\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 connection.manager.save(connection.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n }));\n await connection.manager.save(connection.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\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\n } else {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport {User} from \"./entity/User\";\n\ncreateConnection().then(async connection => {\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 connection.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 connection.manager.find(User);\n console.log(\"Loaded users: \", users);\n\n console.log(\"Here you can setup and run express/koa/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(projectName?: string): string {\n return JSON.stringify({\n name: projectName || \"new-typeorm-project\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n devDependencies: {\n },\n dependencies: {\n },\n scripts: {\n }\n }, undefined, 3);\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n\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(`You cannot initialize a project with docker for Oracle driver yet.`); // 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 }\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 \\`ormconfig.json\\` 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(packageJsonContents: string, database: string, express: boolean /*, docker: boolean*/): string {\n const packageJson = JSON.parse(packageJsonContents);\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {};\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"3.3.0\",\n \"@types/node\": \"^8.0.29\",\n \"typescript\": \"3.3.3333\"\n });\n\n if (!packageJson.dependencies) packageJson.dependencies = {};\n Object.assign(packageJson.dependencies, {\n \"typeorm\": require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.10\"\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\"] = \"^4.0.3\";\n break;\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\";\n break;\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^1.13.1\";\n break;\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^4.0.4\";\n break;\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\";\n break;\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.15.4\";\n packageJson.dependencies[\"body-parser\"] = \"^1.18.1\";\n }\n\n if (!packageJson.scripts) packageJson.scripts = {};\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */\"ts-node src/index.ts\",\n typeorm: \"node --require ts-node/register ./node_modules/typeorm/cli.js\"\n });\n return JSON.stringify(packageJson, undefined, 3);\n }\n\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,+CAA8C;AAE9C,sDAA6B;AAE7B,6DAA0B;AAC1B,+CAAqC;AACrC,sDAAqD;AAErD;;GAEG;AACH;IAAA;QACI,YAAO,GAAG,MAAM,CAAC;QACjB,aAAQ,GAAG,+CAA+C;YACtD,wEAAwE;YACxE,mEAAmE,CAAC;IAinB5E,CAAC;IA/mBG,6BAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,gDAAgD;SAC7D,CAAC;aACD,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,EAAE,yDAAyD;SACtE,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EAAE,4EAA4E;SACzF,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,EAA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CAAC,GAAG,SAAS,CAAC;SACvD;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;QAEnD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAA,wCAAwC;gBAC7F,OAAO,EAAE,yDAAyD;aACrE,CAAC,CAAC;;YAEH,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAA,sBAAsB;gBAC3E,OAAO,EAAE,+DAA+D;aAC3E,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAEL,kBAAC;AAAD,CArnBA,AAqnBC,IAAA;AArnBY,kCAAW","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\";\nimport { ObjectLiteral } from \"../common/ObjectLiteral\";\nimport * as path from \"path\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { exec } from \"child_process\";\nimport { TypeORMError } from \"../error/TypeORMError\";\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\";\n describe = \"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(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which to run a query\"\n })\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: \"Indicates if express should be included in the project.\"\n })\n .option(\"docker\", {\n describe: \"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: \"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 || \"mysql\";\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 ? path.basename(args.name as any) : undefined;\n const installNpm = args.pm === \"yarn\" ? false : true;\n const projectIsEsm = args.ms === \"esm\";\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.getPackageJsonTemplate(projectName, projectIsEsm), false);\n if (isDocker)\n await CommandUtils.createFile(basePath + \"/docker-compose.yml\", InitCommand.getDockerComposeTemplate(database), false);\n await CommandUtils.createFile(basePath + \"/.gitignore\", InitCommand.getGitIgnoreFile());\n await CommandUtils.createFile(basePath + \"/README.md\", InitCommand.getReadmeTemplate({ docker: isDocker }), false);\n await CommandUtils.createFile(basePath + \"/tsconfig.json\", InitCommand.getTsConfigTemplate(projectIsEsm));\n await CommandUtils.createFile(basePath + \"/ormconfig.json\", InitCommand.getOrmConfigTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/entity/User.ts\", InitCommand.getUserEntityTemplate(database));\n await CommandUtils.createFile(basePath + \"/src/index.ts\", InitCommand.getAppIndexTemplate(isExpress, projectIsEsm));\n await CommandUtils.createDirectories(basePath + \"/src/migration\");\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(basePath + \"/src/routes.ts\", InitCommand.getRoutesTemplate(projectIsEsm));\n await CommandUtils.createFile(basePath + \"/src/controller/UserController.ts\", InitCommand.getControllerTemplate(projectIsEsm));\n }\n\n const packageJsonContents = await CommandUtils.readFile(basePath + \"/package.json\");\n await CommandUtils.createFile(basePath + \"/package.json\", InitCommand.appendPackageJson(packageJsonContents, database, isExpress, projectIsEsm));\n\n if (args.name) {\n console.log(chalk.green(`Project created inside ${chalk.blue(basePath)} directory.`));\n\n } else {\n console.log(chalk.green(`Project created inside current directory.`));\n }\n\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath);\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath);\n }\n\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during project initialization:\"));\n console.error(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 getOrmConfigTemplate(database: string): string {\n const options: ObjectLiteral = {};\n switch (database) {\n case \"mysql\":\n Object.assign(options, {\n type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"mariadb\":\n Object.assign(options, {\n type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",\n });\n break;\n case \"sqlite\":\n Object.assign(options, {\n type: \"sqlite\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"better-sqlite3\":\n Object.assign(options, {\n type: \"better-sqlite3\",\n \"database\": \"database.sqlite\",\n });\n break;\n case \"postgres\":\n Object.assign(options, {\n \"type\": \"postgres\",\n \"host\": \"localhost\",\n \"port\": 5432,\n \"username\": \"test\",\n \"password\": \"test\",\n \"database\": \"test\",\n });\n break;\n case \"cockroachdb\":\n Object.assign(options, {\n \"type\": \"cockroachdb\",\n \"host\": \"localhost\",\n \"port\": 26257,\n \"username\": \"root\",\n \"password\": \"\",\n \"database\": \"defaultdb\",\n });\n break;\n case \"mssql\":\n Object.assign(options, {\n \"type\": \"mssql\",\n \"host\": \"localhost\",\n \"username\": \"sa\",\n \"password\": \"Admin12345\",\n \"database\": \"tempdb\",\n });\n break;\n case \"oracle\":\n Object.assign(options, {\n \"type\": \"oracle\",\n \"host\": \"localhost\",\n \"username\": \"system\",\n \"password\": \"oracle\",\n \"port\": 1521,\n \"sid\": \"xe.oracle.docker\",\n });\n break;\n case \"mongodb\":\n Object.assign(options, {\n \"type\": \"mongodb\",\n \"database\": \"test\",\n });\n break;\n }\n Object.assign(options, {\n synchronize: true,\n logging: false,\n entities: [\n \"src/entity/**/*.ts\"\n ],\n migrations: [\n \"src/migration/**/*.ts\"\n ],\n subscribers: [\n \"src/subscriber/**/*.ts\"\n ],\n cli: {\n entitiesDir: \"src/entity\",\n migrationsDir: \"src/migration\",\n subscribersDir: \"src/subscriber\"\n }\n });\n return JSON.stringify(options, undefined, 3);\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 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, 3);\n else\n return JSON.stringify({\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, 3);\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, ${ database === \"mongodb\" ? \"ObjectIdColumn, ObjectID\" : \"PrimaryGeneratedColumn\" }, Column} from \"typeorm\";\n\n@Entity()\nexport class User {\n\n ${ database === \"mongodb\" ? \"@ObjectIdColumn()\" : \"@PrimaryGeneratedColumn()\" }\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${isEsm ? \".js\" : \"\"}\";\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.findOne(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(express: boolean, isEsm: boolean): string {\n if (express) {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport ${!isEsm ? \"* as \" : \"\"}express from \"express\";\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\";\nimport {Request, Response} from \"express\";\nimport {Routes} from \"./routes${isEsm ? \".js\" : \"\"}\";\nimport {User} from \"./entity/User${isEsm ? \".js\" : \"\"}\";\n\ncreateConnection().then(async connection => {\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 connection.manager.save(connection.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n }));\n await connection.manager.save(connection.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\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\n } else {\n return `import \"reflect-metadata\";\nimport {createConnection} from \"typeorm\";\nimport {User} from \"./entity/User${isEsm ? \".js\" : \"\"}\";\n\ncreateConnection().then(async connection => {\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 connection.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 connection.manager.find(User);\n console.log(\"Loaded users: \", users);\n\n console.log(\"Here you can setup and run express/koa/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(projectName?: string, projectIsEsm?: boolean): string {\n return JSON.stringify({\n name: projectName || \"new-typeorm-project\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {\n },\n dependencies: {\n },\n scripts: {\n }\n }, undefined, 3);\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n\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(`You cannot initialize a project with docker for Oracle driver yet.`); // 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 }\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 \\`ormconfig.json\\` 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(packageJsonContents: string, database: string, express: boolean, projectIsEsm: boolean /*, docker: boolean*/): string {\n const packageJson = JSON.parse(packageJsonContents);\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {};\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.4.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\"] = \"^4.0.3\";\n break;\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\";\n break;\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^1.13.1\";\n break;\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^4.0.4\";\n break;\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\";\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: \"node --loader ts-node/esm ./node_modules/typeorm/cli.js\"\n });\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */\"ts-node src/index.ts\",\n typeorm: \"node --require ts-node/register ./node_modules/typeorm/cli.js\"\n });\n\n return JSON.stringify(packageJson, undefined, 3);\n }\n\n}\n"],"sourceRoot":".."}
@@ -16,6 +16,8 @@ export declare class MigrationCreateCommand implements yargs.CommandModule {
16
16
  f: string;
17
17
  } & {
18
18
  o: boolean;
19
+ } & {
20
+ t: boolean;
19
21
  }>;
20
22
  handler(args: yargs.Arguments): Promise<void>;
21
23
  /**
@@ -41,6 +41,12 @@ var MigrationCreateCommand = /** @class */ (function () {
41
41
  type: "boolean",
42
42
  default: false,
43
43
  describe: "Generate a migration file on Javascript instead of Typescript",
44
+ })
45
+ .option("t", {
46
+ alias: "timestamp",
47
+ type: "number",
48
+ default: false,
49
+ describe: "Custom timestamp for the migration name",
44
50
  });
45
51
  };
46
52
  MigrationCreateCommand.prototype.handler = function (args) {
@@ -55,7 +61,7 @@ var MigrationCreateCommand = /** @class */ (function () {
55
61
  _a.label = 1;
56
62
  case 1:
57
63
  _a.trys.push([1, 7, , 8]);
58
- timestamp = new Date().getTime();
64
+ timestamp = CommandUtils_1.CommandUtils.getTimestamp(args.timestamp);
59
65
  fileContent = args.outputJs ?
60
66
  MigrationCreateCommand.getJavascriptTemplate(args.name, timestamp)
61
67
  : MigrationCreateCommand.getTemplate(args.name, timestamp);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAE1B;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,kBAAkB,CAAC;QAC7B,aAAQ,GAAG,+BAA+B,CAAC;QAC3C,YAAO,GAAG,mBAAmB,CAAC;IA6GlC,CAAC;IA3GG,wCAAO,GAAP,UAAQ,IAAgB;QACp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5B,UAA6B,IAAY,EAAE,SAAiB;QACxD,OAAO,gFAEA,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS,gMAS/C,CAAC;IACE,CAAC;IAED;;OAEG;IACc,4CAAqB,GAAtC,UAAuC,IAAY,EAAE,SAAiB;QAClE,OAAO,iGAEU,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS,kGAQjD,CAAC;IACN,CAAC;IACL,6BAAC;AAAD,CAjHA,AAiHC,IAAA;AAjHY,wDAAsB","file":"MigrationCreateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\n\n/**\n * Creates a new migration file.\n */\nexport class MigrationCreateCommand implements yargs.CommandModule {\n\n command = \"migration:create\";\n describe = \"Creates a new migration file.\";\n aliases = \"migrations:create\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which run a query.\"\n })\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the migration class.\",\n demand: true\n })\n .option(\"d\", {\n alias: \"dir\",\n describe: \"Directory where migration should be created.\"\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"Generate a migration file on Javascript instead of Typescript\",\n });\n }\n\n async handler(args: yargs.Arguments) {\n if (args._[0] === \"migrations:create\") {\n console.log(\"'migrations:create' is deprecated, please use 'migration:create' instead\");\n }\n\n try {\n const timestamp = new Date().getTime();\n const fileContent = args.outputJs ?\n MigrationCreateCommand.getJavascriptTemplate(args.name as any, timestamp)\n : MigrationCreateCommand.getTemplate(args.name as any, timestamp);\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\n\n // if directory is not set then try to open tsconfig and find default path there\n if (!directory) {\n try {\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n directory = connectionOptions.cli ? (connectionOptions.cli.migrationsDir || \"\") : \"\";\n } catch (err) { }\n }\n\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (directory ? (directory + \"/\") : \"\") + filename;\n await CommandUtils.createFile(path, fileContent);\n console.log(`Migration ${chalk.blue(path)} has been generated successfully.`);\n\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during migration creation:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number): string {\n return `import {MigrationInterface, QueryRunner} from \"typeorm\";\n\nexport class ${camelCase(name, true)}${timestamp} implements MigrationInterface {\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number): string {\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${camelCase(name, true)}${timestamp} {\n\n async up(queryRunner) {\n }\n\n async down(queryRunner) {\n }\n}\n `;\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationCreateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAE1B;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,kBAAkB,CAAC;QAC7B,aAAQ,GAAG,+BAA+B,CAAC;QAC3C,YAAO,GAAG,mBAAm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kCAAkC,CAAC,CAAC,CAAC;wBACnE,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IAED,4EAA4E;IAC5E,2BAA2B;IAC3B,4EAA4E;IAE5E;;OAEG;IACc,kCAAW,GAA5B,UAA6B,IAAY,EAAE,SAAiB;QACxD,OAAO,gFAEA,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS,gMAS/C,CAAC;IACE,CAAC;IAED;;OAEG;IACc,4CAAqB,GAAtC,UAAuC,IAAY,EAAE,SAAiB;QAClE,OAAO,iGAEU,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAS,kGAQjD,CAAC;IACN,CAAC;IACL,6BAAC;AAAD,CAvHA,AAuHC,IAAA;AAvHY,wDAAsB","file":"MigrationCreateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\n\n/**\n * Creates a new migration file.\n */\nexport class MigrationCreateCommand implements yargs.CommandModule {\n\n command = \"migration:create\";\n describe = \"Creates a new migration file.\";\n aliases = \"migrations:create\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which run a query.\"\n })\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the migration class.\",\n demand: true\n })\n .option(\"d\", {\n alias: \"dir\",\n describe: \"Directory where migration should be created.\"\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n });\n }\n\n async handler(args: yargs.Arguments) {\n if (args._[0] === \"migrations:create\") {\n console.log(\"'migrations:create' is deprecated, please use 'migration:create' instead\");\n }\n\n try {\n const timestamp = CommandUtils.getTimestamp(args.timestamp);\n const fileContent = args.outputJs ?\n MigrationCreateCommand.getJavascriptTemplate(args.name as any, timestamp)\n : MigrationCreateCommand.getTemplate(args.name as any, timestamp);\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\n\n // if directory is not set then try to open tsconfig and find default path there\n if (!directory) {\n try {\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n directory = connectionOptions.cli ? (connectionOptions.cli.migrationsDir || \"\") : \"\";\n } catch (err) { }\n }\n\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (directory ? (directory + \"/\") : \"\") + filename;\n await CommandUtils.createFile(path, fileContent);\n console.log(`Migration ${chalk.blue(path)} has been generated successfully.`);\n\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during migration creation:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number): string {\n return `import {MigrationInterface, QueryRunner} from \"typeorm\";\n\nexport class ${camelCase(name, true)}${timestamp} implements MigrationInterface {\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number): string {\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${camelCase(name, true)}${timestamp} {\n\n async up(queryRunner) {\n }\n\n async down(queryRunner) {\n }\n}\n `;\n }\n}\n"],"sourceRoot":".."}
@@ -22,6 +22,8 @@ export declare class MigrationGenerateCommand implements yargs.CommandModule {
22
22
  dr: boolean;
23
23
  } & {
24
24
  ch: boolean;
25
+ } & {
26
+ t: boolean;
25
27
  }>;
26
28
  handler(args: yargs.Arguments): Promise<void>;
27
29
  /**
@@ -62,6 +62,12 @@ var MigrationGenerateCommand = /** @class */ (function () {
62
62
  type: "boolean",
63
63
  default: false,
64
64
  describe: "Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.",
65
+ })
66
+ .option("t", {
67
+ alias: "timestamp",
68
+ type: "number",
69
+ default: false,
70
+ describe: "Custom timestamp for the migration name",
65
71
  });
66
72
  };
67
73
  MigrationGenerateCommand.prototype.handler = function (args) {
@@ -73,7 +79,7 @@ var MigrationGenerateCommand = /** @class */ (function () {
73
79
  if (args._[0] === "migrations:generate") {
74
80
  console.log("'migrations:generate' is deprecated, please use 'migration:generate' instead");
75
81
  }
76
- timestamp = new Date().getTime();
82
+ timestamp = CommandUtils_1.CommandUtils.getTimestamp(args.timestamp);
77
83
  extension = args.outputJs ? ".js" : ".ts";
78
84
  filename = timestamp + "-" + args.name + extension;
79
85
  directory = args.dir;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,sCAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAC1B,qEAA8D;AAE9D;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,oBAAoB,CAAC;QAC/B,aAAQ,GAAG,gFAAgF,CAAC;QAC5F,YAAO,GAAG,qBAAqB,CAAC;IA6NpC,CAAC;IA3NG,0CAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,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AE,MAAgB,EAAE,QAAkB;QACxG,IAAM,aAAa,GAAG,KAAG,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAW,CAAC;QAE7D,OAAO,iGAEU,aAAa,wBACxB,aAAa,0CAGzB,MAAM,CAAC,IAAI,CAAC,IACb,CAAC,kDAIA,QAAQ,CAAC,IAAI,CAAC,IACf,CAAC,iBAGD,CAAC;IACE,CAAC;IAED;;OAEG;IACc,sCAAa,GAA9B,UAA+B,KAAa;QACxC,IAAM,cAAc,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACzD,OAAO,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CAAC;IAC/E,CAAC;IACL,+BAAC;AAAD,CAjOA,AAiOC,IAAA;AAjOY,4DAAwB","file":"MigrationGenerateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {createConnection} from \"../globals\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\";\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n\n command = \"migration:generate\";\n describe = \"Generates a new migration file with sql needs to be executed to update schema.\";\n aliases = \"migrations:generate\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which run a query.\"\n })\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the migration class.\",\n demand: true,\n type: \"string\"\n })\n .option(\"d\", {\n alias: \"dir\",\n describe: \"Directory where migration should be created.\"\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe: \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe: \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n });\n }\n\n async handler(args: yargs.Arguments) {\n if (args._[0] === \"migrations:generate\") {\n console.log(\"'migrations:generate' is deprecated, please use 'migration:generate' instead\");\n }\n\n const timestamp = new Date().getTime();\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\n\n // if directory is not set then try to open tsconfig and find default path there\n if (!directory) {\n try {\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n directory = connectionOptions.cli ? connectionOptions.cli.migrationsDir : undefined;\n } catch (err) { }\n }\n\n try {\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n Object.assign(connectionOptions, {\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false\n });\n\n const upSqls: string[] = [], downSqls: string[] = [];\n\n const connection = await createConnection(connectionOptions);\n try {\n const sqlInMemory = await connection.driver.createSchemaBuilder().log();\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach(upQuery => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(upQuery.query);\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downQuery.query = MigrationGenerateCommand.prettifyQuery(downQuery.query);\n });\n }\n\n sqlInMemory.upQueries.forEach(upQuery => {\n upSqls.push(\" await queryRunner.query(`\" + upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(upQuery.parameters) + \");\");\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downSqls.push(\" await queryRunner.query(`\" + downQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(downQuery.parameters) + \");\");\n });\n } finally {\n await connection.close();\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(chalk.green(`No changes in database schema were found`));\n process.exit(0);\n } else {\n console.log(chalk.yellow(`No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`));\n process.exit(1);\n }\n } else if (!args.name) {\n console.log(chalk.yellow(\"Please specify a migration name using the `-n` argument\"));\n process.exit(1);\n }\n\n const fileContent = args.outputJs ?\n MigrationGenerateCommand.getJavascriptTemplate(args.name as any, timestamp, upSqls, downSqls.reverse()) :\n MigrationGenerateCommand.getTemplate(args.name as any, timestamp, upSqls, downSqls.reverse());\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (directory ? (directory + \"/\") : \"\") + filename;\n\n if (args.check) {\n console.log(chalk.yellow(`Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(fileContent)}`));\n process.exit(1);\n }\n\n if (args.dryrun) {\n console.log(chalk.green(`Migration ${chalk.blue(path)} has content:\\n\\n${chalk.white(fileContent)}`));\n } else {\n await CommandUtils.createFile(path, fileContent);\n\n console.log(chalk.green(`Migration ${chalk.blue(path)} has been generated successfully.`));\n }\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during migration generation:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\";\n }\n\n return `, ${JSON.stringify(parameters)}`;\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `import {MigrationInterface, QueryRunner} from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`;\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" });\n return \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \";\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationGenerateCommand.ts"],"names":[],"mappings":";;;;AAAA,iFAA8E;AAC9E,+CAA4C;AAC5C,sCAA4C;AAC5C,mDAA8C;AAE9C,6DAA0B;AAC1B,qEAA8D;AAE9D;;GAEG;AACH;IAAA;QAEI,YAAO,GAAG,oBAAoB,CAAC;QAC/B,aAAQ,GAAG,gFAAgF,CAAC;QAC5F,YAAO,GAAG,qBAAqB,CAAC;IAmOpC,CAAC;IAjOG,0CAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,8CAA8C;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ACb,CAAC,qFAIA,QAAQ,CAAC,IAAI,CAAC,IACf,CAAC,mBAID,CAAC;IACE,CAAC;IAED;;OAEG;IACc,8CAAqB,GAAtC,UAAuC,IAAY,EAAE,SAAiB,EAAE,MAAgB,EAAE,QAAkB;QACxG,IAAM,aAAa,GAAG,KAAG,IAAA,uBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,SAAW,CAAC;QAE7D,OAAO,iGAEU,aAAa,wBACxB,aAAa,0CAGzB,MAAM,CAAC,IAAI,CAAC,IACb,CAAC,kDAIA,QAAQ,CAAC,IAAI,CAAC,IACf,CAAC,iBAGD,CAAC;IACE,CAAC;IAED;;OAEG;IACc,sCAAa,GAA9B,UAA+B,KAAa;QACxC,IAAM,cAAc,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACzD,OAAO,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,YAAY,CAAC;IAC/E,CAAC;IACL,+BAAC;AAAD,CAvOA,AAuOC,IAAA;AAvOY,4DAAwB","file":"MigrationGenerateCommand.js","sourcesContent":["import {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {CommandUtils} from \"./CommandUtils\";\nimport {createConnection} from \"../globals\";\nimport {camelCase} from \"../util/StringUtils\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\nimport { format } from \"@sqltools/formatter/lib/sqlFormatter\";\n\n/**\n * Generates a new migration file with sql needs to be executed to update schema.\n */\nexport class MigrationGenerateCommand implements yargs.CommandModule {\n\n command = \"migration:generate\";\n describe = \"Generates a new migration file with sql needs to be executed to update schema.\";\n aliases = \"migrations:generate\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which run a query.\"\n })\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the migration class.\",\n demand: true,\n type: \"string\"\n })\n .option(\"d\", {\n alias: \"dir\",\n describe: \"Directory where migration should be created.\"\n })\n .option(\"p\", {\n alias: \"pretty\",\n type: \"boolean\",\n default: false,\n describe: \"Pretty-print generated SQL\",\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n })\n .option(\"o\", {\n alias: \"outputJs\",\n type: \"boolean\",\n default: false,\n describe: \"Generate a migration file on Javascript instead of Typescript\",\n })\n .option(\"dr\", {\n alias: \"dryrun\",\n type: \"boolean\",\n default: false,\n describe: \"Prints out the contents of the migration instead of writing it to a file\",\n })\n .option(\"ch\", {\n alias: \"check\",\n type: \"boolean\",\n default: false,\n describe: \"Verifies that the current database is up to date and that no migrations are needed. Otherwise exits with code 1.\",\n })\n .option(\"t\", {\n alias: \"timestamp\",\n type: \"number\",\n default: false,\n describe: \"Custom timestamp for the migration name\",\n });\n }\n\n async handler(args: yargs.Arguments) {\n if (args._[0] === \"migrations:generate\") {\n console.log(\"'migrations:generate' is deprecated, please use 'migration:generate' instead\");\n }\n\n const timestamp = CommandUtils.getTimestamp(args.timestamp);\n const extension = args.outputJs ? \".js\" : \".ts\";\n const filename = timestamp + \"-\" + args.name + extension;\n let directory = args.dir as string | undefined;\n\n // if directory is not set then try to open tsconfig and find default path there\n if (!directory) {\n try {\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n directory = connectionOptions.cli ? connectionOptions.cli.migrationsDir : undefined;\n } catch (err) { }\n }\n\n try {\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n Object.assign(connectionOptions, {\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false\n });\n\n const upSqls: string[] = [], downSqls: string[] = [];\n\n const connection = await createConnection(connectionOptions);\n try {\n const sqlInMemory = await connection.driver.createSchemaBuilder().log();\n\n if (args.pretty) {\n sqlInMemory.upQueries.forEach(upQuery => {\n upQuery.query = MigrationGenerateCommand.prettifyQuery(upQuery.query);\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downQuery.query = MigrationGenerateCommand.prettifyQuery(downQuery.query);\n });\n }\n\n sqlInMemory.upQueries.forEach(upQuery => {\n upSqls.push(\" await queryRunner.query(`\" + upQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(upQuery.parameters) + \");\");\n });\n sqlInMemory.downQueries.forEach(downQuery => {\n downSqls.push(\" await queryRunner.query(`\" + downQuery.query.replace(new RegExp(\"`\", \"g\"), \"\\\\`\") + \"`\" + MigrationGenerateCommand.queryParams(downQuery.parameters) + \");\");\n });\n } finally {\n await connection.close();\n }\n\n if (!upSqls.length) {\n if (args.check) {\n console.log(chalk.green(`No changes in database schema were found`));\n process.exit(0);\n } else {\n console.log(chalk.yellow(`No changes in database schema were found - cannot generate a migration. To create a new empty migration use \"typeorm migration:create\" command`));\n process.exit(1);\n }\n } else if (!args.name) {\n console.log(chalk.yellow(\"Please specify a migration name using the `-n` argument\"));\n process.exit(1);\n }\n\n const fileContent = args.outputJs ?\n MigrationGenerateCommand.getJavascriptTemplate(args.name as any, timestamp, upSqls, downSqls.reverse()) :\n MigrationGenerateCommand.getTemplate(args.name as any, timestamp, upSqls, downSqls.reverse());\n if (directory && !directory.startsWith(\"/\")) {\n directory = process.cwd() + \"/\" + directory;\n }\n const path = (directory ? (directory + \"/\") : \"\") + filename;\n\n if (args.check) {\n console.log(chalk.yellow(`Unexpected changes in database schema were found in check mode:\\n\\n${chalk.white(fileContent)}`));\n process.exit(1);\n }\n\n if (args.dryrun) {\n console.log(chalk.green(`Migration ${chalk.blue(path)} has content:\\n\\n${chalk.white(fileContent)}`));\n } else {\n await CommandUtils.createFile(path, fileContent);\n\n console.log(chalk.green(`Migration ${chalk.blue(path)} has been generated successfully.`));\n }\n } catch (err) {\n console.log(chalk.black.bgRed(\"Error during migration generation:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats query parameters for migration queries if parameters actually exist\n */\n protected static queryParams(parameters: any[] | undefined): string {\n if (!parameters || !parameters.length) {\n return \"\";\n }\n\n return `, ${JSON.stringify(parameters)}`;\n }\n\n /**\n * Gets contents of the migration file.\n */\n protected static getTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `import {MigrationInterface, QueryRunner} from \"typeorm\";\n\nexport class ${migrationName} implements MigrationInterface {\n name = '${migrationName}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${upSqls.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${downSqls.join(`\n`)}\n }\n\n}\n`;\n }\n\n /**\n * Gets contents of the migration file in Javascript.\n */\n protected static getJavascriptTemplate(name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {\n const migrationName = `${camelCase(name, true)}${timestamp}`;\n\n return `const { MigrationInterface, QueryRunner } = require(\"typeorm\");\n\nmodule.exports = class ${migrationName} {\n name = '${migrationName}'\n\n async up(queryRunner) {\n${upSqls.join(`\n`)}\n }\n\n async down(queryRunner) {\n${downSqls.join(`\n`)}\n }\n}\n`;\n }\n\n /**\n *\n */\n protected static prettifyQuery(query: string) {\n const formattedQuery = format(query, { indent: \" \" });\n return \"\\n\" + formattedQuery.replace(/^/gm, \" \") + \"\\n \";\n }\n}\n"],"sourceRoot":".."}
@@ -1,6 +1,6 @@
1
1
  import * as yargs from "yargs";
2
2
  /**
3
- * Executes an sql query on the given connection.
3
+ * Executes an SQL query on the given connection.
4
4
  */
5
5
  export declare class QueryCommand implements yargs.CommandModule {
6
6
  command: string;
@@ -7,7 +7,7 @@ var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader")
7
7
  var PlatformTools_1 = require("../platform/PlatformTools");
8
8
  var chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
9
9
  /**
10
- * Executes an sql query on the given connection.
10
+ * Executes an SQL query on the given connection.
11
11
  */
12
12
  var QueryCommand = /** @class */ (function () {
13
13
  function QueryCommand() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/QueryCommand.ts"],"names":[],"mappings":";;;;AAAA,sCAA4C;AAE5C,iFAA8E;AAE9E,2DAAwD;AAExD,6DAA0B;AAE1B;;GAEG;AACH;IAAA;QACI,YAAO,GAAG,eAAe,CAAC;QAC1B,aAAQ,GAAG,kHAAkH,CAAC;IAiElI,CAAC;IA/DG,8BAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,OAAO,EAAE;YACjB,QAAQ,EAAE,sBAAsB;YAChC,IAAI,EAAE,QAAQ;SACjB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,iDAAiD;SAC9D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,WAAW;YACpB,QAAQ,EAAE,iDAAiD;SAC9D,CAAC,CAAC;IACX,CAAC;IAEK,8BAAO,GAAb,UAAc,IAAqB;;;;;;wBAE3B,UAAU,GAAyB,SAAS,CAAC;wBAC7C,WAAW,GAA0B,SAAS,CAAC;;;;wBAIzC,uBAAuB,GAAG,IAAI,iDAAuB,CAAC;4BACxD,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE;4BACnB,UAAU,EAAE,IAAI,CAAC,MAAa;yBACjC,CAAC,CAAC;wBACuB,qBAAM,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAiB,CAAC,EAAA;;wBAA7E,iBAAiB,GAAG,SAAyD;wBACnF,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE;4BAC7B,WAAW,EAAE,K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GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;wBAChE,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IACL,mBAAC;AAAD,CAnEA,AAmEC,IAAA;AAnEY,oCAAY","file":"QueryCommand.js","sourcesContent":["import {createConnection} from \"../globals\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\n\n/**\n * Executes an sql query on the given connection.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query [query]\";\n describe = \"Executes given SQL query on a default connection. Specify connection name to run query on a specific connection.\";\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"query\", {\n describe: \"The SQL Query to run\",\n type: \"string\"\n })\n .option(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which to run a query.\"\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n });\n }\n\n async handler(args: yargs.Arguments) {\n\n let connection: Connection|undefined = undefined;\n let queryRunner: QueryRunner|undefined = undefined;\n try {\n\n // create a connection\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n Object.assign(connectionOptions, {\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false\n });\n connection = await createConnection(connectionOptions);\n\n // create a query runner and execute query using it\n queryRunner = connection.createQueryRunner();\n const query = args.query as string;\n console.log(chalk.green(\"Running query: \") + PlatformTools.highlightSql(query));\n const queryResult = await queryRunner.query(query);\n\n if (typeof queryResult === \"undefined\") {\n console.log(chalk.green(\"Query has been executed. No result was returned.\"));\n } else {\n console.log(chalk.green(\"Query has been executed. Result: \"));\n console.log(PlatformTools.highlightJson(JSON.stringify(queryResult, undefined, 2)));\n }\n\n await queryRunner.release();\n await connection.close();\n\n } catch (err) {\n if (queryRunner) await (queryRunner as QueryRunner).release();\n if (connection) await (connection as Connection).close();\n\n console.log(chalk.black.bgRed(\"Error during query execution:\"));\n console.error(err);\n process.exit(1);\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/QueryCommand.ts"],"names":[],"mappings":";;;;AAAA,sCAA4C;AAE5C,iFAA8E;AAE9E,2DAAwD;AAExD,6DAA0B;AAE1B;;GAEG;AACH;IAAA;QACI,YAAO,GAAG,eAAe,CAAC;QAC1B,aAAQ,GAAG,kHAAkH,CAAC;IAiElI,CAAC;IA/DG,8BAAO,GAAP,UAAQ,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,OAAO,EAAE;YACjB,QAAQ,EAAE,sBAAsB;YAChC,IAAI,EAAE,QAAQ;SACjB,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,iDAAiD;SAC9D,CAAC;aACD,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,WAAW;YACpB,QAAQ,EAAE,iDAAiD;SAC9D,CAAC,CAAC;IACX,CAAC;IAEK,8BAAO,GAAb,UAAc,IAAqB;;;;;;wBAE3B,UAAU,GAAyB,SAAS,CAAC;wBAC7C,WAAW,GAA0B,SAAS,CAAC;;;;wBAIzC,uBAAuB,GAAG,IAAI,iDAAuB,CAAC;4BACxD,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE;4BACnB,UAAU,EAAE,IAAI,CAAC,MAAa;yBACjC,CAAC,CAAC;wBACuB,qBAAM,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAiB,CAAC,EAAA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,yBAAU;wBAAE,qBAAO,UAAyB,CAAC,KAAK,EAAE,EAAA;;wBAAxC,SAAwC,CAAC;;;wBAEzD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;wBAChE,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IACL,mBAAC;AAAD,CAnEA,AAmEC,IAAA;AAnEY,oCAAY","file":"QueryCommand.js","sourcesContent":["import {createConnection} from \"../globals\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport * as yargs from \"yargs\";\nimport chalk from \"chalk\";\n\n/**\n * Executes an SQL query on the given connection.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query [query]\";\n describe = \"Executes given SQL query on a default connection. Specify connection name to run query on a specific connection.\";\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"query\", {\n describe: \"The SQL Query to run\",\n type: \"string\"\n })\n .option(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which to run a query.\"\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n });\n }\n\n async handler(args: yargs.Arguments) {\n\n let connection: Connection|undefined = undefined;\n let queryRunner: QueryRunner|undefined = undefined;\n try {\n\n // create a connection\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n Object.assign(connectionOptions, {\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false\n });\n connection = await createConnection(connectionOptions);\n\n // create a query runner and execute query using it\n queryRunner = connection.createQueryRunner();\n const query = args.query as string;\n console.log(chalk.green(\"Running query: \") + PlatformTools.highlightSql(query));\n const queryResult = await queryRunner.query(query);\n\n if (typeof queryResult === \"undefined\") {\n console.log(chalk.green(\"Query has been executed. No result was returned.\"));\n } else {\n console.log(chalk.green(\"Query has been executed. Result: \"));\n console.log(PlatformTools.highlightJson(JSON.stringify(queryResult, undefined, 2)));\n }\n\n await queryRunner.release();\n await connection.close();\n\n } catch (err) {\n if (queryRunner) await (queryRunner as QueryRunner).release();\n if (connection) await (connection as Connection).close();\n\n console.log(chalk.black.bgRed(\"Error during query execution:\"));\n console.error(err);\n process.exit(1);\n }\n }\n}\n"],"sourceRoot":".."}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Wrapper type for relation type definitions in entities.
3
+ * Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.
4
+ *
5
+ * Usage example:
6
+ * @Entity()
7
+ * export default class User {
8
+ *
9
+ * @OneToOne(() => Profile, profile => profile.user)
10
+ * profile: Relation<Profile>;
11
+ *
12
+ * }
13
+ */
14
+ export declare type Relation<T> = T;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=RelationType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/RelationType.ts"],"names":[],"mappings":"","file":"RelationType.js","sourcesContent":["/**\n * Wrapper type for relation type definitions in entities.\n * Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.\n *\n * Usage example:\n * @Entity()\n * export default class User {\n *\n * @OneToOne(() => Profile, profile => profile.user)\n * profile: Relation<Profile>;\n *\n * }\n */\nexport type Relation<T> = T;\n"],"sourceRoot":".."}
@@ -45,6 +45,11 @@ export interface BaseConnectionOptions {
45
45
  * Transaction mode for migrations to run in
46
46
  */
47
47
  readonly migrationsTransactionMode?: "all" | "none" | "each";
48
+ /**
49
+ * Typeorm metadata table name, in case of different name from "typeorm_metadata".
50
+ * Accepts single string name.
51
+ */
52
+ readonly metadataTableName?: string;
48
53
  /**
49
54
  * Naming strategy to be used to name tables and columns in the database.
50
55
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {LoggerOptions} from \"../logger/LoggerOptions\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {DatabaseType} from \"../driver/types/DatabaseType\";\nimport {Logger} from \"../logger/Logger\";\nimport {Connection} from \"./Connection\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n */\nexport interface BaseConnectionOptions {\n\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType;\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n */\n readonly name?: string;\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: ((Function|string|EntitySchema<any>))[];\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: (Function|string)[];\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and directories where from migrations need to be loaded.\n * Directories support glob patterns.\n */\n readonly migrations?: (Function|string)[];\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string;\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\";\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface;\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions;\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?: \"advanced-console\"|\"simple-console\"|\"file\"|\"debug\"|Logger;\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number;\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean;\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean;\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean;\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string;\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean;\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any;\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?: boolean|{\n\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?: \"database\" | \"redis\" | \"ioredis\" | \"ioredis/cluster\"; // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: Connection) => QueryResultCache;\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string;\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any;\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean;\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number;\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean;\n };\n\n /**\n * CLI settings.\n */\n readonly cli?: {\n\n /**\n * Directory where entities should be created by default.\n */\n readonly entitiesDir?: string;\n\n /**\n * Directory where migrations should be created by default.\n */\n readonly migrationsDir?: string;\n\n /**\n * Directory where subscribers should be created by default.\n */\n readonly subscribersDir?: string;\n\n };\n\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {LoggerOptions} from \"../logger/LoggerOptions\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {DatabaseType} from \"../driver/types/DatabaseType\";\nimport {Logger} from \"../logger/Logger\";\nimport {Connection} from \"./Connection\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n */\nexport interface BaseConnectionOptions {\n\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType;\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n */\n readonly name?: string;\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: ((Function|string|EntitySchema<any>))[];\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: (Function|string)[];\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and directories where from migrations need to be loaded.\n * Directories support glob patterns.\n */\n readonly migrations?: (Function|string)[];\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string;\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\";\n\n /**\n * Typeorm metadata table name, in case of different name from \"typeorm_metadata\".\n * Accepts single string name.\n */\n readonly metadataTableName?: string;\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface;\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions;\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?: \"advanced-console\"|\"simple-console\"|\"file\"|\"debug\"|Logger;\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number;\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean;\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean;\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean;\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string;\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean;\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any;\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?: boolean|{\n\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?: \"database\" | \"redis\" | \"ioredis\" | \"ioredis/cluster\"; // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: Connection) => QueryResultCache;\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string;\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any;\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean;\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number;\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean;\n };\n\n /**\n * CLI settings.\n */\n readonly cli?: {\n\n /**\n * Directory where entities should be created by default.\n */\n readonly entitiesDir?: string;\n\n /**\n * Directory where migrations should be created by default.\n */\n readonly migrationsDir?: string;\n\n /**\n * Directory where subscribers should be created by default.\n */\n readonly subscribersDir?: string;\n\n };\n\n}\n"],"sourceRoot":".."}
@@ -50,6 +50,10 @@ export declare class Connection {
50
50
  * Naming strategy used in the connection.
51
51
  */
52
52
  readonly namingStrategy: NamingStrategyInterface;
53
+ /**
54
+ * Name for the metadata table
55
+ */
56
+ readonly metadataTableName: string;
53
57
  /**
54
58
  * Logger used to log orm events.
55
59
  */
@@ -169,11 +173,11 @@ export declare class Connection {
169
173
  */
170
174
  query(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<any>;
171
175
  /**
172
- * Creates a new query builder that can be used to build a sql query.
176
+ * Creates a new query builder that can be used to build a SQL query.
173
177
  */
174
178
  createQueryBuilder<Entity>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
175
179
  /**
176
- * Creates a new query builder that can be used to build a sql query.
180
+ * Creates a new query builder that can be used to build a SQL query.
177
181
  */
178
182
  createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;
179
183
  /**
@@ -202,5 +206,5 @@ export declare class Connection {
202
206
  /**
203
207
  * Builds metadatas for all registered classes inside this connection.
204
208
  */
205
- protected buildMetadatas(): void;
209
+ protected buildMetadatas(): Promise<void>;
206
210
  }