@mikro-orm/core 7.0.0-dev.23 → 7.0.0-dev.231

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 (209) hide show
  1. package/EntityManager.d.ts +91 -59
  2. package/EntityManager.js +303 -251
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -143
  5. package/README.md +2 -0
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +17 -8
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +0 -1
  11. package/cache/index.js +0 -1
  12. package/connections/Connection.d.ts +12 -5
  13. package/connections/Connection.js +21 -12
  14. package/drivers/DatabaseDriver.d.ts +25 -16
  15. package/drivers/DatabaseDriver.js +118 -35
  16. package/drivers/IDatabaseDriver.d.ts +42 -19
  17. package/entity/BaseEntity.d.ts +61 -2
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +101 -29
  20. package/entity/Collection.js +436 -104
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +26 -18
  23. package/entity/EntityFactory.d.ts +7 -1
  24. package/entity/EntityFactory.js +83 -54
  25. package/entity/EntityHelper.d.ts +2 -2
  26. package/entity/EntityHelper.js +48 -15
  27. package/entity/EntityLoader.d.ts +7 -6
  28. package/entity/EntityLoader.js +221 -93
  29. package/entity/EntityRepository.d.ts +27 -7
  30. package/entity/EntityRepository.js +8 -2
  31. package/entity/PolymorphicRef.d.ts +12 -0
  32. package/entity/PolymorphicRef.js +18 -0
  33. package/entity/Reference.d.ts +1 -5
  34. package/entity/Reference.js +21 -12
  35. package/entity/WrappedEntity.d.ts +0 -5
  36. package/entity/WrappedEntity.js +2 -7
  37. package/entity/defineEntity.d.ts +380 -310
  38. package/entity/defineEntity.js +124 -273
  39. package/entity/index.d.ts +2 -2
  40. package/entity/index.js +2 -2
  41. package/entity/utils.js +1 -1
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +65 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +2 -1
  46. package/errors.d.ts +20 -10
  47. package/errors.js +55 -23
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +19 -11
  50. package/hydration/Hydrator.js +1 -2
  51. package/hydration/ObjectHydrator.d.ts +4 -4
  52. package/hydration/ObjectHydrator.js +87 -35
  53. package/index.d.ts +2 -2
  54. package/index.js +1 -2
  55. package/logging/DefaultLogger.d.ts +1 -1
  56. package/logging/DefaultLogger.js +1 -0
  57. package/logging/SimpleLogger.d.ts +1 -1
  58. package/logging/colors.d.ts +1 -1
  59. package/logging/colors.js +7 -6
  60. package/logging/index.d.ts +1 -0
  61. package/logging/index.js +1 -0
  62. package/logging/inspect.d.ts +2 -0
  63. package/logging/inspect.js +11 -0
  64. package/metadata/EntitySchema.d.ts +47 -23
  65. package/metadata/EntitySchema.js +92 -33
  66. package/metadata/MetadataDiscovery.d.ts +64 -9
  67. package/metadata/MetadataDiscovery.js +778 -325
  68. package/metadata/MetadataProvider.d.ts +11 -2
  69. package/metadata/MetadataProvider.js +46 -2
  70. package/metadata/MetadataStorage.d.ts +13 -11
  71. package/metadata/MetadataStorage.js +70 -37
  72. package/metadata/MetadataValidator.d.ts +32 -9
  73. package/metadata/MetadataValidator.js +196 -41
  74. package/metadata/discover-entities.d.ts +5 -0
  75. package/metadata/discover-entities.js +40 -0
  76. package/metadata/index.d.ts +1 -1
  77. package/metadata/index.js +1 -1
  78. package/metadata/types.d.ts +526 -0
  79. package/metadata/types.js +1 -0
  80. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  81. package/naming-strategy/AbstractNamingStrategy.js +20 -2
  82. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  83. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  84. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  85. package/naming-strategy/MongoNamingStrategy.js +6 -6
  86. package/naming-strategy/NamingStrategy.d.ts +28 -4
  87. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  89. package/not-supported.d.ts +2 -0
  90. package/not-supported.js +4 -0
  91. package/package.json +19 -11
  92. package/platforms/ExceptionConverter.js +1 -1
  93. package/platforms/Platform.d.ts +7 -14
  94. package/platforms/Platform.js +20 -43
  95. package/serialization/EntitySerializer.d.ts +5 -0
  96. package/serialization/EntitySerializer.js +47 -27
  97. package/serialization/EntityTransformer.js +28 -18
  98. package/serialization/SerializationContext.d.ts +6 -6
  99. package/serialization/SerializationContext.js +3 -3
  100. package/types/ArrayType.d.ts +1 -1
  101. package/types/ArrayType.js +2 -3
  102. package/types/BigIntType.d.ts +8 -6
  103. package/types/BigIntType.js +1 -1
  104. package/types/BlobType.d.ts +0 -1
  105. package/types/BlobType.js +0 -3
  106. package/types/BooleanType.d.ts +1 -0
  107. package/types/BooleanType.js +3 -0
  108. package/types/DecimalType.d.ts +6 -4
  109. package/types/DecimalType.js +2 -2
  110. package/types/DoubleType.js +1 -1
  111. package/types/EnumArrayType.js +1 -2
  112. package/types/JsonType.d.ts +1 -1
  113. package/types/JsonType.js +7 -2
  114. package/types/TinyIntType.js +1 -1
  115. package/types/Type.d.ts +2 -4
  116. package/types/Type.js +3 -3
  117. package/types/Uint8ArrayType.d.ts +0 -1
  118. package/types/Uint8ArrayType.js +1 -4
  119. package/types/index.d.ts +1 -1
  120. package/typings.d.ts +381 -171
  121. package/typings.js +97 -44
  122. package/unit-of-work/ChangeSet.d.ts +4 -6
  123. package/unit-of-work/ChangeSet.js +4 -5
  124. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  125. package/unit-of-work/ChangeSetComputer.js +35 -14
  126. package/unit-of-work/ChangeSetPersister.d.ts +7 -3
  127. package/unit-of-work/ChangeSetPersister.js +83 -25
  128. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  129. package/unit-of-work/CommitOrderCalculator.js +13 -13
  130. package/unit-of-work/IdentityMap.d.ts +12 -0
  131. package/unit-of-work/IdentityMap.js +39 -1
  132. package/unit-of-work/UnitOfWork.d.ts +27 -3
  133. package/unit-of-work/UnitOfWork.js +258 -92
  134. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  135. package/utils/AbstractSchemaGenerator.js +28 -17
  136. package/utils/AsyncContext.d.ts +6 -0
  137. package/utils/AsyncContext.js +42 -0
  138. package/utils/Configuration.d.ts +795 -209
  139. package/utils/Configuration.js +150 -192
  140. package/utils/ConfigurationLoader.d.ts +1 -54
  141. package/utils/ConfigurationLoader.js +1 -352
  142. package/utils/Cursor.d.ts +0 -3
  143. package/utils/Cursor.js +24 -11
  144. package/utils/DataloaderUtils.d.ts +10 -5
  145. package/utils/DataloaderUtils.js +29 -12
  146. package/utils/EntityComparator.d.ts +16 -9
  147. package/utils/EntityComparator.js +158 -58
  148. package/utils/QueryHelper.d.ts +18 -6
  149. package/utils/QueryHelper.js +76 -23
  150. package/utils/RawQueryFragment.d.ts +28 -34
  151. package/utils/RawQueryFragment.js +35 -71
  152. package/utils/RequestContext.js +2 -2
  153. package/utils/TransactionContext.js +2 -2
  154. package/utils/TransactionManager.js +28 -4
  155. package/utils/Utils.d.ts +14 -127
  156. package/utils/Utils.js +85 -397
  157. package/utils/clone.js +8 -23
  158. package/utils/env-vars.d.ts +7 -0
  159. package/utils/env-vars.js +97 -0
  160. package/utils/fs-utils.d.ts +33 -0
  161. package/utils/fs-utils.js +192 -0
  162. package/utils/index.d.ts +1 -1
  163. package/utils/index.js +1 -1
  164. package/utils/upsert-utils.d.ts +9 -4
  165. package/utils/upsert-utils.js +46 -3
  166. package/decorators/Check.d.ts +0 -3
  167. package/decorators/Check.js +0 -13
  168. package/decorators/CreateRequestContext.d.ts +0 -3
  169. package/decorators/CreateRequestContext.js +0 -32
  170. package/decorators/Embeddable.d.ts +0 -8
  171. package/decorators/Embeddable.js +0 -11
  172. package/decorators/Embedded.d.ts +0 -12
  173. package/decorators/Embedded.js +0 -18
  174. package/decorators/Entity.d.ts +0 -33
  175. package/decorators/Entity.js +0 -12
  176. package/decorators/Enum.d.ts +0 -9
  177. package/decorators/Enum.js +0 -16
  178. package/decorators/Filter.d.ts +0 -2
  179. package/decorators/Filter.js +0 -8
  180. package/decorators/Formula.d.ts +0 -4
  181. package/decorators/Formula.js +0 -15
  182. package/decorators/Indexed.d.ts +0 -19
  183. package/decorators/Indexed.js +0 -20
  184. package/decorators/ManyToMany.d.ts +0 -42
  185. package/decorators/ManyToMany.js +0 -14
  186. package/decorators/ManyToOne.d.ts +0 -34
  187. package/decorators/ManyToOne.js +0 -14
  188. package/decorators/OneToMany.d.ts +0 -28
  189. package/decorators/OneToMany.js +0 -17
  190. package/decorators/OneToOne.d.ts +0 -28
  191. package/decorators/OneToOne.js +0 -7
  192. package/decorators/PrimaryKey.d.ts +0 -8
  193. package/decorators/PrimaryKey.js +0 -20
  194. package/decorators/Property.d.ts +0 -250
  195. package/decorators/Property.js +0 -32
  196. package/decorators/Transactional.d.ts +0 -14
  197. package/decorators/Transactional.js +0 -28
  198. package/decorators/hooks.d.ts +0 -16
  199. package/decorators/hooks.js +0 -47
  200. package/decorators/index.d.ts +0 -17
  201. package/decorators/index.js +0 -17
  202. package/entity/ArrayCollection.d.ts +0 -118
  203. package/entity/ArrayCollection.js +0 -407
  204. package/entity/EntityValidator.d.ts +0 -19
  205. package/entity/EntityValidator.js +0 -150
  206. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  207. package/metadata/ReflectMetadataProvider.js +0 -44
  208. package/utils/resolveContextProvider.d.ts +0 -10
  209. package/utils/resolveContextProvider.js +0 -28
