typeorm 0.3.12-dev.ef64bfc → 0.3.13-dev.099fcd9

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 (264) hide show
  1. package/browser/cli-ts-node-commonjs.js +0 -0
  2. package/browser/cli-ts-node-esm.js +0 -0
  3. package/browser/common/DeepPartial.d.ts +1 -1
  4. package/browser/common/EntityTarget.d.ts +1 -1
  5. package/browser/common/MixedList.d.ts +1 -1
  6. package/browser/common/NonNever.d.ts +1 -1
  7. package/browser/common/ObjectType.d.ts +1 -1
  8. package/browser/common/PickKeysByType.d.ts +6 -0
  9. package/browser/common/PickKeysByType.js +3 -0
  10. package/browser/common/PickKeysByType.js.map +1 -0
  11. package/browser/common/RelationType.d.ts +1 -1
  12. package/browser/connection/BaseConnectionOptions.d.ts +1 -1
  13. package/browser/connection/ConnectionOptions.d.ts +1 -1
  14. package/browser/container.d.ts +1 -1
  15. package/browser/data-source/DataSourceOptions.d.ts +1 -1
  16. package/browser/decorator/columns/PrimaryColumn.d.ts +1 -1
  17. package/browser/driver/Driver.d.ts +1 -1
  18. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +6 -0
  19. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  20. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +3 -1
  21. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  22. package/browser/driver/mongodb/MongoDriver.d.ts +1 -1
  23. package/browser/driver/mongodb/MongoDriver.js.map +1 -1
  24. package/browser/driver/mongodb/typings.d.ts +6 -6
  25. package/browser/driver/oracle/OracleDriver.d.ts +1 -1
  26. package/browser/driver/oracle/OracleDriver.js.map +1 -1
  27. package/browser/driver/postgres/PostgresQueryRunner.js +1 -1
  28. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  29. package/browser/driver/react-native/ReactNativeDriver.d.ts +219 -6
  30. package/browser/driver/react-native/ReactNativeDriver.js +662 -10
  31. package/browser/driver/react-native/ReactNativeDriver.js.map +1 -1
  32. package/browser/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
  33. package/browser/driver/sap/SapDriver.d.ts +1 -1
  34. package/browser/driver/sap/SapDriver.js.map +1 -1
  35. package/browser/driver/spanner/SpannerDriver.d.ts +1 -1
  36. package/browser/driver/spanner/SpannerDriver.js.map +1 -1
  37. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +1 -1
  38. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +12 -0
  39. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  40. package/browser/driver/sqlserver/SqlServerConnectionCredentialsOptions.d.ts +1 -1
  41. package/browser/driver/sqlserver/SqlServerDriver.d.ts +1 -1
  42. package/browser/driver/sqlserver/SqlServerDriver.js.map +1 -1
  43. package/browser/driver/types/ColumnTypes.d.ts +7 -7
  44. package/browser/driver/types/DatabaseType.d.ts +1 -1
  45. package/browser/driver/types/GeoJsonTypes.d.ts +12 -12
  46. package/browser/driver/types/IsolationLevel.d.ts +1 -1
  47. package/browser/driver/types/ReplicationMode.d.ts +1 -1
  48. package/browser/driver/types/UpsertType.d.ts +1 -1
  49. package/browser/entity-manager/EntityManager.d.ts +18 -0
  50. package/browser/entity-manager/EntityManager.js +32 -0
  51. package/browser/entity-manager/EntityManager.js.map +1 -1
  52. package/browser/entity-manager/MongoEntityManager.js +4 -4
  53. package/browser/entity-manager/MongoEntityManager.js.map +1 -1
  54. package/browser/find-options/FindOperator.d.ts +1 -1
  55. package/browser/find-options/FindOperatorType.d.ts +1 -1
  56. package/browser/find-options/FindOperatorType.js.map +1 -1
  57. package/browser/find-options/FindOptionsOrder.d.ts +3 -3
  58. package/browser/find-options/FindOptionsRelations.d.ts +3 -3
  59. package/browser/find-options/FindOptionsSelect.d.ts +3 -3
  60. package/browser/find-options/FindOptionsWhere.d.ts +6 -2
  61. package/browser/find-options/FindOptionsWhere.js.map +1 -1
  62. package/browser/find-options/OrderByCondition.d.ts +1 -1
  63. package/browser/find-options/mongodb/MongoFindOneOptions.d.ts +1 -1
  64. package/browser/find-options/operator/JsonContains.d.ts +6 -0
  65. package/browser/find-options/operator/JsonContains.js +10 -0
  66. package/browser/find-options/operator/JsonContains.js.map +1 -0
  67. package/browser/index.d.ts +3 -0
  68. package/browser/index.js +3 -0
  69. package/browser/index.js.map +1 -1
  70. package/browser/logger/AbstractLogger.d.ts +49 -0
  71. package/browser/logger/AbstractLogger.js +230 -0
  72. package/browser/logger/AbstractLogger.js.map +1 -0
  73. package/browser/logger/AdvancedConsoleLogger.d.ts +5 -33
  74. package/browser/logger/AdvancedConsoleLogger.js +41 -106
  75. package/browser/logger/AdvancedConsoleLogger.js.map +1 -1
  76. package/browser/logger/DebugLogger.d.ts +9 -29
  77. package/browser/logger/DebugLogger.js +56 -74
  78. package/browser/logger/DebugLogger.js.map +1 -1
  79. package/browser/logger/FileLogger.d.ts +6 -32
  80. package/browser/logger/FileLogger.js +50 -97
  81. package/browser/logger/FileLogger.js.map +1 -1
  82. package/browser/logger/Logger.d.ts +31 -0
  83. package/browser/logger/Logger.js.map +1 -1
  84. package/browser/logger/LoggerOptions.d.ts +3 -2
  85. package/browser/logger/LoggerOptions.js.map +1 -1
  86. package/browser/logger/SimpleConsoleLogger.d.ts +5 -33
  87. package/browser/logger/SimpleConsoleLogger.js +43 -106
  88. package/browser/logger/SimpleConsoleLogger.js.map +1 -1
  89. package/browser/metadata/types/DeferrableType.d.ts +1 -1
  90. package/browser/metadata/types/EventListenerTypes.d.ts +1 -1
  91. package/browser/metadata/types/OnDeleteType.d.ts +1 -1
  92. package/browser/metadata/types/OnUpdateType.d.ts +1 -1
  93. package/browser/metadata/types/PropertyTypeInFunction.d.ts +1 -1
  94. package/browser/metadata/types/RelationTypeInFunction.d.ts +1 -1
  95. package/browser/metadata/types/RelationTypes.d.ts +1 -1
  96. package/browser/metadata/types/TableTypes.d.ts +1 -1
  97. package/browser/metadata/types/TreeTypes.d.ts +1 -1
  98. package/browser/metadata-args/types/ColumnMode.d.ts +1 -1
  99. package/browser/metadata-builder/RelationJoinColumnBuilder.js +2 -1
  100. package/browser/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
  101. package/browser/migration/MigrationExecutor.js +1 -1
  102. package/browser/migration/MigrationExecutor.js.map +1 -1
  103. package/browser/naming-strategy/LegacyOracleNamingStrategy.d.ts +21 -0
  104. package/browser/naming-strategy/LegacyOracleNamingStrategy.js +46 -0
  105. package/browser/naming-strategy/LegacyOracleNamingStrategy.js.map +1 -0
  106. package/browser/persistence/SubjectTopoligicalSorter.js +2 -6
  107. package/browser/persistence/SubjectTopoligicalSorter.js.map +1 -1
  108. package/browser/platform/BrowserPlatformTools.js +2 -2
  109. package/browser/platform/BrowserPlatformTools.js.map +1 -1
  110. package/browser/platform/PlatformTools.d.ts +2 -0
  111. package/browser/platform/PlatformTools.js +6 -0
  112. package/browser/platform/PlatformTools.js.map +1 -1
  113. package/browser/query-builder/InsertOrUpdateOptions.d.ts +1 -1
  114. package/browser/query-builder/QueryBuilder.js +2 -0
  115. package/browser/query-builder/QueryBuilder.js.map +1 -1
  116. package/browser/query-builder/QueryPartialEntity.d.ts +3 -3
  117. package/browser/query-builder/SelectQueryBuilder.d.ts +1 -1
  118. package/browser/query-builder/SelectQueryBuilder.js +8 -4
  119. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  120. package/browser/query-builder/SelectQueryBuilderOption.d.ts +1 -1
  121. package/browser/query-builder/WhereClause.d.ts +3 -3
  122. package/browser/query-builder/WhereClause.js.map +1 -1
  123. package/browser/repository/BaseEntity.d.ts +25 -0
  124. package/browser/repository/BaseEntity.js +24 -0
  125. package/browser/repository/BaseEntity.js.map +1 -1
  126. package/browser/repository/EntityId.d.ts +1 -1
  127. package/browser/repository/Repository.d.ts +17 -0
  128. package/browser/repository/Repository.js +32 -8
  129. package/browser/repository/Repository.js.map +1 -1
  130. package/browser/util/VersionUtils.d.ts +1 -1
  131. package/cli-ts-node-commonjs.js +0 -0
  132. package/cli-ts-node-esm.js +0 -0
  133. package/cli.js +0 -0
  134. package/commands/CommandUtils.d.ts +1 -1
  135. package/commands/MigrationCreateCommand.d.ts +1 -1
  136. package/commands/MigrationGenerateCommand.d.ts +1 -1
  137. package/common/DeepPartial.d.ts +1 -1
  138. package/common/EntityTarget.d.ts +1 -1
  139. package/common/MixedList.d.ts +1 -1
  140. package/common/NonNever.d.ts +1 -1
  141. package/common/ObjectType.d.ts +1 -1
  142. package/common/PickKeysByType.d.ts +6 -0
  143. package/common/PickKeysByType.js +4 -0
  144. package/common/PickKeysByType.js.map +1 -0
  145. package/common/RelationType.d.ts +1 -1
  146. package/connection/BaseConnectionOptions.d.ts +1 -1
  147. package/connection/ConnectionOptions.d.ts +1 -1
  148. package/container.d.ts +1 -1
  149. package/data-source/DataSourceOptions.d.ts +1 -1
  150. package/decorator/columns/PrimaryColumn.d.ts +1 -1
  151. package/driver/Driver.d.ts +1 -1
  152. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +6 -0
  153. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  154. package/driver/better-sqlite3/BetterSqlite3Driver.js +3 -1
  155. package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  156. package/driver/mongodb/MongoDriver.d.ts +1 -1
  157. package/driver/mongodb/MongoDriver.js.map +1 -1
  158. package/driver/mongodb/typings.d.ts +6 -6
  159. package/driver/oracle/OracleDriver.d.ts +1 -1
  160. package/driver/oracle/OracleDriver.js.map +1 -1
  161. package/driver/postgres/PostgresQueryRunner.js +1 -1
  162. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  163. package/driver/react-native/ReactNativeDriver.d.ts +219 -6
  164. package/driver/react-native/ReactNativeDriver.js +663 -11
  165. package/driver/react-native/ReactNativeDriver.js.map +1 -1
  166. package/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
  167. package/driver/sap/SapDriver.d.ts +1 -1
  168. package/driver/sap/SapDriver.js.map +1 -1
  169. package/driver/spanner/SpannerDriver.d.ts +1 -1
  170. package/driver/spanner/SpannerDriver.js.map +1 -1
  171. package/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +1 -1
  172. package/driver/sqlite-abstract/AbstractSqliteDriver.js +12 -0
  173. package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  174. package/driver/sqlserver/SqlServerConnectionCredentialsOptions.d.ts +1 -1
  175. package/driver/sqlserver/SqlServerDriver.d.ts +1 -1
  176. package/driver/sqlserver/SqlServerDriver.js.map +1 -1
  177. package/driver/types/ColumnTypes.d.ts +7 -7
  178. package/driver/types/DatabaseType.d.ts +1 -1
  179. package/driver/types/GeoJsonTypes.d.ts +12 -12
  180. package/driver/types/IsolationLevel.d.ts +1 -1
  181. package/driver/types/ReplicationMode.d.ts +1 -1
  182. package/driver/types/UpsertType.d.ts +1 -1
  183. package/entity-manager/EntityManager.d.ts +18 -0
  184. package/entity-manager/EntityManager.js +32 -0
  185. package/entity-manager/EntityManager.js.map +1 -1
  186. package/entity-manager/MongoEntityManager.js +4 -4
  187. package/entity-manager/MongoEntityManager.js.map +1 -1
  188. package/find-options/FindOperator.d.ts +1 -1
  189. package/find-options/FindOperatorType.d.ts +1 -1
  190. package/find-options/FindOperatorType.js.map +1 -1
  191. package/find-options/FindOptionsOrder.d.ts +3 -3
  192. package/find-options/FindOptionsRelations.d.ts +3 -3
  193. package/find-options/FindOptionsSelect.d.ts +3 -3
  194. package/find-options/FindOptionsWhere.d.ts +6 -2
  195. package/find-options/FindOptionsWhere.js.map +1 -1
  196. package/find-options/OrderByCondition.d.ts +1 -1
  197. package/find-options/mongodb/MongoFindOneOptions.d.ts +1 -1
  198. package/find-options/operator/JsonContains.d.ts +6 -0
  199. package/find-options/operator/JsonContains.js +14 -0
  200. package/find-options/operator/JsonContains.js.map +1 -0
  201. package/index.d.ts +3 -0
  202. package/index.js +5 -1
  203. package/index.js.map +1 -1
  204. package/index.mjs +6 -0
  205. package/logger/AbstractLogger.d.ts +49 -0
  206. package/logger/AbstractLogger.js +234 -0
  207. package/logger/AbstractLogger.js.map +1 -0
  208. package/logger/AdvancedConsoleLogger.d.ts +5 -33
  209. package/logger/AdvancedConsoleLogger.js +41 -106
  210. package/logger/AdvancedConsoleLogger.js.map +1 -1
  211. package/logger/DebugLogger.d.ts +9 -29
  212. package/logger/DebugLogger.js +56 -75
  213. package/logger/DebugLogger.js.map +1 -1
  214. package/logger/FileLogger.d.ts +6 -32
  215. package/logger/FileLogger.js +50 -97
  216. package/logger/FileLogger.js.map +1 -1
  217. package/logger/Logger.d.ts +31 -0
  218. package/logger/Logger.js.map +1 -1
  219. package/logger/LoggerOptions.d.ts +3 -2
  220. package/logger/LoggerOptions.js.map +1 -1
  221. package/logger/SimpleConsoleLogger.d.ts +5 -33
  222. package/logger/SimpleConsoleLogger.js +43 -106
  223. package/logger/SimpleConsoleLogger.js.map +1 -1
  224. package/metadata/types/DeferrableType.d.ts +1 -1
  225. package/metadata/types/EventListenerTypes.d.ts +1 -1
  226. package/metadata/types/OnDeleteType.d.ts +1 -1
  227. package/metadata/types/OnUpdateType.d.ts +1 -1
  228. package/metadata/types/PropertyTypeInFunction.d.ts +1 -1
  229. package/metadata/types/RelationTypeInFunction.d.ts +1 -1
  230. package/metadata/types/RelationTypes.d.ts +1 -1
  231. package/metadata/types/TableTypes.d.ts +1 -1
  232. package/metadata/types/TreeTypes.d.ts +1 -1
  233. package/metadata-args/types/ColumnMode.d.ts +1 -1
  234. package/metadata-builder/RelationJoinColumnBuilder.js +2 -1
  235. package/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
  236. package/migration/MigrationExecutor.js +1 -1
  237. package/migration/MigrationExecutor.js.map +1 -1
  238. package/naming-strategy/LegacyOracleNamingStrategy.d.ts +21 -0
  239. package/naming-strategy/LegacyOracleNamingStrategy.js +50 -0
  240. package/naming-strategy/LegacyOracleNamingStrategy.js.map +1 -0
  241. package/package.json +1 -1
  242. package/persistence/SubjectTopoligicalSorter.js +2 -6
  243. package/persistence/SubjectTopoligicalSorter.js.map +1 -1
  244. package/platform/PlatformTools.d.ts +2 -0
  245. package/platform/PlatformTools.js +6 -0
  246. package/platform/PlatformTools.js.map +1 -1
  247. package/query-builder/InsertOrUpdateOptions.d.ts +1 -1
  248. package/query-builder/QueryBuilder.js +2 -0
  249. package/query-builder/QueryBuilder.js.map +1 -1
  250. package/query-builder/QueryPartialEntity.d.ts +3 -3
  251. package/query-builder/SelectQueryBuilder.d.ts +1 -1
  252. package/query-builder/SelectQueryBuilder.js +8 -4
  253. package/query-builder/SelectQueryBuilder.js.map +1 -1
  254. package/query-builder/SelectQueryBuilderOption.d.ts +1 -1
  255. package/query-builder/WhereClause.d.ts +3 -3
  256. package/query-builder/WhereClause.js.map +1 -1
  257. package/repository/BaseEntity.d.ts +25 -0
  258. package/repository/BaseEntity.js +24 -0
  259. package/repository/BaseEntity.js.map +1 -1
  260. package/repository/EntityId.d.ts +1 -1
  261. package/repository/Repository.d.ts +17 -0
  262. package/repository/Repository.js +32 -8
  263. package/repository/Repository.js.map +1 -1
  264. package/util/VersionUtils.d.ts +1 -1
