@mikro-orm/core 7.0.0-dev.7 → 7.0.0-dev.71

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