@mikro-orm/core 7.0.0-dev.152 → 7.0.0-dev.154
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/entity/defineEntity.d.ts +5 -5
- package/index.d.ts +1 -1
- package/metadata/EntitySchema.js +11 -2
- package/metadata/MetadataDiscovery.js +3 -2
- package/metadata/types.d.ts +2 -2
- package/package.json +1 -1
- package/typings.d.ts +10 -2
- package/utils/Utils.js +1 -1
package/entity/defineEntity.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EntityManager } from '../EntityManager.js';
|
|
2
2
|
import type { ColumnType, PropertyOptions, ReferenceOptions, EnumOptions, EmbeddedOptions, ManyToOneOptions, OneToManyOptions, OneToOneOptions, ManyToManyOptions } from '../metadata/types.js';
|
|
3
|
-
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, IndexCallback, EntityCtor, IsNever } from '../typings.js';
|
|
3
|
+
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, IndexCallback, FormulaCallback, EntityCtor, IsNever } from '../typings.js';
|
|
4
4
|
import type { ScalarReference } from './Reference.js';
|
|
5
5
|
import type { SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
6
6
|
import type { Cascade, DeferMode, EmbeddedPrefixMode, EventType, LoadStrategy, QueryOrderMap } from '../enums.js';
|
|
@@ -139,7 +139,7 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
139
139
|
*
|
|
140
140
|
* @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
|
|
141
141
|
*/
|
|
142
|
-
formula<T extends string | (
|
|
142
|
+
formula<T extends string | FormulaCallback<any>>(formula: T): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'formula'> & {
|
|
143
143
|
formula: T;
|
|
144
144
|
}, IncludeKeys>, IncludeKeys>;
|
|
145
145
|
/**
|
|
@@ -375,7 +375,7 @@ declare const propertyBuilders: {
|
|
|
375
375
|
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => UniversalPropertyOptionsBuilder<T[], EmptyOptions, IncludeKeysForProperty>;
|
|
376
376
|
decimal: <Mode extends "number" | "string" = "string">(mode?: Mode) => UniversalPropertyOptionsBuilder<NonNullable<Mode extends "number" ? number : string>, EmptyOptions, IncludeKeysForProperty>;
|
|
377
377
|
json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
378
|
-
formula: <T>(formula: string |
|
|
378
|
+
formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
379
379
|
datetime: (length?: number) => UniversalPropertyOptionsBuilder<Date, EmptyOptions, IncludeKeysForProperty>;
|
|
380
380
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
381
381
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -449,7 +449,7 @@ export declare namespace defineEntity {
|
|
|
449
449
|
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => UniversalPropertyOptionsBuilder<T[], EmptyOptions, IncludeKeysForProperty>;
|
|
450
450
|
decimal: <Mode extends "number" | "string" = "string">(mode?: Mode) => UniversalPropertyOptionsBuilder<NonNullable<Mode extends "number" ? number : string>, EmptyOptions, IncludeKeysForProperty>;
|
|
451
451
|
json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
452
|
-
formula: <T>(formula: string |
|
|
452
|
+
formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
453
453
|
datetime: (length?: number) => UniversalPropertyOptionsBuilder<Date, EmptyOptions, IncludeKeysForProperty>;
|
|
454
454
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
455
455
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -566,7 +566,7 @@ type MaybeOpt<Value, Options> = Options extends {
|
|
|
566
566
|
} ? Opt<Value> : Options extends {
|
|
567
567
|
version: true;
|
|
568
568
|
} ? Opt<Value> : Options extends {
|
|
569
|
-
formula: string | (() => string);
|
|
569
|
+
formula: string | ((...args: any[]) => string);
|
|
570
570
|
} ? Opt<Value> : Value;
|
|
571
571
|
type MaybeHidden<Value, Options> = Options extends {
|
|
572
572
|
hidden: true;
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
5
|
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
6
|
-
export type { Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, RequiredEntityData, CheckCallback, IndexCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, FilterValue, MergeLoaded, MergeSelected, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, DefineConfig, Opt, Hidden, EntitySchemaWithMeta, InferEntity, CheckConstraint, GeneratedColumnCallback, FilterDef, EntityCtor, } from './typings.js';
|
|
6
|
+
export type { Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, RequiredEntityData, CheckCallback, IndexCallback, FormulaCallback, FormulaTable, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, FilterValue, MergeLoaded, MergeSelected, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, DefineConfig, Opt, Hidden, EntitySchemaWithMeta, InferEntity, CheckConstraint, GeneratedColumnCallback, FilterDef, EntityCtor, } from './typings.js';
|
|
7
7
|
export * from './enums.js';
|
|
8
8
|
export * from './errors.js';
|
|
9
9
|
export * from './exceptions.js';
|
package/metadata/EntitySchema.js
CHANGED
|
@@ -151,7 +151,8 @@ export class EntitySchema {
|
|
|
151
151
|
this._meta.extends = base;
|
|
152
152
|
}
|
|
153
153
|
setClass(cls) {
|
|
154
|
-
const
|
|
154
|
+
const oldClass = this._meta.class;
|
|
155
|
+
const sameClass = this._meta.class === cls;
|
|
155
156
|
this._meta.class = cls;
|
|
156
157
|
this._meta.prototype = cls.prototype;
|
|
157
158
|
this._meta.className = this._meta.name ?? cls.name;
|
|
@@ -159,10 +160,18 @@ export class EntitySchema {
|
|
|
159
160
|
this._meta.constructorParams = Utils.getConstructorParams(cls);
|
|
160
161
|
}
|
|
161
162
|
if (!this.internal) {
|
|
163
|
+
// Remove old class from registry if it's being replaced with a different class
|
|
164
|
+
if (oldClass && oldClass !== cls && EntitySchema.REGISTRY.get(oldClass) === this) {
|
|
165
|
+
EntitySchema.REGISTRY.delete(oldClass);
|
|
166
|
+
}
|
|
162
167
|
EntitySchema.REGISTRY.set(cls, this);
|
|
163
168
|
}
|
|
164
169
|
const base = Object.getPrototypeOf(cls);
|
|
165
|
-
if
|
|
170
|
+
// Only set extends if the parent is NOT the auto-generated class for this same entity.
|
|
171
|
+
// When the user extends the auto-generated class (from defineEntity without a class option)
|
|
172
|
+
// and registers their custom class via setClass, we don't want to discover the
|
|
173
|
+
// auto-generated class as a separate parent entity.
|
|
174
|
+
if (base !== BaseEntity && base.name !== this._meta.className) {
|
|
166
175
|
this._meta.extends ??= base.name ? base : undefined;
|
|
167
176
|
}
|
|
168
177
|
}
|
|
@@ -241,7 +241,8 @@ export class MetadataDiscovery {
|
|
|
241
241
|
continue;
|
|
242
242
|
}
|
|
243
243
|
parent = Object.getPrototypeOf(meta.class);
|
|
244
|
-
if
|
|
244
|
+
// Skip if parent is the auto-generated base class for the same entity (from setClass usage)
|
|
245
|
+
if (parent.name !== '' && parent.name !== meta.className && !this.metadata.has(parent) && parent !== BaseEntity) {
|
|
245
246
|
this.discoverReferences([parent], false);
|
|
246
247
|
}
|
|
247
248
|
}
|
|
@@ -1240,7 +1241,7 @@ export class MetadataDiscovery {
|
|
|
1240
1241
|
prop.referencedPKs = meta2.primaryKeys;
|
|
1241
1242
|
prop.targetMeta = meta2;
|
|
1242
1243
|
if (!prop.formula && prop.persist === false && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && !prop.embedded) {
|
|
1243
|
-
prop.formula =
|
|
1244
|
+
prop.formula = table => `${table}.${this.platform.quoteIdentifier(prop.fieldNames[0])}`;
|
|
1244
1245
|
}
|
|
1245
1246
|
}
|
|
1246
1247
|
initColumnType(prop) {
|
package/metadata/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyEntity, Constructor, EntityName, AnyString, CheckCallback, GeneratedColumnCallback, FilterQuery, Dictionary, AutoPath, EntityClass, IndexCallback, ObjectQuery } from '../typings.js';
|
|
1
|
+
import type { AnyEntity, Constructor, EntityName, AnyString, CheckCallback, GeneratedColumnCallback, FormulaCallback, FilterQuery, Dictionary, AutoPath, EntityClass, IndexCallback, ObjectQuery } from '../typings.js';
|
|
2
2
|
import type { Cascade, LoadStrategy, DeferMode, QueryOrderMap, EmbeddedPrefixMode } from '../enums.js';
|
|
3
3
|
import type { Type, types } from '../types/index.js';
|
|
4
4
|
import type { EntityManager } from '../EntityManager.js';
|
|
@@ -119,7 +119,7 @@ export interface PropertyOptions<Owner> {
|
|
|
119
119
|
*
|
|
120
120
|
* @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
|
|
121
121
|
*/
|
|
122
|
-
formula?: string |
|
|
122
|
+
formula?: string | FormulaCallback<Owner>;
|
|
123
123
|
/**
|
|
124
124
|
* For generated columns. This will be appended to the column type after the `generated always` clause.
|
|
125
125
|
*/
|
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.
|
|
4
|
+
"version": "7.0.0-dev.154",
|
|
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
|
@@ -321,7 +321,15 @@ type TableName = {
|
|
|
321
321
|
schema?: string;
|
|
322
322
|
toString: () => string;
|
|
323
323
|
};
|
|
324
|
+
export type FormulaTable = {
|
|
325
|
+
alias: string;
|
|
326
|
+
name: string;
|
|
327
|
+
schema?: string;
|
|
328
|
+
qualifiedName: string;
|
|
329
|
+
toString: () => string;
|
|
330
|
+
};
|
|
324
331
|
export type IndexCallback<T> = (table: TableName, columns: Record<PropertyName<T>, string>, indexName: string) => string | Raw;
|
|
332
|
+
export type FormulaCallback<T> = (table: FormulaTable, columns: Record<PropertyName<T>, string>) => string;
|
|
325
333
|
export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>) => string;
|
|
326
334
|
export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
|
|
327
335
|
export interface CheckConstraint<T = any> {
|
|
@@ -359,7 +367,7 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
359
367
|
fieldNameRaw?: string;
|
|
360
368
|
default?: string | number | boolean | null;
|
|
361
369
|
defaultRaw?: string;
|
|
362
|
-
formula?:
|
|
370
|
+
formula?: FormulaCallback<Owner>;
|
|
363
371
|
filters?: FilterOptions;
|
|
364
372
|
prefix?: string | boolean;
|
|
365
373
|
prefixMode?: EmbeddedPrefixMode;
|
|
@@ -435,7 +443,7 @@ export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entit
|
|
|
435
443
|
removeProperty(name: string, sync?: boolean): void;
|
|
436
444
|
getPrimaryProps(flatten?: boolean): EntityProperty<Entity>[];
|
|
437
445
|
getPrimaryProp(): EntityProperty<Entity>;
|
|
438
|
-
createColumnMappingObject():
|
|
446
|
+
createColumnMappingObject(): Record<PropertyName<Entity>, string>;
|
|
439
447
|
get tableName(): string;
|
|
440
448
|
set tableName(name: string);
|
|
441
449
|
get uniqueName(): string;
|
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.
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.154';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|