@@ -1 +1 @@
1
- export declare type SelectQueryBuilderOption = "disable-global-order" | "create-pojo";
1
+ export type SelectQueryBuilderOption = "disable-global-order" | "create-pojo";
@@ -1,5 +1,5 @@
1
- declare type WrappingOperator = "not" | "brackets";
2
- declare type PredicateOperator = "lessThan" | "lessThanOrEqual" | "moreThan" | "moreThanOrEqual" | "equal" | "notEqual" | "ilike" | "like" | "between" | "in" | "any" | "isNull" | "arrayContains" | "arrayContainedBy" | "arrayOverlap" | "and";
1
+ type WrappingOperator = "not" | "brackets";
2
+ type PredicateOperator = "lessThan" | "lessThanOrEqual" | "moreThan" | "moreThanOrEqual" | "equal" | "notEqual" | "ilike" | "like" | "between" | "in" | "any" | "isNull" | "arrayContains" | "arrayContainedBy" | "arrayOverlap" | "and" | "jsonContains";
3
3
  export interface WherePredicateOperator {
4
4
  operator: PredicateOperator;
5
5
  parameters: string[];
@@ -12,5 +12,5 @@ export interface WhereClause {
12
12
  type: "simple" | "and" | "or";
13
13
  condition: WhereClauseCondition;
14
14
  }
15
- export declare type WhereClauseCondition = string | WherePredicateOperator | WhereWrappingOperator | WhereClause[];
15
+ export type WhereClauseCondition = string | WherePredicateOperator | WhereWrappingOperator | WhereClause[];
16
16
  export {};
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/query-builder/WhereClause.ts"],"names":[],"mappings":"","file":"WhereClause.js","sourcesContent":["type WrappingOperator = \"not\" | \"brackets\"\n\ntype PredicateOperator =\n | \"lessThan\"\n | \"lessThanOrEqual\"\n | \"moreThan\"\n | \"moreThanOrEqual\"\n | \"equal\"\n | \"notEqual\"\n | \"ilike\"\n | \"like\"\n | \"between\"\n | \"in\"\n | \"any\"\n | \"isNull\"\n | \"arrayContains\"\n | \"arrayContainedBy\"\n | \"arrayOverlap\"\n | \"and\"\n\nexport interface WherePredicateOperator {\n operator: PredicateOperator\n\n parameters: string[]\n}\n\nexport interface WhereWrappingOperator {\n operator: WrappingOperator\n\n condition: WhereClauseCondition\n}\n\nexport interface WhereClause {\n type: \"simple\" | \"and\" | \"or\"\n\n condition: WhereClauseCondition\n}\n\nexport type WhereClauseCondition =\n | string\n | WherePredicateOperator\n | WhereWrappingOperator\n | WhereClause[]\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/query-builder/WhereClause.ts"],"names":[],"mappings":"","file":"WhereClause.js","sourcesContent":["type WrappingOperator = \"not\" | \"brackets\"\n\ntype PredicateOperator =\n | \"lessThan\"\n | \"lessThanOrEqual\"\n | \"moreThan\"\n | \"moreThanOrEqual\"\n | \"equal\"\n | \"notEqual\"\n | \"ilike\"\n | \"like\"\n | \"between\"\n | \"in\"\n | \"any\"\n | \"isNull\"\n | \"arrayContains\"\n | \"arrayContainedBy\"\n | \"arrayOverlap\"\n | \"and\"\n | \"jsonContains\"\n\nexport interface WherePredicateOperator {\n operator: PredicateOperator\n\n parameters: string[]\n}\n\nexport interface WhereWrappingOperator {\n operator: WrappingOperator\n\n condition: WhereClauseCondition\n}\n\nexport interface WhereClause {\n type: \"simple\" | \"and\" | \"or\"\n\n condition: WhereClauseCondition\n}\n\nexport type WhereClauseCondition =\n | string\n | WherePredicateOperator\n | WhereWrappingOperator\n | WhereClause[]\n"],"sourceRoot":".."}
@@ -14,6 +14,7 @@ import { ObjectID } from "../driver/mongodb/typings";
14
14
  import { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity";
15
15
  import { UpsertOptions } from "./UpsertOptions";
16
16
  import { EntityTarget } from "../common/EntityTarget";
17
+ import { PickKeysByType } from "../common/PickKeysByType";
17
18
  /**
18
19
  * Base abstract entity for all entities, used in ActiveRecord patterns.
19
20
  */
@@ -204,6 +205,30 @@ export declare class BaseEntity {
204
205
  static countBy<T extends BaseEntity>(this: {
205
206
  new (): T;
206
207
  } & typeof BaseEntity, where: FindOptionsWhere<T>): Promise<number>;
208
+ /**
209
+ * Return the SUM of a column
210
+ */
211
+ static sum<T extends BaseEntity>(this: {
212
+ new (): T;
213
+ } & typeof BaseEntity, columnName: PickKeysByType<T, number>, where: FindOptionsWhere<T>): Promise<number | null>;
214
+ /**
215
+ * Return the AVG of a column
216
+ */
217
+ static average<T extends BaseEntity>(this: {
218
+ new (): T;
219
+ } & typeof BaseEntity, columnName: PickKeysByType<T, number>, where: FindOptionsWhere<T>): Promise<number | null>;
220
+ /**
221
+ * Return the MIN of a column
222
+ */
223
+ static minimum<T extends BaseEntity>(this: {
224
+ new (): T;
225
+ } & typeof BaseEntity, columnName: PickKeysByType<T, number>, where: FindOptionsWhere<T>): Promise<number | null>;
226
+ /**
227
+ * Return the MAX of a column
228
+ */
229
+ static maximum<T extends BaseEntity>(this: {
230
+ new (): T;
231
+ } & typeof BaseEntity, columnName: PickKeysByType<T, number>, where: FindOptionsWhere<T>): Promise<number | null>;
207
232
  /**
208
233
  * Finds entities that match given options.
209
234
  */
@@ -193,6 +193,30 @@ export class BaseEntity {
193
193
  static countBy(where) {
194
194
  return this.getRepository().countBy(where);
195
195
  }
196
+ /**
197
+ * Return the SUM of a column
198
+ */
199
+ static sum(columnName, where) {
200
+ return this.getRepository().sum(columnName, where);
201
+ }
202
+ /**
203
+ * Return the AVG of a column
204
+ */
205
+ static average(columnName, where) {
206
+ return this.getRepository().average(columnName, where);
207
+ }
208
+ /**
209
+ * Return the MIN of a column
210
+ */
211
+ static minimum(columnName, where) {
212
+ return this.getRepository().minimum(columnName, where);
213
+ }
214
+ /**
215
+ * Return the MAX of a column
216
+ */
217
+ static maximum(columnName, where) {
218
+ return this.getRepository().maximum(columnName, where);
219
+ }
196
220
  /**
197
221
  * Finds entities that match given options.
198
222
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAqB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAuB;QAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAkB,CAAA;IAC5E,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,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a,EAAK,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const id = baseEntity.getRepository().metadata.getEntityIdMap(this)\n if (!id) {\n throw new Error(\n `Entity doesn't have id-s set, cannot reload entity`,\n )\n }\n const reloadedEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneByOrFail(id)\n\n ObjectUtils.assign(this, reloadedEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository<T>()\n return thisRepository.preload(entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAMjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,4EAA4E;IAC5E,iB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AK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { DataSource } from \"../data-source\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().hasId(this)\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const id = baseEntity.getRepository().metadata.getEntityIdMap(this)\n if (!id) {\n throw new Error(\n `Entity doesn't have id-s set, cannot reload entity`,\n )\n }\n const reloadedEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneByOrFail(id)\n\n ObjectUtils.assign(this, reloadedEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.getRepository<T>(this)\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): EntityTarget<any> {\n return this.getRepository().target\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().getId(entity)\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n static createQueryBuilder<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): T\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): T[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): T\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository<T>()\n return thisRepository.preload(entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, partialEntity)\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Return the SUM of a column\n */\n static sum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().sum(columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n static average<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().average(columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n static minimum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().minimum(columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n static maximum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().maximum(columnName, where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectID,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
@@ -1,2 +1,2 @@
1
1
  import { ObjectID } from "../driver/mongodb/typings";
2
- export declare type EntityId = string | number | Date | ObjectID;
2
+ export type EntityId = string | number | Date | ObjectID;
@@ -15,6 +15,7 @@ import { ObjectID } from "../driver/mongodb/typings";
15
15
  import { FindOptionsWhere } from "../find-options/FindOptionsWhere";
16
16
  import { UpsertOptions } from "./UpsertOptions";
17
17
  import { EntityTarget } from "../common/EntityTarget";
18
+ import { PickKeysByType } from "../common/PickKeysByType";
18
19
  /**
19
20
  * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.
20
21
  */
@@ -206,6 +207,22 @@ export declare class Repository<Entity extends ObjectLiteral> {
206
207
  * Useful for pagination.
207
208
  */
208
209
  countBy(where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<number>;
210
+ /**
211
+ * Return the SUM of a column
212
+ */
213
+ sum(columnName: PickKeysByType<Entity, number>, where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<number | null>;
214
+ /**
215
+ * Return the AVG of a column
216
+ */
217
+ average(columnName: PickKeysByType<Entity, number>, where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<number | null>;
218
+ /**
219
+ * Return the MIN of a column
220
+ */
221
+ minimum(columnName: PickKeysByType<Entity, number>, where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<number | null>;
222
+ /**
223
+ * Return the MAX of a column
224
+ */
225
+ maximum(columnName: PickKeysByType<Entity, number>, where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<number | null>;
209
226
  /**
210
227
  * Finds entities that match given find options.
211
228
  */
@@ -2,14 +2,6 @@
2
2
  * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.
3
3
  */
4
4
  export class Repository {
5
- // -------------------------------------------------------------------------
6
- // Constructor
7
- // -------------------------------------------------------------------------
8
- constructor(target, manager, queryRunner) {
9
- this.target = target;
10
- this.manager = manager;
11
- this.queryRunner = queryRunner;
12
- }
13
5
  // -------------------------------------------------------------------------
14
6
  // Accessors
15
7
  // -------------------------------------------------------------------------
@@ -20,6 +12,14 @@ export class Repository {
20
12
  return this.manager.connection.getMetadata(this.target);
21
13
  }
22
14
  // -------------------------------------------------------------------------
15
+ // Constructor
16
+ // -------------------------------------------------------------------------
17
+ constructor(target, manager, queryRunner) {
18
+ this.target = target;
19
+ this.manager = manager;
20
+ this.queryRunner = queryRunner;
21
+ }
22
+ // -------------------------------------------------------------------------
23
23
  // Public Methods
24
24
  // -------------------------------------------------------------------------
25
25
  /**
@@ -163,6 +163,30 @@ export class Repository {
163
163
  countBy(where) {
164
164
  return this.manager.countBy(this.metadata.target, where);
165
165
  }
166
+ /**
167
+ * Return the SUM of a column
168
+ */
169
+ sum(columnName, where) {
170
+ return this.manager.sum(this.metadata.target, columnName, where);
171
+ }
172
+ /**
173
+ * Return the AVG of a column
174
+ */
175
+ average(columnName, where) {
176
+ return this.manager.average(this.metadata.target, columnName, where);
177
+ }
178
+ /**
179
+ * Return the MIN of a column
180
+ */
181
+ minimum(columnName, where) {
182
+ return this.manager.minimum(this.metadata.target, columnName, where);
183
+ }
184
+ /**
185
+ * Return the MAX of a column
186
+ */
187
+ maximum(columnName, where) {
188
+ return this.manager.maximum(this.metadata.target, columnName, where);
189
+ }
166
190
  /**
167
191
  * Finds entities that match given find options.
168
192
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,MAAM,OAAO,UAAU;IAiCnB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;QAEzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAClC,CAAC;IAvBD,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E;;OAEG;IACH,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;IAgBD,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,kBAAkB,CACd,KAAc,EACd,WAAyB;QAEzB,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAClC,IAAI,CAAC,QAAQ,CAAC,MAAa,EAC3B,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EACjC,WAAW,IAAI,IAAI,CAAC,WAAW,CAClC,CAAA;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAc;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAc;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAmBD;;;OAGG;IACH,MA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Y,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CACF,MAA4D;QAE5D,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,KAAK;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAkD,CAAA;QACxE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAM,SAAQ,QAAQ;SAAG,CAAC,CACvC,MAAM,EACN,OAAO,EACP,WAAW,CACd,CAAA;QACD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC1B,OAAO,GAAU,CAAA;IACrB,CAAC;CACJ","file":"Repository.js","sourcesContent":["import { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\n\n/**\n * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.\n */\nexport class Repository<Entity extends ObjectLiteral> {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity target that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n readonly target: EntityTarget<Entity>\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n get metadata() {\n return this.manager.connection.getMetadata(this.target)\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n this.target = target\n this.manager = manager\n this.queryRunner = queryRunner\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(\n this.metadata.target as any,\n alias || this.metadata.targetName,\n queryRunner || this.queryRunner,\n )\n }\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(entity: Entity): boolean {\n return this.manager.hasId(this.metadata.target, entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n getId(entity: Entity): any {\n return this.manager.getId(this.metadata.target, entity)\n }\n\n /**\n * Creates a new entity instance.\n */\n create(): Entity\n\n /**\n * Creates new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLikeArray: DeepPartial<Entity>[]): Entity[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLike: DeepPartial<Entity>): Entity\n\n /**\n * Creates a new entity instance or instances.\n * Can copy properties from the given object into new entities.\n */\n create(\n plainEntityLikeOrPlainEntityLikes?:\n | DeepPartial<Entity>\n | DeepPartial<Entity>[],\n ): Entity | Entity[] {\n return this.manager.create<any>(\n this.metadata.target as any,\n plainEntityLikeOrPlainEntityLikes as any,\n )\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(\n mergeIntoEntity: Entity,\n ...entityLikes: DeepPartial<Entity>[]\n ): Entity {\n return this.manager.merge(\n this.metadata.target as any,\n mergeIntoEntity,\n ...entityLikes,\n )\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n preload(entityLike: DeepPartial<Entity>): Promise<Entity | undefined> {\n return this.manager.preload(this.metadata.target as any, entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.save<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Removes a given entities from the database.\n */\n remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>\n\n /**\n * Removes a given entity from the database.\n */\n remove(entity: Entity, options?: RemoveOptions): Promise<Entity>\n\n /**\n * Removes one or many given entities.\n */\n remove(\n entityOrEntities: Entity | Entity[],\n options?: RemoveOptions,\n ): Promise<Entity | Entity[]> {\n return this.manager.remove(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.softRemove<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.recover<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n insert(\n entity:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n ): Promise<InsertResult> {\n return this.manager.insert(this.metadata.target as any, entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n update(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n partialEntity: QueryDeepPartialEntity<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.update(\n this.metadata.target as any,\n criteria as any,\n partialEntity,\n )\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n upsert(\n entityOrEntities:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n conflictPathsOrOptions: string[] | UpsertOptions<Entity>,\n ): Promise<InsertResult> {\n return this.manager.upsert(\n this.metadata.target as any,\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n delete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n ): Promise<DeleteResult> {\n return this.manager.delete(this.metadata.target as any, criteria as any)\n }\n\n /**\n * Records the delete date of entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n softDelete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.softDelete(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Restores entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n restore(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.restore(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Checks whether any entity exists that match given options.\n */\n exist(options?: FindManyOptions<Entity>): Promise<boolean> {\n return this.manager.exists(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given options.\n * Useful for pagination.\n */\n count(options?: FindManyOptions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given conditions.\n * Useful for pagination.\n */\n countBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number> {\n return this.manager.countBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async find(options?: FindManyOptions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async findBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity[]> {\n return this.manager.findBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(\n options?: FindManyOptions<Entity>,\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCount(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCountBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCountBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities with ids.\n * Optionally find options or conditions can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n async findByIds(ids: any[]): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target, ids)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - returns null.\n */\n async findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {\n return this.manager.findOne(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - returns null.\n */\n async findOneBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity | null> {\n return this.manager.findOneBy(this.metadata.target, where)\n }\n\n /**\n * Finds first entity that matches given id.\n * If entity was not found in the database - returns null.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n async findOneById(\n id: number | string | Date | ObjectID,\n ): Promise<Entity | null> {\n return this.manager.findOneById(this.metadata.target, id)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - rejects with error.\n */\n async findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - rejects with error.\n */\n async findOneByOrFail(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity> {\n return this.manager.findOneByOrFail(this.metadata.target, where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n query(query: string, parameters?: any[]): Promise<any> {\n return this.manager.query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n *\n * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.\n * @see https://stackoverflow.com/a/5972738/925151\n */\n clear(): Promise<void> {\n return this.manager.clear(this.metadata.target)\n }\n\n /**\n * Increments some column by provided value of the entities matched given conditions.\n */\n increment(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.increment(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.decrement(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Extends repository with provided functions.\n */\n extend<CustomRepository>(\n custom: CustomRepository & ThisType<this & CustomRepository>,\n ): this & CustomRepository {\n // return {\n // ...this,\n // ...custom\n // };\n const thisRepo = this.constructor as new (...args: any[]) => typeof this\n const { target, manager, queryRunner } = this\n const cls = new (class extends thisRepo {})(\n target,\n manager,\n queryRunner,\n )\n Object.assign(cls, custom)\n return cls as any\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,OAAO,UAAU;IAsBnB,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E;;OAEG;IACH,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;QAEz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AC,MAAM,EACpB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,SAAS,CACL,UAAoC,EACpC,YAAoB,EACpB,KAAsB;QAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,EACpB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CACF,MAA4D;QAE5D,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,KAAK;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAkD,CAAA;QACxE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAM,SAAQ,QAAQ;SAAG,CAAC,CACvC,MAAM,EACN,OAAO,EACP,WAAW,CACd,CAAA;QACD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC1B,OAAO,GAAU,CAAA;IACrB,CAAC;CACJ","file":"Repository.js","sourcesContent":["import { FindManyOptions } from \"../find-options/FindManyOptions\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { FindOneOptions } from \"../find-options/FindOneOptions\"\nimport { DeepPartial } from \"../common/DeepPartial\"\nimport { SaveOptions } from \"./SaveOptions\"\nimport { RemoveOptions } from \"./RemoveOptions\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { DeleteResult } from \"../query-builder/result/DeleteResult\"\nimport { UpdateResult } from \"../query-builder/result/UpdateResult\"\nimport { InsertResult } from \"../query-builder/result/InsertResult\"\nimport { QueryDeepPartialEntity } from \"../query-builder/QueryPartialEntity\"\nimport { ObjectID } from \"../driver/mongodb/typings\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\n\n/**\n * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.\n */\nexport class Repository<Entity extends ObjectLiteral> {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity target that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n readonly target: EntityTarget<Entity>\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n get metadata() {\n return this.manager.connection.getMetadata(this.target)\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n this.target = target\n this.manager = manager\n this.queryRunner = queryRunner\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(\n this.metadata.target as any,\n alias || this.metadata.targetName,\n queryRunner || this.queryRunner,\n )\n }\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(entity: Entity): boolean {\n return this.manager.hasId(this.metadata.target, entity)\n }\n\n /**\n * Gets entity mixed id.\n */\n getId(entity: Entity): any {\n return this.manager.getId(this.metadata.target, entity)\n }\n\n /**\n * Creates a new entity instance.\n */\n create(): Entity\n\n /**\n * Creates new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLikeArray: DeepPartial<Entity>[]): Entity[]\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLike: DeepPartial<Entity>): Entity\n\n /**\n * Creates a new entity instance or instances.\n * Can copy properties from the given object into new entities.\n */\n create(\n plainEntityLikeOrPlainEntityLikes?:\n | DeepPartial<Entity>\n | DeepPartial<Entity>[],\n ): Entity | Entity[] {\n return this.manager.create<any>(\n this.metadata.target as any,\n plainEntityLikeOrPlainEntityLikes as any,\n )\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(\n mergeIntoEntity: Entity,\n ...entityLikes: DeepPartial<Entity>[]\n ): Entity {\n return this.manager.merge(\n this.metadata.target as any,\n mergeIntoEntity,\n ...entityLikes,\n )\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n preload(entityLike: DeepPartial<Entity>): Promise<Entity | undefined> {\n return this.manager.preload(this.metadata.target as any, entityLike)\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.save<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Removes a given entities from the database.\n */\n remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>\n\n /**\n * Removes a given entity from the database.\n */\n remove(entity: Entity, options?: RemoveOptions): Promise<Entity>\n\n /**\n * Removes one or many given entities.\n */\n remove(\n entityOrEntities: Entity | Entity[],\n options?: RemoveOptions,\n ): Promise<Entity | Entity[]> {\n return this.manager.remove(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.softRemove<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.recover<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n insert(\n entity:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n ): Promise<InsertResult> {\n return this.manager.insert(this.metadata.target as any, entity)\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n update(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n partialEntity: QueryDeepPartialEntity<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.update(\n this.metadata.target as any,\n criteria as any,\n partialEntity,\n )\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n upsert(\n entityOrEntities:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n conflictPathsOrOptions: string[] | UpsertOptions<Entity>,\n ): Promise<InsertResult> {\n return this.manager.upsert(\n this.metadata.target as any,\n entityOrEntities,\n conflictPathsOrOptions,\n )\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n delete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n ): Promise<DeleteResult> {\n return this.manager.delete(this.metadata.target as any, criteria as any)\n }\n\n /**\n * Records the delete date of entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n softDelete(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.softDelete(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Restores entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n restore(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectID\n | ObjectID[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.restore(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Checks whether any entity exists that match given options.\n */\n exist(options?: FindManyOptions<Entity>): Promise<boolean> {\n return this.manager.exists(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given options.\n * Useful for pagination.\n */\n count(options?: FindManyOptions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given conditions.\n * Useful for pagination.\n */\n countBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number> {\n return this.manager.countBy(this.metadata.target, where)\n }\n\n /**\n * Return the SUM of a column\n */\n sum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.sum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n average(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.average(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n minimum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.minimum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n maximum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.maximum(this.metadata.target, columnName, where)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async find(options?: FindManyOptions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async findBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity[]> {\n return this.manager.findBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(\n options?: FindManyOptions<Entity>,\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCount(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCountBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCountBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities with ids.\n * Optionally find options or conditions can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n async findByIds(ids: any[]): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target, ids)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - returns null.\n */\n async findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {\n return this.manager.findOne(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - returns null.\n */\n async findOneBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity | null> {\n return this.manager.findOneBy(this.metadata.target, where)\n }\n\n /**\n * Finds first entity that matches given id.\n * If entity was not found in the database - returns null.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n async findOneById(\n id: number | string | Date | ObjectID,\n ): Promise<Entity | null> {\n return this.manager.findOneById(this.metadata.target, id)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - rejects with error.\n */\n async findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - rejects with error.\n */\n async findOneByOrFail(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity> {\n return this.manager.findOneByOrFail(this.metadata.target, where)\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n query(query: string, parameters?: any[]): Promise<any> {\n return this.manager.query(query, parameters)\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n *\n * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.\n * @see https://stackoverflow.com/a/5972738/925151\n */\n clear(): Promise<void> {\n return this.manager.clear(this.metadata.target)\n }\n\n /**\n * Increments some column by provided value of the entities matched given conditions.\n */\n increment(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.increment(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.decrement(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Extends repository with provided functions.\n */\n extend<CustomRepository>(\n custom: CustomRepository & ThisType<this & CustomRepository>,\n ): this & CustomRepository {\n // return {\n // ...this,\n // ...custom\n // };\n const thisRepo = this.constructor as new (...args: any[]) => typeof this\n const { target, manager, queryRunner } = this\n const cls = new (class extends thisRepo {})(\n target,\n manager,\n queryRunner,\n )\n Object.assign(cls, custom)\n return cls as any\n }\n}\n"],"sourceRoot":".."}
@@ -1,4 +1,4 @@
1
- export declare type Version = [number, number, number];
1
+ export type Version = [number, number, number];
2
2
  export declare class VersionUtils {
3
3
  static isGreaterOrEqual(version: string, targetVersion: string): boolean;
4
4
  }
File without changes
File without changes
package/cli.js CHANGED
File without changes
@@ -7,7 +7,7 @@ export declare class CommandUtils {
7
7
  /**
8
8
  * Creates directories recursively.
9
9
  */
10
- static createDirectories(directory: string): Promise<string | undefined>;
10
+ static createDirectories(directory: string): Promise<string | void | undefined>;
11
11
  /**
12
12
  * Creates a file with the given content in the given path.
13
13
  */
@@ -8,7 +8,7 @@ export declare class MigrationCreateCommand implements yargs.CommandModule {
8
8
  builder(args: yargs.Argv): yargs.Argv<{
9
9
  o: boolean;
10
10
  } & {
11
- t: boolean;
11
+ t: number | boolean;
12
12
  }>;
13
13
  handler(args: yargs.Arguments): Promise<void>;
14
14
  /**
@@ -16,7 +16,7 @@ export declare class MigrationGenerateCommand implements yargs.CommandModule {
16
16
  } & {
17
17
  ch: boolean;
18
18
  } & {
19
- t: boolean;
19
+ t: number | boolean;
20
20
  }>;
21
21
  handler(args: yargs.Arguments): Promise<void>;
22
22
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.
3
3
  */
4
- export declare type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
4
+ export type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
5
5
  [K in keyof T]?: DeepPartial<T[K]>;
6
6
  } : T);
@@ -3,7 +3,7 @@ import { EntitySchema } from "..";
3
3
  /**
4
4
  * Entity target.
5
5
  */
6
- export declare type EntityTarget<Entity> = ObjectType<Entity> | EntitySchema<Entity> | string | {
6
+ export type EntityTarget<Entity> = ObjectType<Entity> | EntitySchema<Entity> | string | {
7
7
  type: Entity;
8
8
  name: string;
9
9
  };
@@ -3,6 +3,6 @@
3
3
  *
4
4
  * Example usage: entities as an array of imported using import * as syntax.
5
5
  */
6
- export declare type MixedList<T> = T[] | {
6
+ export type MixedList<T> = T[] | {
7
7
  [key: string]: T;
8
8
  };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Remove keys with `never` value from object type
3
3
  * */
4
- export declare type NonNever<T extends {}> = Pick<T, {
4
+ export type NonNever<T extends {}> = Pick<T, {
5
5
  [K in keyof T]: T[K] extends never ? never : K;
6
6
  }[keyof T]>;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Represents some Type of the Object.
3
3
  */
4
- export declare type ObjectType<T> = {
4
+ export type ObjectType<T> = {
5
5
  new (): T;
6
6
  } | Function;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Pick only the keys that match the Type `U`
3
+ */
4
+ export type PickKeysByType<T, U> = string & keyof {
5
+ [P in keyof T as T[P] extends U ? P : never]: T[P];
6
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=PickKeysByType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/PickKeysByType.ts"],"names":[],"mappings":"","file":"PickKeysByType.js","sourcesContent":["/**\n * Pick only the keys that match the Type `U`\n */\nexport type PickKeysByType<T, U> = string &\n keyof {\n [P in keyof T as T[P] extends U ? P : never]: T[P]\n }\n"],"sourceRoot":".."}
@@ -11,4 +11,4 @@
11
11
  *
12
12
  * }
13
13
  */
14
- export declare type Relation<T> = T;
14
+ export type Relation<T> = T;
@@ -4,4 +4,4 @@ import { BaseDataSourceOptions } from "../data-source/BaseDataSourceOptions";
4
4
  *
5
5
  * @deprecated
6
6
  */
7
- export declare type BaseConnectionOptions = BaseDataSourceOptions;
7
+ export type BaseConnectionOptions = BaseDataSourceOptions;
@@ -6,4 +6,4 @@ import { DataSourceOptions } from "../data-source/DataSourceOptions";
6
6
  *
7
7
  * @deprecated use DataSourceOptions instead
8
8
  */
9
- export declare type ConnectionOptions = DataSourceOptions;
9
+ export type ConnectionOptions = DataSourceOptions;
package/container.d.ts CHANGED
@@ -16,7 +16,7 @@ export interface UseContainerOptions {
16
16
  /**
17
17
  * @deprecated
18
18
  */
19
- export declare type ContainedType<T> = {
19
+ export type ContainedType<T> = {
20
20
  new (...args: any[]): T;
21
21
  } | Function;
22
22
  /**
@@ -19,4 +19,4 @@ import { SpannerConnectionOptions } from "../driver/spanner/SpannerConnectionOpt
19
19
  /**
20
20
  * DataSourceOptions is an interface with settings and options for specific DataSource.
21
21
  */
22
- export declare type DataSourceOptions = MysqlConnectionOptions | PostgresConnectionOptions | CockroachConnectionOptions | SqliteConnectionOptions | SqlServerConnectionOptions | SapConnectionOptions | OracleConnectionOptions | CordovaConnectionOptions | NativescriptConnectionOptions | ReactNativeConnectionOptions | SqljsConnectionOptions | MongoConnectionOptions | AuroraMysqlConnectionOptions | AuroraPostgresConnectionOptions | ExpoConnectionOptions | BetterSqlite3ConnectionOptions | CapacitorConnectionOptions | SpannerConnectionOptions;
22
+ export type DataSourceOptions = MysqlConnectionOptions | PostgresConnectionOptions | CockroachConnectionOptions | SqliteConnectionOptions | SqlServerConnectionOptions | SapConnectionOptions | OracleConnectionOptions | CordovaConnectionOptions | NativescriptConnectionOptions | ReactNativeConnectionOptions | SqljsConnectionOptions | MongoConnectionOptions | AuroraMysqlConnectionOptions | AuroraPostgresConnectionOptions | ExpoConnectionOptions | BetterSqlite3ConnectionOptions | CapacitorConnectionOptions | SpannerConnectionOptions;