@@ -1,5 +1,4 @@
1
- import type { EntityDTO, EntityKey, FilterQuery, Loaded, LoadedCollection, Populate } from '../typings.js';
2
- import { ArrayCollection } from './ArrayCollection.js';
1
+ import type { EntityDTO, EntityKey, EntityProperty, FilterQuery, IPrimaryKey, Loaded, LoadedCollection, Populate, Primary } from '../typings.js';
3
2
  import { Reference } from './Reference.js';
4
3
  import type { Transaction } from '../connections/Connection.js';
5
4
  import type { CountOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
@@ -9,10 +8,18 @@ export interface MatchingOptions<T extends object, P extends string = never> ext
9
8
  store?: boolean;
10
9
  ctx?: Transaction;
11
10
  }
12
- export declare class Collection<T extends object, O extends object = object> extends ArrayCollection<T, O> {
11
+ export declare class Collection<T extends object, O extends object = object> {
12
+ readonly owner: O;
13
+ [k: number]: T;
14
+ protected readonly items: Set<T>;
15
+ protected initialized: boolean;
16
+ protected dirty: boolean;
17
+ protected partial: boolean;
18
+ protected snapshot: T[] | undefined;
13
19
  private readonly?;
20
+ protected _count?: number;
21
+ private _property?;
14
22
  private _populated?;
15
- private _snapshot?;
16
23
  constructor(owner: O, items?: T[], initialized?: boolean);
17
24
  /**
18
25
  * Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
@@ -39,59 +46,124 @@ export declare class Collection<T extends object, O extends object = object> ext
39
46
  */
40
47
  getItems(check?: boolean): T[];
41
48
  toJSON<TT extends T>(): EntityDTO<TT>[];
42
- add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): void;
49
+ add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): number;
43
50
  /**
44
- * @inheritDoc
51
+ * Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
52
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
53
+ * is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
54
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
45
55
  */
