@mikro-orm/core 6.2.10-dev.73 → 6.2.10-dev.74

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.2.10-dev.73",
3
+ "version": "6.2.10-dev.74",
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.2.10-dev.73",
67
+ "mikro-orm": "6.2.10-dev.74",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -58,6 +58,7 @@ export declare abstract class Platform {
58
58
  length?: number;
59
59
  }): string;
60
60
  getDefaultDateTimeLength(): number;
61
+ getDefaultVarcharLength(): number;
61
62
  getDateTypeDeclarationSQL(length?: number): string;
62
63
  getTimeTypeDeclarationSQL(length?: number): string;
63
64
  getRegExpOperator(val?: unknown, flags?: string): string;
@@ -96,6 +96,9 @@ class Platform {
96
96
  getDefaultDateTimeLength() {
97
97
  return 0;
98
98
  }
99
+ getDefaultVarcharLength() {
100
+ return 255;
101
+ }
99
102
  getDateTypeDeclarationSQL(length) {
100
103
  return 'date' + (length ? `(${length})` : '');
101
104
  }
@@ -151,7 +154,7 @@ class Platform {
151
154
  return 'bigint';
152
155
  }
153
156
  getVarcharTypeDeclarationSQL(column) {
154
- return `varchar(${column.length ?? 255})`;
157
+ return `varchar(${column.length ?? this.getDefaultVarcharLength()})`;
155
158
  }
156
159
  getIntervalTypeDeclarationSQL(column) {
157
160
  return 'interval' + (column.length ? `(${column.length})` : '');
@@ -6,4 +6,5 @@ export declare class DateTimeType extends Type<Date, string> {
6
6
  compareAsType(): string;
7
7
  get runtimeType(): string;
8
8
  ensureComparable(): boolean;
9
+ getDefaultLength(platform: Platform): number;
9
10
  }
@@ -15,5 +15,8 @@ class DateTimeType extends Type_1.Type {
15
15
  ensureComparable() {
16
16
  return false;
17
17
  }
18
+ getDefaultLength(platform) {
19
+ return platform.getDefaultDateTimeLength();
20
+ }
18
21
  }
19
22
  exports.DateTimeType = DateTimeType;
@@ -6,4 +6,5 @@ export declare class DateType extends Type<string | null | undefined, string | n
6
6
  ensureComparable(): boolean;
7
7
  convertToJSValue(value: any, platform: Platform): string | null | undefined;
8
8
  getColumnType(prop: EntityProperty, platform: Platform): string;
9
+ getDefaultLength(platform: Platform): number;
9
10
  }
package/types/DateType.js CHANGED
@@ -15,5 +15,8 @@ class DateType extends Type_1.Type {
15
15
  getColumnType(prop, platform) {
16
16
  return platform.getDateTypeDeclarationSQL(prop.length);
17
17
  }
18
+ getDefaultLength(platform) {
19
+ return 0;
20
+ }
18
21
  }
19
22
  exports.DateType = DateType;
@@ -5,4 +5,5 @@ export declare class IntervalType extends Type<string | null | undefined, string
5
5
  getColumnType(prop: EntityProperty, platform: Platform): string;
6
6
  convertToJSValue(value: string | null | undefined, platform: Platform): string | null | undefined;
7
7
  convertToDatabaseValue(value: string | null | undefined, platform: Platform): string | null | undefined;
8
+ getDefaultLength(platform: Platform): number;
8
9
  }
@@ -12,5 +12,8 @@ class IntervalType extends Type_1.Type {
12
12
  convertToDatabaseValue(value, platform) {
13
13
  return platform.convertIntervalToDatabaseValue(value);
14
14
  }
15
+ getDefaultLength(platform) {
16
+ return platform.getDefaultDateTimeLength();
17
+ }
15
18
  }
16
19
  exports.IntervalType = IntervalType;
@@ -5,4 +5,5 @@ export declare class StringType extends Type<string | null | undefined, string |
5
5
  getColumnType(prop: EntityProperty, platform: Platform): string;
6
6
  compareAsType(): string;
7
7
  ensureComparable(): boolean;
8
+ getDefaultLength(platform: Platform): number;
8
9
  }
@@ -12,5 +12,8 @@ class StringType extends Type_1.Type {
12
12
  ensureComparable() {
13
13
  return false;
14
14
  }
15
+ getDefaultLength(platform) {
16
+ return platform.getDefaultVarcharLength();
17
+ }
15
18
  }
16
19
  exports.StringType = StringType;
@@ -6,4 +6,5 @@ export declare class TimeType extends Type {
6
6
  compareAsType(): string;
7
7
  ensureComparable(): boolean;
8
8
  getColumnType(prop: EntityProperty, platform: Platform): string;
9
+ getDefaultLength(platform: Platform): number;
9
10
  }
package/types/TimeType.js CHANGED
@@ -19,5 +19,8 @@ class TimeType extends Type_1.Type {
19
19
  getColumnType(prop, platform) {
20
20
  return platform.getTimeTypeDeclarationSQL(prop.length);
21
21
  }
22
+ getDefaultLength(platform) {
23
+ return platform.getDefaultDateTimeLength();
24
+ }
22
25
  }
23
26
  exports.TimeType = TimeType;
package/types/Type.d.ts CHANGED
@@ -58,6 +58,21 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
58
58
  * Gets the SQL declaration snippet for a field of this type.
59
59
  */
60
60
  getColumnType(prop: EntityProperty, platform: Platform): string;
61
+ /**
62
+ * Get the default length for values of this type
63
+ *
64
+ * When doing schema generation, if neither "length" nor "columnType" option is provided,
65
+ * the length will be defaulted to this value.
66
+ *
67
+ * When doing entity generation, if the type is recognized to this type, and the inferred length is this value,
68
+ * the length option will be omitted in the output. If this method is not defined, length is always outputted
69
+ * based on what is in the database metadata.
70
+ *
71
+ * @param platform The platform the default will be used for.
72
+ *
73
+ * @return The default value for the given platform.
74
+ */
75
+ getDefaultLength?(platform: Platform): number;
61
76
  static getType<JSType, DBType = JSType, TypeClass extends Constructor<Type<JSType, DBType>> = Constructor<Type<JSType, DBType>>>(cls: TypeClass): InstanceType<TypeClass>;
62
77
  /**
63
78
  * Checks whether the argument is instance of `Type`.