@mikro-orm/core 7.0.0-dev.8 → 7.0.0-dev.81

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 (181) hide show
  1. package/EntityManager.d.ts +85 -48
  2. package/EntityManager.js +300 -225
  3. package/MikroORM.d.ts +40 -31
  4. package/MikroORM.js +98 -137
  5. package/README.md +3 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +6 -5
  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 +11 -7
  13. package/connections/Connection.js +16 -14
  14. package/drivers/DatabaseDriver.d.ts +11 -5
  15. package/drivers/DatabaseDriver.js +23 -11
  16. package/drivers/IDatabaseDriver.d.ts +27 -5
  17. package/entity/BaseEntity.d.ts +0 -1
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +98 -30
  20. package/entity/Collection.js +432 -93
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +15 -7
  23. package/entity/EntityFactory.d.ts +7 -0
  24. package/entity/EntityFactory.js +64 -41
  25. package/entity/EntityHelper.js +26 -9
  26. package/entity/EntityLoader.d.ts +5 -4
  27. package/entity/EntityLoader.js +73 -40
  28. package/entity/EntityRepository.d.ts +1 -1
  29. package/entity/Reference.d.ts +9 -7
  30. package/entity/Reference.js +33 -6
  31. package/entity/WrappedEntity.d.ts +2 -4
  32. package/entity/WrappedEntity.js +1 -5
  33. package/entity/defineEntity.d.ts +549 -0
  34. package/entity/defineEntity.js +529 -0
  35. package/entity/index.d.ts +3 -2
  36. package/entity/index.js +3 -2
  37. package/entity/utils.d.ts +7 -0
  38. package/entity/utils.js +16 -4
  39. package/entity/validators.d.ts +11 -0
  40. package/entity/validators.js +65 -0
  41. package/enums.d.ts +21 -6
  42. package/enums.js +14 -1
  43. package/errors.d.ts +6 -2
  44. package/errors.js +14 -9
  45. package/events/EventSubscriber.d.ts +3 -1
  46. package/hydration/Hydrator.js +1 -2
  47. package/hydration/ObjectHydrator.d.ts +4 -4
  48. package/hydration/ObjectHydrator.js +36 -25
  49. package/index.d.ts +2 -2
  50. package/index.js +1 -2
  51. package/logging/DefaultLogger.d.ts +1 -1
  52. package/logging/SimpleLogger.d.ts +1 -1
  53. package/metadata/EntitySchema.d.ts +9 -13
  54. package/metadata/EntitySchema.js +44 -26
  55. package/metadata/MetadataDiscovery.d.ts +6 -9
  56. package/metadata/MetadataDiscovery.js +167 -206
  57. package/metadata/MetadataProvider.d.ts +11 -2
  58. package/metadata/MetadataProvider.js +44 -2
  59. package/metadata/MetadataStorage.d.ts +1 -6
  60. package/metadata/MetadataStorage.js +6 -18
  61. package/metadata/MetadataValidator.d.ts +0 -7
  62. package/metadata/MetadataValidator.js +4 -13
  63. package/metadata/discover-entities.d.ts +5 -0
  64. package/metadata/discover-entities.js +40 -0
  65. package/metadata/index.d.ts +1 -1
  66. package/metadata/index.js +1 -1
  67. package/metadata/types.d.ts +480 -0
  68. package/metadata/types.js +1 -0
  69. package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
  70. package/naming-strategy/AbstractNamingStrategy.js +8 -2
  71. package/naming-strategy/NamingStrategy.d.ts +11 -1
  72. package/not-supported.d.ts +2 -0
  73. package/not-supported.js +4 -0
  74. package/package.json +18 -10
  75. package/platforms/ExceptionConverter.js +1 -1
  76. package/platforms/Platform.d.ts +6 -10
  77. package/platforms/Platform.js +14 -39
  78. package/serialization/EntitySerializer.d.ts +2 -0
  79. package/serialization/EntitySerializer.js +32 -14
  80. package/serialization/EntityTransformer.js +22 -12
  81. package/serialization/SerializationContext.js +16 -13
  82. package/types/ArrayType.d.ts +1 -1
  83. package/types/ArrayType.js +2 -3
  84. package/types/BigIntType.d.ts +8 -6
  85. package/types/BigIntType.js +1 -1
  86. package/types/BlobType.d.ts +0 -1
  87. package/types/BlobType.js +0 -3
  88. package/types/BooleanType.d.ts +2 -1
  89. package/types/BooleanType.js +3 -0
  90. package/types/DecimalType.d.ts +6 -4
  91. package/types/DecimalType.js +3 -3
  92. package/types/DoubleType.js +2 -2
  93. package/types/JsonType.d.ts +1 -1
  94. package/types/JsonType.js +7 -2
  95. package/types/TinyIntType.js +1 -1
  96. package/types/Type.d.ts +2 -1
  97. package/types/Type.js +1 -1
  98. package/types/Uint8ArrayType.d.ts +0 -1
  99. package/types/Uint8ArrayType.js +1 -4
  100. package/types/index.d.ts +1 -1
  101. package/typings.d.ts +113 -77
  102. package/typings.js +41 -35
  103. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  104. package/unit-of-work/ChangeSetComputer.js +11 -9
  105. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  106. package/unit-of-work/ChangeSetPersister.js +58 -20
  107. package/unit-of-work/UnitOfWork.d.ts +8 -1
  108. package/unit-of-work/UnitOfWork.js +115 -57
  109. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  110. package/utils/AbstractSchemaGenerator.js +11 -9
  111. package/utils/Configuration.d.ts +757 -206
  112. package/utils/Configuration.js +139 -187
  113. package/utils/ConfigurationLoader.d.ts +1 -54
  114. package/utils/ConfigurationLoader.js +1 -352
  115. package/utils/Cursor.d.ts +3 -3
  116. package/utils/Cursor.js +4 -1
  117. package/utils/DataloaderUtils.d.ts +15 -5
  118. package/utils/DataloaderUtils.js +54 -8
  119. package/utils/EntityComparator.d.ts +8 -4
  120. package/utils/EntityComparator.js +111 -64
  121. package/utils/QueryHelper.d.ts +9 -1
  122. package/utils/QueryHelper.js +70 -9
  123. package/utils/RawQueryFragment.d.ts +36 -4
  124. package/utils/RawQueryFragment.js +35 -14
  125. package/utils/TransactionManager.d.ts +65 -0
  126. package/utils/TransactionManager.js +223 -0
  127. package/utils/Utils.d.ts +8 -97
  128. package/utils/Utils.js +88 -303
  129. package/utils/clone.js +2 -3
  130. package/utils/env-vars.d.ts +3 -0
  131. package/utils/env-vars.js +87 -0
  132. package/utils/fs-utils.d.ts +12 -0
  133. package/utils/fs-utils.js +96 -0
  134. package/utils/index.d.ts +2 -1
  135. package/utils/index.js +2 -1
  136. package/utils/upsert-utils.d.ts +7 -2
  137. package/utils/upsert-utils.js +55 -4
  138. package/decorators/Check.d.ts +0 -3
  139. package/decorators/Check.js +0 -13
  140. package/decorators/CreateRequestContext.d.ts +0 -3
  141. package/decorators/CreateRequestContext.js +0 -32
  142. package/decorators/Embeddable.d.ts +0 -8
  143. package/decorators/Embeddable.js +0 -11
  144. package/decorators/Embedded.d.ts +0 -18
  145. package/decorators/Embedded.js +0 -18
  146. package/decorators/Entity.d.ts +0 -18
  147. package/decorators/Entity.js +0 -12
  148. package/decorators/Enum.d.ts +0 -9
  149. package/decorators/Enum.js +0 -16
  150. package/decorators/Filter.d.ts +0 -2
  151. package/decorators/Filter.js +0 -8
  152. package/decorators/Formula.d.ts +0 -4
  153. package/decorators/Formula.js +0 -15
  154. package/decorators/Indexed.d.ts +0 -19
  155. package/decorators/Indexed.js +0 -20
  156. package/decorators/ManyToMany.d.ts +0 -40
  157. package/decorators/ManyToMany.js +0 -14
  158. package/decorators/ManyToOne.d.ts +0 -30
  159. package/decorators/ManyToOne.js +0 -14
  160. package/decorators/OneToMany.d.ts +0 -28
  161. package/decorators/OneToMany.js +0 -17
  162. package/decorators/OneToOne.d.ts +0 -24
  163. package/decorators/OneToOne.js +0 -7
  164. package/decorators/PrimaryKey.d.ts +0 -8
  165. package/decorators/PrimaryKey.js +0 -20
  166. package/decorators/Property.d.ts +0 -250
  167. package/decorators/Property.js +0 -32
  168. package/decorators/Transactional.d.ts +0 -13
  169. package/decorators/Transactional.js +0 -28
  170. package/decorators/hooks.d.ts +0 -16
  171. package/decorators/hooks.js +0 -47
  172. package/decorators/index.d.ts +0 -17
  173. package/decorators/index.js +0 -17
  174. package/entity/ArrayCollection.d.ts +0 -116
  175. package/entity/ArrayCollection.js +0 -402
  176. package/entity/EntityValidator.d.ts +0 -19
  177. package/entity/EntityValidator.js +0 -150
  178. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  179. package/metadata/ReflectMetadataProvider.js +0 -44
  180. package/utils/resolveContextProvider.d.ts +0 -10
  181. package/utils/resolveContextProvider.js +0 -28