46
- remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): void;
56
+ remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): number;
47
57
  contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
48
58
  count(): number;
49
59
  isEmpty(): boolean;
60
+ shouldPopulate(populated?: boolean): boolean;
61
+ populated(populated?: boolean | undefined): void;
62
+ init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
63
+ private getEntityManager;
64
+ private createCondition;
65
+ private createManyToManyCondition;
66
+ private createLoadCountCondition;
67
+ private checkInitialized;
50
68
  /**
51
- * @inheritDoc
69
+ * re-orders items after searching with `$in` operator
70
+ */
71
+ private reorderItems;
72
+ private cancelOrphanRemoval;
73
+ private validateModification;
74
+ toArray<TT extends T>(): EntityDTO<TT>[];
75
+ getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
76
+ /**
77
+ * @internal
78
+ */
79
+ addWithoutPropagation(entity: T): void;
80
+ set(items: Iterable<T | Reference<T>>): void;
81
+ private compare;
82
+ /**
83
+ * @internal
84
+ */
85
+ hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
86
+ /**
87
+ * Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
88
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
89
+ * is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
90
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
91
+ */
92
+ removeAll(): void;
93
+ /**
94
+ * @internal
95
+ */
96
+ removeWithoutPropagation(entity: T): void;
97
+ /**
98
+ * Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
99
+ * If end is null it returns all elements from start to the end of the collection.
52
100
  */
