@mikro-orm/core 7.0.0-dev.218 → 7.0.0-dev.219

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.
package/MikroORM.js CHANGED
@@ -104,7 +104,9 @@ export class MikroORM {
104
104
  */
105
105
  constructor(options) {
106
106
  const env = loadEnvironmentVars();
107
- options = Utils.merge(options, env);
107
+ options = options.preferEnvVars
108
+ ? Utils.merge(options, env)
109
+ : Utils.merge(env, options);
108
110
  this.config = new Configuration(options);
109
111
  const discovery = this.config.get('discovery');
110
112
  this.driver = this.config.getDriver();
package/errors.d.ts CHANGED
@@ -67,7 +67,6 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
67
67
  static targetKeyNotFound(meta: EntityMetadata, prop: EntityProperty): MetadataError<Partial<any>>;
68
68
  static dangerousPropertyName(meta: EntityMetadata, prop: EntityProperty): MetadataError<Partial<any>>;
69
69
  static viewEntityWithoutExpression(meta: EntityMetadata): MetadataError;
70
- static materializedWithoutView(meta: EntityMetadata): MetadataError;
71
70
  private static fromMessage;
72
71
  }
73
72
  export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
package/errors.js CHANGED
@@ -228,9 +228,6 @@ export class MetadataError extends ValidationError {
228
228
  static viewEntityWithoutExpression(meta) {
229
229
  return new MetadataError(`View entity ${meta.className} is missing 'expression'. View entities must have an expression defining the SQL query.`);
230
230
  }
231
- static materializedWithoutView(meta) {
232
- return new MetadataError(`Entity ${meta.className} has 'materialized: true' but is missing 'view: true'. Materialized views must also be marked as views.`);
233
- }
234
231
  static fromMessage(meta, prop, message) {
235
232
  return new MetadataError(`${meta.className}.${prop.name} ${message}`);
236
233
  }
@@ -19,9 +19,6 @@ const DANGEROUS_PROPERTY_NAMES = ['__proto__', 'constructor', 'prototype'];
19
19
  export class MetadataValidator {
20
20
  validateEntityDefinition(metadata, name, options) {
21
21
  const meta = metadata.get(name);
22
- if (meta.materialized && !meta.view) {
23
- throw MetadataError.materializedWithoutView(meta);
24
- }
25
22
  // View entities (expression with view flag) behave like regular tables but are read-only
26
23
  // They can have primary keys and are created as actual database views
27
24
  if (meta.view) {
@@ -34,20 +34,15 @@ export type EntityOptions<T, E = T extends EntityClass<infer P> ? P : T> = {
34
34
  * Marks entity as a database view. Unlike virtual entities which evaluate expressions at query time,
35
35
  * view entities create actual database views. The `expression` option must be provided when `view` is true.
36
36
  * View entities are read-only by default.
37
- */
38
- view?: boolean;
39
- /**
40
- * Marks the view entity as a materialized view. Requires `view: true`.
37
+ *
38
+ * Use `view: true` for regular views, or `view: { materialized: true }` for materialized views (PostgreSQL only).
41
39
  * Materialized views store the query results and must be refreshed to update data.
42
- * Only supported on PostgreSQL.
43
- */
44
- materialized?: boolean;
45
- /**
46
- * For materialized views, whether to populate data immediately on creation.
47
- * Defaults to `true`. Set to `false` to create an unpopulated materialized view.
48
- * Only applicable when `materialized: true`.
40
+ * Use `view: { materialized: true, withData: false }` to create an unpopulated materialized view.
49
41
  */
50
- withData?: boolean;
42
+ view?: boolean | {
43
+ materialized?: boolean;
44
+ withData?: boolean;
45
+ };
51
46
  /** Used to make ORM aware of externally defined triggers. This is needed for MS SQL Server multi inserts, ignored in other dialects. */
52
47
  hasTriggers?: boolean;
53
48
  /** SQL query that maps to a {@doclink virtual-entities | virtual entity}, or for view entities, the view definition. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.218",
4
+ "version": "7.0.0-dev.219",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
package/typings.d.ts CHANGED
@@ -540,8 +540,11 @@ export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> =
540
540
  schema?: string;
541
541
  pivotTable?: boolean;
542
542
  virtual?: boolean;
543
- /** True if this entity represents a database view (not a virtual entity). */
544
- view?: boolean;
543
+ /** True if this entity represents a database view (not a virtual entity). Accepts `{ materialized: true }` as input, normalized to `true` during sync. */
544
+ view?: boolean | {
545
+ materialized?: boolean;
546
+ withData?: boolean;
547
+ };
545
548
  /** True if this is a materialized view (PostgreSQL only). Requires `view: true`. */
546
549
  materialized?: boolean;
547
550
  /** For materialized views, whether data is populated on creation. Defaults to true. */
package/typings.js CHANGED
@@ -109,6 +109,13 @@ export class EntityMetadata {
109
109
  return this.root.uniqueName === prop.targetMeta?.root.uniqueName;
110
110
  });
111
111
  this.hasUniqueProps = this.uniques.length + this.uniqueProps.length > 0;
112
+ // Normalize object-form `view` option: `view: { materialized: true, withData: false }`
113
+ // into flat metadata fields (`view: true`, `materialized: true`, `withData: false`).
114
+ if (typeof this.view === 'object') {
115
+ this.materialized = this.view.materialized;
116
+ this.withData = this.view.withData;
117
+ this.view = true;
118
+ }
112
119
  // If `view` is set, this is a database view entity (not a virtual entity).
113
120
  // Virtual entities evaluate expressions at query time, view entities create actual database views.
114
121
  this.virtual = !!this.expression && !this.view;
@@ -753,6 +753,12 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
753
753
  * @default false
754
754
  */
755
755
  allowGlobalContext?: boolean;
756
+ /**
757
+ * When enabled, environment variables take precedence over explicitly provided config options.
758
+ * By default, explicit options win over env vars.
759
+ * @default false
760
+ */
761
+ preferEnvVars?: boolean;
756
762
  /**
757
763
  * Disable the identity map.
758
764
  * When disabled, each query returns new entity instances.
package/utils/Utils.js CHANGED
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
123
123
  }
124
124
  export class Utils {
125
125
  static PK_SEPARATOR = '~~~';
126
- static #ORM_VERSION = '7.0.0-dev.218';
126
+ static #ORM_VERSION = '7.0.0-dev.219';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */