@yandjin-mikro-orm/core 6.1.4-rc-sti-changes-1

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/EntityManager.d.ts +553 -0
  2. package/EntityManager.js +1736 -0
  3. package/LICENSE +21 -0
  4. package/MikroORM.d.ts +102 -0
  5. package/MikroORM.js +258 -0
  6. package/README.md +383 -0
  7. package/cache/CacheAdapter.d.ts +40 -0
  8. package/cache/CacheAdapter.js +2 -0
  9. package/cache/FileCacheAdapter.d.ts +31 -0
  10. package/cache/FileCacheAdapter.js +90 -0
  11. package/cache/GeneratedCacheAdapter.d.ts +25 -0
  12. package/cache/GeneratedCacheAdapter.js +38 -0
  13. package/cache/MemoryCacheAdapter.d.ts +24 -0
  14. package/cache/MemoryCacheAdapter.js +44 -0
  15. package/cache/NullCacheAdapter.d.ts +19 -0
  16. package/cache/NullCacheAdapter.js +30 -0
  17. package/cache/index.d.ts +5 -0
  18. package/cache/index.js +21 -0
  19. package/connections/Connection.d.ts +85 -0
  20. package/connections/Connection.js +128 -0
  21. package/connections/index.d.ts +1 -0
  22. package/connections/index.js +17 -0
  23. package/decorators/Check.d.ts +3 -0
  24. package/decorators/Check.js +17 -0
  25. package/decorators/CreateRequestContext.d.ts +2 -0
  26. package/decorators/CreateRequestContext.js +31 -0
  27. package/decorators/Embeddable.d.ts +8 -0
  28. package/decorators/Embeddable.js +15 -0
  29. package/decorators/Embedded.d.ts +13 -0
  30. package/decorators/Embedded.js +21 -0
  31. package/decorators/EnsureRequestContext.d.ts +2 -0
  32. package/decorators/EnsureRequestContext.js +26 -0
  33. package/decorators/Entity.d.ts +18 -0
  34. package/decorators/Entity.js +17 -0
  35. package/decorators/Enum.d.ts +9 -0
  36. package/decorators/Enum.js +20 -0
  37. package/decorators/Filter.d.ts +2 -0
  38. package/decorators/Filter.js +12 -0
  39. package/decorators/Formula.d.ts +5 -0
  40. package/decorators/Formula.js +19 -0
  41. package/decorators/Indexed.d.ts +12 -0
  42. package/decorators/Indexed.js +25 -0
  43. package/decorators/ManyToMany.d.ts +21 -0
  44. package/decorators/ManyToMany.js +17 -0
  45. package/decorators/ManyToOne.d.ts +15 -0
  46. package/decorators/ManyToOne.js +17 -0
  47. package/decorators/OneToMany.d.ts +18 -0
  48. package/decorators/OneToMany.js +21 -0
  49. package/decorators/OneToOne.d.ts +12 -0
  50. package/decorators/OneToOne.js +11 -0
  51. package/decorators/PrimaryKey.d.ts +8 -0
  52. package/decorators/PrimaryKey.js +24 -0
  53. package/decorators/Property.d.ts +218 -0
  54. package/decorators/Property.js +35 -0
  55. package/decorators/Subscriber.d.ts +1 -0
  56. package/decorators/Subscriber.js +2 -0
  57. package/decorators/hooks.d.ts +16 -0
  58. package/decorators/hooks.js +60 -0
  59. package/decorators/index.d.ts +17 -0
  60. package/decorators/index.js +36 -0
  61. package/drivers/DatabaseDriver.d.ts +72 -0
  62. package/drivers/DatabaseDriver.js +358 -0
  63. package/drivers/IDatabaseDriver.d.ts +193 -0
  64. package/drivers/IDatabaseDriver.js +4 -0
  65. package/drivers/index.d.ts +2 -0
  66. package/drivers/index.js +18 -0
  67. package/entity/ArrayCollection.d.ts +113 -0
  68. package/entity/ArrayCollection.js +386 -0
  69. package/entity/BaseEntity.d.ts +22 -0
  70. package/entity/BaseEntity.js +47 -0
  71. package/entity/Collection.d.ts +104 -0
  72. package/entity/Collection.js +373 -0
  73. package/entity/EntityAssigner.d.ts +28 -0
  74. package/entity/EntityAssigner.js +226 -0
  75. package/entity/EntityFactory.d.ts +41 -0
  76. package/entity/EntityFactory.js +302 -0
  77. package/entity/EntityHelper.d.ts +29 -0
  78. package/entity/EntityHelper.js +250 -0
  79. package/entity/EntityIdentifier.d.ts +10 -0
  80. package/entity/EntityIdentifier.js +19 -0
  81. package/entity/EntityLoader.d.ts +65 -0
  82. package/entity/EntityLoader.js +579 -0
  83. package/entity/EntityRepository.d.ts +161 -0
  84. package/entity/EntityRepository.js +207 -0
  85. package/entity/EntityValidator.d.ts +19 -0
  86. package/entity/EntityValidator.js +152 -0
  87. package/entity/Reference.d.ts +89 -0
  88. package/entity/Reference.js +242 -0
  89. package/entity/WrappedEntity.d.ts +67 -0
  90. package/entity/WrappedEntity.js +146 -0
  91. package/entity/index.d.ts +13 -0
  92. package/entity/index.js +29 -0
  93. package/entity/wrap.d.ts +15 -0
  94. package/entity/wrap.js +26 -0
  95. package/enums.d.ts +160 -0
  96. package/enums.js +169 -0
  97. package/errors.d.ts +65 -0
  98. package/errors.js +222 -0
  99. package/events/EventManager.d.ts +17 -0
  100. package/events/EventManager.js +77 -0
  101. package/events/EventSubscriber.d.ts +39 -0
  102. package/events/EventSubscriber.js +2 -0
  103. package/events/TransactionEventBroadcaster.d.ts +11 -0
  104. package/events/TransactionEventBroadcaster.js +17 -0
  105. package/events/index.d.ts +3 -0
  106. package/events/index.js +19 -0
  107. package/exceptions.d.ts +104 -0
  108. package/exceptions.js +130 -0
  109. package/hydration/Hydrator.d.ts +23 -0
  110. package/hydration/Hydrator.js +51 -0
  111. package/hydration/ObjectHydrator.d.ts +24 -0
  112. package/hydration/ObjectHydrator.js +332 -0
  113. package/hydration/index.d.ts +2 -0
  114. package/hydration/index.js +18 -0
  115. package/index.d.ts +25 -0
  116. package/index.js +50 -0
  117. package/index.mjs +192 -0
  118. package/logging/DefaultLogger.d.ts +32 -0
  119. package/logging/DefaultLogger.js +90 -0
  120. package/logging/Logger.d.ts +56 -0
  121. package/logging/Logger.js +2 -0
  122. package/logging/SimpleLogger.d.ts +17 -0
  123. package/logging/SimpleLogger.js +31 -0
  124. package/logging/colors.d.ts +9 -0
  125. package/logging/colors.js +20 -0
  126. package/logging/index.d.ts +4 -0
  127. package/logging/index.js +20 -0
  128. package/metadata/EntitySchema.d.ts +74 -0
  129. package/metadata/EntitySchema.js +293 -0
  130. package/metadata/MetadataDiscovery.d.ts +71 -0
  131. package/metadata/MetadataDiscovery.js +1244 -0
  132. package/metadata/MetadataProvider.d.ts +11 -0
  133. package/metadata/MetadataProvider.js +23 -0
  134. package/metadata/MetadataStorage.d.ts +22 -0
  135. package/metadata/MetadataStorage.js +87 -0
  136. package/metadata/MetadataValidator.d.ts +24 -0
  137. package/metadata/MetadataValidator.js +213 -0
  138. package/metadata/ReflectMetadataProvider.d.ts +8 -0
  139. package/metadata/ReflectMetadataProvider.js +48 -0
  140. package/metadata/index.d.ts +6 -0
  141. package/metadata/index.js +22 -0
  142. package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
  143. package/naming-strategy/AbstractNamingStrategy.js +48 -0
  144. package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
  145. package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
  146. package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
  147. package/naming-strategy/MongoNamingStrategy.js +25 -0
  148. package/naming-strategy/NamingStrategy.d.ts +52 -0
  149. package/naming-strategy/NamingStrategy.js +2 -0
  150. package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
  151. package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
  152. package/naming-strategy/index.d.ts +5 -0
  153. package/naming-strategy/index.js +21 -0
  154. package/package.json +70 -0
  155. package/platforms/ExceptionConverter.d.ts +5 -0
  156. package/platforms/ExceptionConverter.js +11 -0
  157. package/platforms/Platform.d.ts +201 -0
  158. package/platforms/Platform.js +452 -0
  159. package/platforms/index.d.ts +2 -0
  160. package/platforms/index.js +18 -0
  161. package/serialization/EntitySerializer.d.ts +34 -0
  162. package/serialization/EntitySerializer.js +206 -0
  163. package/serialization/EntityTransformer.d.ts +8 -0
  164. package/serialization/EntityTransformer.js +192 -0
  165. package/serialization/SerializationContext.d.ts +30 -0
  166. package/serialization/SerializationContext.js +111 -0
  167. package/serialization/index.d.ts +3 -0
  168. package/serialization/index.js +19 -0
  169. package/types/ArrayType.d.ts +13 -0
  170. package/types/ArrayType.js +47 -0
  171. package/types/BigIntType.d.ts +16 -0
  172. package/types/BigIntType.js +45 -0
  173. package/types/BlobType.d.ts +10 -0
  174. package/types/BlobType.js +27 -0
  175. package/types/BooleanType.d.ts +8 -0
  176. package/types/BooleanType.js +16 -0
  177. package/types/DateTimeType.d.ts +8 -0
  178. package/types/DateTimeType.js +16 -0
  179. package/types/DateType.d.ts +8 -0
  180. package/types/DateType.js +16 -0
  181. package/types/DecimalType.d.ts +11 -0
  182. package/types/DecimalType.js +22 -0
  183. package/types/DoubleType.d.ts +11 -0
  184. package/types/DoubleType.js +22 -0
  185. package/types/EnumArrayType.d.ts +9 -0
  186. package/types/EnumArrayType.js +32 -0
  187. package/types/EnumType.d.ts +8 -0
  188. package/types/EnumType.js +16 -0
  189. package/types/FloatType.d.ts +8 -0
  190. package/types/FloatType.js +16 -0
  191. package/types/IntegerType.d.ts +8 -0
  192. package/types/IntegerType.js +16 -0
  193. package/types/IntervalType.d.ts +8 -0
  194. package/types/IntervalType.js +16 -0
  195. package/types/JsonType.d.ts +13 -0
  196. package/types/JsonType.js +34 -0
  197. package/types/MediumIntType.d.ts +6 -0
  198. package/types/MediumIntType.js +10 -0
  199. package/types/SmallIntType.d.ts +8 -0
  200. package/types/SmallIntType.js +16 -0
  201. package/types/StringType.d.ts +8 -0
  202. package/types/StringType.js +16 -0
  203. package/types/TextType.d.ts +8 -0
  204. package/types/TextType.js +16 -0
  205. package/types/TimeType.d.ts +9 -0
  206. package/types/TimeType.js +23 -0
  207. package/types/TinyIntType.d.ts +8 -0
  208. package/types/TinyIntType.js +16 -0
  209. package/types/Type.d.ts +64 -0
  210. package/types/Type.js +84 -0
  211. package/types/Uint8ArrayType.d.ts +11 -0
  212. package/types/Uint8ArrayType.js +37 -0
  213. package/types/UnknownType.d.ts +7 -0
  214. package/types/UnknownType.js +13 -0
  215. package/types/UuidType.d.ts +7 -0
  216. package/types/UuidType.js +13 -0
  217. package/types/index.d.ts +75 -0
  218. package/types/index.js +77 -0
  219. package/typings.d.ts +767 -0
  220. package/typings.js +198 -0
  221. package/unit-of-work/ChangeSet.d.ts +34 -0
  222. package/unit-of-work/ChangeSet.js +62 -0
  223. package/unit-of-work/ChangeSetComputer.d.ts +26 -0
  224. package/unit-of-work/ChangeSetComputer.js +153 -0
  225. package/unit-of-work/ChangeSetPersister.d.ts +50 -0
  226. package/unit-of-work/ChangeSetPersister.js +361 -0
  227. package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
  228. package/unit-of-work/CommitOrderCalculator.js +113 -0
  229. package/unit-of-work/IdentityMap.d.ts +17 -0
  230. package/unit-of-work/IdentityMap.js +84 -0
  231. package/unit-of-work/UnitOfWork.d.ts +124 -0
  232. package/unit-of-work/UnitOfWork.js +1013 -0
  233. package/unit-of-work/index.d.ts +6 -0
  234. package/unit-of-work/index.js +22 -0
  235. package/utils/AbstractSchemaGenerator.d.ts +38 -0
  236. package/utils/AbstractSchemaGenerator.js +101 -0
  237. package/utils/Configuration.d.ts +390 -0
  238. package/utils/Configuration.js +357 -0
  239. package/utils/ConfigurationLoader.d.ts +29 -0
  240. package/utils/ConfigurationLoader.js +282 -0
  241. package/utils/Cursor.d.ts +77 -0
  242. package/utils/Cursor.js +169 -0
  243. package/utils/DataloaderUtils.d.ts +43 -0
  244. package/utils/DataloaderUtils.js +194 -0
  245. package/utils/EntityComparator.d.ts +73 -0
  246. package/utils/EntityComparator.js +568 -0
  247. package/utils/NullHighlighter.d.ts +4 -0
  248. package/utils/NullHighlighter.js +9 -0
  249. package/utils/QueryHelper.d.ts +28 -0
  250. package/utils/QueryHelper.js +228 -0
  251. package/utils/RawQueryFragment.d.ts +96 -0
  252. package/utils/RawQueryFragment.js +188 -0
  253. package/utils/RequestContext.d.ts +34 -0
  254. package/utils/RequestContext.js +54 -0
  255. package/utils/TransactionContext.d.ts +19 -0
  256. package/utils/TransactionContext.js +34 -0
  257. package/utils/Utils.d.ts +274 -0
  258. package/utils/Utils.js +1073 -0
  259. package/utils/clone.d.ts +6 -0
  260. package/utils/clone.js +127 -0
  261. package/utils/index.d.ts +13 -0
  262. package/utils/index.js +29 -0
  263. package/utils/upsert-utils.d.ts +6 -0
  264. package/utils/upsert-utils.js +33 -0
