@mikro-orm/core 6.4.7-dev.1 → 7.0.0-dev.1

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 (40) hide show
  1. package/EntityManager.d.ts +3 -2
  2. package/EntityManager.js +119 -101
  3. package/MikroORM.d.ts +8 -8
  4. package/MikroORM.js +1 -1
  5. package/README.md +0 -2
  6. package/connections/Connection.d.ts +3 -7
  7. package/drivers/DatabaseDriver.js +2 -6
  8. package/entity/Collection.js +8 -8
  9. package/entity/Reference.js +5 -5
  10. package/events/EventManager.js +4 -4
  11. package/events/TransactionEventBroadcaster.d.ts +1 -5
  12. package/events/TransactionEventBroadcaster.js +6 -9
  13. package/index.mjs +2 -0
  14. package/logging/Logger.d.ts +1 -1
  15. package/metadata/MetadataDiscovery.js +12 -0
  16. package/naming-strategy/AbstractNamingStrategy.d.ts +1 -1
  17. package/naming-strategy/NamingStrategy.d.ts +1 -1
  18. package/package.json +3 -3
  19. package/platforms/Platform.d.ts +13 -4
  20. package/platforms/Platform.js +26 -6
  21. package/serialization/EntitySerializer.js +2 -1
  22. package/serialization/EntityTransformer.js +2 -1
  23. package/typings.d.ts +12 -4
  24. package/typings.js +23 -6
  25. package/unit-of-work/ChangeSetComputer.d.ts +1 -1
  26. package/unit-of-work/ChangeSetComputer.js +9 -9
  27. package/unit-of-work/ChangeSetPersister.d.ts +1 -1
  28. package/unit-of-work/ChangeSetPersister.js +19 -18
  29. package/unit-of-work/UnitOfWork.js +1 -1
  30. package/utils/AbstractSchemaGenerator.js +3 -1
  31. package/utils/Configuration.d.ts +6 -20
  32. package/utils/Configuration.js +11 -5
  33. package/utils/ConfigurationLoader.js +7 -8
  34. package/utils/DataloaderUtils.d.ts +0 -2
  35. package/utils/DataloaderUtils.js +0 -10
  36. package/utils/QueryHelper.js +5 -5
  37. package/utils/RawQueryFragment.d.ts +2 -0
  38. package/utils/RawQueryFragment.js +8 -2
  39. package/utils/Utils.d.ts +1 -1
  40. package/utils/Utils.js +1 -1
package/MikroORM.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import type { EntityManagerType, IDatabaseDriver } from './drivers';
2
- import { MetadataStorage, type EntitySchema } from './metadata';
2
+ import { type EntitySchema, MetadataStorage } from './metadata';
3
3
  import { Configuration, type Options } from './utils';
4
4
  import type { EntityManager } from './EntityManager';
5
5
  import type { Constructor, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager } from './typings';
6
6
  /**
7
7
  * Helper class for bootstrapping the MikroORM.
8
8
  */