@@ -34,29 +34,13 @@ export class EntitySchema {
34
34
  return schema;
35
35
  }
36
36
  addProperty(name, type, options = {}) {
37
- const rename = (data, from, to) => {
38
- if (from in options && !(to in options)) {
39
- // @ts-ignore
40
- options[to] = [options[from]];
41
- // @ts-ignore
42
- delete options[from];
43
- }
44
- };
45
- if (name !== options.name) {
46
- Utils.renameKey(options, 'name', 'fieldName');
47
- }
48
- rename(options, 'fieldName', 'fieldNames');
49
- rename(options, 'ref', 'ref');
50
- rename(options, 'joinColumn', 'joinColumns');
51
- rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
52
- rename(options, 'referenceColumnName', 'referencedColumnNames');
53
- rename(options, 'columnType', 'columnTypes');
37
+ this.renameCompositeOptions(name, options);
54
38
  const prop = { name, kind: ReferenceKind.SCALAR, ...options, type: this.normalizeType(options, type) };
55
39
  if (type && Type.isMappedType(type.prototype)) {
56
40
  prop.type = type;
57
41
  }
58
- if (Utils.isString(prop.formula)) {
59
- const formula = prop.formula; // tmp var is needed here
42
+ if (typeof prop.formula === 'string') {
43
+ const formula = prop.formula;
60
44
  prop.formula = () => formula;
61
45
  }
62
46
  if (prop.formula) {
@@ -91,9 +75,10 @@ export class EntitySchema {
91
75
  }
92
76
  addSerializedPrimaryKey(name, type, options = {}) {
93
77
  this._meta.serializedPrimaryKey = name;
94
- this.addProperty(name, type, options);
78
+ this.addProperty(name, type, { serializedPrimaryKey: true, ...options });
95
79
  }
96
80
  addEmbedded(name, options) {
81
+ this.renameCompositeOptions(name, options);
97
82
  Utils.defaultValue(options, 'prefix', true);
98
83
  if (options.array) {
99
84
  options.object = true; // force object mode for arrays
@@ -114,6 +99,8 @@ export class EntitySchema {
114
99
  if (prop.fieldNames && !prop.joinColumns) {
115
100
  prop.joinColumns = prop.fieldNames;
116
101
  }
102
+ // By default, the foreign key constraint is created on the relation
103
+ Utils.defaultValue(prop, 'createForeignKeyConstraint', true);
117
104
  this.addProperty(name, type, prop);
118
105
  }
119
106
  addManyToMany(name, type, options) {
@@ -123,6 +110,8 @@ export class EntitySchema {
123
110
  }
124
111
  if (options.owner) {
125
112
  Utils.renameKey(options, 'mappedBy', 'inversedBy');
113
+ // By default, the foreign key constraint is created on the relation
114
+ Utils.defaultValue(options, 'createForeignKeyConstraint', true);
126
115
  }
127
116
  const prop = this.createProperty(ReferenceKind.MANY_TO_MANY, options);
128
117
  this.addProperty(name, type, prop);
@@ -135,8 +124,12 @@ export class EntitySchema {
135
124
  const prop = this.createProperty(ReferenceKind.ONE_TO_ONE, options);
136
125
  Utils.defaultValue(prop, 'owner', !!prop.inversedBy || !prop.mappedBy);
137
126
  Utils.defaultValue(prop, 'unique', prop.owner);
138
- if (prop.owner && options.mappedBy) {
139
- Utils.renameKey(prop, 'mappedBy', 'inversedBy');
127
+ if (prop.owner) {
128
+ if (options.mappedBy) {
129
+ Utils.renameKey(prop, 'mappedBy', 'inversedBy');
130
+ }
131
+ // By default, the foreign key constraint is created on the relation
132
+ Utils.defaultValue(prop, 'createForeignKeyConstraint', true);
140
133
  }
141
134
  if (prop.joinColumns && !prop.fieldNames) {
142
135
  prop.fieldNames = prop.joinColumns;
@@ -164,9 +157,7 @@ export class EntitySchema {
164
157
  this._meta.prototype = proto.prototype;
165
158
  this._meta.className = proto.name;
166
159
  if (!sameClass || !this._meta.constructorParams) {
167
- const tokens = Utils.tokenize(proto);
168
- this._meta.constructorParams = Utils.getParamNames(tokens, 'constructor');
169
- this._meta.toJsonParams = Utils.getParamNames(tokens, 'toJSON').filter(p => p !== '...args');
160
+ this._meta.constructorParams = Utils.getConstructorParams(proto);
170
161
  }
171
162
  if (!this.internal) {
172
163
  EntitySchema.REGISTRY.set(proto, this);
@@ -181,6 +172,12 @@ export class EntitySchema {
181
172
  get name() {
182
173
  return this._meta.className;
183
174
  }
175
+ get tableName() {
176
+ return this._meta.tableName;
177
+ }
178
+ get properties() {
179
+ return this._meta.properties;
180
+ }
184
181
  /**
185
182
  * @internal
186
183
  */
@@ -266,7 +263,7 @@ export class EntitySchema {
266
263
  }
267
264
  normalizeType(options, type) {
268
265
  if ('entity' in options) {
269
- if (Utils.isString(options.entity)) {
266
+ if (typeof options.entity === 'string') {
270
267
  type = options.type = options.entity;
271
268
  }
272
269
  else if (options.entity) {
@@ -289,4 +286,25 @@ export class EntitySchema {
289
286
  ...options,
290
287
  };
291
288
  }
289
+ rename(data, from, to) {
290
+ if (from in data && !(to in data)) {
291
+ // @ts-ignore
292
+ data[to] = [data[from]];
293
+ // @ts-ignore
294
+ delete data[from];
295
+ }
296
+ }
297
+ renameCompositeOptions(name, options = {}) {
298
+ if (name !== options.name && !options.fieldNames) {
299
+ Utils.renameKey(options, 'name', 'fieldName');
300
+ }
301
+ else if (options.name && (options.fieldNames?.length ?? 0) > 1) {
302
+ delete options.name;
303
+ }
304
+ this.rename(options, 'fieldName', 'fieldNames');
305
+ this.rename(options, 'joinColumn', 'joinColumns');
306
+ this.rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
307
+ this.rename(options, 'referenceColumnName', 'referencedColumnNames');
308
+ this.rename(options, 'columnType', 'columnTypes');
309
+ }
292
310
  }
@@ -1,4 +1,4 @@
1
- import { type Constructor, EntityMetadata } from '../typings.js';
1
+ import { type EntityClass, EntityMetadata } from '../typings.js';
2
2
  import type { Configuration } from '../utils/Configuration.js';
3
3
  import { MetadataStorage } from './MetadataStorage.js';
4
4
  import { EntitySchema } from './EntitySchema.js';
@@ -9,26 +9,25 @@ export declare class MetadataDiscovery {
9
9
  private readonly config;
10
10
  private readonly namingStrategy;
11
11
  private readonly metadataProvider;
12
- private readonly cache;
13
12
  private readonly logger;
14
13
  private readonly schemaHelper;
15
14
  private readonly validator;
16
15
  private readonly discovered;
17
16
  constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
18
17
  discover(preferTs?: boolean): Promise<MetadataStorage>;
19
- discoverSync(preferTs?: boolean): MetadataStorage;
18
+ discoverSync(): MetadataStorage;
19
+ validateDiscovered(metadata: EntityMetadata[]): void;
20
20
  private mapDiscoveredEntities;
21
+ private initAccessors;
21
22
  processDiscoveredEntities(discovered: EntityMetadata[]): EntityMetadata[];
22
23
  private findEntities;
23
24
  private discoverMissingTargets;
24
25
  private tryDiscoverTargets;
25
- private discoverDirectories;
26
- discoverReferences<T>(refs: (Constructor<T> | EntitySchema<T>)[]): EntityMetadata<T>[];
26
+ discoverReferences<T>(refs: Iterable<EntityClass<T> | EntitySchema<T>>, validate?: boolean): EntityMetadata<T>[];
27
27
  reset(className: string): void;
28
- private prepare;
29
28
  private getSchema;
29
+ private getRootEntity;
30
30
  private discoverEntity;
31
- private saveToCache;
32
31
  private initNullability;
33
32
  private applyNamingStrategy;
34
33
  private initOwnColumns;
@@ -54,7 +53,6 @@ export declare class MetadataDiscovery {
54
53
  private initAutoincrement;
55
54
  private initCheckConstraints;
56
55
  private initGeneratedColumn;
57
- private createColumnMappingObject;
58
56
  private getDefaultVersionValue;
59
57
  private inferDefaultValue;
60
58
  private initDefaultValue;
@@ -67,6 +65,5 @@ export declare class MetadataDiscovery {
67
65
  private getPrefix;
68
66
  private initUnsigned;
69
67
  private initIndexes;
70
- private getEntityClassOrSchema;
71
68
  private shouldForceConstructorUsage;
72
69
  }