package/enums.d.ts ADDED
@@ -0,0 +1,160 @@
1
+ import type { Dictionary, EntityKey, ExpandProperty } from './typings';
2
+ import type { Transaction } from './connections';
3
+ import type { LogContext } from './logging';
4
+ export declare enum FlushMode {
5
+ /** The `EntityManager` delays the flush until the current Transaction is committed. */
6
+ COMMIT = "commit",
7
+ /** This is the default mode, and it flushes the `EntityManager` only if necessary. */
8
+ AUTO = "auto",
9
+ /** Flushes the `EntityManager` before every query. */
10
+ ALWAYS = "always"
11
+ }
12
+ export declare enum PopulateHint {
13
+ INFER = "infer",
14
+ ALL = "all"
15
+ }
16
+ export declare enum GroupOperator {
17
+ $and = "and",
18
+ $or = "or"
19
+ }
20
+ export declare enum QueryOperator {
21
+ $eq = "=",
22
+ $in = "in",
23
+ $nin = "not in",
24
+ $gt = ">",
25
+ $gte = ">=",
26
+ $lt = "<",
27
+ $lte = "<=",
28
+ $ne = "!=",
29
+ $not = "not",
30
+ $like = "like",
31
+ $re = "regexp",
32
+ $fulltext = "fulltext",
33
+ $exists = "not null",
34
+ $ilike = "ilike",// postgres only
35
+ $overlap = "&&",// postgres only
36
+ $contains = "@>",// postgres only
37
+ $contained = "<@",// postgres only
38
+ $none = "none",// collection operators, sql only
39
+ $some = "some",// collection operators, sql only
40
+ $every = "every"
41
+ }
42
+ export declare const ARRAY_OPERATORS: string[];
43
+ export declare enum QueryOrder {
44
+ ASC = "ASC",
45
+ ASC_NULLS_LAST = "ASC NULLS LAST",
46
+ ASC_NULLS_FIRST = "ASC NULLS FIRST",
47
+ DESC = "DESC",
48
+ DESC_NULLS_LAST = "DESC NULLS LAST",
49
+ DESC_NULLS_FIRST = "DESC NULLS FIRST",
50
+ asc = "asc",
51
+ asc_nulls_last = "asc nulls last",
52
+ asc_nulls_first = "asc nulls first",
53
+ desc = "desc",
54
+ desc_nulls_last = "desc nulls last",
55
+ desc_nulls_first = "desc nulls first"
56
+ }
57
+ export declare enum QueryOrderNumeric {
58
+ ASC = 1,
59
+ DESC = -1
60
+ }
61
+ export type QueryOrderKeysFlat = QueryOrder | QueryOrderNumeric | keyof typeof QueryOrder;
62
+ export type QueryOrderKeys<T> = QueryOrderKeysFlat | QueryOrderMap<T>;
63
+ export type QueryOrderMap<T> = {
64
+ [K in EntityKey<T>]?: QueryOrderKeys<ExpandProperty<T[K]>>;
65
+ };
66
+ export type QBQueryOrderMap<T> = QueryOrderMap<T> | Dictionary;
67
+ export interface FlatQueryOrderMap {
68
+ [x: string]: QueryOrderKeysFlat;
69
+ }
70
+ export declare enum QueryFlag {
71
+ DISTINCT = "DISTINCT",
72
+ PAGINATE = "PAGINATE",
73
+ DISABLE_PAGINATE = "DISABLE_PAGINATE",
74
+ UPDATE_SUB_QUERY = "UPDATE_SUB_QUERY",
75
+ DELETE_SUB_QUERY = "DELETE_SUB_QUERY",
76
+ CONVERT_CUSTOM_TYPES = "CONVERT_CUSTOM_TYPES",
77
+ INCLUDE_LAZY_FORMULAS = "INCLUDE_LAZY_FORMULAS",
78
+ AUTO_JOIN_ONE_TO_ONE_OWNER = "AUTO_JOIN_ONE_TO_ONE_OWNER",
79
+ INFER_POPULATE = "INFER_POPULATE"
80
+ }
81
+ export declare const SCALAR_TYPES: string[];
82
+ export declare enum ReferenceKind {
83
+ SCALAR = "scalar",
84
+ ONE_TO_ONE = "1:1",
85
+ ONE_TO_MANY = "1:m",
86
+ MANY_TO_ONE = "m:1",
87
+ MANY_TO_MANY = "m:n",
88
+ EMBEDDED = "embedded"
89
+ }
90
+ export declare enum Cascade {
91
+ PERSIST = "persist",
92
+ MERGE = "merge",
93
+ REMOVE = "remove",
94
+ ALL = "all",
95
+ /** @internal */
96
+ SCHEDULE_ORPHAN_REMOVAL = "schedule_orphan_removal",
97
+ /** @internal */
98
+ CANCEL_ORPHAN_REMOVAL = "cancel_orphan_removal"
99
+ }
100
+ export declare enum LoadStrategy {
101
+ SELECT_IN = "select-in",
102
+ JOINED = "joined"
103
+ }
104
+ export declare enum DataloaderType {
105
+ NONE = 0,
106
+ REFERENCE = 1,
107
+ COLLECTION = 2,
108
+ ALL = 3
109
+ }
110
+ export declare enum LockMode {
111
+ NONE = 0,
112
+ OPTIMISTIC = 1,
113
+ PESSIMISTIC_READ = 2,
114
+ PESSIMISTIC_WRITE = 3,
115
+ PESSIMISTIC_PARTIAL_WRITE = 4,
116
+ PESSIMISTIC_WRITE_OR_FAIL = 5,
117
+ PESSIMISTIC_PARTIAL_READ = 6,
118
+ PESSIMISTIC_READ_OR_FAIL = 7
119
+ }
120
+ export declare enum IsolationLevel {
121
+ READ_UNCOMMITTED = "read uncommitted",
122
+ READ_COMMITTED = "read committed",
123
+ SNAPSHOT = "snapshot",
124
+ REPEATABLE_READ = "repeatable read",
125
+ SERIALIZABLE = "serializable"
126
+ }
127
+ export declare enum EventType {
128
+ onInit = "onInit",
129
+ onLoad = "onLoad",
130
+ beforeCreate = "beforeCreate",
131
+ afterCreate = "afterCreate",
132
+ beforeUpdate = "beforeUpdate",
133
+ afterUpdate = "afterUpdate",
134
+ beforeUpsert = "beforeUpsert",
135
+ afterUpsert = "afterUpsert",
136
+ beforeDelete = "beforeDelete",
137
+ afterDelete = "afterDelete",
138
+ beforeFlush = "beforeFlush",
139
+ onFlush = "onFlush",
140
+ afterFlush = "afterFlush",
141
+ beforeTransactionStart = "beforeTransactionStart",
142
+ afterTransactionStart = "afterTransactionStart",
143
+ beforeTransactionCommit = "beforeTransactionCommit",
144
+ afterTransactionCommit = "afterTransactionCommit",
145
+ beforeTransactionRollback = "beforeTransactionRollback",
146
+ afterTransactionRollback = "afterTransactionRollback"
147
+ }
148
+ export declare const EventTypeMap: Record<EventType, number>;
149
+ export type TransactionEventType = EventType.beforeTransactionStart | EventType.afterTransactionStart | EventType.beforeTransactionCommit | EventType.afterTransactionCommit | EventType.beforeTransactionRollback | EventType.afterTransactionRollback;
150
+ export interface TransactionOptions {
151
+ ctx?: Transaction;
152
+ isolationLevel?: IsolationLevel;
153
+ readOnly?: boolean;
154
+ clear?: boolean;
155
+ flushMode?: FlushMode;
156
+ ignoreNestedTransactions?: boolean;
157
+ loggerContext?: LogContext;
158
+ }
159
+ export declare abstract class PlainObject {
160
+ }
package/enums.js ADDED
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlainObject = exports.EventTypeMap = exports.EventType = exports.IsolationLevel = exports.LockMode = exports.DataloaderType = exports.LoadStrategy = exports.Cascade = exports.ReferenceKind = exports.SCALAR_TYPES = exports.QueryFlag = exports.QueryOrderNumeric = exports.QueryOrder = exports.ARRAY_OPERATORS = exports.QueryOperator = exports.GroupOperator = exports.PopulateHint = exports.FlushMode = void 0;
4
+ var FlushMode;
5
+ (function (FlushMode) {
6
+ /** The `EntityManager` delays the flush until the current Transaction is committed. */
7
+ FlushMode["COMMIT"] = "commit";
8
+ /** This is the default mode, and it flushes the `EntityManager` only if necessary. */
9
+ FlushMode["AUTO"] = "auto";
10
+ /** Flushes the `EntityManager` before every query. */
11
+ FlushMode["ALWAYS"] = "always";
12
+ })(FlushMode || (exports.FlushMode = FlushMode = {}));
13
+ var PopulateHint;
14
+ (function (PopulateHint) {
15
+ PopulateHint["INFER"] = "infer";
16
+ PopulateHint["ALL"] = "all";
17
+ })(PopulateHint || (exports.PopulateHint = PopulateHint = {}));
18
+ var GroupOperator;
19
+ (function (GroupOperator) {
20
+ GroupOperator["$and"] = "and";
21
+ GroupOperator["$or"] = "or";
22
+ })(GroupOperator || (exports.GroupOperator = GroupOperator = {}));
23
+ var QueryOperator;
24
+ (function (QueryOperator) {
25
+ QueryOperator["$eq"] = "=";
26
+ QueryOperator["$in"] = "in";
27
+ QueryOperator["$nin"] = "not in";
28
+ QueryOperator["$gt"] = ">";
29
+ QueryOperator["$gte"] = ">=";
30
+ QueryOperator["$lt"] = "<";
31
+ QueryOperator["$lte"] = "<=";
32
+ QueryOperator["$ne"] = "!=";
33
+ QueryOperator["$not"] = "not";
34
+ QueryOperator["$like"] = "like";
35
+ QueryOperator["$re"] = "regexp";
36
+ QueryOperator["$fulltext"] = "fulltext";
37
+ QueryOperator["$exists"] = "not null";
38
+ QueryOperator["$ilike"] = "ilike";
39
+ QueryOperator["$overlap"] = "&&";
40
+ QueryOperator["$contains"] = "@>";
41
+ QueryOperator["$contained"] = "<@";
42
+ QueryOperator["$none"] = "none";
43
+ QueryOperator["$some"] = "some";
44
+ QueryOperator["$every"] = "every";
45
+ })(QueryOperator || (exports.QueryOperator = QueryOperator = {}));
46
+ exports.ARRAY_OPERATORS = [
47
+ '$eq',
48
+ '$gt',
49
+ '$gte',
50
+ '$lt',
51
+ '$lte',
52
+ '$ne',
53
+ '$overlap',
54
+ '$contains',
55
+ '$contained',
56
+ ];
57
+ var QueryOrder;
58
+ (function (QueryOrder) {
59
+ QueryOrder["ASC"] = "ASC";
60
+ QueryOrder["ASC_NULLS_LAST"] = "ASC NULLS LAST";
61
+ QueryOrder["ASC_NULLS_FIRST"] = "ASC NULLS FIRST";
62
+ QueryOrder["DESC"] = "DESC";
63
+ QueryOrder["DESC_NULLS_LAST"] = "DESC NULLS LAST";
64
+ QueryOrder["DESC_NULLS_FIRST"] = "DESC NULLS FIRST";
65
+ QueryOrder["asc"] = "asc";
66
+ QueryOrder["asc_nulls_last"] = "asc nulls last";
67
+ QueryOrder["asc_nulls_first"] = "asc nulls first";
68
+ QueryOrder["desc"] = "desc";
69
+ QueryOrder["desc_nulls_last"] = "desc nulls last";
70
+ QueryOrder["desc_nulls_first"] = "desc nulls first";
71
+ })(QueryOrder || (exports.QueryOrder = QueryOrder = {}));
72
+ var QueryOrderNumeric;
73
+ (function (QueryOrderNumeric) {
74
+ QueryOrderNumeric[QueryOrderNumeric["ASC"] = 1] = "ASC";
75
+ QueryOrderNumeric[QueryOrderNumeric["DESC"] = -1] = "DESC";
76
+ })(QueryOrderNumeric || (exports.QueryOrderNumeric = QueryOrderNumeric = {}));
77
+ var QueryFlag;
78
+ (function (QueryFlag) {
79
+ QueryFlag["DISTINCT"] = "DISTINCT";
80
+ QueryFlag["PAGINATE"] = "PAGINATE";
81
+ QueryFlag["DISABLE_PAGINATE"] = "DISABLE_PAGINATE";
82
+ QueryFlag["UPDATE_SUB_QUERY"] = "UPDATE_SUB_QUERY";
83
+ QueryFlag["DELETE_SUB_QUERY"] = "DELETE_SUB_QUERY";
84
+ QueryFlag["CONVERT_CUSTOM_TYPES"] = "CONVERT_CUSTOM_TYPES";
85
+ QueryFlag["INCLUDE_LAZY_FORMULAS"] = "INCLUDE_LAZY_FORMULAS";
86
+ QueryFlag["AUTO_JOIN_ONE_TO_ONE_OWNER"] = "AUTO_JOIN_ONE_TO_ONE_OWNER";
87
+ QueryFlag["INFER_POPULATE"] = "INFER_POPULATE";
88
+ })(QueryFlag || (exports.QueryFlag = QueryFlag = {}));
89
+ exports.SCALAR_TYPES = ['string', 'number', 'boolean', 'Date', 'Buffer', 'RegExp'];
90
+ var ReferenceKind;
91
+ (function (ReferenceKind) {
92
+ ReferenceKind["SCALAR"] = "scalar";
93
+ ReferenceKind["ONE_TO_ONE"] = "1:1";
94
+ ReferenceKind["ONE_TO_MANY"] = "1:m";
95
+ ReferenceKind["MANY_TO_ONE"] = "m:1";
96
+ ReferenceKind["MANY_TO_MANY"] = "m:n";
97
+ ReferenceKind["EMBEDDED"] = "embedded";
98
+ })(ReferenceKind || (exports.ReferenceKind = ReferenceKind = {}));
99
+ var Cascade;
100
+ (function (Cascade) {
101
+ Cascade["PERSIST"] = "persist";
102
+ Cascade["MERGE"] = "merge";
103
+ Cascade["REMOVE"] = "remove";
104
+ Cascade["ALL"] = "all";
105
+ /** @internal */
106
+ Cascade["SCHEDULE_ORPHAN_REMOVAL"] = "schedule_orphan_removal";
107
+ /** @internal */
108
+ Cascade["CANCEL_ORPHAN_REMOVAL"] = "cancel_orphan_removal";
109
+ })(Cascade || (exports.Cascade = Cascade = {}));
110
+ var LoadStrategy;
111
+ (function (LoadStrategy) {
112
+ LoadStrategy["SELECT_IN"] = "select-in";
113
+ LoadStrategy["JOINED"] = "joined";
114
+ })(LoadStrategy || (exports.LoadStrategy = LoadStrategy = {}));
115
+ var DataloaderType;
116
+ (function (DataloaderType) {
117
+ DataloaderType[DataloaderType["NONE"] = 0] = "NONE";
118
+ DataloaderType[DataloaderType["REFERENCE"] = 1] = "REFERENCE";
119
+ DataloaderType[DataloaderType["COLLECTION"] = 2] = "COLLECTION";
120
+ DataloaderType[DataloaderType["ALL"] = 3] = "ALL";
121
+ })(DataloaderType || (exports.DataloaderType = DataloaderType = {}));
122
+ var LockMode;
123
+ (function (LockMode) {
124
+ LockMode[LockMode["NONE"] = 0] = "NONE";
125
+ LockMode[LockMode["OPTIMISTIC"] = 1] = "OPTIMISTIC";
126
+ LockMode[LockMode["PESSIMISTIC_READ"] = 2] = "PESSIMISTIC_READ";
127
+ LockMode[LockMode["PESSIMISTIC_WRITE"] = 3] = "PESSIMISTIC_WRITE";
128
+ LockMode[LockMode["PESSIMISTIC_PARTIAL_WRITE"] = 4] = "PESSIMISTIC_PARTIAL_WRITE";
129
+ LockMode[LockMode["PESSIMISTIC_WRITE_OR_FAIL"] = 5] = "PESSIMISTIC_WRITE_OR_FAIL";
130
+ LockMode[LockMode["PESSIMISTIC_PARTIAL_READ"] = 6] = "PESSIMISTIC_PARTIAL_READ";
131
+ LockMode[LockMode["PESSIMISTIC_READ_OR_FAIL"] = 7] = "PESSIMISTIC_READ_OR_FAIL";
132
+ })(LockMode || (exports.LockMode = LockMode = {}));
133
+ var IsolationLevel;
134
+ (function (IsolationLevel) {
135
+ IsolationLevel["READ_UNCOMMITTED"] = "read uncommitted";
136
+ IsolationLevel["READ_COMMITTED"] = "read committed";
137
+ IsolationLevel["SNAPSHOT"] = "snapshot";
138
+ IsolationLevel["REPEATABLE_READ"] = "repeatable read";
139
+ IsolationLevel["SERIALIZABLE"] = "serializable";
140
+ })(IsolationLevel || (exports.IsolationLevel = IsolationLevel = {}));
141
+ var EventType;
142
+ (function (EventType) {
143
+ EventType["onInit"] = "onInit";
144
+ EventType["onLoad"] = "onLoad";
145
+ EventType["beforeCreate"] = "beforeCreate";
146
+ EventType["afterCreate"] = "afterCreate";
147
+ EventType["beforeUpdate"] = "beforeUpdate";
148
+ EventType["afterUpdate"] = "afterUpdate";
149
+ EventType["beforeUpsert"] = "beforeUpsert";
150
+ EventType["afterUpsert"] = "afterUpsert";
151
+ EventType["beforeDelete"] = "beforeDelete";
152
+ EventType["afterDelete"] = "afterDelete";
153
+ EventType["beforeFlush"] = "beforeFlush";
154
+ EventType["onFlush"] = "onFlush";
155
+ EventType["afterFlush"] = "afterFlush";
156
+ EventType["beforeTransactionStart"] = "beforeTransactionStart";
157
+ EventType["afterTransactionStart"] = "afterTransactionStart";
158
+ EventType["beforeTransactionCommit"] = "beforeTransactionCommit";
159
+ EventType["afterTransactionCommit"] = "afterTransactionCommit";
160
+ EventType["beforeTransactionRollback"] = "beforeTransactionRollback";
161
+ EventType["afterTransactionRollback"] = "afterTransactionRollback";
162
+ })(EventType || (exports.EventType = EventType = {}));
163
+ exports.EventTypeMap = Object.keys(EventType).reduce((a, b, i) => {
164
+ a[b] = i;
165
+ return a;
166
+ }, {});
167
+ class PlainObject {
168
+ }
169
+ exports.PlainObject = PlainObject;
package/errors.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ import type { AnyEntity, Constructor, Dictionary, EntityMetadata, EntityProperty, IPrimaryKey } from './typings';
2
+ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Error {
3
+ readonly entity?: T | undefined;
4
+ constructor(message: string, entity?: T | undefined);
5
+ /**
6
+ * Gets instance of entity that caused this error.
7
+ */
8
+ getEntity(): AnyEntity | undefined;
9
+ static fromWrongPropertyType(entity: AnyEntity, property: string, expectedType: string, givenType: string, givenValue: string): ValidationError;
10
+ static fromWrongRepositoryType(entityName: string, repoType: string, method: string): ValidationError;
11
+ static fromCollectionNotInitialized(entity: AnyEntity, prop: EntityProperty): ValidationError;
12
+ static fromMergeWithoutPK(meta: EntityMetadata): ValidationError;
13
+ static transactionRequired(): ValidationError;
14
+ static entityNotManaged(entity: AnyEntity): ValidationError;
15
+ static notEntity(owner: AnyEntity, prop: EntityProperty, data: any): ValidationError;
16
+ static notDiscoveredEntity(data: any, meta?: EntityMetadata, action?: string): ValidationError;
17
+ static invalidPropertyName(entityName: string, invalid: string): ValidationError;
18
+ static invalidType(type: Constructor<any>, value: any, mode: string): ValidationError;
19
+ static propertyRequired(entity: AnyEntity, property: EntityProperty): ValidationError;
20
+ static cannotModifyInverseCollection(owner: AnyEntity, property: EntityProperty): ValidationError;
21
+ static cannotModifyReadonlyCollection(owner: AnyEntity, property: EntityProperty): ValidationError;
22
+ static cannotRemoveFromCollectionWithoutOrphanRemoval(owner: AnyEntity, property: EntityProperty): ValidationError;
23
+ static invalidCompositeIdentifier(meta: EntityMetadata): ValidationError;
24
+ static cannotCommit(): ValidationError;
25
+ static cannotUseGlobalContext(): ValidationError;
26
+ static cannotUseOperatorsInsideEmbeddables(className: string, propName: string, payload: unknown): ValidationError;
27
+ static invalidEmbeddableQuery(className: string, propName: string, embeddableType: string): ValidationError;
28
+ }
29
+ export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
30
+ static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError;
31
+ }
32
+ export declare class OptimisticLockError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
33
+ static notVersioned(meta: EntityMetadata): OptimisticLockError;
34
+ static lockFailed(entityOrName: AnyEntity | string): OptimisticLockError;
35
+ static lockFailedVersionMismatch(entity: AnyEntity, expectedLockVersion: number | Date, actualLockVersion: number | Date): OptimisticLockError;
36
+ }
37
+ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
38
+ static fromMissingPrimaryKey(meta: EntityMetadata): MetadataError;
39
+ static fromWrongReference(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy', owner?: EntityProperty): MetadataError;
40
+ static fromWrongTypeDefinition(meta: EntityMetadata, prop: EntityProperty): MetadataError;
41
+ static fromWrongOwnership(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy'): MetadataError;
42
+ static fromWrongReferenceKind(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
43
+ static fromInversideSidePrimary(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
44
+ static entityNotFound(name: string, path: string): MetadataError;
45
+ static unknownIndexProperty(meta: EntityMetadata, prop: string, type: string): MetadataError;
46
+ static multipleVersionFields(meta: EntityMetadata, fields: string[]): MetadataError;
47
+ static invalidVersionFieldType(meta: EntityMetadata): MetadataError;
48
+ static fromUnknownEntity(className: string, source: string): MetadataError;
49
+ static noEntityDiscovered(): MetadataError;
50
+ static onlyAbstractEntitiesDiscovered(): MetadataError;
51
+ static duplicateEntityDiscovered(paths: string[], subject?: string): MetadataError;
52
+ static duplicateFieldName(className: string, names: [string, string][]): MetadataError;
53
+ static multipleDecorators(entityName: string, propertyName: string): MetadataError;
54
+ static missingMetadata(entity: string): MetadataError;
55
+ static invalidPrimaryKey(meta: EntityMetadata, prop: EntityProperty, requiredName: string): MetadataError<Partial<any>>;
56
+ static invalidManyToManyWithPivotEntity(meta1: EntityMetadata, prop1: EntityProperty, meta2: EntityMetadata, prop2: EntityProperty): MetadataError<Partial<any>>;
57
+ static targetIsAbstract(meta: EntityMetadata, prop: EntityProperty): MetadataError<Partial<any>>;
58
+ static propertyTargetsEntityType(meta: EntityMetadata, prop: EntityProperty, target: EntityMetadata): MetadataError<Partial<any>>;
59
+ static fromMissingOption(meta: EntityMetadata, prop: EntityProperty, option: string): MetadataError<Partial<any>>;
60
+ private static fromMessage;
61
+ }
62
+ export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
63
+ static findOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
64
+ static findExactlyOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
65
+ }
package/errors.js ADDED
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotFoundError = exports.MetadataError = exports.OptimisticLockError = exports.CursorError = exports.ValidationError = void 0;
4
+ const util_1 = require("util");
5
+ class ValidationError extends Error {
6
+ entity;
7
+ constructor(message, entity) {
8
+ super(message);
9
+ this.entity = entity;
10
+ Error.captureStackTrace(this, this.constructor);
11
+ this.name = this.constructor.name;
12
+ this.message = message;
13
+ }
14
+ /**
15
+ * Gets instance of entity that caused this error.
16
+ */
17
+ getEntity() {
18
+ return this.entity;
19
+ }
20
+ static fromWrongPropertyType(entity, property, expectedType, givenType, givenValue) {
21
+ const entityName = entity.constructor.name;
22
+ const msg = `Trying to set ${entityName}.${property} of type '${expectedType}' to '${givenValue}' of type '${givenType}'`;
23
+ return new ValidationError(msg);
24
+ }
25
+ static fromWrongRepositoryType(entityName, repoType, method) {
26
+ const msg = `Trying to use EntityRepository.${method}() with '${entityName}' entity while the repository is of type '${repoType}'`;
27
+ return new ValidationError(msg);
28
+ }
29
+ static fromCollectionNotInitialized(entity, prop) {
30
+ const entityName = entity.constructor.name;
31
+ const msg = `${entityName}.${prop.name} is not initialized, define it as '${prop.name} = new Collection<${prop.type}>(this);'`;
32
+ return new ValidationError(msg);
33
+ }
34
+ static fromMergeWithoutPK(meta) {
35
+ return new ValidationError(`You cannot merge entity '${meta.className}' without identifier!`);
36
+ }
37
+ static transactionRequired() {
38
+ return new ValidationError('An open transaction is required for this operation');
39
+ }
40
+ static entityNotManaged(entity) {
41
+ return new ValidationError(`Entity ${entity.constructor.name} is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager.persist()`);
42
+ }
43
+ static notEntity(owner, prop, data) {
44
+ const type = Object.prototype.toString.call(data).match(/\[object (\w+)]/)[1].toLowerCase();
45
+ return new ValidationError(`Entity of type ${prop.type} expected for property ${owner.constructor.name}.${prop.name}, ${(0, util_1.inspect)(data)} of type ${type} given. If you are using Object.assign(entity, data), use em.assign(entity, data) instead.`);
46
+ }
47
+ static notDiscoveredEntity(data, meta, action = 'persist') {
48
+ /* istanbul ignore next */
49
+ const type = meta?.className ?? Object.prototype.toString.call(data).match(/\[object (\w+)]/)[1].toLowerCase();
50
+ let err = `Trying to ${action} not discovered entity of type ${type}.`;
51
+ /* istanbul ignore else */
52
+ if (meta) {
53
+ err += ` Entity with this name was discovered, but not the prototype you are passing to the ORM. If using EntitySchema, be sure to point to the implementation via \`class\`.`;
54
+ }
55
+ return new ValidationError(err);
56
+ }
57
+ static invalidPropertyName(entityName, invalid) {
58
+ return new ValidationError(`Entity '${entityName}' does not have property '${invalid}'`);
59
+ }
60
+ static invalidType(type, value, mode) {
61
+ const valueType = Object.prototype.toString.call(value).match(/\[object (\w+)]/)[1].toLowerCase();
62
+ if (value instanceof Date) {
63
+ value = value.toISOString();
64
+ }
65
+ return new ValidationError(`Could not convert ${mode} value '${value}' of type '${valueType}' to type ${type.name}`);
66
+ }
67
+ static propertyRequired(entity, property) {
68
+ const entityName = entity.__meta.className;
69
+ return new ValidationError(`Value for ${entityName}.${property.name} is required, '${entity[property.name]}' found\nentity: ${(0, util_1.inspect)(entity)}`, entity);
70
+ }
71
+ static cannotModifyInverseCollection(owner, property) {
72
+ const inverseCollection = `${owner.constructor.name}.${property.name}`;
73
+ const ownerCollection = `${property.type}.${property.mappedBy}`;
74
+ const error = `You cannot modify inverse side of M:N collection ${inverseCollection} when the owning side is not initialized. `
75
+ + `Consider working with the owning side instead (${ownerCollection}).`;
76
+ return new ValidationError(error, owner);
77
+ }
78
+ static cannotModifyReadonlyCollection(owner, property) {
79
+ return new ValidationError(`You cannot modify collection ${owner.constructor.name}.${property.name} as it is marked as readonly.`, owner);
80
+ }
81
+ static cannotRemoveFromCollectionWithoutOrphanRemoval(owner, property) {
82
+ const options = [
83
+ ' - add `orphanRemoval: true` to the collection options',
84
+ ' - add `deleteRule: \'cascade\'` to the owning side options',
85
+ ' - add `nullable: true` to the owning side options',
86
+ ].join('\n');
87
+ return new ValidationError(`Removing items from collection ${owner.constructor.name}.${property.name} without \`orphanRemoval: true\` would break non-null constraint on the owning side. You have several options: \n${options}`, owner);
88
+ }
89
+ static invalidCompositeIdentifier(meta) {
90
+ return new ValidationError(`Composite key required for entity ${meta.className}.`);
91
+ }
92
+ static cannotCommit() {
93
+ return new ValidationError('You cannot call em.flush() from inside lifecycle hook handlers');
94
+ }
95
+ static cannotUseGlobalContext() {
96
+ return new ValidationError('Using global EntityManager instance methods for context specific actions is disallowed. If you need to work with the global instance\'s identity map, use `allowGlobalContext` configuration option or `fork()` instead.');
97
+ }
98
+ static cannotUseOperatorsInsideEmbeddables(className, propName, payload) {
99
+ return new ValidationError(`Using operators inside embeddables is not allowed, move the operator above. (property: ${className}.${propName}, payload: ${(0, util_1.inspect)(payload)})`);
100
+ }
101
+ static invalidEmbeddableQuery(className, propName, embeddableType) {
102
+ return new ValidationError(`Invalid query for entity '${className}', property '${propName}' does not exist in embeddable '${embeddableType}'`);
103
+ }
104
+ }
105
+ exports.ValidationError = ValidationError;
106
+ class CursorError extends ValidationError {
107
+ static entityNotPopulated(entity, prop) {
108
+ return new CursorError(`Cannot create cursor, value for '${entity.constructor.name}.${prop}' is missing.`);
109
+ }
110
+ }
111
+ exports.CursorError = CursorError;
112
+ class OptimisticLockError extends ValidationError {
113
+ static notVersioned(meta) {
114
+ return new OptimisticLockError(`Cannot obtain optimistic lock on unversioned entity ${meta.className}`);
115
+ }
116
+ static lockFailed(entityOrName) {
117
+ const name = typeof entityOrName === 'string' ? entityOrName : entityOrName.constructor.name;
118
+ const entity = typeof entityOrName === 'string' ? undefined : entityOrName;
119
+ return new OptimisticLockError(`The optimistic lock on entity ${name} failed`, entity);
120
+ }
121
+ static lockFailedVersionMismatch(entity, expectedLockVersion, actualLockVersion) {
122
+ expectedLockVersion = expectedLockVersion instanceof Date ? expectedLockVersion.getTime() : expectedLockVersion;
123
+ actualLockVersion = actualLockVersion instanceof Date ? actualLockVersion.getTime() : actualLockVersion;
124
+ return new OptimisticLockError(`The optimistic lock failed, version ${expectedLockVersion} was expected, but is actually ${actualLockVersion}`, entity);
125
+ }
126
+ }
127
+ exports.OptimisticLockError = OptimisticLockError;
128
+ class MetadataError extends ValidationError {
129
+ static fromMissingPrimaryKey(meta) {
130
+ return new MetadataError(`${meta.className} entity is missing @PrimaryKey()`);
131
+ }
132
+ static fromWrongReference(meta, prop, key, owner) {
133
+ if (owner) {
134
+ return MetadataError.fromMessage(meta, prop, `has wrong '${key}' reference type: ${owner.type} instead of ${meta.className}`);
135
+ }
136
+ return MetadataError.fromMessage(meta, prop, `has unknown '${key}' reference: ${prop.type}.${prop[key]}`);
137
+ }
138
+ static fromWrongTypeDefinition(meta, prop) {
139
+ if (!prop.type) {
140
+ return MetadataError.fromMessage(meta, prop, `is missing type definition`);
141
+ }
142
+ return MetadataError.fromMessage(meta, prop, `has unknown type: ${prop.type}`);
143
+ }
144
+ static fromWrongOwnership(meta, prop, key) {
145
+ const type = key === 'inversedBy' ? 'owning' : 'inverse';
146
+ const other = key === 'inversedBy' ? 'mappedBy' : 'inversedBy';
147
+ return new MetadataError(`Both ${meta.className}.${prop.name} and ${prop.type}.${prop[key]} are defined as ${type} sides, use '${other}' on one of them`);
148
+ }
149
+ static fromWrongReferenceKind(meta, owner, prop) {
150
+ return new MetadataError(`${meta.className}.${prop.name} is of type ${prop.kind} which is incompatible with its owning side ${prop.type}.${owner.name} of type ${owner.kind}`);
151
+ }
152
+ static fromInversideSidePrimary(meta, owner, prop) {
153
+ return new MetadataError(`${meta.className}.${prop.name} cannot be primary key as it is defined as inverse side. Maybe you should swap the use of 'inversedBy' and 'mappedBy'.`);
154
+ }
155
+ /* istanbul ignore next */
156
+ static entityNotFound(name, path) {
157
+ return new MetadataError(`Entity '${name}' not found in ${path}`);
158
+ }
159
+ static unknownIndexProperty(meta, prop, type) {
160
+ return new MetadataError(`Entity ${meta.className} has wrong ${type} definition: '${prop}' does not exist. You need to use property name, not column name.`);
161
+ }
162
+ static multipleVersionFields(meta, fields) {
163
+ return new MetadataError(`Entity ${meta.className} has multiple version properties defined: '${fields.join('\', \'')}'. Only one version property is allowed per entity.`);
164
+ }
165
+ static invalidVersionFieldType(meta) {
166
+ const prop = meta.properties[meta.versionProperty];
167
+ return new MetadataError(`Version property ${meta.className}.${prop.name} has unsupported type '${prop.type}'. Only 'number' and 'Date' are allowed.`);
168
+ }
169
+ static fromUnknownEntity(className, source) {
170
+ return new MetadataError(`Entity '${className}' was not discovered, please make sure to provide it in 'entities' array when initializing the ORM (used in ${source})`);
171
+ }
172
+ static noEntityDiscovered() {
173
+ return new MetadataError('No entities were discovered');
174
+ }
175
+ static onlyAbstractEntitiesDiscovered() {
176
+ return new MetadataError('Only abstract entities were discovered, maybe you forgot to use @Entity() decorator?');
177
+ }
178
+ static duplicateEntityDiscovered(paths, subject = 'entity names') {
179
+ return new MetadataError(`Duplicate ${subject} are not allowed: ${paths.join(', ')}`);
180
+ }
181
+ static duplicateFieldName(className, names) {
182
+ return new MetadataError(`Duplicate fieldNames are not allowed: ${names.map(n => `${className}.${n[0]} (fieldName: '${n[1]}')`).join(', ')}`);
183
+ }
184
+ static multipleDecorators(entityName, propertyName) {
185
+ return new MetadataError(`Multiple property decorators used on '${entityName}.${propertyName}' property`);
186
+ }
187
+ static missingMetadata(entity) {
188
+ return new MetadataError(`Metadata for entity ${entity} not found`);
189
+ }
190
+ static invalidPrimaryKey(meta, prop, requiredName) {
191
+ return this.fromMessage(meta, prop, `has wrong field name, '${requiredName}' is required in current driver`);
192
+ }
193
+ static invalidManyToManyWithPivotEntity(meta1, prop1, meta2, prop2) {
194
+ const p1 = `${meta1.className}.${prop1.name}`;
195
+ const p2 = `${meta2.className}.${prop2.name}`;
196
+ return new MetadataError(`${p1} and ${p2} use the same 'pivotEntity', but don't form a bidirectional relation. Specify 'inversedBy' or 'mappedBy' to link them.`);
197
+ }
198
+ static targetIsAbstract(meta, prop) {
199
+ return this.fromMessage(meta, prop, `targets abstract entity ${prop.type}. Maybe you forgot to put @Entity() decorator on the ${prop.type} class?`);
200
+ }
201
+ static propertyTargetsEntityType(meta, prop, target) {
202
+ /* istanbul ignore next */
203
+ const suggestion = target.embeddable ? 'Embedded' : 'ManyToOne';
204
+ return this.fromMessage(meta, prop, `is defined as scalar @Property(), but its type is a discovered entity ${target.className}. Maybe you want to use @${suggestion}() decorator instead?`);
205
+ }
206
+ static fromMissingOption(meta, prop, option) {
207
+ return this.fromMessage(meta, prop, `is missing '${option}' option`);
208
+ }
209
+ static fromMessage(meta, prop, message) {
210
+ return new MetadataError(`${meta.className}.${prop.name} ${message}`);
211
+ }
212
+ }
213
+ exports.MetadataError = MetadataError;
214
+ class NotFoundError extends ValidationError {
215
+ static findOneFailed(name, where) {
216
+ return new NotFoundError(`${name} not found (${(0, util_1.inspect)(where)})`);
217
+ }
218
+ static findExactlyOneFailed(name, where) {
219
+ return new NotFoundError(`Wrong number of ${name} entities found for query ${(0, util_1.inspect)(where)}, expected exactly one`);
220
+ }
221
+ }
222
+ exports.NotFoundError = NotFoundError;
@@ -0,0 +1,17 @@
1
+ import type { EntityMetadata } from '../typings';
2
+ import type { EventArgs, EventSubscriber, FlushEventArgs, TransactionEventArgs } from './EventSubscriber';
3
+ import { EventType, type TransactionEventType } from '../enums';
4
+ export declare class EventManager {
5
+ private readonly listeners;
6
+ private readonly entities;
7
+ private readonly cache;
8
+ private readonly subscribers;
9
+ constructor(subscribers: EventSubscriber[]);
10
+ registerSubscriber(subscriber: EventSubscriber): void;
11
+ dispatchEvent<T extends object>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
12
+ dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
13
+ dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;
14
+ hasListeners<T>(event: EventType, meta: EntityMetadata<T>): boolean;
15
+ clone(): EventManager;
16
+ private getSubscribedEntities;
17
+ }