9
- export declare class MikroORM<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager> {
9
+ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = Driver[typeof EntityManagerType] & EntityManager> {
10
10
  /** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
11
11
  em: EM;
12
- readonly config: Configuration<D>;
12
+ readonly driver: Driver;
13
+ readonly config: Configuration<Driver>;
13
14
  private metadata;
14
- private readonly driver;
15
15
  private readonly logger;
16
16
  private readonly discovery;
17
17
  /**
@@ -27,11 +27,11 @@ export declare class MikroORM<D extends IDatabaseDriver = IDatabaseDriver, EM ex
27
27
  * - no check for mismatched package versions
28
28
  */
29
29
  static initSync<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options: Options<D, EM>): MikroORM<D, EM>;
30
- constructor(options: Options<D, EM> | Configuration<D, EM>);
30
+ constructor(options: Options<Driver, EM> | Configuration<Driver, EM>);
31
31
  /**
32
32
  * Connects to the database.
33
33
  */
34
- connect(): Promise<D>;
34
+ connect(): Promise<Driver>;
35
35
  /**
36
36
  * Reconnects, possibly to a different database.
37
37
  */
@@ -72,7 +72,7 @@ export declare class MikroORM<D extends IDatabaseDriver = IDatabaseDriver, EM ex
72
72
  /**
73
73
  * Gets the SchemaGenerator.
74
74
  */
75
- getSchemaGenerator(): ReturnType<ReturnType<D['getPlatform']>['getSchemaGenerator']>;
75
+ getSchemaGenerator(): ReturnType<ReturnType<Driver['getPlatform']>['getSchemaGenerator']>;
76
76
  /**
77
77
  * Gets the EntityGenerator.
78
78
  */
@@ -88,7 +88,7 @@ export declare class MikroORM<D extends IDatabaseDriver = IDatabaseDriver, EM ex
88
88
  /**
89
89
  * Shortcut for `orm.getSchemaGenerator()`
90
90
  */
91
- get schema(): ReturnType<ReturnType<D["getPlatform"]>["getSchemaGenerator"]>;
91
+ get schema(): ReturnType<ReturnType<Driver["getPlatform"]>["getSchemaGenerator"]>;
92
92
  /**
93
93
  * Shortcut for `orm.getSeeder()`
94
94
  */
package/MikroORM.js CHANGED
@@ -11,9 +11,9 @@ const cache_1 = require("./cache");
11
11
  class MikroORM {
12
12
  /** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
13
13
  em;
14
+ driver;
14
15
  config;
15
16
  metadata;
16
- driver;
17
17
  logger;
18
18
  discovery;
19
19
  /**
package/README.md CHANGED
@@ -183,7 +183,6 @@ yarn add @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
183
183
  yarn add @mikro-orm/core @mikro-orm/postgresql # for postgresql
184
184
  yarn add @mikro-orm/core @mikro-orm/mssql # for mssql
185
185
  yarn add @mikro-orm/core @mikro-orm/sqlite # for sqlite
186
- yarn add @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
187
186
  yarn add @mikro-orm/core @mikro-orm/libsql # for libsql
188
187
  ```
189
188
 
@@ -196,7 +195,6 @@ npm i -s @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
196
195
  npm i -s @mikro-orm/core @mikro-orm/postgresql # for postgresql
197
196
  npm i -s @mikro-orm/core @mikro-orm/mssql # for mssql
198
197
  npm i -s @mikro-orm/core @mikro-orm/sqlite # for sqlite
199
- npm i -s @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
200
198
  npm i -s @mikro-orm/core @mikro-orm/libsql # for libsql
201
199
  ```
202
200
 
@@ -1,4 +1,4 @@
1
- import { type Configuration, type ConnectionOptions, type DynamicPassword } from '../utils';
1
+ import { type Configuration, type ConnectionOptions } from '../utils';
2
2
  import type { LogContext, Logger } from '../logging';
3
3
  import type { MetadataStorage } from '../metadata';
4
4
  import type { ConnectionType, Dictionary, MaybePromise, Primary } from '../typings';
@@ -40,10 +40,6 @@ export declare abstract class Connection {
40
40
  * Ensure the connection exists, this is used to support lazy connect when using `MikroORM.initSync()`
41
41
  */
42
42
  ensureConnection(): Promise<void>;
43
- /**
44
- * Returns default client url for given driver (e.g. mongodb://127.0.0.1:27017 for mongodb)
45
- */
46
- abstract getDefaultClientUrl(): string;
47
43
  transactional<T>(cb: (trx: Transaction) => Promise<T>, options?: {
48
44
  isolationLevel?: IsolationLevel;
49
45
  readOnly?: boolean;
@@ -80,8 +76,8 @@ export interface ConnectionConfig {
80
76
  host?: string;
81
77
  port?: number;
82
78
  user?: string;
83
- password?: string | (() => MaybePromise<string> | MaybePromise<DynamicPassword>);
79
+ password?: string | (() => MaybePromise<string>);
84
80
  database?: string;
85
81
  schema?: string;
86
82
  }
87
- export type Transaction<T = any> = T;
83
+ export type Transaction<T = any> = T & {};
@@ -232,18 +232,14 @@ class DatabaseDriver {
232
232
  prop.ownColumns.forEach(joinColumn => data[joinColumn] = null);
233
233
  return;
234
234
  }
235
- if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType_1.JsonType && object) && !this.platform.isRaw(data[k])) {
235
+ if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType_1.JsonType && object) && !(0, utils_1.isRaw)(data[k])) {
236
236
  data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, { fromQuery: true, key: k, mode: 'query-data' });
237
237
  }
