@mikro-orm/decorators 7.0.2-dev.8 → 7.0.2
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/README.md +128 -294
- package/es/Check.d.ts +4 -1
- package/es/Check.js +7 -6
- package/es/CreateRequestContext.d.ts +15 -2
- package/es/CreateRequestContext.js +26 -22
- package/es/Embeddable.d.ts +4 -1
- package/es/Embeddable.js +10 -9
- package/es/Embedded.d.ts +5 -1
- package/es/Embedded.js +11 -10
- package/es/Entity.d.ts +4 -1
- package/es/Entity.js +10 -9
- package/es/Enum.d.ts +4 -1
- package/es/Enum.js +11 -10
- package/es/Filter.d.ts +1 -0
- package/es/Filter.js +5 -4
- package/es/Formula.d.ts +5 -1
- package/es/Formula.js +10 -9
- package/es/Indexed.d.ts +8 -2
- package/es/Indexed.js +13 -11
- package/es/ManyToMany.d.ts +6 -1
- package/es/ManyToMany.js +9 -8
- package/es/ManyToOne.d.ts +5 -1
- package/es/ManyToOne.js +8 -7
- package/es/OneToMany.d.ts +9 -2
- package/es/OneToMany.js +8 -8
- package/es/OneToOne.d.ts +6 -1
- package/es/OneToOne.js +10 -9
- package/es/PrimaryKey.d.ts +8 -2
- package/es/PrimaryKey.js +14 -12
- package/es/Property.d.ts +12 -1
- package/es/Property.js +38 -41
- package/es/Transactional.d.ts +8 -3
- package/es/Transactional.js +18 -15
- package/es/hooks.d.ts +40 -8
- package/es/hooks.js +25 -17
- package/legacy/Check.d.ts +4 -1
- package/legacy/Check.js +10 -9
- package/legacy/CreateRequestContext.d.ts +6 -1
- package/legacy/CreateRequestContext.js +28 -24
- package/legacy/Embeddable.d.ts +1 -0
- package/legacy/Embeddable.js +9 -8
- package/legacy/Embedded.d.ts +5 -1
- package/legacy/Embedded.js +12 -11
- package/legacy/Entity.d.ts +1 -0
- package/legacy/Entity.js +9 -8
- package/legacy/Enum.d.ts +4 -1
- package/legacy/Enum.js +11 -10
- package/legacy/Filter.d.ts +1 -0
- package/legacy/Filter.js +5 -4
- package/legacy/Formula.d.ts +5 -1
- package/legacy/Formula.js +10 -9
- package/legacy/Indexed.d.ts +8 -2
- package/legacy/Indexed.js +14 -12
- package/legacy/ManyToMany.d.ts +9 -2
- package/legacy/ManyToMany.js +8 -8
- package/legacy/ManyToOne.d.ts +8 -2
- package/legacy/ManyToOne.js +8 -8
- package/legacy/OneToMany.d.ts +9 -2
- package/legacy/OneToMany.js +8 -8
- package/legacy/OneToOne.d.ts +9 -2
- package/legacy/OneToOne.js +10 -10
- package/legacy/PrimaryKey.d.ts +8 -2
- package/legacy/PrimaryKey.js +15 -13
- package/legacy/Property.d.ts +4 -1
- package/legacy/Property.js +26 -25
- package/legacy/ReflectMetadataProvider.d.ts +3 -2
- package/legacy/ReflectMetadataProvider.js +49 -44
- package/legacy/Transactional.d.ts +2 -2
- package/legacy/Transactional.js +20 -17
- package/legacy/hooks.d.ts +8 -0
- package/legacy/hooks.js +23 -15
- package/package.json +3 -3
- package/utils.d.ts +41 -10
- package/utils.js +91 -85
package/es/Embedded.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines an embedded property on an entity (TC39 decorator). */
|
|
3
4
|
export function Embedded(type = {}, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
5
|
+
return function (value, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.EMBEDDED);
|
|
7
|
+
options = type instanceof Function ? { entity: type, ...options } : { ...type, ...options };
|
|
8
|
+
Utils.defaultValue(options, 'prefix', true);
|
|
9
|
+
meta.properties[context.name] = {
|
|
10
|
+
name: context.name,
|
|
11
|
+
kind: ReferenceKind.EMBEDDED,
|
|
12
|
+
...options,
|
|
13
13
|
};
|
|
14
|
+
};
|
|
14
15
|
}
|
package/es/Entity.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type Constructor, type EntityOptions, type EntityClass } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Marks a class as a MikroORM entity (TC39 decorator). */
|
|
3
|
+
export declare function Entity<Owner extends EntityClass<unknown> & Constructor>(
|
|
4
|
+
options?: EntityOptions<Owner>,
|
|
5
|
+
): (target: Owner, context: ClassDecoratorContext<Owner>) => void;
|
package/es/Entity.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Utils } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Marks a class as a MikroORM entity (TC39 decorator). */
|
|
3
4
|
export function Entity(options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
return function (target, context) {
|
|
6
|
+
const meta = getMetadataFromDecorator(target);
|
|
7
|
+
const metadata = { ...context.metadata };
|
|
8
|
+
Utils.mergeConfig(meta, metadata, options);
|
|
9
|
+
meta.class = target;
|
|
10
|
+
if (!options.abstract || meta.discriminatorColumn) {
|
|
11
|
+
meta.name = context.name;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
13
14
|
}
|
package/es/Enum.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type EnumOptions, type AnyEntity, type Dictionary } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines an enum property on an entity (TC39 decorator). */
|
|
3
|
+
export declare function Enum<Owner extends object>(
|
|
4
|
+
options?: EnumOptions<AnyEntity> | (() => Dictionary),
|
|
5
|
+
): (target: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Enum.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines an enum property on an entity (TC39 decorator). */
|
|
3
4
|
export function Enum(options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
5
|
+
return function (target, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context);
|
|
7
|
+
options = options instanceof Function ? { items: options } : options;
|
|
8
|
+
meta.properties[context.name] = {
|
|
9
|
+
name: context.name,
|
|
10
|
+
kind: ReferenceKind.SCALAR,
|
|
11
|
+
enum: true,
|
|
12
|
+
...options,
|
|
13
13
|
};
|
|
14
|
+
};
|
|
14
15
|
}
|
package/es/Filter.d.ts
CHANGED
package/es/Filter.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
|
+
/** Registers a named filter on an entity class (TC39 decorator). */
|
|
2
3
|
export function Filter(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
return function (target) {
|
|
5
|
+
const meta = getMetadataFromDecorator(target);
|
|
6
|
+
meta.filters[options.name] = options;
|
|
7
|
+
};
|
|
7
8
|
}
|
package/es/Formula.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { type FormulaCallback, type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a computed SQL formula property on an entity (TC39 decorator). */
|
|
3
|
+
export declare function Formula<Owner extends object>(
|
|
4
|
+
formula: string | FormulaCallback<Owner>,
|
|
5
|
+
options?: PropertyOptions<Owner>,
|
|
6
|
+
): (value: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Formula.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines a computed SQL formula property on an entity (TC39 decorator). */
|
|
3
4
|
export function Formula(formula, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
5
|
+
return function (value, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context);
|
|
7
|
+
meta.properties[context.name] = {
|
|
8
|
+
name: context.name,
|
|
9
|
+
kind: ReferenceKind.SCALAR,
|
|
10
|
+
formula,
|
|
11
|
+
...options,
|
|
12
12
|
};
|
|
13
|
+
};
|
|
13
14
|
}
|
package/es/Indexed.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type IndexOptions, type UniqueOptions, type Constructor } from '@mikro-orm/core';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
/** Defines a database index on a property or entity class (TC39 decorator). */
|
|
3
|
+
export declare function Index<T extends object, H extends string>(
|
|
4
|
+
options?: IndexOptions<T, H>,
|
|
5
|
+
): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T>) => any;
|
|
6
|
+
/** Defines a unique constraint on a property or entity class (TC39 decorator). */
|
|
7
|
+
export declare function Unique<T extends object, H extends string>(
|
|
8
|
+
options?: UniqueOptions<T, H>,
|
|
9
|
+
): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T>) => any;
|
package/es/Indexed.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
function createDecorator(options, unique) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
return function (value, context) {
|
|
3
|
+
const meta = context.metadata;
|
|
4
|
+
if (context.kind === 'field') {
|
|
5
|
+
options.properties ??= context.name;
|
|
6
|
+
}
|
|
7
|
+
const key = unique ? 'uniques' : 'indexes';
|
|
8
|
+
meta[key] ??= [];
|
|
9
|
+
meta[key].push(options);
|
|
10
|
+
};
|
|
11
11
|
}
|
|
12
|
+
/** Defines a database index on a property or entity class (TC39 decorator). */
|
|
12
13
|
export function Index(options = {}) {
|
|
13
|
-
|
|
14
|
+
return createDecorator(options, false);
|
|
14
15
|
}
|
|
16
|
+
/** Defines a unique constraint on a property or entity class (TC39 decorator). */
|
|
15
17
|
export function Unique(options = {}) {
|
|
16
|
-
|
|
18
|
+
return createDecorator(options, true);
|
|
17
19
|
}
|
package/es/ManyToMany.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { type EntityName, type ManyToManyOptions, type Collection } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a many-to-many relationship (TC39 decorator). */
|
|
3
|
+
export declare function ManyToMany<Target extends object, Owner extends object>(
|
|
4
|
+
entity?: ManyToManyOptions<Owner, Target> | string | (() => EntityName<Target>),
|
|
5
|
+
mappedBy?: (string & keyof Target) | ((e: Target) => any),
|
|
6
|
+
options?: Partial<ManyToManyOptions<Owner, Target>>,
|
|
7
|
+
): (_: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
package/es/ManyToMany.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
|
+
/** Defines a many-to-many relationship (TC39 decorator). */
|
|
3
4
|
export function ManyToMany(entity, mappedBy, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
return function (_, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_MANY);
|
|
7
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
8
|
+
const property = { name: context.name, kind: ReferenceKind.MANY_TO_MANY };
|
|
9
|
+
meta.properties[context.name] ??= {};
|
|
10
|
+
Utils.mergeConfig(meta.properties[context.name], property, options);
|
|
11
|
+
};
|
|
11
12
|
}
|
package/es/ManyToOne.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { type ManyToOneOptions, type EntityName, type Ref } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a many-to-one relationship (TC39 decorator). */
|
|
3
|
+
export declare function ManyToOne<Target extends object, Owner extends object>(
|
|
4
|
+
entity?: ManyToOneOptions<Owner, Target> | ((e?: Owner) => EntityName<Target> | EntityName[]),
|
|
5
|
+
options?: Partial<ManyToOneOptions<Owner, Target>>,
|
|
6
|
+
): (_: unknown, context: ClassFieldDecoratorContext<Owner, Target | undefined | null | Ref<Target>>) => void;
|
package/es/ManyToOne.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
|
+
/** Defines a many-to-one relationship (TC39 decorator). */
|
|
3
4
|
export function ManyToOne(entity = {}, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
return function (_, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_ONE);
|
|
7
|
+
options = processDecoratorParameters({ entity, options });
|
|
8
|
+
const property = { name: context.name, kind: ReferenceKind.MANY_TO_ONE };
|
|
9
|
+
meta.properties[context.name] = Utils.mergeConfig(meta.properties[context.name] ?? {}, property, options);
|
|
10
|
+
};
|
|
10
11
|
}
|
package/es/OneToMany.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { type Collection, type EntityName, type OneToManyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
3
|
-
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
2
|
+
/** Defines a one-to-many relationship (TC39 decorator). */
|
|
3
|
+
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
4
|
+
entity: string | ((e?: Owner) => EntityName<Target>),
|
|
5
|
+
mappedBy: (string & keyof Target) | ((e: Target) => any),
|
|
6
|
+
options?: Partial<OneToManyOptions<Owner, Target>>,
|
|
7
|
+
): (value: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
|
8
|
+
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
9
|
+
options: OneToManyOptions<Owner, Target>,
|
|
10
|
+
): (value: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
package/es/OneToMany.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
export function OneToMany(entity, mappedBy, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.ONE_TO_MANY);
|
|
6
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
7
|
+
const property = { name: context.name, kind: ReferenceKind.ONE_TO_MANY };
|
|
8
|
+
meta.properties[context.name] ??= {};
|
|
9
|
+
Utils.mergeConfig(meta.properties[context.name], property, options);
|
|
10
|
+
};
|
|
11
11
|
}
|
package/es/OneToOne.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { type EntityName, type OneToOneOptions, type Ref } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a one-to-one relationship (TC39 decorator). */
|
|
3
|
+
export declare function OneToOne<Target extends object, Owner extends object>(
|
|
4
|
+
entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target> | EntityName[]),
|
|
5
|
+
mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>,
|
|
6
|
+
options?: Partial<OneToOneOptions<Owner, Target>>,
|
|
7
|
+
): (_: unknown, context: ClassFieldDecoratorContext<Owner, Target | Ref<Target> | null | undefined>) => void;
|
package/es/OneToOne.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
|
+
/** Defines a one-to-one relationship (TC39 decorator). */
|
|
3
4
|
export function OneToOne(entity, mappedByOrOptions, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const mappedBy = typeof mappedByOrOptions === 'object' ? mappedByOrOptions.mappedBy : mappedByOrOptions;
|
|
6
|
+
options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
|
|
7
|
+
return function (_, context) {
|
|
8
|
+
const meta = prepareMetadataContext(context, ReferenceKind.ONE_TO_ONE);
|
|
9
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
10
|
+
const property = { name: context.name, kind: ReferenceKind.ONE_TO_ONE };
|
|
11
|
+
meta.properties[context.name] = Object.assign(meta.properties[context.name] ?? {}, property, options);
|
|
12
|
+
};
|
|
12
13
|
}
|
package/es/PrimaryKey.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type PrimaryKeyOptions, type SerializedPrimaryKeyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
/** Marks a property as the primary key of an entity (TC39 decorator). */
|
|
3
|
+
export declare function PrimaryKey<T extends object>(
|
|
4
|
+
options?: PrimaryKeyOptions<T>,
|
|
5
|
+
): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
|
6
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (TC39 decorator). */
|
|
7
|
+
export declare function SerializedPrimaryKey<T extends object>(
|
|
8
|
+
options?: SerializedPrimaryKeyOptions<T>,
|
|
9
|
+
): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
package/es/PrimaryKey.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
function createDecorator(options, serialized) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
|
6
|
+
const key = serialized ? 'serializedPrimaryKey' : 'primary';
|
|
7
|
+
options[key] = true;
|
|
8
|
+
meta.properties[context.name] = {
|
|
9
|
+
name: context.name,
|
|
10
|
+
kind: ReferenceKind.SCALAR,
|
|
11
|
+
...options,
|
|
13
12
|
};
|
|
13
|
+
};
|
|
14
14
|
}
|
|
15
|
+
/** Marks a property as the primary key of an entity (TC39 decorator). */
|
|
15
16
|
export function PrimaryKey(options = {}) {
|
|
16
|
-
|
|
17
|
+
return createDecorator(options, false);
|
|
17
18
|
}
|
|
19
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (TC39 decorator). */
|
|
18
20
|
export function SerializedPrimaryKey(options = {}) {
|
|
19
|
-
|
|
21
|
+
return createDecorator(options, true);
|
|
20
22
|
}
|
package/es/Property.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import { type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a scalar property on an entity (TC39 decorator). */
|
|
3
|
+
export declare function Property<T extends object>(
|
|
4
|
+
options?: PropertyOptions<T>,
|
|
5
|
+
): (
|
|
6
|
+
value: unknown,
|
|
7
|
+
context:
|
|
8
|
+
| ClassFieldDecoratorContext<T>
|
|
9
|
+
| ClassGetterDecoratorContext<T>
|
|
10
|
+
| ClassSetterDecoratorContext<T>
|
|
11
|
+
| ClassAccessorDecoratorContext<T>
|
|
12
|
+
| ClassMethodDecoratorContext<T>,
|
|
13
|
+
) => void;
|
package/es/Property.js
CHANGED
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines a scalar property on an entity (TC39 decorator). */
|
|
3
4
|
export function Property(options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
meta.checks.push({ property: prop.name, expression: check });
|
|
42
|
-
}
|
|
43
|
-
meta.properties[prop.name] = prop;
|
|
44
|
-
};
|
|
5
|
+
return function (value, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
|
7
|
+
const { check, ...opts } = options;
|
|
8
|
+
const prop = { kind: ReferenceKind.SCALAR, ...opts };
|
|
9
|
+
const name = options.name ?? context.name;
|
|
10
|
+
meta.checks ??= [];
|
|
11
|
+
if (context.name !== name) {
|
|
12
|
+
Utils.renameKey(options, 'name', 'fieldName');
|
|
13
|
+
}
|
|
14
|
+
if (context.kind === 'field') {
|
|
15
|
+
prop.name = context.name;
|
|
16
|
+
prop.getter = false;
|
|
17
|
+
prop.setter = false;
|
|
18
|
+
} else if (context.kind === 'getter') {
|
|
19
|
+
prop.name = context.name;
|
|
20
|
+
prop.getter = true;
|
|
21
|
+
prop.setter = false;
|
|
22
|
+
} else if (context.kind === 'setter') {
|
|
23
|
+
prop.name = context.name;
|
|
24
|
+
prop.getter = false;
|
|
25
|
+
prop.setter = true;
|
|
26
|
+
} else if (context.kind === 'accessor') {
|
|
27
|
+
prop.name = context.name;
|
|
28
|
+
prop.getter = true;
|
|
29
|
+
prop.setter = true;
|
|
30
|
+
} else if (context.kind === 'method') {
|
|
31
|
+
prop.getter = true;
|
|
32
|
+
prop.persist = false;
|
|
33
|
+
prop.type = 'method';
|
|
34
|
+
prop.getterName = context.name;
|
|
35
|
+
prop.name = name;
|
|
36
|
+
}
|
|
37
|
+
if (check) {
|
|
38
|
+
meta.checks.push({ property: prop.name, expression: check });
|
|
39
|
+
}
|
|
40
|
+
meta.properties[prop.name] = prop;
|
|
41
|
+
};
|
|
45
42
|
}
|
package/es/Transactional.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type TransactionOptions } from '@mikro-orm/core';
|
|
2
2
|
import { type ContextProvider } from '../utils.js';
|
|
3
3
|
type TransactionalOptions<T> = TransactionOptions & {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
context?: ContextProvider<T>;
|
|
5
|
+
contextName?: string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* This decorator wraps the method with `em.transactional()`, so you can provide `TransactionOptions` just like with `em.transactional()`.
|
|
@@ -11,5 +11,10 @@ type TransactionalOptions<T> = TransactionOptions & {
|
|
|
11
11
|
* It works on async functions and can be nested with `em.transactional()`.
|
|
12
12
|
* Unlike `em.transactional()`, this decorator uses `REQUIRED` propagation by default, which means it will join existing transactions.
|
|
13
13
|
*/
|
|
14
|
-
export declare function Transactional<
|
|
14
|
+
export declare function Transactional<
|
|
15
|
+
Owner extends object,
|
|
16
|
+
Value extends (this: Owner, ...args: any) => any = (this: Owner, ...args: any) => any,
|
|
17
|
+
>(
|
|
18
|
+
options?: TransactionalOptions<Owner>,
|
|
19
|
+
): (value: Value, context: ClassMethodDecoratorContext<Owner, Value>) => (this: Owner, ...args: any) => Promise<any>;
|
|
15
20
|
export {};
|
package/es/Transactional.js
CHANGED
|
@@ -8,20 +8,23 @@ import { resolveContextProvider } from '../utils.js';
|
|
|
8
8
|
* Unlike `em.transactional()`, this decorator uses `REQUIRED` propagation by default, which means it will join existing transactions.
|
|
9
9
|
*/
|
|
10
10
|
export function Transactional(options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
return function (value, context) {
|
|
12
|
+
if (value.constructor.name !== 'AsyncFunction') {
|
|
13
|
+
throw new Error('@Transactional() should be use with async functions');
|
|
14
|
+
}
|
|
15
|
+
return async function (...args) {
|
|
16
|
+
const { context, contextName, ...txOptions } = options;
|
|
17
|
+
txOptions.propagation ??= TransactionPropagation.REQUIRED;
|
|
18
|
+
const em =
|
|
19
|
+
(await resolveContextProvider(this, context)) ||
|
|
20
|
+
TransactionContext.getEntityManager(contextName) ||
|
|
21
|
+
RequestContext.getEntityManager(contextName);
|
|
22
|
+
if (!em) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`@Transactional() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@Transactional(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return em.transactional(() => value.apply(this, args), txOptions);
|
|
26
28
|
};
|
|
29
|
+
};
|
|
27
30
|
}
|
package/es/hooks.d.ts
CHANGED
|
@@ -1,16 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/** Called before a new entity is persisted to the database (TC39 decorator). */
|
|
2
|
+
export declare function BeforeCreate(): (
|
|
3
|
+
value: (...args: any[]) => unknown,
|
|
4
|
+
context: ClassMethodDecoratorContext,
|
|
5
|
+
) => void;
|
|
6
|
+
/** Called after a new entity has been persisted to the database (TC39 decorator). */
|
|
7
|
+
export declare function AfterCreate(): (
|
|
8
|
+
value: (...args: any[]) => unknown,
|
|
9
|
+
context: ClassMethodDecoratorContext,
|
|
10
|
+
) => void;
|
|
11
|
+
/** Called before an existing entity is updated in the database (TC39 decorator). */
|
|
12
|
+
export declare function BeforeUpdate(): (
|
|
13
|
+
value: (...args: any[]) => unknown,
|
|
14
|
+
context: ClassMethodDecoratorContext,
|
|
15
|
+
) => void;
|
|
16
|
+
/** Called after an existing entity has been updated in the database (TC39 decorator). */
|
|
17
|
+
export declare function AfterUpdate(): (
|
|
18
|
+
value: (...args: any[]) => unknown,
|
|
19
|
+
context: ClassMethodDecoratorContext,
|
|
20
|
+
) => void;
|
|
21
|
+
/** Called before an entity is upserted (TC39 decorator). */
|
|
22
|
+
export declare function BeforeUpsert(): (
|
|
23
|
+
value: (...args: any[]) => unknown,
|
|
24
|
+
context: ClassMethodDecoratorContext,
|
|
25
|
+
) => void;
|
|
26
|
+
/** Called after an entity has been upserted (TC39 decorator). */
|
|
27
|
+
export declare function AfterUpsert(): (
|
|
28
|
+
value: (...args: any[]) => unknown,
|
|
29
|
+
context: ClassMethodDecoratorContext,
|
|
30
|
+
) => void;
|
|
31
|
+
/** Called when an entity is instantiated by the EntityManager (TC39 decorator). */
|
|
7
32
|
export declare function OnInit(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
33
|
+
/** Called after an entity is loaded from the database (TC39 decorator). */
|
|
8
34
|
export declare function OnLoad(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
9
35
|
/**
|
|
10
36
|
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
11
37
|
*/
|
|
12
|
-
export declare function BeforeDelete(): (
|
|
38
|
+
export declare function BeforeDelete(): (
|
|
39
|
+
value: (...args: any[]) => unknown,
|
|
40
|
+
context: ClassMethodDecoratorContext,
|
|
41
|
+
) => void;
|
|
13
42
|
/**
|
|
14
43
|
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
15
44
|
*/
|
|
16
|
-
export declare function AfterDelete(): (
|
|
45
|
+
export declare function AfterDelete(): (
|
|
46
|
+
value: (...args: any[]) => unknown,
|
|
47
|
+
context: ClassMethodDecoratorContext,
|
|
48
|
+
) => void;
|