@mikro-orm/core 6.2.10-dev.9 → 6.2.10-dev.91

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 (84) hide show
  1. package/EntityManager.d.ts +1 -2
  2. package/EntityManager.js +26 -24
  3. package/decorators/Check.js +1 -2
  4. package/decorators/CreateRequestContext.js +2 -3
  5. package/decorators/Embeddable.js +1 -2
  6. package/decorators/Embedded.js +1 -2
  7. package/decorators/Entity.js +1 -2
  8. package/decorators/Enum.js +1 -2
  9. package/decorators/Filter.js +1 -2
  10. package/decorators/Formula.js +1 -2
  11. package/decorators/Indexed.d.ts +3 -3
  12. package/decorators/Indexed.js +2 -3
  13. package/decorators/ManyToMany.js +1 -2
  14. package/decorators/ManyToOne.js +1 -2
  15. package/decorators/OneToMany.js +2 -3
  16. package/decorators/OneToOne.d.ts +1 -1
  17. package/decorators/OneToOne.js +1 -2
  18. package/decorators/PrimaryKey.d.ts +3 -2
  19. package/decorators/PrimaryKey.js +2 -3
  20. package/decorators/Property.d.ts +1 -1
  21. package/decorators/Property.js +1 -2
  22. package/decorators/hooks.js +10 -11
  23. package/drivers/DatabaseDriver.js +1 -1
  24. package/drivers/IDatabaseDriver.d.ts +2 -1
  25. package/entity/ArrayCollection.d.ts +0 -1
  26. package/entity/EntityIdentifier.d.ts +1 -1
  27. package/entity/EntityLoader.js +3 -0
  28. package/entity/Reference.d.ts +0 -1
  29. package/entity/Reference.js +10 -7
  30. package/entity/WrappedEntity.d.ts +0 -1
  31. package/entity/wrap.js +2 -3
  32. package/events/TransactionEventBroadcaster.d.ts +2 -2
  33. package/index.d.ts +1 -1
  34. package/index.mjs +1 -0
  35. package/metadata/MetadataDiscovery.js +6 -4
  36. package/naming-strategy/AbstractNamingStrategy.d.ts +13 -0
  37. package/naming-strategy/AbstractNamingStrategy.js +25 -0
  38. package/naming-strategy/NamingStrategy.d.ts +27 -1
  39. package/package.json +2 -2
  40. package/platforms/Platform.d.ts +6 -2
  41. package/platforms/Platform.js +17 -5
  42. package/serialization/EntitySerializer.js +2 -2
  43. package/serialization/SerializationContext.d.ts +2 -2
  44. package/types/BigIntType.d.ts +2 -2
  45. package/types/BigIntType.js +1 -1
  46. package/types/BlobType.d.ts +0 -1
  47. package/types/CharacterType.d.ts +7 -0
  48. package/types/CharacterType.js +13 -0
  49. package/types/DateTimeType.d.ts +1 -0
  50. package/types/DateTimeType.js +3 -0
  51. package/types/DateType.d.ts +1 -0
  52. package/types/DateType.js +3 -0
  53. package/types/DecimalType.d.ts +2 -2
  54. package/types/IntervalType.d.ts +1 -0
  55. package/types/IntervalType.js +3 -0
  56. package/types/JsonType.js +1 -1
  57. package/types/StringType.d.ts +1 -0
  58. package/types/StringType.js +3 -0
  59. package/types/TimeType.d.ts +1 -0
  60. package/types/TimeType.js +3 -0
  61. package/types/Type.d.ts +16 -2
  62. package/types/Uint8ArrayType.d.ts +0 -1
  63. package/types/index.d.ts +19 -16
  64. package/types/index.js +34 -31
  65. package/typings.d.ts +24 -19
  66. package/unit-of-work/ChangeSet.d.ts +0 -1
  67. package/unit-of-work/ChangeSetPersister.d.ts +1 -1
  68. package/unit-of-work/ChangeSetPersister.js +5 -3
  69. package/unit-of-work/UnitOfWork.d.ts +1 -1
  70. package/unit-of-work/UnitOfWork.js +32 -18
  71. package/utils/Configuration.js +2 -2
  72. package/utils/ConfigurationLoader.js +1 -0
  73. package/utils/Cursor.d.ts +0 -1
  74. package/utils/DataloaderUtils.d.ts +3 -3
  75. package/utils/DataloaderUtils.js +4 -4
  76. package/utils/EntityComparator.d.ts +13 -0
  77. package/utils/EntityComparator.js +62 -34
  78. package/utils/RawQueryFragment.d.ts +1 -2
  79. package/utils/RawQueryFragment.js +4 -4
  80. package/utils/Utils.d.ts +4 -6
  81. package/utils/Utils.js +13 -10
  82. package/utils/clone.js +1 -2
  83. package/utils/upsert-utils.d.ts +3 -2
  84. package/utils/upsert-utils.js +4 -5
