@mikro-orm/core 7.0.0-dev.12 → 7.0.0-dev.121

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