@mikro-orm/core 6.6.5-dev.4 → 6.6.5-dev.6
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/decorators/Formula.d.ts +2 -2
- package/decorators/Property.d.ts +2 -2
- package/entity/defineEntity.d.ts +5 -5
- package/index.d.ts +1 -1
- package/metadata/MetadataDiscovery.js +1 -1
- package/package.json +2 -2
- package/typings.d.ts +14 -4
- package/utils/Utils.d.ts +1 -1
- package/utils/Utils.js +2 -2
package/decorators/Formula.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AnyEntity } from '../typings';
|
|
1
|
+
import type { AnyEntity, FormulaCallback } from '../typings';
|
|
2
2
|
import type { PropertyOptions } from './Property';
|
|
3
|
-
export declare function Formula<T extends object>(formula: string |
|
|
3
|
+
export declare function Formula<T extends object>(formula: string | FormulaCallback<T>, options?: FormulaOptions<T>): (target: AnyEntity, propertyName: string) => any;
|
|
4
4
|
export interface FormulaOptions<T> extends PropertyOptions<T> {
|
|
5
5
|
}
|
package/decorators/Property.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Cascade, type LoadStrategy } from '../enums';
|
|
2
|
-
import type { EntityName, Constructor, CheckCallback, GeneratedColumnCallback, AnyString, AnyEntity } from '../typings';
|
|
2
|
+
import type { EntityName, Constructor, CheckCallback, GeneratedColumnCallback, AnyString, AnyEntity, FormulaCallback } from '../typings';
|
|
3
3
|
import type { Type, types } from '../types';
|
|
4
4
|
import type { EntityManager } from '../EntityManager';
|
|
5
5
|
import type { SerializeOptions } from '../serialization/EntitySerializer';
|
|
@@ -88,7 +88,7 @@ export interface PropertyOptions<Owner> {
|
|
|
88
88
|
*
|
|
89
89
|
* @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
|
|
90
90
|
*/
|
|
91
|
-
formula?: string |
|
|
91
|
+
formula?: string | FormulaCallback<Owner>;
|
|
92
92
|
/**
|
|
93
93
|
* For generated columns. This will be appended to the column type after the `generated always` clause.
|
|
94
94
|
*/
|
package/entity/defineEntity.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { ManyToOneOptions } from '../decorators/ManyToOne';
|
|
|
6
6
|
import type { OneToManyOptions } from '../decorators/OneToMany';
|
|
7
7
|
import type { OneToOneOptions } from '../decorators/OneToOne';
|
|
8
8
|
import type { ManyToManyOptions } from '../decorators/ManyToMany';
|
|
9
|
-
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, Hidden, Opt, Primary, EntityClass, Ref, IndexCallback } from '../typings';
|
|
9
|
+
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, Hidden, Opt, Primary, EntityClass, Ref, IndexCallback, FormulaCallback } from '../typings';
|
|
10
10
|
import type { ScalarReference } from './Reference';
|
|
11
11
|
import type { SerializeOptions } from '../serialization/EntitySerializer';
|
|
12
12
|
import type { Cascade, DeferMode, EventType, LoadStrategy, QueryOrderMap } from '../enums';
|
|
@@ -142,7 +142,7 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
142
142
|
*
|
|
143
143
|
* @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
|
|
144
144
|
*/
|
|
145
|
-
formula<T extends string | (
|
|
145
|
+
formula<T extends string | FormulaCallback<any>>(formula: T): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'formula'> & {
|
|
146
146
|
formula: T;
|
|
147
147
|
}, IncludeKeys>, IncludeKeys>;
|
|
148
148
|
/**
|
|
@@ -382,7 +382,7 @@ declare const propertyBuilders: {
|
|
|
382
382
|
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => UniversalPropertyOptionsBuilder<T[], EmptyOptions, IncludeKeysForProperty>;
|
|
383
383
|
decimal: <Mode extends "number" | "string" = "string">(mode?: Mode) => UniversalPropertyOptionsBuilder<NonNullable<Mode extends "number" ? number : string>, EmptyOptions, IncludeKeysForProperty>;
|
|
384
384
|
json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
385
|
-
formula: <T>(formula: string |
|
|
385
|
+
formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
386
386
|
datetime: (length?: number) => UniversalPropertyOptionsBuilder<Date, EmptyOptions, IncludeKeysForProperty>;
|
|
387
387
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
388
388
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -453,7 +453,7 @@ export declare namespace defineEntity {
|
|
|
453
453
|
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => UniversalPropertyOptionsBuilder<T[], EmptyOptions, IncludeKeysForProperty>;
|
|
454
454
|
decimal: <Mode extends "number" | "string" = "string">(mode?: Mode) => UniversalPropertyOptionsBuilder<NonNullable<Mode extends "number" ? number : string>, EmptyOptions, IncludeKeysForProperty>;
|
|
455
455
|
json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
456
|
-
formula: <T>(formula: string |
|
|
456
|
+
formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
457
457
|
datetime: (length?: number) => UniversalPropertyOptionsBuilder<Date, EmptyOptions, IncludeKeysForProperty>;
|
|
458
458
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
459
459
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -564,7 +564,7 @@ type MaybeOpt<Value, Options> = Options extends {
|
|
|
564
564
|
} ? Opt<Value> : Options extends {
|
|
565
565
|
version: true;
|
|
566
566
|
} ? Opt<Value> : Options extends {
|
|
567
|
-
formula: string | (() => string);
|
|
567
|
+
formula: string | ((...args: any[]) => string);
|
|
568
568
|
} ? Opt<Value> : Value;
|
|
569
569
|
type MaybeHidden<Value, Options> = Options extends {
|
|
570
570
|
hidden: true;
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, IndexCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, } from './typings';
|
|
5
|
+
export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, IndexCallback, FormulaCallback, FormulaTable, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, } from './typings';
|
|
6
6
|
export * from './enums';
|
|
7
7
|
export * from './errors';
|
|
8
8
|
export * from './exceptions';
|
|
@@ -1268,7 +1268,7 @@ class MetadataDiscovery {
|
|
|
1268
1268
|
prop.referencedPKs = meta2.primaryKeys;
|
|
1269
1269
|
prop.targetMeta = meta2;
|
|
1270
1270
|
if (!prop.formula && prop.persist === false && [enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && !prop.embedded) {
|
|
1271
|
-
prop.formula =
|
|
1271
|
+
prop.formula = table => `${table}.${this.platform.quoteIdentifier(prop.fieldNames[0])}`;
|
|
1272
1272
|
}
|
|
1273
1273
|
}
|
|
1274
1274
|
initColumnType(prop) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.6.5-dev.
|
|
3
|
+
"version": "6.6.5-dev.6",
|
|
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.3.3",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.6.5-dev.
|
|
67
|
+
"mikro-orm": "6.6.5-dev.6",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/typings.d.ts
CHANGED
|
@@ -313,7 +313,15 @@ type TableName = {
|
|
|
313
313
|
schema?: string;
|
|
314
314
|
toString: () => string;
|
|
315
315
|
};
|
|
316
|
+
export type FormulaTable = {
|
|
317
|
+
alias: string;
|
|
318
|
+
name: string;
|
|
319
|
+
schema?: string;
|
|
320
|
+
qualifiedName: string;
|
|
321
|
+
toString: () => string;
|
|
322
|
+
};
|
|
316
323
|
export type IndexCallback<T> = (table: TableName, columns: Record<PropertyName<T>, string>, indexName: string) => string | RawQueryFragment;
|
|
324
|
+
export type FormulaCallback<T> = (table: FormulaTable, columns: Record<PropertyName<T>, string>) => string;
|
|
317
325
|
export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>) => string;
|
|
318
326
|
export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
|
|
319
327
|
export interface CheckConstraint<T = any> {
|
|
@@ -350,7 +358,7 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
350
358
|
fieldNameRaw?: string;
|
|
351
359
|
default?: string | number | boolean | null;
|
|
352
360
|
defaultRaw?: string;
|
|
353
|
-
formula?:
|
|
361
|
+
formula?: FormulaCallback<Owner>;
|
|
354
362
|
filters?: FilterOptions;
|
|
355
363
|
prefix?: string | boolean;
|
|
356
364
|
prefixMode?: EmbeddedPrefixMode;
|
|
@@ -427,7 +435,7 @@ export declare class EntityMetadata<T = any> {
|
|
|
427
435
|
removeProperty(name: string, sync?: boolean): void;
|
|
428
436
|
getPrimaryProps(flatten?: boolean): EntityProperty<T>[];
|
|
429
437
|
getPrimaryProp(): EntityProperty<T>;
|
|
430
|
-
createColumnMappingObject():
|
|
438
|
+
createColumnMappingObject(): Record<PropertyName<T>, string>;
|
|
431
439
|
get tableName(): string;
|
|
432
440
|
set tableName(name: string);
|
|
433
441
|
sync(initIndexes?: boolean): void;
|
|
@@ -729,17 +737,19 @@ export type PopulateOptions<T> = {
|
|
|
729
737
|
filter?: boolean;
|
|
730
738
|
joinType?: 'inner join' | 'left join';
|
|
731
739
|
children?: PopulateOptions<T[keyof T]>[];
|
|
740
|
+
/** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */
|
|
741
|
+
dataOnly?: boolean;
|
|
732
742
|
};
|
|
733
743
|
type Loadable<T extends object> = Collection<T, any> | Reference<T> | Ref<T> | readonly T[];
|
|
734
744
|
type ExtractType<T> = T extends Loadable<infer U> ? U : T;
|
|
735
745
|
type ExtractStringKeys<T> = {
|
|
736
|
-
[K in keyof T]
|
|
746
|
+
[K in keyof T]-?: CleanKeys<T, K>;
|
|
737
747
|
}[keyof T] & {};
|
|
738
748
|
type StringKeys<T, E extends string = never> = T extends Collection<any, any> ? ExtractStringKeys<ExtractType<T>> | E : T extends Reference<any> ? ExtractStringKeys<ExtractType<T>> | E : T extends object ? ExtractStringKeys<ExtractType<T>> | E : never;
|
|
739
749
|
type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T ? ExtractType<T[K]> : (K extends E ? keyof T : never);
|
|
740
750
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
741
751
|
type CollectionKeys<T> = T extends object ? {
|
|
742
|
-
[K in keyof T]
|
|
752
|
+
[K in keyof T]-?: T[K] extends Collection<any> ? IsAny<T[K]> extends true ? never : K & string : never;
|
|
743
753
|
}[keyof T] & {} : never;
|
|
744
754
|
export type AutoPath<O, P extends string | boolean, E extends string = never, D extends Prev[number] = 9> = P extends boolean ? P : [D] extends [never] ? never : P extends any ? P extends string ? (P & `${string}.` extends never ? P : P & `${string}.`) extends infer Q ? Q extends `${infer A}.${infer B}` ? A extends StringKeys<O, E> ? `${A}.${AutoPath<NonNullable<GetStringKey<O, A, E>>, B, E, Prev[D]>}` : never : Q extends StringKeys<O, E> ? (NonNullable<GetStringKey<O, Q, E>> extends unknown ? Exclude<P, `${string}.`> : never) | (StringKeys<NonNullable<GetStringKey<O, Q, E>>, E> extends never ? never : `${Q & string}.`) : StringKeys<O, E> | `${CollectionKeys<O>}:ref` : never : never : never;
|
|
745
755
|
export type UnboxArray<T> = T extends any[] ? ArrayElement<T> : T;
|
package/utils/Utils.d.ts
CHANGED
|
@@ -215,7 +215,7 @@ export declare class Utils {
|
|
|
215
215
|
* Extracts all possible values of a TS enum. Works with both string and numeric enums.
|
|
216
216
|
*/
|
|
217
217
|
static extractEnumValues(target: Dictionary): (string | number)[];
|
|
218
|
-
static flatten<T>(arrays: T[][]): T[];
|
|
218
|
+
static flatten<T>(arrays: T[][], deep?: boolean): T[];
|
|
219
219
|
static isOperator(key: PropertyKey, includeGroupOperators?: boolean): boolean;
|
|
220
220
|
static isGroupOperator(key: PropertyKey): boolean;
|
|
221
221
|
static isArrayOperator(key: PropertyKey): boolean;
|
package/utils/Utils.js
CHANGED
|
@@ -862,8 +862,8 @@ class Utils {
|
|
|
862
862
|
}
|
|
863
863
|
return values;
|
|
864
864
|
}
|
|
865
|
-
static flatten(arrays) {
|
|
866
|
-
return
|
|
865
|
+
static flatten(arrays, deep) {
|
|
866
|
+
return arrays.flatMap(v => deep && Array.isArray(v) ? this.flatten(v, true) : v);
|
|
867
867
|
}
|
|
868
868
|
static isOperator(key, includeGroupOperators = true) {
|
|
869
869
|
if (!includeGroupOperators) {
|