package/index.mjs CHANGED
@@ -25,6 +25,7 @@ export const ChangeSet = mod.ChangeSet;
25
25
  export const ChangeSetComputer = mod.ChangeSetComputer;
26
26
  export const ChangeSetPersister = mod.ChangeSetPersister;
27
27
  export const ChangeSetType = mod.ChangeSetType;
28
+ export const CharacterType = mod.CharacterType;
28
29
  export const Check = mod.Check;
29
30
  export const CheckConstraintViolationException = mod.CheckConstraintViolationException;
30
31
  export const Collection = mod.Collection;
@@ -109,7 +109,7 @@ class MetadataDiscovery {
109
109
  }
110
110
  }
111
111
  }
112
- filtered.forEach(meta => Object.values(meta.properties).forEach(prop => this.initIndexes(prop)));
112
+ filtered.forEach(meta => Object.values(meta.properties).forEach(prop => this.initIndexes(meta, prop)));
113
113
  filtered.forEach(meta => this.autoWireBidirectionalProperties(meta));
114
114
  filtered.forEach(meta => this.findReferencingProperties(meta, filtered));
115
115
  for (const meta of filtered) {
@@ -1147,7 +1147,8 @@ class MetadataDiscovery {
1147
1147
  && !SCALAR_TYPES.includes(prop.type)
1148
1148
  // or it might be inferred via ts-morph to some generic type alias
1149
1149
  && !prop.type.match(/[<>:"';{}]/)) {
1150
- prop.columnTypes = [prop.type];
1150
+ const type = prop.length != null && !prop.type.endsWith(`(${prop.length})`) ? `${prop.type}(${prop.length})` : prop.type;
1151
+ prop.columnTypes = [type];
1151
1152
  }
1152
1153
  else {
1153
1154
  prop.columnTypes = [mappedType.getColumnType(prop, this.platform)];
@@ -1204,8 +1205,9 @@ class MetadataDiscovery {
1204
1205
  }
1205
1206
  prop.unsigned ??= (prop.primary || prop.unsigned) && this.isNumericProperty(prop) && this.platform.supportsUnsigned();
1206
1207
  }
1207
- initIndexes(prop) {
1208
- if (prop.kind === enums_1.ReferenceKind.MANY_TO_ONE && this.platform.indexForeignKeys()) {
1208
+ initIndexes(meta, prop) {
1209
+ const hasIndex = meta.indexes.some(idx => idx.properties?.length === 1 && idx.properties[0] === prop.name);
1210
+ if (prop.kind === enums_1.ReferenceKind.MANY_TO_ONE && this.platform.indexForeignKeys() && !hasIndex) {
1209
1211
  prop.index ??= true;
1210
1212
  }
1211
1213
  }
@@ -1,4 +1,5 @@
1
1
  import type { NamingStrategy } from './NamingStrategy';
2
+ import { type ReferenceKind } from '../enums';
2
3
  export declare abstract class AbstractNamingStrategy implements NamingStrategy {
3
4
  getClassName(file: string, separator?: string): string;
4
5
  classToMigrationName(timestamp: string, customMigrationName?: string): string;
@@ -8,7 +9,19 @@ export declare abstract class AbstractNamingStrategy implements NamingStrategy {
8
9
  */
9
10
  getEntityName(tableName: string, schemaName?: string): string;
10
11
  columnNameToProperty(columnName: string): string;
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ getEnumClassName(columnName: string, tableName: string, schemaName?: string): string;
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ enumValueToEnumProperty(enumValue: string, columnName: string, tableName: string, schemaName?: string): string;
11
20
  aliasName(entityName: string, index: number): string;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
12
25
  abstract classToTableName(entityName: string): string;
13
26
  abstract joinColumnName(propertyName: string): string;
14
27
  abstract joinKeyColumnName(entityName: string, referencedColumnName?: string): string;
@@ -47,9 +47,34 @@ class AbstractNamingStrategy {
47
47
  }
48
48
  return propName;
49
49
  }
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ getEnumClassName(columnName, tableName, schemaName) {
54
+ return this.getEntityName(`${tableName}_${columnName}`, schemaName);
55
+ }
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ enumValueToEnumProperty(enumValue, columnName, tableName, schemaName) {
60
+ return enumValue.toUpperCase();
61
+ }
50
62
  aliasName(entityName, index) {
51
63
  // Take only the first letter of the prefix to keep character counts down since some engines have character limits
52
64
  return entityName.charAt(0).toLowerCase() + index;
53
65
  }
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ inverseSideName(entityName, propertyName, kind) {
70
+ if (kind === 'm:n') {
71
+ return propertyName + 'Inverse';
72
+ }
73
+ const suffix = kind === '1:m' && !entityName.endsWith('Collection') ? 'Collection' : '';
74
+ if (entityName.length === 1) {
75
+ return entityName[0].toLowerCase() + suffix;
76
+ }
77
+ return entityName[0].toLowerCase() + entityName.substring(1) + suffix;
78
+ }
54
79
  }
55
80
  exports.AbstractNamingStrategy = AbstractNamingStrategy;
@@ -1,3 +1,4 @@
1
+ import type { ReferenceKind } from '../enums';
1
2
  export interface NamingStrategy {
2
3
  /**
3
4
  * Return a name of the class based on its file name
@@ -15,6 +16,27 @@ export interface NamingStrategy {
15
16
  * Return a column name for a property
16
17
  */
17
18
  propertyToColumnName(propertyName: string, object?: boolean): string;
19
+ /**
20
+ * Get an enum class name.
21
+ *
22
+ * @param columnName The column name which has the enum.
23
+ * @param tableName The table name of the column.
24
+ * @param schemaName The schema name of the column.
25
+ *
26
+ * @return A new class name that will be used for the enum.
27
+ */
28
+ getEnumClassName(columnName: string, tableName: string, schemaName?: string): string;
29
+ /**
30
+ * Get an enum option name for a given enum value.
31
+ *
32
+ * @param enumValue The enum value to generate a name for.
33
+ * @param columnName The column name which has the enum.
34
+ * @param tableName The table name of the column.
35
+ * @param schemaName The schema name of the column.
36
+ *
37
+ * @return The name of the enum property that will hold the value.
38
+ */
39
+ enumValueToEnumProperty(enumValue: string, columnName: string, tableName: string, schemaName?: string): string;
18
40
  /**
19
41
  * Return a name of the entity class based on database table name (used in `EntityGenerator`).
20
42
  * Default implementation ignores the schema name.
@@ -41,7 +63,7 @@ export interface NamingStrategy {
41
63
  */
42
64
  joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean): string;
43
65
  /**
44
- * Returns key/constraint name for given type. Some drivers might not support all the types (e.g. mysql and sqlite enforce the PK name).
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).
45
67
  */
46
68
  indexName(tableName: string, columns: string[], type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check'): string;
47
69
  /**
@@ -49,4 +71,8 @@ export interface NamingStrategy {
49
71
  * ensured via appended index parameter. It is optional to use it as long as you ensure it will be unique.
50
72
  */
51
73
  aliasName(entityName: string, index: number): string;
74
+ /**
75
+ * Returns the name of the inverse side property. Used in the `EntityGenerator` with `bidirectionalRelations` option.
76
+ */
77
+ inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
52
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.2.10-dev.9",
3
+ "version": "6.2.10-dev.91",
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.9",
67
+ "mikro-orm": "6.2.10-dev.91",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -58,6 +58,8 @@ export declare abstract class Platform {
58
58
  length?: number;
59
59
  }): string;
60
60
  getDefaultDateTimeLength(): number;
61
+ getDefaultVarcharLength(): number;
62
+ getDefaultCharLength(): number;
61
63
  getDateTypeDeclarationSQL(length?: number): string;
62
64
  getTimeTypeDeclarationSQL(length?: number): string;
63
65
  getRegExpOperator(val?: unknown, flags?: string): string;
@@ -69,7 +71,6 @@ export declare abstract class Platform {
69
71
  quoteVersionValue(value: Date | number, prop: EntityProperty): Date | string | number;
70
72
  getDefaultVersionLength(): number;
71
73
  allowsComparingTuples(): boolean;
72
- allowsUniqueBatchUpdates(): boolean;
73
74
  isBigIntProperty(prop: EntityProperty): boolean;
74
75
  isRaw(value: any): boolean;
75
76
  getDefaultSchemaName(): string | undefined;
@@ -99,6 +100,9 @@ export declare abstract class Platform {
99
100
  unsigned?: boolean;
100
101
  autoincrement?: boolean;
101
102
  }): string;
103
+ getCharTypeDeclarationSQL(column: {
104
+ length?: number;
105
+ }): string;
102
106
  getVarcharTypeDeclarationSQL(column: {
103
107
  length?: number;
104
108
  }): string;
@@ -144,7 +148,7 @@ export declare abstract class Platform {
144
148
  getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
145
149
  convertsJsonAutomatically(): boolean;
146
150
  convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
147
- convertJsonToJSValue(value: unknown): unknown;
151
+ convertJsonToJSValue(value: unknown, prop: EntityProperty): unknown;
148
152
  convertDateToJSValue(value: string | Date): string;
149
153
  convertIntervalToJSValue(value: string): unknown;
150
154
  convertIntervalToDatabaseValue(value: unknown): unknown;
@@ -96,6 +96,12 @@ class Platform {
96
96
  getDefaultDateTimeLength() {
97
97
  return 0;
98
98
  }
99
+ getDefaultVarcharLength() {
100
+ return 255;
101
+ }
102
+ getDefaultCharLength() {
103
+ return 1;
104
+ }
99
105
  getDateTypeDeclarationSQL(length) {
100
106
  return 'date' + (length ? `(${length})` : '');
101
107
  }
@@ -123,9 +129,6 @@ class Platform {
123
129
  allowsComparingTuples() {
124
130
  return true;
125
131
  }
126
- allowsUniqueBatchUpdates() {
127
- return true;
128
- }
129
132
  isBigIntProperty(prop) {
130
133
  return prop.columnTypes && prop.columnTypes[0] === 'bigint';
131
134
  }
@@ -153,8 +156,11 @@ class Platform {
153
156
  getBigIntTypeDeclarationSQL(column) {
154
157
  return 'bigint';
155
158
  }
159
+ getCharTypeDeclarationSQL(column) {
160
+ return `char(${column.length ?? this.getDefaultCharLength()})`;
161
+ }
156
162
  getVarcharTypeDeclarationSQL(column) {
157
- return `varchar(${column.length ?? 255})`;
163
+ return `varchar(${column.length ?? this.getDefaultVarcharLength()})`;
158
164
  }
159
165
  getIntervalTypeDeclarationSQL(column) {
160
166
  return 'interval' + (column.length ? `(${column.length})` : '');
@@ -195,6 +201,8 @@ class Platform {
195
201
  return types_1.Type.getType(types_1.ArrayType);
196
202
  }
197
203
  switch (this.extractSimpleType(type)) {
204
+ case 'character':
205
+ case 'char': return types_1.Type.getType(types_1.CharacterType);
198
206
  case 'string':
199
207
  case 'varchar': return types_1.Type.getType(types_1.StringType);
200
208
  case 'interval': return types_1.Type.getType(types_1.IntervalType);
@@ -274,7 +282,11 @@ class Platform {
274
282
  convertJsonToDatabaseValue(value, context) {
275
283
  return JSON.stringify(value);
276
284
  }
277
- convertJsonToJSValue(value) {
285
+ convertJsonToJSValue(value, prop) {
286
+ const isObjectEmbedded = prop.embedded && prop.object;
287
+ if ((this.convertsJsonAutomatically() || isObjectEmbedded) && ['json', 'jsonb', this.getJsonDeclarationSQL()].includes(prop.columnTypes[0])) {
288
+ return value;
289
+ }
278
290
  return (0, Utils_1.parseJsonSafe)(value);
279
291
  }
280
292
  convertDateToJSValue(value) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serialize = exports.EntitySerializer = void 0;
3
+ exports.EntitySerializer = void 0;
4
+ exports.serialize = serialize;
4
5
  const wrap_1 = require("../entity/wrap");
5
6
  const Utils_1 = require("../utils/Utils");
6
7
  const enums_1 = require("../enums");
@@ -210,4 +211,3 @@ function serialize(entities, options) {
210
211
  }
211
212
  return EntitySerializer.serialize(entities, options);
212
213
  }
213
- exports.serialize = serialize;
@@ -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,8 +6,8 @@ import type { EntityProperty } from '../typings';
6
6
  * or numbers (safe only for values up to `Number.MAX_SAFE_INTEGER`), or strings, depending on the `mode`.
7
7
  */
8
8
  export declare class BigIntType extends Type<string | bigint | number | null | undefined, string | null | undefined> {
9
- mode?: "string" | "number" | "bigint" | undefined;
10
- constructor(mode?: "string" | "number" | "bigint" | undefined);
9
+ mode?: ("bigint" | "number" | "string") | undefined;
10
+ constructor(mode?: ("bigint" | "number" | "string") | undefined);
11
11
  convertToDatabaseValue(value: string | bigint | null | undefined): string | null | undefined;
12
12
  convertToJSValue(value: string | bigint | null | undefined): bigint | number | string | null | undefined;
13
13
  toJSON(value: string | bigint | null | undefined): string | bigint | null | undefined;
@@ -29,7 +29,7 @@ class BigIntType extends Type_1.Type {
29
29
  return String(value);
30
30
  case 'bigint':
31
31
  default:
32
- return BigInt(value);
32
+ return BigInt(String(value));
33
33
  }
34
34
  }
35
35
  toJSON(value) {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Uint8ArrayType } from './Uint8ArrayType';
3
2
  import type { Platform } from '../platforms';
4
3
  import type { EntityProperty } from '../typings';
@@ -0,0 +1,7 @@
1
+ import { StringType } from './StringType';
2
+ import type { Platform } from '../platforms';
3
+ import type { EntityProperty } from '../typings';
4
+ export declare class CharacterType extends StringType {
5
+ getColumnType(prop: EntityProperty, platform: Platform): string;
6
+ getDefaultLength(platform: Platform): number;
7
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CharacterType = void 0;
4
+ const StringType_1 = require("./StringType");
5
+ class CharacterType extends StringType_1.StringType {
6
+ getColumnType(prop, platform) {
7
+ return platform.getCharTypeDeclarationSQL(prop);
8
+ }
9
+ getDefaultLength(platform) {
10
+ return platform.getDefaultCharLength();
11
+ }
12
+ }
13
+ exports.CharacterType = CharacterType;
@@ -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,8 +5,8 @@ import type { EntityProperty } from '../typings';
5
5
  * Type that maps an SQL DECIMAL to a JS string or number.
6
6
  */
7
7
  export declare class DecimalType extends Type<string | number, string> {
8
- mode?: "string" | "number" | undefined;
9
- constructor(mode?: "string" | "number" | undefined);
8
+ mode?: ("number" | "string") | undefined;
9
+ constructor(mode?: ("number" | "string") | undefined);
10
10
  convertToJSValue(value: string): number | string;
11
11
  getColumnType(prop: EntityProperty, platform: Platform): string;
12
12
  compareAsType(): string;
@@ -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;
package/types/JsonType.js CHANGED
@@ -16,7 +16,7 @@ class JsonType extends Type_1.Type {
16
16
  return key + platform.castColumn(this.prop);
17
17
  }
18
18
  convertToJSValue(value, platform) {
19
- return platform.convertJsonToJSValue(value);
19
+ return platform.convertJsonToJSValue(value, this.prop);
20
20
  }
21
21
  getColumnType(prop, platform) {
22
22
  return platform.getJsonDeclarationSQL();
@@ -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
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { inspect } from 'util';
3
2
  import type { Platform } from '../platforms';
4
3
  import type { Constructor, EntityMetadata, EntityProperty } from '../typings';
@@ -59,7 +58,22 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
59
58
  * Gets the SQL declaration snippet for a field of this type.
60
59
  */
61
60
  getColumnType(prop: EntityProperty, platform: Platform): string;
62
- static getType<JSType, DBType = JSType>(cls: Constructor<Type<JSType, DBType>>): Type<JSType, DBType>;
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;
76
+ static getType<JSType, DBType = JSType, TypeClass extends Constructor<Type<JSType, DBType>> = Constructor<Type<JSType, DBType>>>(cls: TypeClass): InstanceType<TypeClass>;
63
77
  /**
64
78
  * Checks whether the argument is instance of `Type`.
65
79
  */
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Type } from './Type';
3
2
  import type { Platform } from '../platforms';
4
3
  import type { EntityProperty } from '../typings';
package/types/index.d.ts CHANGED
@@ -1,28 +1,29 @@
1
- import { Type, TransformContext, IType } from './Type';
2
- import { DateType } from './DateType';
3
- import { TimeType } from './TimeType';
4
- import { DateTimeType } from './DateTimeType';
1
+ import { ArrayType } from './ArrayType';
5
2
  import { BigIntType } from './BigIntType';
6
3
  import { BlobType } from './BlobType';
7
- import { Uint8ArrayType } from './Uint8ArrayType';
8
- import { ArrayType } from './ArrayType';
4
+ import { BooleanType } from './BooleanType';
5
+ import { DateTimeType } from './DateTimeType';
6
+ import { DateType } from './DateType';
7
+ import { DecimalType } from './DecimalType';
8
+ import { DoubleType } from './DoubleType';
9
9
  import { EnumArrayType } from './EnumArrayType';
10
10
  import { EnumType } from './EnumType';
11
- import { JsonType } from './JsonType';
11
+ import { CharacterType } from './CharacterType';
12
+ import { FloatType } from './FloatType';
12
13
  import { IntegerType } from './IntegerType';
13
- import { SmallIntType } from './SmallIntType';
14
- import { TinyIntType } from './TinyIntType';
14
+ import { IntervalType } from './IntervalType';
15
+ import { JsonType } from './JsonType';
15
16
  import { MediumIntType } from './MediumIntType';
16
- import { FloatType } from './FloatType';
17
- import { DoubleType } from './DoubleType';
18
- import { BooleanType } from './BooleanType';
19
- import { DecimalType } from './DecimalType';
17
+ import { SmallIntType } from './SmallIntType';
20
18
  import { StringType } from './StringType';
21
- import { UuidType } from './UuidType';
22
19
  import { TextType } from './TextType';
23
- import { IntervalType } from './IntervalType';
20
+ import { TimeType } from './TimeType';
21
+ import { TinyIntType } from './TinyIntType';
22
+ import { IType, TransformContext, Type } from './Type';
23
+ import { Uint8ArrayType } from './Uint8ArrayType';
24
24
  import { UnknownType } from './UnknownType';
25
- export { Type, DateType, TimeType, DateTimeType, BigIntType, BlobType, Uint8ArrayType, ArrayType, EnumArrayType, EnumType, JsonType, IntegerType, SmallIntType, TinyIntType, MediumIntType, FloatType, DoubleType, BooleanType, DecimalType, StringType, UuidType, TextType, UnknownType, TransformContext, IntervalType, IType, };
25
+ import { UuidType } from './UuidType';
26
+ export { Type, DateType, TimeType, DateTimeType, BigIntType, BlobType, Uint8ArrayType, ArrayType, EnumArrayType, EnumType, JsonType, IntegerType, SmallIntType, TinyIntType, MediumIntType, FloatType, DoubleType, BooleanType, DecimalType, StringType, UuidType, TextType, UnknownType, TransformContext, IntervalType, IType, CharacterType, };
26
27
  export declare const types: {
27
28
  readonly date: typeof DateType;
28
29
  readonly time: typeof TimeType;
@@ -42,6 +43,7 @@ export declare const types: {
42
43
  readonly double: typeof DoubleType;
43
44
  readonly boolean: typeof BooleanType;
44
45
  readonly decimal: typeof DecimalType;
46
+ readonly character: typeof CharacterType;
45
47
  readonly string: typeof StringType;
46
48
  readonly uuid: typeof UuidType;
47
49
  readonly text: typeof TextType;
@@ -67,6 +69,7 @@ export declare const t: {
67
69
  readonly double: typeof DoubleType;
68
70
  readonly boolean: typeof BooleanType;
69
71
  readonly decimal: typeof DecimalType;
72
+ readonly character: typeof CharacterType;
70
73
  readonly string: typeof StringType;
71
74
  readonly uuid: typeof UuidType;
72
75
  readonly text: typeof TextType;