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

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.75",
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.75",
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})` : '');
@@ -5,7 +5,7 @@ import type { Configuration } from '../utils/Configuration';
5
5
  * Before we process a property, we call `visit` that checks if it is not a cycle path (but allows to pass cycles that
6
6
  * are defined in populate hint). If not, we proceed and call `leave` afterwards.
7
7
  */
8
- export declare class SerializationContext<T> {
8
+ export declare class SerializationContext<T extends object> {
9
9
  private readonly config;
10
10
  private readonly populate;
11
11
  private readonly fields?;
@@ -23,7 +23,7 @@ export declare class SerializationContext<T> {
23
23
  /**
24
24
  * When initializing new context, we need to propagate it to the whole entity graph recursively.
25
25
  */
26
- static propagate(root: SerializationContext<AnyEntity>, entity: AnyEntity, isVisible: (meta: EntityMetadata, prop: string) => boolean): void;
26
+ static propagate(root: SerializationContext<any>, entity: AnyEntity, isVisible: (meta: EntityMetadata, prop: string) => boolean): void;
27
27
  isMarkedAsPopulated(entityName: string, prop: string): boolean;
28
28
  isPartiallyLoaded(entityName: string, prop: string): boolean;
29
29
  private register;
@@ -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`.
package/typings.d.ts CHANGED
@@ -13,9 +13,9 @@ export type Constructor<T = unknown> = new (...args: any[]) => T;
13
13
  export type Dictionary<T = any> = {
14
14
  [k: string]: T;
15
15
  };
16
- export type EntityKey<T = unknown, B extends boolean = false> = string & keyof {
17
- [K in keyof T as CleanKeys<T, K, B>]?: unknown;
18
- };
16
+ export type EntityKey<T = unknown, B extends boolean = false> = string & {
17
+ [K in keyof T]-?: CleanKeys<T, K, B> extends never ? never : K;
18
+ }[keyof T];
19
19
  export type EntityValue<T> = T[EntityKey<T>];
20
20
  export type FilterKey<T> = keyof FilterQuery<T>;
21
21
  export type AsyncFunction<R = any, T = Dictionary> = (args: T) => Promise<T>;
@@ -126,7 +126,7 @@ export type ExpandQuery<T> = T extends object ? T extends Scalar ? never : Filte
126
126
  export type EntityProps<T> = {
127
127
  -readonly [K in EntityKey<T>]?: T[K];
128
128
  };
129
- export type ObjectQuery<T> = OperatorMap<T> & ExpandObject<T>;
129
+ export type ObjectQuery<T> = OperatorMap<T> & FilterObject<T>;
130
130
  export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T>>> | NonNullable<EntityProps<T> & OperatorMap<T>> | FilterQuery<T>[];
131
131
  export type QBFilterQuery<T = any> = ObjectQuery<T> | Dictionary;
132
132
  export interface IWrappedEntity<Entity extends object> {