@mikro-orm/core 7.0.0-dev.153 → 7.0.0-dev.155
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 +18 -15
- package/index.d.ts +1 -1
- package/metadata/MetadataDiscovery.js +1 -1
- package/metadata/types.d.ts +2 -2
- package/package.json +1 -1
- package/typings.d.ts +15 -3
- 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
|
/**
|
|
@@ -370,25 +370,28 @@ export declare class OneToManyOptionsBuilderOnlyMappedBy<Value extends object> e
|
|
|
370
370
|
kind: '1:m';
|
|
371
371
|
}, IncludeKeysForOneToManyOptions>, IncludeKeysForOneToManyOptions>;
|
|
372
372
|
}
|
|
373
|
+
type EntityTarget = {
|
|
374
|
+
'~entity': any;
|
|
375
|
+
} | EntityClass;
|
|
373
376
|
declare const propertyBuilders: {
|
|
374
377
|
bigint: <Mode extends "bigint" | "number" | "string" = "bigint">(mode?: Mode) => UniversalPropertyOptionsBuilder<(Mode extends "bigint" ? bigint : Mode extends "number" ? number : string) & {}, EmptyOptions, IncludeKeysForProperty>;
|
|
375
378
|
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => UniversalPropertyOptionsBuilder<T[], EmptyOptions, IncludeKeysForProperty>;
|
|
376
379
|
decimal: <Mode extends "number" | "string" = "string">(mode?: Mode) => UniversalPropertyOptionsBuilder<NonNullable<Mode extends "number" ? number : string>, EmptyOptions, IncludeKeysForProperty>;
|
|
377
380
|
json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
378
|
-
formula: <T>(formula: string |
|
|
381
|
+
formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
379
382
|
datetime: (length?: number) => UniversalPropertyOptionsBuilder<Date, EmptyOptions, IncludeKeysForProperty>;
|
|
380
383
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
381
384
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
382
385
|
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => UniversalPropertyOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T, EmptyOptions, IncludeKeysForEnumOptions>;
|
|
383
|
-
embedded: <Target extends
|
|
384
|
-
manyToMany: <Target extends
|
|
386
|
+
embedded: <Target extends EntityTarget | EntityTarget[]>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions, IncludeKeysForEmbeddedOptions>;
|
|
387
|
+
manyToMany: <Target extends EntityTarget>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target>, EmptyOptions & {
|
|
385
388
|
kind: "m:n";
|
|
386
389
|
}, IncludeKeysForManyToManyOptions>;
|
|
387
|
-
manyToOne: <Target extends
|
|
390
|
+
manyToOne: <Target extends EntityTarget>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target>, EmptyOptions & {
|
|
388
391
|
kind: "m:1";
|
|
389
392
|
}, IncludeKeysForManyToOneOptions>;
|
|
390
|
-
oneToMany: <Target extends
|
|
391
|
-
oneToOne: <Target extends
|
|
393
|
+
oneToMany: <Target extends EntityTarget>(target: Target) => OneToManyOptionsBuilderOnlyMappedBy<InferEntity<Target>>;
|
|
394
|
+
oneToOne: <Target extends EntityTarget>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target>, EmptyOptions & {
|
|
392
395
|
kind: "1:1";
|
|
393
396
|
}, IncludeKeysForOneToOneOptions>;
|
|
394
397
|
date: () => UniversalPropertyOptionsBuilder<string, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -449,20 +452,20 @@ export declare namespace defineEntity {
|
|
|
449
452
|
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => UniversalPropertyOptionsBuilder<T[], EmptyOptions, IncludeKeysForProperty>;
|
|
450
453
|
decimal: <Mode extends "number" | "string" = "string">(mode?: Mode) => UniversalPropertyOptionsBuilder<NonNullable<Mode extends "number" ? number : string>, EmptyOptions, IncludeKeysForProperty>;
|
|
451
454
|
json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
452
|
-
formula: <T>(formula: string |
|
|
455
|
+
formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
453
456
|
datetime: (length?: number) => UniversalPropertyOptionsBuilder<Date, EmptyOptions, IncludeKeysForProperty>;
|
|
454
457
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
455
458
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
456
459
|
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => UniversalPropertyOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T, EmptyOptions, IncludeKeysForEnumOptions>;
|
|
457
|
-
embedded: <Target extends
|
|
458
|
-
manyToMany: <Target extends
|
|
460
|
+
embedded: <Target extends EntityTarget | EntityTarget[]>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions, IncludeKeysForEmbeddedOptions>;
|
|
461
|
+
manyToMany: <Target extends EntityTarget>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target>, EmptyOptions & {
|
|
459
462
|
kind: "m:n";
|
|
460
463
|
}, IncludeKeysForManyToManyOptions>;
|
|
461
|
-
manyToOne: <Target extends
|
|
464
|
+
manyToOne: <Target extends EntityTarget>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target>, EmptyOptions & {
|
|
462
465
|
kind: "m:1";
|
|
463
466
|
}, IncludeKeysForManyToOneOptions>;
|
|
464
|
-
oneToMany: <Target extends
|
|
465
|
-
oneToOne: <Target extends
|
|
467
|
+
oneToMany: <Target extends EntityTarget>(target: Target) => OneToManyOptionsBuilderOnlyMappedBy<InferEntity<Target>>;
|
|
468
|
+
oneToOne: <Target extends EntityTarget>(target: Target) => UniversalPropertyOptionsBuilder<InferEntity<Target>, EmptyOptions & {
|
|
466
469
|
kind: "1:1";
|
|
467
470
|
}, IncludeKeysForOneToOneOptions>;
|
|
468
471
|
date: () => UniversalPropertyOptionsBuilder<string, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -566,7 +569,7 @@ type MaybeOpt<Value, Options> = Options extends {
|
|
|
566
569
|
} ? Opt<Value> : Options extends {
|
|
567
570
|
version: true;
|
|
568
571
|
} ? Opt<Value> : Options extends {
|
|
569
|
-
formula: string | (() => string);
|
|
572
|
+
formula: string | ((...args: any[]) => string);
|
|
570
573
|
} ? Opt<Value> : Value;
|
|
571
574
|
type MaybeHidden<Value, Options> = Options extends {
|
|
572
575
|
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';
|
|
@@ -1241,7 +1241,7 @@ export class MetadataDiscovery {
|
|
|
1241
1241
|
prop.referencedPKs = meta2.primaryKeys;
|
|
1242
1242
|
prop.targetMeta = meta2;
|
|
1243
1243
|
if (!prop.formula && prop.persist === false && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && !prop.embedded) {
|
|
1244
|
-
prop.formula =
|
|
1244
|
+
prop.formula = table => `${table}.${this.platform.quoteIdentifier(prop.fieldNames[0])}`;
|
|
1245
1245
|
}
|
|
1246
1246
|
}
|
|
1247
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.155",
|
|
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;
|
|
@@ -864,6 +872,10 @@ export interface EntitySchemaWithMeta<TName extends string = string, TTableName
|
|
|
864
872
|
readonly name: TName;
|
|
865
873
|
readonly properties: TProperties;
|
|
866
874
|
readonly tableName: TTableName;
|
|
875
|
+
/** @internal Direct entity type access - avoids expensive pattern matching */
|
|
876
|
+
readonly '~entity': TEntity;
|
|
867
877
|
}
|
|
868
|
-
export type InferEntity<Schema> = Schema extends
|
|
878
|
+
export type InferEntity<Schema> = Schema extends {
|
|
879
|
+
'~entity': infer E;
|
|
880
|
+
} ? E : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;
|
|
869
881
|
export {};
|
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.155';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|