53
101
  slice(start?: number, end?: number): T[];
54
102
  /**
55
- * @inheritDoc
103
+ * Tests for the existence of an element that satisfies the given predicate.
56
104
  */
57
105
  exists(cb: (item: T) => boolean): boolean;
58
106
  /**
59
- * @inheritDoc
107
+ * Returns the first element of this collection that satisfies the predicate.
108
+ */
109
+ find<S extends T>(cb: (item: T, index: number) => item is S): S | undefined;
110
+ /**
111
+ * Returns the first element of this collection that satisfies the predicate.
60
112
  */
61
113
  find(cb: (item: T, index: number) => boolean): T | undefined;
62
114
  /**
63
- * @inheritDoc
115
+ * Extracts a subset of the collection items.
116
+ */
117
+ filter<S extends T>(cb: (item: T, index: number) => item is S): S[];
118
+ /**
119
+ * Extracts a subset of the collection items.
64
120
  */
65
121
  filter(cb: (item: T, index: number) => boolean): T[];
66
122
  /**
67
- * @inheritDoc
123
+ * Maps the collection items based on your provided mapper function.
68
124
  */
69
125
  map<R>(mapper: (item: T, index: number) => R): R[];
70
126
  /**
71
- * @inheritDoc
127
+ * Maps the collection items based on your provided mapper function to a single object.
128
+ */
129
+ reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
130
+ /**
131
+ * Maps the collection items to a dictionary, indexed by the key you specify.
132
+ * If there are more items with the same key, only the first one will be present.
72
133
  */
73
134
  indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
74
135
  /**
75
- * @inheritDoc
136
+ * Maps the collection items to a dictionary, indexed by the key you specify.
137
+ * If there are more items with the same key, only the first one will be present.
76
138
  */
77
139
  indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
78
- shouldPopulate(populated?: boolean): boolean;
79
- populated(populated?: boolean | undefined): void;
80
- init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
81
- private getEntityManager;
82
- private createCondition;
83
- private createOrderBy;
84
- private createManyToManyCondition;
85
- private createLoadCountCondition;
86
- private modify;
87
- private checkInitialized;
140
+ isInitialized(fully?: boolean): boolean;
141
+ isDirty(): boolean;
142
+ isPartial(): boolean;
143
+ setDirty(dirty?: boolean): void;
144
+ get length(): number;
145
+ [Symbol.iterator](): IterableIterator<T>;
88
146
  /**
89
- * re-orders items after searching with `$in` operator
147
+ * @internal
90
148
  */
91
- private reorderItems;
92
- private cancelOrphanRemoval;
93
- private validateItemType;
94
- private validateModification;
149
+ takeSnapshot(forcePropagate?: boolean): void;
150
+ /**
151
+ * @internal
152
+ */
153
+ getSnapshot(): T[] | undefined;
154
+ /**
155
+ * @internal
156
+ */
157
+ get property(): EntityProperty;
158
+ /**
159
+ * @internal
160
+ */
161
+ set property(prop: EntityProperty);
162
+ protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
163
+ protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
164
+ protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
165
+ protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
166
+ protected incrementCount(value: number): void;
95
167
  }
96
168
  export interface InitCollectionOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends EntityLoaderOptions<T, F, E> {
97
169
  dataloader?: boolean;