238
- if (prop.hasConvertToDatabaseValueSQL && !prop.object && !this.platform.isRaw(data[k])) {
238
+ if (prop.hasConvertToDatabaseValueSQL && !prop.object && !(0, utils_1.isRaw)(data[k])) {
239
239
  const quoted = this.platform.quoteValue(data[k]);
240
240
  const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
241
241
  data[k] = (0, utils_1.raw)(sql.replace(/\?/g, '\\?'));
242
242
  }
243
- /* istanbul ignore next */
244
- if (!prop.customType && (Array.isArray(data[k]) || utils_1.Utils.isPlainObject(data[k]))) {
245
- data[k] = JSON.stringify(data[k]);
246
- }
247
243
  if (prop.fieldNames) {
248
244
  utils_1.Utils.renameKey(data, k, prop.fieldNames[0]);
249
245
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Collection = void 0;
4
4
  const ArrayCollection_1 = require("./ArrayCollection");
5
- const utils_1 = require("../utils");
5
+ const Utils_1 = require("../utils/Utils");
6
6
  const errors_1 = require("../errors");
7
7
  const enums_1 = require("../enums");
8
8
  const Reference_1 = require("./Reference");
@@ -65,7 +65,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
65
65
  async loadCount(options = {}) {
66
66
  options = typeof options === 'boolean' ? { refresh: options } : options;
67
67
  const { refresh, where, ...countOptions } = options;
68
- if (!refresh && !where && utils_1.Utils.isDefined(this._count)) {
68
+ if (!refresh && !where && Utils_1.Utils.isDefined(this._count)) {
69
69
  return this._count;
70
70
  }
71
71
  const em = this.getEntityManager();
@@ -116,7 +116,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
116
116
  return super.toJSON();
117
117
  }
118
118
  add(entity, ...entities) {
119
- entities = utils_1.Utils.asArray(entity).concat(entities);
119
+ entities = Utils_1.Utils.asArray(entity).concat(entities);
120
120
  const unwrapped = entities.map(i => Reference_1.Reference.unwrapReference(i));
121
121
  unwrapped.forEach(entity => this.validateItemType(entity));
122
122
  this.modify('add', unwrapped);
@@ -134,7 +134,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
134
134
  }
135
135
  return;
136
136
  }
137
- entities = utils_1.Utils.asArray(entity).concat(entities);
137
+ entities = Utils_1.Utils.asArray(entity).concat(entities);
138
138
  const unwrapped = entities.map(i => Reference_1.Reference.unwrapReference(i));
139
139
  this.modify('remove', unwrapped);
140
140
  const em = this.getEntityManager(unwrapped, false);
@@ -221,7 +221,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
221
221
  return this;
222
222
  }
223
223
  const em = this.getEntityManager();
224
- if (options.dataloader ?? [enums_1.DataloaderType.ALL, enums_1.DataloaderType.COLLECTION].includes(utils_1.DataloaderUtils.getDataloaderType(em.config.get('dataloader')))) {
224
+ if (options.dataloader ?? [enums_1.DataloaderType.ALL, enums_1.DataloaderType.COLLECTION].includes(em.config.getDataloaderType())) {
225
225
  const order = [...this.items]; // copy order of references
226
226
  const customOrder = !!options.orderBy;
227
227
  // eslint-disable-next-line dot-notation
@@ -284,10 +284,10 @@ class Collection extends ArrayCollection_1.ArrayCollection {
284
284
  return cond;
285
285
  }
286
286
  createOrderBy(orderBy = []) {
287
- if (utils_1.Utils.isEmpty(orderBy) && this.property.orderBy) {
287
+ if (Utils_1.Utils.isEmpty(orderBy) && this.property.orderBy) {
288
288
  orderBy = this.property.orderBy;
289
289
  }
290
- return utils_1.Utils.asArray(orderBy);
290
+ return Utils_1.Utils.asArray(orderBy);
291
291
  }
292
292
  createManyToManyCondition(cond) {
293
293
  const dict = cond;
@@ -345,7 +345,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
345
345
  }
346
346
  }
347
347
  validateItemType(item) {
348
- if (!utils_1.Utils.isEntity(item)) {
348
+ if (!Utils_1.Utils.isEntity(item)) {
349
349
  throw errors_1.ValidationError.notEntity(this.owner, this.property, item);
350
350
  }
351
351
  }
@@ -6,7 +6,7 @@ exports.rel = rel;
6
6
  const node_util_1 = require("node:util");
7
7
  const enums_1 = require("../enums");
8
8
  const wrap_1 = require("./wrap");
9
- const utils_1 = require("../utils");
9
+ const Utils_1 = require("../utils/Utils");
10
10
  class Reference {
11
11
  entity;
12
12
  constructor(entity) {
@@ -87,7 +87,7 @@ class Reference {
87
87
  await wrapped.__em.populate(this.entity, options.populate, options);
88
88
  }
89
89
  if (!this.isInitialized() || options.refresh) {
90
- if (options.dataloader ?? [enums_1.DataloaderType.ALL, enums_1.DataloaderType.REFERENCE].includes(utils_1.DataloaderUtils.getDataloaderType(wrapped.__em.config.get('dataloader')))) {
90
+ if (options.dataloader ?? [enums_1.DataloaderType.ALL, enums_1.DataloaderType.REFERENCE].includes(wrapped.__em.config.getDataloaderType())) {
91
91
  // eslint-disable-next-line dot-notation
92
92
  return wrapped.__em['refLoader'].load([this, options]);
93
93
  }
@@ -220,10 +220,10 @@ function ref(entityOrType, pk) {
220
220
  if (entityOrType == null) {
221
221
  return entityOrType;
222
222
  }
223
- if (utils_1.Utils.isEntity(entityOrType, true)) {
223
+ if (Utils_1.Utils.isEntity(entityOrType, true)) {
224
224
  return (0, wrap_1.helper)(entityOrType).toReference();
225
225
  }
226
- if (utils_1.Utils.isEntity(pk, true)) {
226
+ if (Utils_1.Utils.isEntity(pk, true)) {
227
227
  return (0, wrap_1.helper)(pk).toReference();
228
228
  }
229
229
  if (arguments.length === 1) {
@@ -238,7 +238,7 @@ function ref(entityOrType, pk) {
238
238
  * shortcut for `Reference.createNakedFromPK(entityType, pk)`
239
239
  */
240
240
  function rel(entityType, pk) {
241
- if (pk == null || utils_1.Utils.isEntity(pk)) {
241
+ if (pk == null || Utils_1.Utils.isEntity(pk)) {
242
242
  return pk;
243
243
  }
244
244
  return Reference.createNakedFromPK(entityType, pk);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventManager = void 0;
4
- const utils_1 = require("../utils");
4
+ const Utils_1 = require("../utils/Utils");
5
5
  const enums_1 = require("../enums");
6
6
  class EventManager {
7
7
  listeners = {};
@@ -15,7 +15,7 @@ class EventManager {
15
15
  this.subscribers.push(subscriber);
16
16
  this.entities.set(subscriber, this.getSubscribedEntities(subscriber));
17
17
  this.cache.clear();
18
- utils_1.Utils.keys(enums_1.EventType)
18
+ Utils_1.Utils.keys(enums_1.EventType)
19
19
  .filter(event => event in subscriber)
20
20
  .forEach(event => {
21
21
  this.listeners[event] ??= [];
@@ -42,7 +42,7 @@ class EventManager {
42
42
  if (event === enums_1.EventType.onInit) {
43
43
  return listeners.forEach(listener => listener(args));
44
44
  }
45
- return utils_1.Utils.runSerial(listeners, listener => listener(args));
45
+ return Utils_1.Utils.runSerial(listeners, listener => listener(args));
46
46
  }
47
47
  hasListeners(event, meta) {
48
48
  const cacheKey = meta._id + enums_1.EventTypeMap[event];
@@ -71,7 +71,7 @@ class EventManager {
71
71
  if (!listener.getSubscribedEntities) {
72
72
  return [];
73
73
  }
74
- return listener.getSubscribedEntities().map(name => utils_1.Utils.className(name));
74
+ return listener.getSubscribedEntities().map(name => Utils_1.Utils.className(name));
75
75
  }
76
76
  }
77
77
  exports.EventManager = EventManager;
@@ -1,17 +1,13 @@
1
1
  import type { Transaction } from '../connections';
2
2
  import type { EntityManager } from '../EntityManager';
3
3
  import type { TransactionEventType } from '../enums';
4
- import type { UnitOfWork } from '../unit-of-work';
5
4
  export declare class TransactionEventBroadcaster {
6
5
  private readonly em;
7
- private readonly uow?;
8
6
  readonly context?: {
9
7
  topLevelTransaction?: boolean;
10
8
  } | undefined;
11
- private readonly eventManager;
12
- constructor(em: EntityManager, uow?: UnitOfWork | undefined, context?: {
9
+ constructor(em: EntityManager, context?: {
13
10
  topLevelTransaction?: boolean;
14
11
  } | undefined);
15
12
  dispatchEvent(event: TransactionEventType, transaction?: Transaction): Promise<void>;
16
- isTopLevel(): boolean;
17
13
  }
@@ -3,20 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransactionEventBroadcaster = void 0;
4
4
  class TransactionEventBroadcaster {
5
5
  em;
6
- uow;
7
6
  context;
8
- eventManager;
9
- constructor(em, uow, context) {
7
+ constructor(em, context) {
10
8
  this.em = em;
11
- this.uow = uow;
12
9
  this.context = context;
13
- this.eventManager = this.em.getEventManager();
14
10
  }
15
11
  async dispatchEvent(event, transaction) {
16
- await this.eventManager.dispatchEvent(event, { em: this.em, transaction, uow: this.uow });
17
- }
18
- isTopLevel() {
19
- return !!this.context?.topLevelTransaction;
12
+ await this.em.getEventManager().dispatchEvent(event, {
13
+ em: this.em,
14
+ uow: this.em.getUnitOfWork(false),
15
+ transaction,
16
+ });
20
17
  }
21
18
  }
22
19
  exports.TransactionEventBroadcaster = TransactionEventBroadcaster;
package/index.mjs CHANGED
@@ -139,6 +139,7 @@ export const QueryHelper = mod.QueryHelper;
139
139
  export const QueryOperator = mod.QueryOperator;
140
140
  export const QueryOrder = mod.QueryOrder;
141
141
  export const QueryOrderNumeric = mod.QueryOrderNumeric;
142
+ export const Raw = mod.Raw;
142
143
  export const RawQueryFragment = mod.RawQueryFragment;
143
144
  export const ReadOnlyException = mod.ReadOnlyException;
144
145
  export const Ref = mod.Ref;
@@ -186,6 +187,7 @@ export const equals = mod.equals;
186
187
  export const getOnConflictFields = mod.getOnConflictFields;
187
188
  export const getOnConflictReturningFields = mod.getOnConflictReturningFields;
188
189
  export const helper = mod.helper;
190
+ export const isRaw = mod.isRaw;
189
191
  export const parseJsonSafe = mod.parseJsonSafe;
190
192
  export const raw = mod.raw;
191
193
  export const ref = mod.ref;
@@ -26,7 +26,7 @@ export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery'
26
26
  export interface LogContext extends Dictionary {
27
27
  query?: string;
28
28
  label?: string;
29
- params?: unknown[];
29
+ params?: readonly unknown[];
30
30
  took?: number;
31
31
  results?: number;
32
32
  affected?: number;
@@ -973,6 +973,18 @@ class MetadataDiscovery {
973
973
  check.expression = check.expression(map);
974
974
  }
975
975
  }
976
+ if (this.platform.usesEnumCheckConstraints() && !meta.embeddable) {
977
+ for (const prop of meta.props) {
978
+ if (prop.enum && !prop.nativeEnumName && prop.items?.every(item => Utils_1.Utils.isString(item))) {
979
+ this.initFieldName(prop);
980
+ meta.checks.push({
981
+ name: this.namingStrategy.indexName(meta.tableName, prop.fieldNames, 'check'),
982
+ property: prop.name,
983
+ expression: `${this.platform.quoteIdentifier(prop.fieldNames[0])} in ('${prop.items.join("', '")}')`,
984
+ });
985
+ }
986
+ }
987
+ }
976
988
  }
977
989
  initGeneratedColumn(meta, prop) {
978
990
  if (!prop.generated && prop.columnTypes) {
@@ -3,7 +3,7 @@ import { type ReferenceKind } from '../enums';
3
3
  export declare abstract class AbstractNamingStrategy implements NamingStrategy {
4
4
  getClassName(file: string, separator?: string): string;
5
5
  classToMigrationName(timestamp: string, customMigrationName?: string): string;
6
- indexName(tableName: string, columns: string[], type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check'): string;
6
+ indexName(tableName: string, columns: string[], type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check' | 'default'): string;
7
7
  /**
8
8
  * @inheritDoc
9
9
  */
@@ -65,7 +65,7 @@ export interface NamingStrategy {
65
65
  /**
66
66
  * Returns key/constraint name for the given type. Some drivers might not support all the types (e.g. mysql and sqlite enforce the PK name).
67
67
  */
68
- indexName(tableName: string, columns: string[], type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check'): string;
68
+ indexName(tableName: string, columns: string[], type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check' | 'default'): string;
69
69
  /**
70
70
  * Returns alias name for given entity. The alias needs to be unique across the query, which is by default
71
71
  * ensured via appended index parameter. It is optional to use it as long as you ensure it will be unique.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.7-dev.1",
3
+ "version": "7.0.0-dev.1",
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",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "homepage": "https://mikro-orm.io",
49
49
  "engines": {
50
- "node": ">= 18.12.0"
50
+ "node": ">= 22.11.0"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "yarn clean && yarn compile && yarn copy && yarn run -T gen-esm-wrapper index.js index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.7-dev.1",
67
+ "mikro-orm": "7.0.0-dev.1",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -1,3 +1,4 @@
1
+ import { inspect } from 'node:util';
1
2
  import { EntityRepository } from '../entity';
2
3
  import { type NamingStrategy } from '../naming-strategy';
3
4
  import type { Constructor, EntityProperty, IPrimaryKey, ISchemaGenerator, PopulateOptions, Primary, EntityMetadata, SimpleColumnMeta } from '../typings';
@@ -25,6 +26,8 @@ export declare abstract class Platform {
25
26
  usesCascadeStatement(): boolean;
26
27
  /** for postgres native enums */
27
28
  supportsNativeEnums(): boolean;
29
+ /** for postgres text enums (default) */
30
+ usesEnumCheckConstraints(): boolean;
28
31
  getSchemaHelper(): unknown;
29
32
  indexForeignKeys(): boolean;
30
33
  allowsMultiInsert(): boolean;
@@ -72,7 +75,6 @@ export declare abstract class Platform {
72
75
  getDefaultVersionLength(): number;
73
76
  allowsComparingTuples(): boolean;
74
77
  isBigIntProperty(prop: EntityProperty): boolean;
75
- isRaw(value: any): boolean;
76
78
  getDefaultSchemaName(): string | undefined;
77
79
  getBooleanTypeDeclarationSQL(): string;
78
80
  getIntegerTypeDeclarationSQL(column: {
@@ -132,7 +134,7 @@ export declare abstract class Platform {
132
134
  /**
133
135
  * This should be used only to compare types, it can strip some information like the length.
134
136
  */
135
- normalizeColumnType(type: string, options?: {
137
+ normalizeColumnType(type: string, options: {
136
138
  length?: number;
137
139
  precision?: number;
138
140
  scale?: number;
@@ -190,18 +192,23 @@ export declare abstract class Platform {
190
192
  getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence'): string;
191
193
  getDefaultPrimaryName(tableName: string, columns: string[]): string;
192
194
  supportsCustomPrimaryKeyNames(): boolean;
193
- isPopulated<T>(key: string, populate: PopulateOptions<T>[] | boolean): boolean;
194
- shouldHaveColumn<T>(prop: EntityProperty<T>, populate: PopulateOptions<T>[] | boolean, exclude?: string[], includeFormulas?: boolean): boolean;
195
+ isPopulated<T>(key: string, populate: readonly PopulateOptions<T>[] | boolean): boolean;
196
+ shouldHaveColumn<T>(prop: EntityProperty<T>, populate: readonly PopulateOptions<T>[] | boolean, exclude?: string[], includeFormulas?: boolean): boolean;
195
197
  /**
196
198
  * Currently not supported due to how knex does complex sqlite diffing (always based on current schema)
197
199
  */
198
200
  supportsDownMigrations(): boolean;
201
+ supportsDeferredUniqueConstraints(): boolean;
199
202
  validateMetadata(meta: EntityMetadata): void;
200
203
  /**
201
204
  * Generates a custom order by statement given a set of in order values, eg.
202
205
  * ORDER BY (CASE WHEN priority = 'low' THEN 1 WHEN priority = 'medium' THEN 2 ELSE NULL END)
203
206
  */
204
207
  generateCustomOrder(escapedColumn: string, values: unknown[]): void;
208
+ /**
209
+ * Returns default client url for given driver (e.g. mongodb://127.0.0.1:27017 for mongodb)
210
+ */
211
+ getDefaultClientUrl(): string;
205
212
  /**
206
213
  * @internal
207
214
  */
@@ -218,4 +225,6 @@ export declare abstract class Platform {
218
225
  * @internal
219
226
  */
220
227
  clone(): this;
228
+ /** @ignore */
229
+ [inspect.custom](): string;
221
230
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Platform = exports.JsonProperty = void 0;
4
+ const node_util_1 = require("node:util");
4
5
  const clone_1 = require("../utils/clone");
5
6
  const entity_1 = require("../entity");
6
7
  const naming_strategy_1 = require("../naming-strategy");
@@ -8,6 +9,7 @@ const ExceptionConverter_1 = require("./ExceptionConverter");
8
9
  const types_1 = require("../types");
9
10
  const Utils_1 = require("../utils/Utils");
10
11
  const enums_1 = require("../enums");
12
+ const RawQueryFragment_1 = require("../utils/RawQueryFragment");
11
13
  exports.JsonProperty = Symbol('JsonProperty');
12
14
  class Platform {
13
15
  exceptionConverter = new ExceptionConverter_1.ExceptionConverter();
@@ -39,6 +41,10 @@ class Platform {
39
41
  supportsNativeEnums() {
40
42
  return false;
41
43
  }
44
+ /** for postgres text enums (default) */
45
+ usesEnumCheckConstraints() {
46
+ return false;
47
+ }
42
48
  getSchemaHelper() {
43
49
  return undefined;
44
50
  }
@@ -132,9 +138,6 @@ class Platform {
132
138
  isBigIntProperty(prop) {
133
139
  return prop.columnTypes && prop.columnTypes[0] === 'bigint';
134
140
  }
135
- isRaw(value) {
136
- return typeof value === 'object' && value !== null && '__raw' in value;
137
- }
138
141
  getDefaultSchemaName() {
139
142
  return undefined;
140
143
  }
@@ -195,7 +198,7 @@ class Platform {
195
198
  /**
196
199
  * This should be used only to compare types, it can strip some information like the length.
197
200
  */
198
- normalizeColumnType(type, options = {}) {
201
+ normalizeColumnType(type, options) {
199
202
  return type.toLowerCase();
200
203
  }
201
204
  getMappedType(type) {
@@ -356,6 +359,10 @@ class Platform {
356
359
  return value;
357
360
  }
358
361
  quoteIdentifier(id, quote = '`') {
362
+ const raw = RawQueryFragment_1.RawQueryFragment.getKnownFragment(id);
363
+ if (raw) {
364
+ return this.formatQuery(raw.sql, raw.params);
365
+ }
359
366
  return `${quote}${id.toString().replace('.', `${quote}.${quote}`)}${quote}`;
360
367
  }
361
368
  quoteValue(value) {
@@ -442,9 +449,8 @@ class Platform {
442
449
  getIndexName(tableName, columns, type) {
443
450
  return this.namingStrategy.indexName(tableName, columns, type);
444
451
  }
445
- /* istanbul ignore next */
446
452
  getDefaultPrimaryName(tableName, columns) {
447
- return this.namingStrategy.indexName(tableName, columns, 'primary');
453
+ return 'primary';
448
454
  }
449
455
  supportsCustomPrimaryKeyNames() {
450
456
  return false;
@@ -482,6 +488,9 @@ class Platform {
482
488
  supportsDownMigrations() {
483
489
  return true;
484
490
  }
491
+ supportsDeferredUniqueConstraints() {
492
+ return true;
493
+ }
485
494
  validateMetadata(meta) {
486
495
  return;
487
496
  }
@@ -492,6 +501,12 @@ class Platform {
492
501
  generateCustomOrder(escapedColumn, values) {
493
502
  throw new Error('Not supported');
494
503
  }
504
+ /**
505
+ * Returns default client url for given driver (e.g. mongodb://127.0.0.1:27017 for mongodb)
506
+ */
507
+ getDefaultClientUrl() {
508
+ return '';
509
+ }
495
510
  /**
496
511
  * @internal
497
512
  */
@@ -510,5 +525,10 @@ class Platform {
510
525
  clone() {
511
526
  return this;
512
527
  }
528
+ /* istanbul ignore next */
529
+ /** @ignore */
530
+ [node_util_1.inspect.custom]() {
531
+ return `[${this.constructor.name}]`;
532
+ }
513
533
  }
514
534
  exports.Platform = Platform;
@@ -7,6 +7,7 @@ const Utils_1 = require("../utils/Utils");
7
7
  const enums_1 = require("../enums");
8
8
  const Reference_1 = require("../entity/Reference");
9
9
  const SerializationContext_1 = require("./SerializationContext");
10
+ const RawQueryFragment_1 = require("../utils/RawQueryFragment");
10
11
  function isVisible(meta, propName, options) {
11
12
  const prop = meta.properties[propName];
12
13
  if (options.groups && prop?.groups) {
@@ -65,7 +66,7 @@ class EntitySerializer {
65
66
  if (options.skipNull && Utils_1.Utils.isPlainObject(val)) {
66
67
  Utils_1.Utils.dropUndefinedProperties(val, null);
67
68
  }
68
- if (Utils_1.Utils.isRawSql(val)) {
69
+ if ((0, RawQueryFragment_1.isRaw)(val)) {
69
70
  throw new Error(`Trying to serialize raw SQL fragment: '${val.sql}'`);
70
71
  }
71
72
  const visible = typeof val !== 'undefined' && !(val === null && options.skipNull);
@@ -5,6 +5,7 @@ const wrap_1 = require("../entity/wrap");
5
5
  const Utils_1 = require("../utils/Utils");
6
6
  const enums_1 = require("../enums");
7
7
  const SerializationContext_1 = require("./SerializationContext");
8
+ const RawQueryFragment_1 = require("../utils/RawQueryFragment");
8
9
  function isVisible(meta, propName, ignoreFields = []) {
9
10
  const prop = meta.properties[propName];
10
11
  const visible = prop && !prop.hidden;
@@ -63,7 +64,7 @@ class EntityTransformer {
63
64
  if (!cycle) {
64
65
  root.leave(meta.className, prop);
65
66
  }
66
- if (Utils_1.Utils.isRawSql(val)) {
67
+ if ((0, RawQueryFragment_1.isRaw)(val)) {
67
68
  throw new Error(`Trying to serialize raw SQL fragment: '${val.sql}'`);
68
69
  }
69
70
  if (typeof val === 'undefined') {