@mikro-orm/core 6.3.5-dev.0 → 6.3.5-dev.10

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.
@@ -132,11 +132,35 @@ export declare class EntityRepository<Entity extends object> {
132
132
  */
133
133
  populate<Ent extends Entity | Entity[], Hint extends string = never, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Fields extends string = '*', Excludes extends string = never>(entities: Ent, populate: AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Ent extends object[] ? MergeLoaded<ArrayElement<Ent>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Ent, Naked, Hint, Fields, Excludes>>;
134
134
  /**
135
- * @inheritDoc EntityManager.create
135
+ * Creates new instance of given entity and populates it with given data.
136
+ * The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
137
+ * The constructor will be given parameters based on the defined constructor of the entity. If the constructor
138
+ * parameter matches a property name, its value will be extracted from `data`. If no matching property exists,
139
+ * the whole `data` parameter will be passed. This means we can also define `constructor(data: Partial<T>)` and
140
+ * `em.create()` will pass the data into it (unless we have a property named `data` too).
141
+ *
142
+ * The parameters are strictly checked, you need to provide all required properties. You can use `OptionalProps`
143
+ * symbol to omit some properties from this check without making them optional. Alternatively, use `partial: true`
144
+ * in the options to disable the strict checks for required properties. This option has no effect on runtime.
145
+ *
146
+ * The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
147
+ * behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
136
148
  */
137
149
  create<Convert extends boolean = false>(data: RequiredEntityData<Entity, never, Convert>, options?: CreateOptions<Convert>): Entity;
138
150
  /**
139
- * @inheritDoc EntityManager.create
151
+ * Creates new instance of given entity and populates it with given data.
152
+ * The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
153
+ * The constructor will be given parameters based on the defined constructor of the entity. If the constructor
154
+ * parameter matches a property name, its value will be extracted from `data`. If no matching property exists,
155
+ * the whole `data` parameter will be passed. This means we can also define `constructor(data: Partial<T>)` and
156
+ * `em.create()` will pass the data into it (unless we have a property named `data` too).
157
+ *
158
+ * The parameters are strictly checked, you need to provide all required properties. You can use `OptionalProps`
159
+ * symbol to omit some properties from this check without making them optional. Alternatively, use `partial: true`
160
+ * in the options to disable the strict checks for required properties. This option has no effect on runtime.
161
+ *
162
+ * The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
163
+ * behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
140
164
  */
141
165
  create<Convert extends boolean = false>(data: EntityData<Entity, Convert>, options: CreateOptions<Convert> & {
142
166
  partial: true;
@@ -153,7 +153,19 @@ class EntityRepository {
153
153
  return this.getEntityManager().populate(entities, populate, options);
154
154
  }
155
155
  /**
156
- * @inheritDoc EntityManager.create
156
+ * Creates new instance of given entity and populates it with given data.
157
+ * The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
158
+ * The constructor will be given parameters based on the defined constructor of the entity. If the constructor
159
+ * parameter matches a property name, its value will be extracted from `data`. If no matching property exists,
160
+ * the whole `data` parameter will be passed. This means we can also define `constructor(data: Partial<T>)` and
161
+ * `em.create()` will pass the data into it (unless we have a property named `data` too).
162
+ *
163
+ * The parameters are strictly checked, you need to provide all required properties. You can use `OptionalProps`
164
+ * symbol to omit some properties from this check without making them optional. Alternatively, use `partial: true`
165
+ * in the options to disable the strict checks for required properties. This option has no effect on runtime.
166
+ *
167
+ * The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
168
+ * behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
157
169
  */
158
170
  create(data, options) {
159
171
  return this.getEntityManager().create(this.entityName, data, options);
@@ -77,7 +77,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
77
77
  else if (prop.runtimeType === 'boolean') {
78
78
  ret.push(` entity${entityKey} = !!data${dataKey};`);
79
79
  }
80
- else if (prop.runtimeType === 'Date') {
80
+ else if (prop.runtimeType === 'Date' && !this.platform.isNumericProperty(prop)) {
81
81
  ret.push(` if (data${dataKey} instanceof Date) {`);
82
82
  ret.push(` entity${entityKey} = data${dataKey};`);
83
83
  if (!tz || tz === 'local') {
@@ -64,7 +64,6 @@ export declare class MetadataDiscovery {
64
64
  private getMappedType;
65
65
  private initUnsigned;
66
66
  private initIndexes;
67
- private isNumericProperty;
68
67
  private getEntityClassOrSchema;
69
68
  private shouldForceConstructorUsage;
70
69
  }
@@ -920,7 +920,7 @@ class MetadataDiscovery {
920
920
  }
921
921
  initAutoincrement(meta) {
922
922
  const pks = meta.getPrimaryProps();
923
- if (pks.length === 1 && this.isNumericProperty(pks[0])) {
923
+ if (pks.length === 1 && this.platform.isNumericProperty(pks[0])) {
924
924
  /* istanbul ignore next */
925
925
  pks[0].autoincrement ??= true;
926
926
  }
@@ -1226,7 +1226,7 @@ class MetadataDiscovery {
1226
1226
  });
1227
1227
  return;
1228
1228
  }
1229
- prop.unsigned ??= (prop.primary || prop.unsigned) && this.isNumericProperty(prop) && this.platform.supportsUnsigned();
1229
+ prop.unsigned ??= (prop.primary || prop.unsigned) && this.platform.isNumericProperty(prop) && this.platform.supportsUnsigned();
1230
1230
  }
1231
1231
  initIndexes(meta, prop) {
1232
1232
  const hasIndex = meta.indexes.some(idx => idx.properties?.length === 1 && idx.properties[0] === prop.name);
@@ -1234,13 +1234,6 @@ class MetadataDiscovery {
1234
1234
  prop.index ??= true;
1235
1235
  }
1236
1236
  }
1237
- isNumericProperty(prop) {
1238
- if (prop.customType) {
1239
- return this.platform.isNumericColumn(prop.customType);
1240
- }
1241
- const numericMappedType = prop.columnTypes?.[0] && this.platform.isNumericColumn(this.platform.getMappedType(prop.columnTypes[0]));
1242
- return numericMappedType || prop.type === 'number' || this.platform.isBigIntProperty(prop);
1243
- }
1244
1237
  async getEntityClassOrSchema(path, name) {
1245
1238
  const exports = await Utils_1.Utils.dynamicImport(path);
1246
1239
  const targets = Object.values(exports)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.3.5-dev.0",
3
+ "version": "6.3.5-dev.10",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.2.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.3.5-dev.0",
67
+ "mikro-orm": "6.3.5-dev.10",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -172,6 +172,7 @@ export declare abstract class Platform {
172
172
  setConfig(config: Configuration): void;
173
173
  getConfig(): Configuration;
174
174
  getTimezone(): string | undefined;
175
+ isNumericProperty(prop: EntityProperty, ignoreCustomType?: boolean): boolean;
175
176
  isNumericColumn(mappedType: Type<unknown>): boolean;
176
177
  supportsUnsigned(): boolean;
177
178
  /**
@@ -300,6 +300,7 @@ class Platform {
300
300
  }
301
301
  parseDate(value) {
302
302
  const date = new Date(value);
303
+ /* istanbul ignore next */
303
304
  if (isNaN(date.getTime())) {
304
305
  return value;
305
306
  }
@@ -415,6 +416,10 @@ class Platform {
415
416
  getTimezone() {
416
417
  return this.timezone;
417
418
  }
419
+ isNumericProperty(prop, ignoreCustomType = false) {
420
+ const numericMappedType = prop.columnTypes?.[0] && this.isNumericColumn(this.getMappedType(prop.columnTypes[0]));
421
+ return numericMappedType || prop.type === 'number' || this.isBigIntProperty(prop);
422
+ }
418
423
  isNumericColumn(mappedType) {
419
424
  return [types_1.IntegerType, types_1.SmallIntType, types_1.BigIntType, types_1.TinyIntType].some(t => mappedType instanceof t);
420
425
  }
@@ -72,7 +72,6 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
72
72
  persistOnCreate: true;
73
73
  forceEntityConstructor: false;
74
74
  forceUndefined: false;
75
- forceUtcTimezone: false;
76
75
  ensureDatabase: true;
77
76
  ensureIndexes: false;
78
77
  batchSize: number;
@@ -330,7 +329,7 @@ export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM
330
329
  persistOnCreate: boolean;
331
330
  forceEntityConstructor: boolean | (Constructor<AnyEntity> | string)[];
332
331
  forceUndefined: boolean;
333
- forceUtcTimezone: boolean;
332
+ forceUtcTimezone?: boolean;
334
333
  timezone?: string;
335
334
  ensureDatabase: boolean | EnsureDatabaseOptions;
336
335
  ensureIndexes: boolean;
@@ -67,7 +67,6 @@ class Configuration {
67
67
  persistOnCreate: true,
68
68
  forceEntityConstructor: false,
69
69
  forceUndefined: false,
70
- forceUtcTimezone: false,
71
70
  ensureDatabase: true,
72
71
  ensureIndexes: false,
73
72
  batchSize: 300,
@@ -214,6 +213,7 @@ class Configuration {
214
213
  this.cache.set(name, ext());
215
214
  return this.cache.get(name);
216
215
  }
216
+ /* istanbul ignore next */
217
217
  return undefined;
218
218
  }
219
219
  /**
@@ -300,7 +300,7 @@ class EntityComparator {
300
300
  lines.push(` ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
301
301
  lines.push(` }`);
302
302
  }
303
- else if (prop.runtimeType === 'Date') {
303
+ else if (prop.runtimeType === 'Date' && !this.platform.isNumericProperty(prop)) {
304
304
  lines.push(` if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
305
305
  context.set('parseDate', (value) => this.platform.parseDate(value));
306
306
  parseDate('ret' + this.wrap(prop.name), this.propName(prop.fieldNames[0]));
@@ -16,8 +16,15 @@ export declare class RequestContext {
16
16
  /**
17
17
  * Creates new RequestContext instance and runs the code inside its domain.
18
18
  * If the handler is async, the return value needs to be awaited.
19
+ * Uses `AsyncLocalStorage.run()`, suitable for regular express style middlewares with a `next` callback.
19
20
  */
20
21
  static create<T>(em: EntityManager | EntityManager[], next: (...args: any[]) => T, options?: CreateContextOptions): T;
22
+ /**
23
+ * Creates new RequestContext instance and runs the code inside its domain.
24
+ * If the handler is async, the return value needs to be awaited.
25
+ * Uses `AsyncLocalStorage.enterWith()`, suitable for elysia style middlewares without a `next` callback.
26
+ */
27
+ static enter(em: EntityManager | EntityManager[], options?: CreateContextOptions): void;
21
28
  /**
22
29
  * Returns current RequestContext (if available).
23
30
  */
@@ -22,11 +22,21 @@ class RequestContext {
22
22
  /**
23
23
  * Creates new RequestContext instance and runs the code inside its domain.
24
24
  * If the handler is async, the return value needs to be awaited.
25
+ * Uses `AsyncLocalStorage.run()`, suitable for regular express style middlewares with a `next` callback.
25
26
  */
26
27
  static create(em, next, options = {}) {
27
28
  const ctx = this.createContext(em, options);
28
29
  return this.storage.run(ctx, next);
29
30
  }
31
+ /**
32
+ * Creates new RequestContext instance and runs the code inside its domain.
33
+ * If the handler is async, the return value needs to be awaited.
34
+ * Uses `AsyncLocalStorage.enterWith()`, suitable for elysia style middlewares without a `next` callback.
35
+ */
36
+ static enter(em, options = {}) {
37
+ const ctx = this.createContext(em, options);
38
+ this.storage.enterWith(ctx);
39
+ }
30
40
  /**
31
41
  * Returns current RequestContext (if available).
32
42
  */
package/utils/Utils.js CHANGED
@@ -46,7 +46,8 @@ function compareObjects(a, b) {
46
46
  return false;
47
47
  }
48
48
  if (isRawSql(a) && isRawSql(b)) {
49
- return false;
49
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
50
+ return a.sql === b.sql && compareArrays(a.params, b.params);
50
51
  }
51
52
  if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf === 'function' && typeof b.valueOf === 'function') {
52
53
  return a.valueOf() === b.valueOf();