@mikro-orm/core 7.1.0-dev.20 → 7.1.0-dev.22

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.
@@ -117,7 +117,7 @@ export interface PropertyChain<Value, Options> {
117
117
  groups(...groups: string[]): PropertyChain<Value, Options>;
118
118
  customOrder(...customOrder: string[] | number[] | boolean[]): PropertyChain<Value, Options>;
119
119
  extra(extra: string): PropertyChain<Value, Options>;
120
- ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): PropertyChain<Value, Options>;
120
+ ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default' | 'collation')[]): PropertyChain<Value, Options>;
121
121
  /** Explicitly specify index on a property. When a string name is passed, it enables type-safe `using` in `FindOptions`. */
122
122
  index<N extends string>(name: N): PropertyChain<Value, Omit<Options, 'index'> & {
123
123
  index: N;
@@ -129,6 +129,7 @@ export interface PropertyChain<Value, Options> {
129
129
  }>;
130
130
  unique(unique?: boolean): PropertyChain<Value, Options>;
131
131
  comment(comment: string): PropertyChain<Value, Options>;
132
+ collation(collation: string): PropertyChain<Value, Options>;
132
133
  accessor(accessor?: string | boolean): PropertyChain<Value, Options>;
133
134
  eager(eager?: boolean): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
134
135
  cascade(...cascade: Cascade[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
@@ -478,6 +479,11 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
478
479
  * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
479
480
  */
480
481
  comment(comment: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
482
+ /**
483
+ * Specify column-level collation for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
484
+ * Emits a `COLLATE` clause on the column definition; the accepted collation names are dialect-specific.
485
+ */
486
+ collation(collation: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
481
487
  /** mysql only */
482
488
  extra(extra: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
483
489
  /**
@@ -485,7 +491,7 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
485
491
  *
486
492
  * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
487
493
  */
488
- ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
494
+ ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default' | 'collation')[]): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
489
495
  array(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'array'> & {
490
496
  array: true;
491
497
  }, IncludeKeys>, IncludeKeys>;
@@ -316,6 +316,13 @@ export class UniversalPropertyOptionsBuilder {
316
316
  comment(comment) {
317
317
  return this.assignOptions({ comment });
318
318
  }
319
+ /**
320
+ * Specify column-level collation for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
321
+ * Emits a `COLLATE` clause on the column definition; the accepted collation names are dialect-specific.
322
+ */
323
+ collation(collation) {
324
+ return this.assignOptions({ collation });
325
+ }
319
326
  /** mysql only */
320
327
  extra(extra) {
321
328
  return this.assignOptions({ extra });
@@ -114,7 +114,12 @@ export class MetadataDiscovery {
114
114
  }
115
115
  else {
116
116
  const name = prop.name;
117
- if (prop.kind === ReferenceKind.SCALAR || prop.kind === ReferenceKind.EMBEDDED) {
117
+ // For to-one relations, only swap to the accessor for the documented
118
+ // backing-field convention (a `_`-prefixed property like `_draft` paired
119
+ // with `accessor: 'draft'`). The non-prefixed sibling-helper pattern
120
+ // (`author` + `accessor: 'authorId'`) keeps the property name as the
121
+ // canonical FK column source, so this stays non-breaking.
122
+ if (prop.kind === ReferenceKind.SCALAR || prop.kind === ReferenceKind.EMBEDDED || name.startsWith('_')) {
118
123
  prop.name = prop.accessor;
119
124
  }
120
125
  this.initRelation(prop);
@@ -1389,10 +1394,10 @@ export class MetadataDiscovery {
1389
1394
  if (meta.root !== meta) {
1390
1395
  meta.root = metadata.find(m => m.class === meta.root.class);
1391
1396
  }
1392
- const inheritance = meta.inheritance;
1393
- if (inheritance === 'tpt' && meta.root === meta) {
1394
- meta.inheritanceType = 'tpt';
1395
- meta.tptChildren = [];
1397
+ // init the root eagerly so children iterated before the root (e.g. alphabetical glob order) still get linked
1398
+ if (meta.root.inheritance === 'tpt' && meta.root.inheritanceType !== 'tpt') {
1399
+ meta.root.inheritanceType = 'tpt';
1400
+ meta.root.tptChildren ??= [];
1396
1401
  }
1397
1402
  if (meta.root.inheritanceType !== 'tpt') {
1398
1403
  return;
@@ -348,7 +348,7 @@ export class MetadataValidator {
348
348
  * Composite unique constraints are not sufficient for targetKey.
349
349
  */
350
350
  isPropertyUnique(prop, meta) {
351
- if (prop.unique) {
351
+ if (prop.unique || (prop.primary && meta.primaryKeys.length === 1)) {
352
352
  return true;
353
353
  }
354
354
  // Check for single-property unique constraint via @Unique decorator
@@ -381,6 +381,11 @@ export interface PropertyOptions<Owner> {
381
381
  * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
382
382
  */
383
383
  comment?: string;
384
+ /**
385
+ * Specify column-level collation for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
386
+ * Emits a `COLLATE` clause on the column definition; the accepted collation names are dialect-specific.
387
+ */
388
+ collation?: string;
384
389
  /** mysql only */
385
390
  extra?: string;
386
391
  /**
@@ -388,7 +393,7 @@ export interface PropertyOptions<Owner> {
388
393
  *
389
394
  * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
390
395
  */
391
- ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
396
+ ignoreSchemaChanges?: ('type' | 'extra' | 'default' | 'collation')[];
392
397
  }
393
398
  export interface ReferenceOptions<Owner, Target> extends PropertyOptions<Owner> {
394
399
  /** Set target entity type. For polymorphic relations, pass an array of entity types. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.0-dev.20",
3
+ "version": "7.1.0-dev.22",
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
  "keywords": [
6
6
  "data-mapper",
@@ -170,7 +170,7 @@ export declare abstract class Platform {
170
170
  getUuidTypeDeclarationSQL(column: {
171
171
  length?: number;
172
172
  }): string;
173
- /** Extracts the base type name from a full SQL type declaration (e.g. "varchar(255)" -> "varchar"). */
173
+ /** Extracts the base type name from a full SQL type declaration (e.g. `varchar(255)` -> `varchar`). */
174
174
  extractSimpleType(type: string): string;
175
175
  /**
176
176
  * This should be used only to compare types, it can strip some information like the length.
@@ -9,6 +9,15 @@ import { ReferenceKind } from '../enums.js';
9
9
  import { Raw } from '../utils/RawQueryFragment.js';
10
10
  /** Symbol used to tag cloned embeddable data for JSON serialization handling. */
11
11
  export const JsonProperty = Symbol('JsonProperty');
12
+ const MULTI_WORD_SQL_TYPES = [
13
+ 'timestamp with time zone',
14
+ 'timestamp without time zone',
15
+ 'time with time zone',
16
+ 'time without time zone',
17
+ 'character varying',
18
+ 'double precision',
19
+ 'bit varying',
20
+ ];
12
21
  /** Abstract base class providing database-specific behavior and SQL dialect differences. */
13
22
  export class Platform {
14
23
  exceptionConverter = new ExceptionConverter();
@@ -227,9 +236,15 @@ export class Platform {
227
236
  column.length ??= 36;
228
237
  return this.getVarcharTypeDeclarationSQL(column);
229
238
  }
230
- /** Extracts the base type name from a full SQL type declaration (e.g. "varchar(255)" -> "varchar"). */
239
+ /** Extracts the base type name from a full SQL type declaration (e.g. `varchar(255)` -> `varchar`). */
231
240
  extractSimpleType(type) {
232
- return /[^(), ]+/.exec(type.toLowerCase())[0];
241
+ const lower = type.toLowerCase();
242
+ for (const multiWord of MULTI_WORD_SQL_TYPES) {
243
+ if (lower.startsWith(multiWord)) {
244
+ return multiWord;
245
+ }
246
+ }
247
+ return /[^(), ]+/.exec(lower)[0];
233
248
  }
234
249
  /**
235
250
  * This should be used only to compare types, it can strip some information like the length.
@@ -253,6 +268,7 @@ export class Platform {
253
268
  return Type.getType(CharacterType);
254
269
  case 'string':
255
270
  case 'varchar':
271
+ case 'character varying':
256
272
  return Type.getType(StringType);
257
273
  case 'interval':
258
274
  return Type.getType(IntervalType);
@@ -272,6 +288,7 @@ export class Platform {
272
288
  case 'float':
273
289
  return Type.getType(FloatType);
274
290
  case 'double':
291
+ case 'double precision':
275
292
  return Type.getType(DoubleType);
276
293
  case 'integer':
277
294
  return Type.getType(IntegerType);
@@ -291,8 +308,12 @@ export class Platform {
291
308
  return Type.getType(DateType);
292
309
  case 'datetime':
293
310
  case 'timestamp':
311
+ case 'timestamp with time zone':
312
+ case 'timestamp without time zone':
294
313
  return Type.getType(DateTimeType);
295
314
  case 'time':
315
+ case 'time with time zone':
316
+ case 'time without time zone':
296
317
  return Type.getType(TimeType);
297
318
  case 'object':
298
319
  case 'json':
package/typings.d.ts CHANGED
@@ -809,11 +809,12 @@ export interface EntityProperty<Owner = any, Target = any> {
809
809
  serializer?: (value: any, options?: SerializeOptions<any>) => any;
810
810
  serializedName?: string;
811
811
  comment?: string;
812
+ collation?: string;
812
813
  /** mysql only */
813
814
  extra?: string;
814
815
  userDefined?: boolean;
815
816
  optional?: boolean;
816
- ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
817
+ ignoreSchemaChanges?: ('type' | 'extra' | 'default' | 'collation')[];
817
818
  deferMode?: DeferMode;
818
819
  createForeignKeyConstraint: boolean;
819
820
  foreignKeyName?: string;
package/utils/Utils.js CHANGED
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.1.0-dev.20';
144
+ static #ORM_VERSION = '7.1.0-dev.22';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */